<?php
  ///////////////////////////////////////////////////
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

require_once "utils/chlang_osn.php";

$title = $TEXT['search-alf-film'];

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

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

if(strlen($_GET['k'])>8) {puterror($result2['skin'],$TEXT['error-paging1']); require_once "utils/bottom_film.php"; exit();}
if(strlen($_GET['bukva'])>4) {puterror($result2['skin'],$TEXT['error-bukva']); require_once "utils/bottom_film.php"; exit();}
$_GET['bukva'] = rep($_GET['bukva']);
$_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;

if(empty($_GET['bukva']))
 {
  if(empty($_POST['bukva'])) {$bukva = "А";}
   else {$bukva = $_POST['bukva'];}
} else {$bukva = $_GET['bukva'];}
?>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="95%">
<tr>
<td align="center">
<?php
    $query_body1 = "SELECT DISTINCT first_bt AS bukva FROM `tbl_film` ORDER BY bukva ";
     $result_body1 = mysqli_query($dbcnx,$query_body1);
     if(!$result_body1) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
       while($result_body_autor1 = mysqli_fetch_array($result_body1))
        {
        if($bukva == $result_body_autor1['bukva']) {echo "&nbsp;<a class='zagolovok' href=film-alf-search.php?bukva=".$result_body_autor1['bukva']." title='".$TEXT['alffilm-title'].$result_body_autor1['bukva']."'>".$result_body_autor1['bukva']."</a>";}
         else {echo "&nbsp;<a href='film-alf-search.php?bukva=".$result_body_autor1['bukva']."' title='".$TEXT['alffilm-title'].$result_body_autor1['bukva']."'>".$result_body_autor1['bukva']."</a>";}
        }
?>
</td>
</tr>
</table>
<hr width="70%" />
<table align="center" border="0" cellpadding="3" cellspacing="0" width="90%">
<tbody id="tab" >
<?php
     $query_body = "SELECT tbl_film.film_name, tbl_film.film_id, tbl_film.vidano, tbl_film.cicle_id AS cicl_film, tbl_cicle.cicle
     FROM tbl_film
     LEFT JOIN tbl_cicle ON tbl_film.cicle_id=tbl_cicle.cicle_id
     WHERE tbl_film.first_bt = '".$bukva."' AND tbl_film.visible ='1'
     ORDER BY 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))
               {
               $result_body_film['film_name'] = rep_back($result_body_film['film_name']);

               if($result_body_film['cicle'] !== '---')
               {
               $query_film_cicle = mysqli_query($dbcnx,"SELECT COUNT(tbl_film.film_id) AS co_film_id FROM tbl_film WHERE tbl_film.cicle_id='".$result_body_film['cicl_film']."'");
	       $coun_film_cicle = mysqli_fetch_array($query_film_cicle);
               $film = "<a href='film-extsearch.php?cicle_id=".$result_body_film['cicl_film']."&amp;cicle_ch=on' title='".$TEXT['search-all-film-cicl']."'>  (".$TEXT['film-cicle']." - ".$result_body_film['cicle'].", ".$TEXT['global-now-film']." - ".$coun_film_cicle['co_film_id'].")</a>";

               if($result_body_film['vidano'] == '3') {$film_name = "<a href='info.php?film_id=".$result_body_film['film_id']."' title='".$TEXT['aut-viewtit']."'><span class='zagolovok_zak'>".$result_body_film['film_name']."</span></a>";}
                elseif($result_body_film['vidano'] == '2') {$film_name = "<a href='info.php?film_id=".$result_body_film['film_id']."' title='".$TEXT['aut-viewtit']."'><span class='zagolovok_sp'>".$result_body_film['film_name']."</span></a>";}
                elseif($result_body_film['vidano'] == '1') {$film_name = "<a href='info.php?film_id=".$result_body_film['film_id']."' title='".$TEXT['aut-viewtit']."'><span class='zagolovok_vid'>".$result_body_film['film_name']."</span></a>";}
               else {$film_name = "<a href='film-info.php?film_id=".$result_body_film['film_id']."' title='".$TEXT['aut-viewtit']."'><span class='zagolovok'>".$result_body_film['film_name']."</span></a>";}

               echo "<tr>";
               echo "<td align= 'right' width='50%'>".$film_name."</td>";
               echo "<td align= 'left' width='50%'>".$film."</td>";
               echo "</tr>";
               }
               else
               {
               $film = "";

               if($result_body_film['vidano'] == '3') {$film_name = "<a href='info.php?film_id=".$result_body_film['film_id']."' title='".$TEXT['aut-viewtit']."'><span class='zagolovok_zak'>".$result_body_film['film_name']."</span></a>";}
                elseif($result_body_film['vidano'] == '2') {$film_name = "<a href='info.php?film_id=".$result_body_film['film_id']."' title='".$TEXT['aut-viewtit']."'><span class='zagolovok_sp'>".$result_body_film['film_name']."</span></a>";}
                elseif($result_body_film['vidano'] == '1') {$film_name = "<a href='info.php?film_id=".$result_body_film['film_id']."' title='".$TEXT['aut-viewtit']."'><span class='zagolovok_vid'>".$result_body_film['film_name']."</span></a>";}
               else {$film_name = "<a href='film-info.php?film_id=".$result_body_film['film_id']."' title='".$TEXT['aut-viewtit']."'><span class='zagolovok'>".$result_body_film['film_name']."</span></a>";}
               
               echo "<tr>";
               echo "<td colspan='2' align= 'center' width='50%'>".$film_name."</td>";
               echo "</tr>";
               }
             }
         }
?>
</tbody>
</table>
     <?php
       $query_count = mysqli_query($dbcnx,"SELECT COUNT(film_id) AS c_film_id FROM tbl_film WHERE `first_bt` = '".$_GET['bukva']."'");
	       $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-alf-search.php?k=".$k."&amp;bukva=".$_GET['bukva']."' 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-alf-search.php?k=".$k."&amp;bukva=".$_GET['bukva']."' 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-alf-search.php?k=".$k."&amp;bukva=".$_GET['bukva'].">".$j."</option>";}
                      else {echo "<option value=film-alf-search.php?k=".$k."&amp;bukva=".$_GET['bukva'].">".$j."</option>";}
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
require_once "utils/bottom_film.php";
?>