Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
bulkmail_subscribe_page.inc
1 <?php
17 require_once SQ_PACKAGES_PATH.'/cms/page_templates/page_user_group_manager/page_user_group_manager.inc';
18 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
19 require_once 'Mail.php';
20 require_once 'Mail/mime.php';
21 
35 {
36 
37  var $keywords = Array(
38  'logged_in' => Array(
39  'error_messages_list',
40  'success_messages_list',
41  'current_subscriptions',
42  'subscriptions_picker',
43  'unsubscriptions_picker',
44  'user_name',
45  'user_short_name',
46  'user_email',
47  'subscribe_user_name',
48  'subscribe_email_address',
49  'commit_button',
50  ),
51  'not_logged_in' => Array(
52  'error_messages_list',
53  'success_messages_list',
54  'subscriptions_picker',
55  'unsubscriptions_picker',
56  'subscribe_user_name',
57  'subscribe_email_address',
58  'commit_button',
59  ),
60  );
61 
62 
69  function __construct($assetid=0)
70  {
71  $this->_ser_attrs = TRUE;
72  parent::__construct($assetid);
73 
74  }//end constructor
75 
76 
84  function _getAllowedLinks()
85  {
86  return Array(
87  SQ_LINK_TYPE_2 => Array(
88  'bodycopy' => Array(
89  'card' => 'M',
90  'exclusive' => FALSE,
91  ),
92  'folder' => Array(
93  'card' => 'M',
94  'exclusive' => FALSE,
95  ),
96  ),
97  SQ_LINK_NOTICE => Array(
98  'design' => Array(
99  'card' => 'M',
100  'exclusive' => FALSE,
101  ),
102  'paint_layout_page' => Array(
103  'card' => 'M',
104  'exclusive' => FALSE,
105  ),
106  ),
107  );
108 
109  }//end _getAllowedLinks()
110 
111 
122  function _createAdditional(&$link)
123  {
124  if (!parent::_createAdditional($link)) return FALSE;
125 
126  $GLOBALS['SQ_SYSTEM']->am->includeAsset('folder');
127 
128  $copy_link = Array(
129  'asset' => &$this,
130  'link_type' => SQ_LINK_TYPE_2,
131  'is_dependant' => 1,
132  'is_exclusive' => 1,
133  'value' => 'unverified_users',
134  );
135 
136  $unverified_users = new Folder();
137  $unverified_users->setAttrValue('name', 'Unverified Users');
138  if (!$unverified_users->create($copy_link)) {
139  return FALSE;
140  }
141 
142  return TRUE;
143 
144  }//end _createAdditional()
145 
146 
154  {
155  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($this->id, SQ_LINK_TYPE_2, 'folder', TRUE, 'unverified_users', 'major', '1');
156  $folder = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid'], $link['minor_type_code']);
157  return $folder;
158 
159  }//end getUnverifiedUsersFolder()
160 
161 
170  function getExistingBulkmailUserid($value)
171  {
172  try {
173  $bind_vars['email'] = $value;
174  $result = MatrixDAL::executeOne('bulkmail_package', 'getExistingBmailUser', $bind_vars);
175  } catch (Exception $e) {
176  throw new Exception("Unable to get existing bulkmail user due to database error: ".$e->getMessage());
177  }
178 
179  if (!$result) return 0;
180 
181  return $result;
182 
183  }//end getExistingBulkmailUserid()
184 
185 
194  {
195  $locations = $GLOBALS['SQ_SYSTEM']->am->getChildren($this->attr('root_node'), 'user_group');
196 
197  // check if we have statuses we want to filter out
198  $statuses = $this->attr('statuses');
199  if (!empty($statuses)) {
200  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($locations));
201  foreach ($asset_info as $assetid => $info) {
202  if (!in_array($info['status'], $statuses)) {
203  unset($locations[$assetid]);
204  }
205  }
206  }
207 
208  // if the root node is a user group and has the correct status, include it
209  $available_locations = array_keys($locations);
210  $root_node = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->attr('root_node'));
211  if (($root_node instanceof User_Group) && (!empty($statuses) && in_array($root_node->status, $statuses))) {
212  $available_locations[] = $root_node->id;
213  }
214  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($root_node);
215 
216  return $available_locations;
217 
218  }//end getAvailableLocations()
219 
220 
229  function processForm()
230  {
231  $public_user = $GLOBALS['SQ_SYSTEM']->getPublicUser();
232  $email_address = array_get_index($_REQUEST, $this->getPrefix().'_email_address', '');
233 
234  // Any user attempting verification
235  if (!empty($_GET['uniqid'])) {
236  $this->processVerification();
237  }
238 
239  // Public user
240  if ($GLOBALS['SQ_SYSTEM']->currentUser($public_user)) {
241  $this->processPublicUserForm();
242 
243  // Matrix User
244  } else {
245  $current_user = $GLOBALS['SQ_SYSTEM']->user;
246  $current_user_email = $current_user->attr('email');
247 
248  // The user is logged in, but wants to subscribe/unsubscribe a different email address
249  if (!empty($email_address) && ($email_address != $current_user_email)) {
250  $this->processPublicUserForm();
251 
252  // Subscribe the logged in user to the list
253  } else {
254  $this->processMatrixUserForm();
255  }
256  }
257 
258  }//end processForm()
259 
260 
269  {
270  $uniqid = array_get_index($_GET, 'uniqid', '');
271  if (empty($uniqid)) return;
272 
273  $subscriptions = array_get_index($_GET, 'subscribe', Array());
274  $unsubscriptions = array_get_index($_GET, 'unsubscribe', Array());
275  $subscriptions = empty($subscriptions) ? Array() : explode(',', $subscriptions);
276  $unsubscriptions = empty($unsubscriptions) ? Array() : explode(',', $unsubscriptions);
277 
278  if (empty($subscriptions) && empty($unsubscriptions)) {
279  $this->errors[] = translate('bm_no_subscription_no_unsubscription');
280  return;
281  }
282 
283  // OK, let's check if there is a user linked under the unverified users
284  // folder with $uniqid as the link value
285 
286  $unverified_folder = $this->getUnverifiedUsersFolder();
287  $type_codes = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants('user', TRUE);
288  $type_codes[] = 'bulkmail_user';
289  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($unverified_folder->id, NULL, $type_codes, TRUE, $uniqid);
290 
291  if (empty($link)) {
292  // Validating and sub/unsubscribing straight after will probably be
293  // confusing if we don't just return silently
294  // $this->errors[] = 'We have no record of your email address. You may need to subscribe again.';
295  return;
296  }
297 
298  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid']);
299 
300  // This is to trip up all the sneaky bastards who want to
301  // try and re-write the URL to link themselves under other groups
302  $all_mailing_lists = $this->getAvailableLocations();
303  $parents = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($user->id, 'user_group', FALSE));
304  $current_subscriptions = array_intersect($all_mailing_lists, $parents);
305 
306  // if the 'Show Root Node' is set to yes and if it was selected then we wont find the individual assetids
307  // for the subscription and unsubscriptions. see bug #5705 Problem with "all" on Bulkmail subscribe page
308  if ($this->attr('include_root_node')) {
309  if (in_array($this->attr('root_node'), $subscriptions)) $subscriptions = $all_mailing_lists;
310  if (in_array($this->attr('root_node'), $unsubscriptions)) $unsubscriptions = $all_mailing_lists;
311  }
312 
313  $bad_subscriptions = array_diff($subscriptions, $all_mailing_lists);
314  $bad_unsubscriptions = array_diff($unsubscriptions, $all_mailing_lists);
315 
316  $good_subscriptions = array_diff($subscriptions, $bad_subscriptions);
317  $good_unsubscriptions = array_diff($unsubscriptions, $bad_unsubscriptions);
318 
319  $curr_plus_new = array_merge($current_subscriptions, $good_subscriptions);
320  $new_minus_old = array_diff($curr_plus_new, $good_unsubscriptions);
321  $new_subscriptions = array_unique($new_minus_old);
322 
323  if (!empty($bad_subscriptions)) {
324  $this->errors[] = translate('bsp_bad_subscriptions');
325  }
326 
327  if (!empty($bad_unsubscriptions)) {
328  $this->errors[] = translate('bsp_bad_unsubscriptions');
329  }
330 
331  // Check if the subscriptions are empty because otherwise
332  // the Bulkmail_User will just go straight to the trash
333  if (!empty($good_subscriptions) || !empty($good_unsubscriptions)) {
334  $current_subscriptions[] = $unverified_folder->id;
335  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED + SQ_SECURITY_LINK_INTEGRITY);
336  if (!empty($good_subscriptions))
337  $done = $this->processMinorLinks($link['minorid'], $current_subscriptions, $new_subscriptions, $this->attr('link_type'), $uniqid);
338  else
339  $done = $this->processMinorLinks($link['minorid'], $current_subscriptions, $new_subscriptions, $this->attr('link_type'));
340  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
341 
342  // OK, let's get rid of the $unverifed_folder->id from
343  // $done so that it doesn't get shown to the frontend user
344  foreach ($done as $done_type => $done_ids) {
345  foreach ($done_ids as $index => $done_id) {
346  if ($done_id == $unverified_folder->id) {
347  unset($done[$done_type][$index]);
348  }
349  if (empty($done[$done_type])) {
350  unset($done[$done_type]);
351  }
352  }
353  }
354 
355  $this->addLinkingMessages($done);
356 
357  } else {
358  $this->errors[] = translate('bsp_no_valid_sub_unsub');
359  }
360 
361  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($unverified_folder);
362 
363  }//end processVerification()
364 
365 
375  {
376  $email_address = array_get_index($_REQUEST, $this->getPrefix().'_email_address', '');
377  $user_name = htmlspecialchars(array_get_index($_REQUEST, $this->getPrefix().'_user_name', ''));
378 
379  if (empty($email_address)) {
380  if (isset($_REQUEST[$this->getPrefix().'_email_address'])) {
381  $this->errors[] = translate('bm_email_empty');
382  }
383  return;
384  }
385 
386  $subscriptions = array_get_index($_REQUEST, $this->getPrefix().'_subscriptions', Array());
387  $unsubscriptions = array_get_index($_REQUEST, $this->getPrefix().'_unsubscriptions', Array());
388 
389  // Flag to check if the subscription request is made
390  $subscription_request = FALSE;
391 
392  if (!empty($subscriptions))
393  $subscription_request = TRUE;
394  // if the values are not passed as an array, force it into an array
395  if (!is_array($subscriptions)) {
396  if (empty($subscriptions)) {
397  $subscriptions = Array();
398  } else {
399  $subscriptions = Array($subscriptions);
400  }
401  }
402  if (!is_array($unsubscriptions)) {
403  if (empty($unsubscriptions)) {
404  $unsubscriptions = Array();
405  } else {
406  $unsubscriptions = Array($unsubscriptions);
407  }
408  }
409  if (empty($subscriptions) && empty($unsubscriptions)) {
410  $this->errors[] = translate('bm_no_subscription_no_unsubscription');
411  return;
412  }
413 
414  switch ($this->attr('verify_not_logged_in')) {
415  case 'always':
416  $sub_verify = !empty($subscriptions);
417  $unsub_verify = !empty($unsubscriptions);
418  break;
419  case 'subscribe':
420  $sub_verify = !empty($subscriptions);
421  $unsub_verify = FALSE;
422  break;
423  case 'unsubscribe':
424  $sub_verify = FALSE;
425  $unsub_verify = !empty($unsubscriptions);
426  break;
427  case 'never':
428  default:
429  $sub_verify = $unsub_verify = FALSE;
430  break;
431  }
432 
433  $unverified_folder = $this->getUnverifiedUsersFolder();
434  $uniqid = md5(uniqid(''));
435 
436  // Get the bulkmail user from email address
437  $bulk_userid = $this->getExistingBulkmailUserid($email_address);
438 
439  // If exists in system, check if user is trying to subscribe to a already subscribed group.
440  if ($bulk_userid) {
441 
442  $available_user_groups = $this->getAvailableLocations();
443  $user_parents = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($bulk_userid, 'user_group', FALSE));
444  $currently_subscribed_groups = array_intersect($available_user_groups, $user_parents);
445 
446  // While subscribing, if user has subscribed to this group previously, don't process further
447  if (array_intersect($subscriptions, $currently_subscribed_groups)) {
448  // However display a message of a bogus conformation email being sent (for security reasons)
449  if ($sub_verify === TRUE) {
450  $from_addr = $this->attr('verify_from_address');
451  $from_addr = empty($from_addr) ? SQ_CONF_DEFAULT_EMAIL : $from_addr;
452  if (empty($from_addr)) {
453  trigger_localised_error('SYS0315', E_USER_WARNING);
454  trigger_localised_error('BML0016', E_USER_WARNING);
455  } else {
456  $this->sendAlreadySubscribedEmail($email_address, $from_addr, $subscriptions);
457  }
458  }
459  $this->messages[] = translate('bsp_verification_email_sent', $email_address);
460  return;
461  }
462  }
463 
464  if ($sub_verify || $unsub_verify) {
465  $from_addr = $this->attr('verify_from_address');
466  $from_addr = empty($from_addr) ? SQ_CONF_DEFAULT_EMAIL : $from_addr;
467  if (empty($from_addr)) {
468  trigger_localised_error('SYS0315', E_USER_WARNING);
469  trigger_localised_error('BML0016', E_USER_WARNING);
470  } else {
471  require_once SQ_FUDGE_PATH.'/general/www.inc';
472  $_email_address_trim = trim($email_address);
473  // if the email is valid send a confirmation
474  if (valid_email($_email_address_trim) && !empty($_email_address_trim)) {
475  $this->sendConfirmationEmail($email_address, $from_addr, $subscriptions, $unsubscriptions, $uniqid);
476  $this->messages[] = translate('bsp_verification_email_sent', $email_address);
477  }
478  }
479  }
480 
481  // We need to verify both subscribing and unsubscribing
482  if ($sub_verify && $unsub_verify) {
483  $subscriptions = Array($unverified_folder->id);
484  $unsubscriptions = Array();
485 
486  // Only verify subscriptions
487  } else if ($sub_verify) {
488  $subscriptions = Array($unverified_folder->id);
489 
490  // Only verify unsubscriptions
491  } else if ($unsub_verify) {
492  $subscriptions[] = $unverified_folder->id;
493  $unsubscriptions = Array();
494  }
495 
496  // The user doesn't exist at all, so we are going to create it
497  if ((empty($bulk_userid)) && !empty($subscriptions) && $subscription_request) {
498  // We should clear the unsubscriptions considering you can't unsubscribe
499  // if you don't exist
500  $unsubscriptions = Array();
501 
502  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bulkmail_user');
503  $bulkmail_user = new Bulkmail_User();
504 
505  $parent_assetid = array_shift($subscriptions);
506  $parent_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($parent_assetid);
507  $link_value = $sub_verify ? $uniqid : '';
508  $link = Array(
509  'asset' => $parent_asset,
510  'link_type' => $this->attr('link_type'),
511  'value' => $link_value,
512  );
513 
514  $creation_succeed = FALSE;
515  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED + SQ_SECURITY_LINK_INTEGRITY);
516 
517  // if we could not set the email add a error
518  if (!$bulkmail_user->setAttrValue('email', $email_address)) {
519  $this->errors[] = translate('bm_email_invalid');
520  }
521 
522  // if we could not set the name add a error
523  if (!$bulkmail_user->setAttrValue('name', $user_name)) {
524  $this->errors[] = translate('bm_username_invalid');
525  }
526  $bulkmail_user->create($link);
527  // if create succeed processMinor Links
528  if (!empty($bulkmail_user->id)) {
529  $done = $this->processMinorLinks($bulkmail_user->id, Array(), $subscriptions, $this->attr('link_type'));
530  $creation_succeed = TRUE;
531  }
532  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
533 
534  if ($creation_succeed) {
535  if ($parent_asset->id != $unverified_folder->id) {
536  $done['add_success'][] = $parent_assetid;
537  }
538  $this->addLinkingMessages($done);
539  }
540 
541  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($parent_asset);
542  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($bulkmail_user);
543  // The user already exists, so we need to shift them in and out of whatever groups they have selected
544  // and thats only if user is not already subscribed to the group
545  } else if ($bulk_userid) {
546  $bulkmail_user = $GLOBALS['SQ_SYSTEM']->am->getAsset($bulk_userid, 'bulkmail_user');
547 
548  foreach ($subscriptions as $index => $assetid) {
549  if ($assetid == $unverified_folder->id) {
550  // We need to manually create the link to the unverified users folder here
551  // because it needs a link value
552  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
553  $GLOBALS['SQ_SYSTEM']->am->createAssetLink($unverified_folder, $bulkmail_user, $this->attr('link_type'), $uniqid);
554  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
555  unset ($subscriptions[$index]);
556  }
557  }
558 
559  $all_mailing_lists = $this->getAvailableLocations();
560  $parents = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($bulkmail_user->id, 'user_group', FALSE));
561  $current_subscriptions = array_intersect($all_mailing_lists, $parents);
562 
563  $curr_plus_new = array_merge($current_subscriptions, $subscriptions);
564  $new_minus_old = array_diff($curr_plus_new, $unsubscriptions);
565  $new_subscriptions = array_unique($new_minus_old);
566 
567  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED + SQ_SECURITY_LINK_INTEGRITY);
568  $done = $this->processMinorLinks($bulkmail_user->id, $current_subscriptions, $new_subscriptions, $this->attr('link_type'));
569  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
570 
571  $this->addLinkingMessages($done);
572  }
573 
574  }//end processPublicUserForm()
575 
576 
584  {
585  $subscriptions = array_get_index($_REQUEST, $this->getPrefix().'_subscriptions', Array());
586  $unsubscriptions = array_get_index($_REQUEST, $this->getPrefix().'_unsubscriptions', Array());
587 
588  // if the values are not passed as an array, force it into an array
589  if (!is_array($subscriptions)) {
590  if (empty($subscriptions)) {
591  $subscriptions = Array();
592  } else {
593  $subscriptions = Array($subscriptions);
594  }
595  }
596  if (!is_array($unsubscriptions)) {
597  if (empty($unsubscriptions)) {
598  $unsubscriptions = Array();
599  } else {
600  $unsubscriptions = Array($unsubscriptions);
601  }
602  }
603  if (empty($subscriptions) && empty($unsubscriptions)) {
604  return;
605  }
606 
607  switch ($this->attr('verify_logged_in')) {
608  case 'always':
609  $sub_verify = !empty($subscriptions);
610  $unsub_verify = !empty($unsubscriptions);
611  break;
612  case 'subscribe':
613  $sub_verify = !empty($subscriptions);
614  $unsub_verify = FALSE;
615  break;
616  case 'unsubscribe':
617  $sub_verify = FALSE;
618  $unsub_verify = !empty($unsubscriptions);
619  break;
620  case 'never':
621  default:
622  $sub_verify = $unsub_verify = FALSE;
623  break;
624  }
625 
626  $unverified_folder = $this->getUnverifiedUsersFolder();
627  $uniqid = md5(uniqid(''));
628 
629  $current_user = $GLOBALS['SQ_SYSTEM']->user;
630  $current_user_email = $current_user->attr('email');
631  if (empty($current_user_email)) {
632  $this->errors[] = translate('bsp_email_not_configured');
633  return;
634  }
635 
636  // If subscription already exists, then reject the subscription
637  $available_user_groups = $this->getAvailableLocations();
638  $user_parents = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($current_user->id, 'user_group', FALSE));
639  $currently_subscribed_groups = array_intersect($available_user_groups, $user_parents);
640 
641  // While subscribing, if user has subscribed to this group previously, don't process further
642  if (array_intersect($subscriptions, $currently_subscribed_groups)) {
643  // However display a message of a bogus conformation email being sent (for security reasons)
644  // Behaviour for a logged in user is to show nothing if subs are not verified, though.
645  if ($sub_verify === TRUE) {
646  $from_addr = $this->attr('verify_from_address');
647  $from_addr = empty($from_addr) ? SQ_CONF_DEFAULT_EMAIL : $from_addr;
648  if (empty($from_addr)) {
649  trigger_localised_error('SYS0315', E_USER_WARNING);
650  trigger_localised_error('BML0016', E_USER_WARNING);
651  } else {
652  $this->sendAlreadySubscribedEmail($current_user_email, $from_addr, $subscriptions);
653  $this->messages[] = translate('bsp_verification_email_sent', $current_user_email);
654  }
655  }
656  return;
657  }
658 
659  if ($sub_verify || $unsub_verify) {
660  $from_addr = $this->attr('verify_from_address');
661  $from_addr = empty($from_addr) ? SQ_CONF_DEFAULT_EMAIL : $from_addr;
662  if (empty($from_addr)) {
663  trigger_localised_error('SYS0315', E_USER_WARNING);
664  trigger_localised_error('BML0016', E_USER_WARNING);
665  } else {
666  $this->sendConfirmationEmail($current_user_email, $from_addr, $subscriptions, $unsubscriptions, $uniqid);
667  $this->messages[] = translate('bsp_verification_email_sent', $current_user_email);
668  }
669  }
670 
671  // We need to verify both subscribing and unsubscribing
672  if ($sub_verify && $unsub_verify) {
673  $subscriptions = Array($unverified_folder->id);
674  $unsubscriptions = Array();
675 
676  // Only verify subscriptions
677  } else if ($sub_verify) {
678  $subscriptions = Array($unverified_folder->id);
679 
680  // Only verify unsubscriptions
681  } else if ($unsub_verify) {
682  $subscriptions[] = $unverified_folder->id;
683  $unsubscriptions = Array();
684  }
685 
686  foreach ($subscriptions as $index => $assetid) {
687  if ($assetid == $unverified_folder->id) {
688  // We need to manually create the link to the unverified users folder here
689  // because it needs a link value
690  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
691  $link = $GLOBALS['SQ_SYSTEM']->am->getLinkByAsset($unverified_folder->id, $current_user->id);
692  if (!empty($link)) {
693  $GLOBALS['SQ_SYSTEM']->am->updateLink($link['linkid'], $link['link_type'], $uniqid);
694  } else {
695  $GLOBALS['SQ_SYSTEM']->am->createAssetLink($unverified_folder, $current_user, $this->attr('link_type'), $uniqid);
696  }
697  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
698  unset ($subscriptions[$index]);
699  }
700  }
701 
702  $all_mailing_lists = $this->getAvailableLocations();
703  $parents = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($current_user->id, 'user_group', FALSE));
704  $current_subscriptions = array_intersect($all_mailing_lists, $parents);
705 
706  $curr_plus_new = array_merge($current_subscriptions, $subscriptions);
707  $new_minus_old = array_diff($curr_plus_new, $unsubscriptions);
708  $new_subscriptions = array_unique($new_minus_old);
709 
710  $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED + SQ_SECURITY_LINK_INTEGRITY);
711  $done = $this->processMinorLinks($current_user->id, $current_subscriptions, $new_subscriptions, $this->attr('link_type'));
712  $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
713 
714  $this->addLinkingMessages($done);
715 
716  }//end processMatrixUserForm()
717 
718 
728  function addLinkingMessages($fail_success)
729  {
730  foreach ($fail_success as $message_type => $assetids) {
731  switch ($message_type) {
732  case 'add_fail':
733  $this->errors[] = translate('bsp_add_failed').$this->_getCommaSeparatedNamesByAssetid($assetids);
734  break;
735  case 'add_success':
736  $this->messages[] = translate('bsp_add_successful').$this->_getCommaSeparatedNamesByAssetid($assetids);
737  break;
738  case 'delete_fail':
739  $this->errors[] = translate('bsp_remove_failed').$this->_getCommaSeparatedNamesByAssetid($assetids);
740  break;
741  case 'delete_success':
742  $this->messages[] = translate('bsp_remove_successful').$this->_getCommaSeparatedNamesByAssetid($assetids);
743  break;
744  }
745  }
746 
747  }//end addLinkingMessages()
748 
749 
763  function sendConfirmationEmail($to, $from, $subscriptions, $unsubscriptions, $uniqid)
764  {
765  if (empty($subscriptions) && empty($unsubscriptions)) {
766  return;
767  }
768 
769  $headers = Array(
770  'From' => $from,
771  'Subject' => translate('bsp_verification_email_subject'),
772  );
773 
774  $body = '';
775 
776  $get_vars = Array(
777  'email' => $to,
778  'subscribe' => implode(',', $subscriptions),
779  'unsubscribe' => implode(',', $unsubscriptions),
780  'uniqid' => $uniqid,
781  );
782 
783  $url = current_url().'?';
784  foreach ($get_vars as $key => $value) {
785  $url .= '&'.$key.'='.$value;
786  }
787 
788  if (!empty($subscriptions) && !empty($unsubscriptions)) {
789  $body .= translate('bsp_verification_email_body_sub_unsub',
790  $this->_getCommaSeparatedNamesByAssetid($subscriptions),
791  $this->_getCommaSeparatedNamesByAssetid($unsubscriptions));
792  $body .= translate('bsp_verification_email_body_part2', $url);
793  } else if (!empty($subscriptions)) {
794  $body .= translate('bsp_verification_email_body_sub', $this->_getCommaSeparatedNamesByAssetid($subscriptions));
795  $body .= translate('bsp_verification_email_body_sub_part2', $url);
796  } else if (!empty($unsubscriptions)) {
797  $body .= translate('bsp_verification_email_body_unsub', $this->_getCommaSeparatedNamesByAssetid($unsubscriptions));
798  $body .= translate('bsp_verification_email_body_part2', $url);
799  }
800  $body .= translate('bsp_verification_email_note', $from);
801 
802 
803  $mime = new Mail_mime("\n");
804  $mime->setTXTBody($body);
805  $param = Array(
806  'head_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
807  'text_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
808  'html_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
809  );
810  $body = @$mime->get($param);
811  $headers = @$mime->headers($headers);
812 
813  $mf = new Mail();
814  $mail = $mf->factory('mail', "-f$from");
815  $status = @$mail->send($to, $headers, $body);
816  if (PEAR::isError($status)) {
817  // unable to send verification email
818  trigger_localised_error('BML0018', E_USER_WARNING);
819  }
820 
821  return;
822 
823  }//end sendConfirmationEmail()
824 
825 
837  function sendAlreadySubscribedEmail($to, $from, $subscriptions)
838  {
839  if (empty($subscriptions)) {
840  return;
841  }
842 
843  $headers = Array(
844  'From' => $from,
845  'Subject' => translate('bsp_verification_email_subject'),
846  );
847 
848  $url = current_url();
849  $body = translate('bsp_already_sub_email_body', $this->_getCommaSeparatedNamesByAssetid($subscriptions), $url);
850 
851  $mime = new Mail_mime("\n");
852  $mime->setTXTBody($body);
853  $param = Array(
854  'head_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
855  'text_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
856  'html_charset' => SQ_CONF_DEFAULT_CHARACTER_SET,
857  );
858  $body = @$mime->get($param);
859  $headers = @$mime->headers($headers);
860 
861  $mf = new Mail();
862  $mail = $mf->factory('mail', "-f$from");
863  $status = $mail->send($to, $headers, $body);
864  if (PEAR::isError($status)) {
865  // unable to send verification email
866  trigger_localised_error('BML0018', E_USER_WARNING);
867  }
868 
869  return;
870 
871  }//end sendAlreadySubscribedEmail()
872 
873 
881  {
882  ob_start();
883  text_box($this->getPrefix().'_email_address', '', 30);
884  $email_address = ob_get_contents();
885  ob_end_clean();
886  return $email_address;
887 
888  }//end getSubscribeEmailAddressKeywordReplacement()
889 
890 
898  {
899  ob_start();
900  text_box($this->getPrefix().'_user_name', '', 30);
901  $user_name = ob_get_contents();
902  ob_end_clean();
903  return $user_name;
904 
905  }//end getSubscribeUserNameKeywordReplacement()
906 
907 
915  {
916  return $this->printAvailableLocations('_subscriptions');
917 
918  }//end getSubscriptionsPickerKeywordReplacement()
919 
920 
928  {
929  return $this->printAvailableLocations('_unsubscriptions');
930 
931  }//end getUnsubscriptionsPickerKeywordReplacement()
932 
933 
941  {
942  $current_user = $GLOBALS['SQ_SYSTEM']->user;
943  if ($current_user instanceof Public_User) {
944  // if current user is public user, %current_subscriptions keyword will be blanked.
945  return '';
946  }
947  $all_mailing_lists = $this->getAvailableLocations();
948  // only get direct parents
949  $parents = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($current_user->id, 'user_group', FALSE, NULL, NULL, NULL, 1));
950  $current_subscriptions = array_intersect($all_mailing_lists, $parents);
951  $string = '';
952  if (!empty($current_subscriptions)) {
953  $string .= '<ul>';
954  $info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_values($current_subscriptions), Array(), TRUE, 'name');
955  foreach ($current_subscriptions as $current_subscription) {
956  $string .= '<li class="'.$this->getPrefix().'_current_subscriptions">'.$info[$current_subscription].'</li>';
957  }
958  $string .= '</ul>';
959  }
960  return $string;
961 
962  }//end getCurrentSubscriptionsKeywordReplacement()
963 
964 
974  {
975  switch ($code) {
976  case 'logged_in':
977  return '<h2>'.translate('bsp_default_title_logged_in', '%user_name%').'</h2>
978  %success_messages_list% %error_messages_list%
979  <h3>'.translate('bsp_default_subtitle_current_subs').'</h3>
980  %current_subscriptions%
981  <h3>'.translate('bsp_default_subtitle_add_sub').'</h3>
982  %subscriptions_picker%
983  <h3>'.translate('bsp_default_subtitle_remove_sub').'</h3>
984  %unsubscriptions_picker%
985  <br />%commit_button%
986  ';
987  case 'not_logged_in':
988  return '<h2>'.translate('bsp_default_title_not_logged_in').'</h2>
989  %success_messages_list% %error_messages_list%
990  '.translate('username').': %subscribe_user_name% <br />
991  '.translate('email').': %subscribe_email_address% <br />
992  <h3>'.translate('bsp_default_subtitle_add_sub').'</h3>
993  %subscriptions_picker%
994  <h3>'.translate('bsp_default_subtitle_remove_sub').'</h3>
995  %unsubscriptions_picker%
996  <br />%commit_button%
997  ';
998  }
999  return '';
1000 
1001  }//end _getDefaultBodycopyContents()
1002 
1003 
1004 }//end class
1005 
1006 ?>