<?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['know-izm-title'];

  require_once "../config.php";
  require_once "top.php";
  ?>
  <title><?php echo $title; ?></title>
  <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(!isset($button)) $button = $TEXT['zhurn-print-btn'];
  if(!isset($action)) $action = "know_print.php target='_top'";

  if(empty($_GET['zh_str_id'])) puterror2($TEXT['error-zhurn1']);
  if(strlen($_GET['zh_str_id'])>11) puterror2($TEXT['error-zhurn2']);
  if(empty($_GET['zhurn_id'])) puterror2($TEXT['error-zhurn11']);
  if(strlen($_GET['zhurn_id'])>11) puterror2($TEXT['error-zhurn12']);
  if(strlen($_GET['k'])>8) puterror2($TEXT['error-zhurn15']);
  $old_zh_str_id = $_GET['zh_str_id'];
  $old_zhurn_id = $_GET['zhurn_id'];

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

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

   while($item_par != 0)
   {
    $resourcebr2 = "SELECT parent, zh_str_id, strukt_name FROM tbl_zhnaniy_strukt WHERE zh_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['zh_str_id'];
     $item_par = $result_bread2['parent'];
     $item_name = "<a class='news3' href=knowledge.php?zh_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;<span class="news3"><?php echo $TEXT['zhurn-path']; ?></span><?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>
<?php
  $query4 = "SELECT
    tbl_bd_zhnaniy.*,
    YEAR(tbl_bd_zhnaniy.data) AS data_year,
    MONTH(tbl_bd_zhnaniy.data) AS data_month,
    DAY(tbl_bd_zhnaniy.data) AS data_day,
    TIME(tbl_bd_zhnaniy.data) AS data_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.zh_str_id = ".$_GET['zh_str_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
           {
 ?>
<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='know_printform.php?print_item=0&amp;zh_str_id=".$_GET['zh_str_id']."&amp;zhurn_id=".$_GET['zhurn_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='know_printform.php?print_item=1&amp;zh_str_id=".$_GET['zh_str_id']."&amp;zhurn_id=".$_GET['zhurn_id']."' /></td>";
            }
         ?>
         <td></td>
       </tr>

       <?php
           while($sost4 = mysql_fetch_array($tmp4,MYSQL_ASSOC))
           {
            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['data_day'];
           $date_month = $sost4['data_month'];
           $date_year = $sost4['data_year'];
           $date_time = $sost4['data_hour'];
           if($sost4['data_year'] == "" || $sost4['data_year'] == "0000") $data_r = "---";
            else $data_r = $date_day." ".$month[$date_month]." ".$date_year." ".$TEXT['year']." ".$date_time;

          $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']);

            if($_GET['print_item'] == 1) $print_ch = "checked";
             else 
             {
              if($sost4['zhurn_id'] == $_GET['zhurn_id']) $print_ch = "checked";
               else $print_ch = "";
             }
            $print_item_tmp = $sost4['zhurn_id'];
            
            if($_GET['zhurn_id'] == $sost4['zhurn_id'])
            {
             echo "<tr>
              <td></td>
              <td colspan=3 >";
              ?>
             <fieldset class='zayavka' >
              <legend align="left" ><?php echo $krit_image; ?>&nbsp;<?php echo $sost4['zh_tema']; ?></legend>
               <table align='center' border='0' width='98%' cellpadding='0' cellspacing='0'>
                <tr>
                  <td>&nbsp;</td><td class="data"><input type="checkbox" name=printitem[<?php echo $print_item_tmp; ?>] <?php echo $print_ch; ?> /></td>
                </tr>
                <tr>
                  <td colspan="2" class="support" width="100%">&nbsp;&nbsp;<?php echo nl2br($sost4['zh_soobschenie']); ?></td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td class="autor"><?php echo $TEXT['zhurn-autor'].$sost4['fullname']; ?></td>
                  <td class="data"><?php echo $data_r; ?></td>
                </tr>
              </table>
            </fieldset>
       <?php
              echo "</td><td></td>
             </tr>";
            }
            else
             {
             echo "<tr>
              <td></td>
              <td width= '16px' class='newsdesch'>".$krit_image."</td>
              <td class='newsdesch'>&nbsp;<a href='know_printform.php?zhurn_id=".$sost4['zhurn_id']."&amp;zh_str_id=".$sost4['zh_str_id']."&amp;k=".$stop_r."' class='news3' title='".$TEXT['support14']."'>".$sost4['zh_tema']."</a></td>
              <td width= '16px' class='newsdesch'><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="86%" cellpadding="0" cellspacing="0"  align="center">
  <tr align="right"><td>
  <input type=hidden name=zh_str_id value='<?php echo $old_zh_str_id; ?>' />
  <input class="button" type=submit value='<?php echo $button; ?>' />
</td>
</tr>
</table>
</form>
</body>
</html>