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

  require_once "../config.php";
  require_once "top.php";
  ?>
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/reader.css" />
  <link rel="StyleSheet" type="text/css" href="../utils/grid.css" />
  <link rel="shortcut icon" href="../Favicon/know-base.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['zhurn-print-btn'];
  if(!isset($action)) $action = "pass_print.php";

  if(empty($_POST['pas_str_id'])) puterror2($TEXT['error-zhurn1']);
  if(strlen($_POST['pas_str_id'])>11) puterror2($TEXT['error-zhurn2']);
?>
<table align="right">
  <tr><td><img align="bottom" alt="Logo" title='<?php echo $TEXT['global-title']; ?>' src="../img/logo.png" /></td><td class="logo"><?php echo $TEXT['global-title']; ?>&nbsp;<span class="logover">(<?php echo $TEXT['maker8']; ?>)</span></td></tr>
  <tr><td></td><td class="logo"><?php echo $TEXT['pass-title']; ?></td></tr>
  <tr><td></td><td>&nbsp;</td></tr>
</table>
<br />
<?php
  $result_strukt_name = "";
 //function disabled by php > 5.5.3
 ////import_request_variables("gP", "in_");
 // before using only ->  while(list($id,$value) = @each($in_printitem))
 while(list($id2,$value2) = @each($_POST)) {
  if($id2 == "printitem") {
   while(list($id,$value) = each($value2)) {
     if($id > 0 && $value == 'on')
     {
      $query4 = "SELECT
    tbl_pass_keep.pas_id,
    tbl_pass_keep.pas_str_id,
    tbl_pass_keep.usr_id,
    tbl_pass_keep.fio,
    tbl_pass_keep.visible,
    tbl_pass_keep.mast_edt,
    tbl_logins.fullname,
    tbl_users.user_id
    FROM tbl_pass_keep
    JOIN tbl_logins ON tbl_pass_keep.login_id=tbl_logins.login_id
    LEFT JOIN tbl_users ON tbl_pass_keep.usr_id=tbl_users.user_id
    WHERE tbl_pass_keep.pas_id = '".$id."'
    ORDER BY tbl_pass_keep.fio ";
    $tmp4 = mysql_query($query4);
     if(!$tmp4) puterror2(mysql_error());
      $num_rows = mysql_num_rows($tmp4);
        if($num_rows == 0)
          {
           echo "<h1 class='userpage'><br />&nbsp;&nbsp;".$TEXT['zhurn-nodata']."</h1>";
          }
           else
           {
 ?>
      <table border="0" width="90%" cellpadding="0" cellspacing="0"  align="center">
       <tr>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
       </tr>
       <?php
           while($sost4 = mysql_fetch_array($tmp4,MYSQL_ASSOC))
           {
             $result_strukt_name .= "&laquo;".$sost4['fio']."&raquo;, ";
             if($sost4['visible'] == 'show')
               {
                $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) $pass_root = "<img alt='picture' src='../img/active.png' height='16' width='16' align='top' />";
                    else $pass_root = "<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>";

                $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_tmp = $result_iskh2['p_tmp'];
                   $cls_frm = "<fieldset class='zayavka_view' >";
                }
                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) $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_iskh = "SELECT `p_tmp` FROM `tbl_p_tmp` WHERE `usr_id` = '".$result2['login_id']."' AND stat = '2' 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'];
                        $cls_frm = "<fieldset class='zayavka_view' >";
                  }

               $query_iskh_p = "SELECT
                   tbl_pass_keep.mail_form,
                   tbl_pass_keep.mail_pass_form,
                   tbl_pass_keep.dom_form,
                   tbl_pass_keep.dom_pass_form,
                   tbl_pass_keep.primechanie,
                   tbl_pass_keep.best_before,
                   tbl_pass_keep.data_create,
                   tbl_pass_keep.data_edt,
                   YEAR(tbl_pass_keep.data_create) AS cr_year,
                   MONTH(tbl_pass_keep.data_create) AS cr_month,
                   DAY(tbl_pass_keep.data_create) AS cr_day,
                   HOUR(tbl_pass_keep.data_create) AS cr_hour,
                   MINUTE(tbl_pass_keep.data_create) AS cr_minute,
                   SECOND(tbl_pass_keep.data_create) AS cr_second,
                   YEAR(tbl_pass_keep.best_before) AS bb_year,
                   MONTH(tbl_pass_keep.best_before) AS bb_month,
                   DAY(tbl_pass_keep.best_before) AS bb_day,
                   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
                   FROM `tbl_pass_keep`
                   WHERE `pas_id` = '".$sost4['pas_id']."'";
                    $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);
                        $key_usr = $result_iskh_p2['dom_pwd'];
                        $key_mail = $result_iskh_p2['mail_pwd'];
                        $login_usr = $result_iskh_p2['dom_login'];
                        $login_mail = $result_iskh_p2['mail_login'];

                        $date_day = $result_iskh_p2['cr_day'];
                        $date_month = $result_iskh_p2['cr_month'];
                        $date_year = $result_iskh_p2['cr_year'];
                        $date_time = $result_iskh_p2['cr_hour'].":".$result_iskh_p2['cr_minute'].":".$result_iskh_p2['cr_second'];
                        $year = $TEXT['year'];
                        if($result_iskh_p2['cr_year'] == "" || $result_iskh_p2['cr_year'] == "0") $data_r = "---";
                            else $data_r = $date_day." ".$month[$date_month]." ".$date_year." ".$year." ".$date_time;

                        $date_day3 = $result_iskh_p2['bb_day'];
                        $date_month3 = $result_iskh_p2['bb_month'];
                        $date_year3 = $result_iskh_p2['bb_year'];
                        if($result_iskh_p2['bb_year'] == "" || $result_iskh_p2['bb_year'] == "0") $data_r3 = "";
                          else $data_r3 = "<span class='autor'>".$TEXT['pass-bb'].": </span><span class='data'>".$date_day3." ".$month[$date_month3]." ".$date_year3." ".$year." 00:00:00</span>";

                       if($result_iskh_p2['bb_year'] == "" || $result_iskh_p2['bb_year'] == "0000") $bb_year = "&nbsp;";
                        else $bb_year = "<div class='tips_tread_drop'><table align='right' class='tipsprim' border='0' width='35%' cellpadding='0' cellspacing='0'><tr class='databb'><td><span class='autor'>".$TEXT['pass-bb'].": </span><span class='data'>".$data_r3."</span></td></tr></table></div>";

            if($_POST['print_item'] == 1) $print_ch = "checked";
             else
             {
              if($sost4['pas_id'] == $_POST['pas_id']) $print_ch = "checked";
               else $print_ch = "";
             }
             echo "<tr>
              <td></td>
              <td colspan=3 >";
              echo $cls_frm;
             echo " <legend align='left' >".$sost4['fio']."</legend>
               <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>";
             if(!empty($login_usr) || !empty($key_usr)) echo "
                <tr>
                  <td>";
                  if(!empty($login_usr)) echo "<span class='autor'>".rep_back_lower($result_iskh_p2['dom_form']).": </span><span class='support'>".rep_back_lower($login_usr)."</span><br />";
                  if(!empty($key_usr)) echo "<span class='autor'>".rep_back_lower($result_iskh_p2['dom_pass_form']).": </span><span class='support'>".$key_usr."</span><hr align='left' width='30%' />";
             if(!empty($login_usr) || !empty($key_usr)) echo "</td>
                  <td>".$bb_year."</td>
                </tr>";
             if(!empty($login_mail) || !empty($key_mail)) echo "<tr>
                  <td>";
                  if(!empty($login_mail)) echo "<span class='autor'>".rep_back_lower($result_iskh_p2['mail_form']).": </span><span class='support'>".rep_back_lower($login_mail)."</span><br />";
                  if(!empty($key_mail)) echo "<span class='autor'>".rep_back_lower($result_iskh_p2['mail_pass_form']).": </span><span class='support'>".$key_mail."</span><hr align='left' width='30%' />";
            if(!empty($login_mail) || !empty($key_mail)) echo "</td>
                  <td>&nbsp;</td>
                </tr>";
// disabled 17.05.2014 //
//             if($result_iskh_p2['dom_login'] !== "NULL" || $result_iskh_p2['dom_login'] !== "") echo "<tr>
//                  <td>
//                  <span class='autor'>".$TEXT['support34'].": </span><span class='support'>".$login_usr."</span><br />
//                  <span class='autor'>".$TEXT['install-pswd'].": </span><span class='support'>".$key_usr."</span><hr align='left' width='30%' />
//                  </td>
//                  <td></td>
//                </tr>";
//             if($result_iskh_p2['mail_login'] !== "NULL" || $result_iskh_p2['mail_login'] !== "") echo "<tr>
//                  <td>
//                  <span class='autor'>".$TEXT['support34']." (e-mail): </span><span class='support'>".$login_mail."</span><br />
//                  <span class='autor'>".$TEXT['install-pswd']." (e-mail): </span><span class='support'>".$key_mail."</span><hr align='left' width='30%' />
//                  </td>
//                  <td>&nbsp;</td>
//                </tr>";
/////////////////////////
             if($result_iskh_p2['primechanie'] !== "") echo "<tr><td colspan='2' class='meetdesc' ><span class='news3'>".$TEXT['know-prim']."&#58;</span><br /><span class='support'>".nl2br($result_iskh_p2['primechanie'])."</span></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
             echo "<tr>
                  <td class='autor'></td>
                  <td class='data'><span class='autor'>".$TEXT['pass-data1'].": </span><span class='data'>".$data_r."</span></td>
                </tr>";
             echo "<tr>
                  <td class='autor'></td>
                  <td class='data'>".$data_r3."</td>
                </tr>";
             echo "</table></fieldset>";
       echo "</td><td></td>
             </tr>";
            }
            ?>
             <tr>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
             </tr>
            </table>
           <?php
         }
     }
    }
   }
  }

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['pass-log'];
  $what = $TEXT['pass-log8'].substr($result_strukt_name,0,-2);
  $who = $result2['fullname'];
  //*************************************
  $query2 = mysql_query("INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')");
?>
</body>
</html>
