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

$title = $TEXT['menu-btn17-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['cicle'])>255) {puterror($result2['skin'],$TEXT['error-cicle1']); require_once "../utils/bottom_adm_film.php"; exit();}
if(strlen($_GET['cicle'])>255) {puterror($result2['skin'],$TEXT['error-cicle1']); require_once "../utils/bottom_adm.php"; exit();}
if(!empty($_GET['cicle'])) {$_POST['cicle']= $_GET['cicle'];}

$_GET['k'] = rep($_GET['k']);
$_POST['cicle'] = rep($_POST['cicle']);
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=cicle title='<?php echo $TEXT['tbl-cicle']; ?>'></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['cicle']))
 {
 $cicle = " AND LOWER(cicle) LIKE LOWER('%".$_POST['cicle']."%')";
 $stranica = $TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
 $cicl_pered = "&amp;cicle=".$_POST['cicle'];
 }
    else
    {
     $cicle = "";
     $stranica =$TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
     $cicl_pered = "";
    }
     $query10 = "SELECT * FROM `tbl_cicle` WHERE use_prog='2' $cicle ORDER BY cicle LIMIT $lim_ogr";
     $result10 = mysqli_query($dbcnx,$query10);
     if(!$result10) {puterror($result2['skin'],$TEXT['error-tbl5']); 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-cicle']."</td>
                 <td colspan=2>".$TEXT['tbl-action']."</td>
              </tr>
             </thead><tbody id='tab'>";
             while($result_cicle = mysqli_fetch_array($result10))
               {
              $cicle_srch = "<a href=book-srch.php?cicle_id=".$result_cicle['cicle_id']." title='".$TEXT['search-all-cicl']."'>".$result_cicle['cicle']."</a>";
              $edit_pic = "<img alt='".$TEXT['edit-new']."' src='../skins/".$result2['skin']."/edit.png' />";
              $edit = $edit_pic."&nbsp;<a href=editform.php?cicle_id=".$result_cicle['cicle_id']." title='".$TEXT['edit-tit']."'>".$TEXT['edit-new']."</a>";

              $query_book_cicle = mysqli_query($dbcnx,"SELECT COUNT(cicle_id) AS co_cicle_id FROM tbl_book WHERE cicle_id='".$result_cicle['cicle_id']."'");
	       $coun_book_cicle = mysqli_fetch_array($query_book_cicle);
               if($coun_book_cicle['co_cicle_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?cicle_id=".$result_cicle['cicle_id']." title='".$TEXT['delete-tit']."'>".$TEXT['delete-new']."</a>";
               }
           ?>
           <tr>
              <td><?php echo $cicle_srch; ?></td>
              <td><?php echo $edit; ?></td>
              <td><?php echo $delete; ?></td>
            </tr>
           <?php
               }
              $query_count = mysqli_query($dbcnx,"SELECT COUNT(cicle_id) AS c_cicle_id FROM tbl_cicle WHERE use_prog='2' $cicle");
	      $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_cicle_id']; ?></td>
           </tr>
           </tfoot>
           <?php
         }
?>
</table>
     <?php
              $pag = $coun_rows['c_cicle_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.$cicl_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.$cicl_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.$cicl_pered.">".$j."</option>";}
                       else {echo "<option value=index.php?k=".$k.$cicl_pered.">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>

                 <?php
                }
?>
</form>
<?php
  require_once "../utils/bottom_adm_film.php";
?>