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

  $title = $TEXT['book-rez'];

  require_once "config.php";
  require_once "utils/functions.php";
  require_once "utils/top_film.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_zakaza'])) {puterror2($result2['skin'],$TEXT['error-film12']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_POST['data_zakaza'])>10) {puterror2($result2['skin'],$TEXT['error-film13']); require_once "utils/bottom_film.php"; exit();}
  $_POST['film_id'] = rep($_POST['film_id']);
  $_POST['user_id'] = rep($_POST['user_id']);
  $_POST['data_zakaza'] = rep($_POST['data_zakaza']);

  //*************************************
  //Информация для лога
   $query_body = "SELECT `film_name` FROM tbl_film WHERE `film_id` = '".$_POST['film_id']."'";
     $result_body = mysqli_query($dbcnx,$query_body);
     if(!$result_body) {puterror2($result2['skin'],$TEXT['error-tbl26']); require_once "utils/bottom_film.php"; exit();}
      $result_body_film = mysqli_fetch_array($result_body);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-film8'];
  $what = $result_body_film['film_name'];
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************

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