<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="100%" bgcolor="#F0F0F0"><p><b>&gt;&gt; TOP-20 Лидеров продаж</b></p></td>
  </tr>
</table>
<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="6%" bgcolor="#FBC900"><p align='center'>№</p></td>
          <td width="65%" bgcolor="#FBC900"><p>организация продавца</p></td>
          <td width="19%" bgcolor="#FBC900"><p>логин</p></td>
          <td width="10%" bgcolor="#FBC900"><p>количество&nbsp;продаж</p></td>
        </tr>
<?
$d2 = dir("users/");
while($flg = $d2->read()) {
 If ($flg <> "." and $flg <> ".." and $flg <> ".htaccess") {

  $prod = 0;
  $d = dir("goods/");
  while($tme = $d->read()) {
   If ($tme <> "." and $tme <> ".." and $tme <> ".htaccess") {
    $fr = @file("goods/$tme");
    If (trim($fr[0]) == $flg) {
     $prod = $prod + (integer) trim($fr[15]);
    }
   }
  }
  $d->close();

  If ($prod > 0) {
   $ar[] = array(0 => $prod, 1 => $flg);
  }

 }
}
$d2->close();


rsort($ar);

$to = 20;
if ($to > count($ar)) {
 $to = count($ar);
}
for ($y = 0; $y < count($ar); $y++) {
 $ff = @file("users/" . $ar[$y][1]);

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

 $posi = $y+1;
 If ($posi == 1) {
  $posi = "<img border='0' src='/pic_place_first.gif' width='16' height='16'>";
 }
 ElseIf ($posi == 2) {
  $posi = "<img border='0' src='/pic_place_second.gif' width='16' height='16'>";
 }
 ElseIf ($posi == 3) {
  $posi = "<img border='0' src='/pic_place_third.gif' width='16' height='16'>";
 }

 echo "
	<tr>
          <td width='6%' bgcolor='$clr'><p align='center'>$posi</p></td>
          <td width='65%' bgcolor='$clr'><p><a href='/seller.phtml?name=" . $ar[$y][1] . "' class='cap2'>" . trim($ff[1]) . "</a></p></td>
          <td width='19%' bgcolor='$clr'><p>" . $ar[$y][1] . "</p></td>
          <td width='10%' bgcolor='$clr'><p>" . $ar[$y][0] . "</p></td>
	</tr>";
}
?>
</table>
    </td>
  </tr>
</table>