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

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

$_GET['k'] = rep($_GET['k']);
$_POST['izdatelstvo'] = rep($_POST['izdatelstvo']);
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="70%" >
<tr>
<td width="10%" align="left"><input size=20 maxlength=255 type=text name=izdatelstvo title='<?php echo $TEXT['login-familiya']; ?>' value='<?php echo $izdatelstvo; ?>'></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="70%" >
<?php
if(!empty($_POST['izdatelstvo']))
 {
 $izdatelstvo = " AND LOWER(izdatelstvo) LIKE LOWER('%".$_POST['izdatelstvo']."%')";
 $stranica = $TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
 $izd_pered = "&amp;izdatelstvo=".$_POST['izdatelstvo'];
 }
  else
   {
    $izdatelstvo = "";
    $stranica = $TEXT['tbl-details2'].$stop_r.$TEXT['tbl-details3'].$ktblvis;
    $izd_pered = "";
   }

     $query10 = "SELECT * FROM `tbl_izdatelstvo` WHERE use_prog='1' $izdatelstvo ORDER BY izdatelstvo LIMIT $lim_ogr";
     $result10 = mysqli_query($dbcnx,$query10);
     if(!$result10) {puterror($result2['skin'],$TEXT['error-tbl6']); require_once "../utils/bottom_adm.php"; exit();}
       $result_rows = mysqli_num_rows($result10);
       if($result_rows > 0)
         {
           echo " <thead>
              <tr class='tableheadercat'>
                 <td width='30%'>".$TEXT['tbl-izd']."</td>
                 <td width='40%'>".$TEXT['user-site']."</td>
                 <td colspan=2>".$TEXT['tbl-action']."</td>
              </tr>
             </thead><tbody id='tab' >";
             while($result_izd = 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?izd_id=".$result_izd['izd_id']." title='".$TEXT['edit-tit']."'>".$TEXT['edit-new']."</a>";

              $query_book_izd = mysqli_query($dbcnx,"SELECT COUNT(izd_id) AS co_izd_id FROM tbl_s_book_izd WHERE izd_id='".$result_izd['izd_id']."'");
	      $coun_book_izd = mysqli_fetch_array($query_book_izd);
              if($coun_book_izd['co_izd_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?izd_id=".$result_izd['izd_id']." title='".$TEXT['delete-tit']."'>".$TEXT['delete-new']."</a>";
                }
               if(!empty($result_izd['site_name'])) {$site_name = "<a href='".$result_izd['site_protocol']."://".$result_izd['site_name']."' target=_blank title='".$result_izd['izdatelstvo']."'>".$result_izd['site_protocol']."://".$result_izd['site_name']."</a>";}
                 else {$site_name ="---";}
           ?>
           <tr>
              <td><?php echo $result_izd['izdatelstvo']; ?></td>
              <td><?php echo $site_name; ?></td>
              <td><?php echo $edit; ?></td>
              <td><?php echo $delete; ?></td>
            </tr>
           <?php
               }
               $query_count = mysqli_query($dbcnx,"SELECT COUNT(izd_id) AS c_izd_id FROM tbl_izdatelstvo WHERE use_prog='1' $izdatelstvo");
	       $coun_rows = mysqli_fetch_array($query_count);
               ?>
               </tbody>
               <tfoot>
                <tr class='tableheadercat'>
                <td colspan=4 align="right"><?php echo $stranica; ?> | <?php echo $TEXT['size-count2']; ?> = <?php echo $result_rows; ?> | <?php echo $TEXT['size-razm']; ?>: <?php echo $coun_rows['c_izd_id']; ?></td>
                </tr>
                </tfoot>
              <?php
         }
?>
</table>
     <?php
              $pag = $coun_rows['c_izd_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.$izd_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.$izd_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.$izd_pered.">".$j."</option>";}
                       else {echo "<option value=index.php?k=".$k.$izd_pered.">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
               ?>
</form>
<?php
  require_once "../utils/bottom_adm.php";
?>