<?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_inst.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']);
?>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="87%">
<?php
  $action = "tbl_instructions.name";
    switch($_POST['typepar'])
      {
      case 1:
      $action = "tbl_instructions.name";
      break;
      case 2:
      $action = "tbl_instructions.description";
      break;
      }

  $query = "SELECT tbl_instructions.razd_id, tbl_instructions.photo, tbl_instructions.path, tbl_instructions.description, tbl_instructions.name, tbl_razdel_instr.razdel 
FROM tbl_instructions 
JOIN tbl_razdel_instr ON tbl_instructions.razd_id=tbl_razdel_instr.razd_id 
WHERE tbl_instructions.visible = 'show' AND LOWER(".$action.") LIKE LOWER('%".$_POST['search']."%') ORDER BY tbl_instructions.name ";
  $result = mysql_query($query);
    if(!$result) puterror($TEXT['error-tbl18']);
       $num_rows = mysql_num_rows($result);
       while($inst = mysql_fetch_array($result,MYSQL_ASSOC))
          {
           $res_razd = $inst['razdel'];
           $inpho = preg_replace("/\.\.+./","",$inst['photo']);
           $inpath = preg_replace("/\.\.+./","",$inst['path']);
           if(!empty($inst['photo']) && file_exists($inpho))
            {
            $image = "<img alt='picture' width='50' height='50' src='".$inpho."' />";
            }
             else $image = " &nbsp; ";
            ?>
            <tr align="left">
              <td width="6%"><?php echo $image; ?></td>
              <td><a href="<?php echo $inpath; ?>" target="_blank" title="<?php echo $inst['description']; ?>" ><span class="texttableusrtit"><?php echo $inst['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'><br />&nbsp;&nbsp; ".$TEXT['search-err4']."</h1>";
?>
</table>
<?php
  require_once "utils/bottom_search.php";
?>