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

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

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

  if(empty($_GET['id'])) puterror3($TEXT['exusr-error1']);
  if(strlen($_GET['id'])>200) puterror3($TEXT['error-user18']);
  $_GET['id'] = rep($_GET['id']);

  //*************************************
  $query = "SELECT id, mbox_host, home, name FROM `users` WHERE `id`='".$_GET['id']."' ";
  $result = mysql_query($query);
  if(!$result) puterror3($TEXT['error-tbl28']);
      $result2 = mysql_fetch_array($result);

    exec("rm -rf ".$result2['home']."");

            $organizaciya = $TEXT['admin-podpis']."<br>".$TEXT['exusr-mail'];
            $address = $TEXT['admin-mail'];
            $podpis = $organizaciya." ".date("D, d-M-Y H:i:s", time());
            $tema = $TEXT['exusr-mail-tema2'];
            $msg = "<b>".$TEXT['user-e-mail']." ".$result2['id']."@".$result2['mbox_host']."&nbsp;".$TEXT['exusr-act12']."</b><br /><br />".$TEXT['exusr-act10']."&nbsp;".$result2['name']."<br />".$TEXT['user-hom']."&nbsp;".$result2['home']."<br />".$TEXT['exusr-mail2']."<br /><hr />".$podpis."";

             $podpis = stripslashes($podpis);
             $tema = stripslashes($tema);
             $msg = nl2br(stripslashes($msg));

              @mail($address, $tema, $msg, join("\r\n", array(
              "From: phonebook@".$result2['mbox_host']."",
              "MIME-Version: 1.0",
              "Content-type: text/html; charset=utf-8",
              "Content-Transfer-Encoding: 8bit",
              "Date: ".date("D, d-M-Y H:i:s", time())."",
              "X-Mailer: Phone Book, version 2.3.5"
              )));

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-ex-mb-del'];
  $what = $result2['id']."@".$result2['mbox_host'];
  $who = $result2['fullname'];
  //*************************************

  $query3 = "DELETE FROM `users` WHERE `id`='".$_GET['id']."' LIMIT 1";
  if(mysql_query($query3))
  {
  $query4 = "DELETE FROM `aliases` WHERE `local_part`='".$_GET['id']."' OR `recipients`='".$_GET['id']."' ";
  if(mysql_query($query4))
  {
  $query5 = "DELETE FROM `userforward` WHERE `local_part`='".$_GET['id']."' OR `recipients`='".$_GET['id']."' ";
  if(mysql_query($query5))
  {
  $query6 = "SELECT * FROM `userforward` WHERE `recipients`REGEXP '".$_GET['id']."' ";
  $result6 = mysql_query($query6);
  if (!$result6) puterror3($TEXT['error-tbl33']);
      while($result7 = mysql_fetch_array($result6))
      {
      $iskh1=$_GET['id'];
      $str1=$result7['recipients'];
      $pattern = "#($iskh1+@[-0-9a-z_\.]+\.[a-z]{2,6}+\, ?)#i";
      $res1=preg_replace($pattern,"",$str1);
      $pattern = "#(\, $iskh1+@[-0-9a-z_\.]+\.[a-z]{2,6}?)#i";
      $res1=preg_replace($pattern,"",$res1);
      $pattern = "#(\, $iskh1?)#i";
      $res1=preg_replace($pattern,"",$res1);
      $pattern = "#($iskh1+\, ?)#i";
      $res1=preg_replace($pattern,"",$res1);

      $query7 = "UPDATE `userforward` SET `recipients`='".$res1."' WHERE `local_part`='".$result7['local_part']."'";
      if(!mysql_query($query7)) puterror3($TEXT['error-tbl33']);
      }
  $query8 = "SELECT * FROM `aliases` WHERE `recipients`REGEXP '".$_GET['id']."' ";
  $result8 = mysql_query($query8);
  if (!$result8) puterror3($TEXT['error-tbl32']);
      while($result9 = mysql_fetch_array($result8))
      {
      $iskh2=$_GET['id'];
      $str2=$result9['recipients'];
      $pattern2 = "#($iskh2+@[-0-9a-z_\.]+\.[a-z]{2,6}+\, ?)#i";
      $res2=preg_replace($pattern2,"",$str2);
      $pattern2 = "#(\, $iskh2+@[-0-9a-z_\.]+\.[a-z]{2,6}?)#i";
      $res2=preg_replace($pattern2,"",$res2);
      $pattern2 = "#(\, $iskh2?)#i";
      $res2=preg_replace($pattern2,"",$res2);
      $pattern2= "#($iskh2+\, ?)#i";
      $res2=preg_replace($pattern2,"",$res2);

      $query9 = "UPDATE `aliases` SET `recipients`='".$res2."' WHERE `local_part`='".$result9['local_part']."'";
      if(!mysql_query($query9)) puterror3($TEXT['error-tbl32']);
      }
    $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-tbl33']);
  } else puterror3($TEXT['error-tbl32']);
  } else puterror3($TEXT['error-tbl28']);
  require_once "../../util/bottom.php";
?>
