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

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

  $title = $TEXT['book-title'];
  $button = $TEXT['btn_save'];
  $action = "edit.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($_POST['book_id']))
{
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']);
$book_id = $_GET['book_id'];
}
else
{
if(strlen($_POST['book_id'])>255) {puterror($result2['skin'],$TEXT['error-book6']); require_once "../utils/bottom_adm.php"; exit();}
$_POST['book_id'] = rep($_POST['book_id']);
$book_id = $_POST['book_id'];
}

$query_iskh = "SELECT
book_id,
bibl_id,
tip_izd_id,
cicle_id,
zhanr_id,
book_name,
visible,
vidano,
zal_id,
shkaf_id,
polka_id,
data_izdaniya,
data_postupleniya,
isbn,
photo_book,
e_book,
opisanie,
oglavlenie,
ser_id,
book_num,
bl_id,
bl2_id,
paper_copy,
remote_copy,
a_book,
cd_book,
prev_books
FROM `tbl_book`
WHERE `book_id`='".$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'];}

if($result_iskh2['visible'] == 1) {$visible = "checked";}
 else {$visible ="";}
 
if($result_iskh2['vidano'] == 3) {$zakupka = "&nbsp;<img alt='".$TEXT['book-show5']."' src='../skins/".$result2['skin']."/zakupka.png' />";}
 else {$zakupka ="<input type='checkbox' name='zakupka' />";}

if($result_iskh2['paper_copy'] == "yes") {$paper_copy = "<input type='checkbox' name='paper_copy' checked />";}
 else {$paper_copy ="<input type='checkbox' name='paper_copy' />";}

if($result_iskh2['remote_copy'] == "yes") {$remote_copy = "<input type='checkbox' name='remote_copy' checked />";}
 else {$remote_copy ="<input type='checkbox' name='remote_copy' />";}

if($result_iskh2['prev_books'] == 0) {$prev_books = "<input type='checkbox' name='prev_books' checked />";}
 else {$prev_books ="<input type='checkbox' name='prev_books' />";}

$old_photo = $result_iskh2['photo_book'];
$old_ebook = $result_iskh2['e_book'];
$old_abook = $result_iskh2['a_book'];
$old_cdbook = $result_iskh2['cd_book'];

$aeb_pic_delete = "<img alt='delete book' src='../skins/".$result2['skin']."/delete.png' />";
$aeb_pic_chname = "<img alt='change book name' src='../skins/".$result2['skin']."/back-book.png' />";
$aeb_pic_10 = "<img alt='10+' src='../skins/".$result2['skin']."/up10-2.png' />";

if(!empty($old_photo) && $old_photo !== "") {$chk_book = "&nbsp;<input type='checkbox' name='clear_photo' />&nbsp;<span class='inform'>".$TEXT['delete-new']."</span>";}
  else {$chk_book = "";}

if(!empty($old_ebook) && $old_ebook !== "") {$chk_ebook = "&nbsp;<input type='checkbox' name='clear_e_book' title=".$TEXT['delete-new']." />&nbsp;".$aeb_pic_delete." | &nbsp;<input type='checkbox' name='chname_e_book' title='".$TEXT['book-chname']."' />&nbsp;".$aeb_pic_chname." | &nbsp;<input type='checkbox' name='e_book_10' title='".$TEXT['book-chname3']."' />&nbsp;".$aeb_pic_10."";}
  else {$chk_ebook = "";}

if(!empty($old_abook) && $old_abook !== "") {$chk_abook = "&nbsp;<input type='checkbox' name='clear_a_book' title=".$TEXT['delete-new']." />&nbsp;".$aeb_pic_delete." | &nbsp;<input type='checkbox' name='chname_a_book' title='".$TEXT['book-chname']."' />&nbsp;".$aeb_pic_chname." | &nbsp;<input type='checkbox' name='a_book_10' title='".$TEXT['book-chname3']."' />&nbsp;".$aeb_pic_10."";}
  else {$chk_abook = "";}

