Start repository

This commit is contained in:
tips-of-mine
2025-05-31 10:26:04 +02:00
commit 486d93a4f0
30 changed files with 5788 additions and 0 deletions

108
inc/profile.class.php Normal file
View File

@ -0,0 +1,108 @@
<?php
/**
* SOC Profile class
*/
class PluginSocProfile extends Profile {
static $rightname = "profile";
/**
* @param string $right
* @return integer
*/
function getRight($right) {
return $this->fields[$right];
}
/**
* Init profiles
*
* @return void
*/
static function initProfile() {
global $DB;
$profile = new self();
// Add new rights in glpi_profilerights table
foreach ($profile->getAllRights() as $right) {
if (!countElementsInTable("glpi_profilerights", ['name' => $right['field']])) {
ProfileRight::addProfileRights([$right['field']]);
}
}
}
/**
* Get all rights
*
* @return array
*/
static function getAllRights() {
$rights = [
[
'field' => 'plugin_soc_case',
'name' => __('SOC Case', 'soc'),
'rights' => [
CREATE => __('Create'),
READ => __('Read'),
UPDATE => __('Update'),
DELETE => __('Delete'),
PURGE => __('Purge')
]
]
];
return $rights;
}
/**
* Create first access for super-admin user
*
* @param integer $ID
* @return void
*/
static function createFirstAccess($ID) {
$profile = new self();
foreach ($profile->getAllRights() as $right) {
self::addDefaultProfileInfos($ID, [$right['field'] => ALLSTANDARDRIGHT]);
}
}
/**
* Show profile form
*
* @param integer $profiles_id
* @param boolean $openform
* @param boolean $closeform
* @return void
*/
function showForm($profiles_id = 0, $openform = true, $closeform = true) {
echo "<div class='firstbloc'>";
if (($canedit = Session::haveRightsOr(self::$rightname, [CREATE, UPDATE, DELETE, PURGE]))
&& $openform) {
$profile = new Profile();
echo "<form method='post' action='".$profile->getFormURL()."'>";
}
$profile = new Profile();
$profile->getFromDB($profiles_id);
$rights = $this->getAllRights();
$profile->displayRightsChoiceMatrix($rights, ['canedit' => $canedit,
'default_class' => 'tab_bg_2',
'title' => __('General')]);
if ($canedit && $closeform) {
echo "<div class='center'>";
echo Html::hidden('id', ['value' => $profiles_id]);
echo Html::submit(_sx('button', 'Save'), ['name' => 'update']);
echo "</div>\n";
Html::closeForm();
}
echo "</div>";
}
}