<?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['org'])) $_GET['org'] = "";
  if(empty($_GET['time'])) $_GET['time'] = "";

  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['org'])>255) puterror2($TEXT['error-supp25']);
  if(strlen($_GET['time'])>4) puterror2($TEXT['error-supp27']);
  $_GET['user'] = rep($_GET['user']);
  $_GET['tema'] = rep($_GET['tema']);
  $_GET['master'] = rep($_GET['master']);
  $_GET['org'] = rep($_GET['org']);
  $_GET['time'] = rep($_GET['time']);

  if($_GET['time'] == 30) $time = " AND time_isp < '30' ";
  if($_GET['time'] == 60) $time = " AND time_isp BETWEEN '30' AND '60' ";
  if($_GET['time'] == 300) $time = " AND time_isp BETWEEN '61' AND '300' ";
  if($_GET['time'] == 1440) $time = " AND time_isp BETWEEN '301' AND '1440' ";
  if($_GET['time'] == 1441) $time = " AND time_isp > '1441' ";
  if($_GET['time'] == "") $time = "";

  if($_GET['time'] == 30) $time_header = "<br />".$TEXT['support47']."&nbsp;<span class='grn'>".$TEXT['support58']."</span>";
  if($_GET['time'] == 60) $time_header = "<br />".$TEXT['support47']."&nbsp;<span class='grn'>".$TEXT['support59']."</span>";
  if($_GET['time'] == 300) $time_header = "<br />".$TEXT['support47']."&nbsp;<span class='grn'>".$TEXT['support60']."</span>";
  if($_GET['time'] == 1440) $time_header = "<br />".$TEXT['support47']."&nbsp;<span class='grn'>".$TEXT['support61']."</span>";
  if($_GET['time'] == 1441) $time_header = "<br />".$TEXT['support47']."&nbsp;<span class='grn'>".$TEXT['support62']."</span>";
  if(empty($_GET['time'])) $time_header = "";
  if($_GET['time'] == "") $time_header = "";

  if(!empty($_GET['org'])) $big = $TEXT['support75']."<span class='grn'>".$_GET['org']."</span><br />".$TEXT['support78']." - <span class='grn'>".$_GET['user']."</span><br />".$TEXT['support13']." - <span class='grn'>".$_GET['tema']."</span>".$time_header;
   else $big = $TEXT['support78']." - <span class='grn'>".$_GET['user']."</span><br />".$TEXT['support13']." - <span class='grn'>".$_GET['tema']."</span>".$time_header;

  if(!empty($_GET['org'])) $organizaciya = " AND organizaciya = '".$_GET['org']."'";
   else $organizaciya = "";
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr align="center"><td class="supp_iniz">&nbsp;<?php echo $big; ?></td></tr>
<tr>
    <td align="center">
      <table class="table" border="1" width="70%" 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['support43']; ?></td>
        <td><?php echo $TEXT['support47']; ?></td>
        <td><?php echo $TEXT['search-date']; ?></td>
       </tr>
       <?php
       $query_total = "SELECT
           `zay_id`,
           `master`,
           `time_isp`,
           `data`,
           YEAR(data) AS usr_year,
           MONTH(data) AS usr_month,
           DAY(data) AS usr_day,
           `pic_tr`,
           `arch_id`,
           `problema`
           FROM tbl_supp_archive
           WHERE user = '".$_GET['user']."' AND tema = '".$_GET['tema']."' ".$organizaciya." ".$time."
           ORDER BY data DESC, zay_id 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['master']."</td>
              <td>".$sost2['time_isp']." ".$TEXT['support48']."</td>
              <td>".$dat1." ".$month[$dat2]." ".$dat3." ".$TEXT['year']."</td>
            </tr>";
           }
            ?>
        </table>
      </td>
   </tr>
</table>
</body>
</html>