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

function pl_sort1($result){


	$diphthongs=array("cs", "dz", "gy", "ly", "ny", "sz", "ty", "zs");

	$i=0;
	while ($row=mysql_fetch_object($result)) {

		$name=$row->megnevezes;
		$url=$row->url;
		$arr_forditok[$i][0]=$name;
		$arr_forditok[$i][4]=$url;
		$arr_forditok[$i][2]=$row->id;
		$arr_forditok[$i][3]=$row->nev;
		$arr_forditok[$i][5]=$row->jovahagyva;
		$arr_forditok[$i][100]=$row->statusz;
		$arr_forditok[$i][6]=$row->datum;
		$arr_forditok[$i][101]=$row->ip;

		switch (substr(strtolower($name), 0, 1)) {
			case "á": $arr_forditok[$i][1]="a"; break;
			case "é": $arr_forditok[$i][1]="e"; break;
			case "í": $arr_forditok[$i][1]="i"; break;
			case "ó": $arr_forditok[$i][1]="o"; break;
			case "ő": $arr_forditok[$i][1]="ö"; break;
			case "ú": $arr_forditok[$i][1]="u"; break;
			case "ű": $arr_forditok[$i][1]="ü"; break;
			default: $arr_forditok[$i][1]=substr(strtolower($name), 0, 1);
		}
		for ($j=0; $j<count($diphthongs); $j++) {
			if (substr(strtolower($name), 0, 2)==$diphthongs[$j])
				$arr_forditok[$i][1]=substr(strtolower($name), 0, 2);
		}
		if (substr(strtolower($name), 0, 3)=="dzs")
			$arr_forditok[$i][1]=substr(strtolower($name), 0, 3);

		$i++;
	}

	usort($arr_forditok, "sort_multidimension_hungarian");
/*
print("<pre>");
	print_r($arr_forditok);
print("</pre>");
*/

return $arr_forditok;

}
define('NEXTVAL', '10');	// hany darab legyen egy oldalon
	if($next=="" || !isset($next)){
		$next=0;
	}

$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();

$stmt=$query . $orderby;

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


		$chunk_rows = array_chunk($rows, NEXTVAL);

        if (!isset($page)) {
             $page = 0;
            }
        $rows = $chunk_rows[$page];



/*
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>
");*/

?>
<TABLE border='1' width="100%" style='border-collapse: collapse' bordercolor='#CCCCCC' CELLPADDING='3' STYLE='background: #FFFFFF;'>
<TR><TH style='font-size: 11px'>Megnevezés&nbsp;</TH>
<TH style='font-size: 11px'>URL&nbsp;</TH>
<TH style='font-size: 11px'>Név&nbsp;</TH>
<TH style='font-size: 11px'>Üzemeltető<br/>által<br/>jóváhagyva&nbsp;</TH>
<TH style='font-size: 11px'>Ajánlatkérő<br/>által<br/>jóváhagyva&nbsp;</TH>
<TH style='font-size: 11px'>Dátum&nbsp;</TH>
<TH style='font-size: 11px'>IP cím&nbsp;</TH>

<TH style='font-size: 11px'>Admin</TH>
</TR>
<?

	foreach ($rows as $key => $value)
	{
	printf("<TR>");
	printf("<TD>%s</TD>", stripslashes($value[0]));
	printf("<TD>%s</TD>", stripslashes($value[4]));
	printf("<TD>%s</TD>", stripslashes($value[3]));
	if ($value[5]==1)	printf("<TD>igen</TD>");
	else				printf("<TD>nem</TD>");
	if ($value[100]==1)	printf("<TD>igen</TD>");
	else				printf("<TD>nem</TD>");
	printf("<TD>%s</TD>", $value[6]);
	printf("<TD>%s</TD>", $value[101]);
	
	printf("<TD><A HREF='%s?id=%s'>szerkeszt</a> | <A HREF='%s?id=%s'>törlés</a></TD></TR>", $edit_script, $value[2], $delete_script, $value[2]);
	printf("</TR>");

	}

printf("</TABLE>");

        $jni = "Oldalak:<BR>";
        if ($page>0) {
            $jni .= sprintf("<A HREF=\"%s?page=%s\">&laquo;</A> | ", $PHP_SELF, $page-1);
            }

        for ($j=0;$j<sizeof($chunk_rows);$j++){
            if ($page == $j) {
                $jni .= sprintf("%s | ", $j+1);
            } else {
                $jni .= sprintf("<A HREF=\"%s?page=%s\">%s</A> | ", $PHP_SELF, $j, $j+1);
                }
            }

        if ($page<sizeof($chunk_rows)-1) {
            $jni .= sprintf("<A HREF=\"%s?page=%s\">&raquo;</A> | ", $PHP_SELF, $page+1);
            }
     
    	printf(substr($jni, 0, strlen($jni)-2));

?>
