--- 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 .= "
'. $form .'
'; - 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 .= "'. drupal_get_form('subscription_admin_channels', $form) .'
'; + 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 = "