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 * PCP Info Page - Summary about the PCP
39 class CRM_PCP_Page_PCPInfo
extends CRM_Core_Page
{
45 * This method is called after the page is created. It checks for the
46 * type of action and executes that action.
47 * Finally it calls the parent's run method.
52 public function run() {
53 $session = CRM_Core_Session
::singleton();
54 $config = CRM_Core_Config
::singleton();
55 $permissionCheck = FALSE;
57 if ($config->userFramework
!= 'Joomla') {
58 $permissionCheck = CRM_Core_Permission
::check('administer CiviCRM');
61 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
63 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
65 $prms = array('id' => $this->_id
);
67 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
68 $this->_component
= $pcpInfo['page_type'];
70 if (empty($pcpInfo)) {
71 $statusMessage = ts('The personal campaign page you requested is currently unavailable.');
72 CRM_Core_Error
::statusBounce($statusMessage,
73 $config->userFrameworkBaseURL
77 CRM_Utils_System
::setTitle($pcpInfo['title']);
78 $this->assign('pcp', $pcpInfo);
80 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
81 $approvedId = CRM_Core_OptionGroup
::getValue('pcp_status', 'Approved', 'name');
83 // check if PCP is created by anonymous user
84 $anonymousPCP = CRM_Utils_Request
::retrieve('ap', 'Boolean', $this);
86 $loginURL = $config->userSystem
->getLoginURL();
87 $anonMessage = ts('Once you\'ve received your new account welcome email, you can <a href=%1>click here</a> to login and promote your campaign page.', array(1 => $loginURL));
88 CRM_Core_Session
::setStatus($anonMessage, ts('Success'), 'success');
91 $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.');
94 $pcpBlock = new CRM_PCP_DAO_PCPBlock();
95 $pcpBlock->entity_table
= CRM_PCP_BAO_PCP
::getPcpEntityTable($pcpInfo['page_type']);
96 $pcpBlock->entity_id
= $pcpInfo['page_id'];
97 $pcpBlock->find(TRUE);
99 // Redirect back to source page in case of error.
100 if ($pcpInfo['page_type'] == 'contribute') {
101 $urlBase = 'civicrm/contribute/transact';
103 elseif ($pcpInfo['page_type'] == 'event') {
104 $urlBase = 'civicrm/event/register';
107 if ($pcpInfo['status_id'] != $approvedId ||
!$pcpInfo['is_active']) {
108 if ($pcpInfo['contact_id'] != $session->get('userID') && !$permissionCheck) {
109 CRM_Core_Error
::statusBounce($statusMessage, CRM_Utils_System
::url($urlBase,
110 "reset=1&id=" . $pcpInfo['page_id'],
111 FALSE, NULL, FALSE, TRUE
116 $getStatus = CRM_PCP_BAO_PCP
::getStatus($this->_id
, $this->_component
);
118 // PCP not enabled for this contribution page. Forward everyone to source page
119 CRM_Core_Error
::statusBounce($statusMessage, CRM_Utils_System
::url($urlBase,
120 "reset=1&id=" . $pcpInfo['page_id'],
121 FALSE, NULL, FALSE, TRUE
128 if ($pcpBlock->target_entity_type
== 'contribute') {
129 $urlBase = 'civicrm/contribute/transact';
131 elseif ($pcpBlock->target_entity_type
== 'event') {
132 $urlBase = 'civicrm/event/register';
135 if ($pcpBlock->entity_table
== 'civicrm_event') {
136 $page_class = 'CRM_Event_DAO_Event';
137 $this->assign('pageName', CRM_Event_PseudoConstant
::event($pcpInfo['page_id']));
138 CRM_Core_DAO
::commonRetrieveAll($page_class, 'id',
139 $pcpInfo['page_id'], $default, array('start_date', 'end_date', 'registration_start_date', 'registration_end_date')
142 elseif ($pcpBlock->entity_table
== 'civicrm_contribution_page') {
143 $page_class = 'CRM_Contribute_DAO_ContributionPage';
144 $this->assign('pageName', CRM_Contribute_PseudoConstant
::contributionPage($pcpInfo['page_id'], TRUE));
145 CRM_Core_DAO
::commonRetrieveAll($page_class, 'id',
146 $pcpInfo['page_id'], $default, array('start_date', 'end_date')
150 $pageInfo = $default[$pcpInfo['page_id']];
152 if ($pcpInfo['contact_id'] == $session->get('userID')) {
154 $owner['status'] = CRM_Utils_Array
::value($pcpInfo['status_id'], $pcpStatus);
156 $this->assign('owner', $owner);
158 $link = CRM_PCP_BAO_PCP
::pcpLinks();
161 CRM_Core_Action
::UPDATE
=> ts('Change the content and appearance of your page'),
162 CRM_Core_Action
::DETACH
=> ts('Send emails inviting your friends to support your campaign!'),
163 CRM_Core_Action
::VIEW
=> ts('Copy this link to share directly with your network!'),
164 CRM_Core_Action
::BROWSE
=> ts('Update your personal contact information'),
165 CRM_Core_Action
::DISABLE
=> ts('De-activate the page (you can re-activate it later)'),
166 CRM_Core_Action
::ENABLE
=> ts('Activate the page (you can de-activate it later)'),
167 CRM_Core_Action
::DELETE
=> ts('Remove the page (this cannot be undone!)'),
172 'block' => $pcpBlock->id
,
173 'pageComponent' => $this->_component
,
176 if (!$pcpBlock->is_tellfriend_enabled || CRM_Utils_Array
::value('status_id', $pcpInfo) != $approvedId) {
177 unset($link['all'][CRM_Core_Action
::DETACH
]);
180 switch ($pcpInfo['is_active']) {
182 unset($link['all'][CRM_Core_Action
::ENABLE
]);
186 unset($link['all'][CRM_Core_Action
::DISABLE
]);
190 $this->assign('links', $link['all']);
191 $this->assign('hints', $hints);
192 $this->assign('replace', $replace);
195 $honor = CRM_PCP_BAO_PCP
::honorRoll($this->_id
);
197 $entityFile = CRM_Core_BAO_File
::getEntityFile('civicrm_pcp', $this->_id
);
198 if (!empty($entityFile)) {
199 $fileInfo = reset($entityFile);
200 $fileId = $fileInfo['fileID'];
201 $image = '<img src="' . CRM_Utils_System
::url('civicrm/file',
202 "reset=1&id=$fileId&eid={$this->_id}"
204 $this->assign('image', $image);
207 $totalAmount = CRM_PCP_BAO_PCP
::thermoMeter($this->_id
);
208 $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2);
210 if ($pcpBlock->is_active
== 1) {
211 $linkTextUrl = CRM_Utils_System
::url('civicrm/contribute/campaign',
212 "action=add&reset=1&pageId={$pcpInfo['page_id']}&component={$pcpInfo['page_type']}",
216 $this->assign('linkTextUrl', $linkTextUrl);
217 $this->assign('linkText', $pcpBlock->link_text
);
220 $this->assign('honor', $honor);
221 $this->assign('total', $totalAmount ?
$totalAmount : '0.0');
222 $this->assign('achieved', $achieved <= 100 ?
$achieved : 100);
224 if ($achieved <= 100) {
225 $this->assign('remaining', 100 - $achieved);
227 // make sure that we are between contribution page start and end dates OR registration start date and end dates if they are set
228 if ($pcpBlock->entity_table
== 'civicrm_event') {
229 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_start_date', $pageInfo));
230 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_end_date', $pageInfo));
233 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('start_date', $pageInfo));
234 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $pageInfo));
239 if ($startDate && $startDate >= $now) {
242 if ($endDate && $endDate < $now) {
246 $this->assign('validDate', $validDate);
248 // form parent page url
249 if ($action == CRM_Core_Action
::PREVIEW
) {
250 $parentUrl = CRM_Utils_System
::url($urlBase,
251 "id={$pcpInfo['page_id']}&reset=1&action=preview",
257 $parentUrl = CRM_Utils_System
::url($urlBase,
258 "id={$pcpInfo['page_id']}&reset=1",
264 $this->assign('parentURL', $parentUrl);
268 $contributionText = ts('Contribute Now');
269 if (!empty($pcpInfo['donate_link_text'])) {
270 $contributionText = $pcpInfo['donate_link_text'];
273 $this->assign('contributionText', $contributionText);
275 // we always generate urls for the front end in joomla
276 if ($action == CRM_Core_Action
::PREVIEW
) {
277 $url = CRM_Utils_System
::url($urlBase,
278 "id=" . $pcpBlock->target_entity_id
. "&pcpId={$this->_id}&reset=1&action=preview",
284 $url = CRM_Utils_System
::url($urlBase,
285 "id=" . $pcpBlock->target_entity_id
. "&pcpId={$this->_id}&reset=1",
290 $this->assign('contributeURL', $url);
293 // we do not want to display recently viewed items, so turn off
294 $this->assign('displayRecent', FALSE);
296 $single = $permission = FALSE;
298 case CRM_Core_Action
::BROWSE
:
299 $subForm = 'PCPAccount';
300 $form = "CRM_PCP_Form_$subForm";
304 case CRM_Core_Action
::UPDATE
:
305 $subForm = 'Campaign';
306 $form = "CRM_PCP_Form_$subForm";
311 $userID = $session->get('userID');
312 //make sure the user has "administer CiviCRM" permission
313 //OR has created the PCP
314 if (CRM_Core_Permission
::check('administer CiviCRM') ||
315 ($userID && (CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'contact_id') == $userID))
319 if ($single && $permission) {
320 $controller = new CRM_Core_Controller_Simple($form, $subForm, $action);
321 $controller->set('id', $this->_id
);
322 $controller->set('single', TRUE);
323 $controller->process();
324 return $controller->run();
326 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&id=' . $this->_id
));
333 public function getTemplateFileName() {
335 $templateFile = "CRM/PCP/Page/{$this->_id}/PCPInfo.tpl";
336 $template = &CRM_Core_Page
::getTemplate();
337 if ($template->template_exists($templateFile)) {
338 return $templateFile;
341 return parent
::getTemplateFileName();