<?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";
?>
<form action=index.php method=post>
<?php
  $title=$titlepage = $TEXT['ex-title'];
  $helppage = $TEXT['ex-help4']."<br />";

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

?>
  <input type=submit value='<?php echo $TEXT['btn_back']; ?>'>
<?php
  if($result2['administrator'] == 0) puterror3($TEXT['error-loginform4']);
  if(strlen($_POST['typepar'])>2) puterror3($TEXT['search-err3']);
  $_POST['typepar'] = rep($_POST['typepar']);

  $action = "logs";
    switch($_POST['typepar'])
      {
      case 1:
      $action = "logs";
      break;
      case 2:
      $action = "logs_cl";
      break;
      }

//     $exp_path = "../../../NormDoc/".$action."-".date("YMd-H-i-s",time()).".csv";
     $exp_path = "../../../NormDoc/".$action."-".date("YMd-H-i-s",time()).".csv";

      $file = fopen($exp_path,"a");

      if($action == "logs") 
      {
      $log_act = $TEXT['ex-log7'];
      $exp_head = $TEXT['tbl-date'].",".$TEXT['tbl-who-ip'].",".$TEXT['tbl-who-name'].",".$TEXT['tbl-what'].",".$TEXT['tbl-details']."\r\n";

      fwrite($file, $exp_head, strlen($exp_head));

     $query = "SELECT * FROM `tbl_logs` ORDER BY data";
     $result = mysql_query($query);
     if(!$result) puterror3($TEXT['error-tbl10']);
       if(mysql_num_rows($result)>0);
         {
          while($result_exps = mysql_fetch_array($result,MYSQL_ASSOC))
               {
        	$exp_string = $result_exps['data'].",".$result_exps['ip'].",".$result_exps['who'].",".$result_exps['doing'].",".$result_exps['what']."\r\n";

  		fwrite($file, $exp_string, strlen($exp_string));
 		}
         }
  	fclose($file);
       }
      if($action == "logs_cl") 
      {
      $log_act = $TEXT['ex-log8'];
      $exp_head = $TEXT['tbl-date'].",".$TEXT['tbl-who-ip'].",".$TEXT['tbl-who-name'].",".$TEXT['tbl-what'].",".$TEXT['tbl-details']."\r\n";

      fwrite($file, $exp_head, strlen($exp_head));

     $query = "SELECT * FROM `tbl_logs` ORDER BY data";
     $result = mysql_query($query);
     if(!$result) puterror3($TEXT['error-tbl10']);
       if(mysql_num_rows($result)>0);
         {
          while($result_exps = mysql_fetch_array($result,MYSQL_ASSOC))
               {
        	$exp_string = $result_exps['data'].",".$result_exps['ip'].",".$result_exps['who'].",".$result_exps['doing'].",".$result_exps['what']."\r\n";

  	        fwrite($file, $exp_string, strlen($exp_string));
 		}
         }
         fclose($file);

  $query_delete = "TRUNCATE TABLE `tbl_logs`";
  if(!mysql_query($query_delete)) puterror3($TEXT['error-tbl10']);
       }
  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['ex-log6'];
  $what = $log_act;
  $who = $result2['fullname'];
  //*************************************

    $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysql_query($query2))
           {
             echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=transfer.php?trans=".$exp_path."' />
                   </head></html>";
           } else puterror3($TEXT['error-log']);
?>
</form>
<?php
  require_once "../../util/bottom_exp.php";
?>