<?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-title2'];
  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" />
  </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(strlen($_GET['pas_str_id'])>11) puterror2($TEXT['error-zhurn2']);
  if(!empty($_GET['pas_str_id']))
   {
    $tmp_pas_str_id = "&amp;pas_str_id=".$_GET['pas_str_id']."";
    $old_pas_str_id = $_GET['pas_str_id'];
    if($_POST['koren'] == "on")
    {
      $koren = "";
      $koren_check = "checked";
      $ord = "tbl_pass_keep.fio ASC, tbl_pass_keep.data_create DESC";
    }
     else
     {
       $koren = " AND tbl_pass_keep.pas_str_id='".$_GET['pas_str_id']."'";
       $ord = "tbl_pass_keep.fio ASC, tbl_pass_keep.data_create DESC";
     }
   }
   elseif(!empty($_POST['pas_str_id']))
   {
    $tmp_pas_str_id = "&amp;pas_str_id=".$_GET['pas_str_id']."";
    $old_pas_str_id = $_POST['pas_str_id'];
    if($_POST['koren'] == "on")
    {
     $koren = "";
     $koren_check = "checked";
     $ord = "tbl_pass_keep.fio ASC, tbl_pass_keep.data_create DESC";
    }
     else
     {
       $koren = " AND tbl_pass_keep.pas_str_id='".$_POST['pas_str_id']."'";
       $ord = "tbl_pass_keep.fio ASC, tbl_pass_keep.data_create DESC";
     }
   }
   else
   {
     $koren = "";
     $ord = "tbl_pass_keep.fio ASC, tbl_pass_keep.data_create DESC";
     if($_GET['koren'] == "on" || $_POST['koren'] == "on") $koren_check = "checked";
   }

  if(strlen($_GET['k'])>8) puterror2($TEXT['error-paging1']);
  if(empty($_GET['k'])) $_GET['k']=0;
  $stop_r = $_GET['k'];
  if($stop_r == 0) $lim_ogr = "20";
   else $lim_ogr = $stop_r.",20";

  $ktblvis = $stop_r+20;
  $str = $ktblvis/20;

  if(empty($_POST['search'])) $_POST['search'] = $_GET['search'];
  if(empty($_POST['typepar'])) $_POST['typepar'] = $_GET['typepar'];

  if(!empty($_POST['search'])) {
   $tmp_srch = "&amp;search=".$_POST['search']."";
   $tmp_tppr = "&amp;typepar=".$_POST['typepar']."";
  } else {
     $tmp_srch = "";
     $tmp_tppr = "";
  }

  if(strlen($_POST['search'])>100) puterror2($TEXT['search-err2']);
  if(strlen($_POST['typepar'])>10) puterror2($TEXT['search-err3']);
  $_POST['search'] = rep($_POST['search']);
  $_POST['typepar'] = rep($_POST['typepar']);

  if($_GET['korzina'] == "on" && empty($_POST['search']))
  {
   $korz = "AND tbl_pass_keep.korzina = 1";
   $tmp_korz = "&amp;korzina=on";
  }
   elseif($_GET['korzina'] == "" && !empty($_POST['search']))
    {
     $korz = "";
     $tmp_korz = "";
     }
   else
    {
     $korz = "AND tbl_pass_keep.korzina = 0";
     $tmp_korz = "";
     }

if($_GET['overdue'] == "on") {
  $overdue_q = " AND tbl_pass_keep.best_before < NOW() AND tbl_pass_keep.best_before != '0000-00-00' ";
  $overdue_ref = "&amp;overdue=on";
}
else
  {
   $overdue_q = "";
   $overdue_ref = "";
  }

$query_tmp_s1 = "SELECT `p_tmp` FROM `tbl_p_tmp` WHERE `usr_id` = '".$result2['login_id']."' AND stat = '1' LIMIT 1";
  $result_tmp_s1 = mysql_query($query_tmp_s1);
    if(!$result_tmp_s1) puterror2($TEXT['error-tbl53']);
     $result_tmp_s12 = mysql_fetch_array($result_tmp_s1,MYSQL_ASSOC);
       $kfr_tmp_s1 = trim($result_tmp_s12['p_tmp']);

$query_tmp_s2 = "SELECT `p_tmp` FROM `tbl_p_tmp` WHERE `usr_id` = '".$result2['login_id']."' AND stat = '2' LIMIT 1";
  $result_tmp_s2 = mysql_query($query_tmp_s2);
    if(!$result_tmp_s2) puterror2($TEXT['error-tbl53']);
     $result_tmp_s22 = mysql_fetch_array($result_tmp_s2,MYSQL_ASSOC);
       $kfr_tmp_s2 = trim($result_tmp_s22['p_tmp']);

