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

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang."/".$lang.".php")) {include "../lang/".$lang."/".$lang.".php";}
     else {include "../lang/ru/ru.php";}

  $title = $TEXT['ondisk_edit'];

  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['ond_id'])) {puterror($result2['skin'],$TEXT['param_err7']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['ond_id'])>12) {puterror($result2['skin'],$TEXT['param_err8']); require_once "../utils/bottom_adm.php"; exit();}
  if(empty($_POST['fs'])) {puterror($result2['skin'],$TEXT['ondisk_err1']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['fs'])>255) {puterror($result2['skin'],$TEXT['ondisk_err2']); require_once "../utils/bottom_adm.php"; exit();}
  if(empty($_POST['tm'])) {puterror($result2['skin'],$TEXT['ondisk_err3']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['tm'])>255) {puterror($result2['skin'],$TEXT['ondisk_err4']); require_once "../utils/bottom_adm.php"; exit();}

  if(isset($_POST['fs'])) {$fs=trim($_POST['fs']);}
    else {$fs="";}
     if(empty($fs)) {puterror($result2['skin'],$TEXT['ondisk_err5']); require_once "../utils/bottom_adm.php"; exit();}

  if(isset($_POST['tm'])) {$tm=trim($_POST['tm']);}
    else {$tm="";}
     if(empty($tm)) {puterror($result2['skin'],$TEXT['ondisk_err6']); require_once "../utils/bottom_adm.php"; exit();}

  $_POST['fs'] = rep($_POST['fs']);
  $_POST['tm'] = rep($_POST['tm']);
  $_POST['ond_id'] = rep($_POST['ond_id']);

  $query10 = "SELECT * FROM `tbl_ondisk` WHERE `ond_id`='".$_POST['ond_id']."' ";
  $result10 = mysqli_query($dbcnx,$query10);
  if(!$result10) {puterror($result2['skin'],$TEXT['error-tbl9']); require_once "../utils/bottom_adm.php"; exit();}
      $result_lib = mysqli_fetch_array($result10,MYSQLI_ASSOC);
      if($_POST['fs']!=$result_lib['disk_name']) {
          $query9 = "SELECT `disk_name` FROM `tbl_ondisk` WHERE `disk_name`='".$_POST['fs']."' ";
            $result9 = mysqli_query($dbcnx,$query9);
              if(!$result9) {puterror($result2['skin'],$TEXT['error-tbl9']); require_once "../utils/bottom_adm.php"; exit();}
                 if(mysqli_num_rows($result9)>0) {puterror($result2['skin'],$TEXT['error-double']); require_once "../utils/bottom_adm.php"; exit();}
                   else {$disk_name = "`disk_name` = '".$_POST['fs']."', ";}
        }
       else {$disk_name = "";}

  //*************************************
  //Информация для лога
  if($_POST['fs'] !== $result_lib['disk_name']) {$log_fs = $TEXT['ondisk_fs']." &laquo;".$result_lib['disk_name']."&raquo;".$TEXT['log-nd8']." &laquo;".$_POST['fs']."&raquo;,";}
   else {$log_fs = "";}

   if($_POST['tm'] !== $result_lib['mp']) {$log_tm = $TEXT['ondisk_tm']." &laquo;".$result_lib['mp']."&raquo;".$TEXT['log-nd8']." &laquo;".$_POST['tm']."&raquo;,";}
   else {$log_tm = "";}

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-ondisk2'];
  $what = $log_fs." ".$log_tm." ".$TEXT['log-id'].$_POST['ond_id'];;
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************

  $query = "UPDATE `tbl_ondisk` SET $disk_name `mp` = '".$_POST['tm']."' WHERE `ond_id`='".$_POST['ond_id']."' LIMIT 1";
  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=index.php' />
                 </head></html>";
           } else {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
  } else {puterror($result2['skin'],$TEXT['error-tbl9']); require_once "../utils/bottom_adm.php"; exit();}
  require_once "../utils/bottom_adm.php";
?>