CRM-13863 - Added setting to disable ajax popups
[civicrm-core.git] / CRM / Report / Page / Options.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2013
33 * $Id$
34 *
35 */
36
37 /**
38 * Page for displaying list of Gender
39 */
40 class CRM_Report_Page_Options extends CRM_Core_Page_Basic {
41
42 /**
43 * The action links that we need to display for the browse screen
44 *
45 * @var array
46 * @static
47 */
48 static $_links = NULL;
49
50 /**
51 * The option group name
52 *
53 * @var array
54 * @static
55 */
56 static $_gName = NULL;
57
58 /**
59 * The option group name in display format (capitalized, without underscores...etc)
60 *
61 * @var array
62 * @static
63 */
64 static $_GName = NULL;
65
66 /**
67 * The option group id
68 *
69 * @var array
70 * @static
71 */
72 static $_gId = NULL;
73
74 /**
75 * Obtains the group name from url and sets the title.
76 *
77 * @return void
78 * @access public
79 *
80 */
81 function preProcess() {
82 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
83 $this->_id = CRM_Utils_Request::retrieve('id', 'String', $this, FALSE);
84
85 self::$_gName = "report_template";
86
87 if (self::$_gName) {
88 self::$_gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'id', 'name');
89 }
90 else {
91 CRM_Core_Error::fatal();
92 }
93
94 self::$_GName = ucwords(str_replace('_', ' ', self::$_gName));
95
96 $this->assign('GName', self::$_GName);
97 $newReportURL = CRM_Utils_System::url("civicrm/admin/report/register",
98 'reset=1'
99 );
100 $this->assign('newReport', $newReportURL);
101 CRM_Utils_System::setTitle(ts('Registered Templates'));
102 }
103
104 /**
105 * Get BAO Name
106 *
107 * @return string Classname of BAO.
108 */
109 function getBAOName() {
110 return 'CRM_Core_BAO_OptionValue';
111 }
112
113 /**
114 * Get action Links
115 *
116 * @return array (reference) of action links
117 */
118 function &links() {
119 if (!(self::$_links)) {
120 self::$_links = array(
121 CRM_Core_Action::UPDATE => array(
122 'name' => ts('Edit'),
123 'url' => 'civicrm/admin/report/register/' . self::$_gName,
124 'qs' => 'action=update&id=%%id%%&reset=1',
125 'title' => ts('Edit %1', array(1 => self::$_gName)),
126 ),
127 CRM_Core_Action::DISABLE => array(
128 'name' => ts('Disable'),
129 'ref' => 'crm-enable-disable',
130 'title' => ts('Disable %1', array(1 => self::$_gName)),
131 ),
132 CRM_Core_Action::ENABLE => array(
133 'name' => ts('Enable'),
134 'ref' => 'crm-enable-disable',
135 'title' => ts('Enable %1', array(1 => self::$_gName)),
136 ),
137 CRM_Core_Action::DELETE => array(
138 'name' => ts('Delete'),
139 'url' => 'civicrm/admin/report/register/' . self::$_gName,
140 'qs' => 'action=delete&id=%%id%%&reset=1',
141 'title' => ts('Delete %1 Type', array(1 => self::$_gName)),
142 ),
143 );
144 }
145
146 return self::$_links;
147 }
148
149 /**
150 * Run the basic page (run essentially starts execution for that page).
151 *
152 * @return void
153 */
154 function run() {
155 $this->preProcess();
156 return parent::run();
157 }
158
159 /**
160 * Browse all options
161 *
162 *
163 * @return void
164 * @access public
165 * @static
166 */
167 function browse() {
168 if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'ajax_popups_enabled', NULL, TRUE)) {
169 CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
170 }
171 $groupParams = array('name' => self::$_gName);
172 $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'weight');
173 $gName = self::$_gName;
174 $returnURL = CRM_Utils_System::url("civicrm/admin/report/options/$gName",
175 "reset=1"
176 );
177 $filter = "option_group_id = " . self::$_gId;
178
179 $session = new CRM_Core_Session();
180 $session->replaceUserContext($returnURL);
181 CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue',
182 'id', $returnURL, $filter
183 );
184 $this->assign('rows', $optionValue);
185 }
186
187 /**
188 * Get name of edit form
189 *
190 * @return string Classname of edit form.
191 */
192 function editForm() {
193 return 'CRM_Report_Form_Register';
194 }
195
196 /**
197 * Get edit form name
198 *
199 * @return string name of this page.
200 */
201 function editName() {
202 return self::$_GName;
203 }
204
205 /**
206 * Get user context.
207 *
208 * @return string user context.
209 */
210 function userContext($mode = NULL) {
211 return 'civicrm/report/options/' . self::$_gName;
212 }
213
214 /**
215 * function to get userContext params
216 *
217 * @param int $mode mode that we are in
218 *
219 * @return string
220 * @access public
221 */
222 function userContextParams($mode = NULL) {
223 return 'reset=1&action=browse';
224 }
225 }
226