<?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";
  //include "by-time-isp.php";
  //include "tutorial-2-charts-pie.php";
  ?>
  <meta http-equiv='Refresh' content='600; URL=report.php' />
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/reader.css" />

<script type="text/javascript" src="../js/swfobject.js"></script>
<script type="text/javascript">

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-month-mast",
  "250", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-month-mast.php"}, {"wmode" : "transparent"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-pre-month-mast",
  "250", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-pre-month-mast.php"}, {"wmode" : "transparent"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-month",
  "550", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-month.php"}, {"wmode" : "transparent"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-year-man",
  "250", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-year-man.php"}, {"wmode" : "transparent"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-month-user",
  "400", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-month-user.php"}, {"wmode" : "transparent"} );

swfobject.embedSWF(
  "../open-flash-chart.swf", "by-this-pre-month-user",
  "400", "250", "9.0.0", "expressInstall.swf",
  {"data-file":"by-this-pre-month-user.php"}, {"wmode" : "transparent"} );

</script>
  </head>
  <body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
  <script type="text/javascript" language="JavaScript" src="../lang/calendar-<?php echo $lang; ?>.js"></script>
  <?php
  if($result2['user'] == 1) puterror2($TEXT['error-supp11']);
  if($result2['master'] == 1) puterror2($TEXT['error-supp11']);

  $query3 = "SELECT
    YEAR(data) AS start_year,
    MONTH(data) AS start_month,
    DAY(data) AS start_day
    FROM `tbl_start` ";
    $count_tmp = mysql_query($query3);
     if(!$count_tmp) puterror2($TEXT['error-tbl11']);
      $count = mysql_fetch_array($count_tmp);

      $day = $count['start_day'];
      $date_year = $count['start_year'];
      $date_month = $count['start_month'];
      $year = $TEXT['year'];
      if($count['start_year'] == "0") $data_r = "---";
        else $data_r = $day." ".$month[$date_month]." ".$date_year." ".$year;

  $query2 = "SELECT COUNT(arch_id) AS work FROM `tbl_supp_archive` ";
    $work_tmp = mysql_query($query2);
     if(!$work_tmp) puterror2($TEXT['error-tbl23']);
      $work = mysql_fetch_array($work_tmp,MYSQL_ASSOC);
      $work_res = $work['work'];

       if(empty($_POST['search'])) $_POST['search'] = "";
       if(empty($_POST['typepar'])) $_POST['typepar'] = "";

  if(strlen($_POST['search'])>100) puterror2($TEXT['search-err2']);
  if(strlen($_POST['typepar'])>10) puterror2($TEXT['search-err3']);
  $_POST['search'] = rep($_POST['search']);
  $_POST['typepar'] = rep($_POST['typepar']);

  $search_string = "";
    switch($_POST['typepar'])
      {
      case 1: //номер заявки
      $search_string = " WHERE `zay_id`='".$_POST['search']."'";
      break;
      case 2: //пользователь
      $search_string = "WHERE `user` LIKE '%".$_POST['search']."%'";
      break;
      case 3: //проблема, тема
      $search_string = "WHERE `tema` LIKE '%".$_POST['search']."%'";
      break;
      case 4: //решение
      $search_string = "WHERE `reshenie` LIKE '%".$_POST['search']."%'";
      break;
      case 5: //за дату
      $search_string = "WHERE `data` LIKE '%".$_POST['search']."%'";
      break;
      case 6: //сквозной
      $search_string = "WHERE `reshenie` LIKE '%".$_POST['search']."%' OR `problema` LIKE '%".$_POST['search']."%' OR `user` LIKE '%".$_POST['search']."%' OR `zay_id`='".$_POST['search']."' OR `data` LIKE '%".$_POST['search']."%' OR `tema` LIKE '%".$_POST['search']."%'";
      break;
      case 7: //описание проблемы
      $search_string = "WHERE `problema` LIKE '%".$_POST['search']."%'";
      break;
      }
