4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 set, then dont add it
134 $config = CRM_Core_Config
::singleton();
135 if (empty($config->recaptchaPublicKey
) ||
136 empty($config->recaptchaPrivateKey
)
141 // if this is POST request and came from a block,
142 // lets add recaptcha only if already present
143 // gross hack for now
144 if (!empty($_POST) &&
145 !array_key_exists('recaptcha_challenge_field', $_POST)
153 $captcha = CRM_Utils_ReCAPTCHA
::singleton();
154 $captcha->add($this);
157 $this->addButtons(array(
160 'name' => ts('Subscribe'),
165 'name' => ts('Cancel'),
171 static function formRule($fields) {
172 foreach ($fields as $name => $dontCare) {
173 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
177 return array('_qf_default' => 'Please select one or more mailing lists.');
186 public function postProcess() {
187 $params = $this->controller
->exportValues($this->_name
);
190 if ($this->_groupID
) {
191 $groups[] = $this->_groupID
;
194 foreach ($params as $name => $dontCare) {
195 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
196 $groups[] = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
201 CRM_Mailing_Event_BAO_Subscribe
::commonSubscribe($groups, $params);