<?php
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
set_magic_quotes_runtime(0);
include("include/dbcommon.php");
include("include/patients_variables.php");
// check if logged in
if(!@$_SESSION["UserID"] || !CheckSecurity(@$_SESSION["OwnerID"],"Edit"))
{
$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
header("Location: login.php?message=expired");
return;
}
$filename="";
$message="";
$error_happened=false;
$readevalues=false;
//connect database
$conn = db_connect();
$keys=array();
$keys["Primary"]=postvalue("editid1");
// prepare data for saving
if(@$_POST["a"]=="edited")
{
$strWhere=KeyWhere($keys);
$strSQL = "update ".AddTableWrappers($strOriginalTableName)." set ";
$evalues=array();
$efilename_values=array();
$files_delete=array();
$files_move=array();
foreach($efilename_values as $ekey=>$value)
$evalues[$ekey]=$value;
// do event
$retval=true;
if(function_exists("BeforeEdit"))
$retval=BeforeEdit($evalues,$strWhere);
if($retval)
{
// construct SQL string
foreach($evalues as $ekey=>$value)
$strSQL.=AddFieldWrappers($ekey)."=".add_db_quotes($ekey,$value).", ";
if(substr($strSQL,-2)==", ")
$strSQL=substr($strSQL,0,strlen($strSQL)-2);
$strSQL.=" where ".$strWhere;
set_error_handler("edit_error_handler");
db_exec($strSQL,$conn);
set_error_handler("error_handler");
if(!$error_happened)
{
// delete & move files
foreach ($files_delete as $file)
{
if(file_exists($file))
@unlink($file);
}
foreach ($files_move as $file)
move_uploaded_file($file[0],$file[1]);
$message="<div class=message><<< "."Record updated"." >>></div>";
// after edit event
if(function_exists("AfterEdit"))
AfterEdit();
}
}
else
$readevalues=true;
}
// get current values and show edit controls
$strSQL = $gstrSQL;
$strWhere=KeyWhere($keys);
$strSQL = AddWhere($strSQL,$strWhere);
LogInfo($strSQL);
$rs=db_query($strSQL,$conn);
$data=db_fetch_array($rs);
if($readevalues)
{
}
include('libs/Smarty.class.php');
$smarty = new Smarty();
// include files
$includes="";
// validation stuff
$bodyonload="";
$onsubmit="";
if($bodyonload)
{
$onsubmit="return validate();";
$bodyonload="onload=\"".$bodyonload."\"";
}
$includes.="<script language=\"JavaScript\" src=\"include/jsfunctions.js\"></script>\r\n";
$includes.="<script language=\"JavaScript\">\r\n".
"var locale_dateformat = ".$locale_info["LOCALE_IDATE"].";\r\n".
"var locale_datedelimiter = \"".$locale_info["LOCALE_SDATE"]."\";\r\n".
"var bLoading=false;\r\n".
"var TEXT_PLEASE_SELECT='".addslashes("Please select")."';\r\n".
"</script>\r\n";
$smarty->assign("includes",$includes);
$smarty->assign("bodyonload",$bodyonload);
if(strlen($onsubmit))
$onsubmit="onSubmit=\"".$onsubmit."\"";
$smarty->assign("onsubmit",$onsubmit);
$smarty->assign("key1",htmlspecialchars($keys["Primary"]));
$smarty->assign("show_key1", htmlspecialchars(GetData($data,"Primary", "")));
$smarty->assign("message",$message);
$max_filesize_set=0;
$readonlyfields=array();
$linkdata="";
$smarty->assign("linkdata",$linkdata);
$where=$strWhere;
$smarty->display("patients_edit.htm");
function edit_error_handler($errno, $errstr, $errfile, $errline)
{
global $readevalues, $message, $error_happened;
$message="<div class=message><<< Record was NOT updated >>><br><br>".$errstr."</div>";
$readevalues=true;
$error_happened=true;
}
?>