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

$title = $TEXT['aut-title'];
$button = $TEXT['btn_save'];
$action = "edit.php";

require_once "../config_a.php";
require_once "../utils/functions.php";
require_once "../utils/top_adm_film.php";

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

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

$query_iskh = "SELECT
film_id,
bibl_id,
tip_izd_id,
cicle_id,
zhanr_id,
film_name,
visible,
zal_id,
shkaf_id,
polka_id,
data_izdaniya,
data_postupleniya,
prod_min,
photo_film,
e_film,
opisanie,
oglavlenie,
ser_id,
film_num,
bl_id,
vozr_id,
subtitle,
autors
FROM `tbl_film`
WHERE `film_id`='".$_GET['film_id']."' ";
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm_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'];}

if($result_iskh2['visible'] == 1) {$visible = "checked";}
 else {$visible ="";}

if($result_iskh2['subtitle'] == '1') {$subtitle= $TEXT['book-zad-yes'];}
 else {$subtitle= $TEXT['book-zad-no'];}

$old_photo = $result_iskh2['photo_film'];
$old_efilm = $result_iskh2['e_film'];

$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_adm_film.php"; exit();}
    if(mysqli_num_rows($result_izd)>0)
      {
       while($result_izd2 = mysqli_fetch_array($result_izd))
       {
       $izd .=$result_izd2['izdatelstvo'].", ";
       }
       $izds ="<a href='edit_izd.php?film_id=".$_GET['film_id']."' title='".$TEXT['edit-tit']."'>".substr($izd, 0,-2)."</a>";
      } else {$izds = "<a href='edit_izd.php?film_id=".$_GET['film_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['film_name'] = rep_back($result_iskh2['film_name']);
     $result_iskh2['autors'] = rep_back($result_iskh2['autors']);
?>
<form name='film' 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['film-info']; ?>"><?php echo $TEXT['film-info']; ?></legend>
<table align="left" width="100%" border="0">
<tr><td class="inform"><?php echo $TEXT['film-name']; ?>:</td><td><input size=40 maxlength=127 type=text name=film_name value='<?php echo $result_iskh2['film_name']; ?>' /></td></tr>
<tr><td class="inform"><?php echo $TEXT['film-rezhiser']; ?>:&nbsp;</td><td class="input"><input size=40 maxlength=127 type=text name=autors value="<?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>
<tr><td class="inform">&#8470; <?php echo $TEXT['global-now-film2']; ?>:</td><td><input size=3 maxlength=3 type=text name=film_num value='<?php echo $film_num; ?>' /></td></tr>
<tr><td class="inform"><?php echo $TEXT['film-prod']; ?>:</td><td><input size=3 maxlength=3 type=text name=prod_min value='<?php echo $result_iskh2['prod_min']; ?>' /></td></tr>
<tr><td class="inform"><?php echo $TEXT['film-subtit']; ?>:</td><td>
 <select name=subtitle>
  <option value='1' <?php if ($result_iskh2['subtitle'] =='1') {echo "selected";} ?>><?php echo $TEXT['book-zad-yes']; ?>
  <option value='2' <?php if ($result_iskh2['subtitle'] =='2') {echo "selected";} ?>><?php echo $TEXT['book-zad-no']; ?>
 </select>
</td></tr>
<tr><td class="inform"><?php echo $TEXT['book-opis']; ?>:</td><td><textarea class="input" cols="38" rows="5" name=opisanie ><?php echo $result_iskh2['opisanie']; ?></textarea></td></tr>
<tr><td class="inform"><?php echo $TEXT['film-soderzh']; ?>:</td><td><textarea class="input" cols="38" rows="5" name=oglavlenie ><?php echo $result_iskh2['oglavlenie']; ?></textarea></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=text name=data_postupleniya value='<?php echo $result_iskh2['data_postupleniya']; ?>' />
<script type="text/javascript" language="JavaScript">
	var o_cal = new tcal ({
		// form name
		'formname': 'film',
		// 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` WHERE use_prog='2' ORDER BY `zhanr` ";
          $result10 = mysqli_query($dbcnx,$query10);
            if(!$result10) {puterror($result2['skin'],$TEXT['error-tbl14']); require_once "../utils/bottom_adm_film.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'].">".$result_zhanr['zhanr']."";}
                 else {$chk_zhanr = "<option value=".$result_zhanr['zhanr_id'].">".$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['menu-btn29-title-film']; ?>:</a></td><td>
    <select name="ser_id">
    <?php
        $queryser = "SELECT * FROM `tbl_seriya` WHERE use_prog='2' ORDER BY `seriya` ";
          $resultser = mysqli_query($dbcnx,$queryser);
            if(!$resultser) {puterror($result2['skin'],$TEXT['error-tbl21']); require_once "../utils/bottom_adm_film.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'].">".$result_seriya['seriya']."";}
                 else {$chk_seriya = "<option value=".$result_seriya['ser_id'].">".$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['menu-btn17']; ?>:</a></td><td>
    <select name="cicle_id">
    <?php
        $query11 = "SELECT * FROM `tbl_cicle` WHERE use_prog='2' ORDER BY `cicle` ";
          $result11 = mysqli_query($dbcnx,$query11);
            if(!$result11) {puterror($result2['skin'],$TEXT['error-tbl5']); require_once "../utils/bottom_adm_film.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'].">".$result_cicle['cicle']."";}
                 else {$chk_cicle = "<option value=".$result_cicle['cicle_id'].">".$result_cicle['cicle']."";}
                 echo $chk_cicle;
                }
    ?>
    </select></td></tr>
<tr><td class="inform"><a class="inform" href='../film-vozrast/addform.php' target="_blank"><?php echo $TEXT['menu-btn38-title']; ?>:</a></td><td>
    <select name="vozr_id">
    <?php
        $query17 = "SELECT * FROM `tbl_vozrast` ORDER BY `vozrast`";
          $result17 = mysqli_query($dbcnx,$query17);
            if(!$result17) {puterror($result2['skin'],$TEXT['error-tbl24']); require_once "../utils/bottom_adm_film.php"; exit();}
              while($result_bl = mysqli_fetch_array($result17))
                {
                 if($result_iskh2['vozr_id'] == $result_bl['vozr_id']) {$chk_bl = "<option selected value=".$result_bl['vozr_id'].">".$result_bl['vozrast']."";}
                 else {$chk_bl = "<option value=".$result_bl['vozr_id'].">".$result_bl['vozrast']."";}
                 echo $chk_bl;
                }
    ?>
    </select></td></tr>
<tr><td class="inform"><a class="inform" href='../film-sound/addform.php' target="_blank" title="<?php echo $TEXT['menu-btn37-title']; ?>"><?php echo $TEXT['menu-btn37']; ?>:</a></td><td>
    <select name="bl_id">
    <?php
        $query18 = "SELECT `bl_id`, `position`, `booklang` FROM `tbl_booklang` WHERE use_prog='2' ORDER BY `position`, `booklang` ";
          $result18 = mysqli_query($dbcnx,$query18);
            if(!$result18) {puterror($result2['skin'],$TEXT['error-tbl23']); require_once "../utils/bottom_adm_film.php"; exit();}
              while($result_snd = mysqli_fetch_array($result18))
                {
                 if($result_iskh2['bl_id'] == $result_snd['bl_id']) {$chk_snd = "<option selected value=".$result_snd['bl_id'].">".$result_snd['booklang']."";}
                 else {$chk_snd = "<option value=".$result_snd['bl_id'].">".$result_snd['booklang']."";}
                 echo $chk_snd;
                }
    ?>
    </select></td></tr>
<tr><td  class="inform"><a class="inform" href='../film-nositel/addform.php' target="_blank"><?php echo $TEXT['nositel-title']; ?>:</a></td><td>
    <select name="tip_izd_id">
    <?php
        $query12 = "SELECT * FROM `tbl_tip_izd` WHERE use_prog='2' ORDER BY `tip_izd` ";
          $result12 = mysqli_query($dbcnx,$query12);
            if(!$result12) {puterror($result2['skin'],$TEXT['error-tbl15']); require_once "../utils/bottom_adm_film.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'].">".$result_izd['tip_izd']."";}
                 else {$chk_izd = "<option value=".$result_izd['tip_izd_id'].">".$result_izd['tip_izd']."";}
                 echo $chk_izd;
                }
    ?>
    </select></td></tr>
<tr><td  class="inform"><?php echo $TEXT['user-photo']; ?>:</td><td><input size=10 type=file name=photo  />  <input type=checkbox name=clear_photo />&nbsp;<span class="inform"><?php echo $TEXT['delete-new']; ?></span></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"><?php echo $TEXT['book-ebook']; ?>:</td><td><input size=10 type=file name=e_film  />  <input type=checkbox name=clear_e_film />&nbsp;<span class="inform"><?php echo $TEXT['delete-new']; ?></span></td></tr>
<tr><td  class="inform"><a class="inform" href='../film-libr/addform.php' target="_blank"><?php echo $TEXT['global-film']; ?>:</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_film.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_film.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_film.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_film.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"><?php echo $TEXT['book-show']; ?></td><td><input type=checkbox name=visible <?php echo $visible; ?> /></td></tr>
</table>
</fieldset>
</td></tr>
<tr><td><input class="button2" type=submit value='<?php echo $button; ?>' />
<input type=hidden name=film_id value='<?php echo $_GET['film_id']; ?>' />
<input type=hidden name=old_photo value='<?php echo $old_photo; ?>' />
<input type=hidden name=old_efilm value='<?php echo $old_efilm; ?>' />
</td><td></td></tr>
</table>
</form>
<?php
  require_once "../utils/bottom_adm_film.php";
?>