if(!empty($old_cdbook) && $old_cdbook !== "") {$chk_cdbook = "&nbsp;<input type='checkbox' name='clear_cd_book' title=".$TEXT['delete-new']." />&nbsp;".$aeb_pic_delete." | &nbsp;<input type='checkbox' name='chname_cd_book' title='".$TEXT['book-chname']."' />&nbsp;".$aeb_pic_chname." | &nbsp;<input type='checkbox' name='cd_book_10' title='".$TEXT['book-chname3']."' />&nbsp;".$aeb_pic_10."";}
  else {$chk_cdbook = "";}


     $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 = '".$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();}
     if(mysqli_num_rows($result_autor)>0)
     {
      while($result_autor2 = mysqli_fetch_array($result_autor))
       {
       $autor .=rep_back($result_autor2['name'])." ".rep_back($result_autor2['otchestvo'])." ".rep_back($result_autor2['familiya']).", ";
       }
       $autors ="<a href='edit_autor.php?book_id=".$book_id."' title='".$TEXT['edit-tit']."'>".substr($autor, 0,-2)."</a>";
     } else {$autors = "<a href='edit_autor.php?book_id=".$book_id."' title='".$TEXT['edit-tit']."'>".$TEXT['add-new']."</a>";}

     $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 = '".$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();}
      if(mysqli_num_rows($result_izd)>0)
      {
       while($result_izd2 = mysqli_fetch_array($result_izd))
       {
       $izd .=rep_back($result_izd2['izdatelstvo']).", ";
       }
       $izds ="<a href='edit_izd.php?book_id=".$book_id."' title='".$TEXT['edit-tit']."'>".substr($izd, 0,-2)."</a>";
      } else {$izds = "<a href='edit_izd.php?book_id=".$book_id."' title='".$TEXT['edit-tit']."'>".$TEXT['add-new']."</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 name="book" enctype="multipart/form-data" action="<?php echo $action; ?>" method="post">
<script type="text/javascript" language="JavaScript" src="../lang/<?php echo $lang; ?>/calendar.js"></script>
<table align="center" width="98%" border="0">
<tr>
<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['book-name']; ?>:</td><td><input size="50" maxlength="127" type="text" name="book_name" value="<?php echo $result_iskh2['book_name']; ?>" /></td></tr>
<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>
<tr><td class="inform"><?php echo $TEXT['book-isbn']; ?>:</td><td><input size="50" maxlength="127" type="text" name="isbn" value="<?php echo $result_iskh2['isbn']; ?>" /></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-num']; ?>:</td><td><input size="3" maxlength="3" type="text" name="book_num" value="<?php echo $book_num; ?>" /></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-opis']; ?>:</td><td><textarea cols="48" rows="5" name="opisanie" ><?php echo $result_iskh2['opisanie']; ?></textarea></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-oglavl']; ?>:</td><td><textarea cols="48" rows="7" name="oglavlenie" ><?php echo $result_iskh2['oglavlenie']; ?></textarea></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-paper']; ?>:</td><td><?php echo $paper_copy; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-remote']; ?>:</td><td><?php echo $remote_copy; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-prereq']; ?>:</td><td title="<?php echo $TEXT['book-cicle']; ?>">
<select name="prev_books">
    <?php
        $query111 = "SELECT * FROM `tbl_cicle` ORDER BY `cicle` ";
          $result111 = mysqli_query($dbcnx,$query111);
            if(!$result111) {puterror($result2['skin'],$TEXT['error-tbl5']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_prev_books = mysqli_fetch_array($result111))
                {
                if($result_iskh2['prev_books'] == $result_prev_books['cicle_id']) {$chk_prev_books = "<option selected value=".$result_prev_books['cicle_id'].">".rep_back($result_prev_books['cicle'])."";}
                 else {$chk_prev_books = "<option value=".$result_prev_books['cicle_id'].">".rep_back($result_prev_books['cicle'])."";}
                 echo $chk_prev_books;
                }
    ?>
    </select></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']; ?>:</td><td><input size="4" maxlength="4" type="text" name="data_izdaniya" value="<?php echo  $result_iskh2['data_izdaniya']; ?>" /></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-data2']; ?>:</td><td><input size="10" maxlength="10" type="date" name="data_postupleniya" value="<?php echo $result_iskh2['data_postupleniya']; ?>" />
