Location: PHPKode > projects > Valid tiny-erp > validerp/kinisi_print.php
<?php
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
header("Expires: Thu, 01 Jan 1970 00:00:01 GMT"); 
set_magic_quotes_runtime(0);

include("include/dbcommon.php");
include("include/kinisi_variables.php");

if(!@$_SESSION["UserID"])
{ 
	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
	header("Location: login.php?message=expired"); 
	return;
}
if(!CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Export"))
{
	echo "<p>"."You don't have permissions to access this table"."<a href=\"login.php\">"."Back to login page"."</a></p>";
	return;
}


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

$conn=db_connect();

//	Before Process event
if(function_exists("BeforeProcessPrint"))
	BeforeProcessPrint($conn);

$strWhereClause="";

if (@$_REQUEST["a"]!="") 
{
	
	$sWhere = "1=0";	
	
//	process selection
	$selected_recs=array();
	if (@$_REQUEST["mdelete"])
	{
		foreach(@$_REQUEST["mdelete"] as $ind)
		{
			$keys=array();
			$keys["id"]=refine($_REQUEST["mdelete1"][$ind-1]);
			$selected_recs[]=$keys;
		}
	}
	elseif(@$_REQUEST["selection"])
	{
		foreach(@$_REQUEST["selection"] as $keyblock)
		{
			$arr=split("&",refine($keyblock));
			if(count($arr)<1)
				continue;
			$keys=array();
			$keys["id"]=urldecode($arr[0]);
			$selected_recs[]=$keys;
		}
	}

	foreach($selected_recs as $keys)
	{
		$sWhere = $sWhere . " or ";
		$sWhere.=KeyWhere($keys);
	}
//	$strSQL = AddWhere($gstrSQL,$sWhere);
	$sWhere=whereAdd($sWhere,SecuritySQL("Search"));
//	if(SecuritySQL("Search"))
//		$strSQL = AddWhere($strSQL, SecuritySQL("Search"));
	$strSQL = gSQLWhere($sWhere);
	$strWhereClause=$sWhere;
}
else
{
	$strWhereClause=@$_SESSION[$strTableName."_where"];
	if(!$strWhereClause)
		$strWhereClause=whereAdd($strWhereClause,SecuritySQL("Search"));
	$strSQL = gSQLWhere($strWhereClause);
}



$strOrderBy=$_SESSION[$strTableName."_order"];
if(!$strOrderBy)
	$strOrderBy=$gstrOrderBy;
$strSQL.=" ".trim($strOrderBy);

$strSQLbak = $strSQL;
if(function_exists("BeforeQueryPrint"))
	BeforeQueryPrint($strSQL,$strWhereClause,$strOrderBy);

//	Rebuild SQL if needed
if($strSQL!=$strSQLbak)
{
//	changed $strSQL - old style	
	$numrows=GetRowCount($strSQL);
}
else
{
	$strSQL = gSQLWhere($strWhereClause);
	$strSQL.=" ".trim($strOrderBy);
	$numrows=gSQLRowCount($strWhereClause);
}
LogInfo($strSQL);
	
$mypage=(integer)$_SESSION[$strTableName."_pagenumber"];
if(!$mypage)
	$mypage=1;

//	page size
$PageSize=(integer)$_SESSION[$strTableName."_pagesize"];
if(!$PageSize)
	$PageSize=$gPageSize;

$recno=1;
	
if($numrows)
{
	$maxRecords = $numrows;
	$maxpages=ceil($maxRecords/$PageSize);
	if($mypage > $maxpages)
		$mypage = $maxpages;
	if($mypage<1) 
		$mypage=1;
	$maxrecs=$PageSize;
	$strSQL.=" limit ".(($mypage-1)*$PageSize).",".$PageSize;
}
$rs=db_query($strSQL,$conn);

//	hide colunm headers if needed
$recordsonpage=$numrows-($mypage-1)*$PageSize;
if($recordsonpage>$PageSize)
	$recordsonpage=$PageSize;
	if($recordsonpage>=1)
		$smarty->assign("column1show",true);
	else
		$smarty->assign("column1show",false);


	$totals=array();
	$totals["timipolisis"]=0;
	$totals["quantityesodo"]=0;
	$totals["apotelesmaesodo"]=0;
	$totals["eispraxi"]=0;
	$totals["timiagoras"]=0;
	$totals["quantityexodo"]=0;
	$totals["apotelesmaexodo"]=0;
	$totals["pliromi"]=0;

//	fill $rowinfo array
	$rowinfo = array();

	$data=db_fetch_array($rs);

	while($data && $recno<=$PageSize)
	{
		$row=array();
		for($col=1;$data && $recno<=$PageSize && $col<=1;$col++)
		{

							$totals["timipolisis"]+=($data["timipolisis"]+0);
							$totals["quantityesodo"]+=($data["quantityesodo"]+0);
							$totals["apotelesmaesodo"]+=($data["apotelesmaesodo"]+0);
							$totals["eispraxi"]+=($data["eispraxi"]+0);
							$totals["timiagoras"]+=($data["timiagoras"]+0);
							$totals["quantityexodo"]+=($data["quantityexodo"]+0);
							$totals["apotelesmaexodo"]+=($data["apotelesmaexodo"]+0);
							$totals["pliromi"]+=($data["pliromi"]+0);
			$recno++;
			$keylink="";
			$keylink.="&key1=".htmlspecialchars(rawurlencode($data["id"]));


//	idkinisicategory - 
			$value="";
				if(strlen($data["idkinisicategory"]))
			{
				$strdata = make_db_value("idkinisicategory",$data["idkinisicategory"]);
				$LookupSQL="SELECT ";
							$LookupSQL.="`name`";
				$LookupSQL.=" FROM `_partner` WHERE `id` = " . $strdata;
							LogInfo($LookupSQL);
				$rsLookup = db_query($LookupSQL,$conn);
				$lookupvalue=$data["idkinisicategory"];
				if($lookuprow=db_fetch_numarray($rsLookup))
					$lookupvalue=$lookuprow[0];
									$value=ProcessLargeText(GetDataInt($lookupvalue,$data,"idkinisicategory", ""),"field=idkinisicategory".$keylink,"",MODE_PRINT);

			}
			else
				$value="";
			$row[$col."idkinisicategory_value"]=$value;

//	ektelesmeni - Checkbox
			$value="";
				$value = GetData($data,"ektelesmeni", "Checkbox");
			$row[$col."ektelesmeni_value"]=$value;

//	synallasomenos - 
			$value="";
				if(strlen($data["synallasomenos"]))
			{
				$strdata = make_db_value("synallasomenos",$data["synallasomenos"]);
				$LookupSQL="SELECT ";
							$LookupSQL.="`name`";
				$LookupSQL.=" FROM `synallasomenos` WHERE `id` = " . $strdata;
							LogInfo($LookupSQL);
				$rsLookup = db_query($LookupSQL,$conn);
				$lookupvalue=$data["synallasomenos"];
				if($lookuprow=db_fetch_numarray($rsLookup))
					$lookupvalue=$lookuprow[0];
									$value=ProcessLargeText(GetDataInt($lookupvalue,$data,"synallasomenos", ""),"field=synallasomenos".$keylink,"",MODE_PRINT);

			}
			else
				$value="";
			$row[$col."synallasomenos_value"]=$value;

//	date - Short Date
			$value="";
				$value = ProcessLargeText(GetData($data,"date", "Short Date"),"field=date".$keylink,"",MODE_PRINT);
			$row[$col."date_value"]=$value;

//	proion - 
			$value="";
				if(strlen($data["proion"]))
			{
				$strdata = make_db_value("proion",$data["proion"]);
				$LookupSQL="SELECT ";
							$LookupSQL.="`proion`";
				$LookupSQL.=" FROM `proion` WHERE `id` = " . $strdata;
							LogInfo($LookupSQL);
				$rsLookup = db_query($LookupSQL,$conn);
				$lookupvalue=$data["proion"];
				if($lookuprow=db_fetch_numarray($rsLookup))
					$lookupvalue=$lookuprow[0];
									$value=ProcessLargeText(GetDataInt($lookupvalue,$data,"proion", ""),"field=proion".$keylink,"",MODE_PRINT);

			}
			else
				$value="";
			$row[$col."proion_value"]=$value;

//	timipolisis - Number
			$value="";
				$value = ProcessLargeText(GetData($data,"timipolisis", "Number"),"field=timipolisis".$keylink,"",MODE_PRINT);
			$row[$col."timipolisis_value"]=$value;

//	quantityesodo - 
			$value="";
				$value = ProcessLargeText(GetData($data,"quantityesodo", ""),"field=quantityesodo".$keylink,"",MODE_PRINT);
			$row[$col."quantityesodo_value"]=$value;

//	apotelesmaesodo - Number
			$value="";
				$value = ProcessLargeText(GetData($data,"apotelesmaesodo", "Number"),"field=apotelesmaesodo".$keylink,"",MODE_PRINT);
			$row[$col."apotelesmaesodo_value"]=$value;

//	eispraxi - Number
			$value="";
				$value = ProcessLargeText(GetData($data,"eispraxi", "Number"),"field=eispraxi".$keylink,"",MODE_PRINT);
			$row[$col."eispraxi_value"]=$value;

//	timiagoras - Number
			$value="";
				$value = ProcessLargeText(GetData($data,"timiagoras", "Number"),"field=timiagoras".$keylink,"",MODE_PRINT);
			$row[$col."timiagoras_value"]=$value;

//	quantityexodo - 
			$value="";
				$value = ProcessLargeText(GetData($data,"quantityexodo", ""),"field=quantityexodo".$keylink,"",MODE_PRINT);
			$row[$col."quantityexodo_value"]=$value;

//	apotelesmaexodo - Number
			$value="";
				$value = ProcessLargeText(GetData($data,"apotelesmaexodo", "Number"),"field=apotelesmaexodo".$keylink,"",MODE_PRINT);
			$row[$col."apotelesmaexodo_value"]=$value;

//	pliromi - Number
			$value="";
				$value = ProcessLargeText(GetData($data,"pliromi", "Number"),"field=pliromi".$keylink,"",MODE_PRINT);
			$row[$col."pliromi_value"]=$value;

//	simioseis - 
			$value="";
				$value = ProcessLargeText(GetData($data,"simioseis", ""),"field=simioseis".$keylink,"",MODE_PRINT);
			$row[$col."simioseis_value"]=$value;
			$row[$col."show"]=true;
			$data=db_fetch_array($rs);
		}
		$rowinfo[]=$row;
	}
	$smarty->assign("rowinfo",$rowinfo);

//	show totals
$smarty->assign("showtotal_timipolisis", GetTotals("timipolisis",$totals["timipolisis"],"AVERAGE",$recno-1,"Number"));
$smarty->assign("showtotal_quantityesodo", GetTotals("quantityesodo",$totals["quantityesodo"],"TOTAL",$recno-1,""));
$smarty->assign("showtotal_apotelesmaesodo", GetTotals("apotelesmaesodo",$totals["apotelesmaesodo"],"TOTAL",$recno-1,"Number"));
$smarty->assign("showtotal_eispraxi", GetTotals("eispraxi",$totals["eispraxi"],"TOTAL",$recno-1,"Number"));
$smarty->assign("showtotal_timiagoras", GetTotals("timiagoras",$totals["timiagoras"],"AVERAGE",$recno-1,"Number"));
$smarty->assign("showtotal_quantityexodo", GetTotals("quantityexodo",$totals["quantityexodo"],"TOTAL",$recno-1,""));
$smarty->assign("showtotal_apotelesmaexodo", GetTotals("apotelesmaexodo",$totals["apotelesmaexodo"],"TOTAL",$recno-1,"Number"));
$smarty->assign("showtotal_pliromi", GetTotals("pliromi",$totals["pliromi"],"TOTAL",$recno-1,"Number"));

	
//	display master table info
$mastertable=$_SESSION[$strTableName."_mastertable"];
$masterkeys=array();
$smarty->assign("showmasterfile","empty.htm");
if($mastertable=="proion")
{
//	include proper masterprint.php code
	include("include/proion_masterprint.php");
	$masterkeys[]=@$_SESSION[$strTableName."_masterkey1"];
	DisplayMasterTableInfo("kinisi", $masterkeys);
	$smarty->assign("showmasterfile","proion_masterprint.htm");
}

$strSQL=$_SESSION[$strTableName."_sql"];

$templatefile = "kinisi_print.htm";
if(function_exists("BeforeShowPrint"))
	BeforeShowPrint($smarty,$templatefile);

$smarty->display($templatefile);

Return current item: Valid tiny-erp