<?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['supp-tema-title3'];
  $helppage = "";

  if(is_file ("../lang/".$lang."/trans.php")) require_once "../lang/".$lang."/trans.php";
     require_once "../lang/ru/trans.php";
  require_once "../config.php";
  require_once "../util/top_layer1.php";

  if($result2['user'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['master'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['manager'] == 1) puterror2($TEXT['error-loginform4']);

  if(empty($_POST['tema_id'])) puterror2($TEXT['error-tema5']);
  if(strlen($_POST['tema_id'])>11) puterror2($TEXT['error-tema4']);
  if(empty($_POST['tema'])) puterror2($TEXT['error-tema1']);
  if(strlen($_POST['tema'])>255) puterror2($TEXT['error-tema2']);
  if(empty($_POST['position'])) puterror2($TEXT['error-nd4']);
  if(strlen($_POST['position'])>11) puterror2($TEXT['error-nd5']);
  if(strlen($_POST['shablon'])>255) puterror2($TEXT['error-shablon']);
  if(strlen($_POST['visible'])>5) puterror2($TEXT['error-new11']);

  if(isset($_POST['tema'])) $tema=trim($_POST['tema']);
    else $tema="";
     if(empty($tema)) puterror2($TEXT['error-tema3']);

  if(isset($_POST['position'])) $position=trim($_POST['position']);
    else $position="";
     if(empty($position)) puterror2($TEXT['error-nd7']);

  $_POST['tema'] = rep($_POST['tema']);
  $_POST['position'] = rep($_POST['position']);
  $_POST['tema_id'] = rep($_POST['tema_id']);
  $_POST['shablon'] = rep($_POST['shablon']);
  $_POST['visible'] = rep($_POST['visible']);

  $query10 = "SELECT `tema` FROM `tbl_supp_tema` WHERE `tema_id`='".$_POST['tema_id']."' ";
  $result10 = mysql_query($query10);
  if(!$result10) puterror2($TEXT['error-tbl22']);
      $result_lib = mysql_fetch_array($result10);
      if($_POST['tema']!=$result_lib['tema']) {
          $query9 = "SELECT `tema` FROM `tbl_supp_tema` WHERE `tema`='".$_POST['tema']."' ";
            $result9 = mysql_query($query9);
              if(!$result9) puterror2($TEXT['error-tbl22']);
                 if(mysql_num_rows($result9)>0) puterror2($TEXT['global-est']);
                   else $name_tema = "`tema` = '".$_POST['tema']."', ";
        }
       else $name_tema = "";

  //*************************************
  $query3 = "SELECT * FROM `tbl_supp_tema` WHERE `tema_id`='".$_POST['tema_id']."' ";
  $result3 = mysql_query($query3);
  if(!$result3) puterror2($TEXT['error-tbl22']);
   $result4 = mysql_fetch_array($result3,MYSQL_ASSOC);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-supp9'];
  $what = "&laquo;".$result4['tema']."&raquo;".$TEXT['log-na']."&laquo;".$_POST['tema']."&raquo;".$TEXT['log-id'].$_POST['tema_id'];
  $who = $result2['fullname'];
  //*************************************
  $query = "UPDATE `tbl_supp_tema` SET $name_tema `position` = '".$_POST['position']."', `shablon` = '".$_POST['shablon']."', `visible` = '".$_POST['visible']."' WHERE `tema_id`='".$_POST['tema_id']."' ";
  if(mysql_query($query))
  {
    $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=index-tema.php' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-tema6']);
  require_once "../util/bottom.php";
?>
