<?
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");
include("./includes/bbcode.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 );




//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

//poeminfo info
$id= trim($_GET['poemid']);
$cleanid = strip_tags($id);
if(! is_numeric($cleanid)) { die("ERROR : Not Found"); }
$selectpoem = mysql_db_query("$dbName", "SELECT * FROM `divan`  WHERE `divan_id` = '$cleanid'") ;
while ($pinfo =  @mysql_fetch_assoc($selectpoem)){
$poemname= $pinfo[divan_title];
$poemcontaining= $pinfo[divan_containing];
$poemdate= $pinfo[divan_date];
$poemcount = $pinfo[divan_count];
$poemgroup = $pinfo[divan_group];
$poembackg = $pinfo[divan_back];
$poemcatid =  $pinfo[cat_id];
  $sounds = $pinfo[divan_sound];
  $formats = $pinfo[poem_format];
}

if(($sounds)!=('')){

$realplayer = "
<div align=\"center\">
            <center>
<embed name='avplayer'
                 src='$sounds'
                 width='305' height='40'  type='audio/x-pn-realaudio-plugin'
                 controls='ControlPanel,StatusBar' pluginspage='www.real.com'
                 autostart='True' loop='0'>
</embed>
</center>
            </div>
";

}else{
$realplayer = "";
}

$javacode =  "<SCRIPT language=javascript src=\"javascript.js\" type=text/javascript></SCRIPT>";

$exp = $_SERVER['HTTP_USER_AGENT'];
$exp = explode("Firefox",$exp);
$exp = $exp[1];
if(($exp) == ('')){
 $poemcode = "<SCRIPT language=javascript src=\"poetry.js\" type=text/javascript></SCRIPT>";


$thispoem = bbcode($poemcontaining);
$thispoem = nl2br($thispoem);
$thispoem = "

<TABLE id=Table_01 dir=ltr cellSpacing=0 cellPadding=0 width=400 align=center border=0>
        <TBODY>
        <TR>
          <TD>
           <div class='font' tag=' font=\"Tahoma,1,sienna,normal\" bkcolor=\"transparent\" bkimage=\"\" border=\"outset,3,gray\" type=$formats line=200% align=center use=ex length=0 char=\"\" num=\"0,black\" filter=\"\"' style='display:none'>
              $thispoem
				</DIV>
            <SCRIPT>doPoetry()</SCRIPT>
          </TD>
          </TR>
        </TBODY></TABLE>

";
 }else{
 $poemcode = "<SCRIPT language=javascript src=\"firefox.js\" type=text/javascript></SCRIPT>";
$thispoem= $poemcontaining;
$thispoem = nltobr($thispoem);
$thispoem = str_replace("=","&nbsp;&nbsp;&nbsp;&nbsp;",$thispoem);
$thispoem = "
<div style=\"font-family: \"Times New Roman\", Times, serif; font-size: medium;\" align=\"center\"><b>$thispoem</b></div>
 <br><div align=center onclink=\"alert('عفوا التنسيق غير فعل علي متصفح الفايرفوكس');\"><i><font type='tahome' color='red'>التنسيق غير مفعل علي متصفح الفايرفوكس</font></i></div>
";
 }


$selectcats = mysql_db_query("$dbName", "SELECT * FROM `cat`  WHERE `cat_id` = '$poemcatid'") ;
 while ($pcatinfo =  @mysql_fetch_assoc($selectcats)){
 $catname =  $pcatinfo[cat_name];

 }
@mysql_free_result($selectpoem);

//gatcat info

$subtitle = "&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;$poemname  ";
  echo $tpl->display("headerinclude.html");


//header
//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);


echo $tpl->display("header.html");


 echo $tpl->display("bodyinclude.html");
 if (($close) == ('yes')){
echo $tpl->display("message.html");
traidntright();
echo $tpl->display("footer.html");
exit();
}

 if(($catname)==('')){
  $message = "عفوا ليس لديك صلاحيات مشاهده القصيدة";
echo $tpl->display("message.html");
traidntright();
echo $tpl->display("footer.html");
exit();
}


if (($poemgroup) != ('1')){
$message = $lang[gpoem];
echo $tpl->display("message.html");
}else{


$selectidpoem = mysql_db_query("$dbName", "SELECT * FROM `divan`  WHERE `divan_id` = '$cleanid'") ;
$totalpoumincat = mysql_affected_rows();
if(($totalpoumincat)==('0')){
$message = $lang[poemnotfound];
echo $tpl->display("message.html");
}else{
//get poem
while ($vdivan =  @mysql_fetch_assoc($selectidpoem)){
$pi[] =   $vdivan  ;
}

if (($commentallow)==('yes')){
addcom($addcom,$stylepath);
}else{
 $addcom = $lang[disalowcomment];
}


$updatcatcount = @mysql_db_query("$dbName", "update `divan` SET `divan_count` =divan_count+1  WHERE `divan_id` = '$cleanid';  ") ;
//get poum
$rating =  pullRating($cleanid,true,false,true);
echo "<br>".$tpl->display("viewpoem.html");
//get comment
$getc = @mysql_db_query("$dbName", "SELECT * FROM `comments` WHERE `comments`.`divan_id` = '$cleanid' and `comment_group` ='1' ORDER BY `comments`.`comment_id` ASC ") ;
$totalcoments = mysql_affected_rows();
if(($totalcoments)!=('0')){
while ($dpc =  @mysql_fetch_assoc($getc)){
$cpd[] =   $dpc  ;
}


echo $tpl->display("comments.html");
}
}
}

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

ob_end_flush();
?>