Correction du fichier hook.php pour le plugin SOC

This commit is contained in:
tips-of-mine
2025-05-31 14:43:12 +02:00
committed by GitHub
parent 5b30a110ac
commit 4622a1a2cd
6 changed files with 554 additions and 24 deletions

View File

@ -77,4 +77,101 @@ class PluginSocCaseChange extends CommonDBRelation {
return $iterator;
}
/**
* Show cases for a change
*
* @param Change $change
* @return void
*/
function showForChange(Change $change) {
global $DB;
$change_id = $change->getID();
if (!$change->can($change_id, READ)) {
return false;
}
$cases = self::getCasesForChange($change_id);
$nb = count($cases);
echo "<div class='spaced'>";
if ($nb > 0) {
echo "<table class='tab_cadre_fixehov'>";
$header = "<tr>";
$header .= "<th>" . __('Name') . "</th>";
$header .= "<th>" . __('Status') . "</th>";
$header .= "<th>" . __('Severity', 'soc') . "</th>";
$header .= "<th>" . __('Creation date') . "</th>";
$header .= "</tr>";
echo $header;
foreach ($cases as $data) {
$case = new PluginSocCase();
$case->getFromDB($data['id']);
echo "<tr class='tab_bg_1'>";
echo "<td><a href='".Plugin::getWebDir('soc')."/front/case.form.php?id=".$data['id']."'>".$data['name']."</a></td>";
echo "<td><span class='soc-status soc-status-".$data['status']."'>".$case->getStatusOptions()[$data['status']]."</span></td>";
echo "<td><span class='soc-severity soc-severity-".$data['severity']."'>".$case->getSeverityOptions()[$data['severity']]."</span></td>";
echo "<td>".Html::convDateTime($data['date_creation'])."</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "<p class='center'>".__('No SOC case associated with this change', 'soc')."</p>";
}
// If user has rights to create cases
if (Session::haveRight('plugin_soc_case', CREATE)) {
echo "<div class='center'>";
echo "<a href='".Plugin::getWebDir('soc')."/front/case.form.php?changes_id=".$change_id."' class='submit'>";
echo __('Create SOC case from this change', 'soc');
echo "</a>";
echo "</div>";
}
echo "</div>";
}
/**
* Show form for linking a change to a case
*
* @param integer $cases_id
* @param array $options
* @return void
*/
function showFormForCase($cases_id, $options = []) {
global $CFG_GLPI;
$case = new PluginSocCase();
$case->getFromDB($cases_id);
echo "<form method='post' action='".Plugin::getWebDir('soc')."/front/case.form.php'>";
echo "<div class='spaced'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'><th colspan='2'>".__('Link a change to this case', 'soc')."</th></tr>";
echo "<tr class='tab_bg_1'><td class='right'>".__('Change')."</td>";
echo "<td class='left'>";
Change::dropdown(['name' => 'changes_id', 'entity' => $case->fields['entities_id']]);
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td class='center' colspan='2'>";
echo "<input type='hidden' name='plugin_soc_cases_id' value='$cases_id'>";
echo "<input type='submit' name='add_change' value=\""._sx('button', 'Add')."\" class='submit'>";
echo "</td></tr>";
echo "</table>";
echo "</div>";
Html::closeForm();
}
}