<?php
include(getabspath("include/My_Visit_Summary_settings.php"));

function DisplayMasterTableInfo_My_Visit_Summary($params)
{
	$detailtable=$params["detailtable"];
	$keys=$params["keys"];
	global $conn,$strTableName;
	$xt = new Xtempl();
	$oldTableName=$strTableName;
	$strTableName="My Visit Summary";

//$strSQL = "SELECT  `Employee Name`,  Date(visit_register.`Date Of Visit`) AS `Date`,  COUNT(idvisit_register) AS Nos,  Date(Now())-Date(visit_register.`Date Of Visit`) AS comp  FROM visit_register  WHERE (Date(Now())-Date(visit_register.`Date Of Visit`) <30)  GROUP BY `Employee Name`, Date(visit_register.`Date Of Visit`)  ORDER BY Date(visit_register.`Date Of Visit`) DESC  ";

$sqlHead="SELECT `Employee Name`,  Date(visit_register.`Date Of Visit`) AS `Date`,  COUNT(idvisit_register) AS Nos,  Date(Now())-Date(visit_register.`Date Of Visit`) AS comp";
$sqlFrom="FROM visit_register";
$sqlWhere="(Date(Now())-Date(visit_register.`Date Of Visit`) <30)";
$sqlTail="GROUP BY `Employee Name`, Date(visit_register.`Date Of Visit`)";

$where="";
$mKeys = array();
$showKeys = "";

if($detailtable=="_details")
{
		$where.= GetFullFieldName("Date Of Visit")."=".make_db_value("Date Of Visit",$keys[1-1]);
	$showKeys .= " : ".$keys[1-1];
	$xt->assign('showKeys',$showKeys);
}
	if(!$where)
	{
		$strTableName=$oldTableName;
		return;
	}
	$str = SecuritySQL("Search");
	if(strlen($str))
		$where.=" and ".$str;

	$strWhere=whereAdd($sqlWhere,$where);
	if(strlen($strWhere))
		$strWhere=" where ".$strWhere." ";
	$strSQL= $sqlHead.' '.$sqlFrom.$strWhere.$sqlTail;

//	$strSQL=AddWhere($strSQL,$where);
	LogInfo($strSQL);
	$rs=db_query($strSQL,$conn);
	$data=db_fetch_array($rs);
	if(!$data)
	{
		$strTableName=$oldTableName;
		return;
	}
	$keylink="";
	$keylink.="&key1=".htmlspecialchars(rawurlencode(@$data["Employee Name"]));
	


//	Date - Short Date
			$value="";
				$value = ProcessLargeText(GetData($data,"Date", "Short Date"),"field=Date".$keylink);
			$xt->assign("Date_mastervalue",$value);

//	Nos - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Nos", ""),"field=Nos".$keylink);
			$xt->assign("Nos_mastervalue",$value);
	$xt->display("My_Visit_Summary_masterlist.htm");
	$strTableName=$oldTableName;
}

?>