<?php
  ///////////////////////////////////////////////////
  //2007 (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=$titlepage = $TEXT['post-title4'];
  $helppage = "";

  require_once "../config.php";
  require_once "../util/top.php";

  if($result2['user'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['master'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['manager'] == 1) puterror2($TEXT['error-loginform4']);

  if(empty($_POST['dol_id'])) puterror2($TEXT['error-post8']);
  if(strlen($_POST['dol_id'])>11) puterror2($TEXT['error-post9']);
  if(empty($_POST['dolzhnost'])) puterror2($TEXT['error-post1']);
  if(strlen($_POST['dolzhnost'])>120) puterror2($TEXT['error-post3']);
  if(empty($_POST['position'])) puterror2($TEXT['error-post4']);
  if(strlen($_POST['position'])>5) puterror2($TEXT['error-post5']);

  if(isset($_POST['dolzhnost'])) $dolzhnost=trim($_POST['dolzhnost']);
    else $dolzhnost="";
     if(empty($dolzhnost)) puterror2($TEXT['error-post6']);

  if(isset($_POST['position'])) $position=trim($_POST['position']);
    else $position="";
     if(empty($position)) puterror2($TEXT['error-post7']);

  $_POST['dolzhnost'] = rep($_POST['dolzhnost']);
  $_POST['position'] = rep($_POST['position']);
  $_POST['dol_id'] = rep($_POST['dol_id']);

  $query10 = "SELECT `dolzhnost` FROM `tbl_dolzhnost` WHERE `dol_id`='".$_POST['dol_id']."' ";
  $result10 = mysql_query($query10);
  if(!$result10) puterror2($TEXT['error-tbl6']);
      $result_lib = mysql_fetch_array($result10);
      if($_POST['dolzhnost']!=$result_lib['dolzhnost']) {
          $query9 = "SELECT `dolzhnost` FROM `tbl_dolzhnost` WHERE `dolzhnost`='".$_POST['dolzhnost']."' ";
            $result9 = mysql_query($query9);
              if(!$result9) puterror2($TEXT['error-tbl6']);
                 if(mysql_num_rows($result9)>0) puterror2($TEXT['global-est']);
                   else $name_dolzhnost = "`dolzhnost` = '".$_POST['dolzhnost']."', ";
        }
       else $name_dolzhnost = "";

  //*************************************
  $query = "SELECT * FROM `tbl_dolzhnost` WHERE `dol_id`='".$_POST['dol_id']."' ";
  $result = mysql_query($query);
  if(!$result) puterror2($TEXT['error-tbl6']);
   $result2 = mysql_fetch_array($result);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-post2'];
  $what = $result2['dolzhnost'].$TEXT['log-na'].$_POST['dolzhnost'].$TEXT['log-id'].$_POST['dol_id'];
  $who = $result2['fullname'];
  //*************************************
  $query = "UPDATE `tbl_dolzhnost` SET $name_dolzhnost `position` = '".$_POST['position']."' WHERE `dol_id`='".$_POST['dol_id']."' ";
  if(mysql_query($query))
  {
    $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysql_query($query2))
           {
             echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-post10']);
  require_once "../util/bottom.php";
?>