Remove all eval instances where eval is being used to instantiate a new object using...
[civicrm-core.git] / CRM / Event / Page / AJAX.php
CommitLineData
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 * This class contains all the function that are called using AJAX
38 */
39class CRM_Event_Page_AJAX {
40
41 /**
42 * Function for building Event combo box
43 */
44 function event() {
45 $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
46 if (!$name) {
47 $name = '%';
48 }
49 $whereClause = " title LIKE '$name%' AND ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
50 $includeOld = CRM_Utils_Request::retrieve('includeOld', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, TRUE);
51 if (!$includeOld) {
52 $whereClause .= " AND ( end_date IS NULL OR end_date >= NOW() )";
53 }
54 $query = "
55SELECT title, id
56FROM civicrm_event
57WHERE {$whereClause}
58ORDER BY title
59";
60 $dao = CRM_Core_DAO::executeQuery($query);
61 while ($dao->fetch()) {
62 echo $elements = "$dao->title|$dao->id\n";
63 }
64 CRM_Utils_System::civiExit();
65 }
66
67 /**
68 * Function for building Event Type combo box
69 */
70 function eventType() {
71 $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
72 if (!$name) {
73 $name = '%';
74 }
75 $whereClause = " v.label LIKE '$name%' ";
76
77 $query = "
78SELECT v.label ,v.value
79FROM civicrm_option_value v,
80 civicrm_option_group g
81WHERE v.option_group_id = g.id
82AND g.name = 'event_type'
83AND v.is_active = 1
84AND {$whereClause}
85ORDER by v.weight";
86
87 $dao = CRM_Core_DAO::executeQuery($query);
88 while ($dao->fetch()) {
89 echo $elements = "$dao->label|$dao->value\n";
90 }
91 CRM_Utils_System::civiExit();
92 }
93
94 /**
95 * Function for building EventFee combo box
96 */
97 function eventFee() {
98 $name = trim(CRM_Utils_Type::escape($_GET['s'], 'String'));
99
100 if (!$name) {
101 $name = '%';
102 }
103
104 $whereClause = "cv.label LIKE '$name%' ";
105
106 $query = "SELECT DISTINCT (
107cv.label
108), cv.id
109FROM civicrm_price_field_value cv
110LEFT JOIN civicrm_price_field cf ON cv.price_field_id = cf.id
111LEFT JOIN civicrm_price_set_entity ce ON ce.price_set_id = cf.price_set_id
112WHERE ce.entity_table = 'civicrm_event' AND {$whereClause}
113GROUP BY cv.label";
114 $dao = CRM_Core_DAO::executeQuery($query);
115 while ($dao->fetch()) {
116 echo $elements = "$dao->label|$dao->id\n";
117 }
118 CRM_Utils_System::civiExit();
119 }
120
121 function eventList() {
122 $events = CRM_Event_BAO_Event::getEvents(TRUE);
123
124 $elements = array(array('name' => ts('- select -'),
125 'value' => '',
126 ));
127 foreach ($events as $id => $name) {
128 $elements[] = array(
129 'name' => $name,
130 'value' => $id,
131 );
132 }
133
134 echo json_encode($elements);
135 CRM_Utils_System::civiExit();
136 }
137
138 /**
139 * Function to get default participant role
140 */
141 function participantRole() {
142 $eventID = $_GET['eventId'];
143
144 $defaultRoleId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event',
145 $eventID,
146 'default_role_id',
147 'id'
148 );
149 $participantRole = array('role' => $defaultRoleId);
150 echo json_encode($participantRole);
151 CRM_Utils_System::civiExit();
152 }
153}
154