--- notify.module	5 Jan 2007 07:53:43 -0000	2.67
+++ notify.module	29 Mar 2007 15:27:42 -0000
@@ -53,6 +53,49 @@
     '#options' => array(t('Disabled'), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20),
   );
 
+		$set = "notify_page_master";
+  $form[$set] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Default Master switch'),
+    '#collapsible' => true,
+    '#collapsed' => false,
+		);
+		$form[$set]['notify_default_receive'] = array(
+				'#title' => t('Notify status'),
+				'#type' => 'radios',
+				'#default_value' => variable_get('notify_default_receive', t('Enabled')),
+				'#options' => array(t('Disabled'), t('Enabled')),
+				'#description' => t('Have new users receive notifications by default?'),
+		);
+
+		$form['notify_page_detailed'] = array(
+				'#type' => 'fieldset',
+				'#title' => t('Default Detailed settings'),
+    '#collapsible' => true,
+    '#collapsed' => false,
+		);
+		$form['notify_page_detailed']['notify_default_node'] = array(
+				'#title' => t('Notify new content'),
+				'#type' => 'radios',
+				'#default_value' => variable_get('notify_default_node', t('Enabled')),
+				'#options' => array(t('Disabled'), t('Enabled')),
+				'#description' => t('Include new content in the notification mail.'),
+		);
+		$form['notify_page_detailed']['notify_default_teasers'] = array(
+				'#type' => 'radios',
+				'#title' => t('Content'),
+				'#default_value' => variable_get('notify_default_teasers', t('Title + Teaser')),
+				'#options' => array(t('Title only'), t('Title + Teaser'),t('Title + Body')),
+				'#description' => t('Select the amount of each post that you would like to see in the notification e-mails.'),
+		);
+		$form['notify_page_detailed']['notify_default_comments'] = array(
+				'#type' => 'radios',
+				'#title' => t('Notify new comments'),
+				'#default_value' => variable_get('notify_default_comments', t('Disabled')),
+				'#options' => array(t('Disabled'), t('Enabled')),
+				'#description' => t('Include new comments in the notification mail.'),
+		);
+
   return system_settings_form($form);
 }
 
@@ -74,6 +117,73 @@
     case 'delete':
       db_query('DELETE FROM {notify} WHERE uid = %d', $user->uid);
       break;
+
+				case 'register':
+						if (user_access('access notify')) {
+								$form['notify_page_master'] = array(
+										'#type' => 'fieldset',
+										'#title' => t('Content Email Notifications'),
+								);
+								$form['notify_page_master']['notify_receive'] = array(
+										'#type' => 'checkboxes',
+										'#title' => t('Notify status'),
+										'#default_value' => variable_get('notify_receive', 'Enabled'),
+										'#options' => array('Enabled' => t('Keep me informed of new content on this site')),
+										'#description' => t('Do you wish to receive periodic e-mails when new content is posted?'),
+								);
+
+								if (user_access('configure own notifications')) {
+										$form['notify_page_master']['notify_default'] = array(
+												'#type' => 'checkboxes',
+										  '#default_value' => 'Enabled',
+										  '#options' =>  array('Enabled' => t('Use site defaults')),
+										  '#description' => t('If selected, site defaults will override any selections made below'),
+										);
+										$form['notify_page_master']['notify_node'] = array(
+												'#type' => 'radios',
+										  '#title' => t('Notify new content'),
+										  '#default_value' => variable_get('notify_default_node', t('Enabled')),
+										  '#options' => array(t('Disabled'), t('Enabled')),
+										  '#description' => t('Include new content in the notification mail.'),
+										);
+										$form['notify_page_master']['notify_teasers'] = array(
+												'#type' => 'radios',
+										  '#title' => t('Content'),
+												'#default_value' => variable_get('notify_default_teasers', t('Title + Teaser')),
+										  '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')),
+										  '#description' => t('Select the amount of each post that you would like to see in your notification e-mails.'),
+										);
+										$form['notify_page_master']['notify_comment'] = array(
+												'#type' => 'radios',
+										  '#title' => t('Notify new comments'),
+												'#default_value' => variable_get('notify_default_comments', t('Disabled')),
+										  '#options' => array(t('Disabled'), t('Enabled')),
+										  '#description' => t('Include new comments in the notification mail.'),
+										);
+								}
+								else {
+										$form['notify_page_master']['notify_default'] = array(
+												'#type' => 'hidden',
+										  '#value' => 1,
+										);
+								}
+
+								return $form;
+						}
+						break;
+
+
+				case 'insert':
+						if (is_array($edit['notify_default'])) {
+								$use_default = $edit['notify_default']['Enabled'];
+						}
+						else {
+								$use_default = $edit['notify_default'];
+						}
+						db_query('INSERT INTO {notify} (uid, status, node, teasers, comment, use_default) VALUES(%d, %d, %d, %d, %d, %d)', $edit['uid'], $edit['notify_receive']['Enabled'], $edit['notify_node'], $edit['notify_teasers'], $edit['notify_comment'], $use_default);
+
+						//drupal_set_message(t('Notify settings saved.'));
+						break;
   }
 }
 
