<?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['supp-mar-del'];
  $helppage = "";

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

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

  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.php";
  if(empty($_GET['mar_id'])) $_GET['mar_id'] = "";
  if(empty($_POST['mar_id'])) $_POST['mar_id'] = "";
?>
<table class="table" border="0" cellpadding="2" cellspacing="0" width="60%">
<?php
  if(strlen($_GET['mar_id'])>11) puterror2($TEXT['error-marsh13']);
  if(strlen($_POST['mar_id'])>11) puterror2($TEXT['error-marsh13']);
  $_GET['mar_id'] = rep($_GET['mar_id']);
  $_POST['mar_id'] = rep($_POST['mar_id']);

  $old_mar_id = $_GET['mar_id'];
  $old_inst_mar_id = $_POST['mar_id'];

  if(empty($_GET['mar_id'])) $mar_id = $old_inst_mar_id;
    else $mar_id = $old_mar_id;

  $query = "SELECT `mar_name` FROM `tbl_marsh` WHERE `mar_id`='$mar_id'";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl42']);
       if (mysql_num_rows($result)>0);
         {
          $result_mar = mysql_fetch_array($result);
           echo "<tr class='delit'><td>".$TEXT['marsh-now'].$result_mar['mar_name']."</td></tr>";
          }
?>
</table>
<?php
  $query2 = "SELECT tbl_instructions.*, tbl_razdel_instr.razd_id, tbl_razdel_instr.razdel FROM tbl_instructions JOIN tbl_razdel_instr ON tbl_instructions.razd_id=tbl_razdel_instr.razd_id WHERE tbl_instructions.razd_id='$razd_id'";
  $result2 = mysql_query($query2);
  if (!$result2) puterror2($TEXT['error-tbl18']);
         $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['tbl-razd']."</td>
            <td>".$TEXT['tbl-nazv']."</td>
            <td>".$TEXT['inst-field5']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_instructions = mysql_fetch_array($result2))
                {
                $res_razd = $result_instructions['razdel'];
                $edit = "<a href=editinstform.php?razd_id=".$result_instructions['razd_id']."&instr_id=".$result_instructions['instr_id']." title='".$TEXT['tbl-edit2-tit']."'>".$TEXT['tbl-edit2']."</a>";
            ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><b><i><?php echo $res_razd; ?></i></b></td>
            <td><?php echo $result_instructions['name']; ?></td>
            <td><?php echo $result_instructions['path']; ?></td>
            <td><?php echo $edit; ?></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=mar_id value='<?php echo $old_mar_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>