<?
If ($lst == "") {
 $lst = "1";
}
If ($sort == "") {
 $sort = "date";
}

$fr = @file("tx/razdel.txt");

If ($com == "seller") {
 $strinfo = "&gt;&gt; Просмотр информации о продавце $name &gt;&gt; Список товаров продавца";
}
ElseIf ($com == "find") {
 $name = htmlspecialchars(stripslashes($name));
 $strinfo = "&gt;&gt; Поиск товара &gt;&gt; Вы искали \"$name\"";
 If ($r1 == "1") {
  $strinfo .= " в названиях";
 }
 ElseIf ($r1 == "2") {
  $strinfo .= " в описаниях";
 }
 ElseIf ($r1 == "3") {
  $strinfo .= " в доп. информации";
 }
}
?>

<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%" bgcolor="#F0F0F0"><p><b><? echo $strinfo ?></b></p></td>
  </tr>
</table>
<p>&nbsp;</p>
<?
If ($com == "find") {
?>
<!-- ПОИКОВИК -->
 <table border="0" width="98%" cellspacing="0" cellpadding="4" bgcolor="#C0C0C0" align="center">
   <tr>
     <td width="2%" valign="middle" bgcolor="#F0F0F0" height="1" style="border-left: 1 solid #C0C0C0; border-top: 1 solid #C0C0C0; border-bottom: 1 solid #C0C0C0"><p align="center"><img border="0" src="/pic_info.gif" width="16" height="16"></p></td>
     <td width="98%" bgcolor="#F0F0F0" height="1" style="border-right: 1 solid #C0C0C0; border-top: 1 solid #C0C0C0; border-bottom: 1 solid #C0C0C0"><p>В этом разделе Вы без труда найдете то, что Вам нужно. Искать можно как в названиях товаров, так и в их описаниях. Для поиска наберите искомое слово в поле 'Что будем искать', и нажмите на кнопку 'Искать'.</p></td>
   </tr>
 </table>
 <p>&nbsp;</p>


 <SCRIPT language=javascript> 
 function frmpost(){
	if(document.all){
		if(frm.name.value.length == 0) {
			alert("Заполните поисковое поле!");
			return;
		}
		frm.submit();
	}
 }
 </SCRIPT>
 <p>&nbsp;</p>

<table border="0" width="98%" cellpadding="0" align="center" style="border: 1 solid #0000FF" cellspacing="1">
  <tr>
    <td width="100%" valign="top">
      <table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
           <td width="100%" bgcolor="#FBC900"><p><b>Поиск во всех разделах</b></p></td>
        </tr>
        <tr>
           <td width="100%" valign="top">
       <form method="POST" name="frm" action="/buy_sort.phtml?com=find">
         <p align="center">Что будем искать: <input type="text" maxlength="100" name="name" value="<? echo $name ?>" size="70" style="font-family: Verdana, Arial; font-size: 8pt; border: 1 solid #7F9DB9"></p>
         <p align="center"><input type="radio" name="r1" value="1" <? If ($r1 == "1" or $r1 == "") { echo "checked"; } ?>>Искать в названии <input type="radio" name="r1" value="2" <? If ($r1 == "2") { echo "checked"; } ?>>В описании <input type="radio" name="r1" value="3" <? If ($r1 == "3") { echo "checked"; } ?>>В доп. информации</p>
         <p align="center"><input type="button" onClick="frmpost();" name="B1" style="font-family: Verdana, Arial; font-size: 8pt" value="Искать"></p>
       </form>
           </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

<!-- END ПОИКОВИК -->

<p>&nbsp;</p>
<?
}
?>

<table border="0" width="98%" cellpadding="0" align="center" style="border: 1 solid #0000FF" cellspacing="1">
  <tr>
    <td width="100%" valign="top">
      <table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
           <td width="48%" bgcolor="#FBC900"><p><a href='/buy_sort.phtml?com=<? echo $com ?>&name=<? echo $name ?>&r1=<? echo $r1 ?>&lst=<? echo $lst ?>&sort=name<? If ($sort == "name" and $rv <> "true") { echo "&rv=true"; } ?>' class='cap2'><? If ($sort == "name") { echo "<b>"; } ?>название<? If ($sort == "name") { echo "</b>"; } ?></a></p></td>
           <td width="10%" bgcolor="#FBC900"><p><a href='/buy_sort.phtml?com=<? echo $com ?>&name=<? echo $name ?>&r1=<? echo $r1 ?>&lst=<? echo $lst ?>&sort=price<? If ($sort == "price" and $rv <> "true") { echo "&rv=true"; } ?>' class='cap2'><? If ($sort == "price") { echo "<b>"; } ?>цена<? If ($sort == "price") { echo "</b>"; } ?></a></p></td>
           <td width="10%" bgcolor="#FBC900"><p><a href='/buy_sort.phtml?com=<? echo $com ?>&name=<? echo $name ?>&r1=<? echo $r1 ?>&lst=<? echo $lst ?>&sort=date<? If ($sort == "date" and $rv <> "true") { echo "&rv=true"; } ?>' class='cap2'><? If ($sort == "date") { echo "<b>"; } ?>добавлено<? If ($sort == "date") { echo "</b>"; } ?></a></p></td>
           <td width="22%" bgcolor="#FBC900"><p><a href='/buy_sort.phtml?com=<? echo $com ?>&name=<? echo $name ?>&r1=<? echo $r1 ?>&lst=<? echo $lst ?>&sort=seller<? If ($sort == "seller" and $rv <> "true") { echo "&rv=true"; } ?>' class='cap2'><? If ($sort == "seller") { echo "<b>"; } ?>продавец<? If ($sort == "seller") { echo "</b>"; } ?></a></p></td>
           <td width="10%" bgcolor="#FBC900"></td>
        </tr>
            
