<?php
  ///////////////////////////////////////////////////
  //2010 (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 = $TEXT['log-tit2'];

  require_once "../config_a.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_adm.php";

  if($result2['administrator'] == 0 && $result2['user'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}
  $button = $TEXT['btn_filter'];
  $action = "index.php";

  if(empty($_POST['what']))
  {
   if(empty($_GET['what'])) {$_POST['what'] = "";}
    else {$_POST['what'] = $_GET['what'];}
  }

  if(empty($_POST['rows'])) {$_POST['rows'] = $result2['fltr_size'];}
  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(empty($_POST['what'])) {$_POST['what'] = "";}

  if(strlen($_POST['rows'])>12) {puterror($result2['skin'],$TEXT['error-log10']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['data'])>20) {puterror($result2['skin'],$TEXT['error-log6']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['ip'])>50) {puterror($result2['skin'],$TEXT['error-log7']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['who'])>100) {puterror($result2['skin'],$TEXT['error-log8']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['doing'])>100) {puterror($result2['skin'],$TEXT['error-log9']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['what'])>100) {puterror($result2['skin'],$TEXT['error-log10']); require_once "../utils/bottom_adm.php"; exit();}
  $_POST['data'] = rep($_POST['data']);
  $_POST['ip'] = rep($_POST['ip']);
  $_POST['who'] = rep($_POST['who']);
  $_POST['what'] = rep($_POST['what']);
  $_POST['doing'] = rep($_POST['doing']);
  $_POST['rows'] = rep($_POST['rows']);
  $_POST['rows'] = intval($_POST['rows']);

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

  $query2 = mysqli_query($dbcnx,"SELECT COUNT(data) AS c_data FROM tbl_logs");
    $coun = mysqli_fetch_array($query2,MYSQLI_ASSOC);
?>
<form enctype='multipart/form-data' action="<?php echo $action; ?>" method="post" >
<table align="center" class="table" border="0" cellpadding="0" cellspacing="0" width="70%">
<tr><td>
<fieldset>
<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="button2"><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-details']; ?></td><td><?php echo $TEXT['size-count']; ?></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="20" maxlength="100" type="text" name="what" title='<?php echo $TEXT['log-tit13']; ?>' value='<?php echo $what; ?>'></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>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="95%">
<tr align="right">
    <td class="bold_it"><?php echo $TEXT['log-tit3']; ?><?php echo $coun['c_data']; ?></td>
</tr>
</table>
<table align="center" 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 = "";}

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

     $query = "SELECT * FROM `tbl_logs` WHERE `what`!='' ".$data." ".$ip." ".$who." ".$doing." ".$what." ORDER BY data DESC, log_id DESC LIMIT ".$rows."";
     $result = mysqli_query($dbcnx,$query);
     if(!$result) {puterror($result2['skin'],$TEXT['error-tbl10']); require_once "../utils/bottom_adm.php"; exit();}
       $result_rows = mysqli_num_rows($result);
        if($result_rows >0)
         {
           ?>
           <thead>
           <tr class='tableheadercat'>
             <td width="10%"><?php echo $TEXT['tbl-date']; ?></td>
             <td width="10%"><?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-details']; ?></td>
                 </tr>
           </thead>
           <tbody id='tab'>
           <?php
             while($result_logs = mysqli_fetch_array($result,MYSQLI_ASSOC))
               {
           ?>
           <tr>
              <td><?php echo $result_logs['data'] ?></td>
              <td><?php echo $result_logs['ip'] ?></td>
              <td><?php echo $result_logs['who'] ?></td>
              <td><?php echo $result_logs['doing'] ?></td>
              <td><?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 "../utils/bottom_adm.php";
?>