<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang."/".$lang.".php")) include "../lang/".$lang."/".$lang.".php";
     else include "../lang/ru/ru.php";

  $title=$titlepage = $TEXT['log-tit2'];
  $helppage = $TEXT['log-help'];

  require_once "../config.php";
  require_once "../util/top.php";

  if($result2['administrator'] == 0) puterror2($TEXT['error-loginform2']);

  if(!isset($button)) $button = $TEXT['btn_filter'];
  if(!isset($action)) $action = "index.php";

  if(empty($_POST['rows'])) $_POST['rows'] = "100";
  if(empty($_POST['data'])) $_POST['data'] = "";
  if(empty($_POST['ip'])) $_POST['ip'] = "";
  if(empty($_POST['who'])) $_POST['who'] = "";
  if(empty($_POST['doing'])) $_POST['doing'] = "";

  if(strlen($_POST['rows'])>12) puterror2($TEXT['error-log10']);
  if(strlen($_POST['data'])>20) puterror2($TEXT['error-log6']);
  if(strlen($_POST['ip'])>50) puterror2($TEXT['error-log7']);
  if(strlen($_POST['who'])>100) puterror2($TEXT['error-log8']);
  if(strlen($_POST['doing'])>100) puterror2($TEXT['error-log9']);
  $_POST['data'] = rep($_POST['data']);
  $_POST['ip'] = rep($_POST['ip']);
  $_POST['who'] = rep($_POST['who']);
  $_POST['doing'] = rep($_POST['doing']);
  $_POST['rows'] = rep($_POST['rows']);
  $_POST['rows'] = intval($_POST['rows']);

  $data=$_POST['data'];
  $ip=$_POST['ip'];
  $who=$_POST['who'];
  $doing=$_POST['doing'];
  $rows=$_POST['rows'];

  $query2 = mysql_query("SELECT COUNT(data) FROM tbl_logs");
    $coun = mysql_result($query2, 0);
?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="80%" >
<tr><td>
<fieldset class="filterr">
<legend align="left" title="<?php echo $TEXT['log-tit7']; ?>"><?php echo $TEXT['btn_filter']; ?></legend>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="zag2"><td><?php echo $TEXT['tbl-date']; ?></td><td><?php echo $TEXT['tbl-who-ip']; ?></td><td><?php echo $TEXT['tbl-who-name']; ?></td><td><?php echo $TEXT['tbl-what']; ?></td><td><?php echo $TEXT['tbl-rows']; ?></td></tr>
<tr><td><input size=10 maxlength=19 type=text name=data title="<?php echo $TEXT['log-tit8']; ?>" value="<?php echo $data; ?>"></td>
    <td><input size=16 maxlength=50 type=text name=ip title="<?php echo $TEXT['log-tit9']; ?>" value="<?php echo $ip; ?>"></td>
    <td><input size=18 maxlength=100 type=text name=who title="<?php echo $TEXT['log-tit10']; ?>" value="<?php echo $who; ?>"></td>
    <td><input size=30 maxlength=100 type=text name=doing title="<?php echo $TEXT['log-tit11']; ?>" value="<?php echo $doing; ?>"></td>
    <td><input size=11 maxlength=11 type=text name=rows title="<?php echo $TEXT['log-tit12']; ?>" value="<?php echo $rows; ?>"></td>
    <td><input class="button" type=submit value="<?php echo $button; ?>"></td>
</tr>
</table>
</fieldset>
</td></tr>
</table>
</form>
<br />
<span class="tabledata"><?php echo $TEXT['log-tit3']; ?></span><span class="boldit"><?php echo $coun; ?></span>
<table class="table" border="1" cellpadding="6" cellspacing="0" width="95%" >
<?php

   if(!empty($_POST['data'])) $data = "AND `data`REGEXP '".$_POST['data']."' ";
    else $data = "";

   if(!empty($_POST['ip'])) $ip = "AND `ip`REGEXP '".$_POST['ip']."' ";
    else $ip = "";

   if(!empty($_POST['who'])) $who = "AND LOWER(who) LIKE LOWER('%".$_POST['who']."%') ";
    else $who = "";

   if(!empty($_POST['doing'])) $doing = "AND LOWER(doing) LIKE LOWER('%".$_POST['doing']."%') ";
    else $doing = "";

     $query = "SELECT * FROM `tbl_logs` WHERE `what`!='' ".$data." ".$ip." ".$who." ".$doing." ORDER BY data DESC LIMIT ".$rows."";
     $result = mysql_query($query);
     if(!$result) puterror2($TEXT['error-tbl10']);
      $result_rows = mysql_num_rows($result);
        if($result_rows >0)
         {
           ?>
           <thead>
           <tr class="tableheadercat">
             <td class="tabledata" width="10%"><?php echo $TEXT['tbl-date']; ?></td>
             <td class="tabledata"><?php echo $TEXT['tbl-who-ip']; ?></td>
             <td class="tabledata"><?php echo $TEXT['tbl-who-name']; ?></td>
             <td class="tabledata"><?php echo $TEXT['tbl-what']; ?></td>
             <td class="tabledata"><?php echo $TEXT['tbl-details']; ?></td>
           </tr>
           </thead>
           <tbody>
           <?php
             while($result_logs = mysql_fetch_array($result,MYSQL_ASSOC))
               {
           ?>
           <tr onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td class="tabledata"><?php echo $result_logs['data']; ?></td>
              <td class="tabledata"><?php echo $result_logs['ip']; ?></td>
              <td class="tabledata"><?php echo $result_logs['who']; ?></td>
              <td class="tabledata"><?php echo $result_logs['doing']; ?></td>
              <td class="tabledata"><?php echo $result_logs['what']; ?></td>
           </tr>
           <?php
               }
               ?>
           </tbody>
           <tfoot>
            <tr class="tableheadercat">
             <td colspan=5 align="right"><?php echo $TEXT['size-count2']; ?> = <?php echo $result_rows; ?></td>
            </tr>
           </tfoot>
               <?php
         }
?>
</table>
<?php
  require_once "../util/bottom.php";
?>