--- subscription.module.orig	2006-01-17 06:38:26.000000000 -0800
+++ subscription.module	2006-01-19 11:33:59.000000000 -0800
@@ -121,14 +121,9 @@
   $avail_channels = subscription_get_available_channels();
   if (!empty($_POST)) {
     $edit = $_POST['edit'];
-    if (empty($edit['name'])) {
-      form_set_error("name", t("The name is empty")); 
-    }
-    else {
-      $cid = db_next_id("subscription_channels", "cid");
-      db_query("INSERT INTO subscription_channels (cid,name,id,daily) VALUES (%d,'%s','%s',%d)", $cid, $edit['name'], $edit['id'], $edit['daily']);
-      drupal_set_message(t("Channel created succesfully"));
-    }
+    $cid = db_next_id("subscription_channels", "cid");
+    db_query("INSERT INTO subscription_channels (cid,name,id,daily) VALUES (%d,'%s','%s',%d)", $cid, $edit['name'], $edit['id'], $edit['daily']);
+    drupal_set_message(t("Channel created succesfully"));
   }
   $channels = subscription_getchannels();
   $table = array();
@@ -146,15 +141,40 @@
   foreach ($avail_channels as $channel) {
     $channel_select[$channel['id']] = $channel['name']; 
   }
-  $form = '';
-  $form .= form_textfield(t('name'), 'name', '', 30, 30);
-  $form .= form_select(t('channel'), 'id', 0, $channel_select);
-  $form .= form_select(t('daily'), 'daily', 0, array(t('instant'), t('daily')));
-  $form .= form_submit(t("Save"), "save");
-  
-  $form = form($form);
-  $page .= "<h2>". t("Add channel") .'</h2><p>'. $form .'</p>';
-  echo theme('page', $page);  
+  $form['name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('name'),
+    '#default_value' => '',
+    '#size' => 30,
+    '#maxlength' => 30,
+  );
+  $form['id'] = array(
+    '#type' => 'select',
+    '#title' => t('channel'),
+    '#default_value' => 0,
+    '#options' => $channel_select,
+  );
+  $form['daily'] = array(
+    '#type' => 'select',
+    '#title' => t('daily'),
+    '#default_value' => 0,
+    '#options' => array(t('instant'), t('daily')),
+  );
+  $form["save"] = array(
+    '#type' => 'submit',
+    '#value' => t("Save"),
+  );
+  $page .= "<h2>". t("Add channel") .'</h2><p>'. drupal_get_form('subscription_admin_channels', $form) .'</p>';
+  return $page;
+}
+/**
+ * Form validation for the "Add channel" field above.
+ */
+function subscription_admin_channels_validate($form_id, &$form) {
+  global $form_values;
+  if (!$form['name']) {
+    form_set_error('name', t("The name is empty"));
+  }
 }
 /**
  * remove a channel 
@@ -223,7 +243,7 @@
     if ($user->subscription_auto && !subscription_is_subscribed('comment', array('nid' => $comment['nid']))) {
         subscription_store('comment', array('nid' => $comment['nid']));          
     }
-    $parent_node = node_load(array('nid' => $comment['nid']));
+    $parent_node = node_load($comment['nid']);
     $new_object = (array_merge($comment, array('parent_uid' => $parent_node->uid))); 
     $newobject = array('comment' => array($comment));
     subscription_trigger($newobject);  
@@ -498,24 +518,32 @@
         foreach ($channels as $channel) {
           $channel_select[$channel['cid']] = $channel['name'];  
         }
-        
-        $group = form_select(t('Default channel'), 
-              'subscription_channel',
-              subscription_get_default_channel(),
-              $channel_select, 
-              t('Select the destination for new subscriptions.'));
-        $group .= form_checkbox(t('Automatically subscribe to those posts in which you have participated.'), 
-              'subscription_auto',
-              1,
-              isset($edit->subscriptions_auto) ? $edit->subscriptions_auto : $account->subscriptions_auto);
-        }
-        return array(array('title '=> t('Subscription settings'), 'data' => form_group(t('Subscription settings'), $group), 'weight' => 2));
-      case 'view':
-        if (user_access('manage subscriptions')  && $user->uid != $account->uid) {
-          $links[] = l(t("Subscribe to content created by this user"), 'subscription/add/user/all/' . $account->uid);
-          $links[] = l(t("Subscribe to comments to this user's content"), 'subscription/add/user/comment/' . $account->uid);
-          return array(t('Subscriptions') => theme('item_list', $links));
-        }
+        $form['subscription'] = array(
+	  '#type' => 'fieldset',
+	  '#title' => t('Subscription settings'),
+	  '#weight' => 2,
+	);
+	$form['subscription']['subscription_channel'] = array(
+	  '#type' => 'select',
+	  '#title' => t('Default channel'),
+	  '#default_value' => subscription_get_default_channel(),
+	  '#options' => $channel_select,
+	  '#description' => t('Select the destination for new subscriptions.'),
+	);
+	$form['subscription']['subscription_auto'] = array(
+	  '#type' => 'checkbox',
+	  '#title' => t('Automatically subscribe to those posts in which you have participated.'),
+	  '#return_value' => 1,
+	  '#default_value' => isset($edit->subscription_auto) ? $edit->subscription_auto : $account->subscription_auto,
+	);
+	return $form;
+      }
+    case 'view':
+      if (user_access('manage subscriptions')  && $user->uid != $account->uid) {
+	$links[] = l(t("Subscribe to content created by this user"), 'subscription/add/user/all/' . $account->uid);
+	$links[] = l(t("Subscribe to comments to this user's content"), 'subscription/add/user/comment/' . $account->uid);
+	return array(t('Subscriptions') => theme('item_list', $links));
+      }
   }
 }
 
@@ -578,11 +606,23 @@
   $page = "<h1>Current subscriptions</h1>";
   if ($roles != array()) { 
     foreach ($roles as $role) {
-      $table[] = array($role['object'], _subscription_condition_readable($role['condition']), $role['name'], l('delete', 'subscription/del/'.$role['sid']), form_checkbox('', 'merge'.$role['sid']));
-    }
-    $form = theme("table", array(t("Object"), t("Condition"), t("Channel"), t("Function"), t("Merge")), $table);
-    $form .= form_submit(t("Merge"));
-    $page .= form($form);
+      $form = array( 'subscription_list_merge'.$role['sid'] => array(
+	'#type' => 'checkbox',
+	'#title' => '',
+      ));
+      $table[] = array($role['object'],
+		       _subscription_condition_readable($role['condition']),
+		       $role['name'],
+		       l('delete', 'subscription/del/'.$role['sid']),
+		       drupal_get_form('subscription_list_'.$role['sid'], $form)
+		      );
+    }
+    $page .= theme("table", array(t("Object"), t("Condition"), t("Channel"), t("Function"), t("Merge")), $table);
+    $form = array( 'subscription_list_submit' => array(
+      '#type' => 'submit',
+      '#value' => t("Merge"),
+    ));
+    $page .= drupal_get_form('subscription_list_submit', $form);
   }
   else {
     $page .= t("Currently there are no subscriptions.");  
@@ -594,7 +634,7 @@
   $page .= "<h1>". t("Available special subscriptions") ."</h1>";
   $page .= theme('item_list', module_invoke_all('subscription', 'special'));
   
-  print theme("page", $page);
+  return $page;
 }
 /**
  * 
@@ -615,12 +655,14 @@
  * Settings menu to the administration section
  */
 function subscription_settings() {
-  $output = form_select(t('Default mode for non-digest events'), 
-    'subscription_instant_mode', 
-    variable_get('subscription_instant_mode', 0), 
-    array('0' => 'instant (small sites)', '1' => 'cronned (big sites)'), 
-    t('When to notify on new content: immediately after content is created (suggested for small sites), or after next cron run (suggested for big sites) '));
-  return $output;
+  $form['subscription_instant_mode'] = array(
+    '#type' => 'select',
+    '#title' => t('Default mode for non-digest events'),
+    '#default_value' => variable_get('subscription_instant_mode', 0),
+    '#options' => array('0' => 'instant (small sites)', '1' => 'cronned (big sites)'),
+    '#description' => t('When to notify on new content: immediately after content is created (suggested for small sites), or after next cron run (suggested for big sites) '),
+  );
+  return $form;
 }
 /* DEFAULT CHANNELS */
 function subscription_simpleformatter($object, $type) {
