<?php
function affiliates($limit) {
global $pre;
global $setting;
global $mrw;
global $siteurl;

$temp = @mysql_fetch_row(@mysql_query("SELECT template FROM ".$pre."templates WHERE name = 'plugin_affiliates'"));

if ($limit == "") {
$sql = mysql_query("SELECT * FROM ".$pre."fielddata WHERE aid = 'plugin_affiliates' ORDER BY `id` DESC");
} else {
$sql = mysql_query("SELECT * FROM ".$pre."fielddata WHERE aid = 'plugin_affiliates' ORDER BY `id` DESC LIMIT ".$limit);
}
while($rs = mysql_fetch_array($sql)) {
$pab = "";$rab = "";
$r = explode("|", $rs[data]);
if ($r[3] == 1) {
$pab[0] = "{affiliate}";
$pab[1] = "{date}";

$url = "";
if ($r[1] == "no") {
$url = $r[0];
} else {
$url = $siteurl."index.php?view=af_click&id=".$rs[id];
}
if ($r[2]) {
$rab[0] = "<a href='".$url."' target=popup'><img src='".$r[2]."' border='0' style='border:1px solid black'></a>";
} else {
$rab[0] = "<a href='".$url."' target='popup'>".$rs[fname]."</a>";
}
$rab[1] = date($setting["date_format"], $r[4]);

$data .= str_replace($pab, $rab, stripslashes($temp[0]));
}
}
$data .= "<br><center>[ <a href='".$mrw['af_apply']."'><b>Apply for Affiliation</b></a> ]</center>";
return $data;
}
?>