<?php
  ///////////////////////////////////////////////////
  //2010 (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['support3'];

  require_once "config.php";
  require_once "utils/top_zayavka_otv.php";

  if(empty($_GET['add'])) $_GET['add'] = 0;
  if(!isset($button)) $button = $TEXT['btn-next'];
  if(!isset($action)) $action = "zayavka_ed_otv.php";
?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="87%">
<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 user_id = '".$result2['usr_id']."'";
  $users = mysql_query($query);
         if(!$users) puterror($TEXT['error-tbl2']);
            $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'];
               $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'];
               $res_upr = $user['upravlenie'];
               $res_otd = $user['otdel'];
               $usr_id = $result2['usr_id'];
	       $org_id = $user['org_id'];

                 if(!empty($user['photo']) && $user['photo']!="-") $result_image = "<tr valign=top><td width='15%' rowspan='12'>&nbsp;&nbsp;&nbsp;&nbsp;<img alt='картинка' width='130' height='185' src='personal/".$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['support10']."</legend>";
             echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'> ";
              echo $result_image;
               if(!empty($familiya)) echo "<tr><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) && $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) && $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) && $phone_city!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-tel-city']."<span class='texttableusr'>&nbsp;$phone_city</span></td></tr>";
                        if(!empty($phone_int) && $phone_int!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-tel-int']."<span class='texttableusr'>&nbsp;$phone_int</span></td></tr>";
                         if(!empty($mail) && $res_dom!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-e-mail']."&nbsp;<a href=mailto:$email><span class='texttableusr'>$email</span></a></td></tr>";
                           echo "</table></fieldset>";
 ?>
      </td>
   </tr>
   <tr>
      <td><hr />
     <table align='center' border='0' width='95%' cellpadding='0' cellspacing='0'>
     <?php
     if($_GET['add'] == 1)
     {
      echo "<tr>";
      echo "<td>";
         echo "<fieldset class='zayavka' >";
         echo "<legend align='left' title=".$TEXT['support3'].">".$TEXT['support12']."</legend>";
          echo "<table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>";
             echo "<tr><td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='80%' align='left'>&nbsp;</td></tr>";
             echo "<tr><td align='right' width='20%' class='support'>&nbsp;".$TEXT['support13']."&nbsp;</td>";
                 echo "<td width='70%' class='support' align='left'>";
                   echo "<select class='support' name='tema_id' onchange=window.location.href=this.options[this.selectedIndex].value;>";
                   $query = "SELECT * FROM `tbl_supp_tema` WHERE `visible` = 'hide' ORDER BY position ";
                    $tema_tmp = mysql_query($query);
                     if(!$tema_tmp) puterror($TEXT['error-tbl22']);
                      while($tema = mysql_fetch_array($tema_tmp,MYSQL_ASSOC))
                       {
                       if($tema['tema_id'] == $_GET['tema_id'])
                        {
                       $chk = "<option selected value=zayavka_otv.php?tema_id=".$tema['tema_id']."&amp;user_id=".$result2['usr_id']."&amp;add=1>".$tema['tema']."</option>";
                       if(!empty($_GET['tema_id'])) {$tema_id_tmp=$_GET['tema_id'];} else {$tema_id_tmp=$tema['tema_id'];}
                       $query_sh = "SELECT shablon FROM `tbl_supp_tema` WHERE tema_id='".$_GET['tema_id']."' AND `visible` = 'hide'  ";
                        $tema_tmp_sh = mysql_query($query_sh);
                         if(!$tema_tmp_sh) puterror($TEXT['error-tbl22']);
                         $tema_sh = mysql_fetch_array($tema_tmp_sh,MYSQL_ASSOC);
                          $shablon = $tema_sh['shablon'];
                        }
                        else
                        {
                        $chk = "<option value=zayavka_otv.php?tema_id=".$tema['tema_id']."&amp;user_id=".$result2['usr_id']."&amp;add=1>".$tema['tema']."</option>";
                       if(!empty($_GET['tema_id'])) 
                         {
                       $query_sh = "SELECT shablon FROM `tbl_supp_tema` WHERE tema_id='".$_GET['tema_id']."' AND `visible` = 'hide' ";
                        $tema_tmp_sh = mysql_query($query_sh);
                         if(!$tema_tmp_sh) puterror($TEXT['error-tbl22']);
                         $tema_sh = mysql_fetch_array($tema_tmp_sh,MYSQL_ASSOC);
                          $shablon = $tema_sh['shablon'];
                         }
                         else 
                         {
                       $query_sh = "SELECT `shablon` FROM `tbl_supp_tema` WHERE `visible` = 'hide' ORDER BY `position` ";
                        $tema_tmp_sh = mysql_query($query_sh);
                         if(!$tema_tmp_sh) puterror($TEXT['error-tbl22']);
                         $tema_sh = mysql_fetch_array($tema_tmp_sh,MYSQL_ASSOC);
                          $shablon = $tema_sh['shablon'];
                         }
                        }
                       echo $chk;
                       }
                 echo "</select>";
               echo "</td>";
             echo "</tr>";
             echo "<tr><td align='right' width='20%' class='support'>&nbsp;".$TEXT['support41']."&nbsp;</td>";
                 echo "<td width='70%' class='support' align='left'>";
                   echo "<select class='support' name='sroch_id'>";
                   $query_sr = "SELECT * FROM `tbl_supp_srochnost` ORDER BY position ";
                    $sroch_tmp = mysql_query($query_sr);
                     if(!$sroch_tmp) puterror($TEXT['error-tbl24']);
                      while($sroch = mysql_fetch_array($sroch_tmp,MYSQL_ASSOC))
                       {
                       $chk = "<option value=".$sroch['sroch_id'].">".$sroch['srochnost']."</option>";
                       echo $chk;
                       }
                 echo "</select>";
               echo "</td>";
             echo "</tr>";
             echo "<tr><td align='right' width='20%' class='support'>&nbsp;".$TEXT['res-title1']."&nbsp;</td>";
                 echo "<td width='70%' class='support' align='left'>";
                   echo "<select class='support' name='res_id'>";
                   $query_res = "SELECT `res_name`, `res_id` FROM `tbl_resource` WHERE `user_id` = ".$result2['usr_id']." ORDER BY `position` ";
                    $res_tmp = mysql_query($query_res);
                     if(!$res_tmp) puterror($TEXT['error-tbl16']);
                      while($res = mysql_fetch_array($res_tmp,MYSQL_ASSOC))
                       {
                       $chk = "<option value=".$res['res_id'].">".$res['res_name']."</option>";
                       echo $chk;
                       }
                 echo "</select>";
               echo "</td>";
             echo "</tr>";
             echo "<tr>";
               echo "<td align='right' width='30%' class='support'>&nbsp;".$TEXT['support20']."&nbsp;</td>";
               echo "<td class='support' width='70%' align='left'><input class='support' size=50 maxlength=100 type=password name=kod ></td>";
             echo "</tr>";
             echo "<tr><td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='80%' align='left'>&nbsp;</td></tr>";
             echo "<tr>";
               echo "<td align='right' width='30%' class='support'>&nbsp;</td>";
               echo "<td class='support' width='70%' align='left'><input class=button type=submit value='".$button."'></td></tr>";
             echo "</tr>";
             echo "<tr><td align='right' width='30%' class='support'>&nbsp;</td><td class='support' width='80%' align='left'>&nbsp;";
               echo "<input type=hidden name=usr_id value='".$usr_id."'>";
               echo "<input type=hidden name=org_id value='".$org_id."'>";
               echo "<input type=hidden name=onorg value='on'>";
               echo "</td></tr>";
          echo "</table>";
       echo "</fieldset>";
      echo "</td>";
     echo "</tr>";
     }
     ?>
     <tr align="left">
     <td width=100% class="support"><br /><?php echo $TEXT['support44']; ?></td>
     </tr>
     <tr align="left">
     <td width=100% ><hr width="80%" align="left" />
     <?php
      $query_z = "SELECT
      tbl_supp_zayavka.zay_id,
      tbl_supp_zayavka.tema_id,
      tbl_supp_zayavka.usr_id,
      tbl_supp_tema.tema,
      tbl_supp_zayavka.usr_id,
      tbl_supp_zayavka.sost_id,
      tbl_supp_sostoyanie.sostoyanie 
      FROM tbl_supp_zayavka
      JOIN tbl_supp_tema ON tbl_supp_zayavka.tema_id=tbl_supp_tema.tema_id
      JOIN tbl_supp_sostoyanie ON tbl_supp_zayavka.sost_id=tbl_supp_sostoyanie.sost_id
      WHERE tbl_supp_zayavka.usr_id='".$result2['usr_id']."' ORDER BY tbl_supp_zayavka.zay_id DESC";
      $zayavka = mysql_query($query_z);
       if(!$zayavka) puterror($TEXT['error-tbl26']);
        if(mysql_num_rows($zayavka) > 0)
        {
         while($zay = mysql_fetch_array($zayavka,MYSQL_ASSOC))
         {
          $tema_full = $zay['tema'];
          $sost = $zay['sostoyanie'];
         ?>
         <a class="support_search" href='search_usr_supp_otv.php?zay_id=<?php echo $zay['zay_id']; ?>' title = '<?php echo $TEXT['support44']; ?>'> <?php echo $TEXT['support1']; ?> = <?php echo $zay['zay_id']; ?>, <?php echo $TEXT['support13']; ?>: <?php echo $tema_full; ?>, <?php echo $TEXT['support25']; ?> - <?php echo $sost; ?></a><hr width=80% align=left />
         <?php
         }
        } else echo "<span class='support_search'>".$TEXT['no-zay']."</span>";
     ?>
     </td>
     </tr>
     </table>
   </td>
   </tr>
</table>
</form>
<?php
  require_once "utils/bottom_search.php";
?>