drupal-site.module 2.98 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
Dries's avatar
 
Dries committed
2 3 4 5 6 7 8 9 10

$module = array("block" => "drupal_block",
                "admin" => "drupal_admin");

function drupal_block() {
  global $site_url;

  $result = db_query("SELECT * FROM drupals ORDER BY name");

Dries's avatar
 
Dries committed
11
  $content .= "<SCRIPT>\n";
Dries's avatar
 
Dries committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  $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=\"drupal\" ONCHANGE=\"gotosite(this.options[this.selectedIndex].value)\">\n";
  $content .= "  <OPTION VALUE=\"$site_url\">select a site</OPTION>\n";
  while ($drupal = db_fetch_object($result)) {
    $content .= "  <OPTION VALUE=\"$drupal->link\">$drupal->name</OPTION>\n";
  }

  $content .= " </SELECT>\n";
  $content .= "</FORM>\n";
  $content .= "</CENTER>\n";
Dries's avatar
 
Dries committed
32

Dries's avatar
 
Dries committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
  $blocks[0]["subject"] = "Drupal sites";
  $blocks[0]["content"] = $content;
  $blocks[0]["info"] = "Drupal sites (selection)";

  unset($content);

  $result = db_query("SELECT * FROM drupals ORDER BY name");
  while ($drupal = db_fetch_object($result)) {
    $content .= "<LI><A HREF=\"$drupal->link\">$drupal->name</A></LI>\n";
  }

  $blocks[1]["subject"] = "Drupal sites";
  $blocks[1]["content"] = $content;
  $blocks[1]["info"] = "Drupal sites (sequential)";
Dries's avatar
 
Dries committed
47

Dries's avatar
 
Dries committed
48 49 50
  return $blocks;
}

Dries's avatar
 
Dries committed
51 52
function drupal_admin_add($name, $url, $contact) {
  db_query("INSERT INTO drupals (name, link, contact) VALUES ('". check_input($name) ."', '". check_input($url) ."', '". check_input($contact) ."')");
Dries's avatar
 
Dries committed
53 54 55 56 57 58 59 60 61
}

function drupal_admin_del($id) {
  db_query("DELETE FROM drupals WHERE id = '$id'");
}

function drupal_admin_display() {
  $result = db_query("SELECT * FROM drupals ORDER BY name");

Dries's avatar
 
Dries committed
62
  $output .= "<FORM ACTION=\"admin.php?mod=drupal-site\" METHOD=\"post\">\n";
Dries's avatar
 
Dries committed
63 64 65 66
  $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 ($drupal = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
67
    $output .= " <TR><TD>$drupal->name</TD><TD>". format_url($drupal->link) ."</TD><TD>". format_email($drupal->contact) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=drupal-site&op=delete&id=$drupal->id\">delete</A></TD></TR>\n";
Dries's avatar
 
Dries committed
68 69
  }

Dries's avatar
 
Dries committed
70
  $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 drupal site\"></TD></TR>\n";
Dries's avatar
 
Dries committed
71 72 73 74 75 76 77
  $output .= "</TABLE>\n";
  $output .= "</FORM>\n";

  print $output;
}

function drupal_admin() {
Dries's avatar
 
Dries committed
78
  global $op, $id, $name, $url, $contact;
Dries's avatar
 
Dries committed
79 80

  switch($op) {
Dries's avatar
 
Dries committed
81
    case "Add drupal site":
Dries's avatar
 
Dries committed
82
      drupal_admin_add($name, $url, $contact);
Dries's avatar
 
Dries committed
83 84 85 86 87 88 89 90 91 92 93 94
      drupal_admin_display();
      break;
    case "delete":
      drupal_admin_del($id);
      drupal_admin_display();
      break;
    default:
      drupal_admin_display();
  }
}

?>