<?
include("const.php");
$ff = @file("myshop/$shop");

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

if (ereg("&", $url) == true or ereg("\?", $url) == true) {
 $sign = "&";
}
elseif (ereg("\?", $url) == false) {
 $sign = "?";
}

$allg = explode(";", trim($ff[2]));
if ($allg[count($allgoods)-1] == "") {
 $min = 1;
}
Else {
 $min = 0;
}
for ($m = 0; $m < count($allg)-$min; $m++){
 $allgoods[] = $allg[$m];
}

$serv_const_lstcount = (integer) trim($ff[3]);
$formcolor = trim($ff[18]);
$bordercolor = trim($ff[19]);
$fonecolor1 = trim($ff[13]);
$fonecolor2 = trim($ff[14]);
?>


<?
If (trim($ff[4]) == "on") {
 ?>
 document.write('<p>&nbsp;&nbsp;Страницы: <?
 for ($c = 1; $c <= ceil(count($allgoods) / $serv_const_lstcount); $c++) {
  If ($lst == $c) {
   echo "<b><a href=\"{$url}{$sign}g=1&wmshop_num_page=$c&wmshop_sort=$sort&wmshop_rv=$rv\" class=\"cap\">$c</a></b>";
  }
  Else {
   echo "<a href=\"{$url}{$sign}g=1&wmshop_num_page=$c&wmshop_sort=$sort&wmshop_rv=$rv\" class=\"cap\">$c</a>";
  }
  If ($c <> ceil(count($allgoods) / $serv_const_lstcount)) {
   echo " | ";
  }
 }

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

document.write('<table border="0" width="98%" cellpadding="0" align="center" style="border: 1 solid #<? echo $bordercolor ?>" cellspacing="1">');
document.write('  <tr>');
document.write('    <td width="100%" valign="top">');
document.write('      <table border="0" width="100%" cellspacing="0" cellpadding="0">');
<?
If (trim($ff[6]) == "on") {
 ?>
 document.write('        <tr>');
 <? If (trim($ff[7]) == "on") { ?>
 document.write('          <td width="5%" bgcolor="#<? echo $formcolor ?>"><p><a href="<? echo $url; echo $sign ?>g=1&wmshop_num_page=<? echo $lst ?>&wmshop_sort=name<? If ($sort == "name" and $rv <> "true") { echo "&wmshop_rv=true"; } ?>" class="cap"><? If ($sort == "name") { echo "<b>"; } ?>№<? If ($sort == "name") { echo "</b>"; } ?></a></p></td>'); 
 <? } ?>
 <? If (trim($ff[8]) == "on") { ?>
 document.write('          <td width="43%" bgcolor="#<? echo $formcolor ?>"><p><a href="<? echo $url; echo $sign ?>g=1&wmshop_num_page=<? echo $lst ?>&wmshop_sort=name<? If ($sort == "name" and $rv <> "true") { echo "&wmshop_rv=true"; } ?>" class="cap"><? If ($sort == "name") { echo "<b>"; } ?>название<? If ($sort == "name") { echo "</b>"; } ?></a></p></td>');
 <? } ?>
 <? If (trim($ff[9]) == "on") { ?>
 document.write('          <td width="10%" bgcolor="#<? echo $formcolor ?>"><p><a href="<? echo $url; echo $sign ?>g=1&wmshop_num_page=<? echo $lst ?>&wmshop_sort=price<? If ($sort == "price" and $rv <> "true") { echo "&wmshop_rv=true"; } ?>" class="cap"><? If ($sort == "price") { echo "<b>"; } ?>цена<? If ($sort == "price") { echo "</b>"; } ?></a></p></td>');
 <? } ?>
 <? If (trim($ff[10]) == "on") { ?>
 document.write('          <td width="10%" bgcolor="#<? echo $formcolor ?>"><p><a href="<? echo $url; echo $sign ?>g=1&wmshop_num_page=<? echo $lst ?>&wmshop_sort=date<? If ($sort == "date" and $rv <> "true") { echo "&wmshop_rv=true"; } ?>" class="cap"><? If ($sort == "date") { echo "<b>"; } ?>добавлено<? If ($sort == "date") { echo "</b>"; } ?></a></p></td>');
 <? } ?>
 <? If (trim($ff[11]) == "on") { ?>
 document.write('          <td width="22%" bgcolor="#<? echo $formcolor ?>"><p><a href="<? echo $url; echo $sign ?>g=1&wmshop_num_page=<? echo $lst ?>&wmshop_sort=seller<? If ($sort == "seller" and $rv <> "true") { echo "&wmshop_rv=true"; } ?>" class="cap"><? If ($sort == "seller") { echo "<b>"; } ?>продавец<? If ($sort == "seller") { echo "</b>"; } ?></a></p></td>');
 <? } ?>
 <? If (trim($ff[12]) == "on") { ?>
 document.write('          <td width="10%" bgcolor="#<? echo $formcolor ?>"></td>');
 <? } ?>
 document.write('        </tr>');
 <?
}
?>


<?

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 "document.write('<tr><td><p>Товаров не найдено.</p></td></tr>');\n";
}

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 = str_replace("'", "\"", trim($fusr[1]));

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

   If ($clr == "$fonecolor1") { 
    $clr = "$fonecolor2";
   }
   Else {
    $clr = "$fonecolor1";
   }

   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 "document.write('<tr>');\n";
   If (trim($ff[7]) == "on") { echo "document.write('<td width=\"5%\" bgcolor=\"$clr\"><p>$allgoods[$r]</p></td>');\n"; }
   If (trim($ff[8]) == "on") { echo "document.write('<td width=\"43%\" bgcolor=\"$clr\"><p><a href=\"http://$serv_const_servname/buy.phtml?tovid=$allgoods[$r]\" class=\"cap\" target=\"_blank\">$ename</a></p></td>');\n"; }
   If (trim($ff[9]) == "on") { echo "document.write('<td width=\"10%\" bgcolor=\"$clr\"><p>$esumm</p></td>');\n"; }
   If (trim($ff[10]) == "on") { echo "document.write('<td width=\"10%\" bgcolor=\"$clr\"><p>$edate</p></td>');\n"; }
   If (trim($ff[11]) == "on") { echo "document.write('<td width=\"22%\" bgcolor=\"$clr\"><p><a href=\"http://$serv_const_servname/seller.phtml?name=$usrname\" class=\"cap\" target=\"_blank\">$eusr</a></p></td>');\n"; }
   If (trim($ff[12]) == "on") { echo "document.write('<td width=\"10%\" bgcolor=\"$clr\"><p align=\"right\"><a href=\"http://$serv_const_servname/buy.phtml?tovid=$allgoods[$r]\" class=\"cap\" target=\"_blank\"><img border=\"0\" src=\"http://$serv_const_servname/pic_buy.gif\" width=\"16\" height=\"16\" alt=\"Купить!\"></a></p></td>');\n"; }
   echo "document.write('</tr>');\n";
}
?>
document.write('      </table>');
document.write('    </td>');
document.write('  </tr>');
document.write('</table>');

<?
If (trim($ff[5]) == "on") {
 ?>
 document.write('<p>&nbsp;&nbsp;Страницы: <?
 for ($c = 1; $c <= ceil(count($allgoods) / $serv_const_lstcount); $c++) {
  If ($lst == $c) {
   echo "<b><a href=\"{$url}{$sign}g=1&wmshop_num_page=$c&wmshop_sort=$sort&wmshop_rv=$rv\" class=\"cap\">$c</a></b>";
  }
  Else {
   echo "<a href=\"{$url}{$sign}g=1&wmshop_num_page=$c&wmshop_sort=$sort&wmshop_rv=$rv\" class=\"cap\">$c</a>";
  }
  If ($c <> ceil(count($allgoods) / $serv_const_lstcount)) {
   echo " | ";
  }
 }

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