<?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['support33'];
  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['support49'];
  if(!isset($action)) $action = "zayavka_add.php";

  if($result2['user'] == 1) puterror2($TEXT['error-supp11']);
  if($result2['master'] == 1 && $result2['administrator'] == 0) puterror2($TEXT['error-supp11']);

  if(empty($_GET['zay_id'])) puterror2($TEXT['error-usr1']);
  if(strlen($_GET['zay_id'])>11) puterror2($TEXT['error-usr2']);
  $_GET['zay_id'] = rep($_GET['zay_id']);

       $query_zaya = "SELECT
         tbl_supp_zayavka.*,
         tbl_supp_tema.tema,
         tbl_step.logika
	     FROM tbl_supp_zayavka
	    JOIN tbl_supp_tema ON tbl_supp_zayavka.tema_id=tbl_supp_tema.tema_id
        LEFT JOIN tbl_step ON tbl_supp_zayavka.mar_id=tbl_step.mar_id AND tbl_supp_zayavka.step=tbl_step.position
	    WHERE tbl_supp_zayavka.zay_id = '".$_GET['zay_id']."'";
       $zaya = mysql_query($query_zaya);
         if(!$zaya) puterror2($TEXT['error-tbl26']);
            $zayavka = mysql_fetch_array($zaya,MYSQL_ASSOC);

      if($zayavka['logika'] == "1" || $zayavka['logika'] == "") $logika = "<img alt='".$TEXT['logic-marsh1']."' src='../admin/img/logik-otkl.png' />";
      elseif($zayavka['logika'] == "2") $logika = "<img alt='".$TEXT['logic-marsh2']."' src='../admin/img/logik-and.png' />";
       else $logika = "<img alt='".$TEXT['logic-marsh3']."' src='../admin/img/logik-or.png' />";

              if(!empty($zayavka['time_isp'])) $action_end = $action2;
                else $action_end = $action;

              if(!empty($zayavka['time_isp'])) $button_end = $button2;
                else $button_end = $button;

              if(!empty($zayavka['pic_tr']) && $zayavka['pic_tr']!=="-") $file_image = "<a href='../".$zayavka['pic_tr']."' target=_blank title='".$TEXT['support26']."'><img alt='picture' src='../img/filesave.png' /></a>";
                else $file_image = $TEXT['support28'];

              if($zayavka['otv'] == "1") $otv = "<img alt='picture' src='../img/active.png' />";
                else $otv = "";

               $tema2 = $zayavka['tema'];
               $old_tema_id = $zayavka['tema_id'];
               $old_mast_id = $zayavka['mast_id'];
               $old_sost_id = $zayavka['sost_id'];
               $old_sroch_id = $zayavka['sroch_id'];
               $zay_id_old = $_GET['zay_id'];
               $org_id = $zayavka['org_id'];
               $ob_type = $zayavka['ob_type'];

               if(!empty($zayavka['mast_id']))
                {
               $query6 = "SELECT `login_id`, `fullname` FROM `tbl_logins` WHERE `login_id` = '".$zayavka['mast_id']."'";
                $mast_tmp = mysql_query($query6);
                  if(!$mast_tmp) puterror2($TEXT['error-tbl20']);
                   $master = mysql_fetch_array($mast_tmp,MYSQL_ASSOC);
                    $master2 = $master['fullname'];
                 } else $master2 = $TEXT['error-photo-no'];
?>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="97%">
<tr>
    <td>
       <?php
       $dog = "@";
       $query = "SELECT tbl_users.user_id, tbl_users.org_id, tbl_users.room, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo, tbl_users.mail, tbl_users.phone_mob, tbl_users.phone_int, tbl_users.phone_city, tbl_users.photo, tbl_dolzhnost.dolzhnost, tbl_domain.domain, tbl_city.city, tbl_street.street, tbl_house.house, tbl_organizaciya.organizaciya, tbl_upravlenie.upravlenie, tbl_otdel.otdel 
