include "am_header.php";
$found_limit=20;
if(empty($_SESSION['searchtype']))$_SESSION['searchtype']="held";
if(empty($_SESSION['searchcrit']))$_SESSION['searchcrit']="";
if(empty($_SESSION['searchpage']))$_SESSION['searchpage']=1;
if(empty($_REQUEST['atxt']))$_REQUEST['atxt']='';
if(empty($_SESSION['days_old']))$_SESSION['days_old']=1;
if(empty($_REQUEST['days_old']))$_REQUEST['days_old']=$_SESSION['days_old'];
$_SESSION['days_old']=$_REQUEST['days_old'];
$search='';
if(!empty($_REQUEST['search'])){
$search=$_REQUEST['search'];
} elseif(!empty($_SESSION['searchtype'])){
$search=$_SESSION['searchtype'];
}
$_SESSION['searchtype']=$search;
$atxt='';
if(!empty($_REQUEST['atxt'])){
$atxt=$_REQUEST['atxt'];
} elseif(!empty($_SESSION['searchcrit'])){
$atxt=$_SESSION['searchcrit'];
}
$_SESSION['searchcrit']=stripslashes($atxt);
$page='';
if(!empty($_REQUEST['page'])){
$page=$_REQUEST['page'];
} elseif(!empty($_SESSION['searchpage'])){
$page=$_SESSION['searchpage'];
}
$_SESSION['searchpage']=$page;
$show_stats=false;
$show_group=false;
$NoneFoundMsg="No Matching Records Were Found";
if($search=="custom"){
if(!isset($_SESSION['atxt']))$_SESSION['atxt']="";
if(!isset($_SESSION['afield']))$_SESSION['afield']="last";
if(!isset($_SESSION['atype']))$_SESSION['atype']=1;
if(!isset($atxt))$atxt=$_SESSION['atxt'];
if(!isset($afield))$afield=$_SESSION['afield'];
if(!isset($atype))$atype=$_SESSION['atype'];
$_SESSION['atxt']=$atxt;
$_SESSION['afield']=$afield;
$_SESSION['atype']=$atype;
$atxt=mysql_escape_string(stripslashes($atxt));
$wheretext="where CID={$_SESSION['u_County']} order by last,first ";
$wheretext="where CID={$_SESSION['u_County']} and 1=0 ";
if(!empty($afield) && !empty($atype) && !empty($atxt)){
if($atype=="1")$customwhere="$afield like '$atxt%'";
if($atype=="2")$customwhere="$afield like '%$atxt%'";
if($atype=="3")$customwhere="soundex($afield)=soundex('$atxt')";
$wheretext="where CID={$_SESSION['u_County']} and $customwhere order by last,first";
}
$table_title="Search All Records";
DrawHeader("Search All Records");
} else if($search=="recent"){
$show_group=true;
$wheretext="where CID={$_SESSION['u_County']} and ";
$wheretext.="(TO_DAYS(NOW()) - TO_DAYS(DT_Submit) <= {$_REQUEST['days_old']}) order by DT_submit desc ";
$table_title="{$_SESSION['u_CountyName']} County Additions with {$_REQUEST['days_old']} days";
DrawHeader("Recent Additions");
} else if($search=="trash"){
$show_group=true;
$wheretext="where CID={$_SESSION['u_County']} and approved='D' order by DT_updated desc ";
$table_title="{$_SESSION['u_CountyName']} County Trash";
$NoneFoundMsg="There are currently no items in your trash- waiting to be deleted.";
DrawHeader("View Trash");
} else { // if none selected -- show recent additions
$show_stats=true;
$show_group=true;
$wheretext="where CID={$_SESSION['u_County']} and approved='N' order by DT_submit, last ";
$table_title="Records Held for Approval";
$NoneFoundMsg="There are no {$_SESSION['u_CountyName']} County records waiting for approval";
DrawHeader("Review Held Entries");
}
$sql="
SELECT
count(*)
FROM
gravestone
INNER JOIN
cemeteries on cemID=cemeteryID and cemCID=CID $wheretext";
$result = mysql_query($sql) or die(mysql_error().'
'.$sql);
//print($sql);
$numrec=mysql_fetch_row ($result);
$numpage=intval($numrec[0]/$found_limit);
if ($numrec[0]%$found_limit)$numpage++; // add one page if remainder
if(!is_numeric($page) || $page>$numpage || $page<1)$page=1;
$offset=($page-1)*$found_limit;
$sql="
SELECT
gravestone.*,CT_Name,cemName
FROM
gravestone
INNER JOIN
countylist on CID=CountyID
INNER JOIN
cemeteries on cemID=cemeteryID and cemCID=CID
$wheretext
limit $offset,$found_limit
";
$result = mysql_query($sql) or die(mysql_error().'
'.$sql);
$db_txt="