<?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" />
  </head>
  <body>
  <?php
  if($result2['administrator'] == 0) puterror2($TEXT['error-supp11']);

  if(empty($_GET['pas_str_id'])) puterror2($TEXT['meet-err-edit2']);
  if(strlen($_GET['pas_str_id'])>11) puterror2($TEXT['meet-err-edit3']);

  $query_iskh = "SELECT `p_tmp` FROM `tbl_p_tmp` WHERE `usr_id` = '".$result2['login_id']."' AND stat = '1' 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_tmp1 = $result_iskh2['p_tmp'];

  $query_iskh2 = "SELECT `p_tmp` FROM `tbl_p_tmp` WHERE `usr_id` = '".$result2['login_id']."' AND stat = '2' LIMIT 1";
    $result_iskh2 = mysql_query($query_iskh2);
      if(!$result_iskh2) puterror2($TEXT['error-tbl53']);
        $result_iskh3 = mysql_fetch_array($result_iskh2,MYSQL_ASSOC);
        $kfr_tmp2 = $result_iskh3['p_tmp'];

  $query = "SELECT 
      tbl_pass_keep.pas_id,
      tbl_pass_keep.visible,
      tbl_pass_strukt.strukt_name
      FROM tbl_pass_keep
      LEFT JOIN tbl_pass_strukt ON tbl_pass_keep.pas_str_id=tbl_pass_strukt.pas_str_id
      WHERE tbl_pass_keep.pas_str_id = '".$_GET['pas_str_id']."' ";
     $result = mysql_query($query);
     if(!$result) puterror3($TEXT['error-tbl54']);
       if(mysql_num_rows($result)>0)
         {
          while($result_exps = mysql_fetch_array($result,MYSQL_ASSOC))
          {
            $strukt_name = $result_exps['strukt_name'];
            if($result_exps['visible'] == "hide") {
            $query_iskh_spr = mysql_query("SELECT `familiya`, `name`, `otchestvo` FROM `tbl_users`
                                                               WHERE LOWER(mail) = LOWER((SELECT AES_DECRYPT(mail_lgn,'".$kfr_tmp2."') AS mail_lgn FROM `tbl_pass_keep` WHERE `pas_id` = '".$result_exps['pas_id']."' LIMIT 1)) LIMIT 1");
            $result_iskh_spr_num = mysql_num_rows($query_iskh_spr);
            if($result_iskh_spr_num > 0)
              {
               $result_iskh_spr = mysql_fetch_array($query_iskh_spr,MYSQL_ASSOC);
               $fio = $result_iskh_spr['familiya']." ".$result_iskh_spr['name']." ".$result_iskh_spr['otchestvo'];

              $query_iskh_p = "UPDATE `tbl_pass_keep` SET `fio` = '".$fio."' WHERE `pas_id` = '".$result_exps['pas_id']."' LIMIT 1";
              $result_iskh_p = mysql_query($query_iskh_p);
               if(!$result_iskh_p) puterror2($TEXT['error-tbl52']);
              }
            } else
               {
                $query_iskh_spr = mysql_query("SELECT `familiya`, `name`, `otchestvo` FROM `tbl_users`
                                                               WHERE LOWER(mail) = LOWER((SELECT AES_DECRYPT(mail_lgn,'".$kfr_tmp1."') AS mail_lgn FROM `tbl_pass_keep` WHERE `pas_id` = '".$result_exps['pas_id']."' LIMIT 1)) LIMIT 1");
                $result_iskh_spr_num = mysql_num_rows($query_iskh_spr);
                if($result_iskh_spr_num > 0)
                 {
                  $result_iskh_spr = mysql_fetch_array($query_iskh_spr,MYSQL_ASSOC);
                  $fio = $result_iskh_spr['familiya']." ".$result_iskh_spr['name']." ".$result_iskh_spr['otchestvo'];

                  $query_iskh_p = "UPDATE `tbl_pass_keep` SET `fio` = '".$fio."' WHERE `pas_id` = '".$result_exps['pas_id']."' LIMIT 1";
                  $result_iskh_p = mysql_query($query_iskh_p);
                  if(!$result_iskh_p) puterror2($TEXT['error-tbl52']);
                 }
              }
         }
       }

//*************************************
$ip = $_SERVER['REMOTE_ADDR'];
$doing = $TEXT['pass-log'];
$what = $TEXT['pass-log6']."&laquo;".$strukt_name."&raquo;";
$who = $result2['fullname'];
//*************************************
$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=pass_keep.php?pas_str_id=".$_GET['pas_str_id']."&amp;k=".$_POST['k']."' />
               </head></html>";
   } else puterror2($TEXT['error-log']);
?>
</body>
</html>