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

  $title = $TEXT['film-info'];
  $button = $TEXT['btn_back'];
  $action = "index.php";

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

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

  if(empty($_GET['film_id'])) {puterror($result2['skin'],$TEXT['error-film5']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_GET['film_id'])>255) {puterror($result2['skin'],$TEXT['error-film6']); require_once "utils/bottom_film.php"; exit();}
  $_GET['film_id'] = rep($_GET['film_id']);

$query_iskh = "SELECT 
tbl_film.*,
YEAR(tbl_film.data_postupleniya) AS data_postupleniya_year,
MONTH(tbl_film.data_postupleniya) AS data_postupleniya_month,
DAY(tbl_film.data_postupleniya) AS data_postupleniya_day,
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,
YEAR(tbl_film.data_zakaza) AS data_zakaza_year,
MONTH(tbl_film.data_zakaza) AS data_zakaza_month,
DAY(tbl_film.data_zakaza) AS data_zakaza_day,
tbl_cicle.cicle,
tbl_biblioteka.name AS biblioteka,
tbl_biblioteka.bibl_id,
tbl_zhanr.zhanr_id,
tbl_zhanr.zhanr,
tbl_tip_izd.tip_izd_id,
tbl_tip_izd.tip_izd,
tbl_zal.zal_id,
tbl_zal.zal,
tbl_shkaf.shkaf_id,
tbl_shkaf.shkaf,
tbl_polka.polka_id,
tbl_polka.polka,
tbl_seriya.ser_id,
tbl_seriya.seriya,
tbl_vozrast.vozr_id,
tbl_vozrast.vozrast,
tbl_booklang.bl_id,
tbl_booklang.booklang,
tbl_booklang.picture
FROM tbl_film
JOIN tbl_cicle ON tbl_film.cicle_id=tbl_cicle.cicle_id
JOIN tbl_biblioteka ON tbl_film.bibl_id=tbl_biblioteka.bibl_id
JOIN tbl_zhanr ON tbl_film.zhanr_id=tbl_zhanr.zhanr_id
JOIN tbl_tip_izd ON tbl_film.tip_izd_id=tbl_tip_izd.tip_izd_id
JOIN tbl_zal ON tbl_film.zal_id=tbl_zal.zal_id
JOIN tbl_shkaf ON tbl_film.shkaf_id=tbl_shkaf.shkaf_id
JOIN tbl_polka ON tbl_film.polka_id=tbl_polka.polka_id
JOIN tbl_seriya ON tbl_film.ser_id=tbl_seriya.ser_id
JOIN tbl_booklang ON tbl_film.bl_id=tbl_booklang.bl_id
LEFT JOIN tbl_vozrast ON tbl_film.vozr_id=tbl_vozrast.vozr_id
WHERE film_id = '".$_GET['film_id']."' ";
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror($result2['skin'],$TEXT['error-tbl26']); require_once "utils/bottom_film.php"; exit();}
      $result_iskh2 = mysqli_fetch_array($result_iskh);

     $bnt = substr($result_iskh2['film_num'],0,1);
      if($bnt == '0')
      {
       $film_n = substr($result_iskh2['film_num'],1,1);
        if($film_n == '0')
        {
         $film_num = substr($result_iskh2['film_num'],2,3);
        } else {$film_num = substr($result_iskh2['film_num'],1,3);}
       } else {$film_num = $result_iskh2['film_num'];}

      $date_day = $result_iskh2['data_postupleniya_day'];
      $date_month = $result_iskh2['data_postupleniya_month'];
      $date_year = $result_iskh2['data_postupleniya_year'];
      if($date_year == "0000" || $date_year == "1970") {$data_r = "---";}
       else {$data_r = $date_day." ".$month[$date_month]." ".$date_year." ".$TEXT['year2'];}

      $date_day2 = $result_iskh2['data_izdaniya'];
      if($result_iskh2['data_izdaniya'] == "0000" || $result_iskh2['data_izdaniya'] == "1970") {$data_r2 = "---";}
       else {$data_r2 = $date_day2." ".$TEXT['year'];}

      $date_day3 = $result_iskh2['data_vidachi_day'];
      $date_month3 = $result_iskh2['data_vidachi_month'];
      $date_year3 = $result_iskh2['data_vidachi_year'];
      if($date_year3 == "0000" || $date_year3 == "1970") {$data_r3 = "---";}
       else {$data_r3 = $date_day3." ".$month[$date_month3]." ".$date_year3." ".$TEXT['year2'];}

      $date_day4 = $result_iskh2['data_sdachi_day'];
      $date_month4 = $result_iskh2['data_sdachi_month'];
      $date_year4 = $result_iskh2['data_sdachi_year'];
      if($date_year4 == "0000" || $date_year4 == "1970") {$data_r4 = "---";}
       else {$data_r4 = $date_day4." ".$month[$date_month4]." ".$date_year4." ".$TEXT['year2'];}

      $date_day5 = $result_iskh2['data_zakaza_day'];
      $date_month5 = $result_iskh2['data_zakaza_month'];
      $date_year5 = $result_iskh2['data_zakaza_year'];
      if($date_year5 == "0000" || $date_year5 == "1970") {$data_r5 = "---";}
       else {$data_r5 = $date_day5." ".$month[$date_month5]." ".$date_year5." ".$TEXT['year2'];}

     $query_izd = "SELECT
     tbl_s_film_izd.*,
     tbl_izdatelstvo.*
     FROM tbl_s_film_izd
     JOIN tbl_izdatelstvo ON tbl_s_film_izd.izd_id=tbl_izdatelstvo.izd_id
     WHERE film_id = '".$_GET['film_id']."' ";
     $result_izd = mysqli_query($dbcnx,$query_izd);
      if(!$result_izd) {puterror($result2['skin'],$TEXT['error-tbl17']); require_once "utils/bottom_film.php"; exit();}
      while($result_izd2 = mysqli_fetch_array($result_izd))
       {
        $izd .="<a href='".$result_izd2['site_protocol']."://".$result_izd2['site_name']."' target=_blank title='".$TEXT['izd-str']."'>".$result_izd2['izdatelstvo']."</a>, ";
       }
       $izds =substr($izd, 0,-2);

      if(!empty($result_iskh2['site_name'])) {$address_aut = "<a href='".$result_iskh2['site_protocol']."://".$result_iskh2['site_name']."' target=_blank title=".$TEXT['aut-site'].">".$result_iskh2['site_protocol']."://".$result_iskh2['site_name']."</a>";}
       else {$address_aut = "";}

      $sm = preg_replace("/\.\.+./","",$result_iskh2['photo_film']);
      if(!empty($result_iskh2['photo_film']) && file_exists($sm) && $result2['administrator'] == '1') {$result_image = "<a href='films/editform.php?film_id=".$_GET['film_id']."' title='".$TEXT['edit-tit']."'><img alt='".$TEXT['global-alt']."' src='".$sm."' /></a>";}
       elseif(!empty($result_iskh2['photo_film']) && file_exists($sm) && $result2['administrator'] == '0') {$result_image = "<img alt='".$TEXT['global-alt']."' src='".$sm."' />";}
        elseif(empty($result_iskh2['photo_film']) && $result2['administrator'] == '1') {$result_image = "<a href='films/editform.php?film_id=".$_GET['film_id']."' title='".$TEXT['edit-tit']."'><img alt='".$TEXT['global-alt']."' src='skins/".$result2['skin']."/nophoto.png' /></a>";}
         else {$result_image = "<img alt='".$TEXT['global-alt']."' src='skins/".$result2['skin']."/nophoto.png' />";}

      if($result2['administrator'] == 0)
      {
      if($result_iskh2['napominalka'] == '1') {$nap=  "<img alt='".$TEXT['book-show2']."' src='skins/".$result2['skin']."/nap_on.png' />";}
       else {$nap= "<img align='top' alt='".$TEXT['book-show2']."' src='skins/".$result2['skin']."/nap_off.png' />";}
      }
      else
      {
      if($result_iskh2['napominalka'] == '1') {$nap=  "<a href='film-nap_off.php?film_id=".$_GET['film_id']."' title='".$TEXT['book-nap-off']."'><img alt='".$TEXT['book-show2']."' src='skins/".$result2['skin']."/nap_on.png' /></a>";}
        else {$nap= "<a href='film-nap_on.php?film_id=".$_GET['film_id']."'title='".$TEXT['book-nap']."'><img align='top' alt='".$TEXT['book-show2']."' src='skins/".$result2['skin']."/nap_off.png' /></a>";}
      }

      $bl = preg_replace("/\.\.+./","",$result_iskh2['picture']);
      if(!empty($result_iskh2['picture']) && file_exists($bl)) {$result_bl = "<img alt='".$result_iskh2['booklang']."' src='".$bl."' />";}
       else {$result_bl = "<span class='menu'>".$TEXT['menu-btn37']." &raquo; ".$result_iskh2['booklang']."</span>";}

     $result_iskh2['opisanie'] = rep_back($result_iskh2['opisanie']);
     $result_iskh2['oglavlenie'] = rep_back($result_iskh2['oglavlenie']);
     $result_iskh2['film_name'] = rep_back($result_iskh2['film_name']);
     $result_iskh2['autors'] = rep_back($result_iskh2['autors']);

     if($result_iskh2['subtitle'] == '1') {$subtitle= $TEXT['book-zad-yes'];}
       else {$subtitle= $TEXT['book-zad-no'];}
