<?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";

  require_once "../../config.php";
?>
<html>
<head>
<meta http-equiv="Expires" content="Mon, 23 May 1995 02:00:00 GMT" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $TEXT['exusr-title2']; ?></title>
<link rel="StyleSheet" type="text/css" href="../../util/admin.css" />
<link rel="icon" href="../../favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon" />
</head>
<body>
<?php

  if(empty($_COOKIE['login'])) puterror3($TEXT['error-loginform7']);
  if(empty($_COOKIE['passwrd'])) puterror3($TEXT['error-loginform7']);

  $query = "SELECT * FROM `tbl_logins` WHERE `login`='".$_COOKIE['login']."' ";
  $result = mysql_query($query);
  if(!$result) puterror2($TEXT['error-tbl20']);
      $result2 = mysql_fetch_array($result);
      $passw1 = $_COOKIE['passwrd'];
      $passw2 = $result2['pass'];

  if($passw1 !== $passw2) puterror3($TEXT['error-loginform6']);
  if(empty($passw1)) puterror3($TEXT['error-loginform8']);
  if($result2['administrator'] == 0) puterror3($TEXT['error-loginform4']);

  if(empty($_GET['user_id'])) puterror3($TEXT['error-usr1']);
  if(strlen($_GET['user_id'])>11) puterror3($TEXT['error-usr2']);
  $_GET['user_id'] = rep($_GET['user_id']);
  if(empty($_GET['id'])) puterror3($TEXT['error-usr1']);
  if(strlen($_GET['id'])>11) puterror3($TEXT['error-usr2']);
  $_GET['id'] = rep($_GET['id']);

     $query = "SELECT id, uid, gid, mbox_host, shell, home, quota, passwd FROM `users` WHERE `user_id` = '".$_GET['user_id']."' AND `id` = '".$_GET['id']."'";
     $result = mysql_query($query);
     if(!$result) puterror3($TEXT['error-tbl34']);
       if(mysql_num_rows($result)>0);
         {
	 $result_mail = mysql_fetch_array($result);

     $query3 = "SELECT * FROM `userforward` WHERE `local_part` = '".$result_mail['id']."' OR `recipients`REGEXP  '".$result_mail['id']."'";
     $result3 = mysql_query($query3);
     if(!$result3) puterror3($TEXT['error-tbl33']);
       if(mysql_num_rows($result3)>0);
         {
	 while($result_forw = mysql_fetch_array($result3))
	{
	  $res_forw .= $result_forw['local_part']." => ".$result_forw['recipients'].", <br />";
	}

     $query4 = "SELECT * FROM `aliases` WHERE `local_part` = '".$result_mail['id']."' OR `recipients`REGEXP  '".$result_mail['id']."'";
     $result4 = mysql_query($query4);
     if(!$result4) puterror3($TEXT['error-tbl32']);
       if(mysql_num_rows($result4)>0);
         {
	 while($result_alias = mysql_fetch_array($result4))
	{
	  $res_ali .= $result_alias['local_part']." => ".$result_alias['recipients'].", <br />";
	}
	       $dog = "@";
               $res_uid= $result_mail['uid'];
               $res_gid = $result_mail['gid'];
               $res_shell = $result_mail['shell'];
               $res_home = $result_mail['home'];
               $res_quota = $result_mail['quota'];
               $res_passw = $result_mail['passwd'];
               $mail = $result_mail['id'];
               $res_dom = $result_mail['mbox_host'];
               $email = $mail.$dog.$res_dom;

	 if($result_mail['user_id'] !== '0')
	  {

  $query2 = "SELECT tbl_users.user_id, tbl_users.room, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo,  tbl_users.phone_mob, tbl_users.phone_int, tbl_users.phone_city, tbl_users.photo, tbl_dolzhnost.dolzhnost, tbl_city.city, tbl_street.street, tbl_house.house, tbl_organizaciya.organizaciya, tbl_upravlenie.upravlenie, tbl_otdel.otdel 
FROM tbl_users 
JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id 
JOIN tbl_city ON tbl_users.city_id=tbl_city.city_id 
JOIN tbl_street ON tbl_users.str_id=tbl_street.str_id 
JOIN tbl_house ON tbl_users.house_id=tbl_house.house_id 
JOIN tbl_organizaciya ON tbl_users.org_id=tbl_organizaciya.org_id 
JOIN tbl_upravlenie ON tbl_users.upr_id=tbl_upravlenie.upr_id 
JOIN tbl_otdel ON tbl_users.otd_id=tbl_otdel.otd_id 
WHERE user_id = '".$_GET['user_id']."'";
  $users = mysql_query($query2);
         if(!$users) puterror3($TEXT['error-tbl2']);
            $user = mysql_fetch_array($users);

               $room = $user['room'];
               $familiya = $user['familiya'];
               $name = $user['name'];
               $otchestvo = $user['otchestvo'];
               $phone_mob = $user['phone_mob'];
               $phone_int = $user['phone_int'];
               $phone_city = $user['phone_city'];
               $res_dol = $user['dolzhnost'];
               $res_cit = $user['city'];
               $res_str = $user['street'];
               $res_hou = $user['house'];
               $res_org = $user['organizaciya'];
               $res_upr = $user['upravlenie'];
               $res_otd = $user['otdel'];

                 if(!empty($user['photo']) && $user['photo']!="-") $result_image = "<img width='130' height='185' class=photo src='../../../photo/".$user['photo']."' />";
                   else $result_image = "<img width='130' height='185' class=photo src='../../../img/nophoto.png' />";

                   if(!empty($res_cit) && $res_cit!=="-"){$cit = "&nbsp;".$TEXT['user-city']."&nbsp;".$res_cit.",&nbsp;";}
                    else $cit = "";

                   if(!empty($res_str) && $res_str!=="-"){$str = $TEXT['user-str']."&nbsp;".$res_str.",&nbsp;";}
                     else $str = "";

                   if(!empty($res_hou) && $res_hou!=="-"){$hou = $TEXT['user-home']." ".$res_hou;}
                     else $hou = "";

                   if(!empty($room) && $room!=="-"){$rum = ",&nbsp;".$TEXT['user-room']." ".$room;}
                     else $rum = "";

        echo "<table align='left' border='0' width='100%' cellpadding='0' cellspacing='0'> ";
        echo "<tr valign=top><td width='10%' rowspan='18'>$result_image</td></tr>";
        if(!empty($familiya)) echo "<tr align=top><td width='80%' class='texttableusrtit'>$familiya&nbsp;$name&nbsp;$otchestvo</td></tr>";
        echo "<tr width='70%' valign=top><td width='100%' class='about'>".$TEXT['user-adrr'].":<span class='texttableusr'>".$cit."".$str."".$hou."".$rum."</span></td></tr>";
        if(!empty($res_org)) echo "<tr valign=top><td width='80%'  class='about'>".$TEXT['search-org'].":<span class='texttableusr'>&nbsp;$res_org</span></td></tr>";
        if(!empty($res_upr) && $res_upr!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['search-upr'].":<span class='texttableusr'>&nbsp;$res_upr</span></td></tr>";
        if(!empty($res_otd) && $res_otd!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['search-otd'].":<span class='texttableusr'>&nbsp;$res_otd</span></td></tr>";
        if(!empty($res_dol) && $res_dol!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['search-dol'].":<span class='texttableusr'>&nbsp;$res_dol</span></td></tr>";
        if(!empty($phone_mob) && $phone_mob!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-tel-mob'].":<span class='texttableusr'>&nbsp;$phone_mob</span></td></tr>";
        if(!empty($phone_city) && $phone_city!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-tel-city'].":<span class='texttableusr'>&nbsp;$phone_city</span></td></tr>";
        if(!empty($phone_int) && $phone_int!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-tel-int'].":<span class='texttableusr'>&nbsp;$phone_int</span></td></tr>";
        if(!empty($mail)) echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-e-mail']."<span class='texttableusr'>&nbsp;<a href=mailto:".$email.">$email</span></td></tr>";
        if(!empty($res_passw) && $res_passw!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['login-password'].":<span class='texttableusr'>&nbsp;$res_passw</span></td></tr>";
        if(!empty($res_uid) && $res_uid!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-uid']."<span class='texttableusr'>&nbsp;$res_uid</span></td></tr>";
        if(!empty($res_gid) && $res_gid!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-gid']."<span class='texttableusr'>&nbsp;$res_gid</span></td></tr>";
        if(!empty($res_shell) && $res_shell!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-shell']."<span class='texttableusr'>&nbsp;$res_shell</span></td></tr>";
        if(!empty($res_home) && $res_home!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['user-hom']."<span class='texttableusr'>&nbsp;$res_home</span></td></tr>";
        if(!empty($res_quota) && $res_quota!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['exusr-kvota'].":<span class='texttableusr'>&nbsp;$res_quota</span></td></tr>";
        if(!empty($res_forw) && $res_forw!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['fwrd-text3'].":<span class='texttableusr'>&nbsp;$res_forw</span></td></tr>";
        if(!empty($res_ali) && $res_ali!=="-") echo "<tr valign=top><td width='80%' class='about'>".$TEXT['alias-text3'].":<span class='texttableusr'>&nbsp;$res_ali</span></td></tr>";
        echo "<tr valign=right><td width='80%' class='about'><a href=# onClick='self.close()' title='".$TEXT['user-close-tit']."'><span class='texttableusr'>&nbsp;".$TEXT['user-close']."</span></a></b></td></tr>";
        echo "</table>";
}
}
}
}
?>
</body>
</html>
