<?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['exusr-title4'];
  $helppage = "";

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

  if($result2['administrator'] == 0) puterror3($TEXT['error-loginform4']);

  if(strlen($_POST['user_id'])>11) puterror3($TEXT['error-user2']);
  if(empty($_POST['id'])) puterror3($TEXT['exusr-error17']);
  if(strlen($_POST['id'])>220) puterror3($TEXT['exusr-error18']);
  if(empty($_POST['mbox_host'])) puterror3($TEXT['error-domain1']);
  if(strlen($_POST['mbox_host'])>128) puterror3($TEXT['error-domain2']);
  if(empty($_POST['passwd'])) puterror3($TEXT['error-login10']);
  if(strlen($_POST['passwd'])>255) puterror3($TEXT['error-login5']);
  if(strlen($_POST['name'])>255) puterror3($TEXT['error-user14']);
  if(strlen($_POST['uid'])>10) puterror3($TEXT['exusr-error1']);
  if(empty($_POST['uid'])) puterror3($TEXT['exusr-error2']);
  if(strlen($_POST['gid'])>10) puterror3($TEXT['exusr-error4']);
  if(empty($_POST['gid'])) puterror3($TEXT['exusr-error5']);
  if(strlen($_POST['shl'])>32) puterror3($TEXT['exusr-error7']);
  if(empty($_POST['shl'])) puterror3($TEXT['exusr-error8']);
  if(strlen($_POST['hom'])>128) puterror3($TEXT['exusr-error10']);
  if(empty($_POST['hom'])) puterror3($TEXT['exusr-error11']);
  if(strlen($_POST['kvota'])>7) puterror3($TEXT['exusr-error13']);
  if(empty($_POST['kvota'])) puterror3($TEXT['exusr-error14']);
  if(strlen($_POST['visible'])>3) puterror3($TEXT['exusr-error16']);

  if(isset($_POST['id'])) $id=trim($_POST['id']);
    else $id="";
     if (empty($id)) puterror3($TEXT['exusr-error1']);

  if(isset($_POST['mbox_host'])) $mbox_host=trim($_POST['mbox_host']);
    else $mbox_host="";
     if (empty($mbox_host)) puterror3($TEXT['error-domain3']);

  if(isset($_POST['passwd'])) $passwd=trim($_POST['passwd']);
    else $passwd="";
     if (empty($passwd)) puterror3($TEXT['error-login10']);

  if(isset($_POST['uid'])) $uid=trim($_POST['uid']);
    else $uid="";
     if (empty($uid)) puterror3($TEXT['exusr-error3']);

  if(isset($_POST['gid'])) $gid=trim($_POST['gid']);
    else $gid="";
     if (empty($gid)) puterror3($TEXT['exusr-error6']);

  if(isset($_POST['shl'])) $shl=trim($_POST['shl']);
    else $shl="";
     if (empty($shl)) puterror3($TEXT['exusr-error9']);

  if(isset($_POST['hom'])) $hom=trim($_POST['hom']);
    else $hom="";
     if (empty($hom)) puterror3($TEXT['exusr-error12']);

  if(isset($_POST['kvota'])) $kvota=trim($_POST['kvota']);
    else $kvota="";
     if (empty($kvota)) puterror3($TEXT['exusr-error15']);

  $_POST['user_id'] = rep($_POST['user_id']);
  $_POST['id'] = rep($_POST['id']);
  $_POST['mbox_host'] = rep($_POST['mbox_host']);
  $_POST['name'] = rep($_POST['name']);
  $_POST['passwd'] = rep($_POST['passwd']);
  $_POST['uid'] = rep($_POST['uid']);
  $_POST['gid'] = rep($_POST['gid']);
  $_POST['shl'] = rep($_POST['shl']);
  $_POST['hom'] = rep($_POST['hom']);
  $_POST['kvota'] = rep($_POST['kvota']);
  $_POST['visible'] = rep($_POST['visible']);

  if($_POST['visible'] == "on") $visible = "Y";
    else $visible = "N";

  //*************************************
  $query = "SELECT * FROM `aliases` WHERE `local_part`='".$_POST['old_address']."' ";
  $result = mysql_query($query);
  if (!$result) puterror3($TEXT['error-tbl32']);
      $result2 = mysql_fetch_array($result);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-ex-mb-ed'];
  $what = $_POST['id']."@".$_POST['mbox_host'];
  $who = $result2['fullname'];
  //*************************************
  $query = "UPDATE `users` SET `name` = '".$_POST['name']."', `user_id` = '".$_POST['user_id']."', `crypt`= ENCRYPT('".$_POST['passwd']."'), `passwd` = '".$_POST['passwd']."', `uid` = '".$_POST['uid']."', `gid` = '".$_POST['gid']."', 
`mbox_host` = '".$_POST['mbox_host']."', `shell` = '".$_POST['shl']."', `home` = '".$_POST['hom']."', `quota` = '".$_POST['kvota']."', `active` = '$visible' WHERE `id`='".$_POST['id']."' LIMIT 1";
  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.php' />
                   </head></html>";
           } else puterror3($TEXT['error-log']);
  } else puterror3($TEXT['error-tbl32']);
  require_once "../../util/bottom.php";
?>
