changes to prior commit
[openemr.git] / contrib / forms / body_composition / new.php
blob59410a2dfb63f20e0e0b39933e93df2922317419
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 die(xlt('Authentication Error'));
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 ));
74 } // If adding a new form...
76 else {
77 $query = 'INSERT INTO form_body_composition (
78 body_type, height, weight, bmi, bmr, impedance, fat_pct, fat_mass, ffm, tbw, other
79 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
81 $newid = sqlInsert($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
82 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']),
83 trim($_POST['form_ffm']), trim($_POST['form_tbw']), trim($_POST['form_other'])));
85 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
88 formHeader("Redirecting....");
89 formJump();
90 formFooter();
91 exit;
94 if ($formid) {
95 $row = sqlQuery("SELECT * FROM form_body_composition WHERE " .
96 "id = ? AND activity = '1'", array($formid));
97 } else {
98 // Get the most recent scale reading.
99 $items = explode(',', trim(file_get_contents($scale_file_name)));
100 if ($items && count($items) > 11) {
101 $scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
102 $row['body_type'] = $items[0] ? 'Athletic' : 'Standard';
103 $row['height'] = $items[2];
104 $row['weight'] = $items[3];
105 $row['bmi'] = $items[10];
106 $row['bmr'] = $items[11];
107 $row['impedance'] = $items[4];
108 $row['fat_pct'] = $items[5];
109 $row['fat_mass'] = $items[6];
110 $row['ffm'] = $items[7];
111 $row['tbw'] = $items[8];
115 <html>
116 <head>
117 <?php html_header_show();?>
118 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
119 <script language="JavaScript">
120 </script>
121 </head>
123 <body <?php echo $top_bg_line;?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
124 <form method="post" action="<?php echo $rootdir ?>/forms/body_composition/new.php?id=<?php echo attr($formid) ?>"
125 onsubmit="return top.restoreSession()">
126 <input type="hidden" name="csrf_token_form" value="<?php echo attr($_SESSION['csrf_token']); ?>" />
128 <center>
131 <table border='0' width='95%'>
133 <tr bgcolor='#dddddd'>
134 <td colspan='3' align='center'><b>Body Composition</b></td>
135 </tr>
137 <tr>
138 <td width='5%' nowrap>Body Type</td>
139 <td colspan='2' nowrap>
140 <?php echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type') ?>&nbsp;
141 <?php echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type') ?>&nbsp;
142 </td>
143 </tr>
145 <tr>
146 <td nowrap>Height in inches</td>
147 <td nowrap>
148 <input type='text' name='form_height' size='6'
149 value='<?php echo attr($row['height']) ?>' /> &nbsp;
150 </td>
151 <td nowrap>
152 &nbsp;
153 </td>
154 </tr>
156 <tr>
157 <td nowrap>Weight in pounds</td>
158 <td nowrap>
159 <input type='text' name='form_weight' size='6'
160 value='<?php echo attr($row['weight']) ?>' /> &nbsp;
161 </td>
162 <td align='center' nowrap>
163 <?php
164 if ($scale_file_age >= 0) {
165 echo "<font color='blue'>This reading was taken " . text($scale_file_age) . " minutes ago.</font>\n";
166 } else {
167 echo "&nbsp;\n";
170 </td>
171 </tr>
173 <tr>
174 <td nowrap>BMI</td>
175 <td nowrap>
176 <input type='text' name='form_bmi' size='6'
177 value='<?php echo attr($row['bmi']) ?>' /> &nbsp;
178 </td>
179 <td nowrap>
180 &nbsp;
181 </td>
182 </tr>
184 <tr>
185 <td nowrap>BMR in kj</td>
186 <td nowrap>
187 <input type='text' name='form_bmr' size='6'
188 value='<?php echo attr($row['bmr']) ?>' /> &nbsp;
189 </td>
190 <td nowrap>
191 &nbsp;
192 </td>
193 </tr>
195 <tr>
196 <td nowrap>Impedance in ohms</td>
197 <td nowrap>
198 <input type='text' name='form_impedance' size='6'
199 value='<?php echo attr($row['impedance']) ?>' /> &nbsp;
200 </td>
201 <td nowrap>
202 &nbsp;
203 </td>
204 </tr>
206 <tr>
207 <td nowrap>Fat %</td>
208 <td nowrap>
209 <input type='text' name='form_fat_pct' size='6'
210 value='<?php echo attr($row['fat_pct']) ?>' /> &nbsp;
211 </td>
212 <td nowrap>
213 &nbsp;
214 </td>
215 </tr>
217 <tr>
218 <td nowrap>Fat Mass in pounds</td>
219 <td nowrap>
220 <input type='text' name='form_fat_mass' size='6'
221 value='<?php echo attr($row['fat_mass']) ?>' /> &nbsp;
222 </td>
223 <td nowrap>
224 &nbsp;
225 </td>
226 </tr>
228 <tr>
229 <td nowrap>FFM in pounds</td>
230 <td nowrap>
231 <input type='text' name='form_ffm' size='6'
232 value='<?php echo attr($row['ffm']) ?>' /> &nbsp;
233 </td>
234 <td nowrap>
235 &nbsp;
236 </td>
237 </tr>
239 <tr>
240 <td nowrap>TBW in pounds</td>
241 <td nowrap>
242 <input type='text' name='form_tbw' size='6'
243 value='<?php echo attr($row['tbw']) ?>' /> &nbsp;
244 </td>
245 <td nowrap>
246 &nbsp;
247 </td>
248 </tr>
250 <tr>
251 <td nowrap>Notes</td>
252 <td colspan='2' nowrap>
253 <textarea name='form_other' rows='8' style='width:100%'><?php echo text($row['other']) ?></textarea>
254 </td>
255 </tr>
257 </table>
260 <input type='submit' name='bn_save' value='Save' />
261 &nbsp;
262 <input type='button' value='Cancel' onclick="parent.closeTab(window.name, false)" />
263 </p>
265 </center>
267 </form>
268 </body>
269 </html>