<?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['nd-title4'];
  $helppage = $TEXT['nd-help4'];

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

  $old_razd_id = $_GET['razd_id'];
  $old_doc_razd_id = $_POST['razd_id'];

  if(empty($_GET['razd_id'])) $razd_id = $old_doc_razd_id;
    else $razd_id = $old_razd_id;

  $query = "SELECT `razdel` FROM `tbl_razdel` WHERE `razd_id`='$razd_id'";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl15']);
       if (mysql_num_rows($result)>0);
         {
          $result_razdel = mysql_fetch_array($result);
           echo "<tr class='delit'><td>".$TEXT['nd-now'].$result_razdel['razdel']."</td></tr>";
          }
?>
</table>
<?php
  $query2 = "SELECT tbl_documents.*, tbl_razdel.razd_id, tbl_razdel.razdel FROM tbl_documents JOIN tbl_razdel ON tbl_documents.razd_id=tbl_razdel.razd_id WHERE tbl_documents.razd_id='$razd_id'";
  $result2 = mysql_query($query2);
  if (!$result2) puterror2($TEXT['error-tbl14']);
          $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-doc-name']."</td>
            <td>".$TEXT['tbl-doc']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

           while($result_documents = mysql_fetch_array($result2))
                {
                 $res_razd = $result_documents['razdel'];
                 $edit = "<a href=editdocform.php?razd_id=".$result_documents['razd_id']."&doc_id=".$result_documents['doc_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_documents['name']; ?></td>
            <td><?php echo $result_documents['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=razd_id value='<?php echo $old_razd_id; ?>' />
</td></tr>
</table>
</form>
<?php
  require_once "../util/bottom.php";
?>