/[drupal]/contributions/modules/google_groups/google_groups.admin.inc
ViewVC logotype

Contents of /contributions/modules/google_groups/google_groups.admin.inc

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


Revision 1.2 - (show annotations) (download) (as text)
Sat Oct 17 06:13:09 2009 UTC (5 weeks, 5 days ago) by dragonwize
Branch: MAIN
CVS Tags: DRUPAL-6--2-0, HEAD
Changes since 1.1: +1 -1 lines
File MIME type: text/x-php
Fixed group name substitution in message after deletion.
1 <?php
2
3 /**
4 * @file
5 * Administration pages and code for the Google Groups module.
6 */
7
8 /**
9 * Lists groups entered in into the site.
10 *
11 * @return
12 * Page HTML.
13 */
14 function google_groups_list_page() {
15 $header = array(t('Group name'), t('Account form'), array('data' => t('Operations'), 'colspan' => '2'));
16 $rows = array();
17 $settings = variable_get('google_groups_settings', array());
18
19 foreach ($settings['groups'] as $delta => $group) {
20 if ($group['register']) {
21 $reg = '<li>' . t('List on form: Yes') . '</li>';
22 $reg .= '<li>' . t('Default: ') . ($group['register_default'] ? t('On') : t('Off')) . '</li>';
23 $reg .= '<li>' . t('Forced: ') . ($group['register_default_forced'] ? t('Yes') : t('No')) . '</li>';
24 } else {
25 $reg = '<li>' . t('List on form: No') . '</li>';
26 }
27 $reg = '<ul>' . $reg . '</ul>';
28 $row = array(check_plain($group['name']), $reg);
29
30 // Set the edit column.
31 $row[] = array('data' => l(t('edit'), 'admin/settings/googlegroups/edit/' . $delta));
32 // Set the delete column.
33 $row[] = array('data' => l(t('delete'), 'admin/settings/googlegroups/delete/' . $delta));
34
35 $rows[] = $row;
36 }
37
38 if (empty($rows)) {
39 $rows[] = array(array('data' => t('No Google Groups have been created.'), 'colspan' => '4', 'class' => 'message'));
40 }
41
42 return theme('table', $header, $rows);
43 }
44
45 /**
46 * Administration form.
47 *
48 * @return
49 * FAPI array.
50 */
51 function google_groups_add_form() {
52 $delta = (arg(3) === 'edit' && arg(4)) ? arg(4) : NULL;
53 if ($delta) {
54 $settings = variable_get('google_groups_settings', array());
55 $group = $settings['groups'][$delta];
56 }
57
58 $form['group_name'] = array(
59 '#type' => 'textfield',
60 '#title' => t('Group Name'),
61 '#default_value' => $delta ? $group['name'] : '',
62 '#required' => TRUE,
63 '#size' => 30,
64 '#maxlength' => 100,
65 '#description' => t("Your Google Group's human readable name."),
66 );
67 $form['group_id'] = array(
68 '#type' => 'textfield',
69 '#title' => t('Group Email'),
70 '#default_value' => ($delta ? $group['id'] : ''),
71 '#required' => TRUE,
72 '#size' => 30,
73 '#maxlength' => 64,
74 '#description' => t("Your Google Group's email address."),
75 '#field_suffix' => '<span class="google-groups-email-domain">@googlegroups.com</span>',
76 );
77 $form['register'] = array(
78 '#type' => 'fieldset',
79 '#title' => t('Registration Form'),
80 '#description' => t('Options for subscribing via the registration form.'),
81 );
82 $form['register']['register'] = array(
83 '#type' => 'checkbox',
84 '#title' => t('Allow subscription during registration'),
85 '#default_value' => ($delta ? $group['register'] : ''),
86 '#description' => t('This will add a subscription checkbox to the registration form.'),
87 );
88 $form['register']['default'] = array(
89 '#type' => 'checkbox',
90 '#title' => t('Checked by default'),
91 '#default_value' => ($delta ? $group['register_default'] : ''),
92 '#description' => t('If checked, the subscription checkbox on the registration form will be checked by default.'),
93 );
94 $form['register']['forced'] = array(
95 '#type' => 'checkbox',
96 '#title' => t('Force default'),
97 '#default_value' => ($delta ? $group['register_default_forced'] : ''),
98 '#description' => t('If checked, the subscription checkbox on the registration form will be disabled. User will not be able to change it from its default setting. Useful to force user subscription.'),
99 );
100 $form['delta'] = array(
101 '#type' => 'value',
102 '#value' => $delta,
103 );
104 $form['submit'] = array(
105 '#type' => 'submit',
106 '#value' => t('Save group'),
107 );
108
109 $form['#submit'][] = 'google_groups_add_form_submit';
110
111 return $form;
112 }
113
114 function google_groups_add_form_submit($form, &$form_state) {
115 $settings = variable_get('google_groups_settings', array());
116 $groups = &$settings['groups'];
117 $values = &$form_state['values'];
118 $delta = check_plain($values['delta']);
119 $group = array();
120
121 $group['name'] = check_plain($values['group_name']);
122 $group['id'] = check_plain($values['group_id']);
123 $group['register'] = (int)$values['register'];
124 $group['register_default'] = (int)$values['default'];
125 $group['register_default_forced'] = (int)$values['forced'];
126
127 if ($delta) {
128 $settings['groups'][$delta] = array_merge($settings['groups'][$delta], $group);
129 }
130 else {
131 $delta = &$settings['next_delta'];
132 $settings['groups']['gg' . $delta] = $group;
133 $delta++;
134 }
135
136 variable_set('google_groups_settings', $settings);
137 drupal_set_message(t('Google Group saved.'), 'status');
138 $form_state['redirect'] = 'admin/settings/googlegroups';
139 return;
140 }
141
142 /**
143 * Menu callback; delete a single Google Group.
144 */
145 function google_groups_delete_confirm(&$form_state) {
146 $settings = variable_get('google_groups_settings', array());
147 $delta = check_plain(arg(4));
148 $form['delta'] = array(
149 '#type' => 'value',
150 '#value' => $delta,
151 );
152
153 $message = t('Are you sure you want to delete the Google Group @group?', array('@group' => $settings['groups'][$delta]['name']));
154 $caption = '<p>'. t('This action cannot be undone.') .'</p>';
155
156 return confirm_form($form, $message, 'admin/settings/googlegroups', $caption, t('Delete'));
157 }
158
159 /**
160 * Process Google Group delete confirm submissions.
161 */
162 function google_groups_delete_confirm_submit($form, &$form_state) {
163 $settings = variable_get('google_groups_settings', array());
164
165 drupal_set_message(t('The Google Group %name has been deleted.', array('%name' => $settings['groups'][$form_state['delta']]['name'])));
166 unset($settings['groups'][$form_state['values']['delta']]);
167 variable_set('google_groups_settings', $settings);
168
169 $form_state['redirect'] = 'admin/settings/googlegroups';
170 return;
171 }
172
173 /**
174 * Implementation of hook_user() register op.
175 */
176 function google_groups_user_register_form() {
177 $form = array();
178
179 $visable = 0;
180 $settings = variable_get('google_groups_settings', array());
181 foreach ($settings['groups'] as $delta => $group) {
182 if ($group['register']) {
183 $form['google_groups_subscribe_' . $delta] = array(
184 '#type' => 'checkbox',
185 '#title' => t('Subscribe to @group', array('@group' => $group['name'])),
186 '#weight' => 10,
187 );
188
189 if ($group['register_default']) {
190 $form['google_groups_subscribe_' . $delta]['#default_value'] = 1;
191 }
192
193 if ($group['register_default_forced']) {
194 $form['google_groups_subscribe_' . $delta]['#type'] = 'hidden';
195 }
196 else {
197 $visable++;
198 }
199 }
200 }
201
202 if ($visable) {
203 $fieldset = array(
204 '#type' => 'fieldset',
205 '#title' => t('Email lists'),
206 '#description' => t('Subscribe to our email list(s).'),
207 );
208 $form = array('google_groups' => array_merge($fieldset, $form));
209 }
210
211 return $form;
212 }
213
214 /**
215 * Implementation of hook_user() insert op.
216 */
217 function google_groups_user_register_submit(&$edit) {
218 $settings = variable_get('google_groups_settings', array());
219
220 foreach ($settings['groups'] as $delta => $group) {
221 if ($group['register']) {
222 if ($edit['google_groups_subscribe_' . $delta] == 1) {
223 if (google_groups_mail($group['id'], $edit['mail'])) {
224 drupal_set_message('You will be receiving a confirmation email for our email list.', 'status');
225 }
226 else {
227 $message = 'An error sending a subscription email occurred and user was NOT subscribed to our email list.';
228 watchdog('error', $message, array(), WATCHDOG_WARNING);
229 drupal_set_message('An error occurred and you were NOT subscribed to our email list.', 'warning');
230 }
231 }
232 $edit['google_groups_subscribe_' . $delta] = NULL;
233 }
234 }
235 }

  ViewVC Help
Powered by ViewVC 1.1.2