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

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

  $title=$titlepage=$TEXT['support102'];
  require_once "../config.php";
  require_once "top.php";
  ?>
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/reader.css" />
  </head>
  <body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
  <?php
  if($result2['user'] == 1) puterror2($TEXT['error-supp11']);
  if($result2['master'] == 1) puterror2($TEXT['error-supp11']);
  if(empty($_POST['zay_id'])) puterror2($TEXT['error-supp6']);
  if(strlen($_POST['zay_id'])>11) puterror2($TEXT['error-supp7']);
  if(strlen($_POST['org_id'])>11) puterror2($TEXT['error-org']);
  if(strlen($_POST['manager'])>255) puterror2($TEXT['error-supp16']);
  if(strlen($_POST['man_id'])>11) puterror2($TEXT['error-supp13']);
  if(strlen($_POST['mast_id'])>11) puterror2($TEXT['error-supp12']);
  if(strlen($_POST['sost_id'])>11) puterror2($TEXT['error-supp21']);
  if(strlen($_POST['sroch_id'])>11) puterror2($TEXT['error-supp20']);

  $_POST['zay_id'] = rep($_POST['zay_id']);
  $_POST['org_id'] = rep($_POST['org_id']);
  $_POST['manager'] = rep($_POST['manager']);
  $_POST['ochistka'] = rep($_POST['ochistka']);
  $_POST['man_id'] = rep($_POST['man_id']);
  $_POST['mast_id'] = rep($_POST['mast_id']);
  $_POST['sost_id'] = rep($_POST['sost_id']);
  $_POST['sroch_id'] = rep($_POST['sroch_id']);

  $query = "UPDATE `tbl_supp_zayavka` SET `ob_type` = '1', `man_id` = '".$_POST['man_id']."', `mast_id` = '".$_POST['mast_id']."' WHERE `zay_id`='".$_POST['zay_id']."'";
   if(!mysql_query($query)) puterror2($TEXT['error-tbl26']);

 //function disabled by php > 5.5.3
 ////import_request_variables("gP", "in_");
 // before using only ->  while(list($id,$value) = @each($in_chzay))
 while(list($id2,$value2) = @each($_POST)) {
  if($id2 == "chzay") {
   while(list($id,$value) = each($value2)) {
     if($id > 0 && $value == 'on')
     {
      $query_ob = "INSERT INTO `tbl_ob_zay` ( `ob_zay_id` , `root_zay_id` , `par_zay_id` ) VALUES ( NULL , '".$_POST['zay_id']."' , '$id')";
        if(mysql_query($query_ob))
        {
         $query_zay = "UPDATE `tbl_supp_zayavka` SET `ob_type` = '2', `man_id` = '".$_POST['man_id']."', `mast_id` = '".$_POST['mast_id']."', `sost_id` = '".$_POST['sost_id']."', `sroch_id` = '".$_POST['sroch_id']."' WHERE `zay_id`='$id'";
          if(!mysql_query($query_zay)) puterror2($TEXT['error-tbl26']);
        }else puterror2(mysql_error());
        $log_zay .= $id.", ";
     }
   }
  }
 }
 //*************************************
 $ip = $_SERVER['REMOTE_ADDR'];
 $doing = $TEXT['support98'];
 $what = $TEXT['support112']." ".$_POST['zay_id'].$TEXT['support107'].substr($log_zay,0,-2);
 $who = $_POST['manager'];
 //*************************************
 $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
  if(!mysql_query($query2)) puterror2($TEXT['error-log']);
 putok2($TEXT['support108']);
?>
</body>
</html>
