profile.class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /*
  3. * @version $Id: profile.class.php 234 2019-12-12 14:34:31Z yllen $
  4. -------------------------------------------------------------------------
  5. LICENSE
  6. This file is part of Archires plugin for GLPI.
  7. Archires is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU Affero General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. Archires is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with Archires. If not, see <http://www.gnu.org/licenses/>.
  17. @package archires
  18. @author Nelly Mahu-Lasson, Xavier Caillaud
  19. @copyright Copyright (c) 2016-2018 Archires plugin team
  20. @license AGPL License 3.0 or (at your option) any later version
  21. http://www.gnu.org/licenses/agpl-3.0-standalone.html
  22. @link https://forge.glpi-project.org/projects/archires
  23. @since version 2.2
  24. --------------------------------------------------------------------------
  25. */
  26. if (!defined('GLPI_ROOT')) {
  27. die("Sorry. You can't access directly to this file");
  28. }
  29. class PluginArchiresProfile extends Profile {
  30. static $rightname = "profile";
  31. //if profile deleted
  32. static function purgeProfiles(Profile $prof) {
  33. $plugprof = new self();
  34. $plugprof->deleteByCriteria(['profiles_id' => $prof->getField("id")]);
  35. }
  36. function getFromDBByProfile($profiles_id) {
  37. global $DB;
  38. $query = ['FROM' => $this->getTable(),
  39. 'WHERE' => ['profiles_id' => $profiles_id]];
  40. if ($result = $DB->request($query)) {
  41. if (count($result) != 1) {
  42. return false;
  43. }
  44. $this->fields = $result->next();
  45. if (is_array($this->fields) && count($this->fields)) {
  46. return true;
  47. }
  48. }
  49. return false;
  50. }
  51. static function createFirstAccess($ID) {
  52. self::addDefaultProfileInfos($ID, ['plugin_archires' => ALLSTANDARDRIGHT], true);
  53. }
  54. //profiles modification
  55. function showForProfile(Profile $prof){
  56. $canedit = Session::haveRightsOr(self::$rightname, [CREATE, UPDATE, PURGE]);
  57. if ($canedit) {
  58. echo "<form method='post' action='".$prof->getFormURL()."'>";
  59. }
  60. $rights = [['itemtype' => 'PluginArchiresArchires',
  61. 'label' => __('Generate graphs', 'archires'),
  62. 'field' => 'plugin_archires']];
  63. $prof->displayRightsChoiceMatrix($rights, ['canedit' => $canedit,
  64. 'default_class' => 'tab_bg_2',
  65. 'title' => __('General')]);
  66. echo "<table class='tab_cadre_fixehov'>";
  67. $effective_rights = ProfileRight::getProfileRights($prof->getField('id'), ['plugin_archires']);
  68. echo Html::hidden('id', ['value' => $prof->getField('id')]);
  69. echo "</table>";
  70. if ($canedit) {
  71. echo "<div class='center'>";
  72. echo Html::hidden('id', ['value' => $prof->getField('id')]);
  73. echo Html::submit(_sx('button', 'Save'), ['name' => 'update']);
  74. echo "</div>\n";
  75. Html::closeForm();
  76. }
  77. }
  78. function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
  79. if ($item->getType() == 'Profile') {
  80. if ($item->getField('id')
  81. && ($item->getField('interface') != 'helpdesk')) {
  82. return PluginArchiresArchires::getTypeName(2);
  83. }
  84. }
  85. return '';
  86. }
  87. static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
  88. if ($item->getType() == 'Profile') {
  89. $prof = new self();
  90. $ID = $item->getField('id');
  91. self::addDefaultProfileInfos($item->getID(), ['plugin_archires' => 0]);
  92. $prof->showForProfile($item);
  93. }
  94. return true;
  95. }
  96. static function addDefaultProfileInfos($profiles_id, $rights) {
  97. $dbu = new DbUtils();
  98. $profileRight = new ProfileRight();
  99. foreach ($rights as $right => $value) {
  100. if (!$dbu->countElementsInTable('glpi_profilerights',
  101. ['profiles_id' => $profiles_id,
  102. 'name' => $right])) {
  103. $myright['profiles_id'] = $profiles_id;
  104. $myright['name'] = $right;
  105. $myright['rights'] = $value;
  106. $profileRight->add($myright);
  107. //Add right to the current session
  108. $_SESSION['glpiactiveprofile'][$right] = $value;
  109. }
  110. }
  111. }
  112. }