3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * Page for displaying list of financial types
23 class CRM_PCP_Page_PCP
extends CRM_Core_Page_Basic
{
26 * The action links that we need to display for the browse screen.
30 public static $_links = NULL;
38 public function getBAOName() {
39 return 'CRM_PCP_BAO_PCP';
46 * (reference) of action links
48 public function &links() {
49 if (!(self
::$_links)) {
50 // helper variable for nicer formatting
51 $deleteExtra = ts('Are you sure you want to delete this Campaign Page ?');
53 self
::$_links = array(
54 CRM_Core_Action
::UPDATE
=> array(
56 'url' => 'civicrm/pcp/info',
57 'qs' => 'action=update&reset=1&id=%%id%%&context=dashboard',
58 'title' => ts('Edit Personal Campaign Page'),
60 CRM_Core_Action
::RENEW
=> array(
61 'name' => ts('Approve'),
62 'url' => 'civicrm/admin/pcp',
63 'qs' => 'action=renew&id=%%id%%',
64 'title' => ts('Approve Personal Campaign Page'),
66 CRM_Core_Action
::REVERT
=> array(
67 'name' => ts('Reject'),
68 'url' => 'civicrm/admin/pcp',
69 'qs' => 'action=revert&id=%%id%%',
70 'title' => ts('Reject Personal Campaign Page'),
72 CRM_Core_Action
::DELETE
=> array(
73 'name' => ts('Delete'),
74 'url' => 'civicrm/admin/pcp',
75 'qs' => 'action=delete&id=%%id%%',
76 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
77 'title' => ts('Delete Personal Campaign Page'),
79 CRM_Core_Action
::ENABLE
=> array(
80 'name' => ts('Enable'),
81 'url' => 'civicrm/admin/pcp',
82 'qs' => 'action=enable&id=%%id%%',
83 'title' => ts('Enable'),
85 CRM_Core_Action
::DISABLE
=> array(
86 'name' => ts('Disable'),
87 'url' => 'civicrm/admin/pcp',
88 'qs' => 'action=disable&id=%%id%%',
89 'title' => ts('Disable'),
99 * This method is called after the page is created. It checks for the
100 * type of action and executes that action.
101 * Finally it calls the parent's run method.
107 public function run() {
108 $id = $this->getIdAndAction();
110 if ($this->_action
& CRM_Core_Action
::REVERT
) {
111 CRM_PCP_BAO_PCP
::setIsActive($id, 0);
112 $session = CRM_Core_Session
::singleton();
113 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
115 elseif ($this->_action
& CRM_Core_Action
::RENEW
) {
116 CRM_PCP_BAO_PCP
::setIsActive($id, 1);
117 $session = CRM_Core_Session
::singleton();
118 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
120 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
121 $session = CRM_Core_Session
::singleton();
122 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&action=browse'));
123 $controller = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP',
124 'Personal Campaign Page',
125 CRM_Core_Action
::DELETE
127 //$this->setContext( $id, $action );
128 $controller->set('id', $id);
129 $controller->process();
130 return $controller->run();
137 CRM_Core_Page
::run();
141 * Browse all custom data groups.
144 * @param null $action
148 public function browse($action = NULL) {
149 CRM_Core_Resources
::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
151 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
155 if ($this->_sortByCharacter
== 1 ||
158 $this->_sortByCharacter
= '';
161 $status = CRM_PCP_BAO_PCP
::buildOptions('status_id', 'create');
163 $pcpSummary = $params = array();
166 if (!empty($_POST) ||
!empty($_GET['page_type'])) {
167 if (!empty($_POST['status_id'])) {
168 $whereClause = ' AND cp.status_id = %1';
169 $params['1'] = array($_POST['status_id'], 'Integer');
172 if (!empty($_POST['page_type'])) {
173 $whereClause .= ' AND cp.page_type = %2';
174 $params['2'] = array($_POST['page_type'], 'String');
176 elseif (!empty($_GET['page_type'])) {
177 $whereClause .= ' AND cp.page_type = %2';
178 $params['2'] = array($_GET['page_type'], 'String');
181 if (!empty($_POST['page_id'])) {
182 $whereClause .= ' AND cp.page_id = %4 AND cp.page_type = "contribute"';
183 $params['4'] = array($_POST['page_id'], 'Integer');
186 if (!empty($_POST['event_id'])) {
187 $whereClause .= ' AND cp.page_id = %5 AND cp.page_type = "event"';
188 $params['5'] = array($_POST['event_id'], 'Integer');
192 $this->set('whereClause', $whereClause);
193 $this->set('params', $params);
196 $this->set('whereClause', NULL);
197 $this->set('params', NULL);
201 $approvedId = CRM_Core_PseudoConstant
::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
203 //check for delete CRM-4418
204 $allowToDelete = CRM_Core_Permission
::check('delete in CiviContribute');
206 // get all contribution pages
207 $query = "SELECT id, title, start_date, end_date FROM civicrm_contribution_page WHERE (1)";
208 $cpages = CRM_Core_DAO
::executeQuery($query);
209 while ($cpages->fetch()) {
210 $pages['contribute'][$cpages->id
]['id'] = $cpages->id
;
211 $pages['contribute'][$cpages->id
]['title'] = $cpages->title
;
212 $pages['contribute'][$cpages->id
]['start_date'] = $cpages->start_date
;
213 $pages['contribute'][$cpages->id
]['end_date'] = $cpages->end_date
;
216 // get all event pages. pcp campaign start and end dates for event related pcp's use the online registration start and end dates,
217 // although if target is contribution page this might not be correct. fixme? dgg
218 $query = "SELECT id, title, start_date, end_date, registration_start_date, registration_end_date
220 WHERE is_template IS NULL OR is_template != 1";
221 $epages = CRM_Core_DAO
::executeQuery($query);
222 while ($epages->fetch()) {
223 $pages['event'][$epages->id
]['id'] = $epages->id
;
224 $pages['event'][$epages->id
]['title'] = $epages->title
;
225 $pages['event'][$epages->id
]['start_date'] = $epages->registration_start_date
;
226 $pages['event'][$epages->id
]['end_date'] = $epages->registration_end_date
;
229 $params = $this->get('params') ?
$this->get('params') : array();
232 if ($this->_sortByCharacter
!== NULL) {
233 $clauses[] = "cp.title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
237 SELECT cp.id, cp.contact_id , cp.status_id, cp.title, cp.is_active, cp.page_type, cp.page_id
239 WHERE $title" . $this->get('whereClause') . " ORDER BY cp.status_id";
241 $pcp = CRM_Core_DAO
::executeQuery($query, $params);
242 while ($pcp->fetch()) {
243 $action = array_sum(array_keys($this->links()));
244 $contact = CRM_Contact_BAO_Contact
::getDisplayAndImage($pcp->contact_id
);
248 if ($pcp->status_id
!= $approvedId ||
$pcp->is_active
!= 1) {
252 switch ($pcp->status_id
) {
254 $action -= CRM_Core_Action
::RENEW
;
258 $action -= CRM_Core_Action
::REVERT
;
262 switch ($pcp->is_active
) {
264 $action -= CRM_Core_Action
::ENABLE
;
268 $action -= CRM_Core_Action
::DISABLE
;
272 if (!$allowToDelete) {
273 $action -= CRM_Core_Action
::DELETE
;
276 $page_type = $pcp->page_type
;
277 $page_id = (int) $pcp->page_id
;
278 if ($pages[$page_type][$page_id]['title'] == '' ||
$pages[$page_type][$page_id]['title'] == NULL) {
279 $title = '(no title found for ' . $page_type . ' id ' . $page_id . ')';
282 $title = $pages[$page_type][$page_id]['title'];
285 if ($pcp->page_type
== 'contribute') {
286 $pageUrl = CRM_Utils_System
::url('civicrm/' . $page_type . '/transact', 'reset=1&id=' . $pcp->page_id
);
289 $pageUrl = CRM_Utils_System
::url('civicrm/' . $page_type . '/register', 'reset=1&id=' . $pcp->page_id
);
292 $pcpSummary[$pcp->id
] = array(
294 'start_date' => $pages[$page_type][$page_id]['start_date'],
295 'end_date' => $pages[$page_type][$page_id]['end_date'],
296 'supporter' => $contact['0'],
297 'supporter_id' => $pcp->contact_id
,
298 'status_id' => $status[$pcp->status_id
],
299 'page_id' => $page_id,
300 'page_title' => $title,
301 'page_url' => $pageUrl,
302 'page_type' => $page_type,
303 'action' => CRM_Core_Action
::formLink(self
::links(), $action,
304 array('id' => $pcp->id
), ts('more'), FALSE, 'contributionpage.pcp.list', 'PCP', $pcp->id
306 'title' => $pcp->title
,
312 $this->pagerAToZ($this->get('whereClause'), $params);
314 $this->assign('rows', $pcpSummary);
316 // Let template know if user has run a search or not
317 if ($this->get('whereClause')) {
318 $this->assign('isSearch', 1);
321 $this->assign('isSearch', 0);
325 public function search() {
327 if ($this->_action
& CRM_Core_Action
::DELETE
) {
331 $form = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP', ts('Search Campaign Pages'), CRM_Core_Action
::ADD
);
332 $form->setEmbedded(TRUE);
333 $form->setParent($this);
339 * Get name of edit form.
342 * Classname of edit form.
344 public function editForm() {
345 return 'CRM_PCP_Form_PCP';
349 * Get edit form name.
354 public function editName() {
355 return ts('Personal Campaign Page');
366 public function userContext($mode = NULL) {
367 return 'civicrm/admin/pcp';
371 * @TODO this function changed, debug this at runtime
372 * @param $whereClause
373 * @param array $whereParams
375 public function pagerAtoZ($whereClause, $whereParams) {
378 if (strpos($whereClause, ' AND') == 0) {
379 $whereClause = substr($whereClause, 4);
381 $where = 'WHERE ' . $whereClause;
385 SELECT UPPER(LEFT(cp.title, 1)) as sort_name
388 ORDER BY LEFT(cp.title, 1);
391 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
393 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
394 $this->assign('aToZ', $aToZBar);