psr2 fixes to prior 2 commits
[openemr.git] / contrib / forms / body_composition / view.php
blob6387867d0b639fabc70cae8ea8d30c9a631ff8e4
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";
51 $ret .= " />" . text($desc);
52 return $ret;
55 $formid = $_GET['id'];
57 // If Save was clicked, save the info.
59 if ($_POST['bn_save']) {
60 if (!verifyCsrfToken($_POST["csrf_token_form"])) {
61 die(xlt('Authentication Error'));
64 // If updating an existing form...
66 if ($formid) {
67 $query = "UPDATE form_body_composition SET
68 body_type = ?, height = ?, weight = ?, bmi = ?, bmr = ?, impedance = ?,
69 fat_pct = ?, fat_mass = ?, ffm = ?, tbw = ?, other = ? WHERE id = ?";
71 sqlStatement($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
72 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']), trim($_POST['form_ffm']),
73 trim($_POST['form_tbw']), trim($_POST['form_other']), $formid ));
75 sqlStatement($query);
76 } // If adding a new form...
78 else {
79 $query = "INSERT INTO form_body_composition
80 ( body_type, height, weight, bmi, bmr, impedance,
81 fat_pct, fat_mass, ffm, tbw, other )
82 VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
84 $newid = sqlInsert($query, array(rbvalue('form_body_type'), trim($_POST['form_height']), trim($_POST['form_weight']), trim($_POST['form_bmi']),
85 trim($_POST['form_bmr']), trim($_POST['form_impedance']), trim($_POST['form_fat_pct']), trim($_POST['form_fat_mass']), trim($_POST['form_ffm']),
86 trim($_POST['form_tbw']), trim($_POST['form_other'])));
88 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
91 formHeader("Redirecting....");
92 formJump();
93 formFooter();
94 exit;
97 if ($formid) {
98 $row = sqlQuery("SELECT * FROM form_body_composition WHERE " .
99 "id = ? AND activity = '1'", array($formid));
100 } else {
101 // Get the most recent scale reading.
102 $items = explode(',', trim(file_get_contents($scale_file_name)));
103 if ($items && count($items) > 11) {
104 $scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
105 $row['body_type'] = $items[0] ? 'Athletic' : 'Standard';
106 $row['height'] = $items[2];
107 $row['weight'] = $items[3];
108 $row['bmi'] = $items[10];
109 $row['bmr'] = $items[11];
110 $row['impedance'] = $items[4];
111 $row['fat_pct'] = $items[5];
112 $row['fat_mass'] = $items[6];
113 $row['ffm'] = $items[7];
114 $row['tbw'] = $items[8];
118 <html>
119 <head>
120 <?php html_header_show();?>
121 <link rel=stylesheet href="<?php echo $css_header; ?>" type="text/css">
122 <script language="JavaScript">
123 </script>
124 </head>
126 <body <?php echo $top_bg_line; ?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
127 <form method="post" action="<?php echo $rootdir ?>/forms/body_composition/new.php?id=<?php echo attr($formid) ?>"
128 onsubmit="return top.restoreSession()">
129 <input type="hidden" name="csrf_token_form" value="<?php echo attr($_SESSION['csrf_token']); ?>" />
131 <center>
134 <table border='0' width='95%'>
136 <tr bgcolor='#dddddd'>
137 <td colspan='3' align='center'><b>Body Composition</b></td>
138 </tr>
140 <tr>
141 <td width='5%' nowrap>Body Type</td>
142 <td colspan='2' nowrap>
144 <?php echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type'); ?>&nbsp;
145 <?php echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type'); ?>&nbsp;
146 </td>
147 </tr>
149 <tr>
150 <td nowrap>Height in inches</td>
151 <td nowrap>
152 <input type='text' name='form_height' size='6'
153 value='<?php echo attr($row['height']) ?>' /> &nbsp;
154 </td>
155 <td nowrap>
156 &nbsp;
157 </td>
158 </tr>
160 <tr>
161 <td nowrap>Weight in pounds</td>
162 <td nowrap>
163 <input type='text' name='form_weight' size='6'
164 value='<?php echo attr($row['weight']) ?>' /> &nbsp;
165 </td>
166 <td align='center' nowrap>
167 <?php
168 if ($scale_file_age >= 0) {
169 echo "<font color='blue'>This reading was taken " . text($scale_file_age) . " minutes ago.</font>\n";
170 } else {
171 echo "&nbsp;\n";
174 </td>
175 </tr>
177 <tr>
178 <td nowrap>BMI</td>
179 <td nowrap>
180 <input type='text' name='form_bmi' size='6'
181 value='<?php echo attr($row['bmi']) ?>' /> &nbsp;
182 </td>
183 <td nowrap>
184 &nbsp;
185 </td>
186 </tr>
188 <tr>
189 <td nowrap>BMR in kj</td>
190 <td nowrap>
191 <input type='text' name='form_bmr' size='6'
192 value='<?php echo attr($row['bmr']) ?>' /> &nbsp;
193 </td>
194 <td nowrap>
195 &nbsp;
196 </td>
197 </tr>
199 <tr>
200 <td nowrap>Impedance in ohms</td>
201 <td nowrap>
202 <input type='text' name='form_impedance' size='6'
203 value='<?php echo attr($row['impedance']) ?>' /> &nbsp;
204 </td>
205 <td nowrap>
206 &nbsp;
207 </td>
208 </tr>
210 <tr>
211 <td nowrap>Fat %</td>
212 <td nowrap>
213 <input type='text' name='form_fat_pct' size='6'
214 value='<?php echo attr($row['fat_pct']) ?>' /> &nbsp;
215 </td>
216 <td nowrap>
217 &nbsp;
218 </td>
219 </tr>
221 <tr>
222 <td nowrap>Fat Mass in pounds</td>
223 <td nowrap>
224 <input type='text' name='form_fat_mass' size='6'
225 value='<?php echo attr($row['fat_mass']) ?>' /> &nbsp;
226 </td>
227 <td nowrap>
228 &nbsp;
229 </td>
230 </tr>
232 <tr>
233 <td nowrap>FFM in pounds</td>
234 <td nowrap>
235 <input type='text' name='form_ffm' size='6'
236 value='<?php echo attr($row['ffm']) ?>' /> &nbsp;
237 </td>
238 <td nowrap>
239 &nbsp;
240 </td>
241 </tr>
243 <tr>
244 <td nowrap>TBW in pounds</td>
245 <td nowrap>
246 <input type='text' name='form_tbw' size='6'
247 value='<?php echo attr($row['tbw']) ?>' /> &nbsp;
248 </td>
249 <td nowrap>
250 &nbsp;
251 </td>
252 </tr>
254 <tr>
255 <td nowrap>Notes</td>
256 <td colspan='2' nowrap>
257 <textarea name='form_other' rows='8' style='width:100%'><?php echo text($row['other']) ?></textarea>
258 </td>
259 </tr>
261 </table>
264 <input type='submit' name='bn_save' value='Save' />
265 &nbsp;
266 <input type='button' value='Cancel' onclick="parent.closeTab(window.name, false)" />
267 </p>
269 </center>
271 </form>
272 </body>
273 </html>