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

  $old_sost_id = $_GET['sost_id'];
  $old_inst_sost_id = $_POST['sost_id'];

  if(empty($_GET['sost_id'])) $sost_id = $old_inst_sost_id;
    else $sost_id = $old_sost_id;

  $query = "SELECT `sostoyanie` FROM `tbl_supp_sostoyanie` WHERE `sost_id`='$sost_id'";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl23']);
       if (mysql_num_rows($result)>0);
         {
          $result_sostoyanie = mysql_fetch_array($result);
           echo "<tr class='delit'><td>".$TEXT['supp-sost-now'].$result_sostoyanie['sostoyanie']."</td></tr>";
          }
?>
</table>
<?php
  $query2 = "SELECT tbl_supp_zayavka.zay_id, tbl_supp_zayavka.sost_id, tbl_supp_sostoyanie.sost_id, tbl_supp_sostoyanie.sostoyanie FROM tbl_supp_zayavka JOIN tbl_supp_sostoyanie ON tbl_supp_zayavka.sost_id=tbl_supp_sostoyanie.sost_id WHERE tbl_supp_zayavka.sost_id='$sost_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_sostoyanie2 = mysql_fetch_array($result2))
                {
                 $res_sost = $result_sostoyanie2['sostoyanie'];
                 $edit = "<a href=editsostform.php?sost_id=".$result_sostoyanie2['sost_id']."&zay_id=".$result_sostoyanie2['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_sost; ?></i></b></td>
            <td><?php echo $result_sostoyanie2['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=sost_id value='<?php echo $old_sost_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>