<?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";
  ?>
  <meta http-equiv='Refresh' content='300; URL=manager.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(!isset($button)) $button = $TEXT['zay-par2'];
  if(!isset($action)) $action = "zayavka_parall.php";
  if(!isset($button2)) $button2 = $TEXT['support104'];
  if(!isset($action2)) $action2 = "zayavka_parall_frm.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-usr1']);
  if(strlen($_POST['zay_id'])>11) puterror2($TEXT['error-usr2']);
  $_POST['zay_id'] = rep($_POST['zay_id']);

  if(empty($_POST['org_id'])) $_POST['org_id'] = "";
  if(strlen($_POST['org_id'])>11) puterror2($TEXT['error-org1']);
  $_POST['org_id'] = rep($_POST['org_id']);

  if(strlen($_POST['org_id2'])>11) puterror2($TEXT['error-org1']);
  $_POST['org_id2'] = rep($_POST['org_id2']);

  if(strlen($_POST['mast_id'])>11) puterror2($TEXT['error-supp12']);
  $_POST['mast_id'] = rep($_POST['mast_id']);

  if($_POST['onorg'] == "on")
    {
   $_POST['org_id'] = $_POST['org_id'];
   $onchb = "checked";
    }
  else
  {
  if(!empty($_POST['org_id2'])) 
    {
    $_POST['org_id'] = $_POST['org_id2'];
    $onchb = "checked";
    }
    else
    {
    $_POST['org_id'] = "";
    $onchb = "";
    }
  }

       $query_zaya = "SELECT tbl_supp_zayavka.*, tbl_supp_tema.tema, tbl_supp_srochnost.srochnost 
	FROM tbl_supp_zayavka 
	JOIN tbl_supp_tema ON tbl_supp_zayavka.tema_id=tbl_supp_tema.tema_id 
	JOIN tbl_supp_srochnost ON tbl_supp_zayavka.sroch_id=tbl_supp_srochnost.sroch_id 
	WHERE tbl_supp_zayavka.zay_id = '".$_POST['zay_id']."'";
       $zaya = mysql_query($query_zaya);
         if(!$zaya) puterror2($TEXT['error-tbl26']);
            $zayavka = mysql_fetch_array($zaya,MYSQL_ASSOC);
            $tema2 = $zayavka['tema'];
            $zay_id_old = $_POST['zay_id'];
            $org_id = $zayavka['org_id'];
            $man_id_old = $zayavka['man_id'];
            $mast_id_old = $zayavka['mast_id'];
            $sost_id_old = $zayavka['sost_id'];
            $sroch_id_old = $zayavka['sroch_id'];
