<?php
  ///////////////////////////////////////////////////
  //Журнал изменений
  //2010 (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['know-izm'];
  $helppage = $TEXT['zhurn-print-tit'];

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

  ?>
  <title><?php echo $title; ?></title>
  <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 = "zhurn_print.php";

  if(empty($_GET['zh_str_id'])) puterror2($TEXT['error-zhurn1']);
  if(strlen($_GET['zh_str_id'])>11) puterror2($TEXT['error-zhurn2']);
  $_GET['s'] == 1;
?>
<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['know-izm']; ?></td></tr>
  <tr><td></td><td>&nbsp;</td></tr>
</table>
<br />
<?php
    $query4 = "SELECT
    tbl_bd_zhnaniy.*,
    YEAR(tbl_bd_zhnaniy.data) AS zhnan_year,
    MONTH(tbl_bd_zhnaniy.data) AS zhnan_month,
    DAY(tbl_bd_zhnaniy.data) AS zhnan_day,
    TIME(tbl_bd_zhnaniy.data) AS zhnan_hour,
    tbl_logins.fullname,
    tbl_kritichnost.pic_krit,
    tbl_kritichnost.kritichnost
    FROM tbl_bd_zhnaniy
    JOIN tbl_logins ON tbl_bd_zhnaniy.login_id=tbl_logins.login_id
    JOIN tbl_kritichnost ON tbl_bd_zhnaniy.krit_id=tbl_kritichnost.krit_id
    WHERE tbl_bd_zhnaniy.zhurn_id = ".$_GET['zhurn_id']."
    ORDER BY tbl_bd_zhnaniy.position, tbl_bd_zhnaniy.data ";
    $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
           {
         $sost4 = mysql_fetch_array($tmp4,MYSQL_ASSOC);

         if($_GET['s'] == 0) {
          $fon_img = "<a href=know_view.php?otkr=".$_GET['otkr']."&amp;zhurn_id=".$sost4['zhurn_id']."&amp;zh_str_id=".$sost4['zh_str_id']."&amp;s=1 title='".$TEXT['know-fon-add']."'><img class='tips_tread_drop' alt='".$TEXT['know-fon-add']."' src='../img/fon-est.png' height='16' width='16' align='top' /></a>";
          $fon = "zayavka_view";
          }
          else {
            $fon_img = "<a href=know_view.php?otkr=".$_GET['otkr']."&amp;zhurn_id=".$sost4['zhurn_id']."&amp;zh_str_id=".$sost4['zh_str_id']."&amp;s=0 title='".$TEXT['know-fon-clr']."'><img class='tips_tread_drop' alt='".$TEXT['know-fon-clr']."' src='../img/fon-clr.png' height='16' width='16' align='top' /></a>";
            $fon = "zayavka";
            }

         if($sost4['primechanie'] !== "" && $_GET['otkr'] == 1)
          {
           $primechanie = "<div class='tips_mesto_prim'><table class='tipsprim' width='200px'><tr><td><span class='newstips'>".$TEXT['know-prim']."&#058;</span></td></tr><tr><td>".nl2br($sost4['primechanie'])."</td></tr></table></div>";
           $img_cl = "<a href=know_view.php?s=".$_GET['s']."&amp;otkr=2&amp;zh_str_id=".$sost4['zh_str_id']."&amp;zhurn_id=".$sost4['zhurn_id']." title='".$TEXT['know-prim-close']."' ><img class='tips_mesto_prim_opener' alt='".$TEXT['know-prim-close']."' src='../img/zakrit.png' /></a>";
         }
         elseif($sost4['primechanie'] !== "" && $_GET['otkr'] == 2)
          {
           $primechanie = "<div class='tips_mesto_prim'><table class='tipsprim' width='200px'><tr><td><span class='newstips'>".$TEXT['know-prim']."&#058;</span></td></tr></table></div>";
           $img_cl = "<a href=know_view.php?s=".$_GET['s']."&amp;otkr=1&amp;zh_str_id=".$sost4['zh_str_id']."&amp;zhurn_id=".$sost4['zhurn_id']." title='".$TEXT['know-prim-open']."' ><img class='tips_mesto_prim_opener' alt='".$TEXT['know-prim-open']."' src='../img/otkrit.png' /></a>";
         }
          $sost4['zh_soobschenie'] = str_replace(":smile:","<img alt='picture' src='../img/smile.png' align=middle />",$sost4['zh_soobschenie']);
          $sost4['zh_soobschenie'] = str_replace(":tongue:","<img alt='picture' src='../img/tongue.png' align=middle />",$sost4['zh_soobschenie']);
          $sost4['zh_soobschenie'] = str_replace(":wink:","<img alt='picture' src='../img/wink.png' align=middle />",$sost4['zh_soobschenie']);
          $sost4['zh_soobschenie'] = str_replace(":wassat:","<img alt='picture' src='../img/wassat.png' align=middle />",$sost4['zh_soobschenie']);
          $sost4['zh_soobschenie'] = str_replace(":sad:","<img alt='picture' src='../img/sad.png' align=middle />",$sost4['zh_soobschenie']);
          $sost4['zh_soobschenie'] = str_replace(":crying:","<img alt='picture' src='../img/crying.png' align=middle />",$sost4['zh_soobschenie']);
          $sost4['zh_soobschenie'] = str_replace(":angry:","<img alt='picture' src='../img/angry.png' align=middle />",$sost4['zh_soobschenie']);
          $sost4['zh_soobschenie'] = str_replace("  ","&nbsp;&nbsp;",$sost4['zh_soobschenie']);
          $sost4['zh_soobschenie'] = rep_back($sost4['zh_soobschenie']);
          $sost4['zh_tema'] = rep_back($sost4['zh_tema']);

          $query5 = "SELECT
           tbl_know_prim.tr_id,
           tbl_know_prim.login_id AS tr_usr_login,
           tbl_know_prim.zh_primechanie,
           YEAR(tbl_know_prim.data) AS prim_year,
           MONTH(tbl_know_prim.data) AS prim_month,
           DAY(tbl_know_prim.data) AS prim_day,
           TIME(tbl_know_prim.data) AS prim_hour,
           tbl_logins.fullname
           FROM tbl_know_prim
           JOIN tbl_logins ON tbl_know_prim.login_id=tbl_logins.login_id
           WHERE tbl_know_prim.zhurn_id = ".$_GET['zhurn_id']."
           ORDER BY tbl_know_prim.data ";
           $tmp5 = mysql_query($query5);
             if(!$tmp5) puterror2(mysql_error());
              $num_rows2 = mysql_num_rows($tmp5);

           if($num_rows2 > 0)
           {
           ////////
           ?>
           <table border="0" width="95%" cellpadding="0" cellspacing="0"  align="center">
          <tr>
          <td align="right"><?php echo $primechanie; ?><?php echo $img_cl; ?></td>
          </tr>
          <?php
            if(!empty($sost4['pic_krit']) && $sost4['pic_krit']!="-") $krit_image = "<img alt='".$sost4['kritichnost']."' title='".$sost4['kritichnost']."' src='".$sost4['pic_krit']."' />";
              else $krit_image = $sost4['kritichnost'];

           $date_day = $sost4['prim_day'];
           $date_month = $sost4['prim_month'];
           $date_year = $sost4['prim_year'];
           $date_time = $sost4['prim_hour'];
           if($sost4['prim_year'] == "" || $sost4['prim_year'] == "0000") $data_r = "---";
            else $data_r = $date_day." ".$month[$date_month]." ".$date_year." ".$TEXT['year']." ".$date_time;

            if($_POST['print_item'] == 1) $print_ch = "checked";
             else
             {
              if($sost4['zhurn_id'] == $_POST['zhurn_id']) $print_ch = "checked";
               else $print_ch = "";
             }
             echo "<tr><td width='70%'  valign='top'>";

          if($result2['administrator'] == 1 || $result2['login_id'] == $sost4['login_id']) $drop_tr2 = "<a href=know_delete_tr.php?otkr=".$_GET['otkr']."&amp;zh_str_id=".$sost4['zh_str_id']."&amp;zhurn_id=".$sost4['zhurn_id']."&amp;all_tr=1 title='".$TEXT['tbl-delete']."' ><img class='tips_tread_drop' alt='".$TEXT['tbl-delete']."' src='../img/drop-all-tr.png' /></a>";
           else $drop_tr2 = "";

              ?>
             <fieldset class='<?php echo $fon; ?>' >
              <legend align="left" ><span class="temaprint"><?php echo $krit_image; ?>&nbsp;<?php echo $sost4['zh_tema']; ?></span></legend>
               <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>
                <tr>
                  <td colspan="2" align="right"><?php echo $fon_img; ?>&nbsp;<?php echo $drop_tr2; ?></td>
                </tr>
                <tr>
                  <td colspan="2" class="support" width="100%"><?php echo nl2br($sost4['zh_soobschenie']); ?></td>
                </tr>
                <tr>
                  <td colspan="2" class="support" >&nbsp;</td>
                </tr>
                <tr>
                  <td class="autor"><?php echo $TEXT['zhurn-autor'].$sost4['fullname']; ?></td>
                  <td class="data tblgrad" width="25%"><?php echo $data_r; ?>&nbsp;<a href=know_addform_zam.php?otkr=<?php echo $_GET['otkr']; ?>&amp;zh_str_id=<?php echo $sost4['zh_str_id']; ?>&amp;zhurn_id=<?php echo $sost4['zhurn_id']; ?> title='<?php echo $TEXT['know-zam']; ?>' ><img alt='picture' src='../img/izmenit.png' align=top /></a></td>
                </tr>
              </table>
            </fieldset>
            <td width='25%' valign='top'>
            <?php
           while($sost5 = mysql_fetch_array($tmp5,MYSQL_ASSOC))
           {
           $date_day2 = $sost5['prim_day'];
           $date_month2 = $sost5['prim_month'];
           $date_year2 = $sost5['prim_year'];
           $date_time2 = $sost5['prim_hour'].":".$sost5['prim_minute'].":".$sost5['prim_second'];
           $year = $TEXT['year'];
           if($sost5['prim_year'] == "" || $sost5['prim_year'] == "0") $data_r_prim = "---";
            else $data_r_prim = $date_day2." ".$month[$date_month2]." ".$date_year2." ".$year." ".$date_time2;

          $sost5['zh_primechanie'] = str_replace(":smile:","<img alt='picture' src='../img/smile.png' align=middle />",$sost5['zh_primechanie']);
          $sost5['zh_primechanie'] = str_replace(":tongue:","<img alt='picture' src='../img/tongue.png' align=middle />",$sost5['zh_primechanie']);
          $sost5['zh_primechanie'] = str_replace(":wink:","<img alt='picture' src='../img/wink.png' align=middle />",$sost5['zh_primechanie']);
          $sost5['zh_primechanie'] = str_replace(":wassat:","<img alt='picture' src='../img/wassat.png' align=middle />",$sost5['zh_primechanie']);
          $sost5['zh_primechanie'] = str_replace(":sad:","<img alt='picture' src='../img/sad.png' align=middle />",$sost5['zh_primechanie']);
          $sost5['zh_primechanie'] = str_replace(":crying:","<img alt='picture' src='../img/crying.png' align=middle />",$sost5['zh_primechanie']);
          $sost5['zh_primechanie'] = str_replace(":angry:","<img alt='picture' src='../img/angry.png' align=middle />",$sost5['zh_primechanie']);
          $sost5['zh_primechanie'] = rep_back($sost5['zh_primechanie']);

          if($result2['administrator'] == 1 || $result2['login_id'] == $sost4['login_id'] ||  $result2['login_id'] == $sost5['tr_usr_login'] ) $drop_tr = "<a href=know_delete_tr.php?otkr=".$_GET['otkr']."&amp;zh_str_id=".$sost4['zh_str_id']."&amp;zhurn_id=".$sost4['zhurn_id']."&amp;tr_id=".$sost5['tr_id']."&amp;all_tr=0 title='".$TEXT['tbl-delete']."' ><img class='tips_tread_drop' alt='".$TEXT['tbl-delete']."' src='../img/drop.png' /></a>";
           else $drop_tr = "";

           ?>
             <fieldset class='zayavka_view' >
              <legend align="left" ><span class="news3"><?php echo $sost5['fullname']; ?></span></legend>
               <table align='top' border='0' width='100%' cellpadding='0' cellspacing='0'>
                <tr>
                  <td align="right"><?php echo $drop_tr; ?></td>
                </tr>
                <tr>
                  <td class="support" width="99%"><?php echo nl2br($sost5['zh_primechanie']); ?></td>
                </tr>
                <tr>
                  <td class="data tblgrad"><?php echo $data_r_prim; ?></td>
                </tr>
              </table>
            </fieldset>
           <?php
             }
            echo "</td></tr></table>";

           }
           else
           {
             ?>
      <table border="0" width="90%" cellpadding="0" cellspacing="0"  align="center">
       <tr>
         <td align="right"><?php echo $primechanie; ?><?php echo $img_cl; ?></td>
       </tr>
       <?php
            if(!empty($sost4['pic_krit']) && $sost4['pic_krit']!="-") $krit_image = "<img alt='".$sost4['kritichnost']."' title='".$sost4['kritichnost']."' src='".$sost4['pic_krit']."' />";
              else $krit_image = $sost4['kritichnost'];

           $date_day = $sost4['zhnan_day'];
           $date_month = $sost4['zhnan_month'];
           $date_year = $sost4['zhnan_year'];
           $date_time = $sost4['zhnan_hour'].":".$sost4['zhnan_minute'].":".$sost4['zhnan_second'];
           $year = $TEXT['year'];
           if($sost4['zhnan_year'] == "" || $sost4['zhnan_year'] == "0") $data_r = "---";
            else $data_r = $date_day." ".$month[$date_month]." ".$date_year." ".$year." ".$date_time;

            if($_POST['print_item'] == 1) $print_ch = "checked";
             else
             {
              if($sost4['zhurn_id'] == $_POST['zhurn_id']) $print_ch = "checked";
               else $print_ch = "";
             }
             echo "<tr><td>";
              ?>
             <fieldset class='<?php echo $fon; ?>' >
              <legend align="left" ><span class="temaprint"><?php echo $krit_image; ?>&nbsp;<?php echo $sost4['zh_tema']; ?></span></legend>
               <table align='center' border='0' width='100%' cellpadding='0' cellspacing='0'>
                <tr>
                  <td colspan="2" align="right"><?php echo $fon_img; ?></td>
                </tr>
                <tr>
                  <td colspan="2" class="support" width="100%"><?php echo nl2br($sost4['zh_soobschenie']); ?></td>
                </tr>
                <tr>
                  <td colspan="2" class="support" >&nbsp;</td>
                </tr>
                <tr>
                  <td class="autor"><?php echo $TEXT['zhurn-autor'].$sost4['fullname']; ?></td>
                  <td class="data tblgrad" width="20%"><?php echo $data_r; ?>&nbsp;<a href=know_addform_zam.php?otkr=<?php echo $_GET['otkr']; ?>&amp;zh_str_id=<?php echo $sost4['zh_str_id']; ?>&amp;zhurn_id=<?php echo $sost4['zhurn_id']; ?> title='<?php echo $TEXT['know-zam']; ?>' ><img alt='picture' src='../img/izmenit.png' align=top /></a></td>
                </tr>
              </table>
            </fieldset>
       <?php
       echo "</td></tr>";
            ?>
            </table>
           <?php
          }
         }
           ?>
   </td>
  </tr>
  </table>
</body>
</html>