<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if (is_file ("../lang/".$lang."/".$lang.".php")) include "../lang/".$lang."/".$lang.".php";
     else include "../lang/ru/ru.php";

  $title=$titlepage = $TEXT['krit-title4'];
  $helppage = $TEXT['krit-help4'];

  require_once "../config.php";
  require_once "../util/top_layer1.php";

  if($result2['user'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['master'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['manager'] == 1) puterror2($TEXT['error-loginform4']);

  if(!isset($title)) $title = $TEXT['krit-title4'];
  if(!isset($button)) $button = $TEXT['btn_del'];
  if(!isset($action)) $action = "delete.php";
  if(!isset($button2)) $button2 = $TEXT['btn_back'];
  if(!isset($action2)) $action2 = "index-krit.php";
  if(empty($_GET['krit_id'])) $_GET['krit_id'] = "";
  if(empty($_POST['krit_id'])) $_POST['krit_id'] = "";
?>
<table class="table" border="0" cellpadding="2" cellspacing="0" width="60%">
<?php
  if(strlen($_GET['krit_id'])>11) puterror2($TEXT['error-krit4']);
  if(strlen($_POST['krit_id'])>11) puterror2($TEXT['error-krit4']);
  $_GET['krit_id'] = rep($_GET['krit_id']);
  $_POST['krit_id'] = rep($_POST['krit_id']);

  $old_krit_id = $_GET['krit_id'];
  $old_inst_krit_id = $_POST['krit_id'];

  if(empty($_GET['krit_id'])) $krit_id = $old_inst_krit_id;
    else $krit_id = $old_krit_id;

  $query = "SELECT `kritichnost`, `pic_krit` FROM `tbl_kritichnost` WHERE `krit_id`='$krit_id'";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl39']);
       if (mysql_num_rows($result)>0);
         {
          $result_kritichnost = mysql_fetch_array($result);
          if(!empty($result_kritichnost['pic_krit']) && $result_kritichnost['pic_krit']!="-") $krit_image = "<img alt='".$result_kritichnost['kritichnost']."' src='../".$result_kritichnost['pic_krit']."' />&nbsp;".$result_kritichnost['kritichnost'];
              else $krit_image = $result_kritichnost['kritichnost'];
           echo "<tr class='delit'><td>".$TEXT['krit-now'].$krit_image."</td></tr>";
          }
?>
</table>
<?php
  $query2 = "SELECT zh_tema, zhurn_id FROM tbl_zhurnal WHERE krit_id='$krit_id'";
  $result2 = mysql_query($query2);
  if (!$result2) puterror2($TEXT['error-tbl41']);
          $num_rows = mysql_num_rows($result2);
       if ($num_rows>0)
          {
           echo "<p><u>".$TEXT['global-title3']."</u></p>
            <table class='table' border='1' cellpadding='3' cellspacing='0' width='40%'>
            <tr class='tableheadercat'>
            <td>".$TEXT['menu-btn33']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_kritichnost2 = mysql_fetch_array($result2))
                {
                 $del = "<a href=zhurn_delete.php?zhurn_id=".$result_kritichnost2['zhurn_id']."&krit_id=".$krit_id." title='".$TEXT['krit-del-tit']."'>".$TEXT['tbl-delete']."</a>";
            ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_kritichnost2['zh_tema']; ?></td>
            <td><?php echo $del; ?></td>
                 </tr>
           <?php
                }
	    ?>
	    </table>
	    <?php
          }
          if($num_rows !== 0) $action_end = $action2;
          else $action_end = $action;

          if($num_rows !== 0) $button_end = $button2;
          else $button_end = $button;

?>
</table>
<form enctype='multipart/form-data' action=<?php echo $action_end; ?> method=post>
<table align='center'>
<tr><td></td><td>
<input class=button type=submit value='<?php echo $button_end; ?>' />
<input type=hidden name=krit_id value='<?php echo $old_krit_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>