?>
<form enctype='multipart/form-data' action=<?php echo $action2; ?> method=post>
<table align="center" class="table" border="0" cellpadding="0" cellspacing="0" width="97%">
<tr><td>
<fieldset class="filterr">
<legend align="left" title="<?php echo $TEXT['support104']; ?>"><?php echo $TEXT['support104']; ?></legend>
<table align="center" class="table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="support_ob3"><td width="30%"><?php echo $TEXT['support89']; ?></td><td width="2%">&nbsp;</td></tr>
<tr><td><input type=checkbox name=onorg <?php echo $onchb; ?> /><select class=input name="org_id">
    <?php
        $query4 = "SELECT `organizaciya`, `org_id` FROM `tbl_organizaciya` ORDER BY position";
        $organizaciya_tmp = mysql_query($query4);
          if(!$organizaciya_tmp) puterror2($TEXT['error-tbl7']);
              while($organizaciya = mysql_fetch_array($organizaciya_tmp,MYSQL_ASSOC))
                {
                 if($organizaciya['org_id'] == $_POST['org_id'])
                   {
                   $chk = "<option selected value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                   }
                 else $chk = "<option value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                 echo $chk;
                }
    ?>
    </select></td>
    	<td width="5%" align="right">
	<input class="button" type=submit value='<?php echo $button2; ?>' />
	<input type=hidden name=zay_id value='<?php echo $zay_id_old; ?>' />
 <input type=hidden name=mast_id value='<?php echo $_POST['mast_id']; ?>' />
	</td>
</tr>
</table>
</fieldset>
</td></tr>
<tr><td>
<hr width="100%"/>
</form>
     <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'><tr>
      <td>
         <fieldset class="zayavka" >
         <legend align="left"><?php echo $TEXT['support1']; ?> <?php echo $_POST['zay_id']; ?></legend>
          <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>
        <form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
             <tr>
               <td align="right" width="20%" class="support">&nbsp;<?php echo $TEXT['support42']; ?></td>
                <?php
                   $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'];
                        $man_id = $man['login_id'];
                   ?>
               <td class="support_ob4" width="80%" align="left">&nbsp;&nbsp;<?php echo $manager; ?></td>
             </tr>
             <tr><td align="right" width="0%" class="support">&nbsp;<?php echo $TEXT['support41']; ?></td>
                 <td width="70%" class="support_ob" align="left">&nbsp;&nbsp;<?php echo $zayavka['srochnost']; ?></td>
             </tr>
             <tr><td align="right" width="20%" class="support">&nbsp;<?php echo $TEXT['support13']; ?></td>
                 <td width="70%" class="support_ob" align="left">&nbsp;&nbsp;<?php echo $zayavka['tema']; ?></td>
             </tr>
             <tr>
               <td align="right" width="20%" class="support">&nbsp;<?php echo $TEXT['support14']; ?></td>
               <td class="support_ob3" width="80%" align="left">&nbsp;&nbsp;<?= nl2br($zayavka['problema']); ?></td>
             </tr>
             <tr>
               <td align="right" width="20%" class="support">&nbsp;</td>
               <td class="support" width="80%" align="right"><input class="button" type=submit value='<?php echo $button; ?>'></td>
	     </tr>
               <input type=hidden name=zay_id value='<?php echo $zay_id_old; ?>' />
               <input type=hidden name=org_id value='<?php echo $org_id; ?>' />
               <input type=hidden name=man_id value='<?php echo $man_id; ?>' />
               <input type=hidden name=manager value='<?php echo $manager; ?>' />
               <input type=hidden name=mast_id value='<?php echo $mast_id_old; ?>' />
               <input type=hidden name=sost_id value='<?php echo $sost_id_old; ?>' />
               <input type=hidden name=sroch_id value='<?php echo $sroch_id_old; ?>' />
              </table>
       </fieldset>
     </td>
     </tr>
     </table>
      <hr />
</td></tr>
<tr><td>
<table align="center" class="table" border="1" cellpadding="4" cellspacing="0" width="100%" >
<?php
   if(!empty($_POST['org_id'])) $organizaciya = "AND tbl_organizaciya.org_id='".$_POST['org_id']."' ";
    else $organizaciya = "";

     $query_zayavka = "SELECT tbl_logins.*, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo, tbl_users.org_id, tbl_organizaciya.organizaciya 
        FROM tbl_logins 
	LEFT JOIN tbl_users ON tbl_logins.usr_id=tbl_users.user_id 
	LEFT JOIN tbl_organizaciya ON tbl_organizaciya.org_id=tbl_users.org_id 
	WHERE tbl_logins.login_id != '$mast_id_old' $organizaciya  
	ORDER BY tbl_logins.login ";
     $result_zayavka1 = mysql_query($query_zayavka);
     if(!$result_zayavka1) puterror2(mysql_error());
       if(mysql_num_rows($result_zayavka1)>0);
         {
           echo "<tr class='tableheadercat'>
            <td>".$TEXT['support43']."</td>
            <td>".$TEXT['support89']."</td>
            <td>".$TEXT['btn_add']."</td>
                 </tr>";
             while($result_zayavka = mysql_fetch_array($result_zayavka1,MYSQL_ASSOC))
              {
               if(empty($result_zayavka['usr_id'])) $master_name = $result_zayavka['login']." (".$result_zayavka['fullname'].")";
                else $master_name = $result_zayavka['login']." (".$result_zayavka['familiya']." ".$result_zayavka['name']." ".$result_zayavka['otchestvo'].")";
               $res_org = $result_zayavka['organizaciya'];
	              $chmast_tmp = $result_zayavka['login_id'];
                ?>
             <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><?php echo $master_name; ?></td>
              <td><?php echo $result_zayavka['organizaciya']; ?></td>
              <td><input type="checkbox" name=chmast[<?php echo $chmast_tmp; ?>]></td>
             </tr>
                <?php
              }
         }
?>
</table>
</form>
</td></tr>
</table>
</body>
</html>