All pastes #533941 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-06-03 16:53 UTC
rendered paste body
<?php 
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
set_magic_quotes_runtime(0);

include("include/dbcommon.php");
include("include/evac_info_prereg_variables.php");
include("include/languages.php");


//	check if logged in
if(!@$_SESSION["UserID"] || !CheckSecurity(@$_SESSION["OwnerID"],"Add"))
{ 
	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
	header("Location: login.php?message=expired"); 
	return;
}


// ---------------------------------------------- 


if($_SESSION["RecentTransfer"]==true)
{
$newID = $_SESSION["newID"];
Header("Location: evac_info_edit.php?editid1=$newID");
}


// ----------------------------------------------


$_SESSION["RecentTransfer"] = false;
$filename="";	
$message="";
$error_happened=false;
$readavalues=false;

//connect database
$conn = db_connect();

// insert new record if we have to

if(@$_POST["a"]=="added")
{
	$afilename_values=array();
	$avalues=array();
	$files_move=array();
//	processing LastName - start

	$value = postvalue("value_LastName");
	$type=postvalue("type_LastName");
	if (in_assoc_array("type_LastName",$_POST) || in_assoc_array("value_LastName",$_POST) || in_assoc_array("value_LastName",$_FILES))
	{
		$value=prepare_for_db("LastName",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["LastName"]=$value;
	}

//	processibng LastName - end
//	processing FirstName - start

	$value = postvalue("value_FirstName");
	$type=postvalue("type_FirstName");
	if (in_assoc_array("type_FirstName",$_POST) || in_assoc_array("value_FirstName",$_POST) || in_assoc_array("value_FirstName",$_FILES))
	{
		$value=prepare_for_db("FirstName",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["FirstName"]=$value;
	}

//	processibng FirstName - end
//	processing MiddleInitial - start

	$value = postvalue("value_MiddleInitial");
	$type=postvalue("type_MiddleInitial");
	if (in_assoc_array("type_MiddleInitial",$_POST) || in_assoc_array("value_MiddleInitial",$_POST) || in_assoc_array("value_MiddleInitial",$_FILES))
	{
		$value=prepare_for_db("MiddleInitial",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["MiddleInitial"]=$value;
	}

//	processibng MiddleInitial - end
//	processing DOB - start

	$value = postvalue("value_DOB");
	$type=postvalue("type_DOB");
	if (in_assoc_array("type_DOB",$_POST) || in_assoc_array("value_DOB",$_POST) || in_assoc_array("value_DOB",$_FILES))
	{
		$value=prepare_for_db("DOB",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["DOB"]=$value;
	}

//	processibng DOB - end
//	processing Gender - start

	$value = postvalue("value_Gender");
	$type=postvalue("type_Gender");
	if (in_assoc_array("type_Gender",$_POST) || in_assoc_array("value_Gender",$_POST) || in_assoc_array("value_Gender",$_FILES))
	{
		$value=prepare_for_db("Gender",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["Gender"]=$value;
	}

//	processibng Gender - end
//	processing Race - start

	$value = postvalue("value_Race");
	$type=postvalue("type_Race");
	if (in_assoc_array("type_Race",$_POST) || in_assoc_array("value_Race",$_POST) || in_assoc_array("value_Race",$_FILES))
	{
		$value=prepare_for_db("Race",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["Race"]=$value;
	}

//	processibng Race - end
//	processing Height - start

	$value = postvalue("value_Height");
	$type=postvalue("type_Height");
	if (in_assoc_array("type_Height",$_POST) || in_assoc_array("value_Height",$_POST) || in_assoc_array("value_Height",$_FILES))
	{
		$value=prepare_for_db("Height",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["Height"]=$value;
	}

//	processibng Height - end
//	processing Weight - start

	$value = postvalue("value_Weight");
	$type=postvalue("type_Weight");
	if (in_assoc_array("type_Weight",$_POST) || in_assoc_array("value_Weight",$_POST) || in_assoc_array("value_Weight",$_FILES))
	{
		$value=prepare_for_db("Weight",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["Weight"]=$value;
	}

//	processibng Weight - end
//	processing HairColor - start

	$value = postvalue("value_HairColor");
	$type=postvalue("type_HairColor");
	if (in_assoc_array("type_HairColor",$_POST) || in_assoc_array("value_HairColor",$_POST) || in_assoc_array("value_HairColor",$_FILES))
	{
		$value=prepare_for_db("HairColor",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["HairColor"]=$value;
	}

//	processibng HairColor - end
//	processing EyeColor - start

	$value = postvalue("value_EyeColor");
	$type=postvalue("type_EyeColor");
	if (in_assoc_array("type_EyeColor",$_POST) || in_assoc_array("value_EyeColor",$_POST) || in_assoc_array("value_EyeColor",$_FILES))
	{
		$value=prepare_for_db("EyeColor",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["EyeColor"]=$value;
	}

//	processibng EyeColor - end
//	processing DLState - start

	$value = postvalue("value_DLState");
	$type=postvalue("type_DLState");
	if (in_assoc_array("type_DLState",$_POST) || in_assoc_array("value_DLState",$_POST) || in_assoc_array("value_DLState",$_FILES))
	{
		$value=prepare_for_db("DLState",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["DLState"]=$value;
	}

//	processibng DLState - end
//	processing DLNumber - start

	$value = postvalue("value_DLNumber");
	$type=postvalue("type_DLNumber");
	if (in_assoc_array("type_DLNumber",$_POST) || in_assoc_array("value_DLNumber",$_POST) || in_assoc_array("value_DLNumber",$_FILES))
	{
		$value=prepare_for_db("DLNumber",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["DLNumber"]=$value;
	}

//	processibng DLNumber - end
//	processing Address - start

	$value = postvalue("value_Address");
	$type=postvalue("type_Address");
	if (in_assoc_array("type_Address",$_POST) || in_assoc_array("value_Address",$_POST) || in_assoc_array("value_Address",$_FILES))
	{
		$value=prepare_for_db("Address",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["Address"]=$value;
	}

//	processibng Address - end
//	processing AptUnit - start

	$value = postvalue("value_AptUnit");
	$type=postvalue("type_AptUnit");
	if (in_assoc_array("type_AptUnit",$_POST) || in_assoc_array("value_AptUnit",$_POST) || in_assoc_array("value_AptUnit",$_FILES))
	{
		$value=prepare_for_db("AptUnit",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["AptUnit"]=$value;
	}

//	processibng AptUnit - end
//	processing City - start

	$value = postvalue("value_City");
	$type=postvalue("type_City");
	if (in_assoc_array("type_City",$_POST) || in_assoc_array("value_City",$_POST) || in_assoc_array("value_City",$_FILES))
	{
		$value=prepare_for_db("City",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["City"]=$value;
	}

//	processibng City - end
//	processing State - start

	$value = postvalue("value_State");
	$type=postvalue("type_State");
	if (in_assoc_array("type_State",$_POST) || in_assoc_array("value_State",$_POST) || in_assoc_array("value_State",$_FILES))
	{
		$value=prepare_for_db("State",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["State"]=$value;
	}

//	processibng State - end
//	processing Zip - start

	$value = postvalue("value_Zip");
	$type=postvalue("type_Zip");
	if (in_assoc_array("type_Zip",$_POST) || in_assoc_array("value_Zip",$_POST) || in_assoc_array("value_Zip",$_FILES))
	{
		$value=prepare_for_db("Zip",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["Zip"]=$value;
	}

//	processibng Zip - end
//	processing HomePhone - start

	$value = postvalue("value_HomePhone");
	$type=postvalue("type_HomePhone");
	if (in_assoc_array("type_HomePhone",$_POST) || in_assoc_array("value_HomePhone",$_POST) || in_assoc_array("value_HomePhone",$_FILES))
	{
		$value=prepare_for_db("HomePhone",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["HomePhone"]=$value;
	}

//	processibng HomePhone - end
//	processing CellPhone - start

	$value = postvalue("value_CellPhone");
	$type=postvalue("type_CellPhone");
	if (in_assoc_array("type_CellPhone",$_POST) || in_assoc_array("value_CellPhone",$_POST) || in_assoc_array("value_CellPhone",$_FILES))
	{
		$value=prepare_for_db("CellPhone",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["CellPhone"]=$value;
	}

//	processibng CellPhone - end
//	processing EmerContName - start

	$value = postvalue("value_EmerContName");
	$type=postvalue("type_EmerContName");
	if (in_assoc_array("type_EmerContName",$_POST) || in_assoc_array("value_EmerContName",$_POST) || in_assoc_array("value_EmerContName",$_FILES))
	{
		$value=prepare_for_db("EmerContName",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["EmerContName"]=$value;
	}

//	processibng EmerContName - end
//	processing EmerContNum - start

	$value = postvalue("value_EmerContNum");
	$type=postvalue("type_EmerContNum");
	if (in_assoc_array("type_EmerContNum",$_POST) || in_assoc_array("value_EmerContNum",$_POST) || in_assoc_array("value_EmerContNum",$_FILES))
	{
		$value=prepare_for_db("EmerContNum",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["EmerContNum"]=$value;
	}

//	processibng EmerContNum - end
//	processing SexOffender - start

	$value = postvalue("value_SexOffender");
	$type=postvalue("type_SexOffender");
	if (in_assoc_array("type_SexOffender",$_POST) || in_assoc_array("value_SexOffender",$_POST) || in_assoc_array("value_SexOffender",$_FILES))
	{
		$value=prepare_for_db("SexOffender",$value,$type);
	}
	else
		$value=false;
	if(!($value===false))
	{
		$avalues["SexOffender"]=$value;
	}

//	processibng SexOffender - end





//	add filenames to values
	foreach($afilename_values as $akey=>$value)
		$avalues[$akey]=$value;
//	make SQL string
	$strSQL = "insert into ".AddTableWrappers("evac_info")." ";
	$strFields="(";
	$strValues="(";
	
//	before Add event
	$retval = true;
	if(function_exists("BeforeAdd"))
		$retval=BeforeAdd($avalues);
	if($retval)
	{
		foreach($avalues as $akey=>$value)
		{
			$strFields.=AddFieldWrappers($akey).", ";
			$strValues.=add_db_quotes($akey,$value).", ";
		}
		if(substr($strFields,-2)==", ")
			$strFields=substr($strFields,0,strlen($strFields)-2);
		if(substr($strValues,-2)==", ")
			$strValues=substr($strValues,0,strlen($strValues)-2);
		$strSQL.=$strFields.") values ".$strValues.")";
		LogInfo($strSQL);
		$key= $_SESSION["keyID"];

// TRANSFER SQL QUERY
				        
		$strSQL="INSERT INTO `evac_info` (`LastName`, `FirstName`, `MiddleInitial`, `Gender`, `Race`, `Height`, `Weight`, `HairColor`, `EyeColor`, `DOB`, `DLState`, `DLNumber`, `Address`, `AptUnit`, `City`, `State`, `Zip`, `HomePhone`, `CellPhone`, `SexOffender`, `EmerContName`, `EmerContNum`, `SpecNeedCat`, `SpecialNeeds`) SELECT `LastName`, `FirstName`, `MiddleInitial`, `Gender`, `Race`, `Height`, `Weight`, `HairColor`, `EyeColor`, `DOB`, `DLState`, `DLNumber`, `Address`, `AptUnit`, `City`, `State`, `Zip`, `HomePhone`, `CellPhone`, `SexOffender`, `EmerContName`, `EmerContNum`, `SpecNeedCat`, `SpecialNeeds` FROM `evac_info_prereg` WHERE `evac_info_prereg`.`ID` = $key";

		set_error_handler("add_error_handler");

		db_exec($strSQL,$conn);
// set newID
		$_SESSION["newID"] = mysql_insert_id();
		echo $_SESSION["newID"];


//remove record now

		$strSQL="DELETE FROM `evac_info_prereg` WHERE `ID` = $key LIMIT 1";
		db_exec($strSQL,$conn);

		set_error_handler("error_handler");
//	move files
		if(!$error_happened)
		{
			foreach ($files_move as $file)
				move_uploaded_file($file[0],$file[1]);
			$message="<div class=message><<< Record Transfered >>></div>";
			$_SESSION["RecentTransfer"] = true;
//	after add event		
			if(function_exists("AfterAdd"))
				AfterAdd();
		}
	}
	else
		$readavalues=true;
}

$defvalues=array();


$keys=array();
$keys["ID"]=postvalue("transid1");
$keyID=postvalue("transid1");
$_SESSION["keyID"] = $keyID; 



//	transfer record
if(array_key_exists("transid1",$_REQUEST))
{
	$strWhere=KeyWhere($keys);
	$strSQL=$gstrSQL;
	$strSQL=AddWhere($strSQL,$strWhere);
	LogInfo($strSQL);
	$rs=db_query($strSQL,$conn);
	$defvalues=db_fetch_array($rs);

//	clear key fields
	$defvalues["ID"]="";
//call CopyOnLoad event
	if(function_exists("CopyOnLoad"))
		CopyOnLoad($defvalues,$strWhere);

}
else if(!count($defvalues))
{
	$defvalues["SexOffender"]=0;
}
if($readavalues)
{
	$defvalues["LastName"]=@$avalues["LastName"];
	$defvalues["FirstName"]=@$avalues["FirstName"];
	$defvalues["MiddleInitial"]=@$avalues["MiddleInitial"];
	$defvalues["Gender"]=@$avalues["Gender"];
	$defvalues["Race"]=@$avalues["Race"];
	$defvalues["Height"]=@$avalues["Height"];
	$defvalues["Weight"]=@$avalues["Weight"];
	$defvalues["HairColor"]=@$avalues["HairColor"];
	$defvalues["EyeColor"]=@$avalues["EyeColor"];
	$defvalues["DOB"]=@$avalues["DOB"];
	$defvalues["DLState"]=@$avalues["DLState"];
	$defvalues["DLNumber"]=@$avalues["DLNumber"];
	$defvalues["Address"]=@$avalues["Address"];
	$defvalues["AptUnit"]=@$avalues["AptUnit"];
	$defvalues["City"]=@$avalues["City"];
	$defvalues["State"]=@$avalues["State"];
	$defvalues["Zip"]=@$avalues["Zip"];
	$defvalues["HomePhone"]=@$avalues["HomePhone"];
	$defvalues["CellPhone"]=@$avalues["CellPhone"];
	$defvalues["SexOffender"]=@$avalues["SexOffender"];
	$defvalues["EmerContName"]=@$avalues["EmerContName"];
	$defvalues["EmerContNum"]=@$avalues["EmerContNum"];
}


include('libs/Smarty.class.php');
$smarty = new Smarty();

foreach($defvalues as $key=>$value)
	$smarty->assign("value_".GoodFieldName($key),$value);


//	include files

$includes="";

//	validation stuff
$bodyonload="";
$onsubmit="";
$includes.="<script language=\"JavaScript\" src=\"include/validate.js\"></script>\r\n";
$includes.="<script language=\"JavaScript\">\r\n";
$includes.="var TEXT_FIELDS_REQUIRED='".addslashes(mlang_message("FIELDS_REQUIRED"))."';\r\n";
$includes.="var TEXT_FIELDS_ZIPCODES='".addslashes(mlang_message("FIELDS_ZIPCODES"))."';\r\n";
$includes.="var TEXT_FIELDS_EMAILS='".addslashes(mlang_message("FIELDS_EMAILS"))."';\r\n";
$includes.="var TEXT_FIELDS_NUMBERS='".addslashes(mlang_message("FIELDS_NUMBERS"))."';\r\n";
$includes.="var TEXT_FIELDS_CURRENCY='".addslashes(mlang_message("FIELDS_CURRENCY"))."';\r\n";
$includes.="var TEXT_FIELDS_PHONE='".addslashes(mlang_message("FIELDS_PHONE"))."';\r\n";
$includes.="var TEXT_FIELDS_PASSWORD1='".addslashes(mlang_message("FIELDS_PASSWORD1"))."';\r\n";
$includes.="var TEXT_FIELDS_PASSWORD2='".addslashes(mlang_message("FIELDS_PASSWORD2"))."';\r\n";
$includes.="var TEXT_FIELDS_PASSWORD3='".addslashes(mlang_message("FIELDS_PASSWORD3"))."';\r\n";
$includes.="var TEXT_FIELDS_STATE='".addslashes(mlang_message("FIELDS_STATE"))."';\r\n";
$includes.="var TEXT_FIELDS_SSN='".addslashes(mlang_message("FIELDS_SSN"))."';\r\n";
$includes.="var TEXT_FIELDS_DATE='".addslashes(mlang_message("FIELDS_DATE"))."';\r\n";
$includes.="var TEXT_FIELDS_TIME='".addslashes(mlang_message("FIELDS_TIME"))."';\r\n";
$includes.="var TEXT_FIELDS_CC='".addslashes(mlang_message("FIELDS_CC"))."';\r\n";
$includes.="var TEXT_FIELDS_SSN='".addslashes(mlang_message("FIELDS_SSN"))."';\r\n";
$includes.="</script>\r\n";
  	$validatetype="";
	$validatetype.="IsRequired";
	if($validatetype)
		$bodyonload.="define('value_LastName','".$validatetype."','LastName');";
  	$validatetype="";
	$validatetype.="IsRequired";
	if($validatetype)
		$bodyonload.="define('value_FirstName','".$validatetype."','FirstName');";
  	$validatetype="IsCC";
	if($validatetype)
		$bodyonload.="define('value_Height','".$validatetype."','Height');";

if($bodyonload)
{
	$onsubmit="return validate();";
	$bodyonload="onload=\"".$bodyonload."\"";
}

if ($useAJAX) {
	$includes.="<script language=\"JavaScript\" src=\"include/jquery.js\"></script>\r\n";
	$includes.="<script language=\"JavaScript\" src=\"include/ajaxsuggest.js\"></script>\r\n";
}
$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='".jsreplace(mlang_message("PLEASE_SELECT"))."';\r\n";
if ($useAJAX) {
	$includes.="var AUTOCOMPLETE_TABLE='evac_info_prereg_autocomplete.php';\r\n";
	$includes.="var SUGGEST_TABLE='evac_info_prereg_searchsuggest.php';\r\n";
	$includes.="var SUGGEST_LOOKUP_TABLE='evac_info_prereg_lookupsuggest.php';\r\n";
}
$includes.="</script>\r\n";
if ($useAJAX) {
	$includes.="<div id=\"search_suggest\"></div>\r\n";
}

	//	include datepicker files
$includes.="<script language=\"JavaScript\" src=\"include/calendar.js\"></script>\r\n";




$smarty->assign("includes",$includes);
$smarty->assign("bodyonload",$bodyonload);
if(strlen($onsubmit))
	$onsubmit="onSubmit=\"".$onsubmit."\"";
$smarty->assign("onsubmit",$onsubmit);

$smarty->assign("message",$message);


$max_filesize_set=0;

$readonlyfields=array();

//	show readonly fields

$linkdata="";

if ($useAJAX) {
	$linkdata .= "<script type=\"text/javascript\">\r\n";
	$linkdata .= "$(document).ready(function(){ \r\n";
	$linkdata .= "
function loadSelectContent(txt, selectControl, selectValue) 
{
	$('#'+selectControl).get(0).options[0]=new Option(TEXT_PLEASE_SELECT,'');
	var str = txt.split('\\n');
	var index = 0;
	for(i=0,j=0; i < str.length - 1; i=i+2, j++) {
		$('#'+selectControl).get(0).options[j+1]=new Option(unescape(str[i+1]),unescape(str[i]));
		if ( unescape(str[i]) == selectValue ) {index = j+1;}
	}
	$('#'+selectControl).get(0).selectedIndex = index;
}"."\r\n";
	$linkdata .= "});\r\n";
	$linkdata .= "</script>\r\n";
} else {
}

$smarty->assign("linkdata",$linkdata);


$smarty->display("evac_info_prereg_trans.htm");


function add_error_handler($errno, $errstr, $errfile, $errline)
{
	global $readavalues, $message, $error_happened;
	$message="<div class=message><<< ".mlang_message("RECORD_NOT_ADDED")." >>><br><br>".$errstr."</div>";
	$readavalues=true;
	$error_happened=true;
}

?>