<?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['pass-key'];
  $helppage = "";

  require_once "../config.php";
  require_once "top.php";

  if(strlen($_POST['kfr'])>255) puterror2($TEXT['pass-kfr-err2']);
 $_POST['kfr'] = rep($_POST['kfr']);
?>
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/grid.css" />
  <link rel="shortcut icon" href="../Favicon/pass-keep.ico" type="image/x-icon" />
  </head>
  <body leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0" topmargin="0" >
<?php
  if(!isset($button)) $button = $TEXT['pass-btn'];
  if(!isset($action)) $action = "pass_rootkfr_form.php";
?>
<table class="tabledata" align="center">
  <tr><td class="z1"><?php echo $titlepage; ?></td></tr>
</table>
<br />
<form enctype='multipart/form-data' name='form' action=<?php echo $action; ?> 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='<?php echo $button; ?>' /></td></tr>
</table>
</form>
<?php
  if(!empty($_POST['kfr'])) 
  {
    $query_count = mysql_query("SELECT COUNT(pas_id) FROM tbl_pass_keep WHERE visible = 'hide' ");
    $coun_rows = mysql_result($query_count, 0);
     if($coun_rows > 0)
     {
      $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'])) puterror3($TEXT['pass-err12']);

    $query_clr = mysql_query("DELETE FROM tbl_p_tmp WHERE `usr_id` = '".$result2['login_id']."' AND `stat` = 2");
    $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 "<table class='statssilka' align='center' border='0' width='60%'><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>";
    } else
       {
        $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 "<table class='statssilka' align='center' border='0' width='60%'><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>";
       }
  }
?>
</body>
</html>