<?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-izm'];
  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 leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
<?php
 if(empty($_POST['kfr'])) puterror2($TEXT['pass-kfr-err1']);
 if(strlen($_POST['kfr'])>255) puterror2($TEXT['pass-kfr-err2']);

 if(isset($_POST['kfr'])) $kfr=trim($_POST['kfr']);
  else $kfr="";
    if(empty($kfr)) puterror2($TEXT['pass-kfr-err1']);

  $_POST['kfr'] = rep($_POST['kfr']);

  $query_iskh = "SELECT
     dom_pass AS rawpwd,
     AES_DECRYPT(dom_pass,'".$_POST['kfr']."') AS pwd
     FROM `tbl_pass_keep`
     WHERE `visible` = 'show'
     LIMIT 1";
  $result_iskh = mysql_query($query_iskh);
  if(!$result_iskh) puterror2($TEXT['error-tbl52']);
      $result_iskh2 = mysql_fetch_array($result_iskh,MYSQL_ASSOC);

  $query_count = mysql_query("SELECT COUNT(pas_id) FROM tbl_pass_keep WHERE visible = 'show' ");
    $coun_rows = mysql_result($query_count, 0);
  if($coun_rows > 0)
   {
    if(empty($result_iskh2['pwd']) && $result_iskh2['rawpwd'] !== "") puterror2($TEXT['pass-kfr-err']);
     else
     {
     $query_clr = mysql_query("DELETE FROM tbl_p_tmp WHERE `usr_id` = '".$result2['login_id']."' ");
     $query_upd = mysql_query("INSERT INTO tbl_p_tmp (`ptmp_id`, `usr_id`, `p_tmp`, `stat`) VALUES (NULL, '".$result2['login_id']."', '".$_POST['kfr']."', 1)");
     echo "<html><head>
               <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=pass_keep.php' />
               </head></html>";
     }
   } else
      {
      $query_clr = mysql_query("DELETE FROM tbl_p_tmp WHERE `usr_id` = '".$result2['login_id']."' ");
      $query_upd = mysql_query("INSERT INTO tbl_p_tmp (`ptmp_id`, `usr_id`, `p_tmp`, `stat`) VALUES (NULL, '".$result2['login_id']."', '".$_POST['kfr']."', 1)");
      echo "<html><head>
                <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=pass_keep.php' />
                </head></html>";
    }
?>
</body>
</html>