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

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

  if(!isset($button)) $button = $TEXT['support29'];
  if(!isset($action2)) $action2 = "zayavka_upd.php";

  if(strlen($_GET['org_id'])>11) puterror($TEXT['error-org']);
  if(strlen($_GET['zay_id'])>11) puterror($TEXT['error-supp7']);
  if(strlen($_POST['search'])>11) puterror($TEXT['error-supp7']);
  $_GET['org_id'] = rep($_GET['org_id']);
  $_GET['zay_id'] = rep($_GET['zay_id']);
  $_POST['search'] = rep($_POST['search']);
  $org_id = $_GET['org_id'];
  ?>
  <table class="table" border="0" align="center" cellpadding="0" cellspacing="0" width="90%">
  <?php
  $query2 = "SELECT 
      tbl_supp_zayavka.zay_id,
      tbl_supp_zayavka.sost_id,
      tbl_supp_zayavka.tema_id,
      tbl_supp_zayavka.usr_id,
      tbl_supp_zayavka.pic_tr,
      tbl_supp_zayavka.man_id,
      tbl_supp_zayavka.mast_id,
      tbl_supp_zayavka.problema,
      tbl_supp_sostoyanie.sostoyanie,
      tbl_supp_tema.tema
      FROM tbl_supp_zayavka
      JOIN tbl_supp_sostoyanie ON tbl_supp_zayavka.sost_id=tbl_supp_sostoyanie.sost_id
      JOIN tbl_supp_tema ON tbl_supp_zayavka.tema_id=tbl_supp_tema.tema_id
      WHERE tbl_supp_zayavka.zay_id='".$_GET['zay_id']."'";
              $zayavka = mysql_query($query2);
               if(!$zayavka) puterror($TEXT['error-tbl26']);
                  $num_rows2 = mysql_num_rows($zayavka);
                  if($num_rows2 == 0) echo "<h1 class='userpage'><br />&nbsp;&nbsp; ".$TEXT['search-err4']."</h1>";
                  while($zay = mysql_fetch_array($zayavka,MYSQL_ASSOC))
                  {
                    $sost = $zay['sostoyanie'];
                    $tema_full = $zay['tema'];

                    $query7 = "SELECT familiya, name, otchestvo FROM tbl_users WHERE user_id = '".$zay['usr_id']."' ";
                     $users2 = mysql_query($query7);
                      if(!$users2) puterror($TEXT['error-tbl2']);
                       $user2 = mysql_fetch_array($users2,MYSQL_ASSOC);

                    $iniziator = $user2['familiya']." ".$user2['name']." ".$user2['otchestvo'];

                    if(!empty($zay['pic_tr'])) $pic_file = $TEXT['support27'];
                      else $pic_file = $TEXT['support28'];

                    if(empty($_GET['zay_id'])) $zayav_id = $_POST['search'];
                      else $zayav_id = $_GET['zay_id'];

                    echo "<tr><td class='supp_iniz' align='left' width='45%'>".$TEXT['support30']." ".$iniziator."</td><td>&nbsp;</td></tr>";
                    echo "<tr><td><br /></td><td><br /></td></tr>";
                   ?>
                    <tr><td width='45%'>
                    <table class="table" border="0" cellpadding="1" cellspacing="0" width="100%">
                      <tr>
                        <td>
                          <?php
                          $dog = "@";

                          $query3 = "SELECT 
                              tbl_users.user_id,
                              tbl_users.dom_id,
                              tbl_users.str_id,
                              tbl_users.house_id,
                              tbl_users.name,
                              tbl_users.familiya,
                              tbl_users.otchestvo,
                              tbl_users.phone_city,
                              tbl_users.phone_int,
                              tbl_users.phone_mob,
                              tbl_users.room,
                              tbl_users.mail,
                              tbl_domain.domain,
                              tbl_street.street,
                              tbl_house.house
                              FROM tbl_users
                              JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_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
                              WHERE tbl_users.user_id = (SELECT usr_id FROM tbl_logins WHERE login_id = '".$zay['man_id']."' limit 1)";
                          $users3 = mysql_query($query3);
                           if(!$users3) puterror(mysql_error());
                           $num_rows_supp1 = mysql_num_rows($users3);
                            while($user3 = mysql_fetch_array($users3,MYSQL_ASSOC))
                             {
                             $room3 = $user3['room'];
                             $familiya3 = $user3['familiya'];
                             $name3 = $user3['name'];
                             $otchestvo3 = $user3['otchestvo'];
                             $mail3 = $user3['mail'];
                             $phone_mob3 = $user3['phone_mob'];
                             $phone_int3 = $user3['phone_int'];
                             $phone_city3 = $user3['phone_city'];
                             $usr_id3 = $zay['man_id'];
                             $res_dom3 = $user3['domain'];
                             $email3 = $mail3.$dog.$res_dom3;
                             $res_str3 = $user3['street'];
                             $res_hou3 = $user3['house'];

                             if(!empty($user3['photo']) && $user3['photo']!="-") $result_image3 = "<tr align='center'><td width='30%' rowspan='12'><img alt='picture' width='130' height='185' src='personal/".$user3['photo']."' /></td></tr>";
                                   else $result_image3 = "";
                             }
                             if($num_rows_supp1 == 0) $no_supp = "<tr valign=top><td class='about'>".$TEXT['error-empty-supp']."</td></tr>";
                              else $no_supp = "";

                                echo "<fieldset class='zayavka2' >";
                                echo " <legend align='left' class='about'>".$TEXT['support22']."</legend>";
                                 echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'> ";
                                 echo $no_supp;
                                  echo $result_image3;
                                    if(!empty($familiya3)) echo "<tr align=top><td width='70%' class='texttableusrtit'>$familiya3&nbsp; $name3&nbsp; $otchestvo3</td></tr>";
                                    if(!empty($room3)) echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-adrr']."<span class='texttableusr'>&nbsp;".$TEXT['user-str']."&nbsp;$res_str3,&nbsp; ".$TEXT['user-home']."$res_hou3,&nbsp; ".$TEXT['user-room']."$room3</span></td></tr>";
                                    if(!empty($phone_mob3) && $phone_mob3!=="-") echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-tel-mob']."<span class='texttableusr'>&nbsp;$phone_mob3</span></td></tr>";
                                    if(!empty($phone_city3) && $phone_city3!=="-") echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-tel-city']."<span class='texttableusr'>&nbsp;$phone_city3</span></td></tr>";
                                    if(!empty($phone_int3) && $phone_int3!=="-") echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-tel-int']."<span class='texttableusr'>&nbsp;$phone_int3</span></td></tr>";
                                    if(!empty($mail3) && $res_dom3!=="-") echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-e-mail']."&nbsp;<a href=mailto:$email3><span class='texttableusr'>$email3</span></td></tr>";
                                    echo "</table></fieldset>";
                                    ?>
                        </td>
                     </tr>
                </table>
            </td>
            <td width='45%'>
               <table class="table" border="0" cellpadding="1" cellspacing="0" width="100%">
                    <tr>
                      <td>
                        <?php
                        $query4 = "SELECT 
                            tbl_users.user_id,
                            tbl_users.dom_id,
                            tbl_users.str_id,
                            tbl_users.house_id,
                            tbl_users.name,
                            tbl_users.familiya,
                            tbl_users.otchestvo,
                            tbl_users.phone_city,
                            tbl_users.phone_int,
                            tbl_users.phone_mob,
                            tbl_users.room,
                            tbl_users.mail,
                            tbl_domain.domain,
                            tbl_street.street,
                            tbl_house.house
                            FROM tbl_users
                            JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_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
                            WHERE tbl_users.user_id = (SELECT usr_id FROM tbl_logins WHERE login_id = '".$zay['man_id']."' limit 1)";
                        $users4 = mysql_query($query4);
                         if(!$users4) puterror(mysql_error());
                         $num_rows_supp2 = mysql_num_rows($users4);
                          while($user4 = mysql_fetch_array($users4,MYSQL_ASSOC))
                           {
                           $room4 = $user4['room'];
                           $familiya4 = $user4['familiya'];
                           $name4 = $user4['name'];
                           $otchestvo4 = $user4['otchestvo'];
                           $mail4 = $user4['mail'];
                           $phone_mob4 = $user4['phone_mob'];
                           $phone_int4 = $user4['phone_int'];
                           $phone_city4 = $user4['phone_city'];
                           $usr_id4 = $zay['mast_id'];
                           $res_dom4 = $user4['domain'];
                           $email4 = $mail4.$dog.$res_dom4;
                           $res_str4 = $user4['street'];
                           $res_hou4 = $user4['house'];

                           if(!empty($user4['photo']) && $user4['photo']!="-") $result_image4 = "<tr align='center'><td width='30%' rowspan='12'><img alt='picture' width='130' height='185' class='photo' src='personal/".$user4['photo']."' /></td></tr>";
                              else $result_image4 = "";
                           }
                           if($num_rows_supp2 == 0) $no_supp2 = "<tr valign=top><td class='about'>".$TEXT['error-empty-supp']."</td></tr>";
                             else $no_supp2 = "";

                           echo "<fieldset class='zayavka3' >";
                           echo " <legend align='left' class='about'>".$TEXT['support23']."</legend>";
                           echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'> ";
                           echo $no_supp2;
                            echo $result_image4;
                             if(!empty($familiya4)) echo "<tr align=top><td width='70%' class='texttableusrtit'>$familiya4&nbsp; $name4&nbsp; $otchestvo4</td></tr>";
                              if(!empty($room4)) echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-adrr']."<span class='texttableusr'>&nbsp;".$TEXT['user-str']."&nbsp;$res_str4,&nbsp; ".$TEXT['user-home']."$res_hou4,&nbsp; ".$TEXT['user-room']."$room4</span></td></tr>";
                               if(!empty($phone_mob4) && $phone_mob4!=="-") echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-tel-mob']."<span class='texttableusr'>&nbsp;$phone_mob4</span></td></tr>";
                                if(!empty($phone_city4) && $phone_city4!=="-") echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-tel-city']."<span class='texttableusr'>&nbsp;$phone_city4</span></td></tr>";
                                 if(!empty($phone_int4) && $phone_int4!=="-") echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-tel-int']."<span class='texttableusr'>&nbsp;$phone_int4</span></td></tr>";
                                  if(!empty($mail4) && $res_dom4!=="-") echo "<tr valign=top><td width='70%' class='about'>".$TEXT['user-e-mail']."<span class='texttableusr'>&nbsp;<a href=mailto:$email4>$email4</span></td></tr>";
                                   echo "</table></fieldset>";
                                   ?>
                 </td>
               </tr>
            </table>
          </td>
       </tr>
  </table>
  <form enctype='multipart/form-data' action=<?php echo $action2; ?> method=post>
<hr width="90%" align="center" />
     <table align='center' border='0' width='90%' cellpadding='0' cellspacing='0'><tr>
      <td>
         <fieldset class='zayavka' >
         <legend align="left"><?php echo $TEXT['support1']; ?> <?php echo $zayav_id; ?></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_ob' width="80%" align="right"><?php echo $TEXT['support25']; ?>: <?php echo $sost; ?></td></tr>
     <tr><td align="right" width="30%" class="support">&nbsp;<b><?php echo $TEXT['support13']; ?>:&nbsp;</b></td><td class="support" width="70%" align="left"><font color=green><b><?php echo $tema_full; ?></b></font></td></tr>
     <tr><td align="right" width="30%" class="support">&nbsp;<b><?php echo $TEXT['support14']; ?>:&nbsp;</b></td><td class="support" width="70%" align="left"><textarea cols="110" rows="5" name=description ><?= $zay['problema']; ?></textarea></td></tr>
     <tr><td align="right" width="30%" class="support">&nbsp;<b><?php echo $TEXT['support26']; ?>:&nbsp;</b></td><td class="support" width="70%" align="left"><font color=green><b><?php echo $pic_file; ?></b></font></td></tr>
     <?php
	$nadpis = $TEXT['support20'];
     if(empty($zay['mast_id'])) echo "
     <tr><td align='right' width='20%' class='support'>&nbsp;$nadpis&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 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='$button'></td></tr>";
     ?>
     </table>
       </fieldset>
     <input type=hidden name=zay_id value='<?php echo $zayav_id; ?>'>
     <input type=hidden name=org_id value='<?php echo $org_id; ?>'>
     </td>
     </tr>
     </table>
  </form>
   <?php
           }
  require_once "utils/bottom_search.php";
?>