<?php
define("F_TABLE", "kk_faliujsag");

function Pages($count_of_row,$l, $sortby) {
	global $PHP_SELF;

	printf("Üzenetek száma: %s | Oldalak száma: ", $count_of_row);

	$count_of_page=ceil($count_of_row/10);

	$i=1;

	if ($l<>0) {
	$prev=$l-10;
	printf("<a href=$PHP_SELF?l=$prev&sortby=$sortby><img src=arrow_lf.jpg border=0></a>\n");
	}


	while ($i <= $count_of_page) {
		$limit=$i * 10 - 10;

		if ($limit==$l) {
			printf("<span><b>$i</b></span>\n");}
		else {
			printf("<a href=$PHP_SELF?l=$limit&sortby=$sortby>$i</a>\n");
		}
		$i++;
	}


	if ($limit<>$l) {
	$next=$l+10;
	printf("<a href=$PHP_SELF?l=$next&sortby=$sortby><img src=arrow_rg.jpg border=0></a>\n");
	}

	printf("<br/>");
}


include_once('db.inc.php');

if (!isset($l)) {
	$l=0;
}

$mydb = new db();
$lightstmt=sprintf("SELECT COUNT(*) AS darab FROM %s WHERE deleted=2", F_TABLE);
$result=$mydb->query($lightstmt);

$row = mysql_fetch_object($result);
$count_of_row=$row->darab;
mysql_free_result($result);

if (isset($sortby)) {
	switch ($sortby) {
		case "dateasc":
			$stmt=sprintf("SELECT * FROM %s WHERE deleted=2 ORDER BY datum ASC LIMIT $l, 10", F_TABLE);
		break;
		default:
			$stmt=sprintf("SELECT * FROM %s WHERE deleted=2 ORDER BY datum DESC LIMIT $l, 10", F_TABLE);
	} // endswitch
} else {
	$stmt=sprintf("SELECT * FROM %s WHERE deleted=2 ORDER BY datum DESC LIMIT $l, 10", F_TABLE);
} // end sortif


$result=$mydb->query($stmt);
$form_no_cache=TRUE;
//include('header.inc.php');

printf("<p>A gazdasági ügyek gyakran nem általánosíthatók. E faliújság alkalmat ad az egyéni problémák megbeszélésére, a közös gondok megoldására, valamint a tapasztalatok megosztására.</p>
");

printf("
<a href=\"#ujuzenet\"><B>Új hozzászólás</B></a> | Rendezés dátum szerint: <a href=\"$PHP_SELF?sortby=dateasc\"><B>növekvő</B></a>/<a href=\"$PHP_SELF?sortby=datedesc\"><B>csökkenő</B></a> | 
");

pages($count_of_row, $l, $sortby);


while ($row = mysql_fetch_object($result)) {
	$id=$row->id;
	$email=stripslashes($row->email);
	if($email<>""){
		$name=sprintf("<a href=mailto:%s>%s</a>", $email, stripslashes($row->name));
	}else{
		$name=stripslashes($row->name);
	}
	$date=stripslashes($row->datum);
	$country=stripslashes($row->country);
	$city=stripslashes($row->city);
	$homepage=stripslashes($row->homepage);
	if($homepage<>""){
		$homepage=sprintf("<a href=%s target=_blank>%s</a>", $homepage, $homepage);
	}

	//$date=sprintf("%04d. %02d. %02d. %02d:%02d", substr($date,0,4), substr($date,4,2), substr($date,6,2), substr($date,8,2), substr($date,10,2));

	include('faliujsag.header.inc.php');

	printf("<p>");
	printf(nl2br(stripslashes($row->memo)));
	printf("</p>");
	include('faliujsag.footer.inc.php');

} // end while

mysql_free_result($result);

pages($count_of_row, $l, $sortby);

include('faliujsag.form.inc.php');

//include('footer.inc.php');

?>