Skip to content

Instantly share code, notes, and snippets.

@timoteoramos
Last active November 10, 2017 20:16
Show Gist options
  • Save timoteoramos/0306bed559c7b5359a9552da780a70c8 to your computer and use it in GitHub Desktop.
Save timoteoramos/0306bed559c7b5359a9552da780a70c8 to your computer and use it in GitHub Desktop.
GLPI Ticket Threshold
<?php
// Arquivo 'inc/session.class.php'
// Edite a função 'haveRight' para que ela fique similar ao exemplo abaixo
static function haveRight($module, $right) {
global $DB;
//If GLPI is using the slave DB -> read only mode
if ($DB->isSlave()
&& ($right & (CREATE | UPDATE | DELETE | PURGE))) {
return false;
}
// CHECAGEM ADICIONAL
// checagem de quantidade: lista os chamados pendentes
$query = "SELECT `id`
FROM `glpi_tickets`
WHERE `closedate` IS NULL
AND `solvedate` IS NOT NULL
AND `users_id_recipient` = " . $_SESSION["glpiID"];
// definindo objetos de sessão
$_SESSION["glpiTicketQueue"] = $DB->numrows($DB->query($query));
$_SESSION["glpiTicketThreshold"] = 2; // limite de chamados pendentes
// executa o script adicional apenas ao checar permissões específicas
if (($_SESSION["glpiTicketQueue"] >= $_SESSION["glpiTicketThreshold"])
&& ((($right & (READ)) && ($module == "reminder_public" || $module == "rssfeed_public"))
|| (($right & (CREATE)) && ($module === "ticket")))) {
return false;
}
if (isset($_SESSION["glpiactiveprofile"][$module])) {
return intval($_SESSION["glpiactiveprofile"][$module]) & $right;
}
return false;
}
<?php
// Arquivo 'front/ticket.php'
// Adicione esse código depois da chamada 'Html::header' para garantir que o cabeçalho HTML seja enviado antes do script injetado
if ($_SESSION["glpiTicketQueue"] >= $_SESSION["glpiTicketThreshold"]) {
echo "<script>alert('Você tem " . $_SESSION["glpiTicketQueue"] . " chamados solucionados com encerramento pendente.\\nFavor encerrá-los para poder abrir novos chamados.');</script>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment