<?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['zhurn-new'];
  $helppage = $TEXT['zhurn-new-help'];

  require_once "../config.php";
  require_once "top.php";
  require_once "../admin/util/pass.php";

  ?>
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/grid.css" />
  <link rel="StyleSheet" type="text/css" href="../utils/reader.css" />
  </head>
  <body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
  <script type="text/javascript" language="JavaScript" src="../lang/calendar-<?php echo $lang; ?>.js"></script>
  <?php
  if($result2['master'] == 0 && $result2['administrator'] == 0) puterror2($TEXT['error-supp11']);

  if(!isset($button)) $button = $TEXT['btn_add'];
  if(!isset($action)) $action = "pass_add.php";
  if(!isset($button2)) $button2 = $TEXT['search-btn'];
  if(!isset($action2)) $action2 = "pass_addform.php";

  if(!empty($_POST['pas_str_id'])) $_GET['pas_str_id'] = $_POST['pas_str_id'];
   else $_GET['pas_str_id'] = $_GET['pas_str_id'];

  if(strlen($_POST['familiya'])>200) puterror3($TEXT['pass-fltr-err']);
  if(empty($_GET['pas_str_id'])) puterror2($TEXT['meet-err-edit2']);
  if(strlen($_GET['pas_str_id'])>11) puterror2($TEXT['meet-err-edit3']);
  if(strlen($_GET['user_id'])>11) puterror2($TEXT['meet-err-edit3']);
  $_POST['familiya'] = rep($_POST['familiya']);
  $_GET['pas_str_id'] = rep($_GET['pas_str_id']);
  $_GET['user_id'] = rep($_GET['user_id']);

  $old_pas_str_id = $_GET['pas_str_id'];
  $passwd=passgen($spr_pass);
  $passwd2=passgen($spr_pass);
  $familiya=$_POST['familiya'];

  $query_prov=mysql_query("SELECT `visible` FROM `tbl_pass_strukt` WHERE `pas_str_id`='".$old_pas_str_id."' LIMIT 1");
    $result_prov = mysql_fetch_array($query_prov);

 $query_count = mysql_query("SELECT COUNT(ptmp_id) FROM tbl_p_tmp WHERE usr_id = '".$result2['login_id']."' AND stat = '2' ");
 $coun_rows = mysql_result($query_count, 0);
 if($coun_rows > 0) $pass_root = "<img alt='picture' src='../img/active.png' height='16' width='16' align='top' />";
  else $pass_root = "<a href=# onClick=\"window.open('pass_rootkfr_form.php','popup','top=".$TEXT['user-top'].",left=".$TEXT['user-left'].",width=".$TEXT['user-width'].",height=".$TEXT['user-height'].",status=no,scrollbars=no,location=no,menubar=no,toolbar=no')\" title ='".$TEXT['pass-err10']."'><img alt='picture' src='../img/warn.png' height='16' width='16' align='top' /></a>";

 $query_count2 = mysql_query("SELECT COUNT(ptmp_id) FROM tbl_p_tmp WHERE usr_id = '".$result2['login_id']."' AND stat = '1' ");
 $coun_rows2 = mysql_result($query_count2, 0);
  if($coun_rows2 > 0) $pass_user = "<img alt='picture' src='../img/active.png' height='16' width='16' align='top' />";
  else $pass_user = "<a href=# onClick=\"window.open('pass_userkfr_form.php','popup','top=".$TEXT['user-top'].",left=".$TEXT['user-left'].",width=".$TEXT['user-width'].",height=".$TEXT['user-height'].",status=no,scrollbars=no,location=no,menubar=no,toolbar=no')\" title ='".$TEXT['pass-err11']."'><img alt='picture' src='../img/warn_usr.png' height='16' width='16' align='top' /></a>";

 if($result2['master'] == 1 && $result2['administrator'] == 0) $rght_mast = "<tr><td class='support22'>".$TEXT['pass-key'].":</td><td class='support'><input type=hidden name=visible value='on' /><input type=hidden name=mast_edt value='on' />&nbsp;".$pass_user."</td><td></td></tr>";
 if($result2['administrator'] == 1 && $result_prov['visible'] == "show") $rght_mast = "<tr><td class='support22'>".$TEXT['meet-view'].$TEXT['pass-tp'].":</td><td class='support'><input type=checkbox name=visible checked />&nbsp;".$pass_user."".$pass_root."</td><td></td></tr>
                 <tr><td class='support22'>".$TEXT['pass-edt-true'].":</td><td class='support'><input type=checkbox name=mast_edt checked /></td><td></td></tr>";
 if($result2['administrator'] == 1 && $result_prov['visible'] == "hide") $rght_mast = "<tr><td class='support22'>".$TEXT['meet-view'].$TEXT['pass-tp'].":</td><td class='support'><input type=checkbox name=visible />&nbsp;".$pass_user."".$pass_root."</td><td></td></tr>
                 <tr><td class='support22'>".$TEXT['pass-edt-true'].":</td><td class='support'><input type=checkbox name=mast_edt /></td><td></td></tr>";
