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!");
33 // encode a string from a form field for database writing.
34 function form2db($fldval)
36 $fldval = trim($fldval);
37 $fldval = formDataCore($fldval);
41 function rbvalue($rbname)
43 $tmp = $_POST[$rbname];
51 function rbinput($name, $value, $desc, $colname)
54 $ret = "<input type='radio' name='$name' value='$value'";
55 if ($row[$colname] == $value) {
63 $formid = $_GET['id'];
65 // If Save was clicked, save the info.
67 if ($_POST['bn_save']) {
68 // If updating an existing form...
71 $query = "UPDATE form_body_composition SET " .
72 "body_type = " . rbvalue('form_body_type') . ", " .
73 "height = '" . form2db($_POST['form_height']) . "', " .
74 "weight = '" . form2db($_POST['form_weight']) . "', " .
75 "bmi = '" . form2db($_POST['form_bmi']) . "', " .
76 "bmr = '" . form2db($_POST['form_bmr']) . "', " .
77 "impedance = '" . form2db($_POST['form_impedance']) . "', " .
78 "fat_pct = '" . form2db($_POST['form_fat_pct']) . "', " .
79 "fat_mass = '" . form2db($_POST['form_fat_mass']) . "', " .
80 "ffm = '" . form2db($_POST['form_ffm']) . "', " .
81 "tbw = '" . form2db($_POST['form_tbw']) . "', " .
82 "other = '" . form2db($_POST['form_other']) . "' " .
83 "WHERE id = '$formid'";
85 } // If adding a new form...
88 $query = "INSERT INTO form_body_composition ( " .
89 "body_type, height, weight, bmi, bmr, impedance, fat_pct, " .
90 "fat_mass, ffm, tbw, other " .
92 rbvalue('form_body_type') . ", " .
93 "'" . form2db($_POST['form_height']) . "', " .
94 "'" . form2db($_POST['form_weight']) . "', " .
95 "'" . form2db($_POST['form_bmi']) . "', " .
96 "'" . form2db($_POST['form_bmr']) . "', " .
97 "'" . form2db($_POST['form_impedance']) . "', " .
98 "'" . form2db($_POST['form_fat_pct']) . "', " .
99 "'" . form2db($_POST['form_fat_mass']) . "', " .
100 "'" . form2db($_POST['form_ffm']) . "', " .
101 "'" . form2db($_POST['form_tbw']) . "', " .
102 "'" . form2db($_POST['form_other']) . "' " .
104 $newid = sqlInsert($query);
105 addForm($encounter, "Body Composition", $newid, "body_composition", $pid, $userauthorized);
108 formHeader("Redirecting....");
115 $row = sqlQuery("SELECT * FROM form_body_composition WHERE " .
116 "id = '$formid' AND activity = '1'") ;
118 // Get the most recent scale reading.
119 $items = explode(',', trim(file_get_contents($scale_file_name)));
120 if ($items && count($items) > 11) {
121 $scale_file_age = round((time() - filemtime($scale_file_name)) / 60);
122 $row['body_type'] = $items[0] ?
'Athletic' : 'Standard';
123 $row['height'] = $items[2];
124 $row['weight'] = $items[3];
125 $row['bmi'] = $items[10];
126 $row['bmr'] = $items[11];
127 $row['impedance'] = $items[4];
128 $row['fat_pct'] = $items[5];
129 $row['fat_mass'] = $items[6];
130 $row['ffm'] = $items[7];
131 $row['tbw'] = $items[8];
137 <?php
html_header_show();?
>
138 <link rel
=stylesheet href
="<?php echo $css_header;?>" type
="text/css">
139 <script language
="JavaScript">
143 <body
<?php
echo $top_bg_line;?
> topmargin
="0" rightmargin
="0" leftmargin
="2" bottommargin
="0" marginwidth
="2" marginheight
="0">
144 <form method
="post" action
="<?php echo $rootdir ?>/forms/body_composition/new.php?id=<?php echo $formid ?>"
145 onsubmit
="return top.restoreSession()">
150 <table border
='0' width
='95%'>
152 <tr bgcolor
='#dddddd'>
153 <td colspan
='3' align
='center'><b
>Body Composition
</b
></td
>
157 <td width
='5%' nowrap
>Body Type
</td
>
158 <td colspan
='2' nowrap
>
159 <?php
echo rbinput('form_body_type', 'Standard', 'Standard', 'body_type') ?
> 
;
160 <?php
echo rbinput('form_body_type', 'Athletic', 'Athletic', 'body_type') ?
> 
;
165 <td nowrap
>Height in inches
</td
>
167 <input type
='text' name
='form_height' size
='6'
168 value
='<?php echo addslashes($row['height
']) ?>' />  
;
176 <td nowrap
>Weight in pounds
</td
>
178 <input type
='text' name
='form_weight' size
='6'
179 value
='<?php echo addslashes($row['weight
']) ?>' />  
;
181 <td align
='center' nowrap
>
183 if ($scale_file_age >= 0) {
184 echo "<font color='blue'>This reading was taken $scale_file_age minutes ago.</font>\n";
195 <input type
='text' name
='form_bmi' size
='6'
196 value
='<?php echo addslashes($row['bmi
']) ?>' />  
;
204 <td nowrap
>BMR in kj
</td
>
206 <input type
='text' name
='form_bmr' size
='6'
207 value
='<?php echo addslashes($row['bmr
']) ?>' />  
;
215 <td nowrap
>Impedance in ohms
</td
>
217 <input type
='text' name
='form_impedance' size
='6'
218 value
='<?php echo addslashes($row['impedance
']) ?>' />  
;
226 <td nowrap
>Fat %
</td
>
228 <input type
='text' name
='form_fat_pct' size
='6'
229 value
='<?php echo addslashes($row['fat_pct
']) ?>' />  
;
237 <td nowrap
>Fat Mass in pounds
</td
>
239 <input type
='text' name
='form_fat_mass' size
='6'
240 value
='<?php echo addslashes($row['fat_mass
']) ?>' />  
;
248 <td nowrap
>FFM in pounds
</td
>
250 <input type
='text' name
='form_ffm' size
='6'
251 value
='<?php echo addslashes($row['ffm
']) ?>' />  
;
259 <td nowrap
>TBW in pounds
</td
>
261 <input type
='text' name
='form_tbw' size
='6'
262 value
='<?php echo addslashes($row['tbw
']) ?>' />  
;
270 <td nowrap
>Notes
</td
>
271 <td colspan
='2' nowrap
>
272 <textarea name
='form_other' rows
='8' style
='width:100%'><?php
echo $row['other'] ?
></textarea
>
279 <input type
='submit' name
='bn_save' value
='Save' />
281 <input type
='button' value
='Cancel' onclick
="top.restoreSession();location='<?php echo $GLOBALS['form_exit_url'] ?>'" />