//  if($action == "zay_id") $search_string = " WHERE `".$action."`='".$_POST['search']."'";
//   else $search_string = " WHERE `".$action."`REGEXP '".$_POST['search']."'";
?>
<form name='rprt' action=report.php method=post>
<table class='tabledata' border="0" cellpadding="3" cellspacing="1" width="100%">
<tr align="center">
  <td>
    <table width=100% class=topheader border="0" cellspacing="5">
     <tr align="center" valign="middle">
     <td align="right"><input class=inputsearch size=30 maxlength=30 type=text name=search title="<?php echo $TEXT['search-btn-title']; ?>" >&nbsp;<input type=submit value='<?php echo $TEXT['search-btn']; ?>'>
     </td>
     </tr>
     <tr>
       <td align="right" class="menu">
         <input type=radio name=typepar value=6 checked><?php echo $TEXT['zhurn-search1']; ?>
         <input type=radio name=typepar value=1><?php echo $TEXT['support1']; ?>
         <input type=radio name=typepar value=2><?php echo $TEXT['support30']; ?>
         <input type=radio name=typepar value=3><?php echo $TEXT['support13']; ?>
         <input type=radio name=typepar value=7><?php echo $TEXT['search-descr2']; ?>
         <input type=radio name=typepar value=4><?php echo $TEXT['support46']; ?>
         <input type=radio name=typepar value=5><?php echo $TEXT['support54']; ?>
         <script type="text/javascript" language="JavaScript">
	var o_cal = new tcal ({
		// form name
		'formname': 'rprt',
		// input name
		'controlname': 'search'
	});
	</script>
       </td>
     </tr>
    </table>
</td>
</tr>
<tr>
   <td align="left">&nbsp;&nbsp;<?php echo $TEXT['support67']; ?><span class="support_ob6"><?php echo $data_r; ?></span></td>
</tr>
<tr>
   <td align="left">&nbsp;&nbsp;<?php echo $TEXT['support68']; ?><span class="support_ob6"><?php echo $work_res; ?>&nbsp;<?php echo $TEXT['support69']; ?></span></td>
</tr>
<tr>
   <td align="left">&nbsp;&nbsp;<?php echo $TEXT['support70']; ?></td>
</tr>
</table>
</form>
<?php
 if(empty($_POST['search']))
 {
echo "<div id='by-this-pre-month-mast'></div>";
echo "<div id='by-this-month-mast'></div>";
echo "<div id='by-this-month'></div><hr width='95%' align='left'/>";
echo "<div id='by-this-year-man'></div>";
echo "<div id='by-this-pre-month-user'></div>";
echo "<div id='by-this-month-user'></div>";

}
 ?>
<?php
 if(!empty($_POST['search']))
 {
        $query4 = "SELECT 
            `arch_id`,
            `zay_id`,
            `manager`,
            `master`,
            `user`,
            `tema`,
            `time_isp`,
            `organizaciya`,
            `data`,
            YEAR(data) AS usr_year,
            MONTH(data) AS usr_month,
            DAY(data) AS usr_day,
            `problema`,
            `reshenie`
            FROM `tbl_supp_archive` ".$search_string."
            ORDER BY data DESC";
        $tmp4 = mysql_query($query4);
         if(!$tmp4) puterror2($TEXT['error-tbl25']);
           $num_rows = mysql_num_rows($tmp4);
           if($num_rows == 0)
            {
           echo "<table><tr><td align='center'>";
           echo "<h1 class='userpage'><br />&nbsp;&nbsp; ".$TEXT['search-err4']."</h1>";
           echo "</td></tr></table>";
             }
             else
              {
 ?>
  <table width=100%>
  <tr>
    <td align="center">
      <table class="table" border="1" width="100%" cellpadding="1" cellspacing="1">
       <tr class="tableheadercat">
        <td><?php echo $TEXT['support1']; ?></td>
        <td><img alt='picture' src='../img/show.png' /></td>
        <td><?php echo $TEXT['support42']; ?></td>
        <td><?php echo $TEXT['support43']; ?></td>
        <td><?php echo $TEXT['support30']; ?></td>
        <td><?php echo $TEXT['support13']; ?></td>
        <td><?php echo $TEXT['support47']; ?></td>
        <td><?php echo $TEXT['support89']; ?></td>
        <td><?php echo $TEXT['support54']; ?></td>
       </tr>
       <?php
           while($sost4 = mysql_fetch_array($tmp4,MYSQL_ASSOC))
           {
           $dat1=$sost4['usr_day'];
           $dat2=$sost4['usr_month'];
           $dat3=$sost4['usr_year'];

           if($sost4['problema'] !== "") $file_image = "<a href='zayavka_rep.php?arch_id=".$sost4['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'>".$sost4['zay_id']."</td>
              <td class='support_ob4'>".$file_image."</td>
              <td>".$sost4['manager']."</td>
              <td>".$sost4['master']."</td>
              <td>".$sost4['user']."</td>
              <td>".$sost4['tema']."</td>
              <td>".$sost4['time_isp']."</td>
              <td>".$sost4['organizaciya']."</td>
              <td>".$dat1." ".$month[$dat2]." ".$dat3." ".$TEXT['year']."</td>
            </tr>";
            }
              }
            ?>
        </table>
      </td>
   </tr>
<?php
 }
?>
</table>
</body>
</html>