?>
<table class="tabledata" align="center" border="0">
  <tr><td class="z1"><?php echo $titlepage; ?></td></tr>
  <tr><td class="help"><?php echo $helppage; ?></td></tr>
</table>
<form enctype='multipart/form-data' action=<?php echo $action2; ?> method=post>
<table class="table" border="0" align="center" cellpadding="0" cellspacing="0" width="30%">
<tr><td>
<fieldset class="filterr">
<legend align="left" title="<?php echo $TEXT['pass-flt-tip']; ?>"><?php echo $TEXT['support104']; ?></legend>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="zag2"><td><?php echo $TEXT['search-name2']; ?></td><td></td></tr>
<tr>
<td><input size=30 maxlength=125 type=text name=familiya title='<?php echo $TEXT['pass-flt-tip']; ?>' value='<?php echo $familiya; ?>'></td>
<td>
    <input type=hidden name=pas_str_id value='<?php echo $old_pas_str_id; ?>' />
    <input class="button" type=submit value='<?php echo $button2; ?>' />
</td>
</tr>
</table>
</fieldset>
</td></tr>
</table>
</form>
<br />
<?php
if(empty($_POST['familiya'])) $_POST['familiya'] = " ";
 else {
           echo "<table class='passusersrch' border='1' cellpadding='3' cellspacing='0' width='70%' align='center' >
            <tr class='tableheadercat' border='1'>
            <td>".$TEXT['pass-usr-fio']."</td>
            <td>".$TEXT['user-e-mail']."</td>
            <td>".$TEXT['pass-action']."</td>
            </tr>";

  $query1 = "SELECT tbl_users.user_id, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo, tbl_users.mail,  tbl_domain.domain
FROM tbl_users
JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_id
WHERE LOWER(tbl_users.familiya) LIKE LOWER('%".$_POST['familiya']."%')";
  $result1 = mysql_query($query1);
  if(!$result1) puterror3($TEXT['error-tbl2']);
    while($res_mail = mysql_fetch_array($result1))
     {
          echo " <tr class='support23' onmouseover=\"this.style.backgroundColor='#cccccc';\" onmouseout=\"this.style.backgroundColor='#ffffff';\">
             <td><a href=# onClick=\"window.open('../user.php?user_id=".$res_mail['user_id']."','popup','top=".$TEXT['user-top'].",left=".$TEXT['user-left'].",width=".$TEXT['user-width'].",height=".$TEXT['user-height'].",status=no,scrollbars=no,location=no,menubar=no,toolbar=no')\" title ='".$TEXT['global-usr']."'>".$res_mail['familiya']." ".$res_mail['name']." ".$res_mail['otchestvo']."</a></td>
             <td>".$res_mail['mail']."@".$res_mail['domain']."</td>
            <td><a href='pass_addform.php?user_id=".$res_mail['user_id'],"&amp;pas_str_id=".$_GET['pas_str_id']."' title='".$TEXT['pass-use-tit'],"'>".$TEXT['pass-use']."</a></td>
           </tr>";

    }
echo "</table>";
 }

 if(empty($_GET['user_id'])) {
     $_GET['user_id'] = " ";
     $user_id_chk = "";
     $user_fio = "";
 }
 else {
  $user_id_chk = "checked";
  $query1 = "SELECT
      tbl_users.user_id,
      tbl_users.familiya,
      tbl_users.name,
      tbl_users.otchestvo,
      tbl_users.mail,
      tbl_domain.domain
      FROM tbl_users
      JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_id
     WHERE tbl_users.user_id = '".$_GET['user_id']."'";
    $result1 = mysql_query($query1);
     if(!$result1) puterror3($TEXT['error-tbl2']);
     while($res_mail = mysql_fetch_array($result1))
     {
       $full_name = $res_mail['familiya']." ".$res_mail['name']." ".$res_mail['otchestvo'];
       $user_mail = $res_mail['mail'];
       $user_fio = "<span class='support24'>(".$res_mail['familiya']." ".$res_mail['name']." ".$res_mail['otchestvo'].")</span>";
     }
 }

