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

  require_once "../config.php";
  require_once "top.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['administrator'] == 0 && $result2['master'] == 0) puterror2($TEXT['error-supp11']);

  if($result2['master'] == 1 && $result2['administrator'] == 0) $mast_vis = " AND visible='show' ";
   else $mast_vis = "";

  if(!isset($button)) $button = $TEXT['btn_save'];
  if(!isset($action)) $action = "pass_edit.php";
  if(!isset($button2)) $button2 = $TEXT['search-btn'];
  if(!isset($action2)) $action2 = "pass_editform.php";
  if(!isset($button3)) $button3 = $TEXT['pass-btn'];

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

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

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

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

  if(empty($_GET['pas_str_id'])) puterror2($TEXT['error-zhurn1']);
  if(strlen($_GET['pas_str_id'])>11) puterror2($TEXT['error-zhurn2']);
  if(empty($_GET['pas_id'])) puterror2($TEXT['error-zhurn11']);
  if(strlen($_GET['pas_id'])>11) puterror2($TEXT['error-zhurn12']);
  if(strlen($_GET['k'])>8) puterror2($TEXT['error-zhurn15']);
  $old_pas_str_id = $_GET['pas_str_id'];
  $old_pas_id = $_GET['pas_id'];
  $old_k = $_GET['k'];

  if(!empty($_POST['kfr'])) 
  {
    if($_POST['uv'] == "on")
   {
    $query_iskh_p = "SELECT AES_DECRYPT(dom_pass,'".$_POST['kfr']."') AS dom_pwd FROM `tbl_pass_keep` WHERE `visible` = 'show'";
      $result_iskh_p = mysql_query($query_iskh_p);
        if(!$result_iskh_p) puterror2($TEXT['error-tbl53']);
          $result_iskh_p2 = mysql_fetch_array($result_iskh_p,MYSQL_ASSOC);
          if(empty($result_iskh_p2['dom_pwd'])) 
           {
              echo "<table class='tabledata' align='center'>
                <tr><td class='z1'>".$TEXT['pass-key']."</td></tr>
                </table>
                <br />
                <form enctype='multipart/form-data' name='form' action=".$action2." method=post>
                <table class='tabledata' align='center' border='0'>
                <tr><td><input type='password' size=40 maxlength=255 name='kfr' /></td></tr>
                <tr><td align='center' ><input class='button' type=submit value='".$button3."' />
                <input type=hidden name=pas_str_id value='".$_GET['pas_str_id']."' />
                <input type=hidden name=pas_id value='".$_GET['pas_id']."' />
                <input type=hidden name=k value='".$_GET['k']."' />
                <input type=hidden name=uv value='".$_GET['uv']."' />
                </td></tr>
                </table>
                </form>";
              puterror3($TEXT['pass-err12']);
              exit();
          }

    $query_upd = "INSERT INTO tbl_p_tmp (`ptmp_id`, `usr_id`, `p_tmp`, `stat`) VALUES (NULL, '".$result2['login_id']."', '".$_POST['kfr']."', 1)";
     if(mysql_query($query_upd)) echo "<br /><table class='statssilka' align='center' border='0' width='30%'><tr><td><img class='tipsimg' alt='tips' src='../img/active.png' />".$TEXT['pass-key3']."</td></tr></table>";
      else echo "<table class='statssilka' align='center' border='0' width='60%'><tr><td><img class='tipsimg' alt='tips' src='../img/warn.png' />".$TEXT['pass-err10']."</td></tr></table>";
  }
  else 
   {
     $query_iskh_p = "SELECT AES_DECRYPT(dom_pass,'".$_POST['kfr']."') AS dom_pwd FROM `tbl_pass_keep` WHERE `visible` = 'hide'";
      $result_iskh_p = mysql_query($query_iskh_p);
        if(!$result_iskh_p) puterror2($TEXT['error-tbl53']);
          $result_iskh_p2 = mysql_fetch_array($result_iskh_p,MYSQL_ASSOC);
          if(empty($result_iskh_p2['dom_pwd'])) 
           {
              echo "<table class='tabledata' align='center'>
                <tr><td class='z1'>".$TEXT['pass-key']."</td></tr>
                </table>
                <br />
                <form enctype='multipart/form-data' name='form' action=".$action2." method=post>
                <table class='tabledata' align='center' border='0'>
                <tr><td><input type='password' size=40 maxlength=255 name='kfr' /></td></tr>
                <tr><td align='center' ><input class='button' type=submit value='".$button3."' />
                <input type=hidden name=pas_str_id value='".$_GET['pas_str_id']."' />
                <input type=hidden name=pas_id value='".$_GET['pas_id']."' />
                <input type=hidden name=k value='".$_GET['k']."' />
                <input type=hidden name=uv value='".$_GET['uv']."' />
                </td></tr>
                </table>
                </form>";
              puterror3($TEXT['pass-err12']);
              exit();
          }

    $query_upd = "INSERT INTO tbl_p_tmp (`ptmp_id`, `usr_id`, `p_tmp`, `stat`) VALUES (NULL, '".$result2['login_id']."', '".$_POST['kfr']."', 2)";
     if(mysql_query($query_upd)) echo "<br /><table class='statssilka' align='center' border='0' width='30%'><tr><td><img class='tipsimg' alt='tips' src='../img/active.png' />".$TEXT['pass-key2']."</td></tr></table>";
      else echo "<table class='statssilka' align='center' border='0' width='60%'><tr><td><img class='tipsimg' alt='tips' src='../img/warn.png' />".$TEXT['pass-err10']."</td></tr></table>";
     
    }
  }
  
  if($_GET['uv'] == "on")
   {
    $query_count = mysql_query("SELECT COUNT(ptmp_id) FROM tbl_p_tmp WHERE usr_id = '".$result2['login_id']."' AND stat = '1' ");
       $coun_rows = mysql_result($query_count, 0);
       if($coun_rows == 0) {
       echo "<table class='tabledata' align='center'>
                <tr><td class='z1'>".$TEXT['pass-key']."</td></tr>
                </table>
                <br />
                <form enctype='multipart/form-data' name='form' action=".$action2." method=post>
                <table class='tabledata' align='center' border='0'>
                <tr><td><input type='password' size=40 maxlength=255 name='kfr' /></td></tr>
                <tr><td align='center' ><input class='button' type=submit value='".$button3."' />
                <input type=hidden name=pas_str_id value='".$_GET['pas_str_id']."' />
                <input type=hidden name=pas_id value='".$_GET['pas_id']."' />
                <input type=hidden name=k value='".$_GET['k']."' />
                <input type=hidden name=uv value='".$_GET['uv']."' />
                </td></tr>
                </table>
                </form>";
           exit();
           }
        else $srch_pas = " AND `stat` = '1' ";
   }
    else
     {
      $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) {
       echo "<table class='tabledata' align='center'>
                <tr><td class='z1'>".$TEXT['pass-key']."</td></tr>
                </table>
                <br />
                <form enctype='multipart/form-data' name='form' action=".$action2." method=post>
                <table class='tabledata' align='center' border='0'>
                <tr><td><input type='password' size=40 maxlength=255 name='kfr' /></td></tr>
                <tr><td align='center' ><input class='button' type=submit value='".$button3."' />
                <input type=hidden name=pas_str_id value='".$_GET['pas_str_id']."' />
                <input type=hidden name=pas_id value='".$_GET['pas_id']."' />
                <input type=hidden name=k value='".$_GET['k']."' />
                <input type=hidden name=uv value='".$_GET['uv']."' />
                </td></tr>
                </table>
                </form>";
           exit();
           }
        else $srch_pas = " AND `stat` = '2' ";
     }

  $query_iskh = "SELECT `p_tmp` FROM `tbl_p_tmp` WHERE `usr_id` = '".$result2['login_id']."' $srch_pas LIMIT 1";
  $result_iskh = mysql_query($query_iskh);
  if(!$result_iskh) puterror2($TEXT['error-tbl53']);
   $result_iskh2 = mysql_fetch_array($result_iskh,MYSQL_ASSOC);
   $kfr_tmp = $result_iskh2['p_tmp'];

  $query3 = "SELECT
                   tbl_pass_keep.*,
                   AES_DECRYPT(tbl_pass_keep.dom_pass,'".$kfr_tmp."') AS dom_pwd,
                   AES_DECRYPT(tbl_pass_keep.mail_pass,'".$kfr_tmp."') AS mail_pwd,
                   AES_DECRYPT(tbl_pass_keep.dom_lgn,'".$kfr_tmp."') AS dom_login,
                   AES_DECRYPT(tbl_pass_keep.mail_lgn,'".$kfr_tmp."') AS mail_login,
                   tbl_users.user_id,
                   tbl_users.familiya,
                   tbl_users.name,
                   tbl_users.otchestvo
                   FROM `tbl_pass_keep`
                   LEFT JOIN tbl_users ON tbl_pass_keep.usr_id=tbl_users.user_id
                   WHERE tbl_pass_keep.pas_id = ".$_GET['pas_id']."";
   $tmp3 = mysql_query($query3);
    if(!$tmp3) puterror2($TEXT['error-tbl52']);
     $tmp_pos = mysql_fetch_array($tmp3,MYSQL_ASSOC);
     $full_name = rep_back_lower($tmp_pos['fio']);
     $user_mail = rep_back_lower($tmp_pos['mail_login']);
     $user_dom = rep_back_lower($tmp_pos['dom_login']);
     $passwd = $tmp_pos['dom_pwd'];
     $passwd2 = $tmp_pos['mail_pwd'];
     $primechanie = rep_back_lower($tmp_pos['primechanie']);
     if($tmp_pos['best_before'] == "0000-00-00") $best_before = "";
      else $best_before = $tmp_pos['best_before'];
     $old_photo = $tmp_pos['pic_tr'];
     if($tmp_pos['visible'] == "show") $vis_chk = "checked";
      else $vis_chk = "";
     if($tmp_pos['mast_edt'] == "yes") $edm_chk = "checked";
      else $edm_chk = "";
     if($tmp_pos['mail_form'] == "") $mail_form = $TEXT['support34']."(e-mail)";
      else $mail_form = rep_back_lower($tmp_pos['mail_form']);
     if($tmp_pos['mail_pass_form'] == "") $mail_pass_form = $TEXT['install-pswd']."(e-mail)";
      else $mail_pass_form = rep_back_lower($tmp_pos['mail_pass_form']);
     if($tmp_pos['dom_form'] == "") $dom_form = $TEXT['support34'];
      else $dom_form = rep_back_lower($tmp_pos['dom_form']);
     if($tmp_pos['dom_pass_form'] == "") $dom_pass_form = $TEXT['install-pswd'];
      else $dom_pass_form = rep_back_lower($tmp_pos['dom_pass_form']);
     if($tmp_pos['usr_id'] > 0) {
      $user_id_chk = "checked";
      $user_fio = "<span class='support24'>(".$tmp_pos['familiya']." ".$tmp_pos['name']." ".$tmp_pos['otchestvo'].")</span>";
     }
      else {
        $user_id_chk = "";
        $user_fio = "";
      }
     if(!empty($tmp_pos['pic_tr'])) $picture = "<img alt='picture' width='16' height='16' src='".$tmp_pos['pic_tr']."' />";
	       else $picture = "";

 $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>";
     }
   else {
       $rght_mast = "<tr><td class='support22'>".$TEXT['meet-view'].$TEXT['pass-tp'].":</td><td class='support'><input type=checkbox name=visible ".$vis_chk." />&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 ".$edm_chk." /></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 $_GET['pas_str_id']; ?>' />
    <input type=hidden name=pas_id value='<?php echo $_GET['pas_id']; ?>' />
    <input type=hidden name=k value='<?php echo $_GET['k']; ?>' />
    <input type=hidden name=uv value='<?php echo $_GET['uv']; ?>' />
    <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_editform.php?user_id=".$res_mail['user_id'],"&amp;pas_str_id=".$_GET['pas_str_id']."&amp;pas_id=".$_GET['pas_id']."&amp;k=".$_GET['k']."&amp;uv=".$_GET['uv']."' title='".$TEXT['pass-use-tit'],"'>".$TEXT['pass-use']."</a></td>
           </tr>";
     }
     echo "</table>";
   }

