<?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['param_new'];

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

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

  if(empty($_POST['tip'])) {puterror($result2['skin'],$TEXT['param_err1']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['tip'])>255) {puterror($result2['skin'],$TEXT['param_err2']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['paramdays'])>20) {puterror($result2['skin'],$TEXT['param_err3']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['sizecount'])>20) {puterror($result2['skin'],$TEXT['param_err4']); require_once "../utils/bottom_adm.php"; exit();}

  if(isset($_POST['tip'])) {$tip=trim($_POST['tip']);}
    else {$tip="";}
     if(empty($tip)) {puterror($result2['skin'],$TEXT['param_err1']); require_once "../utils/bottom_adm.php"; exit();}

  if($_POST['paramon'] == "on" && $_POST['sizeon'] == "on") {puterror($result2['skin'],$TEXT['param_err5']); require_once "../utils/bottom_adm.php"; exit();}

  $_POST['tip'] = rep($_POST['tip']);
  $_POST['paramdays'] = rep($_POST['paramdays']);
  $_POST['sizecount'] = rep($_POST['sizecount']);
  $_POST['paramon'] = rep($_POST['paramon']);
  $_POST['sizeon'] = rep($_POST['sizeon']);

  if($_POST['paramon'] == "on") {$by_data = $_POST['paramdays'];}
    else {$by_data = "0";}

  if($_POST['sizeon'] == "on") {$by_count = $_POST['sizecount'];}
    else {$by_count = "0";}

  if($_POST['tip'] == "tbl_logs" && $_POST['paramon'] == "on") {$col_name = "data";}
   elseif($_POST['tip'] == "tbl_logs" && $_POST['sizeon'] == "on") {$col_name = "log_id";}

  $query_chk = "SELECT `col_tbl_name` FROM `tbl_clear` WHERE `col_tbl_name`='".$_POST['tip']."' ";
     $result_chk = mysqli_query($dbcnx,$query_chk);
     if(!$result_chk) {puterror($result2['skin'],$TEXT['error-tbl8']); require_once "../utils/bottom_adm.php"; exit();}
       if(mysqli_num_rows($result_chk)>0) {puterror($result2['skin'],$TEXT['error-double']); require_once "../utils/bottom_adm.php"; exit();}

  //*************************************
  //Информация для лога
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-praram1'];
  $what = $TEXT['analiz-tab']." &laquo;".$_POST['tip']."&raquo;";
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************
  $query = "INSERT INTO `tbl_clear` ( `cl_id`, `col_tbl_name`, `col_name`, `by_data`, `by_count`) VALUES ( NULL , '".$_POST['tip']."' , '$col_name' , '$by_data' , '$by_count' )";
  if(mysqli_query($dbcnx,$query))
  {
    $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysqli_query($dbcnx,$query2))
           {
             echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
                   </head></html>";
           } else {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
  } else {puterror($result2['skin'],$TEXT['param_err10']); require_once "../utils/bottom_adm.php"; exit();}
 require_once "../utils/bottom_adm.php";
?>