if($result2['administrator'] == 1) {
 $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_m = "<img alt='picture' src='../img/active.png' height='16' width='16' align='top' />";
     else $pass_root_m = "<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>";
} else $pass_root_m = "";

 $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_m = "<img alt='picture' src='../img/active.png' height='16' width='16' align='top' />";
     else $pass_user_m = "<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['administrator'] == 1) $action = "";
 else $action = " AND tbl_pass_keep.visible = 'show' ";

    switch($_POST['typepar'])
      {
      case 1: //сквозной
      {
        if($result2['administrator'] == 1) {
        if($kfr_tmp_s1 == "" && $kfr_tmp_s2 == "") $action = " AND (LOWER(tbl_pass_keep.fio) LIKE LOWER('%".$_POST['search']."%') OR LOWER(tbl_pass_keep.primechanie) LIKE LOWER('%".$_POST['search']."%'))";
        if($kfr_tmp_s1 !== "" && $kfr_tmp_s2 == "") $action = "AND tbl_pass_keep.visible = 'show'  AND (LOWER(tbl_pass_keep.fio) LIKE LOWER('%".$_POST['search']."%') OR LOWER(tbl_pass_keep.primechanie) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.dom_lgn,'".$kfr_tmp_s1."')) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.mail_lgn,'".$kfr_tmp_s1."')) LIKE LOWER('%".$_POST['search']."%'))";
        if($kfr_tmp_s1 == "" && $kfr_tmp_s2 !== "") $action = "AND tbl_pass_keep.visible = 'hide'  AND (LOWER(tbl_pass_keep.fio) LIKE LOWER('%".$_POST['search']."%') OR LOWER(tbl_pass_keep.primechanie) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.dom_lgn,'".$kfr_tmp_s2."')) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.mail_lgn,'".$kfr_tmp_s2."')) LIKE LOWER('%".$_POST['search']."%'))";
        if($kfr_tmp_s1 !== "" && $kfr_tmp_s2 !== "") $action = " AND (LOWER(tbl_pass_keep.fio) LIKE LOWER('%".$_POST['search']."%') OR LOWER(tbl_pass_keep.primechanie) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.dom_lgn,'".$kfr_tmp_s2."')) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.mail_lgn,'".$kfr_tmp_s2."')) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.dom_lgn,'".$kfr_tmp_s1."')) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.mail_lgn,'".$kfr_tmp_s1."')) LIKE LOWER('%".$_POST['search']."%')) ";
        } else {
           if($kfr_tmp_s1 !== "") $action = "AND tbl_pass_keep.visible = 'hide'  AND (LOWER(tbl_pass_keep.fio) LIKE LOWER('%".$_POST['search']."%') OR LOWER(tbl_pass_keep.primechanie) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.dom_lgn,'".$kfr_tmp_s1."')) LIKE LOWER('%".$_POST['search']."%') OR LOWER(AES_DECRYPT(tbl_pass_keep.mail_lgn,'".$kfr_tmp_s1."')) LIKE LOWER('%".$_POST['search']."%'))";
            else $action = "AND tbl_pass_keep.visible = 'hide' AND (LOWER(tbl_pass_keep.fio) LIKE LOWER('%".$_POST['search']."%') OR LOWER(tbl_pass_keep.primechanie) LIKE LOWER('%".$_POST['search']."%'))";
          }
      }
      break;
      case 2: //название(ФИО)
      $action = " AND LOWER(tbl_pass_keep.fio) LIKE LOWER('%".$_POST['search']."%')";
      break;
      case 3: //примечание
      $action = " AND LOWER(tbl_pass_keep.primechanie) LIKE LOWER('%".$_POST['search']."%')";
      break;
      case 4: //дата создания
      $action = " AND tbl_pass_keep.data_create LIKE ('".$_POST['search']."%')";
      break;
      case 5: //дата изменения
      $action = " AND tbl_pass_keep.data_edt LIKE ('".$_POST['search']."%')";
      break;
      }

   // Хлебные крошки Breadcrumbs
   if(!empty($_GET['pas_str_id']))
   {
   $resourcebr = "SELECT parent, pas_str_id, strukt_name FROM tbl_pass_strukt WHERE pas_str_id=".$_GET['pas_str_id']."";
    $resultbr=mysql_query($resourcebr);
     $result_bread=mysql_fetch_array($resultbr);

   $item_id = $_GET['pas_str_id'];
   $item_par = $result_bread['parent'];
   $item_name = "<a class='news3' href=pass_keep.php?pas_str_id=".$item_id.">".$result_bread['strukt_name']."</a>";

   while($item_par != 0)
    {
    $resourcebr2 = "SELECT parent, pas_str_id, strukt_name FROM tbl_pass_strukt WHERE pas_str_id=".$item_par."";
    $resultbr2=mysql_query($resourcebr2);
     $num_br = mysql_num_rows($resultbr2);
     if($num_br > 0)
     {
     $result_bread2=mysql_fetch_array($resultbr2);
     $item_id = $result_bread2['pas_str_id'];
     $item_par = $result_bread2['parent'];
     $item_name = "<a class='news3' href=pass_keep.php?pas_str_id=".$item_id.">".$result_bread2['strukt_name']."</a> &#187; ".$item_name;
     }
    }
   }
   //echo $item_name;
   if($_GET['korzina'] == "on") $item_name = "<span class='news3'>".$TEXT['pass-trash']."";
   if($_POST['typepar'] == 1) $item_name = "<span class='news3'>".$TEXT['top-search']."";
  // конец хлебных крошек

  if($_POST['typepar'] == 1) {
   $srch_tre_res = "";
   $srch_tre = "SELECT pas_str_id, strukt_name FROM tbl_pass_strukt WHERE LOWER(strukt_name) LIKE LOWER('%".$_POST['search']."%')";
    $resul_tre=mysql_query($srch_tre);
     while($result_tre=mysql_fetch_array($resul_tre))
     {
       $srch_tre_res .= "OR tbl_pass_keep.pas_str_id=".$result_tre['pas_str_id']." ";
     }

   $type_chk1 = "checked";
   $type_chk2 = "";
   $type_chk3 = "";
   $type_chk4 = "";
   $type_chk5 = "";
  }
  elseif($_POST['typepar'] == 2) {
   $type_chk1 = "";
   $type_chk2 = "checked";
   $type_chk3 = "";
   $type_chk4 = "";
   $type_chk5 = "";
  }
  elseif($_POST['typepar'] == 3) {
   $type_chk1 = "";
   $type_chk2 = "";
   $type_chk3 = "checked";
   $type_chk4 = "";
   $type_chk5 = "";
  }
  elseif($_POST['typepar'] == 4) {
   $type_chk1 = "";
   $type_chk2 = "";
   $type_chk3 = "";
   $type_chk4 = "checked";
   $type_chk5 = "";
  }
  elseif($_POST['typepar'] == 5) {
   $type_chk1 = "";
   $type_chk2 = "";
   $type_chk3 = "";
   $type_chk4 = "";
   $type_chk5 = "checked";
  }
  else {
   $type_chk1 = "";
   $type_chk2 = "checked";
   $type_chk3 = "";
   $type_chk4 = "";
   $type_chk5 = "";
  }

