<?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['support3'];

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

  if(empty($_GET['user_id'])) puterror($TEXT['error-usr1']);
  if(strlen($_GET['user_id'])>11) puterror($TEXT['error-usr2']);
  if(strlen($_GET['org_id'])>11) puterror($TEXT['search-err9']);
  if(strlen($_GET['tema_id'])>11) puterror($TEXT['error-supp1']);
  $_GET['user_id'] = rep($_GET['user_id']);
  $_GET['org_id'] = rep($_GET['org_id']);
  $_GET['tema_id'] = rep($_GET['tema_id']);

  if(!isset($button)) $button = $TEXT['support16'];
  if(!isset($action)) $action = "zayavka_add.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>&nbsp;</td></tr>
<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 = '".$_GET['user_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 = $_GET['user_id'];
	       $org_id = $user['org_id'];

                 if(!empty($user['photo']) && $user['photo']!="-") $result_image = "<tr valign=top><td width='10%' rowspan='11'>&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>
             <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='90%' cellpadding='0' cellspacing='0'><tr>
      <td>
         <fieldset class='zayavka' >
         <legend align="left" title="<?php echo $TEXT['support3']; ?>"><?php echo $TEXT['support12']; ?></legend>
          <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>
             <tr><td align="right" width="30%" class="support">&nbsp;</td><td class="support" width="80%" align="left">&nbsp;</td></tr>
             <tr><td align="right" width="20%" class="support">&nbsp;<?php echo $TEXT['support13']; ?>&nbsp;</td>
                 <td width="70%" class="support" align="left">
                   <select class="support" name="tema_id" onchange=window.location.href=this.options[this.selectedIndex].value;>
                   <?php
                   $query = "SELECT * FROM `tbl_supp_tema` WHERE `visible` = 'show' 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.php?tema_id=".$tema['tema_id']."&user_id=".$_GET['user_id'].">".$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']."' ";
                        $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.php?tema_id=".$tema['tema_id']."&user_id=".$_GET['user_id'].">".$tema['tema']."</option>";
                       if(!empty($_GET['tema_id'])) 
                         {
                       $query_sh = "SELECT shablon FROM `tbl_supp_tema` WHERE tema_id='".$_GET['tema_id']."' ";
                        $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` 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;
                       }
                   ?>
                 </select>
               </td>
             </tr>
             <tr><td align="right" width="20%" class="support">&nbsp;<?php echo $TEXT['support41']; ?>&nbsp;</td>
                 <td width="70%" class="support" align="left">
                   <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) puterror($TEXT['error-tbl24']);
                      while($sroch = mysql_fetch_array($sroch_tmp,MYSQL_ASSOC))
                       {
                       $chk = "<option value=".$sroch['sroch_id'].">".$sroch['srochnost']."</option>";
                       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 class="support2" cols="70" rows="5" name=description ><?php echo $shablon; ?></textarea></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support15']; ?>&nbsp;</td>
               <td class="support" width="70%" align="left"><input class="support" type=file name=image ></td>
             </tr>
             <tr>
               <td align="right" width="30%" class="support">&nbsp;<?php echo $TEXT['support20']; ?>&nbsp;</td>
               <td class="support" width="70%" align="left"><input class="support" size=50 maxlength=100 type=password name=kod ></td>
             </tr>
             <tr><td align="right" width="30%" class="support">&nbsp;</td><td class="support" width="80%" 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; ?>' /></td></tr>
             </tr>
             <tr><td align="right" width="30%" class="support">&nbsp;</td><td class="support" width="80%" align="left">&nbsp;
               <input type=hidden name=usr_id value='<?php echo $usr_id; ?>' />
               <input type=hidden name=org_id value='<?php echo $org_id; ?>' />
               </td></tr>
          </table>
       </fieldset>
      </td>
     </td>
     </tr>
     </table>
   </tr>
</table>
</form>
<?php
  require_once "utils/bottom_search.php";
?>