Location: PHPKode > projects > Blogs manager > blogs/_comments_Report_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/_comments_Report_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"],"Search"))
{
	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);


$smarty->assign("includes",
"<script language=\"JavaScript\" src=\"include/jsfunctions.js\">".
"</script>".
"<script>".
"	var bSelected=false;".
"var TEXT_FIRST = \""."First"."\";".
"var TEXT_PREVIOUS = \""."Previous"."\";".
"var TEXT_NEXT = \""."Next"."\";".
"var TEXT_LAST = \""."Last"."\";".
"</script>");

$groupno=0;

if(!$_SESSION[$strTableName."_pagenumber"])
	$_SESSION[$strTableName."_pagenumber"]=1;
if(!$_SESSION[$strTableName."_pagesize"])
	$_SESSION[$strTableName."_pagesize"]=5;

$bAll=false;
$PageSize=$_SESSION[$strTableName."_pagesize"];
if(@$_REQUEST["all"])
{
	$PageSize=-1;
	$bAll=true;
}

$pagestart=($_SESSION[$strTableName."_pagenumber"]-1)*$_SESSION[$strTableName."_pagesize"]+1;
$pageend=$pagestart+$_SESSION[$strTableName."_pagesize"]-1;

// init totals

// group totals
$grouptotals_count = array();
$grouptotals_min = array();
$grouptotals_max = array();
$grouptotals_dispmin = array();
$grouptotals_dispmax = array();
$grouptotals_sum = array();
$grouptotals_sum["blogfirstline"]=array();
$grouptotals_min["blogfirstline"]=array();
$grouptotals_max["blogfirstline"]=array();
$grouptotals_dispmin["blogfirstline"]=array();
$grouptotals_dispmax["blogfirstline"]=array();
$grouptotals_count["blogfirstline"]=0;
$grouptotals_sum["blogfirstline"]["id"]=0;
$grouptotals_sum["blogfirstline"]["username"]=0;
$grouptotals_sum["blogfirstline"]["blogfirstline"]=0;
$grouptotals_sum["blogfirstline"]["date"]=0;
$grouptotals_sum["blogfirstline"]["time"]=0;
$grouptotals_sum["blogfirstline"]["rate"]=0;
$grouptotals_sum["blogfirstline"]["comment"]=0;

// page totals
$pagetotals_count = 0;
$pagetotals_min = array();
$pagetotals_max = array();
$pagetotals_dispmin = array();
$pagetotals_dispmax = array();
$pagetotals_sum = array();
$pagetotals_sum["id"]=0;
$pagetotals_sum["username"]=0;
$pagetotals_sum["blogfirstline"]=0;
$pagetotals_sum["date"]=0;
$pagetotals_sum["time"]=0;
$pagetotals_sum["rate"]=0;
$pagetotals_sum["comment"]=0;

// global totals
$globaltotals_count = 0;
$globaltotals_min = array();
$globaltotals_max = array();
$globaltotals_dispmin = array();
$globaltotals_dispmax = array();
$globaltotals_sum = array();
$globaltotals_sum["id"]=0;
$globaltotals_sum["username"]=0;
$globaltotals_sum["blogfirstline"]=0;
$globaltotals_sum["date"]=0;
$globaltotals_sum["time"]=0;
$globaltotals_sum["rate"]=0;
$globaltotals_sum["comment"]=0;


$strWhereClause = @$_SESSION[$strTableName."_where"];

$strSQL = gSQLWhere($strWhereClause);

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

//	select all records

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

if($strSQLbak == $strSQL)
{
	$strSQL = gSQLWhere($strWhereClause);
	$strSQL.=" ".trim($strOrderBy);
}

LogInfo($strSQL);
$rs=db_query($strSQL,$conn);

$start=true;

	$groupstart_blogfirstline=0;
	$groupvalue_blogfirstline="";

$pages=array();
$page=array();
$rowinfo = array();
$rowcount=0;
$summaryrows=1;
$summaryrows++;
$summaryrows++;
$summaryrows++;
$summaryrows++;

