<?php
  ///////////////////////////////////////////////////
  //Выдать книгу
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////
  require_once "utils/chlang_osn.php";

  $title = $TEXT['aut-title-info'];

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

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

  if(empty($_POST['film_id'])) {puterror2($result2['skin'],$TEXT['error-film5']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_POST['film_id'])>20) {puterror2($result2['skin'],$TEXT['error-film6']); require_once "utils/bottom_film.php"; exit();}
  if(empty($_POST['user_id'])) {puterror2($result2['skin'],$TEXT['error-login15']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_POST['user_id'])>15) {puterror2($result2['skin'],$TEXT['error-login14']); require_once "utils/bottom_film.php"; exit();}
  if(empty($_POST['data_vidachi'])) {puterror2($result2['skin'],$TEXT['error-film14']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_POST['data_vidachi'])>10) {puterror2($result2['skin'],$TEXT['error-film15']); require_once "utils/bottom_film.php"; exit();}
  if(empty($_POST['data_sdachi'])) {puterror2($result2['skin'],$TEXT['error-film16']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_POST['data_sdachi'])>10) {puterror2($result2['skin'],$TEXT['error-film17']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_POST['napominalka'])>3) {puterror2($result2['skin'],$TEXT['error-film18']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_POST['naloff'])>3) {puterror2($result2['skin'],$TEXT['error-film19']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_POST['prichina'])>255) {puterror2($result2['skin'],$TEXT['error-film20']); require_once "utils/bottom_film.php"; exit();}
  $_POST['film_id'] = rep($_POST['film_id']);
  $_POST['user_id'] = rep($_POST['user_id']);
  $_POST['data_vidachi'] = rep($_POST['data_vidachi']);
  $_POST['data_sdachi'] = rep($_POST['data_sdachi']);
  $_POST['napominalka'] = rep($_POST['napominalka']);
  $_POST['naloff'] = rep($_POST['naloff']);
  $_POST['prichina'] = rep($_POST['prichina']);

  if($_POST['napominalka'] == "on") {$napominalka = 1;}
   else {$napominalka =0;}

$query_iskh = "SELECT `film_name` FROM `tbl_film` WHERE `film_id` = '".$_POST['film_id']."' ";
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror2($result2['skin'],$TEXT['error-tbl26']); require_once "utils/bottom_film.php"; exit();}
   $result_iskh2 = mysqli_fetch_array($result_iskh);

  if($_POST['naloff'] == "on")
  {
  //*************************************
  //Информация для лога
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-film6'];
  $what = $result_iskh2['film_name'].", ".$TEXT['log-id']." ".$_POST['film_id'];
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************
  $query = "UPDATE `tbl_film` SET `napominalka`='0', `user_id`='".$result2['login_id']."', `data_vidachi`=CURRENT_DATE(), `data_sdachi`='1970-01-01', `vidano`='2', `prichina`='".$_POST['prichina']."', `zakazano`='0', `data_zakaza`='1970-01-01', `user_id_zak`='0' WHERE `film_id`='".$_POST['film_id']."' ";
  if(mysqli_query($dbcnx,$query))
  {
      $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysqli_query($dbcnx,$query2))
           {
           echo "<html><head>
          <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=film-info.php?film_id=".$_POST['film_id']."' />
          </head></html>";
           } else {puterror2($result2['skin'],$TEXT['error-log']); require_once "utils/bottom_film.php"; exit();}
  } else {puterror2($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
  }
   else
  {
  //*************************************
  //Информация для лога
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-film4'];
  $what = $result_iskh2['film_name'].", ".$TEXT['log-id']." ".$_POST['film_id'];
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************

  $query = "UPDATE `tbl_film` SET `napominalka`='".$napominalka."', `user_id`='".$_POST['user_id']."', `data_vidachi`='".$_POST['data_vidachi']."', `data_sdachi`='".$_POST['data_sdachi']."', `vidano`='1', `zakazano`='0', `data_zakaza`='1970-01-01', `user_id_zak`='0' WHERE `film_id`='".$_POST['film_id']."' ";
  if(mysqli_query($dbcnx,$query))
  {
      $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysqli_query($dbcnx,$query2))
           {
           echo "<html><head>
          <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=film-info.php?film_id=".$_POST['film_id']."' />
          </head></html>";
           } else {puterror2($result2['skin'],$TEXT['error-log']); require_once "utils/bottom_film.php"; exit();}
  } else {puterror2($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
 }
  require_once "utils/bottom_film.php";
?>