bug fix march continued (#1921)
[openemr.git] / contrib / forms / body_composition / new.php
blob9e2c96704f9593aacf35254fbce22153dd1bf8d3
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 require_once("../../globals.php");
22 require_once("$srcdir/api.inc");
23 require_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 function rbvalue($rbname)
35 $tmp = $_POST[$rbname];
36 if (! $tmp) {
37 return "NULL";
40 return "$tmp";
43 function rbinput($name, $value, $desc, $colname)
45 global $row;
46 $ret = "<input type='radio' name='" . attr($name) . "' value='" . attr($value) . "'";
47 if ($row[$colname] == $value) {
48 $ret .= " checked";
50 $ret .= " />" . text($desc);
51 return $ret;
54 $formid = $_GET['id'];
56 // If Save was clicked, save the info.
58 if ($_POST['bn_save']) {
59 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
60 csrfNotVerified();
63 // If updating an existing form...
65 if ($formid) {
66 $query = "UPDATE form_body_composition SET
67 body_type = ?, height = ?, weight = ?, bmi = ?, bmr = ?, impedance = ?,
68 fat_pct = ?, fat_mass = ?, ffm = ?, tbw = ?, other = ? WHERE id = ?";
70 sqlStatement($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
71 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']), trim($_POST['form_ffm']),
72 trim($_POST['form_tbw']), trim($_POST['form_other']), $formid ));
73 } // If adding a new form...
75 else {
76 $query = 'INSERT INTO form_body_composition (
77 body_type, height, weight, bmi, bmr, impedance, fat_pct, fat_mass, ffm, tbw, other
78 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
80 $newid = sqlInsert($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
81 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']),
82 trim($_POST['form_ffm']), trim($_POST['form_tbw']), trim($_POST['form_other'])));
84 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
87 formHeader("Redirecting....");
88 formJump();
89 formFooter();
90 exit;
93 if ($formid) {
94 $row = sqlQuery("SELECT * FROM form_body_composition WHERE " .
95 "id = ? AND activity = '1'", array($formid));
96 } else {
97 // Get the most recent scale reading.
98 $items = explode(',', trim(file_get_contents($scale_file_name)));
99 if ($items && count($items) > 11) {
100 $scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
101 $row['body_type'] = $items[0] ? 'Athletic' : 'Standard';
102 $row['height'] = $items[2];
103 $row['weight'] = $items[3];
104 $row['bmi'] = $items[10];
105 $row['bmr'] = $items[11];
106 $row['impedance'] = $items[4];
107 $row['fat_pct'] = $items[5];
108 $row['fat_mass'] = $items[6];
109 $row['ffm'] = $items[7];
110 $row['tbw'] = $items[8];
114 <html>
115 <head>
116 <?php html_header_show();?>
117 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
118 <script language="JavaScript">
119 </script>
120 </head>
122 <body <?php echo $top_bg_line;?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
123 <form method="post" action="<?php echo $rootdir ?>/forms/body_composition/new.php?id=<?php echo attr($formid) ?>"
124 onsubmit="return top.restoreSession()">
125 <input type="hidden" name="csrf_token_form" value="<?php echo attr(collectCsrfToken()); ?>" />
127 <center>
130 <table border='0' width='95%'>
132 <tr bgcolor='#dddddd'>
133 <td colspan='3' align='center'><b>Body Composition</b></td>
134 </tr>
136 <tr>
137 <td width='5%' nowrap>Body Type</td>
138 <td colspan='2' nowrap>
139 <?php echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type') ?>&nbsp;
140 <?php echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type') ?>&nbsp;
141 </td>
142 </tr>
144 <tr>
145 <td nowrap>Height in inches</td>
146 <td nowrap>
147 <input type='text' name='form_height' size='6'
148 value='<?php echo attr($row['height']) ?>' /> &nbsp;
149 </td>
150 <td nowrap>
151 &nbsp;
152 </td>
153 </tr>
155 <tr>
156 <td nowrap>Weight in pounds</td>
157 <td nowrap>
158 <input type='text' name='form_weight' size='6'
159 value='<?php echo attr($row['weight']) ?>' /> &nbsp;
160 </td>
161 <td align='center' nowrap>
162 <?php
163 if ($scale_file_age >= 0) {
164 echo "<font color='blue'>This reading was taken " . text($scale_file_age) . " minutes ago.</font>\n";
165 } else {
166 echo "&nbsp;\n";
169 </td>
170 </tr>
172 <tr>
173 <td nowrap>BMI</td>
174 <td nowrap>
175 <input type='text' name='form_bmi' size='6'
176 value='<?php echo attr($row['bmi']) ?>' /> &nbsp;
177 </td>
178 <td nowrap>
179 &nbsp;
180 </td>
181 </tr>
183 <tr>
184 <td nowrap>BMR in kj</td>
185 <td nowrap>
186 <input type='text' name='form_bmr' size='6'
187 value='<?php echo attr($row['bmr']) ?>' /> &nbsp;
188 </td>
189 <td nowrap>
190 &nbsp;
191 </td>
192 </tr>
194 <tr>
195 <td nowrap>Impedance in ohms</td>
196 <td nowrap>
197 <input type='text' name='form_impedance' size='6'
198 value='<?php echo attr($row['impedance']) ?>' /> &nbsp;
199 </td>
200 <td nowrap>
201 &nbsp;
202 </td>
203 </tr>
205 <tr>
206 <td nowrap>Fat %</td>
207 <td nowrap>
208 <input type='text' name='form_fat_pct' size='6'
209 value='<?php echo attr($row['fat_pct']) ?>' /> &nbsp;
210 </td>
211 <td nowrap>
212 &nbsp;
213 </td>
214 </tr>
216 <tr>
217 <td nowrap>Fat Mass in pounds</td>
218 <td nowrap>
219 <input type='text' name='form_fat_mass' size='6'
220 value='<?php echo attr($row['fat_mass']) ?>' /> &nbsp;
221 </td>
222 <td nowrap>
223 &nbsp;
224 </td>
225 </tr>
227 <tr>
228 <td nowrap>FFM in pounds</td>
229 <td nowrap>
230 <input type='text' name='form_ffm' size='6'
231 value='<?php echo attr($row['ffm']) ?>' /> &nbsp;
232 </td>
233 <td nowrap>
234 &nbsp;
235 </td>
236 </tr>
238 <tr>
239 <td nowrap>TBW in pounds</td>
240 <td nowrap>
241 <input type='text' name='form_tbw' size='6'
242 value='<?php echo attr($row['tbw']) ?>' /> &nbsp;
243 </td>
244 <td nowrap>
245 &nbsp;
246 </td>
247 </tr>
249 <tr>
250 <td nowrap>Notes</td>
251 <td colspan='2' nowrap>
252 <textarea name='form_other' rows='8' style='width:100%'><?php echo text($row['other']) ?></textarea>
253 </td>
254 </tr>
256 </table>
259 <input type='submit' name='bn_save' value='Save' />
260 &nbsp;
261 <input type='button' value='Cancel' onclick="parent.closeTab(window.name, false)" />
262 </p>
264 </center>
266 </form>
267 </body>
268 </html>