<?php
  ///////////////////////////////////////////////////
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////
  require_once "utils/chlang_osn.php";

  $title = $TEXT['book-otziv2'];

  require_once "config.php";
  require_once "utils/functions.php";
  require_once "utils/top_film.php";

  if($result2['administrator'] == 0 && $result2['user'] == 0) {puterror2($result2['skin'],$TEXT['error-loginform2']); require_once "utils/bottom_film.php"; exit();}

  if(empty($_GET['film_id'])) {puterror2($result2['skin'],$TEXT['error-film5']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_GET['film_id'])>255) {puterror2($result2['skin'],$TEXT['error-film6']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_GET['k'])>8) {puterror($result2['skin'],$TEXT['error-paging1']); require_once "../utils/bottom_film.php"; exit();}
  $_GET['film_id'] = rep($_GET['film_id']);
  $_GET['k'] = rep($_GET['k']);

  if(empty($_GET['k'])) {$_GET['k']=0;}
  $stop_r = $_GET['k'];
  if($stop_r == 0) {$lim_ogr = "5";}
   else {$lim_ogr = $stop_r.",5";}

  $ktblvis = $stop_r+5;
  $str = $ktblvis/5;

$query_iskh = "SELECT film_name, photo_film, autors FROM tbl_film WHERE film_id = '".$_GET['film_id']."' ";
 $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror2($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
      $result_iskh2 = mysqli_fetch_array($result_iskh);
      $autors = $result_iskh2['autors'];

      $sm = preg_replace("/\.\.+./","",$result_iskh2['photo_film']);
      if(!empty($result_iskh2['photo_film']) && file_exists($sm)) {$result_image = "<img alt='".$TEXT['global-alt']."' src='".$sm."' />";}
        else {$result_image =  "<img alt='".$TEXT['global-alt']."' align='top' src='skins/".$result2['skin']."/nophoto.png' />";}

?>
<table align="center" width="98%" border="0">
 <tr><td>&nbsp;<a class="zagolovok" href='film-info.php?film_id=<?php echo $_GET['film_id']; ?>' title='<?php echo $TEXT['aut-title-info']; ?>'><?php echo rep_back($result_iskh2['film_name']); ?></a>&nbsp;<span class="opis">&#040;<?php echo $autors; ?>&#041;</span></td></tr>
</table>
<hr width="98%" />
<table align="center" width="98%" border="0">
<tr>
<td width="5%" valign="top">
 <table align="left" border="0" width="100%">
  <tr><td><?php echo $result_image; ?></td></tr>
 </table>
</td>
<td width="65%" valign="top" align="right">
 <?php
 $query_b1 = mysqli_query($dbcnx,"SELECT COUNT(otz_id) AS co_otz_id FROM tbl_otziv WHERE book_id='".$_GET['film_id']."' AND login_id='".$result2['login_id']."' AND use_prog = '2'");
  $coun_b = mysqli_fetch_array($query_b1);
    if($coun_b['co_otz_id'] > 0) {echo "<img alt='".$TEXT['edit-tit']."' src='skins/".$result2['skin']."/edit.png' /><a class='bold_it' href='film-editform_otz.php?film_id=".$_GET['film_id']."' title='".$TEXT['book-otziv-edit']."'>".$TEXT['book-otziv-edit']."</a>";}
     else {echo "<img alt='".$TEXT['add-new']."' src='skins/".$result2['skin']."/add.png' /><a class='bold_it' href='film-addform_otz.php?film_id=".$_GET['film_id']."' title='".$TEXT['book-otziv-add']."'>".$TEXT['book-otziv-add']."</a>";}
 ?>
<fieldset>
 <legend align="left" title="<?php echo $TEXT['book-otziv2']; ?>"><?php echo $TEXT['book-otziv2']; ?></legend>
<table align="left" width="100%" border="0">
<?php
$query_otziv = "SELECT 
 tbl_otziv.*,
 YEAR(tbl_otziv.otz_data) AS otz_data_year,
 MONTH(tbl_otziv.otz_data) AS otz_data_month,
 DAY(tbl_otziv.otz_data) AS otz_data_day,
 tbl_logins.familiya,
 tbl_logins.name,
 tbl_logins.otchestvo
 FROM tbl_otziv
 JOIN tbl_logins ON tbl_otziv.login_id=tbl_logins.login_id
 WHERE tbl_otziv.book_id = '".$_GET['film_id']."' AND tbl_otziv.use_prog = '2' LIMIT $lim_ogr";
 $result_otz = mysqli_query($dbcnx,$query_otziv);
  if(!$result_otz) {puterror2($result2['skin'],$TEXT['error-tbl22']); require_once "utils/bottom_film.php"; exit();}
    $otziv_num = mysqli_num_rows($result_otz);
    if($otziv_num == 0) {echo "<tr><td class='informcntr'>".$TEXT['film-otziv3']."&nbsp;</td></tr>";}
     else
     {
      while($result_otziv = mysqli_fetch_array($result_otz))
       {
       $date_day = $result_otziv['otz_data_day'];
       $date_month = $result_otziv['otz_data_month'];
       $date_year = $result_otziv['otz_data_year'];
       if($date_year == "0000" || $date_year == "1970") {$data_r = "---";}
        else {$data_r = $date_day." ".$month[$date_month]." ".$date_year." ".$TEXT['year2'];}

       if($result_otziv['otziv'] == "" && $result2['login_id'] == $result_otziv['login_id']) {$otziv = $TEXT['film-otziv6']."<a class='bold_it' href='film-editform_otz.php?film_id=".$_GET['film_id']."' title='".$TEXT['book-otziv-edit']."'>".$TEXT['book-otziv-edit']."</a>&raquo;";}
        else {$otziv = "<br />&nbsp;<span class='opis'>".nl2br($result_otziv['otziv'])."</span>";}

      if($result_otziv['otziv'] == "" && $result2['login_id'] == $result_otziv['login_id']) {echo "<tr><td class='informlft'>".$result_otziv['familiya']." ".$result_otziv['name']." ".$result_otziv['otchestvo']."<span class='informlftdat'> &#040;".$data_r." &#124; ".$TEXT['book-rating']." => ".$result_otziv['usr_rating']." &#041;</span>".$otziv."<hr align='left' width='55%' /></td></tr>";}
       elseif($result_otziv['otziv'] !== "" && $result2['login_id'] == $result_otziv['login_id']) {echo "<tr><td class='informlft'>".$result_otziv['familiya']." ".$result_otziv['name']." ".$result_otziv['otchestvo']."<span class='informlftdat'> &#040;".$data_r." &#124; ".$TEXT['book-rating']." => ".$result_otziv['usr_rating']." &#041;</span>".$otziv."<hr align='left' width='55%' /></td></tr>";}
        elseif($result_otziv['otziv'] !== "" && $result2['login_id'] !== $result_otziv['login_id']) {echo "<tr><td class='informlft'>".$result_otziv['familiya']." ".$result_otziv['name']." ".$result_otziv['otchestvo']."<span class='informlftdat'> &#040;".$data_r." &#124; ".$TEXT['book-rating']." => ".$result_otziv['usr_rating']." &#041;</span>".$otziv."<hr align='left' width='55%' /></td></tr>";}
       else {echo "";}
      }
     }
?>
</table>
</fieldset>
</td></tr>
</table>
     <?php
       $query_count = mysqli_query($dbcnx,"SELECT COUNT(otz_id) AS c_otz_id FROM tbl_otziv WHERE book_id = '".$_GET['film_id']."' AND use_prog = '2'");
	       $coun_rows = mysqli_fetch_array($query_count);
               $pag = $coun_rows['c_otz_id']/5;
               if($pag<1) {$pag = ceil($pag);}
                else
                {
                 ?>
                  <hr size="3" width="98%" />
                  <table align="center" border="0" cellpadding="0" cellspacing="0" width="60%" >
                   <tr align="center">
                    <td>
                <?php
                $pag=ceil($pag);
                $strn = $str-5;
                if($strn<1) {$strn=1;}
                $strk = $str+5;
                for($i=$strn; $i<=$pag; $i++)
                 {
                  if($i<=$strk)
                  {
                    if($i==$str)
                    {
                      $k = $i*5-5;
                      $kvis=$k+5;
                      $nvis=$k;
                      echo $pg = " <a class='zagolovok' href='otziv.php?k=".$k."&amp;film_id=".$_GET['film_id']."' title='".$TEXT['tbl-details4'].$nvis.$TEXT['tbl-details3'].$kvis."'>".$i."</a>";
                    }
                    else
                    {
                    $k = $i*5-5;
                    $kvis=$k+5;
                    $nvis=$k;
                    echo $pg = " <a href='otziv.php?k=".$k."&amp;film_id=".$_GET['film_id']."' title='".$TEXT['tbl-details4'].$nvis.$TEXT['tbl-details3'].$kvis."'>[".$i."]</a>";
                    }
                  }
                 }
                 ?>
                    <select name='k' onchange=window.location.href=this.options[this.selectedIndex].value;>
                    <?php
                    for($j=1; $j<=$pag; $j++)
                    {
                     $k = $j*5-5;
                     if($k == $_GET['k']) {echo "<option selected value=otziv.php?k=".$k."&amp;film_id=".$_GET['film_id'].">".$j."</option>";}
                       else {echo "<option value=otziv.php?k=".$k."&amp;film_id=".$_GET['film_id'].">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
  require_once "utils/bottom_film.php";
?>