?>
<form action=pass_keep.php name='rprt' method=post>
<table class="tabledata" border="0" cellpadding="2" cellspacing="0" width="100%">
<tr align="center">
  <td>
    <table width=100% class="topheader" border="0" cellspacing="3">
     <tr align="center" valign="middle">
     <td align="left" width="32px"><?php echo $pass_user_m; ?><?php echo $pass_root_m; ?></td>
     <td align="right">
         <input class="inputsearch" size=30 maxlength=30 type=text name=search title="<?php echo $TEXT['search-btn-title']; ?>" value="<?php echo $_POST['search']; ?>" >&nbsp;<input type=submit value='<?php echo $TEXT['search-btn']; ?>'>
     </td>
     </tr>
     <tr>
         <td align="left" width="32px"></td>
         <td align="right" class="menu">
         <input type=hidden name=pas_str_id value='<?php echo $old_pas_str_id; ?>' />
         <input type=checkbox name=koren <?php echo $koren_check; ?> /><?php echo $TEXT['zhurn-search2']; ?>
         <input type=radio name=typepar value=1 <?php echo $type_chk1; ?> /><?php echo $TEXT['zhurn-search1']; ?>
         <input type=radio name=typepar value=2 <?php echo $type_chk2; ?> /><?php echo $TEXT['search-nazv']; ?>
         <input type=radio name=typepar value=3 <?php echo $type_chk3; ?> /><?php echo $TEXT['know-prim']; ?>
         <input type=radio name=typepar value=4 <?php echo $type_chk4; ?> /><?php echo $TEXT['pass-data1']; ?>
         <input type=radio name=typepar value=5 <?php echo $type_chk5; ?> /><?php echo $TEXT['pass-data2']; ?>
         <script type="text/javascript" language="JavaScript">
	var o_cal = new tcal ({
		// form name
		'formname': 'rprt',
		// input name
		'controlname': 'search'
	});
	</script>
       </td>
     </tr>
    </table>