@@ -81,7 +191,7 @@
  * Implementation of hook_perm().
  */
 function notify_perm() {
-  return array('access notify', 'administer notify');
+  return array('access notify', 'configure own notifications', 'administer notify');
 }
 
 /**
@@ -96,7 +206,7 @@
       'title' => t('My notification settings'),
       'callback' => 'drupal_get_form',
       'callback arguments' => array('notify_user_settings_form', $user->uid),
-      'access' => user_access('access notify'),
+      'access' => user_access('access notify') && $user->uid,
       'type' => MENU_LOCAL_TASK,
     );
     $items[] = array('path' => 'admin/user/user/notify',
@@ -146,7 +256,7 @@
     return;
   }
 
-  $result = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE u.uid = %d AND u.status = 1', $account->uid);
+  $result = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment, n.use_default FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE u.uid = %d AND u.status = 1', $account->uid);
   $notify = db_fetch_object($result);
   $form = array();
   if ($notify->mail) {
@@ -158,25 +268,34 @@
       '#description' => t('Do you wish to receive periodic e-mails when new content is posted?'),
     );
 
-    $form['notify_page_detailed'] = array('#type' => 'fieldset', '#title' => t('Detailed settings'));
-    $form['notify_page_detailed']['node'] = array('#type' => 'radios',
-      '#title' => t('Notify new content'),
-      '#default_value' => $notify->node,
-      '#options' => array(t('Disabled'), t('Enabled')),
-      '#description' => t('Include new content in the notification mail.'),
-    );
-    $form['notify_page_detailed']['teasers'] = array('#type' => 'radios',
-      '#title' => t('Content'),
-      '#default_value' => $notify->teasers,
-      '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')),
-      '#description' => t('Select the amount of each post that you would like to see in your notification e-mails.'),
-    );
-    $form['notify_page_detailed']['comment'] = array('#type' => 'radios',
-      '#title' => t('Notify new comments'),
-      '#default_value' => $notify->comment,
-      '#options' => array(t('Disabled'), t('Enabled')),
-      '#description' => t('Include new comments in the notification mail.'),
-    );
+				if (user_access('configure own notifications')) {
+						$form['notify_page_detailed'] = array('#type' => 'fieldset', '#title' => t('Detailed settings'));
+						$form['notify_page_detailed']['use_default'] = array(
+								'#type' => 'checkboxes',
+								'#default_value' => $notify->use_default,
+								'#options' =>  array(1 => t('Use site defaults')),
+								'#description' => t('If selected, site defaults will override any selections made below'),
+						);
+
+						$form['notify_page_detailed']['node'] = array('#type' => 'radios',
+								'#title' => t('Notify new content'),
+								'#default_value' => $notify->node,
+								'#options' => array(t('Disabled'), t('Enabled')),
+								'#description' => t('Include new content in the notification mail.'),
+						);
+						$form['notify_page_detailed']['teasers'] = array('#type' => 'radios',
+								'#title' => t('Content'),
+								'#default_value' => $notify->teasers,
+								'#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')),
+								'#description' => t('Select the amount of each post that you would like to see in your notification e-mails.'),
+						);
+						$form['notify_page_detailed']['comment'] = array('#type' => 'radios',
+								'#title' => t('Notify new comments'),
+								'#default_value' => $notify->comment,
+								'#options' => array(t('Disabled'), t('Enabled')),
+								'#description' => t('Include new comments in the notification mail.'),
+						);
+				}
     $form['uid'] = array('#type' => 'value', '#value' => $account->uid);
     $form['submit'] = array('#type' => 'submit', '#value' => t('Save settings'));
   }
@@ -189,7 +308,8 @@
 
 function notify_user_settings_form_submit($form_id, $form_values) {
   db_query('DELETE FROM {notify} WHERE uid = %d', $form_values['uid']);
-  db_query('INSERT INTO {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $form_values['uid'], $form_values['status'], $form_values['node'], $form_values['teasers'], $form_values['comment']);
+  db_query('INSERT INTO {notify} (uid, status, node, teasers, comment, use_default) VALUES (%d, %d, %d, %d, %d, %d)', $form_values['uid'], $form_values['status'], $form_values['node'], $form_values['teasers'], $form_values['comment'], $form_values['use_default'][1]);
+
   drupal_set_message(t('Notify settings saved.'));
 }
 
@@ -208,6 +328,7 @@
     $form['users'][$notify->uid] = array();
     $form['users'][$notify->uid]['name'] = array('#type' => 'markup', '#value' => theme('username', $notify));
     $form['users'][$notify->uid]['mail'] = array('#type' => 'markup', '#value' => $notify->mail);
+    $form['users'][$notify->uid]['use_default'] = array('#type' => 'checkbox', '#default_value' => $notify->use_default);
     $form['users'][$notify->uid]['node'] = array('#type' => 'checkbox', '#default_value' => $notify->node);
     $form['users'][$notify->uid]['teasers'] = array('#type' => 'select', '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')));
     $form['users'][$notify->uid]['comment'] = array('#type' => 'checkbox', '#default_value' => $notify->comment);
@@ -232,7 +353,7 @@
 function notify_admin_users_submit($form_id, $form_values) {
   if ($form_values['users']) {
     foreach ($form_values['users'] as $uid => $settings) {
-      db_query('UPDATE {notify} SET node = %d, teasers = %d, comment = %d WHERE uid = %d', $settings['node'], $settings['teasers'], $settings['comment'], $uid);
+      db_query('UPDATE {notify} SET use_default = %d, node = %d, teasers = %d, comment = %d WHERE uid = %d', $settings['use_default'], $settings['node'], $settings['teasers'], $settings['comment'], $uid);
     }
   }
   drupal_set_message(t('Notify settings saved.'));
@@ -258,7 +379,7 @@
  */
 function theme_notify_admin_users($form) {
   $output = drupal_render($form['info']);
-  $header = array(t('Username'), t('E-mail address'), t('Content'), t('Teasers'), t('Comment'), t('Failed attempts'));
+  $header = array(t('Username'), t('E-mail address'), t('Defaults'), t('Content'), t('Teasers'), t('Comment'), t('Failed attempts'));
 
   $rows = array();
   foreach (element_children($form['users']) as $uid) {
@@ -326,9 +447,19 @@
   _notify_switch_user(); // Store current user
 
   // Fetch users with notify enabled
-  $uresult = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment FROM {notify} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND u.status = 1 AND n.attempts <= %d', variable_get('notify_attempts', 5));
+  $uresult = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment, n.use_default FROM {notify} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND u.status = 1 AND n.attempts <= %d', variable_get('notify_attempts', 5));
+		$notify_defaults = array(
+				'node' => variable_get('notify_default_node', 'Enabled'),
+				'teasers' => variable_get('notify_default_teasers', 'Title + Teaser'),
+				'comment' => variable_get('notify_default_comments', 'Disabled'),
+		);
 
   while ($user = db_fetch_object($uresult)) {
+				if ($user->use_default) {
+						foreach ($notify_defaults as $default_key => $default_val) {
+								$user->$default_key = $default_val;
+						}
+				}
     // Switch current user to this account to use node_access functions, etc.
     _notify_switch_user($user->uid);
 
