<?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['manager'])>255) puterror2($TEXT['error-supp16']);
  if(strlen($_POST['man_id'])>11) puterror2($TEXT['error-supp13']);

  $_POST['zay_id'] = rep($_POST['zay_id']);
  $_POST['manager'] = rep($_POST['manager']);
  $_POST['man_id'] = rep($_POST['man_id']);

  $query_man2 = "SELECT * FROM `tbl_logins` WHERE `login`='".$_COOKIE['login']."'";
   $man_tmp = mysql_query($query_man2);
    if(!$man_tmp) puterror2($TEXT['error-tbl20']);
     $man = mysql_fetch_array($man_tmp,MYSQL_ASSOC);
     $manager = $man['fullname'];

    $query = "SELECT * FROM `tbl_supp_zayavka` WHERE `zay_id`='".$_POST['zay_id']."'";
     $result_query = mysql_query($query);
     if(!$result_query) puterror2($TEXT['error-tbl26']);
     $res_query = mysql_fetch_array($result_query,MYSQL_ASSOC);

       //function disabled by php > 5.5.3
       ////import_request_variables("gP", "in_");
       // before using only ->  while(list($id,$value) = @each($in_chmast))
       while(list($id2,$value2) = @each($_POST)) {
        if($id2 == "chmast") {
         while(list($id,$value) = each($value2)) {
         if($id > 0 && $value == 'on')
         {
          $query_zay = "INSERT INTO `tbl_supp_zayavka` (`zay_id` , `data_post` , `data_k_isp` , `data_close` , `man_id` , `mast_id` , `usr_id` , `sost_id` , `sroch_id` , `tema_id` , `problema` , `pic_tr` , `reshenie` , `kod` , `time_isp` , `org_id` , `ob_type` ) VALUES (NULL , NOW() , NOW() , '".$res_query['data_close']."' , '".$_POST['man_id']."' , '".$id."' , '".$res_query['usr_id']."' , '".$res_query['sost_id']."' , '".$res_query['sroch_id']."' , '".$res_query['tema_id']."' , '".$res_query['problema']."' , '".$res_query['pic_tr']."' , '".$res_query['reshenie']."' , '".$res_query['kod']."' , '".$res_query['time_isp']."' , '".$res_query['org_id']."' , '3' )";
         if(!mysql_query($query_zay)) puterror2($TEXT['error-tbl26']);
          $query_lst = mysql_query("SELECT LAST_INSERT_ID()");
          $last = mysql_result($query_lst, 0);
         } else puterror2($TEXT['zay-parerror']);
        $log_zay .= $last.", ";
        }
        }
        }
        //*************************************
        $ip = $_SERVER['REMOTE_ADDR'];
        $doing = $TEXT['zay-par3'];
        $what = $TEXT['support112']." ".$_POST['zay_id']." ".$TEXT['support115'].substr($log_zay,0,-2);
        $who = $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['support116']);
?>
</body>
</html>
