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',
185 $priceSetContexts = array();
186 foreach ($comps as $name => $table) {
187 if (array_key_exists($table, $usedBy)) {
188 $priceSetContexts[] = $name;
191 $this->assign('contexts', $priceSetContexts);
195 // finally browse the price sets
199 return parent
::run();
205 * @param int $id price set id
206 * @param string $action the action to be invoked
211 function edit($sid, $action) {
212 // create a simple controller for editing price sets
213 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Set', ts('Price Set'), $action);
215 // set the userContext stack
216 $session = CRM_Core_Session
::singleton();
217 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
218 $controller->set('sid', $sid);
219 $controller->setEmbedded(TRUE);
220 $controller->process();
227 * @param int $id price set id
232 function preview($sid) {
233 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Price Set'), NULL);
234 $session = CRM_Core_Session
::singleton();
235 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
236 if ($context == 'field') {
237 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', "action=browse&sid={$sid}"));
240 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
242 $controller->set('groupId', $sid);
243 $controller->setEmbedded(TRUE);
244 $controller->process();
249 * Browse all price sets
251 * @param string $action the action to be invoked
256 function browse($action = NULL) {
257 // get all price sets
259 $comps = array('CiviEvent' => ts('Event'),
260 'CiviContribute' => ts('Contribution'),
261 'CiviMember' => ts('Membership'),
264 $dao = new CRM_Price_DAO_Set();
265 if (CRM_Price_BAO_Set
::eventPriceSetDomainID()) {
266 $dao->domain_id
= CRM_Core_Config
::domainID();
268 $dao->is_quick_config
= 0;
270 while ($dao->fetch()) {
271 $priceSet[$dao->id
] = array();
272 CRM_Core_DAO
::storeValues($dao, $priceSet[$dao->id
]);
274 $compIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
275 CRM_Utils_Array
::value('extends', $priceSet[$dao->id
])
278 foreach ($compIds as $compId) $extends[] = $comps[CRM_Core_Component
::getComponentName($compId)];
279 $priceSet[$dao->id
]['extends'] = implode(', ', $extends);
281 // form all action links
282 $action = array_sum(array_keys($this->actionLinks()));
284 // update enable/disable links depending on price_set properties.
285 if ($dao->is_reserved
) {
286 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DISABLE + CRM_Core_Action
::ENABLE + CRM_Core_Action
::DELETE + CRM_Core_Action
::COPY
;
289 if ($dao->is_active
) {
290 $action -= CRM_Core_Action
::ENABLE
;
293 $action -= CRM_Core_Action
::DISABLE
;
296 $actionLinks = self
::actionLinks();
298 if ($dao->is_reserved
) {
299 $actionLinks[CRM_Core_Action
::BROWSE
]['name'] = 'View Price Fields';
301 $priceSet[$dao->id
]['action'] = CRM_Core_Action
::formLink($actionLinks, $action,
302 array('sid' => $dao->id
)
305 $this->assign('rows', $priceSet);
309 * This function is to make a copy of a price set, including
310 * all the fields in the page
316 $id = CRM_Utils_Request
::retrieve('sid', 'Positive',
317 $this, TRUE, 0, 'GET'
320 CRM_Price_BAO_Set
::copy($id);
322 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));