3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * Page for displaying list of events
39 class CRM_Event_Page_ManageEvent
extends CRM_Core_Page
{
42 * The action links that we need to display for the browse screen
47 static $_actionLinks = NULL;
49 static $_links = NULL;
51 protected $_pager = NULL;
53 protected $_sortByCharacter;
55 protected $_isTemplate = FALSE;
60 * @return array (reference) of action links
63 if (!(self
::$_actionLinks)) {
64 // helper variable for nicer formatting
65 $copyExtra = ts('Are you sure you want to make a copy of this Event?');
66 $deleteExtra = ts('Are you sure you want to delete this Event?');
68 self
::$_actionLinks = array(
69 CRM_Core_Action
::DISABLE
=> array(
70 'name' => ts('Disable'),
71 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Event_BAO_Event' . '\',\'' . 'enable-disable' . '\' );"',
72 'ref' => 'disable-action',
73 'title' => ts('Disable Event'),
75 CRM_Core_Action
::ENABLE
=> array(
76 'name' => ts('Enable'),
77 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Event_BAO_Event' . '\',\'' . 'disable-enable' . '\' );"',
78 'ref' => 'enable-action',
79 'title' => ts('Enable Event'),
81 CRM_Core_Action
::DELETE
=> array(
82 'name' => ts('Delete'),
83 'url' => CRM_Utils_System
::currentPath(),
84 'qs' => 'action=delete&id=%%id%%',
85 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
86 'title' => ts('Delete Event'),
88 CRM_Core_Action
::COPY
=> array(
90 'url' => CRM_Utils_System
::currentPath(),
91 'qs' => 'reset=1&action=copy&id=%%id%%',
92 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
93 'title' => ts('Copy Event'),
97 return self
::$_actionLinks;
103 * This method is called after the page is created. It checks for the
104 * type of action and executes that action.
105 * Finally it calls the parent's run method.
112 // get the requested action
113 $action = CRM_Utils_Request
::retrieve('action', 'String',
114 // default to 'browse'
115 $this, FALSE, 'browse'
118 // assign vars to templates
119 $this->assign('action', $action);
120 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
121 $this, FALSE, 0, 'REQUEST'
124 // figure out whether we’re handling an event or an event template
126 $this->_isTemplate
= CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'is_template');
128 elseif ($action & CRM_Core_Action
::ADD
) {
129 $this->_isTemplate
= CRM_Utils_Request
::retrieve('is_template', 'Boolean', $this);
132 if (!$this->_isTemplate
&& $id) {
133 $breadCrumb = array(array('title' => ts('Manage Events'),
134 'url' => CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'),
136 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
139 // what action to take ?
140 if ($action & CRM_Core_Action
::DELETE
) {
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_Event_Form_ManageEvent_Delete',
147 $controller->set('id', $id);
148 $controller->process();
149 return $controller->run();
151 elseif ($action & CRM_Core_Action
::COPY
) {
155 // finally browse the custom groups
159 return parent
::run();
168 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
172 $createdId = CRM_Utils_Request
::retrieve('cid', 'Positive', $this, FALSE, 0);
173 if (strtolower($this->_sortByCharacter
) == 'all' ||
176 $this->_sortByCharacter
= '';
177 $this->set('sortByCharacter', '');
180 $this->_force
= $this->_searchResult
= NULL;
184 $config = CRM_Core_Config
::singleton();
187 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean',
190 $this->_searchResult
= CRM_Utils_Request
::retrieve('searchResult', 'Boolean', $this);
192 $whereClause = $this->whereClause($params, FALSE, $this->_force
);
193 $this->pagerAToZ($whereClause, $params);
196 $whereClause = $this->whereClause($params, TRUE, $this->_force
);
197 // because is_template != 1 would be to simple
198 $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)';
200 $this->pager($whereClause, $params);
202 list($offset, $rowCount) = $this->_pager
->getOffsetAndRowCount();
204 // get all custom groups sorted by weight
205 $manageEvent = array();
211 ORDER BY start_date desc
212 LIMIT $offset, $rowCount";
214 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event');
215 $permissions = CRM_Event_BAO_Event
::checkPermission();
218 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
220 // get the list of active event pcps
221 $eventPCPS = array();
223 $pcpDao = new CRM_PCP_DAO_PCPBlock
;
224 $pcpDao->entity_table
= 'civicrm_event';
227 while ($pcpDao->fetch()) {
228 $eventPCPS[$pcpDao->entity_id
] = $pcpDao->entity_id
;
231 while ($dao->fetch()) {
232 if (in_array($dao->id
, $permissions[CRM_Core_Permission
::VIEW
])) {
233 $manageEvent[$dao->id
] = array();
234 CRM_Core_DAO
::storeValues($dao, $manageEvent[$dao->id
]);
236 // form all action links
237 $action = array_sum(array_keys($this->links()));
239 if ($dao->is_active
) {
240 $action -= CRM_Core_Action
::ENABLE
;
243 $action -= CRM_Core_Action
::DISABLE
;
246 if (!in_array($dao->id
, $permissions[CRM_Core_Permission
::DELETE
])) {
247 $action -= CRM_Core_Action
::DELETE
;
249 if (!in_array($dao->id
, $permissions[CRM_Core_Permission
::EDIT
])) {
250 $action -= CRM_Core_Action
::UPDATE
;
253 $manageEvent[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(),
255 array('id' => $dao->id
),
261 'entity_id' => $dao->id
,
262 'entity_table' => 'civicrm_event',
266 $defaults['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
268 $manageEvent[$dao->id
]['friend'] = CRM_Friend_BAO_Friend
::getValues($params);
270 if (isset($defaults['location']['address'][1]['city'])) {
271 $manageEvent[$dao->id
]['city'] = $defaults['location']['address'][1]['city'];
273 if (isset($defaults['location']['address'][1]['state_province_id'])) {
274 $manageEvent[$dao->id
]['state_province'] = CRM_Core_PseudoConstant
::stateProvince($defaults['location']['address'][1]['state_province_id']);
277 //show campaigns on selector.
278 $manageEvent[$dao->id
]['campaign'] = CRM_Utils_Array
::value($dao->campaign_id
, $allCampaigns);
279 $manageEvent[$dao->id
]['reminder'] = CRM_Core_BAO_ActionSchedule
::isConfigured($dao->id
, 3);
281 $manageEvent[$dao->id
]['is_pcp_enabled'] = CRM_Utils_Array
::value($dao->id
, $eventPCPS);
284 $this->assign('rows', $manageEvent);
286 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
287 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0');
288 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
289 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
290 $this->assign('findParticipants', $findParticipants);
292 // check if we're in shopping cart mode for events
293 $enableCart = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
296 $this->assign('eventCartEnabled', $enableCart);
300 * This function is to make a copy of a Event, including
301 * all the fields in the event wizard
307 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE, 0, 'GET');
309 $urlString = 'civicrm/event/manage';
310 $copyEvent = CRM_Event_BAO_Event
::copy($id);
311 $urlParams = 'reset=1';
312 // Redirect to Copied Event Configuration
313 if ($copyEvent->id
) {
314 $urlString = 'civicrm/event/manage/settings';
315 $urlParams .= '&action=update&id=' . $copyEvent->id
;
318 return CRM_Utils_System
::redirect(CRM_Utils_System
::url($urlString, $urlParams));
322 if (isset($this->_action
) &
323 (CRM_Core_Action
::ADD |
324 CRM_Core_Action
::UPDATE |
325 CRM_Core_Action
::DELETE
331 $form = new CRM_Core_Controller_Simple('CRM_Event_Form_SearchEvent', ts('Search Events'), CRM_Core_Action
::ADD
);
332 $form->setEmbedded(TRUE);
333 $form->setParent($this);
338 function whereClause(&$params, $sortBy = TRUE, $force) {
341 $title = $this->get('title');
342 $createdId = $this->get('cid');
345 $clauses[] = "(created_id = {$createdId})";
349 $clauses[] = "title LIKE %1";
350 if (strpos($title, '%') !== FALSE) {
351 $params[1] = array(trim($title), 'String', FALSE);
354 $params[1] = array(trim($title), 'String', TRUE);
358 $value = $this->get('event_type_id');
361 if (is_array($value)) {
362 foreach ($value as $k => $v) {
367 $type = implode(',', $val);
369 $clauses[] = "event_type_id IN ({$type})";
372 $eventsByDates = $this->get('eventsByDates');
373 if ($this->_searchResult
) {
374 if ($eventsByDates) {
376 $from = $this->get('start_date');
377 if (!CRM_Utils_System
::isNull($from)) {
378 $clauses[] = '( start_date >= %3 OR start_date IS NULL )';
379 $params[3] = array($from, 'String');
382 $to = $this->get('end_date');
383 if (!CRM_Utils_System
::isNull($to)) {
384 $clauses[] = '( end_date <= %4 OR end_date IS NULL )';
385 $params[4] = array($to, 'String');
389 $curDate = date('YmdHis');
390 $clauses[5] = "(end_date >= {$curDate} OR end_date IS NULL)";
394 $curDate = date('YmdHis');
395 $clauses[] = "(end_date >= {$curDate} OR end_date IS NULL)";
399 $this->_sortByCharacter
!== NULL
401 $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
404 $campainIds = $this->get('campaign_id');
405 if (!CRM_Utils_System
::isNull($campainIds)) {
406 if (!is_array($campainIds)) {
407 $campaignIds = array($campaignIds);
409 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
412 // dont do a the below assignment when doing a
415 if (count($clauses) > 1 ||
$eventsByDates) {
416 $this->assign('isSearch', 1);
419 $this->assign('isSearch', 0);
423 return !empty($clauses) ?
implode(' AND ', $clauses) : '(1)';
426 function pager($whereClause, $whereParams) {
428 $params['status'] = ts('Event %%StatusMessage%%');
429 $params['csvString'] = NULL;
430 $params['buttonTop'] = 'PagerTopButton';
431 $params['buttonBottom'] = 'PagerBottomButton';
432 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
433 if (!$params['rowCount']) {
434 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
442 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
444 $this->_pager
= new CRM_Utils_Pager($params);
445 $this->assign_by_ref('pager', $this->_pager
);
448 function pagerAtoZ($whereClause, $whereParams) {
451 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
454 ORDER BY LEFT(title, 1)
456 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
458 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
459 $this->assign('aToZ', $aToZBar);