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

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

$_GET['k'] = rep($_GET['k']);
$_POST['familiya'] = rep($_POST['familiya']);
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="familiya" title="<?php echo $TEXT['login-familiya']; ?>" value="<?php echo $familiya; ?>"></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" border="1" cellpadding="3" cellspacing="0" width="60%" >
<?php
 if(!empty($_POST['familiya'])) 
 {
 $familiya = " WHERE LOWER(familiya) LIKE LOWER('%".$_POST['familiya']."%') OR LOWER(real_name) LIKE LOWER('%".$_POST['familiya']."%') OR LOWER(name) LIKE LOWER('%".$_POST['familiya']."%') ";
 $stranica = $TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
 $fam_pered = "&amp;familiya=".$_POST['familiya'];
 }
  else 
   {
    $familiya = "";
    $stranica = $TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
    $fam_pered = "";
   }

     $query_body = "SELECT autor_id, name, familiya, otchestvo FROM `tbl_autor` $familiya ORDER BY familiya LIMIT $lim_ogr";
     $result_body = mysqli_query($dbcnx,$query_body);
     if(!$result_body) {puterror($result2['skin'],$TEXT['error-tbl1']); 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['aut-full']."</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?autor_id=".$result_body_autor['autor_id']."' title='".$TEXT['edit-tit']."'>".$TEXT['edit-new']."</a>";

              $query_book_cicle = mysqli_query($dbcnx,"SELECT COUNT(autor_id) AS co_autor_id FROM tbl_s_book_aut WHERE autor_id='".$result_body_autor['autor_id']."'");
	      $coun_book_cicle = mysqli_fetch_array($query_book_cicle);
              if($coun_book_cicle['co_autor_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?autor_id=".$result_body_autor['autor_id']."' title='".$TEXT['delete-tit']."'>".$TEXT['delete-new']."</a>";
                 }
              $edit_pic = "<img alt='".$TEXT['edit-new']."' src='../skins/".$result2['skin']."/edit.png' />";
              $usr_name = "<a href='info.php?autor_id=".$result_body_autor['autor_id']."&amp;k=".$stop_r."' title='".$TEXT['aut-viewtit']."'>".rep_back($result_body_autor['name'])." ".rep_back($result_body_autor['otchestvo'])." ".rep_back($result_body_autor['familiya'])."</a>";
           ?>
           <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(autor_id) AS c_autor_id FROM tbl_autor $familiya");
	       $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_autor_id']; ?></td>
                </tr>
                </tfoot>
              <?php
         }
?>
</table>
     <?php
               $pag = $coun_rows['c_autor_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.$fam_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.$fam_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.$fam_pered.">".$j."</option>";}
                       else {echo "<option value=index.php?k=".$k.$fam_pered.">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
               ?>
</form>
<?php
  require_once "../utils/bottom_adm.php";
?>