drupal/modules/affiliate-site.module

106 lines
3.5 KiB
Plaintext

<?php
$module = array("help" => "affiliate_help",
"block" => "affiliate_block",
"admin" => "affiliate_admin");
function affiliate_help() {
?>
<P>This is a small module to manage related and/or affiliate sites. The module exports two different blocks with links to the affiliate sites.</P>
<?php
}
function affiliate_block() {
global $site_url;
$result = db_query("SELECT * FROM affiliates ORDER BY name");
$content .= "<SCRIPT>\n";
$content .= " <!--//\n";
$content .= " function gotosite(site) {\n";
$content .= " if (site != \"\") {\n";
$content .= " parent.location = site\n";
$content .= " }\n";
$content .= " }\n";
$content .= " //-->\n";
$content .= "</SCRIPT>\n";
$content .= "<CENTER>\n";
$content .= "<FORM ACTION=\"\" METHOD=\"post\">\n";
$content .= " <SELECT NAME=\"affiliate\" ONCHANGE=\"gotosite(this.options[this.selectedIndex].value)\">\n";
$content .= " <OPTION VALUE=\"$site_url\">select a site</OPTION>\n";
while ($affiliate = db_fetch_object($result)) {
$content .= " <OPTION VALUE=\"$affiliate->link\">$affiliate->name</OPTION>\n";
}
$content .= " </SELECT>\n";
$content .= "</FORM>\n";
$content .= "</CENTER>\n";
$blocks[0]["subject"] = "Affiliate sites";
$blocks[0]["content"] = $content;
$blocks[0]["info"] = "Affiliate sites (selection)";
unset($content);
$result = db_query("SELECT * FROM affiliates ORDER BY name");
while ($affiliate = db_fetch_object($result)) {
$content .= "<LI><A HREF=\"$affiliate->link\">$affiliate->name</A></LI>\n";
}
$blocks[1]["subject"] = "Affiliate sites";
$blocks[1]["content"] = $content;
$blocks[1]["info"] = "Affiliate sites (sequential)";
return $blocks;
}
function affiliate_admin_add($name, $url, $contact) {
db_query("INSERT INTO affiliates (name, link, contact) VALUES ('". check_input($name) ."', '". check_input($url) ."', '". check_input($contact) ."')");
}
function affiliate_admin_del($id) {
db_query("DELETE FROM affiliates WHERE id = '$id'");
}
function affiliate_admin_display() {
$result = db_query("SELECT * FROM affiliates ORDER BY name");
$output .= "<FORM ACTION=\"admin.php?mod=affiliate-site\" METHOD=\"post\">\n";
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR><TH>name</TH><TH>link</TH><TH>contact</TH><TH>operations</TH></TR>\n";
while ($affiliate = db_fetch_object($result)) {
$output .= " <TR><TD>". check_output($affiliate->name) ."</TD><TD>". format_url($affiliate->link) ."</TD><TD>". format_email($affiliate->contact) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=affiliate-site&op=delete&id=$affiliate->id\">delete</A></TD></TR>\n";
}
$output .= " <TR><TD><INPUT TYPE=\"text\" NAME=\"name\"></TD><TD><INPUT TYPE=\"text\" NAME=\"url\"></TD><TD><INPUT TYPE=\"text\" NAME=\"contact\"></TD><TD><INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Add affiliate site\"></TD></TR>\n";
$output .= "</TABLE>\n";
$output .= "</FORM>\n";
print $output;
}
function affiliate_admin() {
global $op, $id, $name, $url, $contact;
print "<SMALL><A HREF=\"admin.php?mod=affiliate-site\">overview</A> | <A HREF=\"admin.php?mod=affiliate-site&op=help\">help</A></SMALL><HR>\n";
switch($op) {
case "Add affiliate site":
affiliate_admin_add($name, $url, $contact);
affiliate_admin_display();
break;
case "delete":
affiliate_admin_del($id);
affiliate_admin_display();
break;
case "help":
affiliate_help();
break;
default:
affiliate_admin_display();
}
}
?>