</td>
</tr>
<tr>
  <td>
    <table border="0" width="86%" cellpadding="0" cellspacing="0" align="left" class="formainbread">
     <tr><td></td><td></td><td></td></tr>
     <tr>
       <td></td>
       <td class="newsdesch">&nbsp;&nbsp;<a class='news3' href=pass_keep.php><?php echo $TEXT['zhurn-path']; ?></a><?php echo $item_name; ?></td>
       <td></td>
     </tr>
     <tr><td></td><td></td><td></td></tr>
    </table>
    <table border="0" width="11%" cellpadding="0" cellspacing="0" align="right" class="formainbtnpass">
     <tr><td></td><td></td><td></td><td></td></tr>
     <tr>
       <td></td>
       <td>&nbsp;<img class="formainimg" alt="add" src="../img/add.png" /></td>
       <td class="newsdesch">&nbsp;<a href="pass_addform.php?pas_str_id=<?php echo $_GET['pas_str_id']; ?>" class="news3" title="<?php echo $TEXT['zhurn-izm-add-title']; ?>"><?php echo $TEXT['btn_add']; ?></a></td>
       <td></td>
     </tr>
     <?php
     if(!empty($_GET['pas_id'])) echo "<tr><td></td><td>&nbsp;<img class='export' alt='export' src='../img/add2.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_addform_plus.php?pas_id=".$_GET['pas_id']."' class='news3' title='".$TEXT['zhurn-izm-add-title'].$TEXT['pass-plus']."'>".$TEXT['btn_add']."+</a></td><td></td></tr>";
     if($result2['administrator'] == 1)
     {
     $query_count_tmp = mysql_query("SELECT COUNT(ptmp_id) FROM tbl_p_tmp WHERE usr_id = '".$result2['login_id']."' AND stat = '1' ");
       $coun_rows_tmp1 = mysql_result($query_count_tmp, 0);
       $pass_rows1 = $coun_rows_tmp1;

     $query_count_tmp = mysql_query("SELECT COUNT(ptmp_id) FROM tbl_p_tmp WHERE usr_id = '".$result2['login_id']."' AND stat = '2' ");
       $coun_rows_tmp2 = mysql_result($query_count_tmp, 0);
       $pass_rows2 = $coun_rows_tmp2;

     if($coun_rows_tmp1 > 0 && $coun_rows_tmp2 > 0) 
     {
       echo "<tr><td></td><td>&nbsp;<img class='export' alt='export' src='../img/export.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_export.php?pas_str_id=".$_GET['pas_str_id']."' class='news3' title='".$TEXT['pass-exp-tit']."'>".$TEXT['pass-exp']."</a></td><td></td></tr>";
       echo "<tr><td></td><td>&nbsp;<img class='import' alt='import' src='../img/import.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_impform.php?pas_str_id=".$_GET['pas_str_id']."' class='news3' title='".$TEXT['pass-imp-tit']."'>".$TEXT['pass-imp']."</a></td><td></td></tr>";
       echo "<tr><td></td><td>&nbsp;<img class='tospr' alt='import' src='../img/logo2.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_exporttosprform.php?pas_str_id=".$_GET['pas_str_id']."' class='news3' title='".$TEXT['global-tospr-title']."'>".$TEXT['global-tospr']."</a></td><td></td></tr>";
       echo "<tr><td></td><td>&nbsp;<img class='hide' alt='change group' src='../img/pass-visible-off.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_show_hide.php?pas_str_id=".$_GET['pas_str_id']."&amp;show=off&amp;edit=off&amp;k=".$stop_r."' class='news3' title='".$TEXT['pass-sh-tit']."'>".$TEXT['meet-hide']."</a></td><td></td></tr>";
       echo "<tr><td></td><td>&nbsp;<img class='vis-only' alt='change group' src='../img/pass-visible-on.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_show_hide.php?pas_str_id=".$_GET['pas_str_id']."&amp;show=on&amp;edit=off&amp;k=".$stop_r."' class='news3' title='".$TEXT['pass-sh-tit1']."'>".$TEXT['meet-show']."</a></td><td></td></tr>";
       echo "<tr><td></td><td>&nbsp;<img class='vis-edit' alt='change group' src='../img/pass-visible-on2.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_show_hide.php?pas_str_id=".$_GET['pas_str_id']."&amp;show=on&amp;edit=on&amp;k=".$stop_r."' class='news3' title='".$TEXT['pass-sh-tit2']."'>".$TEXT['meet-show']."</a></td><td></td></tr>";
       $pass_to_spr_tmp = "1";
     }

     if($coun_rows_tmp2 > 0) echo "<tr><td></td><td>&nbsp;<img class='pass-adm' alt='change pass' src='../img/pass-adm.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_change_rootkfr_form.php' class='news3' title='".$TEXT['pass-ch-adm-tit']."'>".$TEXT['pass-ch-adm']."</a></td><td></td></tr>";
     if($coun_rows_tmp1 > 0) echo "<tr><td></td><td>&nbsp;<img class='pass-mast' alt='change pass' src='../img/pass16.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_change_mastkfr_form.php' class='news3' title='".$TEXT['pass-ch-mast-tit']."'>".$TEXT['pass-ch-adm']."</a></td><td></td></tr>";
     if(!empty($_GET['pas_str_id'])) echo "<tr><td></td><td>&nbsp;<img class='erase' alt='erase' src='../img/draw-eraser.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_eraseform.php?pas_str_id=".$_GET['pas_str_id']."' class='news3' title='".$TEXT['pass-erase-tit']."'>".$TEXT['pass-erase']."</a></td><td></td></tr>";
     if(!empty($_GET['pas_str_id'])) echo "<tr><td></td><td>&nbsp;<img class='search' alt='erase' src='../img/search_in_spr.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_search.php?pas_str_id=".$_GET['pas_str_id']."' class='news3' title='".$TEXT['pass-search-tit']."'>".$TEXT['pass-search']."</a></td><td></td></tr>";

     $query_count_tmp = mysql_query("SELECT COUNT(pas_id) FROM tbl_pass_keep WHERE korzina = 1");
       $coun_rows_tmp = mysql_result($query_count_tmp, 0);
         if($coun_rows_tmp > 0) echo "<tr><td></td><td>&nbsp;<img class='formainimg' alt='trash' src='../img/trash.png' /></td><td class='newsdesch'>&nbsp;<a href='pass_keep.php?korzina=on' class='news3' title='".$TEXT['pass-trash']."'>".$TEXT['pass-trash']."</a></td><td></td></tr>";

     $query_count_overdue = mysql_query("SELECT COUNT(pas_id) FROM `tbl_pass_keep` WHERE `korzina` = 1 AND `best_before` < NOW() AND `best_before` != '0000-00-00' ");
       $coun_rows_overdue = mysql_result($query_count_overdue, 0);
         if($coun_rows_overdue > 0)
         {
          echo "<tr><td></td><td class='newsdesch' colspan='3'><a href='pass_keep.php?korzina=on&amp;overdue=on' class='news3' title=''>".$TEXT['pass-overdue']."</a></td></tr>";
          $overdue_other = "...";
          if($coun_rows_overdue > 7) $overdue_many = "<tr><td></td><td class='overdue' colspan='3'>&nbsp;&rArr; ".$overdue_other."</td></tr>";
           else $overdue_many = "";

          $query_overdue = "SELECT `pas_id`, SUBSTRING(fio,1,16) AS fio_over FROM `tbl_pass_keep` WHERE `korzina` = 1 AND `best_before` < NOW() AND `best_before` != '0000-00-00' ORDER BY `best_before` LIMIT 7";
            $tmp_overdue = mysql_query($query_overdue);
              if(!$tmp_overdue) puterror2(mysql_error());
                while($overdue = mysql_fetch_array($tmp_overdue,MYSQL_ASSOC))
                {
                  echo "<tr><td></td><td colspan='3'>&nbsp;<a href='pass_keep.php?korzina=on&amp;overdue=on&amp;pas_id=".$overdue['pas_id']."' class='overdue' title=''>".$overdue['fio_over'].$overdue_other."</a></td></tr>";
                }
           echo $overdue_many;
         }
     }
     ?>
     <tr><td></td><td></td><td></td><td></td></tr>
    </table>
