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

$title = $TEXT['menu-btn31-title'];

require_once "config.php";
require_once "utils/functions.php";
require_once "utils/top_film.php";

if($result2['administrator'] == 0) {puterror2($result2['skin'],$TEXT['error-loginform2']); require_once "utils/bottom_film.php"; exit();}

if(strlen($_GET['k'])>8) {puterror2($result2['skin'],$TEXT['error-paging1']); require_once "utils/bottom_film.php"; exit();}
$_GET['k'] = rep($_GET['k']);
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;
?>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr align="right">
<td><img alt="<?php echo $TEXT['film-nap-now']; ?>" src='skins/<?php echo $result2['skin']; ?>/mail-all.png' />&nbsp;<a class="bold_it" href="mail_all.php" title="<?php echo $TEXT['film-nap-now-tit']; ?>"><?php echo $TEXT['film-nap-now']; ?></a></td>
</tr>
</table>
<table align="center" border="0" cellpadding="3" cellspacing="0" width="90%">
<thead><tr class='tableheadercat'>
<td><?php echo $TEXT['book-sost']; ?></td>
<td><?php echo $TEXT['film-name']; ?></td>
<td><?php echo $TEXT['global-film']; ?></td>
<td><?php echo $TEXT['book-who-vid']; ?></td>
<td><?php echo $TEXT['book-data3']; ?></td>
<td><?php echo $TEXT['book-data4']; ?></td>
<td><?php echo $TEXT['book-zad']; ?></td>
</tr></thead>
<tbody id="tab" >
<?php
     $query_body = "SELECT 
     tbl_film.film_name,
     tbl_film.film_id,
     tbl_film.napominalka,
     YEAR(tbl_film.data_vidachi) AS data_vidachi_year,
     MONTH(tbl_film.data_vidachi) AS data_vidachi_month,
     DAY(tbl_film.data_vidachi) AS data_vidachi_day,
     YEAR(tbl_film.data_sdachi) AS data_sdachi_year,
     MONTH(tbl_film.data_sdachi) AS data_sdachi_month,
     DAY(tbl_film.data_sdachi) AS data_sdachi_day,
     tbl_film.user_id,
     tbl_biblioteka.name AS bibl_name,
     tbl_logins.familiya,
     tbl_logins.name,
     tbl_logins.otchestvo
     FROM tbl_film
     JOIN tbl_biblioteka ON tbl_film.bibl_id=tbl_biblioteka.bibl_id
     JOIN tbl_logins ON tbl_film.user_id=tbl_logins.login_id
     WHERE tbl_film.vidano ='1'
     ORDER BY tbl_film.data_sdachi, tbl_film.film_name
     LIMIT $lim_ogr ";
     $result_body = mysqli_query($dbcnx,$query_body);
     if(!$result_body) {puterror2($result2['skin'],$TEXT['error-tbl26']); require_once "utils/bottom_film.php"; exit();}
       $result_rows = mysqli_num_rows($result_body);
       if($result_rows > 0)
         {
          while($result_body_film= mysqli_fetch_array($result_body))
               {
               $query_zad = mysqli_query($dbcnx,"SELECT DATEDIFF(CURRENT_DATE(),data_sdachi) AS zad_date FROM tbl_film WHERE film_id = ".$result_body_film['film_id']."");
                $res_zad = mysqli_fetch_array($query_zad);

               $date_day = $result_body_film['data_sdachi_day'];
               $date_month = $result_body_film['data_sdachi_month'];
               $date_year = $result_body_film['data_sdachi_year'];
               $year = $TEXT['year2'];
               if($date_year == "0000" || $date_year == "1970") {$data_sd = "---";}
                else {$data_sd = (date("$date_day $month[$date_month] $date_year $year"));}

               $date_day2 = $result_body_film['data_vidachi_day'];
               $date_month2 = $result_body_film['data_vidachi_month'];
               $date_year2 = $result_body_film['data_vidachi_year'];
               if($date_year2 == "0000" || $date_year2 == "1970") {$data_vid = "---";}
                else {$data_vid = (date("$date_day2 $month[$date_month2] $date_year2 $year"));}

               if($res_zad['zad_date'] < 1)
               {
                $film_sost = "<img alt='ok' src='skins/".$result2['skin']."/active.png' />";
                $zad = $TEXT['film-zad-no'];
               }
                else
                {
                 if($result_body_film['napominalka'] == "0") {$film_sost = "<img alt='warning' src='skins/".$result2['skin']."/warn.png' />";}
                  else {$film_sost = "<img alt='warning' src='skins/".$result2['skin']."/warn-nap.png' />";}
                 $zad = $res_zad['zad_date']."&nbsp;".$TEXT['film-zad-days']."&nbsp;<a href=film-mail.php?film_id=".$result_body_film['film_id']." title='".$TEXT['log-mail']."'><img alt='mail' src='skins/".$result2['skin']."/mail.png' /></a>";
                }

               $bibl = $result_body_film['bibl_name'];
               $film_name = "<a href=film-info.php?film_id=".$result_body_film['film_id']." title='".$TEXT['aut-viewtit']."'>".rep_back($result_body_film['film_name'])."</a>";

               ?>
               <tr>
                <td><?php echo $film_sost; ?></td>
                <td class="informcntr"><?php echo $film_name; ?></td>
                <td><?php echo $bibl; ?></td>
                <td><?php echo $result_body_film['familiya']; ?> <?php echo $result_body_film['name']; ?> <?php echo $result_body_film['otchestvo']; ?></td>
                <td><?php echo $data_vid; ?></td>
                <td><?php echo $data_sd; ?></td>
                <td><?php echo $zad; ?></td>
               </tr>
               <?php
               }
         }
?>
</tbody>
</table>
     <?php
       $query_count = mysqli_query($dbcnx,"SELECT COUNT(film_id) AS c_film_id FROM tbl_film WHERE vidano ='1'");
	       $coun_rows = mysqli_fetch_array($query_count);
               $pag = $coun_rows['c_film_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='film-vidano-search.php?k=".$k."' 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='film-vidano-search.php?k=".$k."' 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=film-vidano-search.php?k=".$k.">".$j."</option>";}
                       else {echo "<option value=film-vidano-search.php?k=".$k.">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
  require_once "utils/bottom_film.php";
?>