while($data=db_fetch_array($rs))
{
	$row=array();
//	check if starting new group
	$newgroup_blogfirstline=false;
	$firstnewgroup_blogfirstline=false;
	$newgroup=false;

			if($start || $groupstart_blogfirstline!=GetGroupStart("blogfirstline",$data["blogfirstline"]))
		{
			$newgroup_blogfirstline=true;
			if(!$newgroup)
				$firstnewgroup_blogfirstline=true;
			$newgroup=true;
		}
		
//	close groups
	$rowclose=array();
	if(!$start && $newgroup_blogfirstline)
	{
		$rowclose["endgroup_blogfirstline"]=true;
		$rowcount+=$summaryrows;
		$rowclose["1blogfirstline_grval"]=$groupvalue_blogfirstline;
		$rowclose["groupblogfirstline_total_cnt"]=$grouptotals_count["blogfirstline"];
//		$rowclose["groupblogfirstline_totalrate_sum"]=$grouptotals_sum["blogfirstline"]["rate"];
		$sum=array("rate"=>$grouptotals_sum["blogfirstline"]["rate"]);
		$rowclose["groupblogfirstline_totalrate_sum"]=GetData($sum,"rate","");
			if($grouptotals_count["blogfirstline"])
		{
																																			$avg=array("rate"=>$grouptotals_sum["blogfirstline"]["rate"]/$grouptotals_count["blogfirstline"]);
			$rowclose["groupblogfirstline_totalrate_avg"]=GetData($avg,"rate","");
					$rowclose["groupblogfirstline_totalrate_min"]=$grouptotals_dispmin["blogfirstline"]["rate"];
					$rowclose["groupblogfirstline_totalrate_max"]=$grouptotals_dispmax["blogfirstline"]["rate"];
								}
	}
	if(($PageSize<0 || $groupno>=$pagestart && $groupno<=$pageend) && count($rowclose))
	{
		$rowinfo[]=$rowclose;
	}
	if($bAll && $rowcount>=30-$summaryrows)
	{
		$page["rowinfo"]=$rowinfo;
		$page["showpagesummary"]=true;
		ClosePage();
		$pages[]=$page;
		$rowinfo=array();
		$rowcount=0;
	}
	$start=false;
//	open new group
	if($newgroup_blogfirstline)
	{
			$groupno++;
		$row["newgroup_blogfirstline"]=true;
		$row["firstnewgroup_blogfirstline"]=$firstnewgroup_blogfirstline;

		$groupstart_blogfirstline = GetGroupStart("blogfirstline",$data["blogfirstline"]);
		$groupdisplay_blogfirstline = GetGroupStart("blogfirstline",$data["blogfirstline"]);
		$groupvalue_blogfirstline=GetGroupDisplay("blogfirstline",$data["blogfirstline"]);
		
		$row["1blogfirstline_grval"]=$groupvalue_blogfirstline;
		
		$grouptotals_count["blogfirstline"]=0;
		$grouptotals_sum["blogfirstline"]["id"]=0;
		$grouptotals_sum["blogfirstline"]["username"]=0;
		$grouptotals_sum["blogfirstline"]["blogfirstline"]=0;
		$grouptotals_sum["blogfirstline"]["date"]=0;
		$grouptotals_sum["blogfirstline"]["time"]=0;
		$grouptotals_sum["blogfirstline"]["rate"]=0;
		$grouptotals_sum["blogfirstline"]["comment"]=0;
	}

//	display data
	if($PageSize<0 || $groupno>=$pagestart && $groupno<=$pageend)
	{
		$row["havedata"]=true;
/////////////////////////////////
			$keylink="";
			$keylink.="&key1=".htmlspecialchars(rawurlencode($data["id"]));


//	blogfirstline - 
			$value="";
				$value = ProcessLargeText(GetData($data,"blogfirstline", ""),"field=blogfirstline".$keylink,"",MODE_PRINT);
				$row["1blogfirstline_value"]=$value;
		
		if(@$row["newgroup_blogfirstline"])
		{
			$row["1blogfirstline_grval"]=$value;
			$groupvalue_blogfirstline=$value;
		}
	

//	id - 
			$value="";
				$value = ProcessLargeText(GetData($data,"id", ""),"field=id".$keylink,"",MODE_PRINT);
				$row["1id_value"]=$value;

//	username - 
			$value="";
				$value = ProcessLargeText(GetData($data,"username", ""),"field=username".$keylink,"",MODE_PRINT);
				$row["1username_value"]=$value;

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

//	time - Time
			$value="";
				$value = ProcessLargeText(GetData($data,"time", "Time"),"field=time".$keylink,"",MODE_PRINT);
				$row["1time_value"]=$value;

//	rate - 
			$value="";
				$value = ProcessLargeText(GetData($data,"rate", ""),"field=rate".$keylink,"",MODE_PRINT);
				$row["1rate_value"]=$value;

//	comment - 
			$value="";
				$value = ProcessLargeText(GetData($data,"comment", ""),"field=comment".$keylink,"",MODE_PRINT);
				$row["1comment_value"]=$value;
//////////////////////////////////////////////////////////////	

//	update totals
		$grouptotals_sum["blogfirstline"]["rate"]+=$data["rate"];
			if(!$grouptotals_count["blogfirstline"])
		{
			$grouptotals_min["blogfirstline"]["rate"]=$data["rate"];
			$grouptotals_dispmin["blogfirstline"]["rate"]=GetData($data,"rate","");
			$grouptotals_max["blogfirstline"]["rate"]=$data["rate"];
			$grouptotals_dispmax["blogfirstline"]["rate"]=GetData($data,"rate","");
		}
		else
		{
																																				if($grouptotals_min["blogfirstline"]["rate"]>$data["rate"])
			{
				$grouptotals_min["blogfirstline"]["rate"]=$data["rate"];
				$grouptotals_dispmin["blogfirstline"]["rate"]=GetData($data,"rate","");
			}
						if($grouptotals_max["blogfirstline"]["rate"]<$data["rate"])
			{
				$grouptotals_max["blogfirstline"]["rate"]=$data["rate"];
				$grouptotals_dispmax["blogfirstline"]["rate"]=GetData($data,"rate","");
			}
								}
		$grouptotals_count["blogfirstline"]++;
		$pagetotals_sum["rate"]+=$data["rate"];
			if(!$pagetotals_count)
		{
			$pagetotals_min["rate"]=$data["rate"];
			$pagetotals_dispmin["rate"]=GetData($data,"rate","");
			$pagetotals_max["rate"]=$data["rate"];
			$pagetotals_dispmax["rate"]=GetData($data,"rate","");
		}
		else
		{
																																				if($pagetotals_min["rate"]>$data["rate"])
			{
				$pagetotals_min["rate"]=$data["rate"];
				$pagetotals_dispmin["rate"]=GetData($data,"rate","");
			}
						if($pagetotals_max["rate"]<$data["rate"])
			{
				$pagetotals_max["rate"]=$data["rate"];
				$pagetotals_dispmax["rate"]=GetData($data,"rate","");
			}
								}
		$pagetotals_count++;
		$rowinfo[]=$row;
		$rowcount++;
		if($bAll && $rowcount>=30-$summaryrows)
		{
			$page["rowinfo"]=$rowinfo;
			$page["showpagesummary"]=true;
			ClosePage();
			$pages[]=$page;
			$rowinfo=array();
			$rowcount=0;
		}
	}
		$globaltotals_sum["rate"]+=$data["rate"];
			if(!$globaltotals_count)
		{
			$globaltotals_min["rate"]=$data["rate"];
			$globaltotals_dispmin["rate"]=GetData($data,"rate","");
			$globaltotals_max["rate"]=$data["rate"];
			$globaltotals_dispmax["rate"]=GetData($data,"rate","");
		}
		else
		{
																																				if($globaltotals_min["rate"]>$data["rate"])
			{
				$globaltotals_min["rate"]=$data["rate"];
				$globaltotals_dispmin["rate"]=GetData($data,"rate","");
			}
						if($globaltotals_max["rate"]<$data["rate"])
			{
				$globaltotals_max["rate"]=$data["rate"];
				$globaltotals_dispmax["rate"]=GetData($data,"rate","");
			}
								}
		$globaltotals_count++;
}

