<?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['pas-title'];
  $helppage = $TEXT['pas-help'];

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

  if(empty($_GET['pas_str_id'])) $pas_str_id = $_POST['pas_str_id'];
    else $pas_str_id = $_GET['pas_str_id'];

  $query = "SELECT `strukt_name` FROM `tbl_pass_strukt` WHERE `pas_str_id`='$pas_str_id'";
  $result = mysql_query($query);
  if(!$result) puterror2($TEXT['error-tbl40']);
   if(mysql_num_rows($result)>0);
    {
     $result_strukt_name = mysql_fetch_array($result);
      echo "<tr class='delit'><td>".$TEXT['kat-now'].$result_strukt_name['strukt_name']."</td></tr>";
    }
?>
</table>
<?php
  $query_check = mysql_query("SELECT COUNT(parent) FROM tbl_pass_strukt WHERE parent=".$pas_str_id."");
  $result_check1=mysql_result($query_check, 0);
  if($result_check1 > 0)
   {
    echo "<p>".$TEXT['error-kat21']."</p>";
   }
  $querykat = "SELECT fio, pas_id FROM tbl_pass_keep WHERE `pas_str_id`='$pas_str_id'";
  $resultkat = mysql_query($querykat);
  if(!$resultkat) puterror2($TEXT['error-tbl52']);
   $result_check2 = mysql_num_rows($resultkat);
    if($result_check2>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_kat2 = mysql_fetch_array($resultkat))
                {
                 $del = "<a href=zhurn_delete.php?pas_id=".$result_kat2['pas_id']."&pas_str_id=".$pas_str_id." title='".$TEXT['kat-del-tit']."'>".$TEXT['tbl-delete']."</a>";
            ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
            <td><?php echo $result_kat2['fio']; ?></td>
            <td><?php echo $del; ?></td>
                 </tr>
           <?php
                }
	    ?>
	    </table>
	    <?php
          }
 $result_check = $result_check1 + $result_check2;

 if($result_check == 0) $action_end = $action;
  else $action_end = $action2;

 if($result_check == 0) $button_end = $button;
  else $button_end = $button2;
?>
<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=pas_str_id value='<?php echo $pas_str_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>