<?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['support36'];
  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($result2['user'] == 1) puterror2($TEXT['error-supp11']);
  if($result2['master'] == 1) puterror2($TEXT['error-supp11']);

  if(empty($_GET['user'])) $_GET['user'] = "";
  if(empty($_GET['tema'])) $_GET['tema'] = "";
  if(empty($_GET['master'])) $_GET['master'] = "";
  if(empty($_GET['manager'])) $_GET['manager'] = "";

  if(strlen($_GET['user'])>255) puterror2($TEXT['error-supp18']);
  if(strlen($_GET['tema'])>255) puterror2($TEXT['error-supp26']);
  if(strlen($_GET['master'])>255) puterror2($TEXT['error-supp17']);
  if(strlen($_GET['manager'])>255) puterror2($TEXT['error-supp17']);
  $_GET['user'] = rep($_GET['user']);
  $_GET['tema'] = rep($_GET['tema']);
  $_GET['master'] = rep($_GET['master']);
  $_GET['manager'] = rep($_GET['manager']);

  if(!empty($_GET['user'])) $user = " AND user = '".$_GET['user']."'";
   else $user = "";

  if(!empty($_GET['tema'])) $tema = " AND tema = '".$_GET['tema']."'";
   else $tema = "";

  if(!empty($_GET['manager'])) $manager= " AND manager = '".$_GET['manager']."'";
   else $manager = "";

  if(!empty($_GET['user'])) $big = $TEXT['support30']." - ".$_GET['user']."<br />".$TEXT['support13']." - ".$_GET['tema'];
   else $big = $TEXT['support64'];

  if(!empty($tema))
  {
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr align="center"><td class="supp_iniz"><?php echo $TEXT['support72']; ?>&nbsp;<span class="grn"><?php echo $_GET['master']; ?></span><br><?php echo $TEXT['support73']; ?><span class="grn"><?php echo $_GET['tema']; ?></span></td></tr>
<tr>
    <td align="center">
      <table class="table" border="1" width="60%" cellpadding="1" cellspacing="1">
       <tr class="tableheadercat">
        <td><img alt='picture' src='../img/show.png' /></td>
        <td><?php echo $TEXT['support1']; ?></td>
        <td><?php echo $TEXT['support47']; ?></td>
        <td><?php echo $TEXT['search-date']; ?></td>
       </tr>
       <?php
       $query_total = "SELECT 
           `zay_id`,
           `tema`,
           `time_isp`,
           `data`,
           YEAR(data) AS usr_year,
           MONTH(data) AS usr_month,
           DAY(data) AS usr_day,
           `arch_id`,
           `problema`
           FROM `tbl_supp_archive`
           WHERE `master` = '".$_GET['master']."' ".$user." ".$tema." ".$manager."
           ORDER BY data DESC";
        $tot_tmp = mysql_query($query_total);
         if(!$tot_tmp) puterror2($TEXT['error-tbl25']);
           while($sost2 = mysql_fetch_array($tot_tmp,MYSQL_ASSOC))
           {
           $dat1=$sost2['usr_day'];
           $dat2=$sost2['usr_month'];
           $dat3=$sost2['usr_year'];
           if($sost2['problema'] !== "") $file_image = "<a href='zayavka_rep.php?arch_id=".$sost2['arch_id']."' target=_blank title='".$TEXT['support14']."'><img alt='picture' src='../img/show.png' /></a>";
            else $file_image = "---";

            echo "<tr class='texttable'>
              <td class='support_ob4'>".$file_image."</td>
              <td class='support_ob4'>".$sost2['zay_id']."</td>
              <td>".$sost2['time_isp']." ".$TEXT['support48']."</td>
              <td>".$dat1." ".$month[$dat2]." ".$dat3." ".$TEXT['year']."</td>
            </tr>";
           }
            ?>
        </table>
      </td>
   </tr>
</table>
<?php
}
else
{
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr align="center"><td class="supp_iniz"><?php echo $TEXT['support72']; ?>&nbsp;<span class="grn"><?php echo $_GET['master']; ?></span></td></tr>
<tr>
    <td align="center">
      <table class="table" border="1" width="60%" cellpadding="1" cellspacing="1">
       <tr class="tableheadercat">
        <td><?php echo $TEXT['support13']; ?></td>
        <td><?php echo $TEXT['support65']; ?></td>
       </tr>
       <?php
       $query_total = "SELECT DISTINCT `tema` FROM `tbl_supp_archive` WHERE `master` = '".$_GET['master']."' ".$manager."  ORDER BY tema";
        $tot_tmp = mysql_query($query_total);
         if(!$tot_tmp) puterror2($TEXT['error-tbl25']);
           while($sost3 = mysql_fetch_array($tot_tmp,MYSQL_ASSOC))
           {
             $query_total2 = mysql_query("SELECT COUNT(arch_id) FROM tbl_supp_archive WHERE master = '".$_GET['master']."' AND tema = '".$sost3['tema']."' ".$manager." ");
              $mast = mysql_result($query_total2, 0);

            echo "<tr class='texttable'>
              <td><a href='rpt_mast.php?tema=".$sost3['tema']."&master=".$_GET['master']."&manager=".$_GET['manager']."' title='".$TEXT['support14']."'>".$sost3['tema']."</a></td>
              <td>".$mast."</td>
            </tr>";
           }
            ?>
        </table>
      </td>
   </tr>
</table>
<?php
}
?>
</body>
</html>