4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
36 class CRM_Mailing_Form_Subscribe
extends CRM_Core_Form
{
37 protected $_groupID = NULL;
39 function preProcess() {
41 $this->_groupID
= CRM_Utils_Request
::retrieve('gid', 'Integer', $this,
42 FALSE, NULL, 'REQUEST'
45 // ensure that there is a destination, if not set the destination to the
47 if (!$this->controller
->getDestination()) {
48 $this->controller
->setDestination(NULL, TRUE);
52 if ($this->_groupID
) {
53 $groupTypeCondition = CRM_Contact_BAO_Group
::groupTypeCondition('Mailing');
55 // make sure requested qroup is accessible and exists
57 SELECT title, description
59 WHERE id={$this->_groupID}
60 AND visibility != 'User and User Admin Only'
61 AND $groupTypeCondition";
63 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
65 $this->assign('groupName', $dao->title
);
66 CRM_Utils_System
::setTitle(ts('Subscribe to Mailing List - %1', array(1 => $dao->title
)));
69 CRM_Core_Error
::statusBounce("The specified group is not configured for this action OR The group doesn't exist.");
72 $this->assign('single', TRUE);
75 $this->assign('single', FALSE);
76 CRM_Utils_System
::setTitle(ts('Mailing List Subscription'));
81 * Function to actually build the form
86 public function buildQuickForm() {
87 // add the email address
91 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Email',
96 $this->addRule('email', ts("Please enter a valid email address (e.g. 'yourname@example.com')."), 'email');
98 if (!$this->_groupID
) {
99 // create a selector box of all public groups
100 $groupTypeCondition = CRM_Contact_BAO_Group
::groupTypeCondition('Mailing');
103 SELECT id, title, description
105 WHERE ( saved_search_id = 0
106 OR saved_search_id IS NULL )
107 AND visibility != 'User and User Admin Only'
108 AND $groupTypeCondition
110 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
112 while ($dao->fetch()) {
114 $row['id'] = $dao->id
;
115 $row['title'] = $dao->title
;
116 $row['description'] = $dao->description
;
117 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $row['id'];
118 $this->addElement('checkbox',
125 CRM_Core_Error
::fatal(ts('There are no public mailing list groups to display.'));
127 $this->assign('rows', $rows);
128 $this->addFormRule(array('CRM_Mailing_Form_Subscribe', 'formRule'));
133 // if recaptcha is not configured, then dont add it
134 // CRM-11316 Only enable ReCAPTCHA for anonymous visitors
135 $config = CRM_Core_Config
::singleton();
136 $session = CRM_Core_Session
::singleton();
137 $contactID = $session->get('userID');
139 if (empty($config->recaptchaPublicKey
) ||
140 empty($config->recaptchaPrivateKey
) ||
145 // if this is POST request and came from a block,
146 // lets add recaptcha only if already present
147 // gross hack for now
148 if (!empty($_POST) &&
149 !array_key_exists('recaptcha_challenge_field', $_POST)
157 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
158 $captcha->add($this);
159 $this->assign('isCaptcha', TRUE);
162 $this->addButtons(array(
165 'name' => ts('Subscribe'),
170 'name' => ts('Cancel'),
176 static function formRule($fields) {
177 foreach ($fields as $name => $dontCare) {
178 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
182 return array('_qf_default' => 'Please select one or more mailing lists.');
191 public function postProcess() {
192 $params = $this->controller
->exportValues($this->_name
);
195 if ($this->_groupID
) {
196 $groups[] = $this->_groupID
;
199 foreach ($params as $name => $dontCare) {
200 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
201 $groups[] = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
206 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($groups, $params);