DIR : /home/kozerus/public_html/ka/fb/med/med.php
/home/kozerus/public_html/ka/fb/med
<?php
$args=""; $todo=""; $tbl="";
$script_filename=$_SERVER['SCRIPT_FILENAME'];
$script_name=$_SERVER['SCRIPT_NAME'];
$ht=str_replace($script_name,"",$script_filename);
$db3fil="med.db3"; $ht_db3fil="$ht/ka/fb/med/$db3fil";
if( ! file_exists($ht_db3fil)) {
print( "BUGS_011 NOTFOUND ht_db3fil=$ht_db3fil<br>\n" );
exit;
}
if( isset($_REQUEST['todo'])) { $todo=$_REQUEST['todo']; }
if( isset($_REQUEST['tbl'])) { $tbl=$_REQUEST['tbl']; }
if( isset($_REQUEST['pid'])) { $tbl=$_REQUEST['pid']; }
$todo=""; if( isset( $_REQUEST['todo'])) { $todo=trim(htmlspecialchars($_REQUEST['todo'])); }
$db3=""; if( isset( $_REQUEST['db3'])) { $db3=trim(htmlspecialchars($_REQUEST['db3'])); }
$tbl=""; if( isset( $_REQUEST['tbl'])) { $tbl=trim(htmlspecialchars($_REQUEST['tbl'])); }
$fmt=""; if( isset( $_REQUEST['fmt'])) { $fmt=trim(htmlspecialchars($_REQUEST['fmt'])); }
if( $todo == "form" ) { form($tbl); exit(); }
if( $todo == "insert" ) {
insert($tbl);
// phpinfo();
exit();
}
if( $todo == "select" ) { select($tbl); exit(); }
if( isset($_REQUEST['exec'])) { $exec=$_REQUEST['exec'];
koexec($exec);
exit;
}
menu($args);
function menu($args) {
$htmout = "";
$htmout .= htmout_head($args);
$htmout .= htmout_menu($args);
# phpinfo();
$htmout .= htmout_tail($args);
print( $htmout );
return($args);
}
function select($args) {
if( $args == "" ) { $tbl="glucose"; } else { $tbl=$args; }
$script_filename=$_SERVER['SCRIPT_FILENAME'];
$script_name=$_SERVER['SCRIPT_NAME'];
$ht=str_replace($script_name,"",$script_filename);
$db3fil="med.db3";
$ht_db3fil="$ht/ka/fb/med/$db3fil";
if( ! file_exists($ht_db3fil)) {
print( "BUGS_050 NOTFOUND ht_db3fil=$ht_db3fil<br>\n" );
exit;
}
if( isset($_REQUEST['tbl'])) { $tbl=$_REQUEST['tbl']; }
$pid=""; if( isset($_REQUEST['pid'])) { $pid=$_REQUEST['pid']; }
$ht_txtfil = str_replace("$db3fil","$tbl.txt", $ht_db3fil );
$ht_psvfil = str_replace("$db3fil","$tbl.psv", $ht_db3fil );
$ht_csvfil = str_replace("$db3fil","$tbl.csv", $ht_db3fil );
$ht_jsonfil = str_replace("$db3fil","$tbl.json", $ht_db3fil );
$ht_htmlfil = str_replace("$db3fil","$tbl.html", $ht_db3fil );
# echo "<h3>ht_txtfil=$ht_txtfil</h3>\n";
# echo "<h3>ht_csvfil=$ht_csvfil</h3>\n";
# echo "<h3>ht_psvfil=$ht_psvfil</h3>\n";
# echo "<h3>ht_jsonfil=$ht_jsonfil</h3>\n";
# echo "<h3>ht_htmlfil=$ht_htmlfil</h3>\n";
$psv=""; $csv=""; $txt=""; $json=""; $htmout="";
$tbl="glucose";
if( isset( $_REQUEST['tbl'] )) {
$tbl=$_REQUEST['tbl'];
}
if( $tbl == "bps" ) {
$fldstext="rowid pid dt tm right left bm glucose notes";
}
if( $tbl == "doctors" ) {
$fldstext="rowid pdf name specialty phone office address url pid notes";
}
if( $tbl == "meds" ) {
$fldstext="rowid img name qty size directions doctor refills cost desc url pid notes";
}
if( $tbl == "glucose" ) {
$fldstext="rowid pid dt tm glucose notes";
}
$flds = explode( " ", $fldstext );
$fldcnt = count($flds);
$pdo = newpdo($db3fil);
$sql = "select rowid,* from $tbl";
if( $tbl == "bps" ) {
$sql = "select rowid,* from $tbl order by pid, dt desc, tm desc";
}
if( $tbl == "glucose" ) {
$sql = "select rowid,* from $tbl order by pid, dt desc, tm desc";
}
$htmout = ""; $json= ""; $psv=""; $csv=""; $txt="";
# $json .= '{ "tbl": [';
$json="{ \"$tbl\": [\n";
# $htmout .= "<a href=med.php?menu ><img src=/imgs/btn/ko.png height=25 border=0></a><br>\n";
# $htmout .= htmout_head('');
$htmout .= "<hr color=goldenrod>\n";
$htmout .= "<h2>$tbl</h2>\n";
$htmout .= "<table id=table_$tbl>\n";
$htmout .= "<tr>";
$last_dt="";
foreach( $flds as $fld ) {
if( $fld == "dt" ) {
# echo "<h3>BUGS_200 fld=$fld last_dt=$last_dt</h3>";
if( $last_dt == $fld ) {
# echo "<h3>BUGS_201 fld=$fld last_dt=$last_dt</h3>";
$htmout .= "<td width=100px><b> ... </b></td>";
}
else {
# echo "<h3>BUGS_202 fld=$fld last_dt=$last_dt</h3>";
$htmout .= "<td width=100px><b>$fld</b></td>";
}
$last_dt=$fld;
}
else {
if( $fld == "tm" ) {
$htmout .= "<td width=75px><b>$fld</b></td>";
}
else {
$htmout .= "<td >$fld</td>";
}
}
$psv .= "$fld|";
$csv .= "$fld,";
$txt .= "$fld ";
}
$htmout .= "</tr>\n";
$j=0; $k=0;
foreach( $pdo->query($sql) as $row ) {
$htmout .= "<tr>";
$json_record = "{";
# echo "<h2>BUGS_150 j=$j k=$k json_record=$json_record</h2>\n";
$j=$j+1; $k=0;
foreach( $flds as $fld ) {
$k=$k+1;
$val=$row[$fld];
if( $fld == "dt" ) {
if( $last_dt == $val ) {
$htmout .= "<td width=100px><b> ... </b></td>";
}
else {
$htmout .= "<td width=100px><b>$val</b></td>";
}
$last_dt=$val;
}
else {
if( $fld == "tm" ) {
$htmout .= "<td width=75px><b>$val</b></td>";
}
else {
if( $fld == "right" ) {
$htmout .= "<td ><b>$val</b></td>";
}
else {
$htmout .= "<td >$val</td>";
}
}
}
$psv .= "$val|";
$csv .= "$val,";
$txt .= "$val ";
$json_record .= "\"".$fld."\":\"".$val."\",";
# echo "<h2>BUGS_151 j=$j k=$k json_record=$json_record</h2>\n";
}
# echo "<h2>BUGS_152 j=$j k=$k json_record=$json_record</h2>\n";
$json_kludge = str_replace_last( ",", "" , $json_record );
# echo "<h2>BUGS_153 j=$j k=$k json_kludge=$json_kludge</h2>\n";
$json_kludge .= "},\n";
# echo "<h2>BUGS_154 j=$j k=$k json_kludge=$json_kludge</h2>\n";
$json .= $json_kludge;
$psv .= "\n";
$csv .= "\n";
$txt .= "\n";
$htmout .= "</tr>";
}
$htmout .= "</table id=table_$tbl\_end>\n";
# echo "<h2>BUGS_155 j=$j k=$k json_record=$json_record</h2>\n";
$json_kludge = str_replace_last( ",", "" , $json );
$json_kludge .= "]}";
$json=$json_kludge;
# $matches="";
# $json = preg_replace( "/,}$/", "}", $matches );
# $json .= str_replace_last( ",", "" , $json );
# $json = preg_replace( "/,}$/", "}", $matches );
# $sql = preg_replace( "/,\)$/", ")", $matches );
# $psv = preg_replace( "/|$/", "", $matches );
# $csv = preg_replace( "/,$/", "", $matches );
# $fp=fopen($ht_csvfil,"w"); fwrite($fp,$csv); fclose($fp);
file_put_contents($ht_csvfil,$csv);
file_put_contents($ht_txtfil,$txt);
file_put_contents($ht_jsonfil,$json);
file_put_contents($ht_htmlfil,$htmout);
# echo "<h3>ht_csvfil=$ht_csvfil csv=$csv</h3>\n";
# echo "<h3>ht_txtfil=$ht_txtfil txt=$txt</h3>\n";
# echo "<h3>ht_jsonfil=$ht_jsonfil json=$json</h3>\n";
# echo "<h3>ht_htmlfil=$ht_htmlfil html=$html</h3>\n";
$fmt="html";
if( isset( $_REQUEST['fmt'] )) { $fmt=$_REQUEST['fmt']; }
# echo "<h2>BUGS_120 fmt=$fmt</h2>\n";
# echo "<h2>BUGS_121 psv=$psv</h2>\n";
# echo "<h2>BUGS_122 csv=$csv</h2>\n";
# echo "<h2>BUGS_123 txt=$txt</h2>\n";
# echo "<h2>BUGS_124 htmout=$htmout</h2>\n";
# echo "<h2>BUGS_125 json=$json</h2>\n";
$htmout_body = $htmout;
$htmout = "";
# $htmout .= htmout_head('');
if( $pid == "" ) {
$htmout .= table_stats($db3fil,$tbl,"jk");
$htmout .= table_stats($db3fil,$tbl,"sk");
}
else {
$htmout .= table_stats($db3fil,$tbl,$pid);
}
$htmout .= $htmout_body;
$htmout_body = $htmout;
$htmout = "";
$htmout .= htmout_head('');
$htmout .= $htmout_body;
if( $fmt == "psv" ) { echo "$psv"; exit; }
if( $fmt == "csv" ) {
header('Content-type: text/csv');
echo "$csv"; exit();
}
if( $fmt == "txt" ) {
header('Content-type: text/plain');
echo "$txt"; exit();
}
if( $fmt == "json" ) {
header('Content-type: application/json');
echo "$json"; exit();
}
if( $fmt == "html" ) { echo "$htmout"; exit(); }
if( $fmt == "htm" ) { echo "$htmout"; exit(); }
echo "$htmout";
exit();
// return($htmout);
}
function table_stats($db3fil, $tbl, $pid) {
$script_filename=$_SERVER['SCRIPT_FILENAME'];
$script_name=$_SERVER['SCRIPT_NAME'];
$ht=str_replace($script_name,"",$script_filename);
$ht_db3fil="$ht/ka/fb/med/$db3fil";
if( ! file_exists($ht_db3fil)) {
print( "BUGS_050 NOTFOUND ht_db3fil=$ht_db3fil<br>\n" );
exit;
}
if( isset($_REQUEST['tbl'])) { $tbl=$_REQUEST['tbl']; }
if( isset($_REQUEST['pid'])) { $pid=$_REQUEST['pid']; }
if( $tbl == "bps" ) {
$fldstext="rowid pid dt tm right left bm glucose notes";
$systolic=0; $diastolic=0; $pulse=0;
$systolic_cnt=0; $diastolic_cnt=0; $pulse_cnt=0;
$systolic_tot=0; $diastolic_tot=0; $pulse_tot=0;
$systolic_min=0; $diastolic_min=0; $pulse_min=0;
$systolic_max=0; $diastolic_max=0; $pulse_max=0;
$systolic_avg=0; $diastolic_avg=0; $pulse_avg=0;
$systolic_longavg=0; $diastolic_longavg=0; $pulse_longavg=0;
}
if( $tbl == "glucose" ) {
$fldstext="rowid pid dt tm glucose notes";
$glucose = 0; $glucose_tot = 0; $glucose_cnt = 0;
$glucose_avg = 0; $glucose_min = 0; $glucose_max = 0;
$glucose_longavg=0;
}
$pdo = newpdo($db3fil);
$sql = "select rowid,* from $tbl";
if( $tbl == "bps" ) {
$flds = explode(" ","rowid pid dt tm left right bm glucose notes");
$sql = "select rowid,* from $tbl where pid='$pid' order by pid, dt desc, tm desc";
}
if( $tbl == "glucose" ) {
$flds = explode(" ","rowid pid dt tm glucose notes");
$sql = "select rowid,* from $tbl where pid='$pid' order by pid, dt desc, tm desc";
}
$j=0; $k=0; $htmout="";
foreach( $pdo->query($sql) as $row ) {
$htmout .= "<tr>";
# echo "<h2>BUGS_150 j=$j k=$k json_record=$json_record</h2>\n";
$j=$j+1; $k=0;
foreach( $flds as $fld ) {
$k=$k+1;
$val=$row[$fld];
if( $tbl == "glucose" ) {
if( $fld == "glucose" ) {
if( $val != "" ) {
$glucose=(int)$val;
if( $glucose_min == 0 ) { $glucose_min = $glucose; }
$glucose_cnt = $glucose_cnt + 1;
$glucose_tot = $glucose_tot + $glucose;
if( $glucose < $glucose_min ) { $glucose_min = $glucose; }
if( $glucose > $glucose_max ) { $glucose_max = $glucose; }
# echo "<h3>BUGS_330 $j,$k fld=$fld val=$val glucose=$glucose $glucose_min,$glucose_max,$glucose_tot, $glucose_cnt</h3>\n";
}
}
}
if( $tbl == "bps" ) {
if(( $fld == "right" ) || ( $fld == "left" )) {
if(( $val != "" ) & ( $val != $fld )) {
$systolic=explode("/",$val)[0];
$diastolic_pulse=explode("/",$val)[1];
$diastolic=explode("-",$diastolic_pulse)[0];
$pulse=0;
if( count(explode("-",$diastolic_pulse)) > 1 ) {
$pulse=explode("-",$diastolic_pulse)[1];
}
if( is_numeric($systolic)) {
$systolic_cnt = $systolic_cnt+1;
$systolic_tot = $systolic_tot + $systolic;
if( $systolic_min == 0 ) { $systolic_min=$systolic; }
if( $systolic < $systolic_min ) { $systolic_min = $systolic; }
if( $systolic > $systolic_max ) { $systolic_max = $systolic; }
}
if( is_numeric($diastolic)) {
$diastolic_cnt = $diastolic_cnt+1;
$diastolic_tot = $diastolic_tot+$diastolic;
if( $diastolic_min == 0 ) { $diastolic_min=$diastolic; }
if( $diastolic < $diastolic_min ) { $diastolic_min = $diastolic; }
if( $diastolic > $diastolic_max ) { $diastolic_max = $diastolic; }
}
if( is_numeric($pulse)) {
$pulse_cnt = $pulse_cnt+1;
$pulse_tot = $pulse_tot+$pulse;
if( $pulse_min == 0 ) { $pulse_min=$pulse; }
if( $pulse < $pulse_min ) { $pulse_min = $pulse; }
if( $pulse > $pulse_max ) { $pulse_max = $pulse; }
}
# echo "<h3>BUGS_330 $j,$k fld=$fld val=$val $systolic,$diastolic,$pulse min=$systolic_min,$diastolic_min,$pulse_min max=$systolic_max,$diastolic_max,$pulse_max</h3>";
}
}
}
}
}
if( $tbl == "bps" ) {
$systolic_longavg = $systolic_tot / $systolic_cnt;
$diastolic_longavg = $diastolic_tot / $diastolic_cnt;
$pulse_longavg = $pulse_tot / $pulse_cnt;
# $systolic_avg = sprintf( '%0.2f',$systolic_longavg );
# $diastolic_avg = sprintf( '%0.2f',$diastolic_longavg );
# $pulse_avg = sprintf( '%0.2f',$pulse_longavg );
$systolic_avg = sprintf( '%0.0f',$systolic_longavg );
$diastolic_avg = sprintf( '%0.0f',$diastolic_longavg );
$pulse_avg = sprintf( '%0.0f',$pulse_longavg );
# echo "<h3>BUGS_311 systolic_avg=$systolic_avg $systolic_tot,$systolic_cnt</h3>\n";
# echo "<h3>BUGS_312 diastolic_avg=$diastolic_avg $diastolic_tot,$diastolic_cnt</h3>\n";
# echo "<h3>BUGS_313 pulse_avg=$pulse_avg $pulse_tot,$pulse_cnt</h3>\n";
$htmout_stats = "";
$htmout_stats .= "<br>\n";
$htmout_stats .= "<hr color=goldenrod>\n";
$htmout_stats .= "<table id=$tbl"."_$pid"."_stats>\n";
$htmout_stats .= "<tr><td width=100px> $pid </td><td> </td><td> </td><td> </td></tr>";
$htmout_stats .= "<tr>";
$htmout_stats .= "<td width=100px> bps </td>";
$htmout_stats .= "<td width=50px>systolic</td>";
$htmout_stats .= "<td> / </td>";
$htmout_stats .= "<td width=50px>diastolic</td>";
$htmout_stats .= "<td> - </td>";
$htmout_stats .= "<td width=50px>pulse</td>";
$htmout_stats .= "</tr>\n";
$htmout_stats .= "<tr>";
$htmout_stats .= "<td width=200px>avg</td>";
$htmout_stats .= "<td width=100px><b>$systolic_avg</b></td>";
$htmout_stats .= "<td> / </td>";
$htmout_stats .= "<td width=100px><b>$diastolic_avg</b></td>";
$htmout_stats .= "<td> - </td>";
$htmout_stats .= "<td width=100px><b>$pulse_avg</b></td>";
$htmout_stats .= "</tr>\n";
$htmout_stats .= "<tr>";
$htmout_stats .= "<td width=200px>min</td>";
$htmout_stats .= "<td width=100px>$systolic_min</td>";
$htmout_stats .= "<td> / </td>";
$htmout_stats .= "<td width=100px>$diastolic_min</td>";
$htmout_stats .= "<td> - </td>";
$htmout_stats .= "<td width=100px>$pulse_min</td>";
$htmout_stats .= "</tr>\n";
$htmout_stats .= "<tr>";
$htmout_stats .= "<td width=200px>max</td>";
$htmout_stats .= "<td width=100px>$systolic_max</td>";
$htmout_stats .= "<td> / </td>";
$htmout_stats .= "<td width=100px>$diastolic_max</td>";
$htmout_stats .= "<td> - </td>";
$htmout_stats .= "<td width=100px>$pulse_max</td>";
$htmout_stats .= "</tr>\n";
$htmout_stats .= "</table id=table_$tbl"."_$pid"."_stats_end>\n";
$htmout_stats .= "<hr color=goldenrod>\n";
# echo "<h3>$j,$k fld=$fld val=$val $systolic,$diastolic,$pulse min=$systolic_min,$diastolic_min,$pulse_min max=$systolic_max,$diastolic_max,$pulse_max</h3>";
}
if( $tbl == "glucose" ) {
$glucose_lognavg=0;
if( $glucose_cnt > 0 ) {
$glucose_longavg = $glucose_tot / $glucose_cnt;
}
$glucose_avg = sprintf( '%0.0f', $glucose_longavg );
$htmout_stats = "";
$htmout_stats .= "<br>\n";
$htmout_stats .= "<hr color=goldenrod>\n";
$htmout_stats .= "<table id=table_$tbl"."_$pid"."_stats>\n";
$htmout_stats .= "<tr><td width=100>$pid</td><td> </td><td> </td><tr>";
$htmout_stats .= "<tr>";
$htmout_stats .= "<td width=100>avg</td>";
$htmout_stats .= "<td width=100>min</td>";
$htmout_stats .= "<td width=100>max</td>";
$htmout_stats .= "</tr>\n";
$htmout_stats .= "<tr>";
$htmout_stats .= "<td width=100>$glucose_avg</td>";
$htmout_stats .= "<td width=100>$glucose_min</td>";
$htmout_stats .= "<td width=100>$glucose_max</td>";
$htmout_stats .= "</tr>\n";
$htmout_stats .= "</table id=table_$tbl"."_$pid"."_stats_end>\n";
$htmout_stats .= "<hr color=goldenrod>\n";
$htmout_stats .= "<br>\n";
}
return($htmout_stats);
}
function form($args) {
# if( $args == "" ) { $tbl = $args; }
$tbl="glucose";
if( isset( $_REQUEST['tbl'] )) { $tbl=$_REQUEST['tbl']; }
if( $tbl == "bps" ) {
# $fldstext="dt tm left right bm glucose notes db3 tbl sel fld val fmt lim";
# $fldstext="dt tm right left bm glucose notes";
$fldstext="pid dt tm right left bm glucose notes";
}
if( $tbl == "doctors" ) {
# $fldstext="pdf name specialty phone office address url notes db3 tbl sel fld val fmt lim";
# $fldstext="pdf name specialty phone office address url notes";
$fldstext="pdf name specialty phone office address url desc pid notes";
}
if( $tbl == "meds" ) {
# $fldstext="img name qty size directions doctor refills cost desc url notes db3 tbl sel fld val fmt lim";
# $fldstext="img name qty size directions doctor refills cost desc url notes";
$fldstext="img name qty size directions doctor refills cost desc url pid notes";
}
if( $tbl == "glucose" ) {
# $fldstext="dt tm glucose notes db3 tbl sel fld val fmt lim";
# $fldstext="dt tm glucose notes";
$fldstext="pid dt tm glucose notes";
}
$flds = explode( " ", $fldstext );
$fldcnt = count($flds);
$htmout="";
$htmout .= htmout_head('');
$htmout .= "<form id=form_$tbl method=\"post\" action=\"med.php?todo=insert&tbl=$tbl\">\n";
$htmout .= "<table id=table_$tbl>\n";
$htmout .= "<tr><td width=100px> </td><td width=300px><b>$tbl</b></td><tr>\n";
$htmout .= "<tr><td width=100px ><b>fld</b></td><td width=300px><b>val</b></td></tr>\n";
for ( $j=0; $j<$fldcnt; $j++ ) {
$fld=$flds[$j];
$val="";
if(( $fld == "dt" ) || ( $fld == "date" )) {
$val=date('Y-m-d');
}
if(( $fld == "tm" ) || ( $fld == "time" )) {
$val=date('Hi');
}
if( $fld == "pid" ) { $val="jk"; }
$htmout .= "<tr><td>";
$htmout .= "<label for=\"$fld\">$fld:</label>";
$htmout .= "</td><td>";
$htmout .= "<input type=\"text\" id=\"$fld\" name=\"$fld\" value=\"$val\" >";
$htmout .= "</td></tr>\n";
}
$htmout .= "<tr><td> </td><td>";
$htmout .= "<input type=\"submit\" id=\"submit\" name=\"submit\" value=\"submit\" >\n";
$htmout .= "</td></tr>\n";
$htmout .= "<tr><td> </td><td>";
$htmout .= "<input type=\"reset\" id=\"reset\" name=\"reset\" value=\"reset\" >\n";
$htmout .= "</td/</tr>\n";
$htmout .= " </table id=table_$tbl\_end>\n";
$htmout .= " </form id=form_$tbl\_end>\n";
$htmout .= "<hr color=goldenrod>\n";
$htmout .= htmout_tail('');
echo $htmout;
exit;
$htmout = "";
if ( $tbl == "bps" ) {
$htmout .= "<form id=form_$tbl >\n";
$vals = "'$dt','$tm','$right','$left','$bm','$glucose','$notes'";
$htmout .= " </form id=form_$tbl\_end>\n";
$fids="pid dt tm right left bm glucose notes db3 tbl sel fld val fmt lim";
}
if ( $tbl == "doctors" ) {
$htmout .= "<form id=form_$tbl >\n";
# $vals = "'$pdf','$name','$specialty','$phone','$office','$address','$url','$notes'";
$vals = "'$pdf','$name','$specialty','$phone','$office','$address','$url','$desc','$pid','$notes'";
$htmout .= " </form id=form_$tbl\_end>\n";
# $fids="pdf name specialty phone office address url notes db3 tbl sel fld val fmt lim";
$fids="pdf name specialty phone office address url desc pid notes";
}
if ( $tbl == "meds" ) {
$htmout .= "<form id=form_$tbl >\n";
# $vals = "'$img','$name','$qty','$size','$directions','$doctor','$refills','$cost','$desc','$url','$notes'";
$vals = "'$img','$name','$qty','$size','$directions','$doctor','$refills','$cost','$desc','$url','pid','$notes'";
$htmout .= " </form id=form_$tbl\_end>\n";
# $fids="img name qty size directions doctor refills cost desc url notes db3 tbl sel fld val fmt lim";
$fids="img name qty size directions doctor refills cost desc url pid notes";
}
if ( $tbl == "glucose" ) {
$htmout .= "<form id=form_$tbl >\n";
$vals = "'$pid','$dt','$tm','$glucose','$notes'\n";
$htmout .= " </form id=form_$tbl\_end>\n";
# $fids="dt tm glucose notes db3 tbl sel fld val fmt lim";
$fids="pid dt tm glucose notes";
}
$htmout = "";
$htmout .= "<div id=div_med_form_$tbl>\n";
$htmout .= "<h1>div_med_form_$tbl</h1>\n";
$htmout .= '<form id=form_med_form_$tbl method=\"POST\" action="./med.php?todo=insert&tbl=$tbl">\n';
$htmout .= ' <input onkeydown="ko_onkeydown(event)" ><br>\n';
$htmout .= " </input>\n";
$fidarry = explode( " ", $fids );
foreach( $fidarry as $fid ) {
$htmout .= ' <div id=div_form_$fid> <label for="$fid">$fid: </label> <input id="$fid" type="text"> </div>\n';
}
$htmout .= ' <div id=div_form_date> <label for="date">date: </label> <input id="date" type="date"> </div>\n';
$htmout .= ' <div id=div_form_time> <label for="time">time: </label> <input id="time" type="time"> </div>\n';
$htmout .= ' <div id=div_form_color> <label for="color">color: </label> <input id="color" type="color"> </div>\n';
$htmout .= ' <div id=div_form_textarea> <label for="textarea">textarea: </label> <textarea name="comment" id="comment" type="textarea"></textarea> </div>\n';
$htmout .= ' <div id=div_form_radio> <label for="radio">radio: </label><br>\n';
$htmout .= ' <input id="radio" name="gender" value="m" type="radio">m<br>\n';
$htmout .= ' <input id="radio" name="gender" value="f" type="radio">f<br>\n';
$htmout .= ' </div>\n';
$htmout .= ' <div id=div_form_submit> <label for="submit">submit: </label> <input id="submit" type="submit"> </div>\n';
$htmout .= ' <div id=div_form_cancel> <label for="cancel">cancel: </label> <input id="cancel" type="cancel"> </div>\n';
$htmout .= " </form id=form_med_form_$tbl\_end>\n";
$htmout .= " </div id=div_med_form_$tbl\_end>\n";
print( "$htmout" );
exit;
return(args);
}
function insert($args) {
# phpinfo();
$script_filename=$_SERVER['SCRIPT_FILENAME'];
$script_name=$_SERVER['SCRIPT_NAME'];
$ht=str_replace($script_name,"",$script_filename);
$db3fil="med.db3"; $ht_db3fil="$ht/ka/fb/med/$db3fil";
if( ! file_exists($ht_db3fil)) {
print( "BUGS_011 NOTFOUND ht_db3fil=$ht_db3fil<br>\n" );
exit;
}
if( isset($_REQUEST['tbl'] )) { $tbl=$_REQUEST['tbl']; }
if ( $tbl == "bps" ) {
$pid=""; if( isset($_REQUEST['pid'] )) { $dt = $_REQUEST['pid']; }
$dt=""; if( isset($_REQUEST['dt'] )) { $dt = $_REQUEST['dt']; }
$tm=""; if( isset($_REQUEST['tm'] )) { $tm = $_REQUEST['tm']; }
$left=""; if( isset($_REQUEST['left'] )) { $left = $_REQUEST['left']; }
$right=""; if( isset($_REQUEST['right'] )) { $right = $_REQUEST['right']; }
$bm=""; if( isset($_REQUEST['bm'] )) { $bm = $_REQUEST['bm']; }
$glucose=""; if( isset($_REQUEST['glucose'] )) { $glucose = $_REQUEST['glucose']; }
$notes=""; if( isset($_REQUEST['notes'] )) { $notes = $_REQUEST['notes']; }
$flds = "dt,tm,right,left,bm,glucose,notes";
$vals = "'$dt','$tm','$right','$left','$bm','$glucose','$notes'";
}
if ( $tbl == "doctors" ) {
$pdf=""; if( isset($_REQUEST['pdf'] )) { $pdf = $_REQUEST['pdf']; }
$name=""; if( isset($_REQUEST['name'] )) { $name = $_REQUEST['name']; }
$specialty=""; if( isset($_REQUEST['specialty'] )) { $specialty = $_REQUEST['specialty']; }
$phone=""; if( isset($_REQUEST['phone']) ) { $phone = $_REQUEST['phone']; }
$office=""; if( isset($_REQUEST['office'] )) { $office = $_REQUEST['office']; }
$address=""; if( isset($_REQUEST['address'] )) { $address = $_REQUEST['address']; }
$url=""; if( isset($_REQUEST['url'] )) { $url = $_REQUEST['url']; }
$desc=""; if( isset($_REQUEST['desc'] )) { $desc = $_REQUEST['desc']; }
$pid=""; if( isset($_REQUEST['pid'] )) { $pid = $_REQUEST['pid']; }
$notes=""; if( isset($_REQUEST['notes'] )) { $notes = $_REQUEST['notes']; }
$flds = "pdf,name,specialty,phone,office,address,url,desc, pid, notes";
$vals = "'$pdf','$name','$specialty','$phone','$office','$address','$url','$desc','$pid','$notes'";
}
if ( $tbl == "meds" ) {
$img=""; if( isset($_REQUEST['img'] )) { $img = $_REQUEST['img']; }
$name=""; if( isset($_REQUEST['name'] )) { $name = $_REQUEST['name']; }
$qty=""; if( isset($_REQUEST['qty'] )) { $qty = $_REQUEST['qty']; }
$size=""; if( isset($_REQUEST['size'] )) { $size = $_REQUEST['size']; }
$directions=""; if( isset($_REQUEST['directions'] )) { $directions = $_REQUEST['directions']; }
$refills=""; if( isset($_REQUEST['refills'] )) { $refills = $_REQUEST['refills']; }
$cost=""; if( isset($_REQUEST['cost'] )) { $cost = $_REQUEST['cost']; }
$desc=""; if( isset($_REQUEST['desc'] )) { $desc = $_REQUEST['desc']; }
$url=""; if( isset($_REQUEST['url'] )) { $url = $_REQUEST['url']; }
$pid=""; if( isset($_REQUEST['pid'] )) { $pid = $_REQUEST['pid']; }
$notes=""; if( isset($_REQUEST['notes'] )) { $notes = $_REQUEST['notes']; }
$flds = "img,name,qty,size,directions,doctor,refills,cost,desc,url,pid,notes";
$vals = "'$img','$name','$qty','$size','$directions','$doctor','$refills','$cost','$desc','$url','$pid','$notes'";
}
if ( $tbl == "glucose" ) {
$pid=""; if( isset($_REQUEST['pid'] )) { $pid = $_REQUEST['pid']; }
$dt=""; if( isset($_REQUEST['dt'] )) { $dt = $_REQUEST['dt']; }
$tm=""; if( isset($_REQUEST['tm'] )) { $tm = $_REQUEST['tm']; }
$glucose=""; if( isset($_REQUEST['glucose'] )) { $glucose = $_REQUEST['glucose']; }
$notes=""; if( isset($_REQUEST['notes'] )) { $notes = $_REQUEST['notes']; }
$flds = "pid dt,tm,glucose,notes\n";
$vals = "'$pid','$dt','$tm','$glucose','$notes'\n";
}
$sql_insert="insert or replace into $tbl ( $flds ) values ( $vals );\n";
$dttm=date('Y-m-d_H:i:s');
print( "<h3>BUGS_350 dttm=$dttm db3fil=$db3fil sql_insert=$sql_insert</h1>" );
db3_connect($db3fil );
db3_exec( $db3fil, $sql_insert );
$status=db32psv($db3fil,$tbl);
# echo "<h3>BUGS_351 db32psv status=$status</h3>";
$htmout="";
$htmout .= htmout_head('');
$htmout .= "<br>\n";
$htmout .= "<hr color=goldenrod>";
$htmout .= "<br>\n";
$htmout .= "<a href=med.php?todo=form&tbl=$tbl>form $tbl</a><br>\n";
$htmout .= "<br>\n";
$htmout .= "<hr color=goldenrod>";
$htmout .= "<br>\n";
$htmout .= "<a href=med.php?todo=select&tbl=$tbl>select $tbl</a><br>\n";
$htmout .= "<br>\n";
$htmout .= "<hr color=goldenrod>";
$htmout .= "<br>\n";
$htmout .= htmout_tail('');
echo "$htmout";
exit;
# return($sql_insert);
}
function db32psv($db3fil,$tbl) {
# echo "<h1>BUGS_370 db32psv db3fil=$db3fil tbl=$tbl</h1>\n";
if( $tbl == "" ) { echo "<h1>BUGS_371 NULL tbl=$tbl</h1>\n"; return('NULLTBL'); }
$script_filename=$_SERVER['SCRIPT_FILENAME'];
$script_name=$_SERVER['SCRIPT_NAME'];
$ht=str_replace($script_name,"",$script_filename);
$db3fil="med.db3"; $ht_db3fil="$ht/ka/fb/med/$db3fil";
$dttm=date("Ymd_Hi");
$dt=date("Ymd");
$ht_psvfil="$ht/ka/fb/med/$tbl.psv";
$ht_csvfil="$ht/ka/fb/med/$tbl.csv";
$ht_txtfil="$ht/ka/fb/med/$tbl.txt";
$ht_jsonfil="$ht/ka/fb/med/$tbl.json";
$ht_psvfil_dttm="$ht/ka/fb/med/$tbl"."_$dttm.psv";
$ht_psvfil_dt="$ht/ka/fb/med/$tbl"."_$dt.psv";
if( ! file_exists($ht_db3fil)) {
print( "BUGS_011 NOTFOUND ht_db3fil=$ht_db3fil<br>\n" );
return("NOTFOUND_ht_db3fil=".$ht_db3fil);
}
if( file_exists($ht_psvfil)) {
# echo "mv $ht_psvfil $ht_psvfil_dt<br>\n";
# echo "ls -lat $ht_psvfil_dt<br>\n";
# echo "<h1>BUGS_371 ___FOUND RENAME ht_psvfil=$ht_psvfil ht_psvfil_dttm=$ht_psvfil_dt</h1>\n";
rename($ht_psvfil, $ht_psvfil_dttm);
}
else {
echo "<h1>BUGS_372 NOTFOUND RENAME ht_psvfil=$ht_psvfil ht_psvfil_dttm=$ht_psvfil_dttm</h1>\n";
}
if( $tbl == "bps" ) {
$syscmd="sqlite3 $ht_db3fil -header \"select * from $tbl order by pid, dt desc, tm desc\" > $ht_psvfil";
}
if( $tbl == "glucose" ) {
$syscmd="sqlite3 $ht_db3fil -header \"select * from $tbl order by pid, dt desc, tm desc\" > $ht_psvfil";
}
if( $tbl == "doctors" ) {
$syscmd="sqlite3 $ht_db3fil -header \"select * from $tbl order by pid\" > $ht_psvfil";
}
if( $tbl == "meds" ) {
$syscmd="sqlite3 $ht_db3fil -header \"select * from $tbl order by pid\" > $ht_psvfil";
}
# echo "<h1>BUGS_372 syscmd=$syscmd</h1>\n";
shell_exec($syscmd);
return($ht_psvfil);
}
function htmout_head($args) {
$htmout = "";
$htmout .= "<html>\n";
$htmout .= "<head><title>/ka/fb/med.php</title>\n";
$htmout .= " </head>\n";
$htmout .= "<body bgcolor=linen>\n";
$htmout .= "<hr color=goldenrod>\n";
$htmout .= "<a href=med.php?menu ><img src=/imgs/btn/ko.png height=25 border=0></a><br>\n";
$htmout .= "<hr color=goldenrod>\n";
$htmout .= "<br>\n";
return($htmout);
}
function htmout_menu($args) {
$php_self=$_SERVER['PHP_SELF'];
$basename=basename($php_self);
$htmout = "";
# $htmout .= "<hr color=goldenrod>\n";
# $htmout .= "<h1>inserts</h1>\n";
# $htmout .= "<a href=./$basename?todo=insert&tbl=bps >insert_bps</a><br>\n";
# $htmout .= "<a href=./$basename?todo=insert&tbl=doctors >insert_doctors</a><br>\n";
# $htmout .= "<a href=./$basename?todo=insert&tbl=meds >insert_meds</a><br>\n";
# $htmout .= "<a href=./$basename?todo=insert&tbl=glucose >insert_glucose</a><br>\n";
# $htmout .= "<hr color=goldenrod>\n";
$htmout .= "<hr color=goldenrod>\n";
$htmout .= "<h1>select</h1>\n";
$htmout .= "<table id_selects>\n";
# $htmout .= "<tr><td>html</td><td>csv</td><td>json</td><tr>\n";
$htmout .= "<tr><td>html</td><tr>\n";
$htmout .= "<tr>";
$htmout .= "<td>";
$htmout .= "<a href=./$basename?todo=select&tbl=bps >select_bps</a><br>\n";
$htmout .= "<a href=./$basename?todo=select&tbl=doctors >select_doctors</a><br>\n";
$htmout .= "<a href=./$basename?todo=select&tbl=meds >select_meds</a><br>\n";
$htmout .= "<a href=./$basename?todo=select&tbl=glucose >select_glucose</a><br>\n";
$htmout .= "</td>";
# $htmout .= "<td>";
# $htmout .= "<a href=./$basename?todo=select&tbl=bps&fmt=csv >select_bps</a><br>\n";
# $htmout .= "<a href=./$basename?todo=select&tbl=doctors&fmt=csv >select_doctors</a><br>\n";
# $htmout .= "<a href=./$basename?todo=select&tbl=meds&fmt=csv >select_meds</a><br>\n";
# $htmout .= "<a href=./$basename?todo=select&tbl=glucose&fmt=csv >select_glucose</a><br>\n";
# $htmout .= "</td>";
# $htmout .= "<td>";
# $htmout .= "<a href=./$basename?todo=select&tbl=bps&fmt=json >select_bps</a><br>\n";
# $htmout .= "<a href=./$basename?todo=select&tbl=doctors&fmt=json >select_doctors</a><br>\n";
# $htmout .= "<a href=./$basename?todo=select&tbl=meds&fmt=json >select_meds</a><br>\n";
# $htmout .= "<a href=./$basename?todo=select&tbl=glucose&fmt=json >select_glucose</a><br>\n";
# $htmout .= "</td>";
$htmout .= "</tr>\n";
$htmout .= " </table id=table_selects_end>\n";
$htmout .= "<hr color=goldenrod>\n";
$htmout .= "<h1>forms</h1>\n";
$htmout .= "<a href=./$basename?todo=form&tbl=bps >form_bps</a><br>\n";
$htmout .= "<a href=./$basename?todo=form&tbl=doctors >form_doctors</a><br>\n";
$htmout .= "<a href=./$basename?todo=form&tbl=meds >form_meds</a><br>\n";
$htmout .= "<a href=./$basename?todo=form&tbl=glucose >form_glucose</a><br>\n";
$htmout .= "<hr color=goldenrod>\n";
return( $htmout );
}
function htmout_tail($args) {
$htmout = "";
$htmout .= " </body>\n";
$htmout .= " </html>\n";
return($args);
}
function db3_connect($db3fil ) {
# print( "<h1>MSG_500 DB3_CONNECT db3fil=$db3fil</h1>\n" );
$db3 = newpdo($db3fil);
# $db3->exec($sql);
$db3=null;
return($db3);
}
function db3_query($db3fil, $sql) {
print( "<h1>MSG_510 DB3_QUERY db3fil=$db3fil sql=$sql</h1>\n" );
$htmout = "";
$db3 = newpdo($db3fil);
$db3->query($sql);
$db3=null;
return($htmout);
}
function db3_exec($db3fil,$sql) {
echo "<h3>MSG_521 DB3_EXEC db3fil=$db3fil sql=$sql</h3>\n";
$htmout = "";
$db3 = newpdo($db3fil);
$db3->exec($sql);
echo "<h3>MSG_522 DB3_EXEC db3fil=$db3fil sql=$sql</h3>\n";
$db3=null;
return($htmout);
}
function newpdo( $db3fil ) {
if( $db3fil == "" ) { $db3fil="med.db3"; }
$php_self=$_SERVER['PHP_SELF'];
$http_host=$_SERVER['HTTP_HOST'];
$request_uri=$_SERVER['REQUEST_URI'];
$script_filename=$_SERVER['SCRIPT_FILENAME'];
$script_name=$_SERVER['SCRIPT_NAME'];
$ht=str_replace($script_name,"",$script_filename);
$ht_db3fil="$ht/ka/fb/med/$db3fil";
if( ! file_exists($ht_db3fil)) {
print( "BUGS_400 NOTFOUND ht_db3fil=$ht_db3fil<br>\n" );
exit;
}
if( ! file_exists( $ht_db3fil )) {
print( "$php_self newpdo ERR_400: NOTFOUND db3fil=[$db3fil]<br>\n" );
if( $GLOBALS['install'] != true ) {
print( "$php_self newpdo ERR: NOT_INSTALL db3fil=[$db3fil]<br>\n" );
return;
}
else {
print( "$php_self newpdo MSG: CREATE db3fil=[$db3fil]<br>\n" );
}
}
try {
$pdo = null;
$pdo = new PDO("sqlite:$db3fil" );
// $pdo = new PDO("sqlite:$ht_db3fil" );
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
if( $pdo == null ) {
print( "$php_self newpdo ERR: db3fil=[$db3fil]<br>\n" );
return $pdo;
}
return $pdo;
}
catch(PDOException $e ) {
$errmsg = $e->getMessage();
print( "$php_self newpdo ERR: pdo=[$pdo] dbfile=[$dbfile] errmsg=[$errmsg]<br>\n" );
$pdo = null;
return $pdo;
}
}
function koexec($query_string) {
// $cmd=explode("=", $query_string)[1];
// phpinfo();
print( "<h1>BUGS_500 koexec query_string=$query_string </h1>\n" );
shell_exec($query_string);
return($query_string);
}
function str_replace_last( $search , $replace , $str ) {
if( ( $pos = strrpos( $str , $search ) ) !== false ) {
$search_length = strlen( $search );
$str = substr_replace( $str , $replace , $pos , $search_length );
}
return $str;
}
//
koh5_pano
Drag mouse to navigate.
Navigation
- Left/Right Mouse drag: Changes camera heading.
- Up/Sown Mouse drag: Changes camera pitch.
- Scroll wheel: Changes camera field of view.
- I-Key: Displays Info panel with canvas size, image size and FPS.
17.Aug.2010, Martin Wengenmayer