O header usava item de menu 'plugins' (inexistente), quebrando o caminho
em "Home > Configurar". Agora usa sector/item do core ('config'/'plugin')
e o título correto "Redmine Integration".
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
80 lines
3.2 KiB
PHP
80 lines
3.2 KiB
PHP
<?php
|
|
include ("../../../inc/includes.php");
|
|
|
|
Session::checkRight("config", UPDATE);
|
|
|
|
$config = new PluginRedmineConfig();
|
|
global $DB;
|
|
|
|
if (isset($_POST["update"]) || isset($_POST["sync"])) {
|
|
// Save whatever was typed (URL/key/defaults) before anything else.
|
|
$config->update($_POST);
|
|
|
|
// Templates de payload: salvos junto pelo botão Salvar único.
|
|
if (!empty($_POST['templates_json']) && is_array($_POST['templates_json'])) {
|
|
foreach ($_POST['templates_json'] as $op => $json) {
|
|
if (!in_array($op, PluginRedmineTemplateengine::OPERATIONS, true)) {
|
|
continue;
|
|
}
|
|
$json = (string) $json;
|
|
// Defensivo contra escaping de aspas na camada de entrada.
|
|
if ($json !== '' && json_decode($json, true) === null && json_decode(stripslashes($json), true) !== null) {
|
|
$json = stripslashes($json);
|
|
}
|
|
if ($json !== '' && json_decode($json, true) === null) {
|
|
Session::addMessageAfterRedirect(
|
|
sprintf(__('Template "%s" não é JSON válido — não foi salvo.', 'redmine'), $op),
|
|
false,
|
|
ERROR
|
|
);
|
|
continue;
|
|
}
|
|
$active = !empty($_POST['templates_active'][$op]) && $json !== '';
|
|
PluginRedmineTemplateengine::save($op, $json, $active);
|
|
}
|
|
}
|
|
|
|
if (isset($_POST["sync"])) {
|
|
$metadata = PluginRedmineRedmineapi::syncMetadata();
|
|
if ($metadata !== false) {
|
|
$DB->update('glpi_plugin_redmine_configs', [
|
|
'metadata_cache' => json_encode($metadata)
|
|
], ['id' => 1]);
|
|
PluginRedmineRedmineapi::syncUsers(); // refresh Redmine user cache
|
|
Session::addMessageAfterRedirect(__('Metadados sincronizados com sucesso!', 'redmine'));
|
|
} else {
|
|
Session::addMessageAfterRedirect(__('Erro ao sincronizar com o Redmine. Verifique URL e chave.', 'redmine'), false, ERROR);
|
|
}
|
|
}
|
|
|
|
Html::back();
|
|
}
|
|
|
|
// Add a manual user mapping override (GLPI user -> Redmine user).
|
|
if (isset($_POST["add_usermap"])) {
|
|
$uid = (int) ($_POST['override_users_id'] ?? 0);
|
|
$rid = (int) ($_POST['override_redmine_user_id'] ?? 0);
|
|
if ($uid > 0 && $rid > 0) {
|
|
$DB->delete('glpi_plugin_redmine_usermap', ['users_id' => $uid]); // replace existing
|
|
$DB->insert('glpi_plugin_redmine_usermap', ['users_id' => $uid, 'redmine_user_id' => $rid]);
|
|
Session::addMessageAfterRedirect(__('Mapeamento adicionado.', 'redmine'));
|
|
} else {
|
|
Session::addMessageAfterRedirect(__('Selecione um usuário GLPI e um usuário Redmine.', 'redmine'), false, ERROR);
|
|
}
|
|
Html::back();
|
|
}
|
|
|
|
// Remove a manual user mapping override.
|
|
if (isset($_POST["del_usermap"])) {
|
|
$DB->delete('glpi_plugin_redmine_usermap', ['id' => (int) $_POST['del_usermap']]);
|
|
Session::addMessageAfterRedirect(__('Mapeamento removido.', 'redmine'));
|
|
Html::back();
|
|
}
|
|
|
|
// sector 'config' + item 'plugin' = breadcrumb "Início > Configurar > Plugins"
|
|
// (mesmas chaves de front/plugin.php do core; 'plugins' no plural não existe no menu)
|
|
Html::header(__('Redmine Integration', 'redmine'), $_SERVER['PHP_SELF'], 'config', 'plugin');
|
|
|
|
$config->showForm(1);
|
|
|
|
Html::footer();
|