<?php
  $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_pass_keep.korzina,
    tbl_pass_keep.pic_tr,
    IF((`best_before` < NOW() AND `best_before` != '0000-00-00'),'yes','no') AS over_color,
    tbl_logins.fullname,
    tbl_users.user_id,
    tbl_pass_strukt.strukt_name
    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
    LEFT JOIN tbl_pass_strukt ON tbl_pass_keep.pas_str_id=tbl_pass_strukt.pas_str_id
    WHERE tbl_pass_keep.pas_id != 0 ".$koren." ".$action.$srch_tre_res." ".$korz." ".$overdue_q."
    ORDER BY ".$ord." LIMIT $lim_ogr";
    $tmp4 = mysql_query($query4);
     if(!$tmp4) puterror2(mysql_error());
      $num_rows = mysql_num_rows($tmp4);
        if($num_rows == 0)
          {
           echo "<tr><td align='center' class='zagolovok'>";
           echo "<br />".$TEXT['zhurn-nodata']."";
           echo "</td></tr>";
          }
           else
           {
 ?>
  <tr>
      <td>
      <table border="0" cellpadding="0" cellspacing="0" class="formainpass">
       <tr>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
       </tr>
       <?php
           while($sost4 = mysql_fetch_array($tmp4,MYSQL_ASSOC))
           {
           if(!empty($_POST['search'])) {
            if($sost4['korzina'] == 1) $korz_srch_vis = "<img class='formainimg' alt='in trash' src='../img/trash.png' />";
             else  $korz_srch_vis = "";

            // Хлебные крошки Breadcrumbs
            $resourcebr = "SELECT parent, pas_str_id, strukt_name FROM tbl_pass_strukt WHERE pas_str_id=".$sost4['pas_str_id']."";
            $resultbr=mysql_query($resourcebr);
            $result_bread=mysql_fetch_array($resultbr);

            $item_id = $sost4['pas_str_id'];
            $item_par = $result_bread['parent'];
            $vetka = "<a class='support24' href=pass_keep.php?pas_str_id=".$item_id.">".$result_bread['strukt_name']."</a>";
            $vetka2 = $result_bread['strukt_name'];

            while($item_par != 0)
            {
            $resourcebr2 = "SELECT parent, pas_str_id, strukt_name FROM tbl_pass_strukt WHERE pas_str_id=".$item_par."";
            $resultbr2=mysql_query($resourcebr2);
            $num_br = mysql_num_rows($resultbr2);
            if($num_br > 0)
            {
            $result_bread2=mysql_fetch_array($resultbr2);
            $item_id = $result_bread2['pas_str_id'];
            $item_par = $result_bread2['parent'];
            $vetka = "<a class='support24' href=pass_keep.php?pas_str_id=".$item_id.">".$result_bread2['strukt_name']."</a> <span class='support24'> &#187; </span>".$vetka;
            $vetka2 = $result_bread2['strukt_name']." &#187; ".$vetka2;
            }
            }
            // конец хлебных крошек
            $vetka = " <span class='support24'>(".$TEXT['new-tag37']." &#187; </span>".$vetka."<span class='support24'>)</span>";
            $vetka2 = " ".$TEXT['new-tag37'].": ".$vetka2."";
               }
              else {
               $vetka = "";
               $vetka2 = "";
                }

            if(!empty($sost4['usr_id']) && $sost4['usr_id']!="-")
                {
                  if($sost4['pic_tr'] !== NULL && $sost4['pic_tr']!="")
                   {
                    $krit_image2 = "<td width= '32px' align='bottom'><a href=# onClick=\"window.open('../user.php?user_id=".$sost4['usr_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']."'><img alt='pic' src='../img/onway.png' /><img alt='pic' width= '16px' height='16px' src='".$sost4['pic_tr']."' /></a></td>";
                    $krit_image = "<a href=# onClick=\"window.open('../user.php?user_id=".$sost4['usr_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']."'><img alt='pic' src='../img/onway.png' /></a>";
                    }
                    else
                     {
                      $krit_image2 = "<td width= '16px' align='bottom'><a href=# onClick=\"window.open('../user.php?user_id=".$sost4['usr_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']."'><img alt='pic' src='../img/onway.png' /></a></td>";
                      $krit_image = "<a href=# onClick=\"window.open('../user.php?user_id=".$sost4['usr_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']."'><img alt='pic' src='../img/onway.png' /></a>";
                     }
                }
              else {
                  if($sost4['pic_tr'] !== NULL && $sost4['pic_tr']!="")
                   {
                    $krit_image2 = "<td width= '16px' align='right'><img alt='pic' width= '16px' height='16px' src='".$sost4['pic_tr']."' /></td>";
                    $krit_image = "";
                    }
                    else
                     {
                      $krit_image2 = "<td></td>";
                      $krit_image = "";
                     }
                  
              }

             if($sost4['visible'] == 'show') 
              {
                $uv = "&amp;uv=on";
                if($sost4['over_color'] == "yes") $usr_visible = "overduetbl";
                  else $usr_visible = "support24";
               }
               else 
                {
                 $uv = "&amp;uv=off";
                 if($sost4['over_color'] == "yes") $usr_visible = "overduetbl";
                  else $usr_visible = "support25";
                }

            if($result2['administrator'] == 1 && $_GET['korzina'] == "on") $edit = "<a href=pass_to_back.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;korzina=on&amp;k=".$stop_r.$uv." title='".$TEXT['pass-rest']."'><img alt='".$TEXT['pass-rest']."' src='../img/restore.png' height='16' width='16' align='top' /></a>";
            elseif($sost4['korzina'] == 1 && $result2['administrator'] == 1) $edit = "<a href=pass_to_back.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;korzina=on&amp;k=".$stop_r.$uv." title='".$TEXT['pass-rest']."'><img alt='".$TEXT['pass-rest']."' src='../img/restore.png' height='16' width='16' align='top' /></a>";
             elseif($sost4['mast_edt'] == 'yes' && $result2['master'] == 1) {
                  $edit = "<a href=pass_editform.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;k=".$stop_r.$uv." title='".$TEXT['pass-edt']."'> <img alt='".$TEXT['pass-edt']."' src='../img/edit.png' height='16' width='16' align='top' /></a>";
                  $edit_vis = "";
                  $edit_vis_yes = "";
                  }
             elseif($sost4['mast_edt'] == 'yes' && $result2['administrator'] == 1) {
                  $edit = "<a href=pass_editform.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;k=".$stop_r.$uv." title='".$TEXT['pass-edt']."'> <img alt='".$TEXT['pass-edt']."' src='../img/edit.png' height='16' width='16' align='top' /></a>";
                  $edit_vis = "<img alt='".$TEXT['pass-edt']."' src='../img/pass-visible-on2.png' height='16' width='16' align='top' />";
                  $edit_vis_yes = "";
                  }
                elseif($sost4['mast_edt'] == 'no' && $result2['administrator'] == 1 ) {
                    $edit = "<a href=pass_editform.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;k=".$stop_r.$uv." title='".$TEXT['pass-edt']."'> <img alt='".$TEXT['pass-edt']."' src='../img/edit.png' height='16' width='16' align='top' /></a>";
                    if($sost4['visible'] == 'show') {
                    $edit_vis = "";
                    $edit_vis_yes = "<img alt='".$TEXT['pass-edt']."' src='../img/pass-visible-on.png' height='16' width='16' align='top' />";
                    } else {
                       $edit_vis = "";
                       $edit_vis_yes = "";
                       }
                    }
                  else $edit = "<img alt='".$TEXT['pass-edt']."' src='../img/lock.png' height='16' width='16' align='top' />";

            if($result2['administrator'] == 1 && $_GET['korzina'] == "on") $delete = "<a href=pass_delete.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;korzina=on&amp;k=".$stop_r." title='".$TEXT['tbl-delete']."'><img alt='".$TEXT['tbl-delete']."' src='../img/drop.png' height='16' width='16' align='top' /></a>";
            elseif($result2['administrator'] == 1 && $sost4['korzina'] == 1) $delete = "<a href=pass_delete.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;korzina=on&amp;k=".$stop_r." title='".$TEXT['tbl-delete']."'><img alt='".$TEXT['tbl-delete']."' src='../img/drop.png' height='16' width='16' align='top' /></a>";
              elseif($result2['administrator'] == 1 && $_GET['korzina'] == "") $delete = "<a href=pass_to_korz.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;k=".$stop_r." title='".$TEXT['tbl-delete']."'><img alt='".$TEXT['tbl-delete']."' src='../img/delete_sm.png' height='16' width='16' align='top' /></a>";
                else $delete ="";

            if($result2['administrator'] == 1) {
                $pass_mail = "<a href=pass_mailform.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']."&amp;k=".$stop_r.$uv." title='".$TEXT['pass-invite']."'> <img alt='to e-mail' src='../img/mail-pass.png' height='16' width='16' align='top' /> </a>";
                if($pass_to_spr_tmp == "1") $pass_to_spr = "<a href=pass_exporttosprform.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']." title='".$TEXT['global-tospr-title']."'> <img alt='to tel-spr' src='../img/logo2.png' height='16' width='16' align='top' /> </a>";
                    else $pass_to_spr = "";
            }
            $print = "<a href=pass_printform.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$sost4['pas_str_id']." title='".$TEXT['print-vers']."'><img alt='".$TEXT['print-vers']."' src='../img/printer.png' height='16' width='16' align='top' /></a>";

                if($sost4['visible'] == 'hide' && $result2['master'] == 1 && $result2['administrator'] == 0)
               {

                }
                else
                {

            if($_GET['pas_id'] == $sost4['pas_id'])
            {
             echo "<tr>
              <td></td>
              <td></td>
              <td colspan=3 >";

             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>";
                    $kfr_tmp = $kfr_tmp_s1;
                    $cls_frm = "<fieldset class='zayavka' >";
                }
                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>";
                      $kfr_tmp = $kfr_tmp_s2;
                      $cls_frm = "<fieldset class='zayavka2' >";
                  }

               $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,
                   TIME(tbl_pass_keep.data_create) AS cr_hour,
                   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,
                   YEAR(tbl_pass_keep.data_edt) AS ed_year,
                   MONTH(tbl_pass_keep.data_edt) AS ed_month,
                   DAY(tbl_pass_keep.data_edt) AS ed_day,
                   TIME(tbl_pass_keep.data_edt) AS ed_hour,
                   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_logins.fullname
                   FROM `tbl_pass_keep`
                   LEFT JOIN tbl_logins ON tbl_pass_keep.login_edt_id=tbl_logins.login_id
                   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'];
                        $result_primechanie = rep_back_lower($result_iskh_p2['primechanie']);
                        $result_primechanie = str_replace("  ","&nbsp;&nbsp;",$result_primechanie);

                        $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'];
                        $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_day2 = $result_iskh_p2['ed_day'];
                        $date_month2 = $result_iskh_p2['ed_month'];
                        $date_year2 = $result_iskh_p2['ed_year'];
                        $date_time2 = $result_iskh_p2['ed_hour'];
                        if($result_iskh_p2['ed_year'] == "" || $result_iskh_p2['ed_year'] == "0000") $data_r2 = "---";
                         else $data_r2 = $date_day2." ".$month[$date_month2]." ".$date_year2." ".$year." ".$date_time2;

                        $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'] == "0000") $bb_year = "&nbsp;";
                         else $bb_year = "<div class='tips_tread_drop'><table align='right' class='tipsprim' border='0' width='45%' cellpadding='0' cellspacing='0'><tr class='databb'><td><span class='autor'>".$TEXT['pass-bb'].": </span><span class='data'>".$date_day3." ".$month[$date_month3]." ".$date_year3." ".$year."</span></td></tr></table></div>";

             echo $cls_frm;
             echo "<legend align='left' >".$krit_image."".$pass_root."".rep_back_lower($sost4['fio'])."</legend>
               <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>
                <tr>
                  <td></td><td class='data'>".$edit_vis.$edit_vis_yes.$pass_to_spr.$pass_mail.$print.$edit.$delete."</td>
                </tr>";
             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>";
             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_primechanie)."</span></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
             echo "<tr><td class='autor' colspan=2>".$korz_srch_vis."".$vetka2."</td></tr>";
             echo "<tr>
                  <td class='autor'>".$TEXT['zhurn-autor'].$sost4['fullname']."</td>
                  <td class='data'><span class='autor'>".$TEXT['pass-data1'].": </span><span class='data'>".$data_r."</span></td>
                </tr>";
             if($result_iskh_p2['data_create'] !== $result_iskh_p2['data_edt'] && $data_r2 !== "---") echo "<tr>
                  <td class='autor'>".$TEXT['pass-editor'].$result_iskh_p2['fullname']."</td>
                  <td class='data'><span class='autor'>".$TEXT['pass-data2'].": </span><span class='data'>".$data_r2."</span></td>
                </tr>";
             echo "</table></fieldset>";
             echo "</td><td></td></tr>";
            }
            else
             {
             echo "<tr>
              <td></td>
              ".$zap_image."
              ".$krit_image2."
              <td class='newsdesch'>&nbsp;<a href='pass_keep.php?pas_id=".$sost4['pas_id'].$tmp_pas_str_id.$koren_tmp.$krt_str.$tmp_srch.$tmp_tppr.$tmp_korz.$overdue_ref."&amp;k=".$stop_r."' class='".$usr_visible."' title='".$TEXT['support14']."'>".rep_back_lower($sost4['fio'])."</a></td>
              <td width= '52px' class='data'>".$edit_vis.$edit.$delete."</td>
              <td></td>
             </tr>";
             }
             }
            }
            ?>
             <tr>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
             </tr>
            </table>
           <?php
         }
            ?>
   </td>
  </tr>
