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

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

  $title=$titlepage=$TEXT['meet-help2'];

  require_once "config.php";
  require_once "utils/top_meet_otv.php";

  if(empty($_POST['evnt_id'])) puterror($TEXT['meet-err-edit2']);
  if(strlen($_POST['evnt_id'])>11) puterror($TEXT['meet-err-edit3']);
  if(empty($_POST['room_id'])) puterror($TEXT['meet-err-edit2']);
  if(strlen($_POST['room_id'])>11) puterror($TEXT['meet-err-edit3']);
  if(strlen($_POST['message'])>1000) puterror($TEXT['meet-err-edit7']);
  if(strlen($_POST['meet_name'])>255) puterror($TEXT['meet-err-edit6']);
  if(strlen($_POST['data'])>10) puterror($TEXT['meet-err-edit4']);
  if(strlen($_POST['timestart'])>2) puterror($TEXT['meet-err-edit5']);
  if(strlen($_POST['timestop'])>2) puterror($TEXT['meet-err-edit5']);
  if(!preg_match("/^[\d]{4}[\-][\d]{2}[\-][\d]{2}$/", $_POST['data'])) puterror($TEXT['meet-err-edit4']);
  if(!preg_match("/^[\d]{1,2}$/", $_POST['timestart'])) puterror($TEXT['meet-err-edit5']);
  if(!preg_match("/^[\d]{1,2}$/", $_POST['timestop'])) puterror($TEXT['meet-err-edit5']);
  if(!preg_match("/^[\d]{1,2}$/", $_POST['timestartmin'])) puterror($TEXT['meet-err-edit5']);
  if(!preg_match("/^[\d]{1,2}$/", $_POST['timestopmin'])) puterror($TEXT['meet-err-edit5']);
  if($_POST['timestart']>23) puterror($TEXT['meet-err-edit5']);
  if($_POST['timestop']>23) puterror($TEXT['meet-err-edit5']);
  if($_POST['timestart']<0) puterror($TEXT['meet-err-edit5']);
  if($_POST['timestop']<0) puterror($TEXT['meet-err-edit5']);
  if(strlen($_POST['timestartmin'])>2) puterror($TEXT['meet-err-edit5']);
  if(strlen($_POST['timestopmin'])>2) puterror($TEXT['meet-err-edit5']);
  if($_POST['timestop'] < $_POST['timestart']) puterror($TEXT['meet-err-edit8']);
  if(strlen($_POST['org_id'])>11) puterror($TEXT['error-org']);
  $_POST['data'] = rep($_POST['data']);
  $_POST['timestart'] = rep($_POST['timestart']);
  $_POST['timestop'] = rep($_POST['timestop']);
  $_POST['timestartmin'] = rep($_POST['timestartmin']);
  $_POST['timestopmin'] = rep($_POST['timestopmin']);
  $_POST['org_id'] = rep($_POST['org_id']);
  $_POST['old_org_id'] = rep($_POST['old_org_id']);
  $_POST['color_line'] = rep($_POST['color_line']);
  $_POST['meet_name'] = rep($_POST['meet_name']);
  $_POST['room_id'] = rep($_POST['room_id']);
  $_POST['evnt_id'] = rep($_POST['evnt_id']);
  $_POST['message'] = rep2($_POST['message']);
  if(empty($_POST['timestartmin'])) $_POST['timestartmin'] = "00";
  if(empty($_POST['timestopmin'])) $_POST['timestopmin'] = "00";

  $org_id = $_POST['org_id'];

  if($_POST['visible'] == "on") $meet_visible = "yes";
  else $meet_visible = "no";

  $query = "UPDATE `tbl_meet_event` SET
   `meet_name` = '".$_POST['meet_name']."',
   `meet_descr` = '".$_POST['message']."',
   `meet_visible` = '$meet_visible',
   `usr_id` = '".$result2['usr_id']."',
   `meet_data` = '".$_POST['data']."',
   `time_start` = '".$_POST['timestart']."' ,
   `time_stop` = '".$_POST['timestop']."' ,
   `meet_color` = '".$_POST['color_line']."',
   `room_id` = '".$_POST['room_id']."',
   `time_start_min` = '".$_POST['timestartmin']."',
   `time_stop_min` = '".$_POST['timestopmin']."'
   WHERE `evnt_id` = '".$_POST['evnt_id']."' ";
   if(mysql_query($query))
   {

   $usr_prep = mysql_query("DELETE FROM tbl_meet_users WHERE `evnt_id` = '".$_POST['evnt_id']."' ");

//function disabled by php > 5.5.3
////import_request_variables("gP", "in_");
// before using only ->  while(list($id,$value) = @each($in_usr))
 while(list($id2,$value2) = @each($_POST)) {
  if($id2 == "usr") {
   while(list($id,$value) = each($value2)) {
    if($id > 0 && $value == 'on')
     {
      $usr_tmp = mysql_query("INSERT INTO tbl_meet_users ( `meet_usr_id` , `evnt_id` , `usr_id`) VALUES ( NULL , '".$_POST['evnt_id']."' , '$id')");
     }
   }
  }
 }

   $query6 = "SELECT `familiya`, `name`, `otchestvo` FROM `tbl_users` WHERE `user_id` = '".$result2['usr_id']."'";
   $usr_tmp = mysql_query($query6);
    if(!$usr_tmp) puterror($TEXT['error-tbl2']);
     $usr = mysql_fetch_array($usr_tmp,MYSQL_ASSOC);
     $usr_name = $usr['familiya']." ".$usr['name']." ".$usr['otchestvo'];

    //*************************************
    $ip = $_SERVER['REMOTE_ADDR'];
    $doing = $TEXT['meet-log'];
    $what = $TEXT['meet-log2']." ".$_POST['evnt_id'];
    $who = $usr_name;
    //*************************************
    $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=meet_otv.php' />
                   </head></html>";
           } else puterror($TEXT['error-log']);
   } else puterror($TEXT['error-tbl49']);

  require_once "utils/bottom_search.php";
?>
