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.
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';
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);
39 function rbvalue($rbname) {
40 $tmp = $_POST[$rbname];
41 if (! $tmp) return "NULL";
45 function rbinput($name, $value, $desc, $colname) {
47 $ret = "<input type='radio' name='$name' value='$value'";
48 if ($row[$colname] == $value) $ret .= " checked";
53 $formid = $_GET['id'];
55 // If Save was clicked, save the info.
57 if ($_POST['bn_save']) {
59 // If updating an existing form...
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'";
78 // If adding a new form...
81 $query = "INSERT INTO form_body_composition ( " .
82 "body_type, height, weight, bmi, bmr, impedance, fat_pct, " .
83 "fat_mass, ffm, tbw, other " .
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']) . "' " .
97 $newid = sqlInsert($query);
98 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
101 formHeader("Redirecting....");
108 $row = sqlQuery ("SELECT * FROM form_body_composition WHERE " .
109 "id = '$formid' AND activity = '1'") ;
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];
131 <?php
html_header_show();?
>
132 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
133 <script language
="JavaScript">
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()">
144 <table border
='0' width
='95%'>
146 <tr bgcolor
='#dddddd'>
147 <td colspan
='3' align
='center'><b
>Body Composition
</b
></td
>
151 <td width
='5%' nowrap
>Body Type
</td
>
152 <td colspan
='2' nowrap
>
153 <?php
echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type') ?
> 
;
154 <?php
echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type') ?
> 
;
159 <td nowrap
>Height in inches
</td
>
161 <input type
='text' name
='form_height' size
='6'
162 value
='<?php echo addslashes($row['height
']) ?>' />  
;
170 <td nowrap
>Weight in pounds
</td
>
172 <input type
='text' name
='form_weight' size
='6'
173 value
='<?php echo addslashes($row['weight
']) ?>' />  
;
175 <td align
='center' nowrap
>
177 if ($scale_file_age >= 0) {
178 echo "<font color='blue'>This reading was taken $scale_file_age minutes ago.</font>\n";
189 <input type
='text' name
='form_bmi' size
='6'
190 value
='<?php echo addslashes($row['bmi
']) ?>' />  
;
198 <td nowrap
>BMR in kj
</td
>
200 <input type
='text' name
='form_bmr' size
='6'
201 value
='<?php echo addslashes($row['bmr
']) ?>' />  
;
209 <td nowrap
>Impedance in ohms
</td
>
211 <input type
='text' name
='form_impedance' size
='6'
212 value
='<?php echo addslashes($row['impedance
']) ?>' />  
;
220 <td nowrap
>Fat %
</td
>
222 <input type
='text' name
='form_fat_pct' size
='6'
223 value
='<?php echo addslashes($row['fat_pct
']) ?>' />  
;
231 <td nowrap
>Fat Mass in pounds
</td
>
233 <input type
='text' name
='form_fat_mass' size
='6'
234 value
='<?php echo addslashes($row['fat_mass
']) ?>' />  
;
242 <td nowrap
>FFM in pounds
</td
>
244 <input type
='text' name
='form_ffm' size
='6'
245 value
='<?php echo addslashes($row['ffm
']) ?>' />  
;
253 <td nowrap
>TBW in pounds
</td
>
255 <input type
='text' name
='form_tbw' size
='6'
256 value
='<?php echo addslashes($row['tbw
']) ?>' />  
;
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
>
273 <input type
='submit' name
='bn_save' value
='Save' />
275 <input type
='button' value
='Cancel' onclick
="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url'] ?>'" />