</table>
</form>
<form>
     <?php
       $query_count = mysql_query("SELECT COUNT(tbl_pass_keep.pas_id) FROM tbl_pass_keep WHERE tbl_pass_keep.pas_id != 0 ".$koren." ".$action." ".$korz." ".$overdue_q." ");
       $coun_rows = mysql_result($query_count, 0);
               $pag = $coun_rows/20;
               if($pag<=1) $pag = ceil($pag);
                else
                {
                 ?>
                  <table align="center" border="0" cellpadding="0" cellspacing="0" width="60%" >
                   <tr align="center">
                    <td>
                <?php
                $pag=ceil($pag);
                $strn = $str-5;
                if($strn<1) $strn=1;
                $strk = $str+5;
                for($i=$strn; $i<=$pag; $i++)
                 {
                  if($i<=$strk)
                  {
                    if($i==$str)
                    {
                      $k = $i*20-20;
                      $kvis=$k+20;
                      $nvis=$k;
                      echo $pg = " <a class='zagolovok' href='pass_keep.php?k=".$k.$tmp_pas_str_id.$koren_tmp.$krt_str.$tmp_srch.$tmp_tppr.$tmp_korz.$overdue_ref."' title='".$TEXT['zhurn-details2'].$nvis.$TEXT['zhurn-details1'].$kvis."'>".$i."</a>";
                    }
                    else
                    {
                    $k = $i*20-20;
                    $kvis=$k+20;
                    $nvis=$k;
                    echo $pg = " <a href='pass_keep.php?k=".$k.$tmp_pas_str_id.$koren_tmp.$krt_str.$tmp_srch.$tmp_tppr.$tmp_korz.$overdue_ref."' title='".$TEXT['zhurn-details2'].$nvis.$TEXT['zhurn-details1'].$kvis."'>[".$i."]</a>";
                    }
                  }
                 }
                 ?>
                    <select name='k' onchange=window.location.href=this.options[this.selectedIndex].value;>
                    <?php
                    for($j=1; $j<=$pag; $j++)
                    {
                     $k = $j*20-20;
                     if($k == $_GET['k']) echo "<option selected value=pass_keep.php?k=".$k.$tmp_pas_str_id.$koren_tmp.$krt_str.$tmp_srch.$tmp_tppr.$tmp_korz.$overdue_ref.">".$j."</option>";
                       else echo "<option value=pass_keep.php?k=".$k.$tmp_pas_str_id.$koren_tmp.$krt_str.$tmp_srch.$tmp_tppr.$tmp_korz.$overdue_ref.">".$j."</option>";
                    }
                    ?>
                    </select>
                    </td>
                   </tr>
                  </table>
                 <?php
                }
               ?>
</form>
</body>
</html>