?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table align="center" width="98%" border="0">
<?php
if($result_iskh2['vidano'] == '3') {echo "<tr><td class='zagolovok_zak'>&nbsp;".$result_iskh2['film_name']."</td><td width='15%' align='right' title='".$TEXT['menu-btn37']." &raquo; ".$result_iskh2['booklang']."'>".$result_bl."</td></tr>";}
  elseif($result_iskh2['vidano'] == '2') {echo "<tr><td class='zagolovok_sp'>&nbsp;".$result_iskh2['film_name']."</td><td width='15%' align='right' title='".$TEXT['menu-btn37']." &raquo; ".$result_iskh2['booklang']."'>".$result_bl."</td></tr>";}
 else {echo "<tr><td class='zagolovok'>&nbsp;".$result_iskh2['film_name']."</td><td width='15%' align='right' title='".$TEXT['menu-btn37']." &raquo; ".$result_iskh2['booklang']."'>".$result_bl."</td></tr>";}
?>
<tr><td>
</table>
<hr width="98%" />
<table align="center" width="98%" border="0">
<tr>
<td width="5%" valign="top">
   <table align="left" border="0" width="100%">
    <tr><td><?php echo $result_image; ?></td></tr>
    <?php
      //if(!empty($result_iskh2['e_film'])) $e_film = "<tr><td class='informcntr'><a class='informcntr' href='".$result_iskh2['e_film']."' target=_blank title='".$result_iskh2['film_name']."'>".$TEXT['film-efilm']."</a></td></tr>";
       $fl = $result_iskh2['e_film'];
      if(!empty($result_iskh2['e_film']) && file_exists($fl)) {$e_film = "<tr><td class='informcntr'><a class='informcntr' href='get_film.php?film_id=".$result_iskh2['film_id']."' target=_blank title='".$result_iskh2['film_name']."'>".$TEXT['film-efilm']."</a></td></tr>";}
       else {$e_film = "";}
      echo $e_film;
    ?>
    </table>