if($PageSize<0 || $groupno>=$pagestart && $groupno<=$pageend)
{
//	close groups
	$rowclose=array();
	$rowclose["endgroup_blogfirstline"]=true;
	$rowcount+=$summaryrows;
	$rowclose["1blogfirstline_grval"]=$groupvalue_blogfirstline;
	$rowclose["groupblogfirstline_total_cnt"]=$grouptotals_count["blogfirstline"];
//		$rowclose["groupblogfirstline_totalrate_sum"]=$grouptotals_sum["blogfirstline"]["rate"];
		$sum=array("rate"=>$grouptotals_sum["blogfirstline"]["rate"]);
		$rowclose["groupblogfirstline_totalrate_sum"]=GetData($sum,"rate","");
			if($grouptotals_count["blogfirstline"])
		{
																																			$avg=array("rate"=>$grouptotals_sum["blogfirstline"]["rate"]/$grouptotals_count["blogfirstline"]);
			$rowclose["groupblogfirstline_totalrate_avg"]=GetData($avg,"rate","");
					$rowclose["groupblogfirstline_totalrate_min"]=$grouptotals_dispmin["blogfirstline"]["rate"];
					$rowclose["groupblogfirstline_totalrate_max"]=$grouptotals_dispmax["blogfirstline"]["rate"];
							}
	if(count($rowclose))
		$rowinfo[]=$rowclose;
}
if(count($rowinfo))
{
	$page["rowinfo"]=$rowinfo;
	$page["showpagesummary"]=true;
	ClosePage();
	$rowcount+=$summaryrows;
}


	if($bAll && $rowcount>=30-$summaryrows)
	{
		$pages[]=$page;
		$page=array();
	}
	$page["showglobalsummary"]=true;
	$smarty->assign("global_total_cnt",$globaltotals_count);
																						//	$smarty->assign("global_totalrate_sum",$globaltotals_sum["rate"]);
	$sum=array("rate"=>$globaltotals_sum["rate"]);
	$smarty->assign("global_totalrate_sum",GetData($sum,"rate",""));
			if($globaltotals_count)
	{
				$avg=array("rate"=>$globaltotals_sum["rate"]/$globaltotals_count);
		$smarty->assign("global_totalrate_avg",GetData($avg,"rate",""));
				$smarty->assign("global_totalrate_min",$globaltotals_dispmin["rate"]);
				$smarty->assign("global_totalrate_max",$globaltotals_dispmax["rate"]);
	}
				
