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
39 abstract class CRM_Core_Page_Basic
extends CRM_Core_Page
{
44 * define all the abstract functions here
48 * name of the BAO to perform various DB manipulations
54 abstract function getBAOName();
57 * an array of action links
59 * @return array (reference)
62 abstract function &links();
65 * name of the edit form class
70 abstract function editForm();
78 abstract function editName();
81 * userContext to pop back to
83 * @param int $mode mode that we are in
88 abstract function userContext($mode = NULL);
91 * function to get userContext params
93 * @param int $mode mode that we are in
98 function userContextParams($mode = NULL) {
99 return 'reset=1&action=browse';
103 * allow objects to be added based on permission
105 * @param int $id the id of the object
106 * @param int $name the name or title of the object
108 * @return string permission value if permission is granted, else null
111 public function checkPermission($id, $name) {
112 return CRM_Core_Permission
::EDIT
;
116 * allows the derived class to add some more state variables to
117 * the controller. By default does nothing, and hence is abstract
119 * @param CRM_Core_Controller $controller the controller object
124 function addValues($controller) {}
129 * @param string $title title of the page
130 * @param int $mode mode of the page
132 * @return CRM_Core_Page
134 function __construct($title = NULL, $mode = NULL) {
135 parent
::__construct($title, $mode);
139 * Run the basic page (run essentially starts execution for that page).
145 // dont see args or pageArgs being used, so we should
146 // consider eliminating them in a future version
147 $n = func_num_args();
148 $args = ($n > 0) ?
func_get_arg(0) : NULL;
149 $pageArgs = ($n > 1) ?
func_get_arg(1) : NULL;
150 $sort = ($n > 2) ?
func_get_arg(2) : NULL;
151 // what action do we want to perform ? (store it for smarty too.. :)
153 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
154 $this->assign('action', $this->_action
);
156 // get 'id' if present
157 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, 0);
159 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $this->getBAOName()) . ".php");
162 if (!$this->checkPermission($id, NULL)) {
163 CRM_Core_Error
::fatal(ts('You do not have permission to make changes to the record'));
168 (CRM_Core_Action
::VIEW |
169 CRM_Core_Action
::ADD |
170 CRM_Core_Action
::UPDATE |
171 CRM_Core_Action
::COPY |
172 CRM_Core_Action
::ENABLE |
173 CRM_Core_Action
::DISABLE |
174 CRM_Core_Action
::DELETE
177 // use edit form for view, add or update or delete
178 $this->edit($this->_action
, $id);
181 // if no action or browse
182 $this->browse(NULL, $sort);
185 return parent
::run();
188 function superRun() {
189 return parent
::run();
193 * browse all entities.
201 $n = func_num_args();
202 $action = ($n > 0) ?
func_get_arg(0) : NULL;
203 $sort = ($n > 0) ?
func_get_arg(1) : NULL;
204 $links = &$this->links();
205 if ($action == NULL) {
206 if (!empty($links)) {
207 $action = array_sum(array_keys($links));
210 if ($action & CRM_Core_Action
::DISABLE
) {
211 $action -= CRM_Core_Action
::DISABLE
;
213 if ($action & CRM_Core_Action
::ENABLE
) {
214 $action -= CRM_Core_Action
::ENABLE
;
216 $baoString = $this->getBAOName();
217 $object = new $baoString();
222 * lets make sure we get the stuff sorted by name if it exists
225 $fields = &$object->fields();
227 if (CRM_Utils_Array
::value('title', $fields)) {
230 elseif (CRM_Utils_Array
::value('label', $fields)) {
233 elseif (CRM_Utils_Array
::value('name', $fields)) {
238 $object->orderBy($sort);
241 $object->orderBy($key . ' asc');
247 while ($object->fetch()) {
248 if (!isset($object->mapping_type_id
) ||
249 // "1 for Search Builder"
250 $object->mapping_type_id
!= 1
252 $permission = CRM_Core_Permission
::EDIT
;
254 $permission = $this->checkPermission($object->id
, $object->$key);
257 $values[$object->id
] = array();
258 CRM_Core_DAO
::storeValues($object, $values[$object->id
]);
260 CRM_Contact_DAO_RelationshipType
::addDisplayEnums($values[$object->id
]);
262 // populate action links
263 $this->action($object, $action, $values[$object->id
], $links, $permission);
265 if (isset($object->mapping_type_id
)) {
266 $mappintTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Mapping', 'mapping_type_id');
267 $values[$object->id
]['mapping_type'] = $mappintTypes[$object->mapping_type_id
];
272 $this->assign('rows', $values);
276 * Given an object, get the actions that can be associated with this
277 * object. Check the is_active and is_required flags to display valid
280 * @param CRM_Core_DAO $object the object being considered
281 * @param int $action the base set of actions
282 * @param array $values the array of values that we send to the template
283 * @param array $links the array of links
284 * @param string $permission the permission assigned to this object
289 function action(&$object, $action, &$values, &$links, $permission, $forceAction = FALSE) {
290 $values['class'] = '';
291 $newAction = $action;
292 $hasDelete = $hasDisable = TRUE;
294 if (CRM_Utils_Array
::value('name', $values) && in_array($values['name'], array(
295 'encounter_medium', 'case_type', 'case_status'))) {
296 static $caseCount = NULL;
297 if (!isset($caseCount)) {
298 $caseCount = CRM_Case_BAO_Case
::caseCount(NULL, FALSE);
300 if ($caseCount > 0) {
301 $hasDelete = $hasDisable = FALSE;
306 if (array_key_exists('is_reserved', $object) && $object->is_reserved
) {
307 $values['class'] = 'reserved';
308 // check if object is relationship type
309 $object_type = get_class($object);
310 if ($object_type == 'CRM_Contact_BAO_RelationshipType' ||
$object_type == 'CRM_Core_BAO_LocationType') {
311 $newAction = CRM_Core_Action
::VIEW + CRM_Core_Action
::UPDATE
;
315 $values['action'] = '';
320 if (array_key_exists('is_active', $object)) {
321 if ($object->is_active
) {
323 $newAction +
= CRM_Core_Action
::DISABLE
;
327 $newAction +
= CRM_Core_Action
::ENABLE
;
333 //CRM-4418, handling edit and delete separately.
334 $permissions = array($permission);
335 if ($hasDelete && ($permission == CRM_Core_Permission
::EDIT
)) {
336 //previously delete was subset of edit
337 //so for consistency lets grant delete also.
338 $permissions[] = CRM_Core_Permission
::DELETE
;
341 // make sure we only allow those actions that the user is permissioned for
342 $newAction = $newAction & CRM_Core_Action
::mask($permissions);
344 $values['action'] = CRM_Core_Action
::formLink($links, $newAction, array('id' => $object->id
));
350 * @param int $mode - what mode for the form ?
351 * @param int $id - id of the entity (for update, view operations)
355 function edit($mode, $id = NULL, $imageUpload = FALSE, $pushUserContext = TRUE) {
356 $controller = new CRM_Core_Controller_Simple($this->editForm(),
362 // set the userContext stack
363 if ($pushUserContext) {
364 $session = CRM_Core_Session
::singleton();
365 $session->pushUserContext(CRM_Utils_System
::url($this->userContext($mode), $this->userContextParams($mode)));
368 $controller->set('id', $id);
370 $controller->set('BAOName', $this->getBAOName());
371 $this->addValues($controller);
372 $controller->setEmbedded(TRUE);
373 $controller->process();