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

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

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

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

$_GET['k'] = rep($_GET['k']);
$_POST['book_name'] = rep($_POST['book_name']);
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="60%" >
<tr>
<td width="10%" align="left"><input size=20 maxlength=255 type=text name=book_name title='<?php echo $TEXT['book_name']; ?>'></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="add_form_init.php" title="<?php echo $TEXT['add-new-tit']; ?>"><?php echo $TEXT['add-new']; ?></a></td>
</tr>
</table>
<table align="center" border="1" cellpadding="3" cellspacing="0" width="60%" >
<?php
 if(!empty($_POST['book_name']))
 {
 $book_name = " WHERE LOWER(book_name) LIKE LOWER('%".$_POST['book_name']."%')";
 $book_name_tmp = " AND LOWER(book_name) LIKE LOWER('%".$_POST['book_name']."%')";
 $stranica = $TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
 $book_pered = "&amp;book_name=".$_POST['book_name'];
 }
    else 
    {
     $book_name = "";
     $stranica =$TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
     $book_pered = "";
    }
     $query_body = "SELECT book_id, book_name, visible, vidano FROM `tbl_book` $book_name ORDER BY book_name LIMIT $lim_ogr";
     $result_body = mysqli_query($dbcnx,$query_body);
     if(!$result_body) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm.php"; exit();}
       $result_rows = mysqli_num_rows($result_body);
       if($result_rows > 0)
         {
           echo "<thead ><tr class='tableheadercat'>
            <td>".$TEXT['book-name']."</td>
            <td colspan=2>".$TEXT['global-action']."</td>
            </tr></thead><tbody id='tab'>";
             while($result_body_autor = mysqli_fetch_array($result_body))
               {
              $edit = "<a href=editform.php?book_id=".$result_body_autor['book_id']." title='".$TEXT['edit-tit']."'>".$TEXT['edit-new']."</a>";

              $delete_pic = "<img alt='".$TEXT['delete-tit']."' src='../skins/".$result2['skin']."/delete.png' />";
              $delete = $delete_pic."&nbsp;<a href=delete.php?book_id=".$result_body_autor['book_id']." title='".$TEXT['delete-tit']."'>".$TEXT['delete-new']."</a>";

              $edit_pic = "<img alt='".$TEXT['aut-viewtit']."' src='../skins/".$result2['skin']."/edit.png' />";

              if($result_body_autor['visible'] == '1') {$vis= "<img alt='".$TEXT['book-show2']."' src='../skins/".$result2['skin']."/visible.png' />";}
               else {$vis= "<img alt='".$TEXT['book-show2']."' src='../skins/".$result2['skin']."/invisible.png' />";}

              if($result_body_autor['vidano'] == '3') {$usr_name = "<a href=info.php?book_id=".$result_body_autor['book_id']." title='".$TEXT['aut-viewtit']."'><span class='zakaz'>".$result_body_autor['book_name']."</span></a>&nbsp;(".$vis."<img alt='".$TEXT['book-show5']."' src='../skins/".$result2['skin']."/zakupka.png' />)";}
               else {$usr_name = "<a href=info.php?book_id=".$result_body_autor['book_id']." title='".$TEXT['aut-viewtit']."'>".rep_back($result_body_autor['book_name'])."</a>&nbsp;(".$vis.")";}
           ?>
           <tr>
              <td><?php echo $usr_name; ?></td>
              <td><?php echo $edit_pic; ?>&nbsp;<?php echo $edit; ?></td>
              <td><?php echo $delete; ?></td>
           </tr>
           <?php
               }
               $query_count = mysqli_query($dbcnx,"SELECT COUNT(book_id) AS c_book_id FROM tbl_book WHERE (vidano!='2' AND vidano!='3') $book_name_tmp");
	       $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_book_id']; ?></td>
                </tr>
               </tfoot>
              <?php
         }
?>
</table>
     <?php
          $pag = $coun_rows['c_book_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.$book_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.$book_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.$book_pered.">".$j."</option>";}
                       else {echo "<option value=index.php?k=".$k.$book_pered.">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
               ?>
</form>
<?php
  require_once "../utils/bottom_adm.php";
?>