2001-03-10 11:07:52 +00:00
<?php
2000-12-23 15:20:10 +00:00
2000-12-24 15:44:29 +00:00
$module = array("page" => "block_page",
2001-01-13 16:33:19 +00:00
"help" => "block_help",
2000-12-24 15:44:29 +00:00
"admin" => "block_admin");
2001-01-13 16:33:19 +00:00
function block_help() {
?>
2001-02-05 16:42:38 +00:00
<P>Blocks are the boxes visible in the side bars on the left- and right-hand side of the website. They are either exported by the engine or by any of the active modules. To really get your teeth into a drupal website, you are going to have to deal with blocks and administering blocks in a fairly sophisticated fashion. This means you will need to understand how the block placement strategy works.</P>
<P>The placement of blocks is delegated to the administrator. In most cases (i.e., the "custom" blocks), the user has complete control -- using preferences -- over whether or not they are enabled.</P>
<P>An administrator can lay out and arrange the available blocks to fit in two regions: "left" and "right". Regions simply contain blocks. In addition, an administrator can assign each block (within a region) a weight to sort them vertically. The heavier blocks will sink and the lighter blocks will be positioned nearer the top.</P>
<P>As mentioned, blocks may be arranged to fit in two regions: left and right. For theme builders, each region is identified by a corresponding constant: "left" and "right".</P>
2001-03-10 11:07:52 +00:00
<?php
2001-01-13 16:33:19 +00:00
}
2000-12-24 15:44:29 +00:00
function block_page() {
global $theme;
$result = db_query("SELECT * FROM blocks WHERE status = 1 ORDER BY module");
2001-01-26 13:38:46 +00:00
2000-12-24 15:44:29 +00:00
$theme->header();
print "<TABLE BORDER=\"0\">\n";
while ($block = db_fetch_object($result)) {
if ($state % 3 == 0) print " <TR>\n";
2001-01-26 13:38:46 +00:00
print " <TD ALIGN=\"center\" VALIGN=\"top\" WIDTH=\"33%\">\n";
2000-12-24 15:44:29 +00:00
$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;
2001-01-26 13:38:46 +00:00
}
2000-12-24 15:44:29 +00:00
print "</TABLE>\n";
$theme->footer();
}
2000-12-23 15:20:10 +00:00
function block_admin_save($edit) {
foreach ($edit as $key=>$value) {
2001-03-07 21:29:40 +00:00
db_query("UPDATE blocks SET region = '". check_input($value[region]) ."', status = '". check_input($value[status]) ."', weight = '". check_input($value[weight]) ."' WHERE name = '". check_input($key) ."'");
2000-12-23 15:20:10 +00:00
}
}
function block_admin_display() {
global $repository;
2000-12-24 15:44:29 +00:00
$result = db_query("SELECT * FROM blocks ORDER BY module");
2001-01-26 13:38:46 +00:00
2000-12-23 15:20:10 +00:00
// Generate output:
$output .= "<FORM ACTION=\"admin.php?mod=block\" METHOD=\"post\">\n";
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2001-01-13 16:33:19 +00:00
$output .= " <TR><TH>block</TH><TH>module</TH><TH>status</TH><TH>weight</TH><TH>region</TH></TR>\n";
2001-01-26 13:38:46 +00:00
2000-12-23 15:20:10 +00:00
while ($block = db_fetch_object($result)) {
$module = ($repository[$block->module]["admin"]) ? "<A HREF=\"admin.php?mod=$block->module\">$block->module</A>" : $block->module;
2001-01-13 16:33:19 +00:00
$status .= "<SELECT NAME=\"edit[$block->name][status]\">\n";
2000-12-29 11:00:56 +00:00
$status .= " <OPTION VALUE=\"2\"". (($block->status == 2) ? " SELECTED" : "") .">enabled: always</OPTION>\n";
$status .= " <OPTION VALUE=\"1\"". (($block->status == 1) ? " SELECTED" : "") .">enabled: custom</OPTION>\n";
2000-12-23 15:20:10 +00:00
$status .= " <OPTION VALUE=\"0\"". (($block->status == 0) ? " SELECTED" : "") .">disabled</OPTION>\n";
$status .= "</SELECT>\n";
2001-01-13 16:33:19 +00:00
$weight .= "<SELECT NAME=\"edit[$block->name][weight]\">\n";
for ($count = 0; $count < 10; $count++) {
$weight .= "<OPTION VALUE=\"$count\"". (($block->weight == $count) ? " SELECTED" : "") .">$count</OPTION>\n";
}
$weight .= "</SELECT>\n";
$region .= "<SELECT NAME=\"edit[$block->name][region]\">\n";
$region .= " <OPTION VALUE=\"0\"". (($block->region == 0) ? " SELECTED" : "") .">left</OPTION>\n";
$region .= " <OPTION VALUE=\"1\"". (($block->region == 1) ? " SELECTED" : "") .">right</OPTION>\n";
$region .= "</SELECT>\n";
$output .= " <TR><TD>". $block->name ."</TD><TD ALIGN=\"center\">$module</TD><TD>$status</TD><TD>$weight</TD><TD>$region</TD></TR>\n";
2001-01-26 13:38:46 +00:00
2000-12-23 15:20:10 +00:00
unset($status);
2001-01-13 16:33:19 +00:00
unset($weight);
unset($region);
2000-12-23 15:20:10 +00:00
}
2001-01-26 13:38:46 +00:00
2000-12-23 15:20:10 +00:00
$output .= "</TABLE>\n";
$output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Save blocks\">\n";
$output .= "</FORM>\n";
print $output;
}
2001-01-13 16:33:19 +00:00
function block_admin_overview() {
$result = db_query("SELECT * FROM blocks WHERE status > 0 AND region = 0 ORDER BY weight");
$lblocks .= "<TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
while ($block = db_fetch_object($result)) $lblocks .= " <TR><TD NOWRAP>". ($block->status == 2 ? "<B>$block->name</B>" : $block->name) ."</TD><TD>$block->weight</TD></TR>\n";
$lblocks .= "</TABLE>\n";
$result = db_query("SELECT * FROM blocks WHERE status > 0 AND region = 1 ORDER BY weight");
$rblocks .= "<TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
while ($block = db_fetch_object($result)) $rblocks .= " <TR><TD NOWRAP>". ($block->status == 2 ? "<B>$block->name</B>" : $block->name) ."</TD><TD>$block->weight</TD></TR>\n";
$rblocks .= "</TABLE>\n";
2001-01-26 13:38:46 +00:00
2001-01-13 16:33:19 +00:00
$output .= "<P><B>layout 1:</B></P>\n";
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"3\">header</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= " <TR><TD>\n". ($lblocks ? $lblocks : " ") ."</TD><TD WIDTH=\"300\"> </TD><TD>\n". ($rblocks ? $rblocks : " ") ."</TD></TR>\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"3\">footer</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= "</TABLE>\n";
$result = db_query("SELECT * FROM blocks WHERE status > 0 ORDER BY weight");
$blocks .= "<TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
while ($block = db_fetch_object($result)) $blocks .= " <TR><TD NOWRAP>". ($block->status == 2 ? "<B>$block->name</B>" : $block->name) ."</TD><TD>$block->weight</TD></TR>\n";
$blocks .= "</TABLE>\n";
$output .= "<P><B>layout 2:</B></P>\n";
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">header</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= " <TR><TD WIDTH=\"400\"> </TD><TD>\n". ($blocks ? $blocks : " ") ."</TD></TR>\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">footer</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= "</TABLE>\n";
$output .= "<P><B>layout 3:</B></P>\n";
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">header</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= " <TR><TD>\n". ($blocks ? $blocks : " ") ."</TD><TD WIDTH=\"400\"> </TD></TR>\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">footer</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= "</TABLE>\n";
print $output;
}
2000-12-23 15:20:10 +00:00
function block_admin() {
global $op, $edit;
2001-01-26 13:38:46 +00:00
2001-01-13 16:33:19 +00:00
print "<SMALL><A HREF=\"admin.php?mod=block\">configure</A> | <A HREF=\"admin.php?mod=block&op=overview\">overview</A> | <A HREF=\"admin.php?mod=block&op=help\">help</A></SMALL><HR>\n";
2000-12-23 15:20:10 +00:00
switch ($op) {
2001-01-13 16:33:19 +00:00
case "help":
block_help();
break;
case "overview":
block_admin_overview();
break;
2000-12-23 15:20:10 +00:00
case "Save blocks":
block_admin_save($edit);
2001-01-13 16:33:19 +00:00
// fall through
default:
block_admin_display();
2000-12-23 15:20:10 +00:00
}
2001-01-26 13:38:46 +00:00
2000-12-23 15:20:10 +00:00
}
?>