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 * Create a page for displaying Price Sets.
39 * Heart of this class is the run method which checks
40 * for action type and then displays the appropriate
44 class CRM_Price_Page_Set
extends CRM_Core_Page
{
47 * The action links that we need to display for the browse screen
51 private static $_actionLinks;
54 * Get the action links for this page.
58 * @return array array of action links that we need to display for the browse screen
60 */ function &actionLinks() {
61 // check if variable _actionsLinks is populated
62 if (!isset(self
::$_actionLinks)) {
63 // helper variable for nicer formatting
64 $deleteExtra = ts('Are you sure you want to delete this price set?');
65 $copyExtra = ts('Are you sure you want to make a copy of this price set?');
66 self
::$_actionLinks = array(
67 CRM_Core_Action
::BROWSE
=> array(
68 'name' => ts('View and Edit Price Fields'),
69 'url' => 'civicrm/admin/price/field',
70 'qs' => 'reset=1&action=browse&sid=%%sid%%',
71 'title' => ts('View and Edit Price Fields'),
73 CRM_Core_Action
::PREVIEW
=> array(
74 'name' => ts('Preview'),
75 'url' => 'civicrm/admin/price',
76 'qs' => 'action=preview&reset=1&sid=%%sid%%',
77 'title' => ts('Preview Price Set'),
79 CRM_Core_Action
::UPDATE
=> array(
80 'name' => ts('Settings'),
81 'url' => 'civicrm/admin/price',
82 'qs' => 'action=update&reset=1&sid=%%sid%%',
83 'title' => ts('Edit Price Set'),
85 CRM_Core_Action
::DISABLE
=> array(
86 'name' => ts('Disable'),
87 'extra' => 'onclick = "enableDisable( %%sid%%,\'' . 'CRM_Price_BAO_Set' . '\',\'' . 'enable-disable' . '\' );"',
88 'ref' => 'disable-action',
89 'title' => ts('Disable Price Set'),
91 CRM_Core_Action
::ENABLE
=> array(
92 'name' => ts('Enable'),
93 'extra' => 'onclick = "enableDisable( %%sid%%,\'' . 'CRM_Price_BAO_Set' . '\',\'' . 'disable-enable' . '\' );"',
94 'ref' => 'enable-action',
95 'title' => ts('Enable Price Set'),
97 CRM_Core_Action
::DELETE
=> array(
98 'name' => ts('Delete'),
99 'url' => 'civicrm/admin/price',
100 'qs' => 'action=delete&reset=1&sid=%%sid%%',
101 'title' => ts('Delete Price Set'),
102 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
104 CRM_Core_Action
::COPY
=> array(
105 'name' => ts('Copy Price Set'),
106 'url' => CRM_Utils_System
::currentPath(),
107 'qs' => 'action=copy&sid=%%sid%%',
108 'title' => ts('Make a Copy of Price Set'),
109 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
113 return self
::$_actionLinks;
119 * This method is called after the page is created. It checks for the
120 * type of action and executes that action.
121 * Finally it calls the parent's run method.
130 // get the requested action
131 $action = CRM_Utils_Request
::retrieve('action', 'String',
132 // default to 'browse'
133 $this, FALSE, 'browse'
136 // assign vars to templates
137 $this->assign('action', $action);
138 $sid = CRM_Utils_Request
::retrieve('sid', 'Positive',
143 CRM_Price_BAO_Set
::checkPermission($sid);
145 // what action to take ?
146 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
147 $this->edit($sid, $action);
149 elseif ($action & CRM_Core_Action
::PREVIEW
) {
150 $this->preview($sid);
152 elseif ($action & CRM_Core_Action
::COPY
) {
153 $session = CRM_Core_Session
::singleton();
154 CRM_Core_Session
::setStatus(ts('A copy of the price set has been created'), ts('Saved'), 'success');
159 // if action is delete do the needful.
160 if ($action & (CRM_Core_Action
::DELETE
)) {
161 $usedBy = CRM_Price_BAO_Set
::getUsedBy($sid);
163 if (empty($usedBy)) {
165 $session = CRM_Core_Session
::singleton();
166 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
167 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteSet', 'Delete Price Set', NULL);
168 // $id = CRM_Utils_Request::retrieve('sid', 'Positive', $this, false, 0);
169 $controller->set('sid', $sid);
170 $controller->setEmbedded(TRUE);
171 $controller->process();
176 $url = CRM_Utils_System
::url('civicrm/admin/price', 'reset=1');
177 CRM_Utils_System
::appendBreadCrumb(ts('Price Sets'), $url);
178 $this->assign('usedPriceSetTitle', CRM_Price_BAO_Set
::getTitle($sid));
179 $this->assign('usedBy', $usedBy);
182 'Event' => 'civicrm_event',
183 'Contribution' => 'civicrm_contribution_page',
184 'EventTemplate' => 'civicrm_event_template'
186 $priceSetContexts = array();
187 foreach ($comps as $name => $table) {
188 if (array_key_exists($table, $usedBy)) {
189 $priceSetContexts[] = $name;
192 $this->assign('contexts', $priceSetContexts);
196 // finally browse the price sets
200 return parent
::run();
206 * @param int $id price set id
207 * @param string $action the action to be invoked
212 function edit($sid, $action) {
213 // create a simple controller for editing price sets
214 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Set', ts('Price Set'), $action);
216 // set the userContext stack
217 $session = CRM_Core_Session
::singleton();
218 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
219 $controller->set('sid', $sid);
220 $controller->setEmbedded(TRUE);
221 $controller->process();
228 * @param int $id price set id
233 function preview($sid) {
234 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Price Set'), NULL);
235 $session = CRM_Core_Session
::singleton();
236 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
237 if ($context == 'field') {
238 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', "action=browse&sid={$sid}"));
241 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
243 $controller->set('groupId', $sid);
244 $controller->setEmbedded(TRUE);
245 $controller->process();
250 * Browse all price sets
252 * @param string $action the action to be invoked
257 function browse($action = NULL) {
258 // get all price sets
260 $comps = array('CiviEvent' => ts('Event'),
261 'CiviContribute' => ts('Contribution'),
262 'CiviMember' => ts('Membership'),
265 $dao = new CRM_Price_DAO_Set();
266 if (CRM_Price_BAO_Set
::eventPriceSetDomainID()) {
267 $dao->domain_id
= CRM_Core_Config
::domainID();
269 $dao->is_quick_config
= 0;
271 while ($dao->fetch()) {
272 $priceSet[$dao->id
] = array();
273 CRM_Core_DAO
::storeValues($dao, $priceSet[$dao->id
]);
275 $compIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
276 CRM_Utils_Array
::value('extends', $priceSet[$dao->id
])
279 foreach ($compIds as $compId) $extends[] = $comps[CRM_Core_Component
::getComponentName($compId)];
280 $priceSet[$dao->id
]['extends'] = implode(', ', $extends);
282 // form all action links
283 $action = array_sum(array_keys($this->actionLinks()));
285 // update enable/disable links depending on price_set properties.
286 if ($dao->is_reserved
) {
287 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DISABLE + CRM_Core_Action
::ENABLE + CRM_Core_Action
::DELETE + CRM_Core_Action
::COPY
;
290 if ($dao->is_active
) {
291 $action -= CRM_Core_Action
::ENABLE
;
294 $action -= CRM_Core_Action
::DISABLE
;
297 $actionLinks = self
::actionLinks();
299 if ($dao->is_reserved
) {
300 $actionLinks[CRM_Core_Action
::BROWSE
]['name'] = 'View Price Fields';
302 $priceSet[$dao->id
]['action'] = CRM_Core_Action
::formLink($actionLinks, $action,
303 array('sid' => $dao->id
)
306 $this->assign('rows', $priceSet);
310 * This function is to make a copy of a price set, including
311 * all the fields in the page
317 $id = CRM_Utils_Request
::retrieve('sid', 'Positive',
318 $this, TRUE, 0, 'GET'
321 CRM_Price_BAO_Set
::copy($id);
323 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));