<?
ob_start("ob_gzhandler");
include("./includes/config.php");
include("./lang/arabic.php");
include("./includes/function.php");
include("./includes/online.php");
include("./includes/easytemplate.php");
include("./includes/inquiry.php");
$PhpGroup_style['def_style'] = "designs/$style";
$stylepath= $PhpGroup_style['def_style'];
$tpl = new EasyTemplate;
$tpl->Temp = $PhpGroup_style['def_style'];
$tpl->Cache = "easycache";

//get the can name in the right page
$selectc = @mysql_db_query("$dbName", "SELECT * FROM `cat`  WHERE `cat_group` = '1' ORDER BY `cat`.`cat_display` ASC  ") ;
while ($s =  @mysql_fetch_assoc($selectc)){
$cat[] =   $s  ;
}
@mysql_free_result($selectc);

//loginbox
loginbox( $login );

function short_string($a,$h)
{
if(strlen($a)>$h )
{
echo "".substr($a,0,$h)." ...";
}
return $a;
  }

//get the last new poem
$selectnewdivan = mysql_db_query("$dbName", "SELECT * FROM `divan`  WHERE `divan_group` = '1' ORDER BY `divan_id` DESC LIMIT 10") ;
while ($ndivan =  @mysql_fetch_assoc($selectnewdivan)){
$nd[] =   $ndivan  ;
}

@mysql_free_result($selectnewdivan);



//statistics
$selectcount= mysql_db_query("$dbName", "SELECT * FROM  cat;") ;
$totalcat = mysql_affected_rows();
@mysql_free_result($selectcount);
$selectcount= mysql_db_query("$dbName", "SELECT * FROM  divan;") ;
$totaldivan = mysql_affected_rows();
@mysql_free_result($selectcount);
$selectcount= mysql_db_query("$dbName", "SELECT * FROM  users;") ;
$totalusers = mysql_affected_rows();
@mysql_free_result($selectcount);

//getcat info

$id= trim($_GET['catid']);
$cleanid = strip_tags($id);
if(! is_numeric($cleanid))  { die("ERROR : Not Found"); }
$selectcat = mysql_db_query("$dbName", "SELECT * FROM `cat`  WHERE `cat_id` = '$cleanid'") ;
while ($cinfo =  @mysql_fetch_assoc($selectcat)){
$catname = $cinfo[cat_name];
$catmeta = $cinfo[cat_meta];
$catuser = $cinfo[cat_user];
$catgroup = $cinfo[cat_group];
$catcount = $cinfo[cat_count];
$imgbg = $cinfo[divan_back];
}
@mysql_free_result($selectcat);

//gatcat info

$subtitle = "&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;$catname  ";
$submeta = ",$catmeta";

echo $tpl->display("headerinclude.html");
//header
echo $tpl->display("header.html");
//endheader
 echo $tpl->display("bodyinclude.html");

 if (($close) == ('yes')){
echo $tpl->display("message.html");
traidntright();
echo $tpl->display("footer.html");
exit();
}
//page body
if (($catgroup) == ('2')){
$message = $lang[hidecat];
echo $tpl->display("message.html");
}else{
 if(($catuser)==('yes')){
 $addpoem = "<a href='addpoem-$cleanid.html'><img  src='$stylepath/images/newthread.gif' border='0' alt='اضافه قصيدة' ></a>";
 }

//بداية تقسيم الصفحة
$page = (!isset($_GET['page']) ? 1 : intval($_GET['page']));
$page =(intval($_GET['page'])<=0 ? 1 : $page );
$numpage=50; #العدد بكل صفحة
$limit=($page * $numpage) - $numpage;
//نهاية

$selectcatpoem = mysql_db_query("$dbName", "SELECT * FROM `divan` WHERE `cat_id`='$cleanid' and `divan_group` ='1' ORDER BY `divan`.`divan_id` DESC  limit  $limit,$numpage   ") ;
$totalpoumincat = mysql_affected_rows();
if(($totalpoumincat)==('0')){
echo "<div align=\"right\">$addpoem</div>";
$message = $lang[nopoem];
echo $tpl->display("message.html");

}else{
//get poem
while ($catdivan =  @mysql_fetch_assoc($selectcatpoem)){
$cp[] =   $catdivan  ;
$diid = $catdivan[divan_id];
}



 //
$selectcatpoemt = mysql_db_query("$dbName", "SELECT * FROM `divan` WHERE `cat_id`='$cleanid' ") ;

$totalpoum =mysql_affected_rows();

$allpoum= $totalpoum/$numpage;


 //

$updatcatcount = @mysql_db_query("$dbName", "update `cat` SET `cat_count` =cat_count+1 WHERE `cat_id`= '$cleanid';  ") ;
//get poum
echo "<br>".$tpl->display("viewcat.html");

}
}
//page body
//page left
//get most divan visit

traidntright();
echo $tpl->display("footer.html");
//page footer

ob_end_flush();
?>