<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("lang/".$lang.".php")) include "lang/".$lang.".php";
     else include "lang/ru.php";

  $title=$titlepage=$TEXT['top-search'];

  require_once "config.php";
  require_once "utils/top_search_doc.php";

  if(empty($_POST['search'])) puterror($TEXT['search-err1']);
  if(strlen($_POST['search'])>200) puterror($TEXT['search-err2']);
  if(strlen($_POST['typepar'])>10) puterror($TEXT['search-err3']);
  $_POST['search'] = rep($_POST['search']);
  $_POST['typepar'] = rep($_POST['typepar']);

  $query_org_no = "SELECT * FROM tbl_organizaciya WHERE organizaciya = '-' ";
   $org_no = mysql_query($query_org_no);
     if(!$org_no) puterror($TEXT['error-tbl7']);
       $result_org_no = mysql_query($org_no,MYSQL_ASSOC);

  if($_GET['org_id']!=="" && !empty($_GET['org_id'])) $org_razdel = $_GET['org_id'];
   else $org_razdel = $result_org_no['org_id'];
?>
<table class="table" border="0" cellpadding="1" cellspacing="0" width="87%">
<?php
  $action = "tbl_documents.name";
    switch($_POST['typepar'])
      {
      case 1:
      $action = "tbl_documents.name";
      break;
      case 2:
      $action = "tbl_documents.description";
      break;
      case 3:
      $action = "tbl_documents.data";
      break;
      }

  $query = "SELECT tbl_documents.razd_id, tbl_documents.name, tbl_documents.description, tbl_documents.data, tbl_documents.path, tbl_razdel.razdel 
FROM tbl_documents 
JOIN tbl_razdel ON tbl_documents.razd_id=tbl_razdel.razd_id
WHERE tbl_documents.visible = 'show' AND tbl_razdel.org_id = '".$org_razdel."' AND LOWER(".$action.") LIKE LOWER('%".$_POST['search']."%') ORDER BY tbl_documents.name ";
  $result = mysql_query($query);
    if(!$result) puterror($TEXT['error-tbl14']);
       $num_rows = mysql_num_rows($result);
       while($doc = mysql_fetch_array($result,MYSQL_ASSOC))
          {
           $res_razd = $doc['razdel'];
           $docpath = preg_replace("/\.\.+./","",$doc['path']);
           ?>
           <tr align="left">
           <td width="5%"><img alt="picture" src="img/document.gif"></td>
           <td><a href="<?php echo $docpath; ?>" target="_blank" title="<?php echo $doc['description']; ?>"><span class="texttableusrtit"><?php echo $doc['name']; ?></span><span class="phoneotd">(<?php echo $TEXT['search-razdel']; ?> <?php echo $res_razd; ?>)</span></a><hr /></td>
           </tr>
           <?php
          }
       if($num_rows == 0) echo "<h1 class=userpage>".$TEXT['search-err4']."</h1>";
?>
</table>
<?php
  require_once "utils/bottom_search.php";
?>