<script type="text/javascript" language="JavaScript">
	var o_cal = new tcal ({
		// form name
		'formname': 'book',
		// input name
		'controlname': 'data_postupleniya'
	});
	</script></td></tr>
<tr><td class="inform"><a class="inform" href="../zhanr/addform.php" target="_blank"><?php echo $TEXT['book-zhanr']; ?>:</a></td><td>
    <select name="zhanr_id">
    <?php
        $query10 = "SELECT * FROM `tbl_zhanr`ORDER BY `zhanr` ";
          $result10 = mysqli_query($dbcnx,$query10);
            if(!$result10) {puterror($result2['skin'],$TEXT['error-tbl14']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_zhanr = mysqli_fetch_array($result10))
                {
                if($result_iskh2['zhanr_id'] == $result_zhanr['zhanr_id']) {$chk_zhanr = "<option selected value=".$result_zhanr['zhanr_id'].">".rep_back($result_zhanr['zhanr'])."";}
                 else {$chk_zhanr = "<option value=".$result_zhanr['zhanr_id'].">".rep_back($result_zhanr['zhanr'])."";}
                 echo $chk_zhanr;
                }
    ?>
    </select></td></tr>
<tr><td  class="inform"><a class="inform" href="../seriya/addform.php" target="_blank"><?php echo $TEXT['ser-title']; ?>:</a></td><td>
    <select name="ser_id">
    <?php
        $queryser = "SELECT * FROM `tbl_seriya` ORDER BY `seriya` ";
          $resultser = mysqli_query($dbcnx,$queryser);
            if(!$resultser) {puterror($result2['skin'],$TEXT['error-tbl21']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_seriya = mysqli_fetch_array($resultser))
                {
                if($result_iskh2['ser_id'] == $result_seriya['ser_id']) {$chk_seriya = "<option selected value=".$result_seriya['ser_id'].">".rep_back($result_seriya['seriya'])."";}
                 else {$chk_seriya = "<option value=".$result_seriya['ser_id'].">".rep_back($result_seriya['seriya'])."";}
                 echo $chk_seriya;
                }
    ?>
    </select></td></tr>
<tr><td  class="inform"><a class="inform" href="../cicl/addform.php" target="_blank"><?php echo $TEXT['book-cicle']; ?>:</a></td><td>
    <select name="cicle_id">
    <?php
        $query11 = "SELECT * FROM `tbl_cicle` ORDER BY `cicle` ";
          $result11 = mysqli_query($dbcnx,$query11);
            if(!$result11) {puterror($result2['skin'],$TEXT['error-tbl5']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_cicle = mysqli_fetch_array($result11))
                {
                if($result_iskh2['cicle_id'] == $result_cicle['cicle_id']) {$chk_cicle = "<option selected value=".$result_cicle['cicle_id'].">".rep_back($result_cicle['cicle'])."";}
                 else {$chk_cicle = "<option value=".$result_cicle['cicle_id'].">".rep_back($result_cicle['cicle'])."";}
                 echo $chk_cicle;
                }
    ?>
    </select></td></tr>
<tr><td  class="inform"><a class="inform" href="../typeizd/addform.php" target="_blank"><?php echo $TEXT['book-tip-izd']; ?>:</a></td><td>
    <select name="tip_izd_id">
    <?php
        $query12 = "SELECT * FROM `tbl_tip_izd` ORDER BY `tip_izd` ";
          $result12 = mysqli_query($dbcnx,$query12);
            if(!$result12) {puterror($result2['skin'],$TEXT['error-tbl15']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_izd = mysqli_fetch_array($result12))
                {
                if($result_iskh2['tip_izd_id'] == $result_izd['tip_izd_id']) {$chk_izd = "<option selected value=".$result_izd['tip_izd_id'].">".rep_back($result_izd['tip_izd'])."";}
                 else {$chk_izd = "<option value=".$result_izd['tip_izd_id'].">".rep_back($result_izd['tip_izd'])."";}
                 echo $chk_izd;
                }
    ?>
    </select></td></tr>
<tr><td class="inform" title="195x275"><?php echo $TEXT['user-photo']; ?>:</td><td><input size="10" type="file" name="photo" /><?php echo $chk_book; ?></td></tr>
<tr><td class="inform"><?php echo $TEXT['photo_obr']; ?>:</td><td>
 <select name="photo_obr">
  <option value="1" selected><?php echo $TEXT['photo_no']; ?>
  <option value="2" ><?php echo $TEXT['photo_rec_l']; ?>
  <option value="4" ><?php echo $TEXT['photo_rec_l_t']; ?>
  <option value="6" ><?php echo $TEXT['photo_rec_l_r']; ?>
 </select>
</td></tr>
<tr><td class="inform" title="<?php echo substr(strrchr($old_ebook, "/"), 1); ?>"><?php echo $TEXT['book-ebook']; ?>:</td><td><input size="10" type="file" name="e_book" /><?php echo $chk_ebook; ?></td></tr>
<tr><td class="inform" title="<?php echo substr(strrchr($old_abook, "/"), 1); ?>"><?php echo $TEXT['book-audio']; ?>:</td><td><input size="10" type="file" name="a_book" /><?php echo $chk_abook; ?></td></tr>
<tr><td class="inform" title="<?php echo substr(strrchr($old_cdbook, "/"), 1); ?>"><?php echo $TEXT['book-cdrom']; ?>:</td><td><input size="10" type="file" name="cd_book" /><?php echo $chk_cdbook; ?></td></tr>
<tr><td class="inform"><a class="inform" href="../libr/addform.php" target="_blank"><?php echo $TEXT['book-bibl']; ?>:</a></td><td>
    <select name="bibl_id">
    <?php
        $query13 = "SELECT name, bibl_id FROM `tbl_biblioteka` ORDER BY `name` ";
          $result13 = mysqli_query($dbcnx,$query13);
            if(!$result13) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_libr = mysqli_fetch_array($result13))
                {
                if($result_iskh2['bibl_id'] == $result_libr['bibl_id']) {$chk_libr = "<option selected value=".$result_libr['bibl_id'].">".$result_libr['name']."";}
                 else {$chk_libr = "<option value=".$result_libr['bibl_id'].">".$result_libr['name']."";}
                 echo $chk_libr;
                }
    ?>
    </select></td></tr>
<tr><td  class="inform"><a class="inform" href="../zal/addform.php" target="_blank"><?php echo $TEXT['book-zal']; ?>:</a></td><td>
    <select name="zal_id">
    <?php
        $query14 = "SELECT * FROM `tbl_zal` ORDER BY `zal` ";
          $result14 = mysqli_query($dbcnx,$query14);
            if(!$result14) {puterror($result2['skin'],$TEXT['error-tbl11']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_zal = mysqli_fetch_array($result14))
                {
                if($result_iskh2['zal_id'] == $result_zal['zal_id']) {$chk_zal = "<option selected value=".$result_zal['zal_id'].">".$result_zal['zal']."";}
                 else {$chk_zal = "<option value=".$result_zal['zal_id'].">".$result_zal['zal']."";}
                 echo $chk_zal;
                }
    ?>
    </select></td></tr>
<tr><td  class="inform"><a class="inform" href="../shkaf/addform.php" target="_blank"><?php echo $TEXT['book-shkaf']; ?>:</a></td><td>
    <select name="shkaf_id">
    <?php
        $query15 = "SELECT * FROM `tbl_shkaf` ORDER BY `shkaf` ";
          $result15 = mysqli_query($dbcnx,$query15);
            if(!$result15) {puterror($result2['skin'],$TEXT['error-tbl9']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_shkaf = mysqli_fetch_array($result15))
                {
                if($result_iskh2['shkaf_id'] == $result_shkaf['shkaf_id']) {$chk_shkaf = "<option selected value=".$result_shkaf['shkaf_id'].">".$result_shkaf['shkaf']."";}
                 else {$chk_shkaf = "<option value=".$result_shkaf['shkaf_id'].">".$result_shkaf['shkaf']."";}
                 echo $chk_shkaf;
                }
    ?>
    </select></td></tr>
<tr><td  class="inform"><a class="inform" href="../polki/addform.php" target="_blank"><?php echo $TEXT['book-polka']; ?>:</a></td><td>
    <select name="polka_id">
    <?php
        $query16 = "SELECT * FROM `tbl_polka` ORDER BY `polka` ";
          $result16 = mysqli_query($dbcnx,$query16);
            if(!$result16) {puterror($result2['skin'],$TEXT['error-tbl8']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_polka = mysqli_fetch_array($result16))
                {
                if($result_iskh2['polka_id'] == $result_polka['polka_id']) {$chk_polka = "<option selected value=".$result_polka['polka_id'].">".$result_polka['polka']."";}
                 else {$chk_polka = "<option value=".$result_polka['polka_id'].">".$result_polka['polka']."";}
                 echo $chk_polka;
                }
    ?>
    </select></td></tr>
<tr><td class="inform"><a class="inform" href="../book_lang/addform.php" target="_blank"><?php echo $TEXT['menu-btn35']; ?>:</a></td><td>
    <select name="bl_id">
    <?php
        $query17 = "SELECT `bl_id`, `position`, `booklang` FROM `tbl_booklang` ORDER BY `position`, `booklang` ";
          $result17 = mysqli_query($dbcnx,$query17);
            if(!$result17) {puterror($result2['skin'],$TEXT['error-tbl23']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_bl = mysqli_fetch_array($result17))
                {
                if($result_iskh2['bl_id'] == $result_bl['bl_id']) {$chk_bl = "<option selected value=".$result_bl['bl_id'].">".$result_bl['booklang']."";}
                 else {$chk_bl = "<option value=".$result_bl['bl_id'].">".$result_bl['booklang']."";}
                 echo $chk_bl;
                }
    ?>
    </select></td></tr>
<tr><td class="inform"><?php echo $TEXT['menu-btn35-2']; ?>:</td><td>
    <select name="bl2_id">
    <?php
        $query17 = "SELECT `bl_id`, `position`, `booklang` FROM `tbl_booklang` ORDER BY `position`, `booklang` ";
          $result17 = mysqli_query($dbcnx,$query17);
            if(!$result17) {puterror($result2['skin'],$TEXT['error-tbl23']); require_once "../utils/bottom_adm.php"; exit();}
              while($result_bl = mysqli_fetch_array($result17))
                {
                if($result_iskh2['bl2_id'] == $result_bl['bl_id']) {$chk_bl = "<option selected value=".$result_bl['bl_id'].">".$result_bl['booklang']."";}
                 else {$chk_bl = "<option value=".$result_bl['bl_id'].">".$result_bl['booklang']."";}
                 echo $chk_bl;
                }
    ?>
    </select></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-show']; ?>:</td><td><input type="checkbox" name="visible" <?php echo $visible; ?> /></td></tr>
<tr><td class="inform"><?php echo $TEXT['book-show5']; ?>:</td><td><?php echo $zakupka; ?></td></tr>
</table>
</fieldset>
</td></tr>
<tr><td><input class="button2" type="submit" value="<?php echo $button; ?>" />
<input type="hidden" name="book_id" value="<?php echo $book_id; ?>" />
<input type="hidden" name="old_photo" value="<?php echo $old_photo; ?>" />
<input type="hidden" name="old_ebook" value="<?php echo $old_ebook; ?>" />
<input type="hidden" name="old_abook" value="<?php echo $old_abook; ?>" />
<input type="hidden" name="old_cdbook" value="<?php echo $old_cdbook; ?>" />
</td><td></td></tr>
</table>
</form>
<?php
  require_once "../utils/bottom_adm.php";
?>