3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class generates form components for processing a pcp page creati
40 class CRM_PCP_Form_Campaign
extends CRM_Core_Form
{
44 public function preProcess() {
45 // we do not want to display recently viewed items, so turn off
46 $this->assign('displayRecent', FALSE);
48 // component null in controller object - fix? dgg
49 // $this->_component = $this->controller->get('component');
50 $this->_component
= CRM_Utils_Request
::retrieve('component', 'String', $this);
51 $this->assign('component', $this->_component
);
53 $this->_context
= CRM_Utils_Request
::retrieve('context', 'String', $this);
54 $this->assign('context', $this->_context
);
56 $this->_pageId
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
57 $title = ts('Setup a Personal Campaign Page - Step 2');
60 $title = ts('Edit Your Personal Campaign Page');
63 CRM_Utils_System
::setTitle($title);
67 public function setDefaultValues() {
69 $dao = new CRM_PCP_DAO_PCP();
72 $dao->id
= $this->_pageId
;
73 if ($dao->find(TRUE)) {
74 CRM_Core_DAO
::storeValues($dao, $defaults);
76 // fix the display of the monetary value, CRM-4038
77 if (isset($defaults['goal_amount'])) {
78 $defaults['goal_amount'] = CRM_Utils_Money
::format($defaults['goal_amount'], NULL, '%a');
81 $defaults['pcp_title'] = CRM_Utils_Array
::value('title', $defaults);
82 $defaults['pcp_intro_text'] = CRM_Utils_Array
::value('intro_text', $defaults);
85 if ($this->get('action') & CRM_Core_Action
::ADD
) {
86 $defaults['is_active'] = 1;
87 $defaults['is_honor_roll'] = 1;
88 $defaults['is_thermometer'] = 1;
91 $this->_contactID
= CRM_Utils_Array
::value('contact_id', $defaults);
92 $this->_contriPageId
= CRM_Utils_Array
::value('page_id', $defaults);
98 * Build the form object
103 public function buildQuickForm() {
104 $this->add('text', 'pcp_title', ts('Title'), NULL, TRUE);
105 $this->add('textarea', 'pcp_intro_text', ts('Welcome'), NULL, TRUE);
106 $this->add('text', 'goal_amount', ts('Your Goal'), NULL, TRUE);
107 $this->addRule('goal_amount', ts('Goal Amount should be a numeric value'), 'money');
109 $attributes = array();
110 if ($this->_component
== 'event') {
111 if ($this->get('action') & CRM_Core_Action
::ADD
) {
112 $attributes = array('value' => ts('Join Us'), 'onClick' => 'select();');
114 $this->add('text', 'donate_link_text', ts('Sign up Button'), $attributes);
117 if ($this->get('action') & CRM_Core_Action
::ADD
) {
118 $attributes = array('value' => ts('Donate Now'), 'onClick' => 'select();');
120 $this->add('text', 'donate_link_text', ts('Donation Button'), $attributes);
123 $attrib = array('rows' => 8, 'cols' => 60);
124 $this->add('textarea', 'page_text', ts('Your Message'), null, false );
127 CRM_Core_BAO_File
::buildAttachment($this, 'civicrm_pcp', $this->_pageId
, $maxAttachments);
129 $this->addElement('checkbox', 'is_thermometer', ts('Progress Bar'));
130 $this->addElement('checkbox', 'is_honor_roll', ts('Honor Roll'), NULL);
131 $this->addElement('checkbox', 'is_active', ts('Active'));
137 'name' => ts('Save'),
142 'name' => ts('Cancel'),
146 $this->addFormRule(array('CRM_PCP_Form_Campaign', 'formRule'), $this);
152 * @param array $fields the input form values
153 * @param array $files the uploaded files if any
157 * @return true if no errors, else array of errors
161 public static function formRule($fields, $files, $self) {
163 if ($fields['goal_amount'] <= 0) {
164 $errors['goal_amount'] = ts('Goal Amount should be a numeric value greater than zero.');
166 if (strlen($fields['donate_link_text']) >= 64) {
167 $errors['donate_link_text'] = ts('Button Text must be less than 64 characters.');
173 * Process the form submission
179 public function postProcess() {
180 $params = $this->controller
->exportValues( $this->_name
);
181 $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active');
183 foreach ($checkBoxes as $key) {
184 if (!isset($params[$key])) {
188 $session = CRM_Core_Session
::singleton();
189 $contactID = isset($this->_contactID
) ?
$this->_contactID
: $session->get('userID');
191 $contactID = $this->get('contactID');
193 $params['title'] = $params['pcp_title'];
194 $params['intro_text'] = $params['pcp_intro_text'];
195 $params['contact_id'] = $contactID;
196 $params['page_id'] = $this->get('component_page_id') ?
$this->get('component_page_id') : $this->_contriPageId
;
197 $params['page_type'] = $this->_component
;
199 // since we are allowing html input from the user
200 // we also need to purify it, so lets clean it up
201 $htmlFields = array( 'intro_text', 'page_text', 'title' );
202 foreach ( $htmlFields as $field ) {
203 if ( ! empty($params[$field]) ) {
204 $params[$field] = CRM_Utils_String
::purifyHTML($params[$field]);
208 $entity_table = CRM_PCP_BAO_PCP
::getPcpEntityTable($params['page_type']);
210 $pcpBlock = new CRM_PCP_DAO_PCPBlock();
211 $pcpBlock->entity_table
= $entity_table;
212 $pcpBlock->entity_id
= $params['page_id'];
213 $pcpBlock->find(TRUE);
215 $params['pcp_block_id'] = $pcpBlock->id
;
217 $params['goal_amount'] = CRM_Utils_Rule
::cleanMoney($params['goal_amount']);
219 $approval_needed = $pcpBlock->is_approval_needed
;
220 $approvalMessage = NULL;
222 if ($this->get('action') & CRM_Core_Action
::ADD
) {
223 $params['status_id'] = $approval_needed ?
1 : 2;
224 $approvalMessage = $approval_needed ?
ts('but requires administrator review before you can begin promoting your campaign. You will receive an email confirmation shortly which includes a link to return to this page.') : ts('and is ready to use.');
227 $params['id'] = $this->_pageId
;
229 $pcp = CRM_PCP_BAO_PCP
::add($params, FALSE);
232 // add attachments as needed
233 CRM_Core_BAO_File
::formatAttachment($params,
239 $pageStatus = isset($this->_pageId
) ?
ts('updated') : ts('created');
240 $statusId = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $pcp->id
, 'status_id');
242 //send notification of PCP create/update.
243 $pcpParams = array('entity_table' => $entity_table, 'entity_id' => $pcp->page_id
);
244 $notifyParams = array();
246 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
248 if ($emails = $pcpBlock->notify_email
) {
249 $this->assign('pcpTitle', $pcp->title
);
251 if ($this->_pageId
) {
252 $this->assign('mode', 'Update');
255 $this->assign('mode', 'Add');
257 $pcpStatus = CRM_Core_OptionGroup
::getLabel('pcp_status', $statusId);
258 $this->assign('pcpStatus', $pcpStatus);
260 $this->assign('pcpId', $pcp->id
);
262 $supporterUrl = CRM_Utils_System
::url('civicrm/contact/view',
263 "reset=1&cid={$pcp->contact_id}",
267 $this->assign('supporterUrl', $supporterUrl);
268 $supporterName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id
, 'display_name');
269 $this->assign('supporterName', $supporterName);
272 if ($this->_component
== 'contribute') {
273 $pageUrl = CRM_Utils_System
::url('civicrm/contribute/transact',
274 "reset=1&id={$pcpBlock->entity_id}",
278 $contribPageTitle = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcpBlock->entity_id
, 'title');
280 elseif ($this->_component
== 'event') {
281 $pageUrl = CRM_Utils_System
::url('civicrm/event',
282 "reset=1&id={$pcpBlock->entity_id}",
286 $contribPageTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $pcpBlock->entity_id
, 'title');
289 $this->assign('contribPageUrl', $pageUrl);
290 $this->assign('contribPageTitle', $contribPageTitle);
292 $managePCPUrl = CRM_Utils_System
::url('civicrm/admin/pcp',
297 $this->assign('managePCPUrl', $managePCPUrl);
299 //get the default domain email address.
300 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain
::getNameAndEmail();
302 if (!$domainEmailAddress ||
$domainEmailAddress == 'info@EXAMPLE.ORG') {
303 $fixUrl = CRM_Utils_System
::url('civicrm/admin/domain', 'action=update&reset=1');
304 CRM_Core_Error
::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM » Communications » FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
307 //if more than one email present for PCP notification ,
308 //first email take it as To and other as CC and First email
309 //address should be sent in users email receipt for
311 $emailArray = explode(',', $emails);
312 $to = $emailArray[0];
313 unset($emailArray[0]);
314 $cc = implode(',', $emailArray);
316 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
318 'groupName' => 'msg_tpl_workflow_contribution',
319 'valueName' => 'pcp_notify',
320 'contactId' => $contactID,
321 'from' => "$domainEmailName <$domainEmailAddress>",
328 $notifyStatus = ts('A notification email has been sent to the site administrator.');
332 CRM_Core_BAO_File
::processAttachment($params, 'civicrm_pcp', $pcp->id
);
334 // send email notification to supporter, if initial setup / add mode.
335 if (!$this->_pageId
) {
336 CRM_PCP_BAO_PCP
::sendStatusUpdate($pcp->id
, $statusId, TRUE, $this->_component
);
337 if ($approvalMessage && CRM_Utils_Array
::value('status_id', $params) == 1) {
338 $notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.');
342 //check if pcp created by anonymous user
344 if (!$session->get('userID')) {
348 CRM_Core_Session
::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3",
349 array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus)
351 if (!$this->_pageId
) {
352 $session->pushUserContext(CRM_Utils_System
::url('civicrm/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}"));
354 elseif ($this->_context
== 'dashboard') {
355 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/pcp', 'reset=1'));