Index: simplenews_roles.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simplenews_roles/simplenews_roles.module,v retrieving revision 1.2.2.4 diff -u -p -r1.2.2.4 simplenews_roles.module --- simplenews_roles.module 28 Jul 2009 22:49:39 -0000 1.2.2.4 +++ simplenews_roles.module 1 Oct 2009 14:42:33 -0000 @@ -36,6 +36,7 @@ function simplenews_roles_form_simplenew if (!empty($form['tid']['#value'])) { $form['#submit'][] = 'simplenews_roles_newsletter_submit'; $role_newsletters = variable_get('simplenews_roles_tids_rids', array()); + $restricted_newsletters = variable_get('simplenews_roles_tids_restricted', array()); $form['simplenews_roles'] = array( '#type' => 'fieldset', @@ -50,6 +51,13 @@ function simplenews_roles_form_simplenew '#default_value' => isset($role_newsletters[$form['tid']['#value']]) ? $role_newsletters[$form['tid']['#value']] : array(), '#weight' => 10, ); + $form['simplenews_roles']['restricted'] = array( + '#type' => 'checkbox', + '#title' => t('Restricted'), + '#default_value' => isset($restricted_newsletters[$form['tid']['#value']]) ? $restricted_newsletters[$form['tid']['#value']] : array(), + '#description' => t('Only users with the selected roles are subscribed to this newsletter. If not selected subscription of other users are allowed, even anonymous subscribers.'), + '#weight' => 11, + ); } } @@ -78,6 +86,20 @@ function simplenews_roles_newsletter_sub } variable_set('simplenews_roles_tids_rids', $role_newsletters); + + // Store restricted newsletter setting. + $restricted_newsletters = variable_get('simplenews_roles_tids_restricted', array()); + if ($form_state['values']['restricted']) { + $restricted_newsletters[$tid] = $tid; + } + else { + unset($restricted_newsletters[$tid]); + } + // Variable 'simplenews_roles_tids_restricted' is an array of + // tids of the restricted newsletters. Non restricted newsletters are + // *not* in the array. + variable_set('simplenews_roles_tids_restricted', $restricted_newsletters); + } /** @@ -157,8 +179,11 @@ function simplenews_roles_update_subscri if (is_array($rids) && $rids) { // TODO: Don't delete then insert, find the diff and add/remove! - // Remove all subscriptions from this newsletter. - $result = db_query('DELETE FROM {simplenews_snid_tid} WHERE tid = %d', $tid); + // We don't allow other users, only users with the selected roles. + $enforced_newsletters = variable_get('simplenews_roles_tids_restricted', array()); + if ($enforced_newsletters['$tid']) { + $result = db_query('DELETE FROM {simplenews_snid_tid} WHERE tid = %d', $tid); + } // Subscribe all active users from selected roles, if special authenticated user // is in selected roles, just pull all active users.