<?php
include('header.inc.php');


$tablaleiro=adatleiro($leiro_type);

if(!isset($$leiro_type)){

	while (list($key, $val) = each($tablaleiro)) {
		if($tablaleiro[$key]["T_VIS"]=="true"){
			$fields[$key]="true";
		}else{
			$fields[$key]="false";
		}
		if($tablaleiro[$key]["T_ORD"]=="true"){
			$fields[$key."_ORD_"]="true";
			$fields[$key."_BY_"]=$tablaleiro[$key]["T_BY"];

			$orderby.=$key." ".$tablaleiro[$key]["T_BY"].", ";
		}
	}
	reset($tablaleiro);

}else{
	$fields=unserialize(base64_decode($$leiro_type));
	while (list($key, $val) = each($fields)) {
		if($fields[$key."_ORD_"]=="true"){
			$orderby.=$key." ".$fields[$key."_BY_"].", ";
		}
	}
	reset($fields);
}


$orderby=substr($orderby,0,strlen($orderby)-2);
if(strlen($orderby)<>0){
	$orderby=" ORDER BY " . $orderby;
}


$mydb = new db();

if ($leiro_type=="faliujsag")
{
	if (!$_REQUEST['osztas'])	$_REQUEST['osztas']=20;
	if (!$_REQUEST['szam'])	$_REQUEST['szam']=0;
	
	$mydb = new db();
	$stmt1="SELECT count(id) AS darab FROM kk_faliujsag ORDER BY datum DESC";
	$result1=$mydb->query($stmt1);
	while($row1 = mysql_fetch_object($result1)){
		$_REQUEST['darab'] = $row1->darab;
	}
	
	
	
	$stmt=$query . " ORDER BY datum DESC limit ".$_REQUEST['osztas']." offset ".$_REQUEST['szam'];
}
else
{
	$stmt=$query . $orderby;
}

$result=$mydb->query($stmt);

printf("
<B>%s</B>
<TABLE border='1' style='border-collapse: collapse' bordercolor='#CCCCCC' CELLPADDING='5' STYLE='background: #FFFFFF;'>
<TR>", $h3_title);

while (list($key, $val) = each($tablaleiro)) {
	if($fields[$key]=="true"){
		if($fields[$key."_ORD_"]=="true"){
			$by=$fields[$key."_BY_"];
		}
		printf("<TH style='font-size: 11px'>%s&nbsp;%s</TH>\n", $tablaleiro[$key]["TITLE"], $by);
		$by="";
	}
}



printf("
<TH style='font-size: 11px'>Admin</TH>
</TR>
");



while($row = mysql_fetch_object($result)){
	
	printf("<TR>");

	reset($tablaleiro);

	while (list($key, $val) = each($tablaleiro)) {
		if($fields[$key]=="true"){
			if($tablaleiro[$key]["TYPE"]=="RADIO"){
				$opt="OPT" . $row->$key;
				printf("<TD>%s</TD>\n", $tablaleiro[$key][$opt]);
			}else{
				printf("<TD>%s</TD>\n", $row->$key);
			}
		}
	}
	
	if ($leiro_type=="faliujsag")
	{
		printf("<TD><A HREF='%s?id=%s&osztas=".$osztas."&szam=".$szam."&lapszam=".$lapszam."&tizes=".$tizes."'>szerkeszt</a> | <A HREF='%s?id=%s&osztas=".$osztas."&szam=".$szam."&lapszam=".$lapszam."&tizes=".$tizes."'>törlés</a> | <A HREF='%s?id=%s&osztas=".$osztas."&szam=".$szam."&lapszam=".$lapszam."&tizes=".$tizes."'>végleges törlés</a></TD></TR>", $edit_script, $row->id, $delete_script, $row->id, $deletev_script, $row->id);
	}
	else
	{
		printf("<TD><A HREF='%s?id=%s'>szerkeszt</a> | <A HREF='%s?id=%s'>törlés</a></TD></TR>", $edit_script, $row->id, $delete_script, $row->id);
	}
}

printf("</TABLE>");

if ($leiro_type=="faliujsag")
{

if ($_REQUEST['darab'] > $_REQUEST['osztas']) {
	$lapszam=ceil($_REQUEST['darab']/$_REQUEST['osztas']);
	echo "<p align='center'>";
	if (!$_REQUEST['tizes']) $_REQUEST['tizes']=0;
	if ($_REQUEST['tizes']>0)
	echo "<a href='a_faliujsag.php?osztas=".$_REQUEST['osztas']."&szam=".($j*$_REQUEST['osztas'])."&lapszam=".($j)."&tizes=".($_REQUEST['tizes']-1)."'>előző 10...</a>&nbsp;&nbsp;";
	for ($j=($_REQUEST['tizes']*10);$j<(($_REQUEST['tizes']+1)*10);$j++)
	{
		if ($j<$lapszam)
		{
			if ($_REQUEST['lapszam']==$j)	echo ($j+1)."&nbsp;&nbsp;";
			else							echo "<a href='a_faliujsag.php?osztas=".$_REQUEST['osztas']."&szam=".($j*$_REQUEST['osztas'])."&lapszam=".($j)."&tizes=".($_REQUEST['tizes'])."'>".($j+1)."</a>&nbsp;&nbsp;";	
		}
	}
	if ($lapszam>(($_REQUEST['tizes']+1)*10))
		echo "&nbsp;&nbsp;<a href='a_faliujsag.php?osztas=".$_REQUEST['osztas']."&szam=".($j*$_REQUEST['osztas'])."&lapszam=".($j)."&tizes=".($_REQUEST['tizes']+1)."'>következő 10...</a>";
	echo "</p>";
}
 
} 

?>