<?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-vazh-title4'];
  $helppage = $TEXT['supp-vazh-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['supp-vazh-title4'];
  if(!isset($button)) $button = $TEXT['btn_del'];
  if(!isset($action)) $action = "delete-vazh.php";
  if(!isset($button2)) $button2 = $TEXT['btn_back'];
  if(!isset($action2)) $action2 = "index-vazh.php";
  if(empty($_GET['vazh_id'])) $_GET['vazh_id'] = "";
  if(empty($_POST['vazh_id'])) $_POST['vazh_id'] = "";
?>
<table class="table" border="0" cellpadding="2" cellspacing="0" width="60%">
<?php
  if(strlen($_GET['vazh_id'])>11) puterror2($TEXT['error-vazh4']);
  if(strlen($_POST['vazh_id'])>11) puterror2($TEXT['error-vazh4']);
  $_GET['vazh_id'] = rep($_GET['vazh_id']);
  $_POST['vazh_id'] = rep($_POST['vazh_id']);

  $old_vazh_id = $_GET['vazh_id'];
  $old_inst_vazh_id = $_POST['vazh_id'];

  if(empty($_GET['vazh_id'])) $vazh_id = $old_inst_vazh_id;
    else $vazh_id = $old_vazh_id;

  $query = "SELECT `srochnost` FROM `tbl_supp_srochnost` WHERE `sroch_id`='$vazh_id'";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl24']);
       if (mysql_num_rows($result)>0);
         {
          $result_srochnost = mysql_fetch_array($result);
           echo "<tr class='delit'><td>".$TEXT['supp-vazh-now'].$result_srochnost['srochnost']."</td></tr>";
          }
?>
</table>
<?php
  $query2 = "SELECT tbl_supp_zayavka.zay_id, tbl_supp_zayavka.sroch_id, tbl_supp_srochnost.sroch_id, tbl_supp_srochnost.srochnost FROM tbl_supp_zayavka JOIN tbl_supp_srochnost ON tbl_supp_zayavka.sroch_id=tbl_supp_srochnost.sroch_id WHERE tbl_supp_zayavka.sroch_id='$vazh_id'";
  $result2 = mysql_query($query2);
  if (!$result2) puterror2($TEXT['error-tbl26']);
          $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['analiz-msg-text']."</td>
            <td>".$TEXT['supp-num-zay']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_srochnost2 = mysql_fetch_array($result2))
                {
                 $res_vazh = $result_srochnost2['srochnost'];
                 $edit = "<a href=editvazhform.php?vazh_id=".$result_srochnost2['sroch_id']."&zay_id=".$result_srochnost2['zay_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_vazh; ?></i></b></td>
            <td><?php echo $result_srochnost2['zay_id']; ?></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=vazh_id value='<?php echo $old_vazh_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>