Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Page for displaying list of events | |
38 | */ | |
39 | class CRM_Event_Page_ManageEvent extends CRM_Core_Page { | |
40 | ||
41 | /** | |
42 | * The action links that we need to display for the browse screen | |
43 | * | |
44 | * @var array | |
45 | * @static | |
46 | */ | |
47 | static $_actionLinks = NULL; | |
48 | ||
49 | static $_links = NULL; | |
50 | ||
d7d7d5ab | 51 | static $_tabLinks = NULL; |
52 | ||
6a488035 TO |
53 | protected $_pager = NULL; |
54 | ||
55 | protected $_sortByCharacter; | |
56 | ||
57 | protected $_isTemplate = FALSE; | |
58 | ||
59 | /** | |
60 | * Get action Links | |
61 | * | |
62 | * @return array (reference) of action links | |
63 | */ | |
64 | function &links() { | |
65 | if (!(self::$_actionLinks)) { | |
66 | // helper variable for nicer formatting | |
67 | $copyExtra = ts('Are you sure you want to make a copy of this Event?'); | |
68 | $deleteExtra = ts('Are you sure you want to delete this Event?'); | |
69 | ||
70 | self::$_actionLinks = array( | |
71 | CRM_Core_Action::DISABLE => array( | |
72 | 'name' => ts('Disable'), | |
73 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Event_BAO_Event' . '\',\'' . 'enable-disable' . '\' );"', | |
74 | 'ref' => 'disable-action', | |
75 | 'title' => ts('Disable Event'), | |
76 | ), | |
77 | CRM_Core_Action::ENABLE => array( | |
78 | 'name' => ts('Enable'), | |
79 | 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Event_BAO_Event' . '\',\'' . 'disable-enable' . '\' );"', | |
80 | 'ref' => 'enable-action', | |
81 | 'title' => ts('Enable Event'), | |
82 | ), | |
83 | CRM_Core_Action::DELETE => array( | |
84 | 'name' => ts('Delete'), | |
85 | 'url' => CRM_Utils_System::currentPath(), | |
86 | 'qs' => 'action=delete&id=%%id%%', | |
87 | 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', | |
88 | 'title' => ts('Delete Event'), | |
89 | ), | |
90 | CRM_Core_Action::COPY => array( | |
91 | 'name' => ts('Copy'), | |
92 | 'url' => CRM_Utils_System::currentPath(), | |
93 | 'qs' => 'reset=1&action=copy&id=%%id%%', | |
94 | 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"', | |
95 | 'title' => ts('Copy Event'), | |
96 | ), | |
97 | ); | |
98 | } | |
99 | return self::$_actionLinks; | |
100 | } | |
101 | ||
d7d7d5ab | 102 | /** |
103 | * Get tab Links for events | |
104 | * | |
105 | * @return array (reference) of tab links | |
106 | */ | |
107 | function &tabs($enableCart) { | |
108 | if (!(self::$_tabLinks)) { | |
109 | self::$_tabLinks = array( | |
110 | 'settings' => array( | |
111 | 'title' => ts('Info and Settings'), | |
112 | 'url' => 'civicrm/event/manage/settings', | |
113 | 'field' => 'id' | |
114 | ), | |
115 | 'location' => array( | |
116 | 'title' => ts('Location'), | |
117 | 'url' => 'civicrm/event/manage/location', | |
118 | 'field' => 'is_show_location', | |
119 | ), | |
120 | 'fee' => array( | |
121 | 'title' => ts('Fees'), | |
122 | 'url' => 'civicrm/event/manage/fee', | |
123 | 'field' => 'is_monetary', | |
124 | ), | |
125 | 'registration' => array( | |
126 | 'title' => ts('Online Registration'), | |
127 | 'url' => 'civicrm/event/manage/registration', | |
128 | 'field' => 'is_online_registration', | |
129 | ), | |
130 | 'reminder' => array( | |
131 | 'title' => ts('Schedule Reminders'), | |
132 | 'url' => 'civicrm/event/manage/reminder', | |
133 | 'field' => 'reminder', | |
134 | ), | |
135 | 'conference' => array( | |
136 | 'title' => ts('Conference Slots'), | |
137 | 'url' => 'civicrm/event/manage/conference', | |
138 | 'field' => 'slot_label_id', | |
139 | ), | |
140 | 'friend' => array( | |
141 | 'title' => ts('Tell a Friend'), | |
142 | 'url' => 'civicrm/event/manage/friend', | |
143 | 'field' => 'friend', | |
144 | ), | |
145 | 'pcp' => array( | |
146 | 'title' => ts('Personal Campaign Pages'), | |
147 | 'url' => 'civicrm/event/manage/pcp', | |
148 | 'field' => 'is_pcp_enabled', | |
149 | ), | |
150 | ); | |
151 | } | |
152 | ||
153 | if (!$enableCart) { | |
154 | unset(self::$_tabLinks['conference']); | |
155 | } | |
156 | ||
157 | CRM_Utils_Hook::tabset('civicrm/event/manage', self::$_tabLinks, array()); | |
158 | return self::$_tabLinks; | |
159 | } | |
160 | ||
6a488035 TO |
161 | /** |
162 | * Run the page. | |
163 | * | |
164 | * This method is called after the page is created. It checks for the | |
165 | * type of action and executes that action. | |
166 | * Finally it calls the parent's run method. | |
167 | * | |
168 | * @return void | |
169 | * @access public | |
170 | * | |
171 | */ | |
172 | function run() { | |
173 | // get the requested action | |
174 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
175 | // default to 'browse' | |
176 | $this, FALSE, 'browse' | |
177 | ); | |
178 | ||
179 | // assign vars to templates | |
180 | $this->assign('action', $action); | |
181 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
182 | $this, FALSE, 0, 'REQUEST' | |
183 | ); | |
184 | ||
185 | // figure out whether we’re handling an event or an event template | |
186 | if ($id) { | |
187 | $this->_isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_template'); | |
188 | } | |
189 | elseif ($action & CRM_Core_Action::ADD) { | |
190 | $this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this); | |
191 | } | |
192 | ||
193 | if (!$this->_isTemplate && $id) { | |
194 | $breadCrumb = array(array('title' => ts('Manage Events'), | |
195 | 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'), | |
196 | )); | |
197 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
198 | } | |
199 | ||
200 | // what action to take ? | |
201 | if ($action & CRM_Core_Action::DELETE) { | |
202 | $session = CRM_Core_Session::singleton(); | |
203 | $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=browse')); | |
204 | $controller = new CRM_Core_Controller_Simple('CRM_Event_Form_ManageEvent_Delete', | |
205 | 'Delete Event', | |
206 | $action | |
207 | ); | |
208 | $controller->set('id', $id); | |
209 | $controller->process(); | |
210 | return $controller->run(); | |
211 | } | |
212 | elseif ($action & CRM_Core_Action::COPY) { | |
213 | $this->copy(); | |
214 | } | |
215 | ||
216 | // finally browse the custom groups | |
217 | $this->browse(); | |
218 | ||
219 | // parent run | |
220 | return parent::run(); | |
221 | } | |
222 | ||
223 | /** | |
224 | * browse all events | |
225 | * | |
226 | * @return void | |
227 | */ | |
228 | function browse() { | |
229 | $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', | |
230 | 'String', | |
231 | $this | |
232 | ); | |
233 | $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0); | |
234 | if (strtolower($this->_sortByCharacter) == 'all' || | |
235 | !empty($_POST) | |
236 | ) { | |
237 | $this->_sortByCharacter = ''; | |
238 | $this->set('sortByCharacter', ''); | |
239 | } | |
240 | ||
241 | $this->_force = $this->_searchResult = NULL; | |
242 | ||
243 | $this->search(); | |
244 | ||
6a488035 TO |
245 | $params = array(); |
246 | $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', | |
247 | $this, FALSE | |
248 | ); | |
249 | $this->_searchResult = CRM_Utils_Request::retrieve('searchResult', 'Boolean', $this); | |
250 | ||
251 | $whereClause = $this->whereClause($params, FALSE, $this->_force); | |
252 | $this->pagerAToZ($whereClause, $params); | |
253 | ||
254 | $params = array(); | |
255 | $whereClause = $this->whereClause($params, TRUE, $this->_force); | |
256 | // because is_template != 1 would be to simple | |
257 | $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)'; | |
258 | ||
259 | $this->pager($whereClause, $params); | |
260 | ||
261 | list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); | |
262 | ||
263 | // get all custom groups sorted by weight | |
264 | $manageEvent = array(); | |
265 | ||
266 | $query = " | |
267 | SELECT * | |
268 | FROM civicrm_event | |
269 | WHERE $whereClause | |
270 | ORDER BY start_date desc | |
271 | LIMIT $offset, $rowCount"; | |
272 | ||
273 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event'); | |
274 | $permissions = CRM_Event_BAO_Event::checkPermission(); | |
275 | ||
276 | //get all campaigns. | |
277 | $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
278 | ||
279 | // get the list of active event pcps | |
280 | $eventPCPS = array(); | |
281 | ||
282 | $pcpDao = new CRM_PCP_DAO_PCPBlock; | |
283 | $pcpDao->entity_table = 'civicrm_event'; | |
284 | $pcpDao->find(); | |
285 | ||
286 | while ($pcpDao->fetch()) { | |
287 | $eventPCPS[$pcpDao->entity_id] = $pcpDao->entity_id; | |
288 | } | |
d7d7d5ab | 289 | // check if we're in shopping cart mode for events |
290 | $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, | |
291 | 'enable_cart' | |
292 | ); | |
293 | $this->assign('eventCartEnabled', $enableCart); | |
294 | $mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', 'civicrm_event', 'id', 'entity_value'); | |
6a488035 TO |
295 | |
296 | while ($dao->fetch()) { | |
297 | if (in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])) { | |
298 | $manageEvent[$dao->id] = array(); | |
299 | CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]); | |
300 | ||
301 | // form all action links | |
302 | $action = array_sum(array_keys($this->links())); | |
303 | ||
304 | if ($dao->is_active) { | |
305 | $action -= CRM_Core_Action::ENABLE; | |
306 | } | |
307 | else { | |
308 | $action -= CRM_Core_Action::DISABLE; | |
309 | } | |
310 | ||
311 | if (!in_array($dao->id, $permissions[CRM_Core_Permission::DELETE])) { | |
312 | $action -= CRM_Core_Action::DELETE; | |
313 | } | |
314 | if (!in_array($dao->id, $permissions[CRM_Core_Permission::EDIT])) { | |
315 | $action -= CRM_Core_Action::UPDATE; | |
316 | } | |
317 | ||
318 | $manageEvent[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), | |
319 | $action, | |
320 | array('id' => $dao->id), | |
321 | ts('more'), | |
322 | TRUE | |
323 | ); | |
324 | ||
325 | $params = array( | |
326 | 'entity_id' => $dao->id, | |
327 | 'entity_table' => 'civicrm_event', | |
328 | 'is_active' => 1, | |
329 | ); | |
330 | ||
331 | $defaults['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); | |
332 | ||
333 | $manageEvent[$dao->id]['friend'] = CRM_Friend_BAO_Friend::getValues($params); | |
334 | ||
335 | if (isset($defaults['location']['address'][1]['city'])) { | |
336 | $manageEvent[$dao->id]['city'] = $defaults['location']['address'][1]['city']; | |
337 | } | |
338 | if (isset($defaults['location']['address'][1]['state_province_id'])) { | |
339 | $manageEvent[$dao->id]['state_province'] = CRM_Core_PseudoConstant::stateProvince($defaults['location']['address'][1]['state_province_id']); | |
340 | } | |
341 | ||
342 | //show campaigns on selector. | |
343 | $manageEvent[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns); | |
d7d7d5ab | 344 | $manageEvent[$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mappingID); |
6a488035 TO |
345 | $manageEvent[$dao->id]['is_pcp_enabled'] = CRM_Utils_Array::value($dao->id, $eventPCPS); |
346 | } | |
347 | } | |
d7d7d5ab | 348 | $manageEvent['tab'] = self::tabs($enableCart); |
6a488035 TO |
349 | $this->assign('rows', $manageEvent); |
350 | ||
351 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); | |
352 | $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0'); | |
353 | $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); | |
354 | $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); | |
355 | $this->assign('findParticipants', $findParticipants); | |
6a488035 TO |
356 | } |
357 | ||
358 | /** | |
359 | * This function is to make a copy of a Event, including | |
360 | * all the fields in the event wizard | |
361 | * | |
362 | * @return void | |
363 | * @access public | |
364 | */ | |
365 | function copy() { | |
366 | $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE, 0, 'GET'); | |
367 | ||
368 | $urlString = 'civicrm/event/manage'; | |
369 | $copyEvent = CRM_Event_BAO_Event::copy($id); | |
370 | $urlParams = 'reset=1'; | |
371 | // Redirect to Copied Event Configuration | |
372 | if ($copyEvent->id) { | |
373 | $urlString = 'civicrm/event/manage/settings'; | |
374 | $urlParams .= '&action=update&id=' . $copyEvent->id; | |
375 | } | |
376 | ||
377 | return CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams)); | |
378 | } | |
379 | ||
380 | function search() { | |
381 | if (isset($this->_action) & | |
382 | (CRM_Core_Action::ADD | | |
383 | CRM_Core_Action::UPDATE | | |
384 | CRM_Core_Action::DELETE | |
385 | ) | |
386 | ) { | |
387 | return; | |
388 | } | |
389 | ||
390 | $form = new CRM_Core_Controller_Simple('CRM_Event_Form_SearchEvent', ts('Search Events'), CRM_Core_Action::ADD); | |
391 | $form->setEmbedded(TRUE); | |
392 | $form->setParent($this); | |
393 | $form->process(); | |
394 | $form->run(); | |
395 | } | |
396 | ||
397 | function whereClause(&$params, $sortBy = TRUE, $force) { | |
398 | $values = array(); | |
399 | $clauses = array(); | |
400 | $title = $this->get('title'); | |
401 | $createdId = $this->get('cid'); | |
402 | ||
403 | if ($createdId) { | |
404 | $clauses[] = "(created_id = {$createdId})"; | |
405 | } | |
406 | ||
407 | if ($title) { | |
408 | $clauses[] = "title LIKE %1"; | |
409 | if (strpos($title, '%') !== FALSE) { | |
410 | $params[1] = array(trim($title), 'String', FALSE); | |
411 | } | |
412 | else { | |
413 | $params[1] = array(trim($title), 'String', TRUE); | |
414 | } | |
415 | } | |
416 | ||
417 | $value = $this->get('event_type_id'); | |
418 | $val = array(); | |
419 | if ($value) { | |
420 | if (is_array($value)) { | |
421 | foreach ($value as $k => $v) { | |
422 | if ($v) { | |
423 | $val[$k] = $k; | |
424 | } | |
425 | } | |
426 | $type = implode(',', $val); | |
427 | } | |
428 | $clauses[] = "event_type_id IN ({$type})"; | |
429 | } | |
430 | ||
431 | $eventsByDates = $this->get('eventsByDates'); | |
432 | if ($this->_searchResult) { | |
433 | if ($eventsByDates) { | |
434 | ||
435 | $from = $this->get('start_date'); | |
436 | if (!CRM_Utils_System::isNull($from)) { | |
437 | $clauses[] = '( start_date >= %3 OR start_date IS NULL )'; | |
438 | $params[3] = array($from, 'String'); | |
439 | } | |
440 | ||
441 | $to = $this->get('end_date'); | |
442 | if (!CRM_Utils_System::isNull($to)) { | |
443 | $clauses[] = '( end_date <= %4 OR end_date IS NULL )'; | |
444 | $params[4] = array($to, 'String'); | |
445 | } | |
446 | } | |
447 | else { | |
448 | $curDate = date('YmdHis'); | |
449 | $clauses[5] = "(end_date >= {$curDate} OR end_date IS NULL)"; | |
450 | } | |
451 | } | |
452 | else { | |
453 | $curDate = date('YmdHis'); | |
454 | $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)"; | |
455 | } | |
456 | ||
457 | if ($sortBy && | |
458 | $this->_sortByCharacter !== NULL | |
459 | ) { | |
460 | $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'"; | |
461 | } | |
462 | ||
e070961b | 463 | $campaignIds = $this->get('campaign_id'); |
464 | if (!CRM_Utils_System::isNull($campaignIds)) { | |
465 | if (!is_array($campaignIds)) { | |
6a488035 TO |
466 | $campaignIds = array($campaignIds); |
467 | } | |
e070961b | 468 | $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campaignIds)) . ' ) )'; |
6a488035 TO |
469 | } |
470 | ||
d7d7d5ab | 471 | // don't do a the below assignment when doing a |
6a488035 TO |
472 | // AtoZ pager clause |
473 | if ($sortBy) { | |
474 | if (count($clauses) > 1 || $eventsByDates) { | |
475 | $this->assign('isSearch', 1); | |
476 | } | |
477 | else { | |
478 | $this->assign('isSearch', 0); | |
479 | } | |
480 | } | |
481 | ||
482 | return !empty($clauses) ? implode(' AND ', $clauses) : '(1)'; | |
483 | } | |
484 | ||
485 | function pager($whereClause, $whereParams) { | |
486 | ||
487 | $params['status'] = ts('Event %%StatusMessage%%'); | |
488 | $params['csvString'] = NULL; | |
489 | $params['buttonTop'] = 'PagerTopButton'; | |
490 | $params['buttonBottom'] = 'PagerBottomButton'; | |
491 | $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); | |
492 | if (!$params['rowCount']) { | |
493 | $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; | |
494 | } | |
495 | ||
496 | $query = " | |
497 | SELECT count(id) | |
498 | FROM civicrm_event | |
499 | WHERE $whereClause"; | |
500 | ||
501 | $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams); | |
502 | ||
503 | $this->_pager = new CRM_Utils_Pager($params); | |
504 | $this->assign_by_ref('pager', $this->_pager); | |
505 | } | |
506 | ||
507 | function pagerAtoZ($whereClause, $whereParams) { | |
508 | ||
509 | $query = " | |
510 | SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name | |
511 | FROM civicrm_event | |
512 | WHERE $whereClause | |
513 | ORDER BY LEFT(title, 1) | |
514 | "; | |
515 | $dao = CRM_Core_DAO::executeQuery($query, $whereParams); | |
516 | ||
517 | $aToZBar = CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE); | |
518 | $this->assign('aToZ', $aToZBar); | |
519 | } | |
520 | } | |
521 |