$pages[]=$page;
$smarty->assign("pages",$pages);


$mypage=$_SESSION[$strTableName."_pagenumber"];
$maxpages=ceil($groupno/$PageSize);
//	write pagination
if($maxpages>1)
	$smarty->assign("pagination","<script language=\"JavaScript\">WritePagination(".$mypage.",".$maxpages.");
		function GotoPage(nPageNumber)
		{
			window.location='_comments_Report_report.php?goto='+nPageNumber;
		}
</script>");

$smarty->assign("gpp1_selected",($PageSize==1)?"selected":"");
$smarty->assign("gpp3_selected",($PageSize==3)?"selected":"");
$smarty->assign("gpp5_selected",($PageSize==5)?"selected":"");
$smarty->assign("gpp10_selected",($PageSize==10)?"selected":"");
$smarty->assign("gpp50_selected",($PageSize==50)?"selected":"");
$smarty->assign("gpp100_selected",($PageSize==100)?"selected":"");
$smarty->assign("gpp0_selected",($PageSize==-1)?"selected":"");


$smarty->assign("userid",htmlspecialchars($_SESSION["UserID"]));


//	table selector
$strPerm = GetUserPermissions("_authors");
$smarty->assign("allow__authors",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("_blogs");
$smarty->assign("allow__blogs",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("_comments");
$smarty->assign("allow__comments",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("_category");
$smarty->assign("allow__category",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("_policy");
$smarty->assign("allow__policy",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("chosen authors");
$smarty->assign("allow_chosen_authors",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("_rate");
$smarty->assign("allow__rate",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("help");
$smarty->assign("allow_help",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("_comments Report");
$smarty->assign("allow__comments_Report",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));
$strPerm = GetUserPermissions("categoriesblogs");
$smarty->assign("allow_categoriesblogs",!(strpos($strPerm, "A")===false && strpos($strPerm, "S")===false));

	$smarty->assign("allow_delete",CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Delete"));
	$smarty->assign("allow_add",CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Add"));
	$smarty->assign("allow_edit",CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Edit"));
	$smarty->assign("allow_export",CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Export"));
	$smarty->assign("allow_search",CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Search"));
	$smarty->assign("allow_deleteorexport",CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Delete") || CheckSecurity(@$_SESSION["_".$strTableName."_OwnerID"],"Export") );



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

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

$smarty->display($templatefile);

function GetGroupStart($field,$value)
{
	if($field=="blogfirstline")
	{
			return $value;
	}

}

function GetGroupDisplay($field,$value)
{
	global $locale_info;
	if($field=="blogfirstline")
	{
			return $value;
	}

}

function ClosePage()
{
	global $page;
	global $pagetotals_count;
	global $pagetotals_min;
	global $pagetotals_max;
	global $pagetotals_dispmin;
	global $pagetotals_dispmax;
	global $pagetotals_sum;
		$page["page_total_cnt"]=$pagetotals_count;
																						//		$page["page_totalrate_sum"]=$pagetotals_sum["rate"];
		$sum=array("rate"=>$pagetotals_sum["rate"]);
		$page["page_totalrate_sum"]=GetData($sum,"rate","");
				if($pagetotals_count)
		{
					$avg=array("rate"=>$pagetotals_sum["rate"]/$pagetotals_count);
			$page["page_totalrate_avg"]=GetData($avg,"rate","");
					$page["page_totalrate_min"]=$pagetotals_dispmin["rate"];
					$page["page_totalrate_max"]=$pagetotals_dispmax["rate"];
		}
					$pagetotals_count = 0;
	$pagetotals_min = array();
	$pagetotals_max = array();
	$pagetotals_dispmin = array();
	$pagetotals_dispmax = array();
	$pagetotals_sum = array();
	$pagetotals_sum["id"]=0;
	$pagetotals_sum["username"]=0;
	$pagetotals_sum["blogfirstline"]=0;
	$pagetotals_sum["date"]=0;
	$pagetotals_sum["time"]=0;
	$pagetotals_sum["rate"]=0;
	$pagetotals_sum["comment"]=0;
}
Return current item: Blogs manager