affiliate-site.module 3.53 KB
Newer Older
Dries's avatar
 
Dries committed
1 2
<?

Dries's avatar
 
Dries committed
3 4
$module = array("help" => "affiliate_help",
                "block" => "affiliate_block",
Dries's avatar
 
Dries committed
5 6
                "admin" => "affiliate_admin");

Dries's avatar
 
Dries committed
7 8
function affiliate_help() {
 ?>
Dries's avatar
 
Dries committed
9
  <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>
Dries's avatar
 
Dries committed
10 11 12
 <?
}

Dries's avatar
 
Dries committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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";

Dries's avatar
 
Dries committed
28
  $content .= "<CENTER>\n";
Dries's avatar
 
Dries committed
29 30 31 32 33 34 35 36 37
  $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";
Dries's avatar
 
Dries committed
38
  $content .= "</CENTER>\n";
Dries's avatar
 
Dries committed
39

Dries's avatar
 
Dries committed
40
  $blocks[0]["subject"] = "Affiliate sites";
Dries's avatar
 
Dries committed
41
  $blocks[0]["content"] = $content;
Dries's avatar
 
Dries committed
42
  $blocks[0]["info"] = "Affiliate sites (selection)";
Dries's avatar
 
Dries committed
43 44 45 46 47 48 49 50

  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";
  }

Dries's avatar
 
Dries committed
51
  $blocks[1]["subject"] = "Affiliate sites";
Dries's avatar
 
Dries committed
52
  $blocks[1]["content"] = $content;
Dries's avatar
 
Dries committed
53
  $blocks[1]["info"] = "Affiliate sites (sequential)";
Dries's avatar
 
Dries committed
54

Dries's avatar
 
Dries committed
55 56 57
  return $blocks;
}

Dries's avatar
 
Dries committed
58 59
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) ."')");
Dries's avatar
 
Dries committed
60 61 62 63 64 65 66 67 68
}

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");

Dries's avatar
 
Dries committed
69
  $output .= "<FORM ACTION=\"admin.php?mod=affiliate-site\" METHOD=\"post\">\n";
Dries's avatar
 
Dries committed
70 71 72 73
  $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)) {
Dries's avatar
 
Dries committed
74
    $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";
Dries's avatar
 
Dries committed
75 76
  }

Dries's avatar
 
Dries committed
77
  $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";
Dries's avatar
 
Dries committed
78 79 80 81 82 83 84
  $output .= "</TABLE>\n";
  $output .= "</FORM>\n";

  print $output;
}

function affiliate_admin() {
Dries's avatar
 
Dries committed
85
  global $op, $id, $name, $url, $contact;
Dries's avatar
 
Dries committed
86

Dries's avatar
 
Dries committed
87 88
  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";

Dries's avatar
 
Dries committed
89
  switch($op) {
Dries's avatar
 
Dries committed
90 91
    case "Add affiliate site":
      affiliate_admin_add($name, $url, $contact);
Dries's avatar
 
Dries committed
92 93 94 95 96 97
      affiliate_admin_display();
      break;
    case "delete":
      affiliate_admin_del($id);
      affiliate_admin_display();
      break;
Dries's avatar
 
Dries committed
98 99 100
    case "help":
      affiliate_help();
      break;
Dries's avatar
 
Dries committed
101 102 103 104 105 106
    default:
      affiliate_admin_display();
  }
}

?>