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

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

  $title = $TEXT['aut-title-info'];
  $button = $TEXT['btn_back'];
  $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(empty($_GET['book_id'])) {puterror($result2['skin'],$TEXT['error-book5']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['book_id'])>255) {puterror($result2['skin'],$TEXT['error-book6']); require_once "../utils/bottom_adm.php"; exit();}
  $_GET['book_id'] = rep($_GET['book_id']);

$query_iskh = "SELECT 
tbl_book.*,
UNIX_TIMESTAMP(tbl_book.data_postupleniya) AS data_postupleniya,
UNIX_TIMESTAMP(tbl_book.data_vidachi) AS data_vidachi,
UNIX_TIMESTAMP(tbl_book.data_sdachi) AS data_sdachi,
UNIX_TIMESTAMP(tbl_book.data_zakaza) AS data_zakaza,
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_booklang.bl_id,
tbl_booklang.booklang,
tbl_booklang.picture
FROM tbl_book
JOIN tbl_cicle ON tbl_book.cicle_id=tbl_cicle.cicle_id
JOIN tbl_biblioteka ON tbl_book.bibl_id=tbl_biblioteka.bibl_id
JOIN tbl_zhanr ON tbl_book.zhanr_id=tbl_zhanr.zhanr_id
JOIN tbl_tip_izd ON tbl_book.tip_izd_id=tbl_tip_izd.tip_izd_id
JOIN tbl_zal ON tbl_book.zal_id=tbl_zal.zal_id
JOIN tbl_shkaf ON tbl_book.shkaf_id=tbl_shkaf.shkaf_id
JOIN tbl_polka ON tbl_book.polka_id=tbl_polka.polka_id
JOIN tbl_seriya ON tbl_book.ser_id=tbl_seriya.ser_id
JOIN tbl_booklang ON tbl_book.bl_id=tbl_booklang.bl_id
WHERE book_id = '".$_GET['book_id']."' ";
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm.php"; exit();}
      $result_iskh2 = mysqli_fetch_array($result_iskh);

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

      $date_day = date("d",$result_iskh2['data_postupleniya']);
      $date_month = date("m",$result_iskh2['data_postupleniya']);
      $date_year = date("Y",$result_iskh2['data_postupleniya']);
      $year = $TEXT['year2'];
      if($result_iskh2['data_postupleniya'] == "0") {$data_r = "---";}
       else {$data_r = (date("$date_day $month[$date_month] $date_year $year"));}

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

      $date_day3 = date("d",$result_iskh2['data_vidachi']);
      $date_month3 = date("m",$result_iskh2['data_vidachi']);
      $date_year3 = date("Y",$result_iskh2['data_vidachi']);
      if($result_iskh2['data_vidachi'] == "0") {$data_r3 = "---";}
       else {$data_r3 = (date("$date_day3 $month[$date_month3] $date_year3 $year"));}

      $date_day4 = date("d",$result_iskh2['data_sdachi']);
      $date_month4 = date("m",$result_iskh2['data_sdachi']);
      $date_year4 = date("Y",$result_iskh2['data_sdachi']);
      if($result_iskh2['data_sdachi'] == "0") {$data_r4 = "---";}
       else {$data_r4 = (date("$date_day4 $month[$date_month4] $date_year4 $year"));}

      $date_day5 = date("d",$result_iskh2['data_zakaza']);
      $date_month5 = date("m",$result_iskh2['data_zakaza']);
      $date_year5 = date("Y",$result_iskh2['data_zakaza']);
      if($result_iskh2['data_zakaza'] == "0") {$data_r5 = "---";}
       else {$data_r5 = (date("$date_day5 $month[$date_month5] $date_year5 $year"));}

     $query_autor = "SELECT
     tbl_s_book_aut.*,
     tbl_autor.autor_id,
     tbl_autor.name,
     tbl_autor.familiya,
     tbl_autor.otchestvo
     FROM tbl_s_book_aut
     JOIN tbl_autor ON tbl_s_book_aut.autor_id=tbl_autor.autor_id
    WHERE book_id = '".$_GET['book_id']."' ";
    $result_autor = mysqli_query($dbcnx,$query_autor);
     if (!$result_autor) {puterror($result2['skin'],$TEXT['error-tbl16']); require_once "../utils/bottom_adm.php"; exit();}
      while($result_autor2 = mysqli_fetch_array($result_autor))
       {
           $autor .=$result_autor2['name']." ".$result_autor2['otchestvo']." ".$result_autor2['familiya'].", ";
       }
       $autors =substr($autor, 0,-2);

     $query_izd = "SELECT
     tbl_s_book_izd.*,
     tbl_izdatelstvo.*
     FROM tbl_s_book_izd
     JOIN tbl_izdatelstvo ON tbl_s_book_izd.izd_id=tbl_izdatelstvo.izd_id
     WHERE book_id = '".$_GET['book_id']."' ";
     $result_izd = mysqli_query($dbcnx,$query_izd);
      if (!$result_izd) {puterror($result2['skin'],$TEXT['error-tbl17']); require_once "../utils/bottom_adm.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 = "";}

      if(!empty($result_iskh2['photo_book']) && file_exists($result_iskh2['photo_book'])) {$result_image = "<a href='editform.php?book_id=".$_GET['book_id']."' title='".$TEXT['edit-tit']."'><img alt='".$TEXT['global-alt']."' src='".$result_iskh2['photo_book']."' /></a>";}
        else {$result_image =  "<a href='editform.php?book_id=".$_GET['book_id']."' title='".$TEXT['edit-tit']."'><img alt='".$TEXT['global-alt']."' src='../skins/".$result2['skin']."/nophoto.png' /></a>";}

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

       if($result_iskh2['visible'] == '1') {$vis=  "<a href='vis_off.php?book_id=".$_GET['book_id']."' title='".$TEXT['book-show-off']."'><img align='top' alt='".$TEXT['book-show2']."' src='../skins/".$result2['skin']."/visible.png' /></a>";}
        else {$vis= "<a href='vis_on.php?book_id=".$_GET['book_id']."'title='".$TEXT['book-show']."'><img align='top' alt='".$TEXT['book-show2']."' src='../skins/".$result2['skin']."/invisible.png' /></a>";}

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

       $result_iskh2['opisanie'] = rep_back($result_iskh2['opisanie']);
       $result_iskh2['oglavlenie'] = rep_back($result_iskh2['oglavlenie']);
       $result_iskh2['book_name'] = rep_back($result_iskh2['book_name']);
       $result_iskh2['isbn'] = rep_back($result_iskh2['isbn']);
?>
<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['book_name']."</td><td width='15%' align='right' title='".$TEXT['menu-btn35']." &raquo; ".$result_iskh2['booklang']."'>".$result_bl."</td></tr>";}
  elseif($result_iskh2['vidano'] == '2') {echo "<tr><td class='zagolovok_sp'>&nbsp;".$result_iskh2['book_name']."</td><td width='15%' align='right' title='".$TEXT['menu-btn35']." &raquo; ".$result_iskh2['booklang']."'>".$result_bl."</td></tr>";}
 else {echo "<tr><td class='zagolovok'>&nbsp;".$result_iskh2['book_name']."</td><td width='15%' align='right' title='".$TEXT['menu-btn35']." &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_book'])) $e_book = "<tr><td class='informcntr'><a class='informcntr' href='".$result_iskh2['e_book']."' target=_blank title='".$result_iskh2['book_name']."'>".$TEXT['book-ebook']."</a></td></tr>";
       $fl = $result_iskh2['e_book'];
      if(!empty($result_iskh2['e_book']) && file_exists($fl)) {$e_book = "<tr><td class='informcntr'><a class='informcntr' href='get_book.php?book_id=".$result_iskh2['book_id']."' target=_blank title='".$result_iskh2['book_name']."'>".$TEXT['book-ebook']."</a></td></tr>";}
       else {$e_book = "";}
      echo $e_book;
    ?>
    </table>
</td>
<td width="42%" valign="top">
<fieldset>
    <legend align="left" title="<?php echo $TEXT['book-fldset1-tit']; ?>"><?php echo $TEXT['book-fldset1']; ?></legend>
<table align="left" width="100%" border="0">
<tr><td class="inform"><?php echo $TEXT['menu-btn23']; ?>:&nbsp;</td><td class="input"><?php echo $autors; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['menu-btn22']; ?>:&nbsp;</td><td class="input"><?php echo $izds; ?></td></tr>
<?php
if(!empty($result_iskh2['isbn'])) {echo "<tr><td class='inform'>".$TEXT['book-isbn'].":&nbsp;</td><td class='input'>".$result_iskh2['isbn']."</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['book-cicle'].":&nbsp;</td><td class='input'>".$result_iskh2['cicle']."</td></tr>";}
if(!empty($result_iskh2['book_num']) && $result_iskh2['book_num'] !== "0") {echo "<tr><td class='inform'>".$TEXT['book-num'].":&nbsp;</td><td class='input'>".$book_num."</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['book-oglavl'].":&nbsp;</td><td class='ogl'>".nl2br($result_iskh2['oglavlenie'])."</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['ser-title']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['seriya']; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-tip-izd']; ?>:&nbsp;</td><td class="input"><?php echo $result_iskh2['tip_izd']; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-bibl']; ?>:&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>
<tr><td class="inform"><?php echo $TEXT['book-show2']; ?>:&nbsp;</td><td><?php echo $vis; ?></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_book.user_id,
tbl_logins.login_id,
tbl_logins.familiya,
tbl_logins.name,
tbl_logins.otchestvo
FROM tbl_book
JOIN tbl_logins ON tbl_book.user_id=tbl_logins.login_id
WHERE book_id = '".$_GET['book_id']."' ";
  $result_nal = mysqli_query($dbcnx,$query_nal1);
  if (!$result_nal) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm.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?book_id=".$_GET['book_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?book_id=".$_GET['book_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?book_id=".$_GET['book_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_book.user_id,
tbl_logins.login_id,
tbl_logins.familiya,
tbl_logins.name,
tbl_logins.otchestvo
FROM tbl_book
JOIN tbl_logins ON tbl_book.user_id=tbl_logins.login_id
WHERE book_id = '".$_GET['book_id']."' ";
  $result_nal = mysqli_query($dbcnx,$query_nal1);
  if (!$result_nal) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm.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?book_id=".$_GET['book_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['book-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_book.user_id_zak,
tbl_logins.login_id,
tbl_logins.familiya,
tbl_logins.name,
tbl_logins.otchestvo
FROM tbl_book
JOIN tbl_logins ON tbl_book.user_id_zak=tbl_logins.login_id
WHERE book_id = '".$_GET['book_id']."' ";
  $result_rez = mysqli_query($dbcnx,$query_rez1);
  if (!$result_rez) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm.php"; exit();}
      $result_rez1 = mysqli_fetch_array($result_rez);
      $user_name_rez1 = $result_rez1['familiya']." ".$result_rez1['name']." ".$result_rez1['otchestvo'];

$rez=  "<a href='rez_off.php?book_id=".$_GET['book_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='rez_on_frm.php?book_id=".$_GET['book_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=book_id value='<?php echo $_GET['book_id']; ?>' />
<?php
if(!empty($_GET['familiya'])) {echo "<input type=hidden name=familiya value='".$_GET['familiya']."' />";}
?>
</td></tr>
</table>
</form>
<?php
  require_once "../utils/bottom_adm.php";
?>