--- user_mailman_register.module	Tue Feb 12 04:09:58 2008
+++ user_mailman_register.module	Fri Feb 15 17:27:36 2008
@@ -95,17 +95,18 @@ function _user_mailman_register_form($ac
     $form['user_mailman_register']['lists'] = array(
                                                     '#type' => 'fieldset',
                                                     '#title' => t('Mailing list subscription'),
-                                                    '#description' => t('Join a mailing list to receive or partecipate in its discussions via email.'),
+                                                    '#description' => t('Join a mailing list to receive or participate in its discussions via email.'),
                                                     '#collapsible' => FALSE 
                                                     );
     foreach ($lists as $list) {
-      if (!$list['webadmin']||!$list['webpass']) {
+      if (!$list['webadmin'] || !$list['webpass'] || !user_access("can subscribe to ".$list['name'])) {
         continue;
       }
       $lstatus = 0;
       $form['user_mailman_register']['lists']['list'. trim($list['lid'])] = array(
                                                                                  '#type' => 'fieldset',
                                                                                  '#title' => $list['name'],
+                                                                                 '#description' => $list['description'],
                                                                                  '#collapsible' => TRUE
                                                                                  );
       if ($account) {
@@ -115,17 +116,26 @@ function _user_mailman_register_form($ac
 
       if ($lstatus == 0) {
         $title = t('Subscribe to ') . $list['name'] ."?";
-        $options = array( '3' => t('Yes'), '0' => t('No'));
+        if ($list['allow_unsubscribe'])
+          $options['0'] = t('No');
+        $options['3'] = t('Yes');
       } 
       else {
         $title = t('Change your subscription');
-        $options = array('0' => t('Unsubscribe'),
-                         '1' => t('No mail (temporarily disable delivery)'),
-                         '2' => t('Subscribe for digest (receive emails in a bundle)'),
-                         '3' => t('Subscribe for all Mail (normal delivery)')
-                         );
+        if ($list['allow_unsubscribe'])
+          $options['0'] = t('Unsubscribe');
+        if ($list['allow_temp_disable'])
+          $options['1'] = t('No mail (temporarily disable delivery)');
+        if ($list['allow_digest']) {
+          $options['2'] = t('Subscribe for digest (receive emails in a bundle)');
+          $options['3'] = t('Subscribe for all mail (normal delivery)');
+        }
+        else
+          $options['3'] = t('Subscribe');
       }
 
+      if (!$account) $lstatus = 3; // feeds default values of "yes" into the form on new-user registration
+
       $form['user_mailman_register']['lists']['list'. trim($list['lid'])]['options'. trim($list['lid'])] = array(
                                                                                                                 '#type' => 'radios',
                                                                                                                 '#title' => $title,
@@ -318,6 +328,10 @@ function user_mailman_register_admin() {
                    array('data' => t('User invite'), 'field' => 'user_invite'),
                    array('data' => t('User notify'), 'field' => 'user_notify'),
                    array('data' => t('list admins notify'), 'field' => 'user_admin_notify'),
+                   array('data' => t('allow unsubscribe'), 'field' => 'allow_unsubscribe'),
+                   array('data' => t('allow temporary disable'), 'field' => 'allow_temp_disable'),
+                   array('data' => t('allow digest'), 'field' => 'allow_digest'),
+                   array('data' => t('Description'), 'field' => 'description'),
                    );
   
     
@@ -471,6 +485,30 @@ function user_mailman_register_adminedit
                                       '#description' => t('Send notifications of new subscription to the list owner?'),
                                       '#type' => 'checkbox',
                                       );
+  $form['allow_unsubscribe'] = array(
+    '#title' => t('Allow unsubscribe'),
+    '#default_value' => $list->allow_unsubscribe,
+    '#description' => t('Allow users to unsubscribe from the list? This is equivalent to forcing subscription to this list.'),
+    '#type' => 'checkbox',
+    );
+  $form['allow_temp_disable'] = array(
+    '#title' => t('Allow temporary disable'),
+    '#default_value' => $list->allow_temp_disable,
+    '#description' => t('Allow users to temporarily disable delivery?'),
+    '#type' => 'checkbox',
+    );
+  $form['allow_digest'] = array(
+    '#title' => t('Allow digest'),
+    '#default_value' => $list->allow_digest,
+    '#description' => t('Allow users to subscribe in digest mode?'),
+    '#type' => 'checkbox',
+    );
+  $form['description'] = array(
+    '#title' => t('Description'),
+    '#default_value' => $list->description,
+    '#description' => t('A brief description of this mailing list. This text will be displayed in the subscriptions page.'),
+    '#type' => 'textarea',
+    );
 
   $form['lid'] = array('#type' => 'hidden', '#value' => $id );
   $form['name'] = array('#type' => 'hidden', '#value' => $list->name );
@@ -493,13 +531,17 @@ function user_mailman_register_adminedit
     return;
   }
   //Update existin
-  $query = "UPDATE {mailman_lists} SET webadmin = '%s', webpass = '%s', user_invite = '%s', user_notify = '%s', user_admin_notify = '%s' WHERE lid = %d";
+  $query = "UPDATE {mailman_lists} SET webadmin = '%s', webpass = '%s', user_invite = '%s', user_notify = '%s', user_admin_notify = '%s', allow_unsubscribe = '%s', allow_temp_disable = '%s', allow_digest = '%s', description = '%s' WHERE lid = %d";
   $result = db_query($query, 
                      $form_values['webadmin'], 
                      $form_values['webpass'], 
                      $form_values['user_invite'], 
                      $form_values['user_notify'], 
                      $form_values['user_admin_notify'],
+                     $form_values['allow_unsubscribe'],
+                     $form_values['allow_temp_disable'],
+                     $form_values['allow_digest'],
+                     $form_values['description'],
                      $form_values['lid']
                      );
   
@@ -519,7 +561,14 @@ function user_mailman_register_adminedit
  * Implementation of hook_perm().
  */
 function user_mailman_register_perm() {
-  return array('access user_mailman_register');
+  $permStrings = array('access user_mailman_register');
+  $lists = _mailman_manager_get_lists();
+  if (count($lists) > 0) {
+    foreach ($lists as $list) {
+      $permStrings[] = "can subscribe to ".$list['name'];
+    }
+  }
+  return $permStrings;
 }
 
 
