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

$title = $TEXT['menu-btn29-title-film'];
$button = $TEXT['btn_filter'];
$action = "index.php";

require_once "../config_a.php";
require_once "../utils/functions.php";
require_once "../utils/top_adm_film.php";

if($result2['administrator'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm_film.php"; exit();}
if(strlen($_GET['k'])>8) {puterror($result2['skin'],$TEXT['error-paging1']); require_once "../utils/bottom_adm_film.php"; exit();}
if(strlen($_POST['seriya'])>255) {puterror($result2['skin'],$TEXT['error-ser2']); require_once "../utils/bottom_adm_film.php"; exit();}
if(strlen($_GET['seriya'])>255) {puterror($result2['skin'],$TEXT['error-ser2']); require_once "../utils/bottom_adm.php"; exit();}
if(!empty($_GET['seriya'])) {$_POST['seriya']= $_GET['seriya'];}

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

$ktblvis = $stop_r+10;
$str = $ktblvis/10;
?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post >
<table align="center" border="0" cellpadding="0" cellspacing="0" width="50%">
<tr align="right">
<td width="10%" align="left"><input size=20 maxlength=255 type=text name=seriya title='<?php echo $TEXT['tbl-ser']; ?>'></td>
<td align="left"><input class="button2" type=submit value='<?php echo $button; ?>' /></td>
<td align="right"><img alt='<?php echo $TEXT['add-new']; ?>' src="../skins/<?php echo $result2['skin']; ?>/add.png"><a class="bold_it" href="addform.php" title="<?php echo $TEXT['add-new-tit']; ?>"><?php echo $TEXT['add-new']; ?></a></td>
</tr>
</table>
<table align="center" class="table" border="1" cellpadding="3" cellspacing="0" width="50%">
<?php
 if(!empty($_POST['seriya']))
 {
 $seriya = " AND LOWER(seriya) LIKE LOWER('%".$_POST['seriya']."%')";
 $stranica = $TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
 $ser_pered = "&amp;seriya=".$_POST['seriya'];
 }
    else
    {
     $seriya = "";
     $stranica =$TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
     $ser_pered = "";
    }
     $query10 = "SELECT * FROM `tbl_seriya` WHERE use_prog='2' $seriya ORDER BY seriya LIMIT $lim_ogr";
     $result10 = mysqli_query($dbcnx,$query10);
     if(!$result10) {puterror($result2['skin'],$TEXT['error-tbl21']); require_once "../utils/bottom_adm_film.php"; exit();}
       $result_rows = mysqli_num_rows($result10);
       if($result_rows > 0)
         {
           echo " <thead>
              <tr class='tableheadercat'>
                 <td width='60%'>".$TEXT['tbl-ser']."</td>
                 <td colspan=2>".$TEXT['tbl-action']."</td>
              </tr>
             </thead><tbody id='tab'>";
             while($result_ser = mysqli_fetch_array($result10))
               {
              $edit_pic = "<img alt='".$TEXT['edit-new']."' src='../skins/".$result2['skin']."/edit.png'>";
              $edit = $edit_pic."&nbsp;<a href=editform.php?ser_id=".$result_ser['ser_id']." title='".$TEXT['edit-tit']."'>".$TEXT['edit-new']."</a>";

              $query_book_ser = mysqli_query($dbcnx,"SELECT COUNT(ser_id) AS co_ser_id FROM tbl_book WHERE ser_id='".$result_ser['ser_id']."'");
	      $coun_book_ser = mysqli_fetch_array($query_book_ser);
              if($coun_book_ser['co_ser_id'] > 0)
               {
                $delete_pic = "<img alt='".$TEXT['global-lock']."' src='../skins/".$result2['skin']."/nodelete.png'>";
                $delete =$delete_pic."&nbsp;".$TEXT['delete-new'];
               }
              else
                {
                 $delete_pic = "<img alt='".$TEXT['delete-new']."' src='../skins/".$result2['skin']."/delete.png'>";
                 $delete = $delete_pic."&nbsp;<a href=delete.php?ser_id=".$result_ser['ser_id']." title='".$TEXT['delete-tit']."'>".$TEXT['delete-new']."</a>";
                }
           ?>
           <tr>
              <td><?php echo $result_ser['seriya']; ?></td>
              <td><?php echo $edit; ?></td>
              <td><?php echo $delete; ?></td>
           </tr>
           <?php
               }
              $query_count = mysqli_query($dbcnx,"SELECT COUNT(ser_id) AS c_ser_id FROM tbl_seriya WHERE use_prog='2' $seriya");
	      $coun_rows = mysqli_fetch_array($query_count);
             ?>
           </tbody>
           <tfoot>
           <tr class='tableheadercat'>
           <td colspan=3 align="right"><?php echo $stranica; ?> | <?php echo $TEXT['size-count2']; ?> = <?php echo $result_rows; ?> | <?php echo $TEXT['size-razm']; ?>: <?php echo $coun_rows['c_ser_id']; ?></td>
           </tr>
           </tfoot>
         <?php
         }
?>
</table>
     <?php
             $pag = $coun_rows['c_ser_id']/10;
               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*10-10;
                      $kvis=$k+10;
                      $nvis=$k;
                      echo $pg = " <a class='zagolovok' href='index.php?k=".$k.$ser_pered."' title='".$TEXT['tbl-details4'].$nvis.$TEXT['tbl-details3'].$kvis."'>".$i."</a>";
                    }
                    else
                    {
                    $k = $i*10-10;
                    $kvis=$k+10;
                    $nvis=$k;
                    echo $pg = " <a href='index.php?k=".$k.$ser_pered."' 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*10-10;
                     if($k == $_GET['k']) {echo "<option selected value=index.php?k=".$k.$ser_pered.">".$j."</option>";}
                       else {echo "<option value=index.php?k=".$k.$ser_pered.">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
?>
</form>
<?php
  require_once "../utils/bottom_adm_film.php";
?>