<?
$d = dir("goods/");
while($flg = $d->read()) {
 If ($flg <> "." and $flg <> ".." and $flg <> ".htaccess") {
  $fgoods = @file("goods/" . $flg);
  If ($com == "seller") {
   If (trim($fgoods[0]) == $name) {
    $allgoods[] = $flg;
   }
  }
  ElseIf ($com == "find") {
   $name = strtolower($name);
   If ($r1 == "1") {
    $where = strtolower(trim($fgoods[3]));
   }
   ElseIf ($r1 == "2") {
    $where = strtolower(trim($fgoods[7]));
   }
   ElseIf ($r1 == "3") {
    $where = strtolower(trim($fgoods[8]));
   }
   If ($name <> "") {
    If (ereg($name, $where) == true) {
     $allgoods[] = $flg;
    }
   }
  }
 }
}
$d->close();


for ($k = 0; $k < count($allgoods); $k++){
 $rf = @file("goods/" . $allgoods[$k]);
 $ru = @file("users/" . trim($rf[0]));

 If ($sort == "name") {
  $srt = trim($rf[3]);
 }
 ElseIf ($sort == "price") {
  $srt = trim($rf[1]);
 }
 ElseIf ($sort == "date") {
  $ar = explode(".", trim($rf[4]));
  $str = (integer) $ar[2] * date("z", mktime($ar[3], $ar[4], $ar[5], $ar[1], $ar[0], $ar[2]));
 }
 ElseIf ($sort == "seller") {
  $srt = trim($ru[1]);
 }

 $srtar[] = array(0 => $srt, 1 => $allgoods[$k]);
}

If (count($allgoods) > 0) {
 If ($rv == "true") {
  If ($sort == "date") {
   sort($srtar);
  }
  Else {
   rsort($srtar);
  }
 }
 Else {
  If ($sort == "date") {
   rsort($srtar);
  }
  Else {
   sort($srtar);
  }
 }
}

for ($y = 0; $y < count($srtar); $y++) {
 $allgoods[$y] = $srtar[$y][1];
}



$lfrom = (integer) $lst * $serv_const_lstcount - $serv_const_lstcount;
$lto = (integer) $lst * $serv_const_lstcount;
If ($lto > count($allgoods)) {
 $lto = count($allgoods);
}

If (count($allgoods) <= 0) {
 echo "<tr><td><p>По Вашему запросу товаров не найдено.</p></td></tr>";
}

for ($r = $lfrom; $r < $lto; $r++) {

   price_min($allgoods[$r]);
   $fgoods = @file("goods/" . $allgoods[$r]);

   $edatear = explode(".", trim($fgoods[4]));
   $edate = "$edatear[0].$edatear[1].$edatear[2]";
   $fusr = @file("users/" . trim($fgoods[0]));
   $usrname = trim($fgoods[0]);

   $eusr = trim($fusr[1]);

   $ename = trim($fgoods[3]);

   If ($clr == "#F9FBFF") { 
    $clr = "#EAEDFF";
   }
   Else {
    $clr = "#F9FBFF";
   }


   If (trim($fgoods[16]) <> "" and trim($fgoods[16]) <> "0") {
    $esumm = "<font style='text-decoration: line-through'>" . trim($fgoods[16]) . "</font>&nbsp;<font color='#FF0000'>" . trim($fgoods[1]) . "</font>";
   }
   Else {
    $esumm = trim($fgoods[1]);
   }

    

   echo "
	<tr>
	<td width='48%' bgcolor='$clr'><p><a href='/buy.phtml?tovid=$allgoods[$r]' class='cap2'>$ename</a></p></td>
	<td width='10%' bgcolor='$clr'><p>$esumm</p></td>
	<td width='10%' bgcolor='$clr'><p>$edate</p></td>
	<td width='22%' bgcolor='$clr'><p><a href='/seller.phtml?name=$usrname' class='cap0'>$eusr</a></p></td>
	<td width='10%' bgcolor='$clr'><p align='right'><a href='/buy.phtml?tovid=$allgoods[$r]' class='cap2'><img border='0' src='/pic_buy.gif' width='16' height='16' alt='Купить!'></a></p></td>
	</tr>";
}
?>
      </table>
    </td>
  </tr>
</table>
<p>&nbsp;&nbsp;<b>Всего найдено: <? echo count($allgoods) ?></b></p>

<p>&nbsp;&nbsp;Страницы:
<?
//PAGES
for ($c = 1; $c <= ceil(count($allgoods) / $serv_const_lstcount); $c++) {
 If ($lst == $c) {
  echo "<b><a href='/buy_sort.phtml?com=$com&name=$name&r1=$r1&lst=$c&sort=$sort&rv=$rv' class='cap3'>$c</a></b>";
 }
 Else {
  echo "<a href='/buy_sort.phtml?com=$com&name=$name&r1=$r1&lst=$c&sort=$sort&rv=$rv' class='cap4'>$c</a>";
 }
 If ($c <> ceil(count($allgoods) / $serv_const_lstcount)) {
  echo " | ";
 }
}

If (count($allgoods) <= 0) {
 echo "<b><font color='#FF0000'>1</font></b>";
}
?>
</p>