FROM tbl_users 
JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id 
JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_id 
JOIN tbl_city ON tbl_users.city_id=tbl_city.city_id 
JOIN tbl_street ON tbl_users.str_id=tbl_street.str_id 
JOIN tbl_house ON tbl_users.house_id=tbl_house.house_id 
JOIN tbl_organizaciya ON tbl_users.org_id=tbl_organizaciya.org_id 
JOIN tbl_upravlenie ON tbl_users.upr_id=tbl_upravlenie.upr_id 
JOIN tbl_otdel ON tbl_users.otd_id=tbl_otdel.otd_id 
WHERE tbl_users.user_id = '".$zayavka['usr_id']."'";
       $users = mysql_query($query);
         if(!$users) puterror2($TEXT['error-tbl2']);
         if(mysql_num_rows($users) > 0)
          {
            while($user = mysql_fetch_array($users,MYSQL_ASSOC))
            {
               $room = $user['room'];
               $familiya = $user['familiya'];
               $name = $user['name'];
               $otchestvo = $user['otchestvo'];
               $mail = $user['mail'];
               $phone_mob = $user['phone_mob'];
               $phone_int = $user['phone_int'];
               $phone_city = $user['phone_city'];
               $user_full = $user['familiya']." ".$user['name']." ".$user['otchestvo'];
               $res_dol = $user['dolzhnost'];
               $res_dom = $user['domain'];
               $email = $mail.$dog.$res_dom;
               $res_cit = $user['city'];
               $res_str = $user['street'];
               $res_hou = $user['house'];
               $res_org = $user['organizaciya'];
               //$org_id =  $user['org_id'];
               $res_upr = $user['upravlenie'];
               $res_otd = $user['otdel'];
               $res_name = "";

                   if(!empty($res_cit) && $res_cit!=="-"){$cit = "&nbsp;".$TEXT['user-city']."&nbsp;".$res_cit.",&nbsp;";}
                    else $cit = "";

                   if(!empty($res_str) && $res_str!=="-"){$str = $TEXT['user-str']."&nbsp;".$res_str.",&nbsp;";}
                     else $str = "";

                   if(!empty($res_hou) && $res_hou!=="-"){$hou = $TEXT['user-home']." ".$res_hou;}
                     else $hou = "";

                   if(!empty($room) && $room!=="-"){$rum = ",&nbsp;".$TEXT['user-room']." ".$room;}
                     else $rum = "";

            $query_res = "SELECT tbl_resource.res_id, tbl_resource.resource, tbl_resource.ukk FROM tbl_resource WHERE tbl_resource.user_id =".$zayavka['usr_id']." AND `visible` = 'show'";
             $result_res = mysql_query($query_res);
             if(!$result_res) puterror2($TEXT['error-tbl16']);
             if(mysql_num_rows($result_res) > 0)
             {
              while($resource = mysql_fetch_array($result_res,MYSQL_ASSOC))
              {
              $res_name .= "<a href# onClick=window.open('../admin/resources/resource.php?res_id=".$resource['res_id']."','popup','top=".$TEXT['resour-top'].",left=".$TEXT['resour-left'].",width=".$TEXT['resour-width'].",height=".$TEXT['resour-height'].",status=no,scrollbars=no,location=no,menubar=no,toolbar=no') title='".$TEXT['res-field5'].":&nbsp;".$resource['ukk']."'>".$resource['resource']."</a>, ";
              }
              $res_name = substr($res_name,0,-2);
             }
            if(!empty($user['photo']) && $user['photo']!="-") $result_image = "<tr valign=top><td width='15%' rowspan='13'>&nbsp;&nbsp;&nbsp;<img alt='picture' width='130' height='185' class=photo src='".$user['photo']."' /></td></tr>";
             else $result_image = "";
            }
            echo "<fieldset class='zayavka2' >";
             echo " <legend align='left' class='about'>".$TEXT['support30']."</legend>";
             echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'> ";
              echo $result_image;
               if(!empty($familiya)) echo "<tr align=top><td width='80%' class='texttableusrtit'>$familiya&nbsp; $name&nbsp; $otchestvo</td></tr>";
                 if($cit!=="" || $str !== "" || $hou !== "" || $rum !== "")  echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-adrr']."<span class='texttableusr'>".$cit."".$str."".$hou."".$rum."</span></td></tr>";
                  if(!empty($res_org)) echo "<tr valign=top><td width='80%' class='about'>".$TEXT['search-org']."<span class='texttableusr'>&nbsp;$res_org</span></td></tr>";
                   if(!empty($res_upr) && $res_upr!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['search-upr']."<span class='texttableusr'>&nbsp;$res_upr</span></td></tr>";
                    if(!empty($res_otd) && $res_otd!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['search-otd']."<span class='texttableusr'>&nbsp;$res_otd</span></td></tr>";
                     if(!empty($res_dol)) echo "<tr valign=top><td width='80%' class='about'>".$TEXT['search-dol']."<span class='texttableusr'>&nbsp;$res_dol</span></td></tr>";
                      if(!empty($phone_mob)) echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-tel-mob']."<span class='texttableusr'>&nbsp;$phone_mob</span></td></tr>";
                       if(!empty($phone_city)) echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-tel-city']."<span class='texttableusr'>&nbsp;<a href='callto://$phone_city'>$phone_city</a></span></td></tr>";
                        if(!empty($phone_int)) echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-tel-int']."<span class='texttableusr'>&nbsp;<a href='callto://$phone_int'>$phone_int</a></span></td></tr>";
                         if(!empty($mail)) echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-e-mail']."<span class='texttableusr'>&nbsp;<a href=mailto:$email>$email</span></td></tr>";
                          if(!empty($res_name)) echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-res']."<span class='texttableusr'>&nbsp;$res_name</span></td></tr>";
                           echo "</table></fieldset>";
          }
          else echo "<span class='about'>&nbsp;&nbsp;".$TEXT['support120']."</span>";
   ?>
      </td>
   </tr>
   <tr>
      <td>
     <table align='center' border='0' width='97%' cellpadding='0' cellspacing='0'><hr /><tr>
      <td>
         <fieldset class='zayavka' >
         <legend align="left"><?php echo $TEXT['support1']; ?> <?php echo $_GET['zay_id']; ?> <?php echo $otv; ?> <?php echo $logika; ?></legend>
          <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>
	<?php
	if($ob_type == 0) {
          echo "<form enctype='multipart/form-data' action=zayavka_obed_frm.php method=post>
                <tr><td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class=button type=submit value='".$TEXT['support98']."'><input type=hidden name=org_id2 value=".$org_id."><input type=hidden name=zay_id value=".$zay_id_old."><input type=hidden name=tema_id2 value=".$old_tema_id."></td>
                </form>
                <form enctype='multipart/form-data' action=zayavka_parall_frm.php method=post>
                <td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class=button type=submit value='".$TEXT['zay-par1']."'><input type=hidden name=org_id2 value=".$org_id."><input type=hidden name=zay_id value=".$zay_id_old."><input type=hidden name=mast_id value=".$old_mast_id."></td></tr>
                </form>";
	}
	elseif ($ob_type == 1) {
          echo "<form enctype='multipart/form-data' action=zayavka_ed_frm.php method=post>
                <tr><td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class='button' type=submit value='".$TEXT['support99']."'><input type=hidden name=org_id2 value=".$org_id."><input type=hidden name=zay_id value=".$zay_id_old."><input type=hidden name=tema_id2 value=".$old_tema_id."></td>
                </form>
                <form enctype='multipart/form-data' action=zayavka_parall_frm.php method=post>
                <td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class='button' type=submit value='".$TEXT['zay-par1']."'><input type=hidden name=org_id2 value=".$org_id."><input type=hidden name=zay_id value=".$zay_id_old."><input type=hidden name=mast_id value=".$old_mast_id."></td></tr>
                </form>";
	}
	elseif($ob_type == 2) {
          echo "<form enctype='multipart/form-data' action=zayavka_obed_frm.php method=post>
                <tr><td align='right' width='30%' class='support'>&nbsp;</td><td class='support_ob' width='70%' align='right'>".$TEXT['support100']."</td></tr>
                </form>";
	}
	elseif($ob_type == 3) {
          echo "<form enctype='multipart/form-data' action=zayavka_obed_frm.php method=post>
                <tr><td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class='button' type=submit value='".$TEXT['support98']."'><input type=hidden name=org_id2 value=".$org_id."><input type=hidden name=zay_id value=".$zay_id_old."><input type=hidden name=tema_id2 value=".$old_tema_id."></td>
                </form>
                <form enctype='multipart/form-data' action=zayavka_parall_frm.php method=post>
                <td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class='button' type=submit value='".$TEXT['zay-par1']."'><input type=hidden name=org_id2 value=".$org_id."><input type=hidden name=zay_id value=".$zay_id_old."><input type=hidden name=mast_id value=".$old_mast_id."></td>
                </form>
                <form enctype='multipart/form-data' action=zayavka_del_frm.php method=post>
                <td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class='button' type=submit value='".$TEXT['zay-pardel']."'><input type=hidden name=zay_id value=".$zay_id_old."></td></tr>
                </form>";
	}
        elseif($ob_type == 4) {
          echo "<form enctype='multipart/form-data' action=zayavka_obed_frm.php method=post>
                <tr><td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class='button' type=submit value='".$TEXT['support98']."'><input type=hidden name=org_id2 value=".$org_id."><input type=hidden name=zay_id value=".$zay_id_old."><input type=hidden name=tema_id2 value=".$old_tema_id."></td>
                </form>
                <form enctype='multipart/form-data' action=zayavka_parall_frm.php method=post>
                <td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class='button' type=submit value='".$TEXT['zay-par1']."'><input type=hidden name=org_id2 value=".$org_id."><input type=hidden name=zay_id value=".$zay_id_old."><input type=hidden name=mast_id value=".$old_mast_id."></td>
                </form>
                <form enctype='multipart/form-data' action=zayavka_del_frm.php method=post>
                <td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='70%' align='right'><input class='button' type=submit value='".$TEXT['zay-pardel']."'><input type=hidden name=zay_id value=".$zay_id_old."></td></tr>
                </form>";
	}
	?>
        </table>
        <form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
          <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>
             <tr><td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support40']; ?></td>
                 <td width="70%" class="support" align="left">&nbsp;
                   <select class="support" name="sost_id">
                   <?php
                   $query_st = "SELECT * FROM `tbl_supp_sostoyanie` ORDER BY position ";
                    $sost_tmp = mysql_query($query_st);
                     if(!$sost_tmp) puterror2($TEXT['error-tbl23']);
                      while($sost = mysql_fetch_array($sost_tmp,MYSQL_ASSOC))
                       {
                       if($sost['sost_id'] == $zayavka['sost_id'])
                       {
                       $chk = "<option selected value=".$sost['sost_id'].">".$sost['sostoyanie']."";
                       }
                       else $chk = "<option value=".$sost['sost_id'].">".$sost['sostoyanie']."";
                       echo $chk;
                       }
                   ?>
                 </select>
               </td>
             </tr>
             <tr><td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support41']; ?></td>
                 <td width="70%" class="support" align="left">&nbsp;
                   <select class="support" name="sroch_id">
                   <?php
                   $query_sr = "SELECT * FROM `tbl_supp_srochnost` ORDER BY position ";
                    $sroch_tmp = mysql_query($query_sr);
                     if(!$sroch_tmp) puterror2($TEXT['error-tbl24']);
                      while($sroch = mysql_fetch_array($sroch_tmp,MYSQL_ASSOC))
                       {
                       if($sroch['sroch_id'] == $zayavka['sroch_id'])
                       {
                       $chk = "<option selected value=".$sroch['sroch_id'].">".$sroch['srochnost']."";
                       }
                       else $chk = "<option value=".$sroch['sroch_id'].">".$sroch['srochnost']."";
                       echo $chk;
                       }
                   ?>
                 </select>
               </td>
             </tr>
             <tr><td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support13']; ?></td>
                 <td width="70%" class="support" align="left">&nbsp;
                   <select class="support" name="tema_id">
                   <?php
                   $query_tm = "SELECT * FROM `tbl_supp_tema` ORDER BY position ";
                    $tema_tmp = mysql_query($query_tm);
                     if(!$tema_tmp) puterror2($TEXT['error-tbl22']);
                      while($tema = mysql_fetch_array($tema_tmp,MYSQL_ASSOC))
                       {
                       if($tema['tema_id'] == $zayavka['tema_id'])
                       {
                       $chk = "<option selected value=".$tema['tema_id'].">".$tema['tema']."";
                       }
                       else $chk = "<option value=".$tema['tema_id'].">".$tema['tema']."";
                       echo $chk;
                       }
                   ?>
                 </select>
               </td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support14']; ?>&nbsp;</td>
               <td class="support" width="70%" align="left"><textarea cols="70" rows="5" name=description ><?= $zayavka['problema']; ?></textarea></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support26']; ?></td>
               <td class="flop" width="70%" align="left">&nbsp;<?php echo $file_image; ?></td>
             </tr>
             <tr>
               <td align="right" width="30%" 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="70%" align="left">&nbsp;<?php echo $manager; ?></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support43']; ?></td>
               <td class="support" width="70%" align="left">&nbsp;
                   <select class="support" name="mast_id">
                   <?php
                   $query_mast2 = "SELECT * FROM `tbl_logins` WHERE `master`='1' OR `administrator`='1' ORDER BY fullname ";
                    $mast_tmp = mysql_query($query_mast2);
                     if(!$mast_tmp) puterror2($TEXT['error-tbl20']);
                      while($mast = mysql_fetch_array($mast_tmp,MYSQL_ASSOC))
                       {
                        if($mast['administrator'] == 1) $rtdir1 = "#&thinsp;";
                         else  $rtdir1 = "";

                       if($mast['login_id'] == $zayavka['mast_id']) $chk = "<option selected value=".$mast['login_id'].">".$rtdir1.$mast['fullname']."";
                        else $chk = "<option value=".$mast['login_id'].">".$rtdir1.$mast['fullname']."";
                       echo $chk;
                       }
                   ?>
                 </select>
               </td>
             </tr>
             <tr><td align="right" width="20%" class="support">&nbsp;<?php echo $TEXT['marsh-tit']; ?></td>
                 <td width="70%" class="support" align="left">&nbsp;
                   <select class="support" name="mar_id">
                   <?php
                   $query_mar = "SELECT `mar_name`, `mar_id` FROM `tbl_marsh` WHERE visible = 'show' ORDER BY position";
                    $mar_tmp = mysql_query($query_mar);
                     if(!$mar_tmp) puterror2($TEXT['error-tbl42']);
                      while($mar = mysql_fetch_array($mar_tmp,MYSQL_ASSOC))
                       {
                       if($zayavka['mar_id'] == $mar['mar_id']) $chk_mar = "<option selected value=".$mar['mar_id'].">".$mar['mar_name']."</option>";
                        else $chk_mar = "<option value=".$mar['mar_id'].">".$mar['mar_name']."</option>";
                       echo $chk_mar;
                       }
                   ?>
                 </select>
                 <input type="checkbox" name="mar_chb" />
               </td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support"><?php echo $TEXT['support53']; ?></td>
               <td class="support_ob2" width="70%" align="left">&nbsp;&nbsp;<?php echo $zayavka['data_post']; ?></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support"><?php echo $TEXT['support55']; ?></td>
               <td class="support_ob" width="70%" align="left">&nbsp;&nbsp;<?php echo $zayavka['data_k_isp']; ?></td>
             </tr>
             <tr>
		<td align="right" width="30%">&nbsp;</td>
		<td width="70%" align="left">&nbsp;</td>
             <tr>
               <td align="right" width="30%">&nbsp;</td>
               <td class="support" width="70%" align="left"><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=man_id value='<?php echo $man_id; ?>' />
               <input type=hidden name=org_id value='<?php echo $org_id; ?>' />
               <input type=hidden name=old_tema_id value='<?php echo $old_tema_id; ?>' />
               <input type=hidden name=old_mast_id value='<?php echo $old_mast_id; ?>' />
               <input type=hidden name=master value='<?php echo $master2; ?>' />
               <input type=hidden name=manager value='<?php echo $manager; ?>' />
               <input type=hidden name=user value='<?php echo $user_full; ?>' />
               <input type=hidden name=old_sost_id value='<?php echo $old_sost_id; ?>' />
               <input type=hidden name=old_sroch_id value='<?php echo $old_sroch_id; ?>' />
              </table>
       </fieldset>
     </td>
     </tr>
     </table>
      </td>
   </tr>
</table>
</form>
</body>
</html>