<img src="images/dokumentumtar.gif" width=339 height=27 alt="">
			<table border="0" cellpadding="0" cellspacing="5" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber6">
              <tr>
                <td width="100%"><p>&nbsp;</p>
<p>Válogasson kedvére a dokumentumok között.</p><p>&nbsp;</p>
<?

define('NEXTVAL', '15');	// hany darab legyen egy oldalon

include_once('db.inc.php');
include_once('pl_sort.inc.php');


function p_lista(){

	$mydb = new db();
	$stmt="SELECT * FROM kk_doctopic ORDER BY name";
	$result=$mydb->query($stmt);

	$numrows=mysql_num_rows($result);

	while ($row = mysql_fetch_object($result)) {
		$i++;
		if($i<($numrows/2)+1){
			$elso[]=$row->name;
			$elso_id[]=$row->id;
		} else {
			$masodik[]=$row->name;
			$masodik_id[]=$row->id;
		}
	}


	printf("<table border='0' width='100%%' cellspacing='10'>");

	for($j=0;$j<($numrows/2);$j++){
		printf("<tr><td width=50%%><a href=$PHP_SELF?c=%s>%s %s</a></td><td width=50%%><a href=$PHP_SELF?c=%s>%s %s</a></td></tr>", $elso_id[$j], $elso[$j], c_lista($elso_id[$j]), $masodik_id[$j], $masodik[$j], c_lista($masodik_id[$j]));
	}

	printf("</table>\n");
}


function c_lista($c){

	global $filter;

	if($c==0 || !isset($c)){
		return null;
		exit;
	}

	$mydb = new db();

    $stmt="SELECT COUNT(*) AS darab FROM kk_upload WHERE doctopic_id=$c AND letoltheto=1";

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

	$row = mysql_fetch_object($result);

	return "(".$row->darab.")";

}


function in_array_letter($s_needle, $a_haystack) {

    while (list($key, $value)=each($a_haystack)) {
        $r_letter = strtolower(substr($value[0], 0, strlen($s_needle)));

        if (is_numeric($r_letter) && $s_needle === "0") {
            return TRUE;
            }

        if (strtolower($r_letter) == strtolower($s_needle)) {
            return TRUE;
            }
        }

return FALSE;
}



// main



// lista
if(!isset($c)){

	p_lista();

} else {



	// kategorialista

	$mydb = new db();
	$stmt="SELECT name FROM kk_doctopic WHERE id=$c";
	$result=$mydb->query($stmt);
	$row = mysql_fetch_object($result);

	printf("<h5>%s</h5><P>", $row->name);


	if($next=="" || !isset($next)){
		$next=0;
	}



	$stmt="SELECT * FROM kk_upload WHERE doctopic_id=$c AND letoltheto=1 ORDER BY cim";

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

	    // abc lista kiirasa
/*
        $letter="";
        $i=0;
        $ini = sprintf("<A HREF=\"%s?c=%s&filter=%s\">Mind</A> | ", $PHP_SELF, $c, $filter);
        while (list($key, $val)=each($rows)) {
            if (is_numeric($val[1])) {
                $val[1] = '0';
                }

            if ($letter!=$val[1]) {
                $ini.=sprintf("<A HREF=\"%s?c=%s&filter=%s&abc=%s\">%s</A> | ", $PHP_SELF, $c, $filter, $val[1], letter_title($val[1]));
                $i++;
                }
            $letter=$val[1];
        }
    	printf(substr($ini, 0, strlen($ini)-2));
        printf("<hr color=#c1c1a6 size=1>");
*/

        $ini = sprintf("<A HREF=\"%s?c=%s\">Mind</A> | ", $PHP_SELF, $c);
        $all_letter = all_letter();
        while (list($key, $val)=each($all_letter)) {
                $b_link = in_array_letter($val, $rows);
                if ($b_link) {
                    $ini.=sprintf("<A HREF=\"%s?c=%s&abc=%s\">%s</A> | ", $PHP_SELF, $c, $val, letter_title($val));
                } else {
                    $ini.=sprintf("%s | ", letter_title($val));
                    }
            }
    	printf(substr($ini, 0, strlen($ini)-2));
        printf("<hr color=#c1c1a6 size=1>");


        // csak az adott betuvel kezdodoek
        if (isset($abc) && $abc!='') {
            reset($rows);
            while (list($key, $val)=each($rows)) {
                if (is_numeric($val[1])) {
                    $val[1] = '0';
                    }

                if ($val[1] == $abc) {
                    $new_rows[$key] = $val;
                    }

                }
        } else {
            $new_rows = $rows;
            }


        // oldalakra tores
        $chunk_rows = array_chunk($new_rows, NEXTVAL);

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


        // maguk a cegek
		foreach ($rows as $key => $value){
   			printf("<a href=dokumentumtar_more.php?id=%s>%s</a>", $value[2], $value[0]);
            printf("<hr color=#c1c1a6 size=1>");
    		}


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

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

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

?>
                </td>
              </tr>
            </table>




