/** * Send subscribe mail. * * @param array $groups * The list of group ids for subscribe. * @param array $params * The list of email. * @param int $contactId * Currently used during event registration/contribution. * Specifically to avoid linking group to wrong duplicate contact * during event registration. * @param string $context * * @return void */ public static function commonSubscribe(&$groups, &$params, $contactId = NULL, $context = NULL) { $contactGroups = CRM_Mailing_Event_BAO_Subscribe::getContactGroups($params['email'], $contactId); $group = array(); $success = NULL; foreach ($groups as $groupID) { $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $groupID, 'title'); if (array_key_exists($groupID, $contactGroups) && $contactGroups[$groupID]['status'] != 'Removed') { $group[$groupID]['title'] = $contactGroups[$groupID]['title']; $group[$groupID]['status'] = $contactGroups[$groupID]['status']; $status = ts('You are already subscribed in %1, your subscription is %2.', array(1 => $group[$groupID]['title'], 2 => ts($group[$groupID]['status']))); CRM_Utils_System::setUFMessage($status); continue; } $se = self::subscribe($groupID, $params['email'], $contactId, $context); if ($se !== NULL) { $success = TRUE; $groupAdded[] = $title; // Ask the contact for confirmation $se->send_confirm_request($params['email']); } else { $success = FALSE; $groupFailed[] = $title; } } if ($success) { $groupTitle = implode(', ', $groupAdded); CRM_Utils_System::setUFMessage(ts('Your subscription request has been submitted for %1. Check your inbox shortly for the confirmation email(s). If you do not see a confirmation email, please check your spam/junk mail folder.', array(1 => $groupTitle))); } elseif ($success === FALSE) { $groupTitle = implode(',', $groupFailed); CRM_Utils_System::setUFMessage(ts('We had a problem processing your subscription request for %1. You have tried to subscribe to a private group and/or we encountered a database error. Please contact the site administrator.', array(1 => $groupTitle))); } }
static function formRule(&$fields) { $groups = CRM_Mailing_Event_BAO_Subscribe::getContactGroups($fields['email']); foreach ($fields as $name => $dontCare) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $gid = substr($name, CRM_Core_Form::CB_PREFIX_LEN); if (array_key_exists($gid, $groups)) { $errors[$name] = ts('You are already subscribed in %1, your subscription is %2.', array(1 => $groups[$gid]['title'], 2 => $groups[$gid]['status'])); } } } if ($errors) { return $errors; } else { foreach ($fields as $name => $dontCare) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { return true; } } } return array('_qf_default' => 'Please select one or more mailing lists.'); }