1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8//this script may only be included - so its better to die if called directly. 9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) { 10 header("location: index.php"); 11 exit; 12} 13 14/** 15 * Generates a link to the object permission screen, and verifies if there are 16 * active permissions to render the link differently as required. 17 * 18 * Important parameters: type and id, for the target object - otherwise global 19 * permType, if different from type 20 * title, the name of the object 21 * 22 * Almost mandatory: mode, display style of the button 23 * glyph: simple fa (Font Awesome) 24 * icon: classic tiki icon 25 * link: plain text link (label) 26 * text: glyph + label 27 * button: button with label 28 * button_link: button with label (btn-link) 29 * 30 * Occasional: label, alter the displayed text from default 31 group, parameter to objectpermissions 32 textFilter, parameter to objectpermissions 33 showDisabled, parameter to objectpermissions 34 addclass: add classes separated by spaces 35 */ 36function smarty_function_permission_link($params, $smarty) 37{ 38 $params = new JitFilter($params); 39 $type = $params->type->text(); 40 $objectType = $params->objectType->text(); 41 if (! $objectType) { 42 $objectType = $type; 43 } 44 $id = $params->id->none(); 45 46 $objectlib = TikiLib::lib('object'); 47 if (isset($params['type'], $params['id'])) { 48 $arguments = [ 49 'objectType' => $objectType, 50 'objectId' => $id, 51 'permType' => $type, 52 'objectName' => $params->title->none() ?: $objectlib->get_title($type, $id), 53 ]; 54 } else { 55 $arguments = []; 56 } 57 58 if ($params->permType->text()) { 59 $arguments['permType'] = $params->permType->text(); 60 } 61 62 if ($params->textFilter->text()) { 63 $arguments['textFilter'] = $params->textFilter->text(); 64 } 65 66 if ($params->group->groupname()) { 67 $arguments['group'] = $params->group->groupname(); 68 } 69 70 if ($params->showDisabled->word() == 'y') { 71 $arguments['show_disabled_features'] = 'y'; 72 } 73 74 if ($params->parentId->text()) { 75 $arguments['parentId'] = $params->parentId->text(); 76 } 77 78 if (! empty($arguments)) { 79 $link = 'tiki-objectpermissions.php?' . http_build_query($arguments, '', '&'); 80 } else { 81 $link = 'tiki-objectpermissions.php'; 82 } 83 84 $perms = Perms::get($type, $id); 85 $source = $perms->getResolver()->from(); 86 87 return $smarty->fetch('permission_link.tpl', [ 88 'permission_link' => [ 89 'url' => $link, 90 'active' => $source == 'object', 91 'mode' => $params->mode->word() ?: 'glyph', 92 'label' => $params->label->text() ?: tr('Permissions'), 93 'count' => $params->count->int(), 94 'type' => $type, 95 'addclass' => $params->addclass->text(), 96 ], 97 ]); 98} 99