block.module 2.11 KB
Newer Older
Dries's avatar
 
Dries committed
1 2
<?

Dries's avatar
 
Dries committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
$module = array("page" => "block_page",
                "admin" => "block_admin");

function block_page() {
  global $theme;

  $result = db_query("SELECT * FROM blocks WHERE status = 1 ORDER BY module");
  
  $theme->header();
  print "<TABLE BORDER=\"0\">\n";
  while ($block = db_fetch_object($result)) {
    if ($state % 3 == 0) print " <TR>\n";
    print "  <TD ALIGN=\"center\" VALIGN=\"top\" WIDTH=\"33%\">\n"; 
    $blocks = module_execute($block->module, "block");
    $theme->box($blocks[$block->offset]["subject"], $blocks[$block->offset]["content"]);
    print " </TD>\n";
    if ($state % 3 == 2) print " </TR>\n";
    $state += 1;
  }  
  print "</TABLE>\n";
  $theme->footer();
}
Dries's avatar
 
Dries committed
25 26 27 28 29 30 31 32 33 34

function block_admin_save($edit) {
  foreach ($edit as $key=>$value) {
    db_query("UPDATE blocks SET status = '$value' WHERE name = '$key'");
  }
}

function block_admin_display() {
  global $repository;

Dries's avatar
 
Dries committed
35
  $result = db_query("SELECT * FROM blocks ORDER BY module");
Dries's avatar
 
Dries committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49
  
  // Generate output:
  $output .= "<FORM ACTION=\"admin.php?mod=block\" METHOD=\"post\">\n";
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
  $output .= " <TR><TH>block</TH><TH>module</TH><TH>status</TH></TR>\n";
  
  while ($block = db_fetch_object($result)) {
    $module = ($repository[$block->module]["admin"]) ? "<A HREF=\"admin.php?mod=$block->module\">$block->module</A>" : $block->module;

    $status .= "<SELECT NAME=\"edit[$block->name]\">\n";
    $status .= " <OPTION VALUE=\"1\"". (($block->status == 1) ? " SELECTED" : "") .">enabled</OPTION>\n";
    $status .= " <OPTION VALUE=\"0\"". (($block->status == 0) ? " SELECTED" : "") .">disabled</OPTION>\n";
    $status .= "</SELECT>\n";

Dries's avatar
 
Dries committed
50
    $output .= " <TR><TD>". $block->name ."</TD><TD ALIGN=\"center\">$module</TD><TD>$status</TD></TR>\n";
Dries's avatar
 
Dries committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    
    unset($status);
  }
  
  $output .= "</TABLE>\n";
  $output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Save blocks\">\n";
  $output .= "</FORM>\n";

  print $output;
}

function block_admin() {
  global $op, $edit;

  switch ($op) {
    case "Save blocks":
      block_admin_save($edit);
      break;
  }
 
  block_admin_display();
}

?>