<?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";
  ?>
  <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['support56'];
  if(!isset($action)) $action = "mast_zayavka_add.php";
  if($result2['user'] == 1) 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_srochnost.srochnost, 
       tbl_supp_tema.tema,
       tbl_step.logika
       FROM tbl_supp_zayavka 
       JOIN tbl_supp_srochnost ON tbl_supp_zayavka.sroch_id=tbl_supp_srochnost.sroch_id 
       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['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'];

                    $srochnost = $zayavka['srochnost'];
                    $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'];

               if(!empty($zayavka['man_id']))
                {
               $query6 = "SELECT `login_id`, `fullname` FROM `tbl_logins` WHERE `login_id` = '".$zayavka['man_id']."'";
                $man_tmp = mysql_query($query6);
                  if(!$man_tmp) puterror2($TEXT['error-tbl20']);
                   $manager = mysql_fetch_array($man_tmp,MYSQL_ASSOC);
                    $manager2 = $manager['fullname'];
                 } else $manager2 = $TEXT['error-photo-no'];

               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'];

               if(!empty($user['photo']) && $user['photo']!="-") $result_image = "<tr valign=top><td width='15%' rowspan='12'>&nbsp;&nbsp;&nbsp;<img alt='picture' width='130' height='185' class=photo src='".$user['photo']."' /></td></tr>";
                else $result_image = "";

                   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 = "";

            }
            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>";
                           echo "</table></fieldset>";
       }
          else echo "<span class='about'>&nbsp;&nbsp;".$TEXT['support120']."</span>";
   ?>
      </td>
   </tr>
   <tr>
      <td>
        <form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
    <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 $logika; ?></legend>
          <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>
             <tr><td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support41']; ?></td>
                 <td width="70%" class="support_ob4" align="left">&nbsp;&nbsp;<?php echo $srochnost; ?></td>
             </tr>
             <tr><td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support13']; ?></td>
                 <td width="70%" class="support_ob4" align="left">&nbsp;&nbsp;<?php echo $tema2; ?></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support14']; ?>&nbsp;</td>
               <td class="textfilecont" align="left"><?= nl2br($zayavka['problema']); ?></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support26']; ?></td>
               <td class="flop" width="70%" align="left">&nbsp;&nbsp;<?php echo $file_image; ?></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support46']; ?>&nbsp;</td>
               <td class="support" width="70%" align="left"><textarea cols="70" rows="5" name=reshenie ><?= $zayavka['reshenie']; ?></textarea></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support47']; ?></td>
               <td class="support_ob4" width="70%" align="left">&nbsp; <input size=10 maxlength=10 class="support" type=text name=time_isp value='<?php echo $zayavka['time_isp']; ?>'>&nbsp;<?php echo $TEXT['support48']; ?></td>
             </tr>
             <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['support42']; ?></td>
               <td class="support_ob4" width="70%" align="left">&nbsp;&nbsp;<?php echo $manager2; ?></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support53']; ?></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%" class="support">&nbsp;</td>
               <td class="support" width="70%" align="left">&nbsp;</td></tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;</td>
               <td class="support" width="70%" align="left">
               <input class="button" type=submit value='<?php echo $button; ?>' />
               <input type=hidden name=zay_id value='<?php echo $zay_id_old; ?>' />
               <input type=hidden name=old_sost_id value='<?php echo $old_sost_id; ?>' />
               </td></tr>
             </tr>
          </table>
       </fieldset>
     </td>
     </tr>
     </table>
      </td>
   </tr>
</table>
</form>
</body>
</html>