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

  if(!isset($button)) $button = $TEXT['pass-exp'];
  if(!isset($action)) $action = "pass_exporttospr.php";

   if(empty($_GET['pas_str_id'])) puterror2($TEXT['meet-err-edit2']);
  if(strlen($_GET['pas_str_id'])>11) puterror2($TEXT['meet-err-edit3']);
  if(strlen($_GET['pas_id'])>11) puterror2($TEXT['meet-err-edit3']);
  if(strlen($_GET['k'])>8) puterror2($TEXT['error-zhurn15']);
  $old_pas_str_id = $_GET['pas_str_id'];
  $old_pas_id = $_GET['pas_id'];

   // Хлебные крошки Breadcrumbs
   $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,MYSQL_ASSOC);

   $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,MYSQL_ASSOC);
     $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;
  // конец хлебных крошек

?>
<table class="tabledata" align="center">
  <tr><td class="z1"><?php echo $titlepage; ?></td></tr>
  <tr><td class="help"><?php echo $helppage; ?></td></tr>
</table>
<br />
<table border="0" width="86%" cellpadding="0" cellspacing="0" align="center" 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>
<br />
<form enctype='multipart/form-data' name='form' action=<?php echo $action; ?> method=post>
<table class="table" align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr><td>
<fieldset class="filterr">
<legend align="left" title="<?php echo $TEXT['global-tospr-title2']; ?>"><span class='support'><?php echo $TEXT['global-tospr-title2']; ?></span></legend>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="zag2"><td class="support22"><?php echo $TEXT['search-org']; ?></td><td><select name="org_id">
    <?php
        $query4 = "SELECT * FROM `tbl_organizaciya` ORDER BY position";
        $organizaciya_tmp = mysql_query($query4);
          if(!$organizaciya_tmp) puterror2($TEXT['error-tbl7']);
              while($organizaciya = mysql_fetch_array($organizaciya_tmp,MYSQL_ASSOC))
                {
                 if($organizaciya['org_id'] == $_POST['org_id'])
                   {
                   $chk = "<option selected value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                   }
                 else $chk = "<option value=".$organizaciya['org_id'].">".$organizaciya['organizaciya']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="support22"><?php echo $TEXT['search-upr']; ?></td><td><select name="upr_id">
    <?php
        $query5 = "SELECT * FROM `tbl_upravlenie` ORDER BY upravlenie, position";
        $upravlenie_tmp = mysql_query($query5);
          if(!$upravlenie_tmp) puterror2($TEXT['error-tbl9']);
              while($upravlenie = mysql_fetch_array($upravlenie_tmp,MYSQL_ASSOC))
                {
                 $chk = "<option value=".$upravlenie['upr_id'].">".$upravlenie['upravlenie']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="support22"><?php echo $TEXT['search-otd']; ?></td><td><select name="otd_id">
    <?php
        $query6 = "SELECT * FROM `tbl_otdel` ORDER BY otdel, position";
        $otdel_tmp = mysql_query($query6);
          if(!$otdel_tmp) puterror2($TEXT['error-tbl8']);
              while($otdel = mysql_fetch_array($otdel_tmp,MYSQL_ASSOC))
                {
                 $chk = "<option value=".$otdel['otd_id'].">".$otdel['otdel']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="support22"><?php echo $TEXT['search-dol']; ?></td><td><select name="dol_id">
    <?php
        $query7 = "SELECT * FROM `tbl_dolzhnost` ORDER BY dolzhnost, position";
        $dolzhnost_tmp = mysql_query($query7);
          if(!$dolzhnost_tmp) puterror2($TEXT['error-tbl6']);
              while($dolzhnost = mysql_fetch_array($dolzhnost_tmp,MYSQL_ASSOC))
                {
                 $chk = "<option value=".$dolzhnost['dol_id'].">".$dolzhnost['dolzhnost']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="support22"><?php echo $TEXT['search-city']; ?></td><td><select name="city_id">
    <?php
        $query1 = "SELECT * FROM `tbl_city` ORDER BY city";
        $city_tmp = mysql_query($query1);
          if(!$city_tmp) puterror2($TEXT['error-tbl1']);
              while($city = mysql_fetch_array($city_tmp,MYSQL_ASSOC))
                {
		$chk = "<option value=".$city['city_id'].">".$city['city']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="support22"><?php echo $TEXT['search-street']; ?></td><td><select name="str_id">
    <?php
        $query2 = "SELECT * FROM `tbl_street` ORDER BY street";
        $street_tmp = mysql_query($query2);
          if(!$street_tmp) puterror2($TEXT['error-tbl3']);
              while($street = mysql_fetch_array($street_tmp,MYSQL_ASSOC))
                {
                 $chk = "<option value=".$street['str_id'].">".$street['street']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="support22"><?php echo $TEXT['search-home']; ?></td><td><select name="house_id">
    <?php
        $query3 = "SELECT * FROM `tbl_house` ORDER BY house DESC";
        $house_tmp = mysql_query($query3);
          if(!$house_tmp) puterror2($TEXT['error-tbl4']);
              while($house = mysql_fetch_array($house_tmp,MYSQL_ASSOC))
                {
                 $chk = "<option value=".$house['house_id'].">".$house['house']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="support22"><?php echo $TEXT['search-mail-dom']; ?></td><td><select name="dom_id">
    <?php
        $query = "SELECT * FROM `tbl_domain` ORDER BY domain";
        $domain_tmp = mysql_query($query);
          if(!$domain_tmp) puterror2($TEXT['error-tbl5']);
              while($domain = mysql_fetch_array($domain_tmp,MYSQL_ASSOC))
                {
		 $chk = "<option value=".$domain['dom_id'].">".$domain['domain']."";
                 echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="support22"><?php echo $TEXT['support34']; ?>:</td><td><span class="support"><input type=checkbox name=onepass><?php echo $TEXT['pass-use2pair']; ?></span></td></tr>
<tr><td class="support22"><?php echo $TEXT['izm-pos']; ?>:</td><td><span class="support"><input size=5 maxlength=5 type=text name=position value="100"/></span></td></tr>
</table>
</fieldset>
</td></tr>
</table>
<br />
<?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_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_str_id = '".$_GET['pas_str_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" cellpadding="0" cellspacing="0" align="center" class="formainpassprint">
       <tr>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
         <td></td>
       </tr>
       <tr>
         <td></td>
         <td></td>
         <?php
          if($_GET['print_item'] == 1)
           {
            echo "<td class='data'>".$TEXT['zhurn-print-all-no']."</td>";
            echo "<td width= '16px'><input type='checkbox' name=print_item checked onchange=window.location.href='pass_exporttosprform.php?print_item=0&amp;pas_str_id=".$_GET['pas_str_id']."&amp;pas_id=".$_GET['pas_id']."' /></td>";
           }
            else
            {
            echo "<td class='data'>".$TEXT['zhurn-print-all']."</td>";
            echo "<td width= '16px'><input type='checkbox' name=print_item onchange=window.location.href='pass_exporttosprform.php?print_item=1&amp;pas_str_id=".$_GET['pas_str_id']."&amp;pas_id=".$_GET['pas_id']."' /></td>";
            }
         ?>
         <td></td>
       </tr>
       <?php
           while($sost4 = mysql_fetch_array($tmp4,MYSQL_ASSOC))
           {
             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' >";
                }
                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='zayavka2' >";
                  }

               $query_iskh_p = "SELECT
                   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
                   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'];
                        $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'] == "0") $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'] == "0") $data_r3 = "---";
                          else $data_r3 = $date_day3." ".$month[$date_month3]." ".$date_year3." ".$year;

                       if($result_iskh_p2['bb_year'] == "" || $result_iskh_p2['bb_year'] == "0000-00-00" || $result_iskh_p2['bb_year'] == "0") $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>";

          /////
            if($_GET['print_item'] == 1) $print_ch = "checked";
             else 
             {
              if($sost4['pas_id'] == $_GET['pas_id']) $print_ch = "checked";
               else $print_ch = "";
             }
            $print_item_tmp = $sost4['pas_id'];
            
            if($_GET['pas_id'] == $sost4['pas_id'])
            {
             echo "<tr>
              <td></td>
              <td colspan=3 >";
             echo $cls_frm;
             echo " <legend align='left' >".$krit_image."".$pass_root."".$sost4['fio']."</legend>
               <table align='center' border='0' width='98%' cellpadding='0' cellspacing='0'>
                <tr>
                  <td>&nbsp;</td><td class='data'><input type='checkbox' name=printitem[".$print_item_tmp."] ".$print_ch." /></td>
                </tr>";
             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>".$bb_year."</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'>".$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']) echo "<tr>
                  <td class='autor'>".$TEXT['pass-editor'].$sost4['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>
              <td width= '16px' align='bottom'>".$krit_image."</td>
              <td class='newsdesch'>&nbsp;<a href='pass_printform.php?pas_id=".$sost4['pas_id']."&amp;pas_str_id=".$_GET['pas_str_id'].$tmp_pas_str_id.$koren_tmp.$krt_str.$tmp_srch.$tmp_tppr.$tmp_korz."' class='news3' title='".$TEXT['support14']."'>".$sost4['fio']."</a></td>
              <td class='data'><input type='checkbox' name=printitem[".$print_item_tmp."] ".$print_ch." /></td>
              <td></td>
             </tr>";
             }
            }
            ?>
             <tr>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
             </tr>
            </table>
           <?php
         }
            ?>
<table border="0" width="90%" cellpadding="0" cellspacing="0"  align="center">
  <tr align="right"><td>
  <input type=hidden name=pas_str_id value='<?php echo $old_pas_str_id; ?>' />
  <input class="button" type=submit value='<?php echo $button; ?>' />
</td>
</tr>
</table>
</form>
</body>
</html>