</td>
<td width="42%" valign="top">
<fieldset>
<legend align="left" title="<?php echo $TEXT['film-info']; ?>"><?php echo $TEXT['film-info']; ?></legend>
<table align="left" width="100%" border="0">
<tr><td class="inform"><?php echo $TEXT['film-rezhiser']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['autors']; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['menu-btn22-film']; ?>:&nbsp;</td><td class="input"><?php echo $izds; ?></td></tr>
<?php
if(!empty($result_iskh2['prod_min'])) {echo "<tr><td class='inform'>".$TEXT['film-prod'].":&nbsp;</td><td class='input'>".$result_iskh2['prod_min']."</td></tr>";}
?>
<tr><td class="inform"><?php echo $TEXT['film-subtit']; ?>:&nbsp;</td><td class="input"><?php echo $subtitle; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-zhanr']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['zhanr']; ?></td></tr>
<?php
if(!empty($result_iskh2['cicle'])) {echo "<tr><td class='inform'>".$TEXT['menu-btn17'].":&nbsp;</td><td class='input'>".$result_iskh2['cicle']."</td></tr>";}
if(!empty($result_iskh2['film_num']) && $result_iskh2['film_num'] !== "0") {echo "<tr><td class='inform'>&#8470; ".$TEXT['global-now-film2'].":&nbsp;</td><td class='input'>".$film_num."</td></tr>";}
if(!empty($result_iskh2['vozrast'])) {echo "<tr><td class='inform'>".$TEXT['menu-btn38-title'].":&nbsp;</td><td class='opis'>".$result_iskh2['vozrast']."</td></tr>";}
if(!empty($result_iskh2['opisanie'])) {echo "<tr><td class='inform'>".$TEXT['book-opis'].":&nbsp;</td><td class='opis'>".nl2br($result_iskh2['opisanie'])."</td></tr>";}
if(!empty($result_iskh2['oglavlenie'])) {echo "<tr><td class='inform'>".$TEXT['film-soderzh'].":&nbsp;</td><td class='ogl'>".nl2br( $result_iskh2['oglavlenie'])."</td></tr>";}

