|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * ------------------------------------------------------------------------- |
| 5 | + * Example plugin for GLPI |
| 6 | + * ------------------------------------------------------------------------- |
| 7 | + * |
| 8 | + * LICENSE |
| 9 | + * |
| 10 | + * This file is part of Example. |
| 11 | + * |
| 12 | + * Example is free software; you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU General Public License as published by |
| 14 | + * the Free Software Foundation; either version 2 of the License, or |
| 15 | + * (at your option) any later version. |
| 16 | + * |
| 17 | + * Example is distributed in the hope that it will be useful, |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | + * GNU General Public License for more details. |
| 21 | + * |
| 22 | + * You should have received a copy of the GNU General Public License |
| 23 | + * along with Example. If not, see <http://www.gnu.org/licenses/>. |
| 24 | + * ------------------------------------------------------------------------- |
| 25 | + * @copyright Copyright (C) 2006-2022 by Example plugin team. |
| 26 | + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html |
| 27 | + * @link https://github.com/pluginsGLPI/example |
| 28 | + * ------------------------------------------------------------------------- |
| 29 | + */ |
| 30 | + |
| 31 | +namespace GlpiPlugin\Example; |
| 32 | + |
| 33 | +use CommonGLPI; |
| 34 | +use Html; |
| 35 | +use Session; |
| 36 | + |
| 37 | +final class Profile extends \Profile |
| 38 | +{ |
| 39 | + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) |
| 40 | + { |
| 41 | + return __('Example plugin'); |
| 42 | + } |
| 43 | + |
| 44 | + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) |
| 45 | + { |
| 46 | + $profile = new self(); |
| 47 | + $profile->showFormExample($item->getID()); |
| 48 | + } |
| 49 | + |
| 50 | + public function showFormExample(int $profiles_id): void |
| 51 | + { |
| 52 | + if (!$this->can($profiles_id, READ)) { |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + echo "<div class='spaced'>"; |
| 57 | + |
| 58 | + $can_edit = Session::haveRight(self::$rightname, UPDATE); |
| 59 | + if ($can_edit) { |
| 60 | + echo "<form method='post' action='" . htmlspecialchars(self::getFormURL()) . "'>"; |
| 61 | + } |
| 62 | + |
| 63 | + $matrix_options = [ |
| 64 | + 'canedit' => $can_edit, |
| 65 | + ]; |
| 66 | + $rights = [ |
| 67 | + [ |
| 68 | + 'itemtype' => Example::class, |
| 69 | + 'label' => Example::getTypeName(Session::getPluralNumber()), |
| 70 | + 'field' => Example::$rightname |
| 71 | + ] |
| 72 | + ]; |
| 73 | + $matrix_options['title'] = self::getTypeName(1); |
| 74 | + $this->displayRightsChoiceMatrix($rights, $matrix_options); |
| 75 | + |
| 76 | + if ($can_edit) { |
| 77 | + echo "<div class='text-center'>"; |
| 78 | + echo Html::hidden('id', ['value' => $profiles_id]); |
| 79 | + echo Html::submit(_sx('button', 'Save'), ['name' => 'update']); |
| 80 | + echo "</div>\n"; |
| 81 | + Html::closeForm(); |
| 82 | + } |
| 83 | + echo '</div>'; |
| 84 | + } |
| 85 | +} |
0 commit comments