/[drupal]/contributions/modules/simplenews_register/simplenews_register.module
ViewVC logotype

Contents of /contributions/modules/simplenews_register/simplenews_register.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Wed Jun 4 20:53:22 2008 UTC (17 months, 3 weeks ago) by moonray
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines
File MIME type: text/x-php
Fix for missing bracket.
1 <?php
2 // $Id: simplenews_register.module,v 1.2 2008/06/02 15:53:04 moonray Exp $
3
4 if (!function_exists('_simplenews_get_vid')) {
5 function _simplenews_get_vid() {
6 return variable_get('simplenews_vid', '');
7 }
8 }
9
10 /**
11 * Implementation of hook_menu().
12 */
13 function simplenews_register_menu($may_cache) {
14 $items = array();
15 $administer = user_access('administer newsletters');
16
17 if ($may_cache) {
18 }
19 }
20
21 /**
22 * Implementation of hook_form_alter().
23 */
24 function simplenews_register_form_alter($form_id, &$form) {
25 if ($form_id == 'simplenews_admin_settings') {
26 $form['buttons']['#weight'] = 10;
27
28 $form['simplenews_register_options'] = array(
29 '#type' => 'fieldset',
30 '#title' => t('User registration page options'),
31 '#description' => t('Enable the newsletters you wish people to sign up for on the user registration page. You can change the default setting of opt-in to opt-out for each newsletter as well as changing the option to send a confirmation email before the user is subscribed to the newsletter, or automatically signing them up on submission if they checked to subscribe to that newsletter.'),
32 '#collapsible' => TRUE,
33 '#collapsed' => TRUE,
34 '#theme' => 'simplenews_register_admin_settings',
35 '#weight' => 1,
36 );
37
38 foreach (taxonomy_get_tree(_simplenews_get_vid()) as $term) {
39 $form['simplenews_register_options']['simplenews_register_'. $term->tid .'_newsletter'] = array(
40 '#value' => check_plain($term->name),
41 );
42 $form['simplenews_register_options']['simplenews_register_'. $term->tid .'_show'] = array(
43 '#type' => 'checkbox',
44 '#return_value' => 1,
45 '#default_value' => variable_get('simplenews_register_'. $term->tid .'_show', TRUE),
46 );
47 $form['simplenews_register_options']['simplenews_register_'. $term->tid .'_optout'] = array(
48 '#type' => 'checkbox',
49 '#return_value' => 1,
50 '#default_value' => variable_get('simplenews_register_'. $term->tid .'_optout', FALSE),
51 );
52 $form['simplenews_register_options']['simplenews_register_'. $term->tid .'_confirm'] = array(
53 '#type' => 'checkbox',
54 '#return_value' => 1,
55 '#default_value' => variable_get('simplenews_register_'. $term->tid .'_confirm', TRUE),
56 );
57 }
58 }
59 }
60
61 /**
62 * Custom theme function for a table for simplenews register page settings
63 */
64 function theme_simplenews_register_admin_settings($form) {
65 foreach (taxonomy_get_tree(_simplenews_get_vid()) as $term) {
66 $row = array();
67 $row[] = drupal_render($form['simplenews_register_'. $term->tid .'_newsletter']);
68 $row[] = drupal_render($form['simplenews_register_'. $term->tid .'_show']);
69 $row[] = drupal_render($form['simplenews_register_'. $term->tid .'_optout']);
70 $row[] = drupal_render($form['simplenews_register_'. $term->tid .'_confirm']);
71 $rows[] = $row;
72 }
73 $header = array(t('Newsletter'), t('Show'), t('Opt-out'), t('Email confirmation'));
74 $output = theme('table', $header, $rows);
75 return $output;
76 }
77
78 /**
79 * Implementation of hook_user().
80 */
81 function simplenews_register_user($op, &$edit, &$account, $category = NULL) {
82 switch ($op) {
83 case 'register':
84 $form = array();
85 $form['simplenews'] = array(
86 '#type' => 'fieldset',
87 '#title' => t('Newsletters'),
88 '#weight' => 5,
89 );
90
91 foreach (taxonomy_get_tree(_simplenews_get_vid()) as $term) {
92 if (variable_get('simplenews_register_'. $term->tid .'_show', TRUE)) {
93 $form['simplenews']['simplenews-'. $term->tid] = array(
94 '#type' => 'checkbox',
95 '#title' => t('Subscribe to !newsletter', array('!newsletter' => $term->name)),
96 '#default_value' => isset($edit['simplenews-'. $term->tid]) ? $edit['simplenews-'. $term->tid] : variable_get('simplenews_register_'. $term->tid .'_optout', FALSE),
97 );
98 }
99 }
100
101 return $form;
102 break;
103
104 case 'insert':
105 case 'update':
106 foreach (taxonomy_get_tree(_simplenews_get_vid()) as $term) {
107 if (variable_get('simplenews_register_'. $term->tid .'_show', TRUE) && !empty($edit['simplenews-'. $term->tid])) {
108 drupal_set_message('Signing up for newsletter.');
109 simplenews_subscribe_user($edit['mail'], $term->tid, variable_get('simplenews_register_'. $term->tid .'_confirm', FALSE));
110 }
111 }
112 break;
113 }
114 }

  ViewVC Help
Powered by ViewVC 1.1.2