Highway to PSR2
[openemr.git] / contrib / forms / body_composition / new.php
blobd982f940e42e3333a1318fcc200e8eb82da77770
1 <?php
2 //////////////////////////////////////////////////////////////////////
3 // ------------------ DO NOT MODIFY VIEW.PHP !!! ---------------------
4 // View.php is an exact duplicate of new.php. If you wish to make
5 // any changes, then change new.php and either (recommended) make
6 // view.php a symbolic link to new.php, or copy new.php to view.php.
7 //
8 // And if you check in a change to either module, be sure to check
9 // in the other (identical) module also.
11 // This nonsense will go away if we ever move to subversion.
12 //////////////////////////////////////////////////////////////////////
14 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
16 // This program is free software; you can redistribute it and/or
17 // modify it under the terms of the GNU General Public License
18 // as published by the Free Software Foundation; either version 2
19 // of the License, or (at your option) any later version.
21 include_once("../../globals.php");
22 include_once("$srcdir/api.inc");
23 include_once("$srcdir/forms.inc");
25 $scale_file_name = '/tmp/tanita_scale.txt';
26 $scale_file_age = -1;
27 $row = array();
29 if (! $encounter) { // comes from globals.php
30 die("Internal error: we do not seem to be in an encounter!");
33 // encode a string from a form field for database writing.
34 function form2db($fldval)
36 $fldval = trim($fldval);
37 $fldval = formDataCore($fldval);
38 return $fldval;
41 function rbvalue($rbname)
43 $tmp = $_POST[$rbname];
44 if (! $tmp) {
45 return "NULL";
48 return "'$tmp'";
51 function rbinput($name, $value, $desc, $colname)
53 global $row;
54 $ret = "<input type='radio' name='$name' value='$value'";
55 if ($row[$colname] == $value) {
56 $ret .= " checked";
59 $ret .= " />$desc";
60 return $ret;
63 $formid = $_GET['id'];
65 // If Save was clicked, save the info.
67 if ($_POST['bn_save']) {
68 // If updating an existing form...
70 if ($formid) {
71 $query = "UPDATE form_body_composition SET " .
72 "body_type = " . rbvalue('form_body_type') . ", " .
73 "height = '" . form2db($_POST['form_height']) . "', " .
74 "weight = '" . form2db($_POST['form_weight']) . "', " .
75 "bmi = '" . form2db($_POST['form_bmi']) . "', " .
76 "bmr = '" . form2db($_POST['form_bmr']) . "', " .
77 "impedance = '" . form2db($_POST['form_impedance']) . "', " .
78 "fat_pct = '" . form2db($_POST['form_fat_pct']) . "', " .
79 "fat_mass = '" . form2db($_POST['form_fat_mass']) . "', " .
80 "ffm = '" . form2db($_POST['form_ffm']) . "', " .
81 "tbw = '" . form2db($_POST['form_tbw']) . "', " .
82 "other = '" . form2db($_POST['form_other']) . "' " .
83 "WHERE id = '$formid'";
84 sqlStatement($query);
85 } // If adding a new form...
87 else {
88 $query = "INSERT INTO form_body_composition ( " .
89 "body_type, height, weight, bmi, bmr, impedance, fat_pct, " .
90 "fat_mass, ffm, tbw, other " .
91 ") VALUES ( " .
92 rbvalue('form_body_type') . ", " .
93 "'" . form2db($_POST['form_height']) . "', " .
94 "'" . form2db($_POST['form_weight']) . "', " .
95 "'" . form2db($_POST['form_bmi']) . "', " .
96 "'" . form2db($_POST['form_bmr']) . "', " .
97 "'" . form2db($_POST['form_impedance']) . "', " .
98 "'" . form2db($_POST['form_fat_pct']) . "', " .
99 "'" . form2db($_POST['form_fat_mass']) . "', " .
100 "'" . form2db($_POST['form_ffm']) . "', " .
101 "'" . form2db($_POST['form_tbw']) . "', " .
102 "'" . form2db($_POST['form_other']) . "' " .
103 ")";
104 $newid = sqlInsert($query);
105 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
108 formHeader("Redirecting....");
109 formJump();
110 formFooter();
111 exit;
114 if ($formid) {
115 $row = sqlQuery("SELECT * FROM form_body_composition WHERE " .
116 "id = '$formid' AND activity = '1'") ;
117 } else {
118 // Get the most recent scale reading.
119 $items = explode(',', trim(file_get_contents($scale_file_name)));
120 if ($items && count($items) > 11) {
121 $scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
122 $row['body_type'] = $items[0] ? 'Athletic' : 'Standard';
123 $row['height'] = $items[2];
124 $row['weight'] = $items[3];
125 $row['bmi'] = $items[10];
126 $row['bmr'] = $items[11];
127 $row['impedance'] = $items[4];
128 $row['fat_pct'] = $items[5];
129 $row['fat_mass'] = $items[6];
130 $row['ffm'] = $items[7];
131 $row['tbw'] = $items[8];
135 <html>
136 <head>
137 <?php html_header_show();?>
138 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
139 <script language="JavaScript">
140 </script>
141 </head>
143 <body <?php echo $top_bg_line;?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
144 <form method="post" action="<?php echo $rootdir ?>/forms/body_composition/new.php?id=<?php echo $formid ?>"
145 onsubmit="return top.restoreSession()">
147 <center>
150 <table border='0' width='95%'>
152 <tr bgcolor='#dddddd'>
153 <td colspan='3' align='center'><b>Body Composition</b></td>
154 </tr>
156 <tr>
157 <td width='5%' nowrap>Body Type</td>
158 <td colspan='2' nowrap>
159 <?php echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type') ?>&nbsp;
160 <?php echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type') ?>&nbsp;
161 </td>
162 </tr>
164 <tr>
165 <td nowrap>Height in inches</td>
166 <td nowrap>
167 <input type='text' name='form_height' size='6'
168 value='<?php echo addslashes($row['height']) ?>' /> &nbsp;
169 </td>
170 <td nowrap>
171 &nbsp;
172 </td>
173 </tr>
175 <tr>
176 <td nowrap>Weight in pounds</td>
177 <td nowrap>
178 <input type='text' name='form_weight' size='6'
179 value='<?php echo addslashes($row['weight']) ?>' /> &nbsp;
180 </td>
181 <td align='center' nowrap>
182 <?php
183 if ($scale_file_age >= 0) {
184 echo "<font color='blue'>This reading was taken $scale_file_age minutes ago.</font>\n";
185 } else {
186 echo "&nbsp;\n";
189 </td>
190 </tr>
192 <tr>
193 <td nowrap>BMI</td>
194 <td nowrap>
195 <input type='text' name='form_bmi' size='6'
196 value='<?php echo addslashes($row['bmi']) ?>' /> &nbsp;
197 </td>
198 <td nowrap>
199 &nbsp;
200 </td>
201 </tr>
203 <tr>
204 <td nowrap>BMR in kj</td>
205 <td nowrap>
206 <input type='text' name='form_bmr' size='6'
207 value='<?php echo addslashes($row['bmr']) ?>' /> &nbsp;
208 </td>
209 <td nowrap>
210 &nbsp;
211 </td>
212 </tr>
214 <tr>
215 <td nowrap>Impedance in ohms</td>
216 <td nowrap>
217 <input type='text' name='form_impedance' size='6'
218 value='<?php echo addslashes($row['impedance']) ?>' /> &nbsp;
219 </td>
220 <td nowrap>
221 &nbsp;
222 </td>
223 </tr>
225 <tr>
226 <td nowrap>Fat %</td>
227 <td nowrap>
228 <input type='text' name='form_fat_pct' size='6'
229 value='<?php echo addslashes($row['fat_pct']) ?>' /> &nbsp;
230 </td>
231 <td nowrap>
232 &nbsp;
233 </td>
234 </tr>
236 <tr>
237 <td nowrap>Fat Mass in pounds</td>
238 <td nowrap>
239 <input type='text' name='form_fat_mass' size='6'
240 value='<?php echo addslashes($row['fat_mass']) ?>' /> &nbsp;
241 </td>
242 <td nowrap>
243 &nbsp;
244 </td>
245 </tr>
247 <tr>
248 <td nowrap>FFM in pounds</td>
249 <td nowrap>
250 <input type='text' name='form_ffm' size='6'
251 value='<?php echo addslashes($row['ffm']) ?>' /> &nbsp;
252 </td>
253 <td nowrap>
254 &nbsp;
255 </td>
256 </tr>
258 <tr>
259 <td nowrap>TBW in pounds</td>
260 <td nowrap>
261 <input type='text' name='form_tbw' size='6'
262 value='<?php echo addslashes($row['tbw']) ?>' /> &nbsp;
263 </td>
264 <td nowrap>
265 &nbsp;
266 </td>
267 </tr>
269 <tr>
270 <td nowrap>Notes</td>
271 <td colspan='2' nowrap>
272 <textarea name='form_other' rows='8' style='width:100%'><?php echo $row['other'] ?></textarea>
273 </td>
274 </tr>
276 </table>
279 <input type='submit' name='bn_save' value='Save' />
280 &nbsp;
281 <input type='button' value='Cancel' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url'] ?>'" />
282 </p>
284 </center>
286 </form>
287 </body>
288 </html>