| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Implementation of hook_help().
|
| 5 |
*/
|
| 6 |
function user_mailman_register_help($path, $arg) {
|
| 7 |
$output = '';
|
| 8 |
switch ($path) {
|
| 9 |
case 'admin/modules#description':
|
| 10 |
return t('This is a module for mailman subscribing which extends the <a href="@mmanager">Mailman Manager</a> module features.', array('@mmanager' => url('admin/help/mailman_manager')));
|
| 11 |
break;
|
| 12 |
case 'admin/help#user_mailman_register':
|
| 13 |
$output = '<p>'. t('This is a module for mailman subscribing which extends the <a href="@mmanager">Mailman Manager</a> module features.', array('@mmanager' => url('admin/help/mailman_manager'))) .'</p>';
|
| 14 |
$output .= '<p>'. t('The main feature is that, instead of sending user commands in mail format as Mailman Manager does, it sends url requests to the mailman web interface where admins manage lists members.') .'</p>';
|
| 15 |
$output .= '<p>'. t('With access permissions you\'ll be able to choose the subscription method (Mailman Manager mail, User Mailman Register http or even both) for a user of your site, and in any moment you can switch between the two methods preserving users subscription status.') .'</p>';
|
| 16 |
}
|
| 17 |
return $output;
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Implementation of hook_user().
|
| 22 |
*/
|
| 23 |
function user_mailman_register_user($op, &$edit, &$account, $category = NULL) {
|
| 24 |
switch ($op) {
|
| 25 |
//Create menu option on user tab;
|
| 26 |
case 'categories':
|
| 27 |
if (variable_get('user_mailman_register_ownform', 1)) {
|
| 28 |
$lists = _mailman_manager_get_lists();
|
| 29 |
if (count($lists) && user_access('access user_mailman_register')) {
|
| 30 |
$output_user[] = array('name' => 'user_mailman_register', 'title' => t('Mailing Lists register'), 'weight' => 9);
|
| 31 |
}
|
| 32 |
return $output_user;
|
| 33 |
}
|
| 34 |
break;
|
| 35 |
case 'form':
|
| 36 |
if ($category == (variable_get('user_mailman_register_ownform', 1)?'user_mailman_register':'account') && user_access('access user_mailman_register')) {
|
| 37 |
return _user_mailman_register_form($account);
|
| 38 |
}
|
| 39 |
break;
|
| 40 |
case 'insert':
|
| 41 |
if (variable_get('user_mailman_register_registerform', 1)) {
|
| 42 |
_user_mailman_register_subscribe($account, $edit);
|
| 43 |
}
|
| 44 |
break;
|
| 45 |
case 'delete':
|
| 46 |
_user_mailman_register_subscribe($account, $edit, 1);
|
| 47 |
db_query("DELETE FROM {mailman_users} WHERE uid = %d", $account->uid);
|
| 48 |
break;
|
| 49 |
case 'validate':
|
| 50 |
$nosub = variable_get('user_mailman_register_required', 0);
|
| 51 |
$lists = _mailman_manager_get_lists();
|
| 52 |
if (count($lists) > 0) {
|
| 53 |
foreach ($lists as $list) {
|
| 54 |
if (_user_mailman_register_list_allowed($list) && $edit['options'. trim($list['lid'])] != '0') $nosub=0;
|
| 55 |
}
|
| 56 |
if ($nosub && $account->uid <> 1) {
|
| 57 |
form_set_error('user_mailman_register', t('At least one mailing list subscription is required'));
|
| 58 |
}
|
| 59 |
}
|
| 60 |
break;
|
| 61 |
case 'register':
|
| 62 |
if (variable_get('user_mailman_register_registerform', 1)) {
|
| 63 |
return _user_mailman_register_form();
|
| 64 |
}
|
| 65 |
break;
|
| 66 |
case 'update':
|
| 67 |
if ($category==(variable_get('user_mailman_register_ownform', 1)?'user_mailman_register':'account')) {
|
| 68 |
_user_mailman_register_subscribe($account, $edit);
|
| 69 |
}
|
| 70 |
|
| 71 |
if ($category=='account') {
|
| 72 |
//User mail is going to be changed
|
| 73 |
if (isset($edit['mail']) && $account->mail != $edit['mail']) {
|
| 74 |
$lists = _mailman_manager_get_lists();
|
| 75 |
if (count($lists) > 0) {
|
| 76 |
//prepare a form from old status subscriptions.
|
| 77 |
$cpedit = $edit;
|
| 78 |
foreach ($lists as $list) {
|
| 79 |
$subscript=_mailman_manager_get_subscriptions($account->uid, $list['lid']);
|
| 80 |
//Only normal is supported in first subscription.
|
| 81 |
if ($subscript['lstatus'] == '0') {
|
| 82 |
$subsc = '0';
|
| 83 |
}
|
| 84 |
else {
|
| 85 |
$subsc = '3';
|
| 86 |
}
|
| 87 |
$cpedit['options'. trim($list['lid'])] = $subsc;
|
| 88 |
}
|
| 89 |
//Unsubribe old email.
|
| 90 |
_user_mailman_register_subscribe($account, $edit, 1);
|
| 91 |
//Subscribe new mail with old staus.
|
| 92 |
_user_mailman_register_subscribe($account, $cpedit, 0, $edit['mail']);
|
| 93 |
}
|
| 94 |
}
|
| 95 |
//User roles are going to be changed.
|
| 96 |
if (is_array($edit['roles']) && $edit['roles'] !== $account->roles) {
|
| 97 |
//Authenticated user without special role.
|
| 98 |
$edit['roles'][2] = 2;
|
| 99 |
$acc_tmp = $account;
|
| 100 |
$acc_tmp->roles = $edit['roles'];
|
| 101 |
if (!$list) {
|
| 102 |
$lists = _mailman_manager_get_lists();
|
| 103 |
}
|
| 104 |
if (count($lists) > 0) {
|
| 105 |
foreach ($lists as $list) {
|
| 106 |
if (!_user_mailman_register_list_allowed($list,$acc_tmp)) {
|
| 107 |
//Check if user is subscribed to $list even though their role doesn't allow it. If so, unsubscribe user from $list.
|
| 108 |
$query = "SELECT * FROM {mailman_users} WHERE uid = %d AND lid = %d AND lstatus > 0";
|
| 109 |
$result = db_query($query, $account->uid, $list['lid']);
|
| 110 |
$subscrip = db_fetch_array($result);
|
| 111 |
if ($subscrip) {
|
| 112 |
//unsubscribe user from this list
|
| 113 |
_user_mailman_register_subscribe_update($account, $list, '0', $subscrip['lstatus'], $account->mail, NULL);
|
| 114 |
}
|
| 115 |
}
|
| 116 |
}
|
| 117 |
}
|
| 118 |
}
|
| 119 |
}
|
| 120 |
break;
|
| 121 |
}
|
| 122 |
}
|
| 123 |
|
| 124 |
function _user_mailman_register_form($account=false) {
|
| 125 |
$lists = _mailman_manager_get_lists();
|
| 126 |
if (count($lists) > 0) {
|
| 127 |
$status = 0;
|
| 128 |
$form['user_mailman_register'] = array('#weight' => 0.9);
|
| 129 |
$form['user_mailman_register']['lists'] = array(
|
| 130 |
'#type' => 'fieldset',
|
| 131 |
'#title' => t('Mailing list subscription'),
|
| 132 |
'#description' => t('Join a mailing list to receive or participate in its discussions via email.'),
|
| 133 |
'#collapsible' => FALSE
|
| 134 |
);
|
| 135 |
foreach ($lists as $list) {
|
| 136 |
if (!_user_mailman_register_list_allowed($list)) {
|
| 137 |
continue;
|
| 138 |
}
|
| 139 |
$lstatus = 0;
|
| 140 |
$status = 1;
|
| 141 |
$form['user_mailman_register']['lists']['list'. trim($list['lid'])] = array(
|
| 142 |
'#type' => 'fieldset',
|
| 143 |
'#title' => $list['name'],
|
| 144 |
'#description' => $list['description'],
|
| 145 |
'#collapsible' => TRUE
|
| 146 |
);
|
| 147 |
if ($account) {
|
| 148 |
$subscrip = _mailman_manager_get_subscriptions($account->uid, $list['lid']);
|
| 149 |
$lstatus=$subscrip['lstatus'];
|
| 150 |
}
|
| 151 |
|
| 152 |
if ($lstatus == 0) {
|
| 153 |
$title = t('Subscribe to ') . $list['name'] ."?";
|
| 154 |
if ($list['allow_unsubscribe'])
|
| 155 |
$options['0'] = t('No');
|
| 156 |
$options['3'] = t('Yes');
|
| 157 |
}
|
| 158 |
else {
|
| 159 |
$title = t('Change your subscription');
|
| 160 |
if ($list['allow_unsubscribe'])
|
| 161 |
$options['0'] = t('Unsubscribe');
|
| 162 |
if ($list['allow_temp_disable'])
|
| 163 |
$options['1'] = t('No mail (temporarily disable delivery)');
|
| 164 |
if ($list['allow_digest']) {
|
| 165 |
$options['2'] = t('Subscribe for digest (receive emails in a bundle)');
|
| 166 |
$options['3'] = t('Subscribe for all mail (normal delivery)');
|
| 167 |
}
|
| 168 |
else
|
| 169 |
$options['3'] = t('Subscribe');
|
| 170 |
}
|
| 171 |
|
| 172 |
// feeds specified default value into the form on new-user registration if allowed
|
| 173 |
if (!$account) $lstatus = ((variable_get('user_mailman_register_defaultnewreg', 0)==0 && $list['allow_unsubscribe'])?0:3);
|
| 174 |
|
| 175 |
$form['user_mailman_register']['lists']['list'. trim($list['lid'])]['options'. trim($list['lid'])] = array(
|
| 176 |
'#type' => 'radios',
|
| 177 |
'#title' => $title,
|
| 178 |
'#options' => $options,
|
| 179 |
'#default_value' => $lstatus
|
| 180 |
);
|
| 181 |
}
|
| 182 |
if (!$status) $form['user_mailman_register']['lists']['#description'] = t('Any mailing list is avaiable', array());
|
| 183 |
return $form;
|
| 184 |
}
|
| 185 |
}
|
| 186 |
|
| 187 |
function _user_mailman_register_subscribe($account, $edit, $deluser=0, $umail=false) {
|
| 188 |
$msg='';
|
| 189 |
if (!$umail) {
|
| 190 |
$umail = $account->mail;
|
| 191 |
}
|
| 192 |
$lists = _mailman_manager_get_lists();
|
| 193 |
if (count($lists) > 0) {
|
| 194 |
foreach ($lists as $list) {
|
| 195 |
if ($deluser) {
|
| 196 |
$reqstatus='0';
|
| 197 |
}
|
| 198 |
else {
|
| 199 |
if (!isset($edit['options'. trim($list['lid'])]))
|
| 200 |
continue;
|
| 201 |
$reqstatus=$edit['options'. trim($list['lid'])];
|
| 202 |
}
|
| 203 |
$subscrip=_mailman_manager_get_subscriptions($account->uid, $list['lid']);
|
| 204 |
$query = "SELECT * FROM {mailman_users} WHERE uid = %d AND lid = %d";
|
| 205 |
$result = db_query($query, $account->uid, $list['lid']);
|
| 206 |
$subscrip = db_fetch_array($result);
|
| 207 |
if ($subscrip['lstatus'] == $reqstatus) {
|
| 208 |
continue;
|
| 209 |
}
|
| 210 |
$msg .= _user_mailman_register_subscribe_update($account, $list, $reqstatus, $subscrip['lstatus'], $umail, $edit);
|
| 211 |
}
|
| 212 |
}
|
| 213 |
return $msg;
|
| 214 |
}
|
| 215 |
|
| 216 |
function _user_mailman_register_subscribe_update($account, $list, $nstatus, $ostatus, $umail, $edit) {
|
| 217 |
$msg = '';
|
| 218 |
$email = urlencode($umail);
|
| 219 |
$regurl = rtrim($list['webadmin'], '/') .'/members';
|
| 220 |
$mailname='';
|
| 221 |
switch ($nstatus) {
|
| 222 |
//unsubscribe
|
| 223 |
case '0':
|
| 224 |
$regurl .= '/remove?send_unsub_ack_to_this_batch='. $list['user_notify'];
|
| 225 |
$regurl .= '&send_unsub_notifications_to_list_owner='. $list['user_admin_notify'];
|
| 226 |
$regurl .= '&unsubscribees_upload='. $email;
|
| 227 |
$msg .= t('Unsubscription to ');
|
| 228 |
break;
|
| 229 |
case '1':
|
| 230 |
case '2':
|
| 231 |
case '3':
|
| 232 |
$type='Digest';
|
| 233 |
$digest='&'. $email .'_digest=1';
|
| 234 |
//mail address name
|
| 235 |
$strprofile = variable_get('user_mailman_register_profilename', '');
|
| 236 |
$arrprofile = explode(",", $strprofile);
|
| 237 |
if (!empty($strprofile) && count($arrprofile) > 0 && module_exists('profile')) {
|
| 238 |
profile_load_profile($account);
|
| 239 |
foreach ($arrprofile as $name) {
|
| 240 |
if ($account->$name) {
|
| 241 |
$item = $account->$name;
|
| 242 |
}
|
| 243 |
else {
|
| 244 |
$item = $edit[$name];
|
| 245 |
}
|
| 246 |
if ($item) {
|
| 247 |
$mailname .= $item ." ";
|
| 248 |
}
|
| 249 |
}
|
| 250 |
$mailname=rtrim($mailname);
|
| 251 |
}
|
| 252 |
//normal
|
| 253 |
if ($nstatus == '3') {
|
| 254 |
if ($ostatus == '0') {
|
| 255 |
//new subscription
|
| 256 |
if (!empty($mailname)) {
|
| 257 |
$email = urlencode($mailname ." <". $umail .">");
|
| 258 |
}
|
| 259 |
$regurl .= '/add?subscribe_or_invite='. $list['user_invite'];
|
| 260 |
$regurl .= '&send_welcome_msg_to_this_batch='. $list['user_notify'];
|
| 261 |
$regurl .= '¬ification_to_list_owner='. $list['user_admin_notify'];
|
| 262 |
$regurl .= '&subscribees_upload='. $email;
|
| 263 |
$msg .= t('Subscription to ');
|
| 264 |
}
|
| 265 |
else {
|
| 266 |
//change nomail or digest to normal
|
| 267 |
$digest = '';
|
| 268 |
$type = 'Normal';
|
| 269 |
}
|
| 270 |
}
|
| 271 |
//digest
|
| 272 |
if ($nstatus != '3' || $type == 'Normal') {
|
| 273 |
$regurl .= '?user='. $email;
|
| 274 |
$regurl .= $digest;
|
| 275 |
$regurl .= '&'. $email .'_nodupes=1';
|
| 276 |
$regurl .= '&'. $email .'_realname='. urlencode($mailname);
|
| 277 |
$regurl .= '&'. $email .'_plain=1';
|
| 278 |
$regurl .= '&allmodbit_val=0&setmemberopts_btn=Submit%20Your%20Changes';
|
| 279 |
if ($nstatus =='1') {
|
| 280 |
$regurl .= '&'. $email .'_nomail=1';
|
| 281 |
$msg .= t('Temporary no mails from ');
|
| 282 |
}
|
| 283 |
else {
|
| 284 |
$msg .= t('@type subscription to ', array('@type' => $type));
|
| 285 |
}
|
| 286 |
}
|
| 287 |
break;
|
| 288 |
default:
|
| 289 |
return drupal_set_message(t('Unknown list subscription request.'), 'error');
|
| 290 |
}
|
| 291 |
$regurl .= '&adminpw='. $list['webpass'];
|
| 292 |
//Debug
|
| 293 |
// drupal_set_message($regurl);
|
| 294 |
$httpreq=drupal_http_request($regurl);
|
| 295 |
//Not so good. Data response should be checked too.
|
| 296 |
if ($httpreq->code <> 200) {
|
| 297 |
watchdog('user mailman reg', $list['name'] .' ['. $list['lid'] .'] list: '. $httpreq->code .' HTTP error code.', array(), WATCHDOG_ERROR);
|
| 298 |
$msg = drupal_set_message(t('Sorry, %name mailing list registration is currently unavaiable. Please, try again shortly.', array('%name' => $list['name'])), 'error');
|
| 299 |
$mailonerrors=variable_get('user_mailman_register_mailonerrors', '');
|
| 300 |
if (!empty($mailonerrors)) {
|
| 301 |
_user_mailman_register_mail_send($account, $list, $nstatus, $ostatus, $umail, $mailonerrors, $httpreq);
|
| 302 |
}
|
| 303 |
}
|
| 304 |
else {
|
| 305 |
$query = "UPDATE {mailman_users} SET lmail = '%s', lstatus = %d WHERE uid = %d AND lid = %d";
|
| 306 |
if (db_query($query, $umail, $nstatus, $account->uid, $list['lid'])) {
|
| 307 |
$msg .= '%name list completed successfully for %email';
|
| 308 |
watchdog('user mailman reg', $msg, array('%name' => $list['name'], '%email' => $mailname .'<'. $umail .'>'), WATCHDOG_NOTICE);
|
| 309 |
$msg = drupal_set_message(t($msg, array('%name' => $list['name'], '%email' => $mailname .'<'. $umail .'>')));
|
| 310 |
}
|
| 311 |
else {
|
| 312 |
$msg .= '%name list failed.';
|
| 313 |
watchdog('user mailman reg', $msg, array('%name' => $list['name']), WATCHDOG_ERROR);
|
| 314 |
$msg = drupal_set_message(t($msg, array('%name' => $list['name'])), 'error');
|
| 315 |
}
|
| 316 |
}
|
| 317 |
return $msg;
|
| 318 |
}
|
| 319 |
|
| 320 |
/**
|
| 321 |
* Implementation of hook_menu().
|
| 322 |
*/
|
| 323 |
function user_mailman_register_menu() {
|
| 324 |
$items = array();
|
| 325 |
|
| 326 |
$items['user_mailman_register'] = array(
|
| 327 |
'title' => 'Mailing Lists register',
|
| 328 |
'page callback' => 'user_mailman_register_page',
|
| 329 |
'access arguments' => array('access user_mailman_register'),
|
| 330 |
'type' => MENU_NORMAL_ITEM);
|
| 331 |
|
| 332 |
$items['admin/settings/user_mailman_register'] = array(
|
| 333 |
'title' => 'Mailing Lists register',
|
| 334 |
'access arguments' => array('administer mailman_manager'),
|
| 335 |
'description' => 'Allow users to subscribe and change their subscriptions to Mailman mailing lists.',
|
| 336 |
'page callback' => 'user_mailman_register_admin',
|
| 337 |
'type' => MENU_NORMAL_ITEM);
|
| 338 |
|
| 339 |
$items['admin/settings/user_mailman_register/edit/%'] = array(
|
| 340 |
'title' => 'Edit Mailing list commands',
|
| 341 |
'access arguments' => array('administer mailman_manager'),
|
| 342 |
'description' => 'Edit Mailman mailing lists web commands.',
|
| 343 |
'page callback' => 'drupal_get_form',
|
| 344 |
'page arguments' => array('user_mailman_register_adminedit_form', 4),
|
| 345 |
'type' => MENU__CALLBACK);
|
| 346 |
return $items;
|
| 347 |
}
|
| 348 |
|
| 349 |
|
| 350 |
/**
|
| 351 |
* Prepare the mailing list admin form.
|
| 352 |
*/
|
| 353 |
function user_mailman_register_admin() {
|
| 354 |
$output = '';
|
| 355 |
|
| 356 |
$headers = array(
|
| 357 |
array('data' => NULL),
|
| 358 |
array('data' => t('ID'), 'field' => 'lid', 'sort' => 'asc'),
|
| 359 |
array('data' => t('Name'), 'field' => 'name'),
|
| 360 |
array('data' => t('Web administration'), 'field' => 'webadmin'),
|
| 361 |
array('data' => t('User invite'), 'field' => 'user_invite'),
|
| 362 |
array('data' => t('User notify'), 'field' => 'user_notify'),
|
| 363 |
array('data' => t('List admins notify'), 'field' => 'user_admin_notify'),
|
| 364 |
array('data' => t('Allow unsubscribe'), 'field' => 'allow_unsubscribe'),
|
| 365 |
array('data' => t('Allow temporary disable'), 'field' => 'allow_temp_disable'),
|
| 366 |
array('data' => t('Allow digest'), 'field' => 'allow_digest'),
|
| 367 |
array('data' => t('Description'), 'field' => 'description'),
|
| 368 |
);
|
| 369 |
|
| 370 |
|
| 371 |
$query = "SELECT * from {mailman_lists}";
|
| 372 |
$query .= tablesort_sql($headers);
|
| 373 |
$num_per_page = 15;
|
| 374 |
$result = pager_query($query, $num_per_page);
|
| 375 |
$lists = array();
|
| 376 |
while ($list = db_fetch_array($result)) {
|
| 377 |
$cmd = 'Edit';
|
| 378 |
if (!_user_mailman_register_list_allowed($list)) {
|
| 379 |
$cmd = 'Activate';
|
| 380 |
}
|
| 381 |
unset($list['web']);
|
| 382 |
unset($list['webarch']);
|
| 383 |
unset($list['admin']);
|
| 384 |
unset($list['webpass']);
|
| 385 |
unset($list['command']);
|
| 386 |
$list['manage'] = l(t('Manage'), 'admin/settings/mailman_manager/edit/'. $list['lid']);
|
| 387 |
$lists[] = array_merge(array('status' => l(t('@cmd', array('@cmd' => $cmd)), 'admin/settings/user_mailman_register/edit/'. $list['lid'])), $list);
|
| 388 |
}
|
| 389 |
|
| 390 |
if (count($lists) == 0 ) {
|
| 391 |
$output .= t('There are no lists available for subscription.') ." ";
|
| 392 |
}
|
| 393 |
else {
|
| 394 |
$output .= drupal_get_form('user_mailman_register_adminlist_form');
|
| 395 |
$output .= theme('table', $headers, $lists);
|
| 396 |
$output .= theme('pager', $num_per_page);
|
| 397 |
}
|
| 398 |
|
| 399 |
$output .= l(t('Add new mailing list'), 'admin/settings/mailman_manager/add');
|
| 400 |
|
| 401 |
return $output;
|
| 402 |
}
|
| 403 |
|
| 404 |
function user_mailman_register_adminlist_form() {
|
| 405 |
$form['user_mailman_admin'] = array(
|
| 406 |
'#type' => 'fieldset',
|
| 407 |
'#title' => t('Settings'),
|
| 408 |
'#tree' => TRUE,
|
| 409 |
);
|
| 410 |
|
| 411 |
$form['user_mailman_admin']['required'] = array(
|
| 412 |
'#type' => 'checkbox',
|
| 413 |
'#title' => t('A subscription is required'),
|
| 414 |
'#default_value' => variable_get('user_mailman_register_required', 0),
|
| 415 |
'#description' => t('If checked, user must subscribe at least to one mailing list'),
|
| 416 |
);
|
| 417 |
$form['user_mailman_admin']['register'] = array(
|
| 418 |
'#type' => 'checkbox',
|
| 419 |
'#title' => t('Visible in user registration form'),
|
| 420 |
'#default_value' => variable_get('user_mailman_register_registerform', 1),
|
| 421 |
'#description' => t('If checked, mailing list subscription is displayed in the register new user form.'),
|
| 422 |
);
|
| 423 |
$form['user_mailman_admin']['defaultnewreg'] = array(
|
| 424 |
'#type' => 'radios',
|
| 425 |
'#title' => t('Default choice in user registration form'),
|
| 426 |
'#options' => array('0' => t('No'), '1' => t('Yes')),
|
| 427 |
'#default_value' => variable_get('user_mailman_register_defaultnewreg', 0),
|
| 428 |
'#description' => t('If the above box is checked, this will be the default choice for all mailing lists in the register new user form.'),
|
| 429 |
);
|
| 430 |
$form['user_mailman_admin']['ownform'] = array(
|
| 431 |
'#type' => 'checkbox',
|
| 432 |
'#title' => t('Display in own separate category'),
|
| 433 |
'#default_value' => variable_get('user_mailman_register_ownform', 1),
|
| 434 |
'#description' => t('If checked, mailing list subscription is displayed in a separate category on the user account edit form.'),
|
| 435 |
);
|
| 436 |
if (module_exists('profile')) {
|
| 437 |
$form['user_mailman_admin']['profilename'] = array(
|
| 438 |
'#type' => 'textfield',
|
| 439 |
'#title' => t('Profile module'),
|
| 440 |
'#size' => 50,
|
| 441 |
'#default_value' => variable_get('user_mailman_register_profilename', ''),
|
| 442 |
'#description' => t('Retrieve the display name of mail address from !profile-url name fields. Multiple fields have to be comma separated. Optional', array('!profile-url' => l(t('Profile'), 'admin/user/profile'))),
|
| 443 |
);
|
| 444 |
}
|
| 445 |
$form['user_mailman_admin']['mailonerrors'] = array(
|
| 446 |
'#type' => 'textfield',
|
| 447 |
'#title' => t('Mail on errors'),
|
| 448 |
'#size' => 50,
|
| 449 |
'#default_value' => variable_get('user_mailman_register_mailonerrors', ''),
|
| 450 |
'#description' => t('If not empty, a warning mail will be sent to these addresses when a user can not modify his subscriptions because of a mailman server connection failure. Multiple emails have to be comma separated. Optional'),
|
| 451 |
);
|
| 452 |
|
| 453 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
|
| 454 |
return $form;
|
| 455 |
}
|
| 456 |
|
| 457 |
function user_mailman_register_adminlist_form_submit($form, &$form_state) {
|
| 458 |
if (!user_access('administer mailman_manager')) {
|
| 459 |
drupal_access_denied();
|
| 460 |
return;
|
| 461 |
}
|
| 462 |
$required = $form_state['values']['user_mailman_admin']['required'];
|
| 463 |
$register = $form_state['values']['user_mailman_admin']['register'];
|
| 464 |
$defaultnewreg = $form_state['values']['user_mailman_admin']['defaultnewreg'];
|
| 465 |
$ownform = $form_state['values']['user_mailman_admin']['ownform'];
|
| 466 |
$profilename = $form_state['values']['user_mailman_admin']['profilename'];
|
| 467 |
$mailonerrors = $form_state['values']['user_mailman_admin']['mailonerrors'];
|
| 468 |
if (is_numeric($required) && is_numeric($register)) {
|
| 469 |
variable_set('user_mailman_register_required', $required);
|
| 470 |
variable_set('user_mailman_register_registerform', $register);
|
| 471 |
variable_set('user_mailman_register_defaultnewreg', $defaultnewreg);
|
| 472 |
variable_set('user_mailman_register_ownform', $ownform);
|
| 473 |
variable_set('user_mailman_register_profilename', $profilename);
|
| 474 |
if (isset($mailonerrors)) {
|
| 475 |
variable_set('user_mailman_register_mailonerrors', $mailonerrors);
|
| 476 |
}
|
| 477 |
drupal_set_message(t('Mailing list settings updated.'));
|
| 478 |
}
|
| 479 |
}
|
| 480 |
|
| 481 |
function user_mailman_register_admin_edit($id=FALSE) {
|
| 482 |
if (!$id) {
|
| 483 |
drupal_goto('admin/settings/user_mailman_register');
|
| 484 |
return;
|
| 485 |
}
|
| 486 |
return drupal_get_form('user_mailman_register_adminedit_form', $id);
|
| 487 |
}
|
| 488 |
|
| 489 |
function user_mailman_register_adminedit_form($form, $id) {
|
| 490 |
$form = array();
|
| 491 |
_user_password_dynamic_validation();
|
| 492 |
$list = mailman_manager_get_list($id);
|
| 493 |
$headers = array(
|
| 494 |
array('data' => t('ID')),
|
| 495 |
array('data' => t('Name')),
|
| 496 |
array('data' => t('Address')),
|
| 497 |
array('data' => t('Status')),
|
| 498 |
);
|
| 499 |
|
| 500 |
$items=array();
|
| 501 |
$items[]=array('lid' => $list->lid,
|
| 502 |
'name' => $list->name,
|
| 503 |
'command' => $list->command,
|
| 504 |
'status' => (_user_mailman_register_list_allowed($list)) ? t('Enabled') : t('Disabled')
|
| 505 |
);
|
| 506 |
$form['list']= array('#value' => theme('table', $headers, $items));
|
| 507 |
$form['mailman_admin'] = array(
|
| 508 |
'#type' => 'fieldset',
|
| 509 |
'#title' => t('Mailman settings'),
|
| 510 |
'#tree' => TRUE,
|
| 511 |
);
|
| 512 |
//Mailman list managment
|
| 513 |
$form['mailman_admin']['webadmin'] = array(
|
| 514 |
'#title' => t('Admin web page'),
|
| 515 |
'#default_value' => $list->webadmin,
|
| 516 |
'#description' => t("Mailing list administration web page. The url has to be avaiable from your drupal web server ip. ") . t("Example: ") ."http://www.mysite.com/cgi-bin/mailman/admin/mylist .",
|
| 517 |
'#type' => 'textfield',
|
| 518 |
'#required' => false
|
| 519 |
);
|
| 520 |
$form['mailman_admin']['webpass'] = array(
|
| 521 |
'#title' => t('Admin web password'),
|
| 522 |
'#description' => t('Administrator web password for the Mailing list Administrator'),
|
| 523 |
'#type' => 'password_confirm',
|
| 524 |
'#size' => 15,
|
| 525 |
);
|
| 526 |
$form['mailman_admin']['user_invite'] = array(
|
| 527 |
'#title' => t('Invite users'),
|
| 528 |
'#default_value' => $list->user_invite,
|
| 529 |
'#description' => t('Subscribe new users now or invite them?'),
|
| 530 |
'#type' => 'checkbox',
|
| 531 |
);
|
| 532 |
$form['mailman_admin']['user_notify'] = array(
|
| 533 |
'#title' => t('Notify users'),
|
| 534 |
'#default_value' => $list->user_notify,
|
| 535 |
'#description' => t('Send welcome messages to the new subscribee?'),
|
| 536 |
'#type' => 'checkbox',
|
| 537 |
);
|
| 538 |
$form['mailman_admin']['user_admin_notify'] = array(
|
| 539 |
'#title' => t('Notify mailman administrators'),
|
| 540 |
'#default_value' => $list->user_admin_notify,
|
| 541 |
'#description' => t('Send notifications of new subscription to the list owner?'),
|
| 542 |
'#type' => 'checkbox',
|
| 543 |
);
|
| 544 |
//Drupal list managment
|
| 545 |
$form['drupal_admin'] = array(
|
| 546 |
'#type' => 'fieldset',
|
| 547 |
'#title' => t('List interface settings'),
|
| 548 |
'#tree' => TRUE,
|
| 549 |
);
|
| 550 |
|
| 551 |
$form['drupal_admin']['allow_unsubscribe'] = array(
|
| 552 |
'#title' => t('Allow unsubscribe'),
|
| 553 |
'#default_value' => $list->allow_unsubscribe,
|
| 554 |
'#description' => t('Allow users to unsubscribe from the list? Unchecked is equivalent to forcing subscription to this list.'),
|
| 555 |
'#type' => 'checkbox',
|
| 556 |
);
|
| 557 |
$form['drupal_admin']['allow_temp_disable'] = array(
|
| 558 |
'#title' => t('Allow temporary disable'),
|
| 559 |
'#default_value' => $list->allow_temp_disable,
|
| 560 |
'#description' => t('Allow users to temporarily disable delivery?'),
|
| 561 |
'#type' => 'checkbox',
|
| 562 |
);
|
| 563 |
$form['drupal_admin']['allow_digest'] = array(
|
| 564 |
'#title' => t('Allow digest'),
|
| 565 |
'#default_value' => $list->allow_digest,
|
| 566 |
'#description' => t('Allow users to subscribe in digest mode?'),
|
| 567 |
'#type' => 'checkbox',
|
| 568 |
);
|
| 569 |
$form['drupal_admin']['description'] = array(
|
| 570 |
'#title' => t('Description'),
|
| 571 |
'#default_value' => $list->description,
|
| 572 |
'#description' => t('A brief description of this mailing list. This text will be displayed in the subscriptions page.'),
|
| 573 |
'#type' => 'textarea',
|
| 574 |
);
|
| 575 |
|
| 576 |
$form['lid'] = array('#type' => 'hidden', '#value' => $id );
|
| 577 |
$form['name'] = array('#type' => 'hidden', '#value' => $list->name );
|
| 578 |
$form['submit'] = array(
|
| 579 |
'#type' => 'submit',
|
| 580 |
'#value' => (t('Save')),
|
| 581 |
);
|
| 582 |
$b = drupal_get_breadcrumb();
|
| 583 |
$b[] = l(t('Mailing Lists register'), 'admin/settings/user_mailman_register', array('title' => t('Allow users to subscribe and change their subscriptions to Mailman mailing lists.')));
|
| 584 |
drupal_set_breadcrumb($b);
|
| 585 |
return $form;
|
| 586 |
}
|
| 587 |
|
| 588 |
function user_mailman_register_adminedit_form_validate($form, &$form_state) {
|
| 589 |
if (!valid_url($form_state['values']['mailman_admin']['webadmin'], 1)) {
|
| 590 |
form_set_error('webadmin', t('%webadmin is not a valid url', array('%webadmin' => $form_state['mailman_admin']['webadmin'])));
|
| 591 |
}
|
| 592 |
}
|
| 593 |
|
| 594 |
function user_mailman_register_adminedit_form_submit($form, &$form_state) {
|
| 595 |
if (!user_access('administer mailman_manager')) {
|
| 596 |
drupal_access_denied();
|
| 597 |
return;
|
| 598 |
}
|
| 599 |
//Update existing
|
| 600 |
$v = array( $form_state['values']['mailman_admin']['webadmin'],
|
| 601 |
$form_state['values']['mailman_admin']['user_invite'],
|
| 602 |
$form_state['values']['mailman_admin']['user_notify'],
|
| 603 |
$form_state['values']['mailman_admin']['user_admin_notify'],
|
| 604 |
$form_state['values']['drupal_admin']['allow_unsubscribe'],
|
| 605 |
$form_state['values']['drupal_admin']['allow_temp_disable'],
|
| 606 |
$form_state['values']['drupal_admin']['allow_digest'],
|
| 607 |
$form_state['values']['drupal_admin']['description'],
|
| 608 |
$form_state['values']['lid']
|
| 609 |
);
|
| 610 |
$query = "UPDATE {mailman_lists} SET ";
|
| 611 |
if (!empty($form_state['values']['mailman_admin']['webpass'])) {
|
| 612 |
$query .= "webpass = '%s', ";
|
| 613 |
array_unshift($v, $form_state['values']['mailman_admin']['webpass']);
|
| 614 |
}
|
| 615 |
$query .= "webadmin = '%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";
|
| 616 |
$result = db_query($query,
|
| 617 |
$v
|
| 618 |
);
|
| 619 |
|
| 620 |
if ($result) {
|
| 621 |
$log = '%form-name list settings updated';
|
| 622 |
$msg = t($log, array('%form-name' => $form_state['values']['name']));
|
| 623 |
watchdog('user mailman reg', $log, array('%form-name' => $form_state['values']['name']), WATCHDOG_NOTICE);
|
| 624 |
}
|
| 625 |
else {
|
| 626 |
$log = '%form-name list settings not updated';
|
| 627 |
$msg = t($log, array('%form-name' => $form_state['values']['name']));
|
| 628 |
watchdog('user mailman reg', $log, array('%form-name' => $form_state['values']['name']), WATCHDOG_ERROR);
|
| 629 |
}
|
| 630 |
drupal_set_message($msg);
|
| 631 |
}
|
| 632 |
|
| 633 |
|
| 634 |
/**
|
| 635 |
* Implementation of hook_perm().
|
| 636 |
*/
|
| 637 |
function user_mailman_register_perm() {
|
| 638 |
$str_perm = array('access user_mailman_register');
|
| 639 |
$lists = _mailman_manager_get_lists();
|
| 640 |
if (count($lists) > 0) {
|
| 641 |
foreach ($lists as $list) {
|
| 642 |
$str_perm[] = "can subscribe to ". $list['name'];
|
| 643 |
}
|
| 644 |
}
|
| 645 |
return $str_perm;
|
| 646 |
}
|
| 647 |
|
| 648 |
/**
|
| 649 |
* Menu callback; Forwards request to hook_user;
|
| 650 |
*/
|
| 651 |
function user_mailman_register_page() {
|
| 652 |
if (!user_access('access user_mailman_register')) {
|
| 653 |
drupal_access_denied();
|
| 654 |
return;
|
| 655 |
}
|
| 656 |
else {
|
| 657 |
global $user;
|
| 658 |
drupal_goto('user/'. $user->uid .'/edit'. (variable_get('user_mailman_register_ownform', 1)?'/user_mailman_register':''));
|
| 659 |
}
|
| 660 |
}
|
| 661 |
|
| 662 |
|
| 663 |
/**
|
| 664 |
* Implementation of hook_link().
|
| 665 |
*/
|
| 666 |
function user_mailman_register_link($type, $node = NULL, $teaser = FALSE) {
|
| 667 |
$links = array();
|
| 668 |
|
| 669 |
if ($type == 'page' && user_access('access content')) {
|
| 670 |
$links[] = l(t('User mailman register'), 'user_mailman_register', array('title' => t('Subscribe to mailing lists')));
|
| 671 |
}
|
| 672 |
|
| 673 |
return $links;
|
| 674 |
}
|
| 675 |
|
| 676 |
function _user_mailman_register_mail_send($account, $list, $nstatus, $ostatus, $umail, $mailonerrors, $ohttp) {
|
| 677 |
$params['subject'] = t('Mailman subscription error for !name', array('!name' => $account->name));
|
| 678 |
$params['body'] = t("User !name failed to change his list subscription.\nThe following infos can help you to solve the problem.\n\nUser mail: !umail\nList name: !list\nOld subscription status: !ostatus\nRequested subscription status: !nstatus\nRequested http url: !murl\nMailman Http response code: !code", array('!name' => $account->name, '!umail' => $umail, '!list' => $list['name'], '!ostatus' => $ostatus, '!nstatus' => $nstatus, '!murl' => $ohttp->request, '!code' => $ohttp->code));
|
| 679 |
$mail_success = drupal_mail('user_mailman_register', 'error', wordwrap($mailonerrors), language_default(), $params);
|
| 680 |
$watchdog_params = array('@name' => $account->name, '@to' => "<$mailonerrors>");
|
| 681 |
if ($mail_success) {
|
| 682 |
watchdog('user mailman reg', 'Mailman error notification for @name at @to', $watchdog_params);
|
| 683 |
}
|
| 684 |
else {
|
| 685 |
watchdog('user mailman reg', 'Error mailing Mailman error notification for @name at @to', $watchdog_params, WATCHDOG_ERROR);
|
| 686 |
}
|
| 687 |
}
|
| 688 |
|
| 689 |
function user_mailman_register_mail($key, &$message, $params) {
|
| 690 |
$message['subject'] = $params['subject'];
|
| 691 |
$message['body'][] = $params['body'];
|
| 692 |
}
|
| 693 |
|
| 694 |
function _user_mailman_register_list_allowed($list, $account=NULL) {
|
| 695 |
if (is_array($list)) {
|
| 696 |
$list = (object) $list;
|
| 697 |
}
|
| 698 |
return $list->webadmin && $list->webpass && user_access("can subscribe to ". $list->name,$account);
|
| 699 |
}
|