3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 * Page for displaying list of financial types
39 class CRM_PCP_Page_PCP
extends CRM_Core_Page_Basic
{
42 * The action links that we need to display for the browse screen
47 static $_links = NULL;
52 * @return string Classname of BAO.
54 function getBAOName() {
55 return 'CRM_PCP_BAO_PCP';
61 * @return array (reference) of action links
64 if (!(self
::$_links)) {
65 // helper variable for nicer formatting
66 $deleteExtra = ts('Are you sure you want to delete this Campaign Page ?');
68 self
::$_links = array(
69 CRM_Core_Action
::UPDATE
=> array(
71 'url' => 'civicrm/pcp/info',
72 'qs' => 'action=update&reset=1&id=%%id%%&context=dashboard',
73 'title' => ts('Edit Personal Campaign Page'),
75 CRM_Core_Action
::RENEW
=> array(
76 'name' => ts('Approve'),
77 'url' => 'civicrm/admin/pcp',
78 'qs' => 'action=renew&id=%%id%%',
79 'title' => ts('Approve Personal Campaign Page'),
81 CRM_Core_Action
::REVERT
=> array(
82 'name' => ts('Reject'),
83 'url' => 'civicrm/admin/pcp',
84 'qs' => 'action=revert&id=%%id%%',
85 'title' => ts('Reject Personal Campaign Page'),
87 CRM_Core_Action
::DELETE
=> array(
88 'name' => ts('Delete'),
89 'url' => 'civicrm/admin/pcp',
90 'qs' => 'action=delete&id=%%id%%',
91 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
92 'title' => ts('Delete Personal Campaign Page'),
94 CRM_Core_Action
::ENABLE
=> array('name' => ts('Enable'),
95 'url' => 'civicrm/admin/pcp',
96 'qs' => 'action=enable&id=%%id%%',
97 'title' => ts('Enable'),
99 CRM_Core_Action
::DISABLE
=> array('name' => ts('Disable'),
100 'url' => 'civicrm/admin/pcp',
101 'qs' => 'action=disable&id=%%id%%',
102 'title' => ts('Disable'),
106 return self
::$_links;
112 * This method is called after the page is created. It checks for the
113 * type of action and executes that action.
114 * Finally it calls the parent's run method.
122 // get the requested action
123 $action = CRM_Utils_Request
::retrieve('action', 'String',
127 if ($action & CRM_Core_Action
::REVERT
) {
128 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
129 CRM_PCP_BAO_PCP
::setIsActive($id, 0);
130 $session = CRM_Core_Session
::singleton();
131 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
133 elseif ($action & CRM_Core_Action
::RENEW
) {
134 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
135 CRM_PCP_BAO_PCP
::setIsActive($id, 1);
136 $session = CRM_Core_Session
::singleton();
137 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
139 elseif ($action & CRM_Core_Action
::DELETE
) {
140 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE);
141 $session = CRM_Core_Session
::singleton();
142 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&action=browse'));
143 $controller = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP',
144 'Personal Campaign Page',
145 CRM_Core_Action
::DELETE
147 //$this->setContext( $id, $action );
148 $controller->set('id', $id);
149 $controller->process();
150 return $controller->run();
161 * Browse all custom data groups.
164 * @param null $action
170 function browse($action = NULL) {
171 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
175 if ($this->_sortByCharacter
== 1 ||
178 $this->_sortByCharacter
= '';
182 $status = CRM_PCP_BAO_PCP
::buildOptions('status_id', 'create');
184 $pcpSummary = $params = array();
187 if (!empty($_POST) ||
!empty($_GET['page_type'])) {
188 if (!empty($_POST['status_id'])) {
189 $whereClause = ' AND cp.status_id = %1';
190 $params['1'] = array($_POST['status_id'], 'Integer');
193 if (!empty($_POST['page_type'])) {
194 $whereClause .= ' AND cp.page_type = %2';
195 $params['2'] = array($_POST['page_type'], 'String');
197 elseif (!empty($_GET['page_type'])) {
198 $whereClause .= ' AND cp.page_type = %2';
199 $params['2'] = array($_GET['page_type'], 'String');
202 if (!empty($_POST['page_id'])) {
203 $whereClause .= ' AND cp.page_id = %4 AND cp.page_type = "contribute"';
204 $params['4'] = array($_POST['page_id'], 'Integer');
207 if (!empty($_POST['event_id'])) {
208 $whereClause .= ' AND cp.page_id = %5 AND cp.page_type = "event"';
209 $params['5'] = array($_POST['event_id'], 'Integer');
213 $this->set('whereClause', $whereClause);
214 $this->set('params', $params);
217 $this->set('whereClause', NULL);
218 $this->set('params', NULL);
222 $approvedId = CRM_Core_OptionGroup
::getValue('pcp_status', 'Approved', 'name');
224 //check for delete CRM-4418
225 $allowToDelete = CRM_Core_Permission
::check('delete in CiviContribute');
227 // get all contribution pages
228 $query = "SELECT id, title, start_date, end_date FROM civicrm_contribution_page WHERE (1)";
229 $cpages = CRM_Core_DAO
::executeQuery($query);
230 while ($cpages->fetch()) {
231 $pages['contribute'][$cpages->id
]['id'] = $cpages->id
;
232 $pages['contribute'][$cpages->id
]['title'] = $cpages->title
;
233 $pages['contribute'][$cpages->id
]['start_date'] = $cpages->start_date
;
234 $pages['contribute'][$cpages->id
]['end_date'] = $cpages->end_date
;
237 // get all event pages. pcp campaign start and end dates for event related pcp's use the online registration start and end dates,
238 // altho if target is contribution page this might not be correct. fixme? dgg
239 $query = "SELECT id, title, start_date, end_date, registration_start_date, registration_end_date
241 WHERE is_template IS NULL OR is_template != 1";
242 $epages = CRM_Core_DAO
::executeQuery($query);
243 while ($epages->fetch()) {
244 $pages['event'][$epages->id
]['id'] = $epages->id
;
245 $pages['event'][$epages->id
]['title'] = $epages->title
;
246 $pages['event'][$epages->id
]['start_date'] = $epages->registration_start_date
;
247 $pages['event'][$epages->id
]['end_date'] = $epages->registration_end_date
;
250 $params = $this->get('params') ?
$this->get('params') : array();
253 if ($this->_sortByCharacter
!== NULL) {
254 $clauses[] = "cp.title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
258 SELECT cp.id, cp.contact_id , cp.status_id, cp.title, cp.is_active, cp.page_type, cp.page_id
260 WHERE $title" . $this->get('whereClause') . " ORDER BY cp.status_id";
262 $pcp = CRM_Core_DAO
::executeQuery($query, $params);
263 while ($pcp->fetch()) {
264 $action = array_sum(array_keys($this->links()));
265 $contact = CRM_Contact_BAO_Contact
::getDisplayAndImage($pcp->contact_id
);
269 if ($pcp->status_id
!= $approvedId ||
$pcp->is_active
!= 1) {
273 switch ($pcp->status_id
) {
275 $action -= CRM_Core_Action
::RENEW
;
279 $action -= CRM_Core_Action
::REVERT
;
283 switch ($pcp->is_active
) {
285 $action -= CRM_Core_Action
::ENABLE
;
289 $action -= CRM_Core_Action
::DISABLE
;
293 if (!$allowToDelete) {
294 $action -= CRM_Core_Action
::DELETE
;
297 $page_type = $pcp->page_type
;
298 $page_id = (int) $pcp->page_id
;
299 if ($pages[$page_type][$page_id]['title'] == '' ||
$pages[$page_type][$page_id]['title'] == NULL) {
300 $title = '(no title found for ' . $page_type . ' id ' . $page_id . ')';
303 $title = $pages[$page_type][$page_id]['title'];
306 if ($pcp->page_type
== 'contribute') {
307 $pageUrl = CRM_Utils_System
::url('civicrm/' . $page_type . '/transact', 'reset=1&id=' . $pcp->page_id
);
310 $pageUrl = CRM_Utils_System
::url('civicrm/' . $page_type . '/register', 'reset=1&id=' . $pcp->page_id
);
313 $pcpSummary[$pcp->id
] = array(
315 'start_date' => $pages[$page_type][$page_id]['start_date'],
316 'end_date' => $pages[$page_type][$page_id]['end_date'],
317 'supporter' => $contact['0'],
318 'supporter_id' => $pcp->contact_id
,
319 'status_id' => $status[$pcp->status_id
],
320 'page_id' => $page_id,
321 'page_title' => $title,
322 'page_url' => $pageUrl,
323 'page_type' => $page_type,
324 'action' => CRM_Core_Action
::formLink(self
::links(), $action,
325 array('id' => $pcp->id
), ts('more'), FALSE, 'contributionpage.pcp.list', 'PCP', $pcp->id
327 'title' => $pcp->title
,
333 $this->pagerAToZ($this->get('whereClause'), $params);
335 $this->assign('rows', $pcpSummary);
337 // Let template know if user has run a search or not
338 if ($this->get('whereClause')) {
339 $this->assign('isSearch', 1);
342 $this->assign('isSearch', 0);
348 if ($this->_action
& CRM_Core_Action
::DELETE
) {
352 $form = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP', ts('Search Campaign Pages'), CRM_Core_Action
::ADD
);
353 $form->setEmbedded(TRUE);
354 $form->setParent($this);
360 * Get name of edit form
362 * @return string Classname of edit form.
364 function editForm() {
365 return 'CRM_PCP_Form_PCP';
371 * @return string name of this page.
373 function editName() {
374 return ts('Personal Campaign Page');
382 * @return string user context.
384 function userContext($mode = NULL) {
385 return 'civicrm/admin/pcp';
388 //@TODO this function changed, debug this at runtime
390 * @param $whereClause
391 * @param $whereParams
393 function pagerAtoZ($whereClause, $whereParams) {
396 if (strpos($whereClause, ' AND') == 0) {
397 $whereClause = substr($whereClause, 4);
399 $where = 'WHERE ' . $whereClause;
403 SELECT UPPER(LEFT(cp.title, 1)) as sort_name
406 ORDER BY LEFT(cp.title, 1);
409 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
411 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
412 $this->assign('aToZ', $aToZBar);