Moving towards HTML5 and CSS3 compatibility. revision 2.
[openemr.git] / contrib / forms / body_composition / view.php
bloba6413188829117e4e4d946606a582423d997b62b
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!");
32 // encode a string from a form field for database writing.
33 function form2db($fldval) {
34 $fldval = trim($fldval);
35 if (!get_magic_quotes_gpc()) $fldval = addslashes($fldval);
36 return $fldval;
39 function rbvalue($rbname) {
40 $tmp = $_POST[$rbname];
41 if (! $tmp) return "NULL";
42 return "'$tmp'";
45 function rbinput($name, $value, $desc, $colname) {
46 global $row;
47 $ret = "<input type='radio' name='$name' value='$value'";
48 if ($row[$colname] == $value) $ret .= " checked";
49 $ret .= " />$desc";
50 return $ret;
53 $formid = $_GET['id'];
55 // If Save was clicked, save the info.
57 if ($_POST['bn_save']) {
59 // If updating an existing form...
61 if ($formid) {
62 $query = "UPDATE form_body_composition SET " .
63 "body_type = " . rbvalue('form_body_type') . ", " .
64 "height = '" . form2db($_POST['form_height']) . "', " .
65 "weight = '" . form2db($_POST['form_weight']) . "', " .
66 "bmi = '" . form2db($_POST['form_bmi']) . "', " .
67 "bmr = '" . form2db($_POST['form_bmr']) . "', " .
68 "impedance = '" . form2db($_POST['form_impedance']) . "', " .
69 "fat_pct = '" . form2db($_POST['form_fat_pct']) . "', " .
70 "fat_mass = '" . form2db($_POST['form_fat_mass']) . "', " .
71 "ffm = '" . form2db($_POST['form_ffm']) . "', " .
72 "tbw = '" . form2db($_POST['form_tbw']) . "', " .
73 "other = '" . form2db($_POST['form_other']) . "' " .
74 "WHERE id = '$formid'";
75 sqlStatement($query);
78 // If adding a new form...
80 else {
81 $query = "INSERT INTO form_body_composition ( " .
82 "body_type, height, weight, bmi, bmr, impedance, fat_pct, " .
83 "fat_mass, ffm, tbw, other " .
84 ") VALUES ( " .
85 rbvalue('form_body_type') . ", " .
86 "'" . form2db($_POST['form_height']) . "', " .
87 "'" . form2db($_POST['form_weight']) . "', " .
88 "'" . form2db($_POST['form_bmi']) . "', " .
89 "'" . form2db($_POST['form_bmr']) . "', " .
90 "'" . form2db($_POST['form_impedance']) . "', " .
91 "'" . form2db($_POST['form_fat_pct']) . "', " .
92 "'" . form2db($_POST['form_fat_mass']) . "', " .
93 "'" . form2db($_POST['form_ffm']) . "', " .
94 "'" . form2db($_POST['form_tbw']) . "', " .
95 "'" . form2db($_POST['form_other']) . "' " .
96 ")";
97 $newid = sqlInsert($query);
98 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
101 formHeader("Redirecting....");
102 formJump();
103 formFooter();
104 exit;
107 if ($formid) {
108 $row = sqlQuery ("SELECT * FROM form_body_composition WHERE " .
109 "id = '$formid' AND activity = '1'") ;
111 else {
112 // Get the most recent scale reading.
113 $items = explode(',', trim(file_get_contents($scale_file_name)));
114 if ($items && count($items) > 11) {
115 $scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
116 $row['body_type'] = $items[0] ? 'Athletic' : 'Standard';
117 $row['height'] = $items[2];
118 $row['weight'] = $items[3];
119 $row['bmi'] = $items[10];
120 $row['bmr'] = $items[11];
121 $row['impedance'] = $items[4];
122 $row['fat_pct'] = $items[5];
123 $row['fat_mass'] = $items[6];
124 $row['ffm'] = $items[7];
125 $row['tbw'] = $items[8];
129 <html>
130 <head>
131 <?php html_header_show();?>
132 <link rel=stylesheet href="<?php echo $css_header;?>" type="text/css">
133 <script language="JavaScript">
134 </script>
135 </head>
137 <body <?php echo $top_bg_line;?> topmargin="0" rightmargin="0" leftmargin="2" bottommargin="0" marginwidth="2" marginheight="0">
138 <form method="post" action="<?php echo $rootdir ?>/forms/body_composition/new.php?id=<?php echo $formid ?>"
139 onsubmit="return top.restoreSession()">
141 <center>
144 <table border='0' width='95%'>
146 <tr bgcolor='#dddddd'>
147 <td colspan='3' align='center'><b>Body Composition</b></td>
148 </tr>
150 <tr>
151 <td width='5%' nowrap>Body Type</td>
152 <td colspan='2' nowrap>
153 <?php echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type') ?>&nbsp;
154 <?php echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type') ?>&nbsp;
155 </td>
156 </tr>
158 <tr>
159 <td nowrap>Height in inches</td>
160 <td nowrap>
161 <input type='text' name='form_height' size='6'
162 value='<?php echo addslashes($row['height']) ?>' /> &nbsp;
163 </td>
164 <td nowrap>
165 &nbsp;
166 </td>
167 </tr>
169 <tr>
170 <td nowrap>Weight in pounds</td>
171 <td nowrap>
172 <input type='text' name='form_weight' size='6'
173 value='<?php echo addslashes($row['weight']) ?>' /> &nbsp;
174 </td>
175 <td align='center' nowrap>
176 <?php
177 if ($scale_file_age >= 0) {
178 echo "<font color='blue'>This reading was taken $scale_file_age minutes ago.</font>\n";
179 } else {
180 echo "&nbsp;\n";
183 </td>
184 </tr>
186 <tr>
187 <td nowrap>BMI</td>
188 <td nowrap>
189 <input type='text' name='form_bmi' size='6'
190 value='<?php echo addslashes($row['bmi']) ?>' /> &nbsp;
191 </td>
192 <td nowrap>
193 &nbsp;
194 </td>
195 </tr>
197 <tr>
198 <td nowrap>BMR in kj</td>
199 <td nowrap>
200 <input type='text' name='form_bmr' size='6'
201 value='<?php echo addslashes($row['bmr']) ?>' /> &nbsp;
202 </td>
203 <td nowrap>
204 &nbsp;
205 </td>
206 </tr>
208 <tr>
209 <td nowrap>Impedance in ohms</td>
210 <td nowrap>
211 <input type='text' name='form_impedance' size='6'
212 value='<?php echo addslashes($row['impedance']) ?>' /> &nbsp;
213 </td>
214 <td nowrap>
215 &nbsp;
216 </td>
217 </tr>
219 <tr>
220 <td nowrap>Fat %</td>
221 <td nowrap>
222 <input type='text' name='form_fat_pct' size='6'
223 value='<?php echo addslashes($row['fat_pct']) ?>' /> &nbsp;
224 </td>
225 <td nowrap>
226 &nbsp;
227 </td>
228 </tr>
230 <tr>
231 <td nowrap>Fat Mass in pounds</td>
232 <td nowrap>
233 <input type='text' name='form_fat_mass' size='6'
234 value='<?php echo addslashes($row['fat_mass']) ?>' /> &nbsp;
235 </td>
236 <td nowrap>
237 &nbsp;
238 </td>
239 </tr>
241 <tr>
242 <td nowrap>FFM in pounds</td>
243 <td nowrap>
244 <input type='text' name='form_ffm' size='6'
245 value='<?php echo addslashes($row['ffm']) ?>' /> &nbsp;
246 </td>
247 <td nowrap>
248 &nbsp;
249 </td>
250 </tr>
252 <tr>
253 <td nowrap>TBW in pounds</td>
254 <td nowrap>
255 <input type='text' name='form_tbw' size='6'
256 value='<?php echo addslashes($row['tbw']) ?>' /> &nbsp;
257 </td>
258 <td nowrap>
259 &nbsp;
260 </td>
261 </tr>
263 <tr>
264 <td nowrap>Notes</td>
265 <td colspan='2' nowrap>
266 <textarea name='form_other' rows='8' style='width:100%'><?php echo $row['other'] ?></textarea>
267 </td>
268 </tr>
270 </table>
273 <input type='submit' name='bn_save' value='Save' />
274 &nbsp;
275 <input type='button' value='Cancel' onclick="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url'] ?>'" />
276 </p>
278 </center>
280 </form>
281 </body>
282 </html>