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