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

  require_once "../utils/chlang.php";

  $title = $TEXT['search-title'];
  $button = $TEXT['btn_add_new'];
  require_once "../config_a.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_adm_film.php";

  if($result2['administrator'] == 0 && $result2['user'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(empty($_POST['film_name'])) {puterror($result2['skin'],$TEXT['error-film1']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(trim($_POST['film_name']) == "") {puterror($result2['skin'],$TEXT['error-film1']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(strlen($_POST['film_name'])>255) {puterror($result2['skin'],$TEXT['error-film2']); require_once "../utils/bottom_adm_film.php"; exit();}
  $_POST['film_name'] = rep($_POST['film_name']);

$query_iskh = "SELECT
tbl_film.film_id,
tbl_film.bibl_id,
tbl_film.film_name,
tbl_film.autors,
tbl_biblioteka.name AS biblioteka,
tbl_biblioteka.bibl_id
FROM tbl_film
JOIN tbl_biblioteka ON tbl_film.bibl_id=tbl_biblioteka.bibl_id 
WHERE LOWER(tbl_film.film_name) LIKE LOWER('%".$_POST['film_name']."%') ";
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror($result2['skin'],$TEXT['error-tbl26']); require_once "../utils/bottom_adm_film.php"; exit();}
    $res_rows = mysqli_num_rows($result_iskh);
     if($res_rows == 0)
       {
        echo "<html><head><meta HTTP-EQUIV='Refresh' CONTENT='0; URL=addform.php?film_name=".rep_back($_POST['film_name'])."' /></head></html>";
       }
      else
      {
       echo "<form name='film' enctype='multipart/form-data' action=addform.php method=post>
             <table align='center' border='0' cellpadding='3' cellspacing='0' width='90%' >
             <tbody id='tab'>";
       while($result_iskh2 = mysqli_fetch_array($result_iskh))
       {
       $autor = "";

        $film_name = "<a href=editform.php?film_id=".$result_iskh2['film_id']." title='".$TEXT['aut-viewtit']."'><h2>".rep_back($result_iskh2['film_name'])."</h2></a>";
        $film = "<h4>(".$TEXT['global-film']." &rArr; ".$result_iskh2['biblioteka']." | ".$TEXT['film-rezhiser']." &rArr; ".$result_iskh2['autors'].")</h4>";

       echo "<tr>
             <td align= 'right'>".$film_name."</td>
             <td align= 'left'>".$film."</td>
             </tr>";
       }
       echo "</tbody>
             <tfoot>
             <tr>
             <td>
             <input class='button2' type=submit value='".$button."' />
             <input type=hidden name=film_name value='".rep_back($_POST['film_name'])."' />
             </td>
             <td>
               <table align='right' width='25%'>
               <tr>
                <td class='search_res' width='5%'>".$TEXT['search-res-tit'].$res_rows."</td>
               </tr>
               </table>
             </td>
             </tr>
             </tfoot>
             </table>
             </form>";
      }
  require_once "../utils/bottom_adm_film.php";
?>