$usr_id = $_GET['user_id'];
if(!empty($_GET['user_id'])) {
 $query1 = "SELECT
      tbl_users.user_id,
      tbl_users.familiya,
      tbl_users.name,
      tbl_users.otchestvo
      FROM tbl_users
     WHERE tbl_users.user_id = '".$_GET['user_id']."'";
    $result1 = mysql_query($query1);
     if(!$result1) puterror3($TEXT['error-tbl2']);
     $res_mail = mysql_fetch_array($result1);
     $user_fio = "<span class='support24'>(".$res_mail['familiya']." ".$res_mail['name']." ".$res_mail['otchestvo'].")</span>";
 $new_usr = "&nbsp;<a href=# onClick=\"window.open('../user.php?user_id=".$_GET['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['pass-usr-new']."'><img alt='picture' src='../img/warn.png' height='16' width='16' align='top' /></a>";
 $user_id_chk = "checked";
}
    else $new_usr ="";
?>
<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; ?>'/><?php echo $new_usr; ?></td><td></td></tr>
<tr><td class="support22"><input class='mailform' size=20 maxlength=50 type=text name=dom_form  value='<?php echo $dom_form; ?>' />:</td><td class="support"><input class="inputmandatory" size=50 maxlength=255 type=text name=dom_lgn  value='<?php echo $user_dom; ?>' /></td><td></td></tr>
<tr><td class="support22"><input class='mailform' size=20 maxlength=50 type=text name=dom_pass_form  value='<?php echo $dom_pass_form; ?>' />:</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='".$mail_form."' />:</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='".$mail_pass_form."' />:</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 ><?php echo $primechanie; ?></textarea></td>
<td></td>
</tr>
<tr><td class="support22"><?php echo $TEXT['pic']; ?>:</td><td class="support"><input type=file name=photo> <?php echo $picture; ?> <input type=checkbox name=clear_picture> <?php echo $TEXT['tbl-delete']; ?></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 value='<?php echo $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['new-tag37']; ?>:</td><td class="support">
<?php
  function ShowTree($ParentID,$Level,$old_pas_str_id){
    $Level++;

    $query_tree="SELECT * FROM tbl_pass_strukt WHERE parent=".$ParentID." ".$mast_vis." ORDER BY position, strukt_name";
     $result4=mysql_query($query_tree);
      $num_rows = mysql_num_rows($result4);
       $kurent = 1;
       if($num_rows > 0)
       {
        while($row = mysql_fetch_array($result4,MYSQL_ASSOC))
        {
        $ID1 = $row['pas_str_id'];
        if($ID1 == $old_pas_str_id) $id1chk = "selected";
         else $id1chk = "";
        if($row['visible'] == "hide") $rtdir1 = "#&thinsp;";
         else  $rtdir1 = "";

         $query_check=mysql_query("SELECT COUNT(pas_str_id) FROM tbl_pass_strukt WHERE `parent`=".$ID1." ".$mast_vis."");
          $result_check=mysql_result($query_check, 0);
            if($result_check > 0)
            {
             if($Level == 1) $otstup = "&nbsp;&nbsp;";
              elseif($Level == 2) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;";
               elseif($Level == 3) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                elseif($Level == 4) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                 elseif($Level == 5) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                  elseif($Level == 6) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                   else $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
             if($kurent == $num_rows)
             {
             echo("<option ".$id1chk." value=".$ID1.">".$otstup.$rtdir1.$row['strukt_name']."");
             }
              else
              {
              echo("<option ".$id1chk." value=".$ID1.">".$otstup.$rtdir1.$row['strukt_name']."");
              }
            ShowTree($ID1, $Level,$old_pas_str_id);
            }
            else
            {
             if($Level == 1) $otstup = "&nbsp;&nbsp;";
              elseif($Level == 2) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;";
               elseif($Level == 3) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                elseif($Level == 4) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                 elseif($Level == 5) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                  elseif($Level == 6) $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                   else $otstup = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
              if($kurent == $num_rows)
             {
             echo("<option ".$id1chk." value=".$ID1.">".$otstup.$rtdir1.$row['strukt_name']."");
             }
              else
              {
              echo("<option ".$id1chk." value=".$ID1.">".$otstup.$rtdir1.$row['strukt_name']."");
              }
            }
            $kurent++;
       }
       $Level--;
     }
   }

echo("<select name='parent'>");
     $query = "SELECT * FROM `tbl_pass_strukt` WHERE `parent` = 0 ".$mast_vis." ORDER BY position, strukt_name";
     $result = mysql_query($query);
     if(!$result) puterror2($TEXT['error-tbl51']);
     $num_row = mysql_num_rows($result);
      $kurent_row = 1;
         if($num_row > 0){
           while($result_kat = mysql_fetch_array($result,MYSQL_ASSOC))
           {
             $ID = $result_kat['pas_str_id'];
             if($ID == $old_pas_str_id) $idchk = "selected";
              else $idchk = "";
             if($result_kat['visible'] == "hide") $rtdir = "#&thinsp;";
              else  $rtdir = "";

             $query_chk=mysql_query("SELECT COUNT(pas_str_id) FROM tbl_pass_strukt WHERE `parent`= ".$ID." ".$mast_vis."");
             $result_chk=mysql_result($query_chk, 0);
            if($result_chk > 0)
            {
             if($kurent_row == $num_row)
             {
             echo("<option ".$idchk." value=".$ID.">".$rtdir.$result_kat['strukt_name']."");
             }
              else
              {
              echo("<option ".$idchk." value=".$ID.">".$rtdir.$result_kat['strukt_name']."");
              }

             ShowTree($ID,$Level,$old_pas_str_id);
            }
             else
             {
              if($kurent_row == $num_row)
              {
              echo("<option ".$idchk." value=".$ID.">".$rtdir.$result_kat['strukt_name']."");
              }
              else
               {
               echo("<option ".$idchk." value=".$ID.">".$rtdir.$result_kat['strukt_name']."");
               }
            }
             $kurent_row++;
           }
         }
   echo("</select>");
   ?>
<input type=checkbox name="movechb" /></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 class="button" type=submit value='<?php echo $button; ?>' />
  <input type=hidden name=pas_str_id value='<?php echo $old_pas_str_id; ?>' />
  <input type=hidden name=pas_id value='<?php echo $old_pas_id; ?>' />
  <input type=hidden name=k value='<?php echo $old_k; ?>' />
  <input type=hidden name=usr_id value='<?php echo $usr_id; ?>' />
  <input type=hidden name=old_photo value='<?php echo $old_photo; ?>' />
  <?php
if($result2['administrator'] == 0) echo "<input type=hidden name=mail_form  value='".$mail_form."' />
                                                              <input type=hidden name=mail_lgn  value='".$user_mail."' />
                                                              <input type=hidden name=mail_pass_form  value='".$mail_pass_form."' />
                                                              <input type=hidden name=mail_pass  value='".$passwd2."'/>";
?>
</td>
<td></td>
</tr>
</table>
</form>
</body>
</html>