Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Report / Page / Options.php
CommitLineData
6a488035
TO
1<?php
2// $Id$
3
4/*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
28*/
29
30/**
31 *
32 * @package CRM
33 * @copyright CiviCRM LLC (c) 2004-2013
34 * $Id$
35 *
36 */
37
38/**
39 * Page for displaying list of Gender
40 */
41class CRM_Report_Page_Options extends CRM_Core_Page_Basic {
42
43 /**
44 * The action links that we need to display for the browse screen
45 *
46 * @var array
47 * @static
48 */
49 static $_links = NULL;
50
51 /**
52 * The option group name
53 *
54 * @var array
55 * @static
56 */
57 static $_gName = NULL;
58
59 /**
60 * The option group name in display format (capitalized, without underscores...etc)
61 *
62 * @var array
63 * @static
64 */
65 static $_GName = NULL;
66
67 /**
68 * The option group id
69 *
70 * @var array
71 * @static
72 */
73 static $_gId = NULL;
74
75 /**
76 * Obtains the group name from url and sets the title.
77 *
78 * @return void
79 * @access public
80 *
81 */
82 function preProcess() {
83 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
84 $this->_id = CRM_Utils_Request::retrieve('id', 'String', $this, FALSE);
85
86 self::$_gName = "report_template";
87
88 if (self::$_gName) {
89 self::$_gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'id', 'name');
90 }
91 else {
92 CRM_Core_Error::fatal();
93 }
94
95 self::$_GName = ucwords(str_replace('_', ' ', self::$_gName));
96
97 $this->assign('GName', self::$_GName);
98 $newReportURL = CRM_Utils_System::url("civicrm/admin/report/register",
99 'reset=1'
100 );
101 $this->assign('newReport', $newReportURL);
102 CRM_Utils_System::setTitle(ts('Registered Templates'));
103 }
104
105 /**
106 * Get BAO Name
107 *
108 * @return string Classname of BAO.
109 */
110 function getBAOName() {
111 return 'CRM_Core_BAO_OptionValue';
112 }
113
114 /**
115 * Get action Links
116 *
117 * @return array (reference) of action links
118 */
119 function &links() {
120 if (!(self::$_links)) {
121 self::$_links = array(
122 CRM_Core_Action::UPDATE => array(
123 'name' => ts('Edit'),
124 'url' => 'civicrm/admin/report/register/' . self::$_gName,
125 'qs' => 'action=update&id=%%id%%&reset=1',
126 'title' => ts('Edit %1', array(1 => self::$_gName)),
127 ),
128 CRM_Core_Action::DISABLE => array(
129 'name' => ts('Disable'),
130 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'enable-disable' . '\' );"',
131 'ref' => 'disable-action',
132 'title' => ts('Disable %1', array(1 => self::$_gName)),
133 ),
134 CRM_Core_Action::ENABLE => array(
135 'name' => ts('Enable'),
136 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'disable-enable' . '\' );"',
137 'ref' => 'enable-action',
138 'title' => ts('Enable %1', array(1 => self::$_gName)),
139 ),
140 CRM_Core_Action::DELETE => array(
141 'name' => ts('Delete'),
142 'url' => 'civicrm/admin/report/register/' . self::$_gName,
143 'qs' => 'action=delete&id=%%id%%&reset=1',
144 'title' => ts('Delete %1 Type', array(1 => self::$_gName)),
145 ),
146 );
147 }
148
149 return self::$_links;
150 }
151
152 /**
153 * Run the basic page (run essentially starts execution for that page).
154 *
155 * @return void
156 */
157 function run() {
158 $this->preProcess();
159 return parent::run();
160 }
161
162 /**
163 * Browse all options
164 *
165 *
166 * @return void
167 * @access public
168 * @static
169 */
170 function browse() {
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