$old_usr_id = $_GET['user_id'];
?>
<form enctype='multipart/form-data' name='rprt' action=<?php echo $action; ?> method=post>
<table class="tabledata" align="center">
<tr><td class="support22"><?php echo $TEXT['search-nazv']; ?>:</td><td class="support"><input class="inputmandatory" size=50 maxlength=255 type=text name=fio   value='<?php echo $full_name; ?>'/></td><td></td></tr>
<tr><td class="support22"><input class='mailform' size=20 maxlength=50 type=text name=dom_form  value='<?php echo $TEXT['support34']; ?>' />:</td><td class="support"><input class="inputmandatory" size=50 maxlength=255 type=text name=dom_lgn  value='<?php echo $user_mail; ?>' /></td><td></td></tr>
<tr><td class="support22"><input class='mailform' size=20 maxlength=50 type=text name=dom_pass_form  value='<?php echo $TEXT['install-pswd']; ?>' />:</td><td class="support"><input class="inputmandatory" size=50 maxlength=255 type=text name=dom_pass  value='<?php echo $passwd; ?>'/></td><td></td></tr>
<?php
if($result2['administrator'] == 1) echo "<tr><td class='support22'><input class='mailform' size=20 maxlength=50 type=text name=mail_form  value='".$TEXT['support34']." (e-mail)' />:</td><td class='support'><input size=50 maxlength=255 type=text name=mail_lgn  value='".$user_mail."' /></td><td></td></tr>
                                                                                                          <tr><td class='support22'><input class='mailform' size=20 maxlength=50 type=text name=mail_pass_form  value='".$TEXT['install-pswd']." (e-mail)' />:</td><td class='support'><input size=50 maxlength=255 type=text name=mail_pass  value='".$passwd2."'/></td><td></td></tr>";
?>
<tr><td class="support22"><?php echo $TEXT['know-prim']; ?>:</td><td class="support"><textarea cols="48" rows="8" name=primechanie ></textarea></td>
<td></td>
</tr>
<tr><td class="support22"><?php echo $TEXT['pic']; ?>:</td><td class="support"><input type=file name=photo></td></tr>
<tr><td class="support22"><?php echo $TEXT['pass-bb']; ?>:</td><td class="support"><input size=10 maxlength=10 type=text name=best_before />
   <script type="text/javascript" language="JavaScript">
	var o_cal = new tcal ({
		// form name
		'formname': 'rprt',
		// input name
		'controlname': 'best_before'
	});
	</script>
    </td><td></td></tr>
<tr><td class='support22'><?php echo $TEXT['pass-usr']; ?>:</td><td class='support'><input type=checkbox name=usr_using <?php echo $user_id_chk; ?> />&nbsp;<?php echo $user_fio; ?></td><td></td></tr>
<?php echo $rght_mast; ?>
<tr><td></td><td>
  <input type=hidden name=pas_str_id value='<?php echo $old_pas_str_id; ?>' />
  <input type=hidden name=usr_id value='<?php echo $old_usr_id; ?>' />
  <input class="button" type=submit value='<?php echo $button; ?>' />
</td>
<td></td>
</tr>
</table>
</form>
</body>
</html>