Index: modules/sections/sections.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sections/sections.module,v
retrieving revision 1.6
diff -u -r1.6 sections.module
--- modules/sections/sections.module	9 Oct 2005 14:34:11 -0000	1.6
+++ modules/sections/sections.module	20 Oct 2005 19:47:36 -0000
@@ -1,12 +1,10 @@
 <?php
 // $Id: sections.module,v 1.6 2005/10/09 14:34:11 ber Exp $
-
 /**
  * @file
  * This is an example outlining how a module can be used to display a
  * custom page at a given URL.
  */
-
 /**
  * Implementation of hook_help().
  *
@@ -23,7 +21,6 @@
       return t('A module that allows you to define sections on your site and aply themes to those sections');
   }
 }
-
 /**
  * Declare administrative settings for a module.
  *
@@ -41,7 +38,7 @@
  * need to store more complicated data (for example, in a separate table),
  * define your own administration page and link to it using hook_menu().
  */
-function sections_settings() {
+function sections_settings_list() {
   $header = array(t('Section'), t('Enabled'), t('Template'), array('data' => t('Operations')) );
   
   foreach(_sections_load() as $section) {
@@ -54,7 +51,6 @@
   }
   return theme('table', $header, $rows);
 }
-
 function sections_settings_form($edit = NULL, $section = NULL) {
   if ($section && !$_POST['op']) {
     foreach ($section as $key => $value) {
@@ -65,7 +61,6 @@
     $edit = $_POST['edit'];
     $op = $_POST['op'];
   }
-
   switch ($op) {
     case t('Save section'):
       db_query("UPDATE {sections_data} SET name = '%s', status = '%d', template = '%s', path = '%s' WHERE sid = '%d'", $edit['name'], $edit['status'], $edit['template'], $edit['path'], $edit['sid']);     
@@ -82,32 +77,53 @@
       drupal_goto('admin/settings/sections/');
     default:
       // Standard sections configurations.
-      $group = form_textfield(t('Name'), 'name', $edit['name'], 40, 64, t("Give the name of the section"), NULL, TRUE);
-      $group .= form_textarea(t('Pages'), 'path', $edit['path'], 40, 5, t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em>&lt;front&gt;</em>' is the front page. "));
-      
-      $group .= form_checkbox(t('Enabled'), 'status', 1, $edit['status'], t('Enable or disable this section'));
-      
-      $group .= form_select(t('Select template'), 'template', $edit['template'], _sections_theme_select(), t('Select the template you want to use for this section'));
-
-      $form .= form_group(t('Section settings'), $group);
+      $form['general'] = array(
+        '#type' => 'fieldset', '#title' => t('Section settings'),
+        '#weight' => 1
+      );
+      $form['general']['name'] = array(
+        '#type' => 'textfield', '#title' => t('Name'), 
+        '#default_value' => $edit['name'],
+        '#size' => 40, '#maxlength' => 64,
+        '#required' => TRUE,
+        '#weight' => 1,
+        '#description' => t('Give the name of the section')
+      );
+      $form['general']['path'] = array(
+        '#type' => 'textarea', '#title' => t('Pages'), 
+        '#default_value' => $edit['path'],
+        '#weight' => 2,
+        '#size' => 40, '#maxlength' => 5,
+        '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em>&lt;front&gt;</em>' is the front page. ")
+      );
+      $form['general']['status'] = array(
+        '#type' => 'checkbox', '#title' => t('Enabled'), 
+        '#default_value' => $edit['status'], 
+        '#weight' => 3,
+        '#description' => t('Enable or disable this section')
+      );
+      $form['general']['template'] = array(
+        '#type' => 'select', '#title' => t('Select template'), 
+        '#default_value' => $edit['template'], 
+        '#options' => _sections_theme_select(),
+        '#weight' => 4,
+        '#description' => t('Select the template you want to use for this section')
+      );
       
       if($edit['sid']) {
         //we are updating
-        $form .= form_hidden('sid', $edit['sid']);
-        $form .= form_submit(t('Save section'));
+        $form['sid'] = array('#type' => 'hidden', '#value' => $edit['sid']);
+        $form['submit'] = array('#type' => 'submit', '#value' => t('Save section'), '#weight' => 99);
       }
       else {
         //we are adding
-        $form .= form_submit(t('Add section'));
+        $form['submit'] = array('#type' => 'submit', '#value' => t('Add section'), '#weight' => 99);
       }
-
-      print theme('page', form($form));
-  }
+      return drupal_get_form('sections_settings_form', $form);
+    }
 }
-
 function _sections_delete($section) {
   $op = $_POST['op'];
-
   switch ($op) {
     case t('Delete'):
       db_query('DELETE FROM {sections_data} WHERE sid = %d', $section->sid);
@@ -115,17 +131,14 @@
       cache_clear_all();
       drupal_goto('admin/settings/sections');
       break;
-
     default:
       $form = '<p>'. t('Are you sure you want to delete the section %name?', array('%name' => '<em>'. $ection->name .'</em>')) ."</p>\n";
       $form .= form_submit(t('Delete'));
       $output = form($form);
       break;
   }
-
-  print theme('page', $output);
+  return $output;
 }
-
 /**
  * Implementation of hook_perm().
  *
@@ -135,9 +148,8 @@
  * administration pages.
  */
 function sections_perm() {
-  return array('adminster sections');
+  return array('administer sections');
 }
-
 /**
  * Implementation of hook_menu().
  */
@@ -153,15 +165,15 @@
   */
   
   if ($may_cache) {
-    $access = user_access('adminster sections');
+    $access = user_access('administer sections');
     
     // This is the minimum information you can provide for a menu item.
     $items[] = array('path' => 'admin/settings/sections', 'title' => t('sections settings'),
-      'callback' => 'sections_settings',
+      'callback' => 'sections_settings_list',
       'access' => $access);
  
     $items[] = array('path' => 'admin/settings/sections/list', 'title' => t('list'),
-      'callback' => 'sections_settings',
+      'callback' => 'sections_settings_list',
       'access' => $access,
       'type' => MENU_DEFAULT_LOCAL_TASK);
     $items[] = array('path' => 'admin/settings/sections/add', 'title' => t('add'),
@@ -185,10 +197,8 @@
   else if ($section = sections_in_section()) {
     $custom_theme = $section->template;
   }
-
   return $items;
 }
-
 function _sections_load() {
   $sections = array();
   
@@ -199,28 +209,23 @@
   }
   return $sections;
 }
-
 /**
  * Loads the section names
  */
-
 function _section_load($section_name) {
   return db_fetch_object(db_query('SELECT * FROM {sections_data} WHERE n.name = %s', $section_name));
 }
-
 /**
  * Loads the options for the themes select form element 
  */
 function _sections_theme_select() {
   $themes = list_themes();
   $options = array();
-
   foreach (array_keys($themes) as $name) {
     $options[$name] = $name;
   }
   return $options;
 }
-
 /**
  * An API for modules that want to know about sections.
  *
@@ -248,11 +253,9 @@
    
     $res = db_query("SELECT path, status, template FROM {sections_data} WHERE status=1");
     while ($row = db_fetch_object($res)) {
-
         // This bizarre bit of magic courtesy of block.module
         $path = drupal_get_path_alias($_GET['q']);
         $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($row->path, '/')) .')$/';
-
       if(preg_match($regexp, $path) && !($path == 'admin/block')) {
        return $row;
       }
