3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 class CRM_Mailing_Form_Subscribe
extends CRM_Core_Form
{
36 protected $_groupID = NULL;
38 public function preProcess() {
40 $this->_groupID
= CRM_Utils_Request
::retrieve('gid', 'Integer', $this,
41 FALSE, NULL, 'REQUEST'
44 // ensure that there is a destination, if not set the destination to the
46 if (!$this->controller
->getDestination()) {
47 $this->controller
->setDestination(NULL, TRUE);
50 if ($this->_groupID
) {
51 $groupTypeCondition = CRM_Contact_BAO_Group
::groupTypeCondition('Mailing');
53 // make sure requested qroup is accessible and exists
55 SELECT title, description
57 WHERE id={$this->_groupID}
58 AND visibility != 'User and User Admin Only'
59 AND $groupTypeCondition";
61 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
63 $this->assign('groupName', $dao->title
);
64 CRM_Utils_System
::setTitle(ts('Subscribe to Mailing List - %1', array(1 => $dao->title
)));
67 CRM_Core_Error
::statusBounce("The specified group is not configured for this action OR The group doesn't exist.");
70 $this->assign('single', TRUE);
73 $this->assign('single', FALSE);
74 CRM_Utils_System
::setTitle(ts('Mailing List Subscription'));
79 * Build the form object.
83 public function buildQuickForm() {
84 // add the email address
88 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Email',
93 $this->addRule('email', ts("Please enter a valid email address."), 'email');
95 if (!$this->_groupID
) {
96 // create a selector box of all public groups
97 $groupTypeCondition = CRM_Contact_BAO_Group
::groupTypeCondition('Mailing');
100 SELECT id, title, description
102 WHERE ( saved_search_id = 0
103 OR saved_search_id IS NULL )
104 AND visibility != 'User and User Admin Only'
105 AND $groupTypeCondition
107 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
109 while ($dao->fetch()) {
111 $row['id'] = $dao->id
;
112 $row['title'] = $dao->title
;
113 $row['description'] = $dao->description
;
114 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $row['id'];
115 $this->addElement('checkbox',
122 CRM_Core_Error
::fatal(ts('There are no public mailing list groups to display.'));
124 $this->assign('rows', $rows);
125 $this->addFormRule(array('CRM_Mailing_Form_Subscribe', 'formRule'));
130 // if recaptcha is not configured, then dont add it
131 // CRM-11316 Only enable ReCAPTCHA for anonymous visitors
132 $config = CRM_Core_Config
::singleton();
133 $session = CRM_Core_Session
::singleton();
134 $contactID = $session->get('userID');
136 if (empty($config->recaptchaPublicKey
) ||
137 empty($config->recaptchaPrivateKey
) ||
143 // if this is POST request and came from a block,
144 // lets add recaptcha only if already present
145 // gross hack for now
146 if (!empty($_POST) &&
147 !array_key_exists('recaptcha_challenge_field', $_POST)
155 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
156 $captcha->add($this);
157 $this->assign('isCaptcha', TRUE);
160 $this->addButtons(array(
163 'name' => ts('Subscribe'),
168 'name' => ts('Cancel'),
179 public static function formRule($fields) {
180 foreach ($fields as $name => $dontCare) {
181 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
185 return array('_qf_default' => 'Please select one or more mailing lists.');
192 public function postProcess() {
193 $params = $this->controller
->exportValues($this->_name
);
196 if ($this->_groupID
) {
197 $groups[] = $this->_groupID
;
200 foreach ($params as $name => $dontCare) {
201 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
202 $groups[] = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
207 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($groups, $params);