2001-03-10 11:07:52 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2000-12-23 15:20:10 +00:00
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
}
2001-06-20 20:00:40 +00:00
function block_perm() {
2001-06-29 22:08:57 +00:00
return array("administer blocks");
}
function block_link($type) {
2001-07-07 14:58:54 +00:00
if ($type == "admin" && user_access("administer blocks")) {
2001-06-29 22:08:57 +00:00
$links[] = "<a href=\"admin.php?mod=block\">blocks</a>";
}
return $links ? $links : array();
2001-06-20 20:00:40 +00:00
}
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() {
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)) {
2001-05-05 13:57:29 +00:00
$module = module_hook($block->module, "admin") ? "<A HREF=\"admin.php?mod=$block->module\">$block->module</A>" : $block->module;
2000-12-23 15:20:10 +00:00
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-06-18 18:00:13 +00:00
function block_admin_preview() {
2001-01-13 16:33:19 +00:00
$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-06-18 18:00:13 +00:00
$output .= "<H3>layout scheme #1:</H3>\n";
2001-01-13 16:33:19 +00:00
$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";
2001-06-18 18:00:13 +00:00
$output .= "<H3>layout scheme #2:</H3>\n";
2001-01-13 16:33:19 +00:00
$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";
2001-06-18 18:00:13 +00:00
$output .= "<H3>layout scheme #3:</H3>\n";
2001-01-13 16:33:19 +00:00
$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;
}
2001-06-23 11:09:40 +00:00
function block_init() {
2001-10-16 20:13:22 +00:00
2001-06-23 11:09:40 +00:00
$result = db_query("SELECT * FROM modules");
while ($module = db_fetch_object($result)) {
module_rehash($module->name);
}
foreach (module_list() as $name) {
module_rehash($name);
}
}
2000-12-23 15:20:10 +00:00
function block_admin() {
2001-06-29 22:08:57 +00:00
global $op, $edit;
2001-06-20 20:00:40 +00:00
2001-06-29 22:08:57 +00:00
if (user_access("administer blocks")) {
2001-06-23 11:09:40 +00:00
2001-06-20 20:00:40 +00:00
print "<SMALL><A HREF=\"admin.php?mod=block\">configure</A> | <A HREF=\"admin.php?mod=block&op=preview\">preview</A> | <A HREF=\"admin.php?mod=block&op=help\">help</A></SMALL><HR>\n";
2001-06-23 11:09:40 +00:00
block_init();
2001-06-20 20:00:40 +00:00
switch ($op) {
case "help":
block_help();
break;
case "preview":
block_admin_preview();
break;
case "Save blocks":
block_admin_save($edit);
// fall through
default:
block_admin_display();
}
}
else {
print message_access();
2000-12-23 15:20:10 +00:00
}
}
2001-10-20 18:57:09 +00:00
2000-12-23 15:20:10 +00:00
?>