$query_otz = mysqli_query($dbcnx,"SELECT COUNT(otz_id) AS c_otz_id FROM tbl_otziv WHERE book_id = '".$_GET['film_id']."' AND otziv!='' AND use_prog = '2'");
$coun_otz = mysqli_fetch_array($query_otz);
echo "<tr><td></td><td><hr width='50%' align='left' /></td></tr>";
if($coun_otz['c_otz_id'] > 0) {echo "<tr><td class='inform'></td><td class='input'><a href='film-otziv.php?film_id=".$_GET['film_id']."' >".$TEXT['book-otziv2']."&nbsp;&#040;".$coun_otz['c_otz_id']."&#041;</a></td></tr>";}
 else {echo "<tr><td class='inform'></td><td class='input'><a href='film-otziv.php?film_id=".$_GET['film_id']."' >".$TEXT['book-otziv2']."</a></td></tr>";}
?>
</table>
</fieldset>
</td>
<td width="42%" valign="top">
<fieldset>
<legend align="left" title="<?php echo $TEXT['book-fldset2-tit']; ?>"><?php echo $TEXT['book-fldset2']; ?></legend>
<table align="right" width="100%" border="0">
<tr><td class="inform"><?php echo $TEXT['book-data']; ?>:&nbsp;</td><td class="input"><?php echo  $data_r2; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-data2']; ?>:&nbsp;</td><td class="input"><?php echo $data_r; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['menu-btn29-title-film']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['seriya']; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['nositel-title']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['tip_izd']; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['global-film']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['biblioteka']; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-zal']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['zal']; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-shkaf']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['shkaf']; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-polka']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['polka']; ?></td></tr>
</table>
</fieldset>
<fieldset>
<legend align="left" title="<?php echo $TEXT['book-fldset3-tit']; ?>"><?php echo $TEXT['book-fldset3']; ?></legend>
<table align="right" width="100%" border="0">
<?php
if($result_iskh2['vidano'] == '2' || $result_iskh2['vidano'] == '3')
{
   $query_nal1 = "SELECT
tbl_film.user_id,
tbl_logins.login_id,
tbl_logins.familiya,
tbl_logins.name,
tbl_logins.otchestvo
FROM tbl_film
JOIN tbl_logins ON tbl_film.user_id=tbl_logins.login_id
WHERE film_id = '".$_GET['film_id']."' ";
  $result_nal = mysqli_query($dbcnx,$query_nal1);
  if(!$result_nal) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
      $result_nal1 = mysqli_fetch_array($result_nal);
      $user_name_nal1 = $result_nal1['familiya']." ".$result_nal1['name'];

   if($result_iskh2['vidano'] == '2')
   {
   $nal=  "<a href='nal_back.php?film_id=".$_GET['film_id']."' title='".$TEXT['book-nal']."'><img align='top' alt='".$TEXT['book-show3']."' src='skins/".$result2['skin']."/noobr.png' /></a>";
   echo "<tr><td class='inform'>".$TEXT['book-show3'].":&nbsp;</td><td class='input'>".$nal."</td></tr>";
   echo "<tr><td class='inform'>".$TEXT['book-who-viv'].":&nbsp;</td><td class='input'>".$user_name_nal1."</td></tr>";
   echo "<tr><td class='inform'>".$TEXT['book-data6'].":&nbsp;</td><td class='input'>".$data_r3."</td></tr>";
   echo "<tr><td class='inform'>".$TEXT['book-prichina'].":&nbsp;</td><td class='input'>".$result_iskh2['prichina']."</td></tr>";
   }
   else
    {
    $nal=  "<a href='nal_back.php?film_id=".$_GET['film_id']."' title='".$TEXT['book-zak']."'><img align='top' alt='".$TEXT['book-show5']."' src='skins/".$result2['skin']."/zakupka.png' /></a>";
    echo "<tr><td class='inform'>".$TEXT['book-show5'].":&nbsp;</td><td class='input'>".$nal."</td></tr>";
    echo "<tr><td class='inform'>".$TEXT['book-who-zak'].":&nbsp;</td><td class='input'>".$user_name_nal1."</td></tr>";
    echo "<tr><td class='inform'>".$TEXT['book-data5'].":&nbsp;</td><td class='input'>".$data_r3."</td></tr>";
    }
}
else
{

if($result_iskh2['vidano'] == '0')
{
$nal=  "<a href='nal_off_frm.php?film_id=".$_GET['film_id']."&amp;user_id=".$result_iskh2['user_id_zak']."' title='".$TEXT['book-nal-off']."'><img align='top' alt='".$TEXT['book-show2']."' src='skins/".$result2['skin']."/online.png' /></a>";
 echo "<tr><td class='inform'>".$TEXT['book-fldset3'].":&nbsp;</td><td class='input'>".$nal."</td></tr>";
}
else
{
$query_nal1 = "SELECT
tbl_film.user_id,
tbl_logins.login_id,
tbl_logins.familiya,
tbl_logins.name,
tbl_logins.otchestvo
FROM tbl_film
JOIN tbl_logins ON tbl_film.user_id=tbl_logins.login_id
WHERE film_id = '".$_GET['film_id']."' ";
  $result_nal = mysqli_query($dbcnx,$query_nal1);
  if(!$result_nal) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
      $result_nal1 = mysqli_fetch_array($result_nal);
      $user_name_nal1 = $result_nal1['familiya']." ".$result_nal1['name']." ".$result_nal1['otchestvo'];

$nal= "<a href='nal_on_frm.php?film_id=".$_GET['film_id']."'title='".$TEXT['book-nal']."'><img align='top' alt='".$TEXT['book-show2']."' src='skins/".$result2['skin']."/offline.png' /></a>";
 echo "<tr><td class='inform'>".$TEXT['book-fldset3'].":&nbsp;</td><td class='input'>".$nal."</td></tr>";
 echo "<tr><td class='inform'>".$TEXT['book-data3'].":&nbsp;</td><td class='input'>".$data_r3."</td></tr>";
 echo "<tr><td class='inform'>".$TEXT['book-data4'].":&nbsp;</td><td class='input'>".$data_r4."</td></tr>";
 echo "<tr><td class='inform'>".$TEXT['bppk-who-vid'].":&nbsp;</td><td class='input'>".$user_name_nal1."</td></tr>";
 echo "<tr><td class='inform'>".$TEXT['book-napom'].":&nbsp;</td><td class='input'>".$nap."</td></tr>";
}

if($result_iskh2['zakazano'] == '1')
{
$query_rez1 = "SELECT
tbl_film.user_id_zak,
tbl_logins.login_id,
tbl_logins.familiya,
tbl_logins.name,
tbl_logins.otchestvo
FROM tbl_film
JOIN tbl_logins ON tbl_film.user_id_zak=tbl_logins.login_id
WHERE film_id = '".$_GET['film_id']."' ";
  $result_rez = mysqli_query($dbcnx,$query_rez1);
  if(!$result_rez) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
      $result_rez1 = mysqli_fetch_array($result_rez);
      $user_name_rez1 = $result_rez1['familiya']." ".$result_rez1['name']." ".$result_rez1['otchestvo'];

$rez=  "<a href='film-rez_off.php?film_id=".$_GET['film_id']."' title='".$TEXT['book-rez-off']."'><img align='top' alt='".$TEXT['book-show2']."' src='skins/".$result2['skin']."/rezervon.png' /></a>";
echo "<tr><td class='inform'><hr width='30%' align='right' />".$TEXT['book-rez'].":&nbsp;</td><td class='input'><hr width='1%' align='left' />".$rez."</td></tr>";
echo "<tr><td class='inform'>".$TEXT['book-who-rez'].":&nbsp;</td><td class='input'>".$user_name_rez1."</td></tr>";
echo "<tr><td class='inform'>".$TEXT['book-data5'].":&nbsp;</td><td class='input'>".$data_r5."</td></tr>";
}
 else
{
$rez= "<a href='film-rez_on_frm.php?film_id=".$_GET['film_id']."'title='".$TEXT['book-rez-on']."'><img align='top' alt='".$TEXT['book-show2']."' src='skins/".$result2['skin']."/offline.png' /></a>";
echo "<tr><td class='inform'><hr width='30%' align='right' />".$TEXT['book-rez'].":&nbsp;</td><td class='input'><hr width='1%' align='left' />".$rez."</td></tr>";
}
}
?>
</table>
</fieldset>
</td></tr>
<tr><td colspan="3">
<input class="button" type=submit value='<?php echo $button; ?>' />
<input type="hidden" name=film_id value='<?php echo $_GET['film_id']; ?>' />
<?php
if(!empty($_GET['familiya'])) {echo "<input type=hidden name=familiya value='".$_GET['familiya']."' />";}
?>
</td></tr>
</table>
</form>
<?php
  require_once "utils/bottom_film.php";
?>