Ticket system implemented ticketregeln (ticket rules)

This commit is contained in:
Xenomporio 2022-08-07 11:50:13 +02:00
parent cdaecb3969
commit dfdad1b8c4
5 changed files with 450 additions and 7 deletions

View File

@ -216,7 +216,7 @@ class TicketImportHelper
} }
} }
/* Function from Gateway */ /* Functions from Gateway */
/** /**
* @param string $ticketNumber * @param string $ticketNumber
* *
@ -233,6 +233,81 @@ class TicketImportHelper
return (int) $count; return (int) $count;
} }
/**
* @param string $recipientMail
* @param string $senderMail
* @param string $senderName
* @param string $subject
*
* @return array
*/
public function getTicketRules(
string $recipientMail,
string $senderMail,
string $senderName,
string $subject
): array {
/*
$sql = "SELECT
tr.spam AS `is_spam`,
tr.dsgvo AS `is_gdpr_relevant`,
tr.prio AS `priority`,
tr.persoenlich AS `is_private`,
tr.warteschlange AS `queue_id`
FROM `ticket_regeln` AS `tr`
WHERE
tr.aktiv = 1
AND (tr.empfaenger_email LIKE :source_email OR empfaenger_email = '')
AND (
tr.sender_email LIKE :sender_email
OR (tr.sender_email LIKE '@%' AND :sender_email LIKE CONCAT('%', tr.sender_email))
OR tr.sender_email = ''
)
AND (tr.name LIKE :sender_name OR tr.name = '')
AND (tr.betreff LIKE :subject OR tr.betreff = '')";
$values = [
'source_email' => $recipientMail,
'sender_email' => $senderMail,
'sender_name' => $senderName,
'subject' => $subject,
];
return $this->db->fetchAll($sql, $values);
*/
// Legacy DB implementation:
$sql = "SELECT
tr.id,
tr.spam AS `is_spam`,
tr.dsgvo AS `is_gdpr_relevant`,
tr.prio AS `priority`,
tr.persoenlich AS `is_private`,
tr.warteschlange AS `queue_id`
FROM `ticket_regeln` AS `tr`
WHERE
tr.aktiv = 1
AND ('".$recipientMail."' LIKE tr.empfaenger_email OR tr.empfaenger_email = '')
AND ('".$senderMail."' LIKE tr.sender_email OR tr.sender_email = '')
AND ('".$senderMail."' LIKE tr.name OR tr.name = '')
AND ('".$subject."' LIKE tr.betreff OR tr.betreff = '')";
$this->logger->debug('ticket rule',['sql' => $sql]);
$result = $this->db->SelectArr($sql);
if ($result != null) {
$this->logger->debug('ticket rules',['count',count($result)]);
return ($result);
} else {
$this->logger->debug('no ticket rules applicable',['']);
return(array());
}
}
/* END Functions from Gateway */
public function createTicket( public function createTicket(
int $projectId, int $projectId,
@ -322,21 +397,81 @@ class TicketImportHelper
$messageId = $this->db->GetInsertID(); $messageId = $this->db->GetInsertID();
$this->logger->debug('inserted',['id' => $messageId, 'schluessel' => $ticketNumber]); $this->logger->debug('inserted',['id' => $messageId, 'schluessel' => $ticketNumber]);
$this->updateTicketMessagesCount($ticketNumber); $this->updateTicketMessagesCount($ticketNumber);
$this->resetTicketStatus($ticketNumber); $this->resetTicketStatus($ticketNumber);
// $this->db->commit(); // $this->db->commit();
$success = 1;
return (int) $messageId; $this->markTicketMessagesCompleted($ticketNumber);
} catch (Throwable $e) { } catch (Throwable $e) {
// $this->db->rollBack(); // $this->db->rollBack();
$success = 0;
$this->logger->error('Failed to insert ticket message into db', ['exception' => $e]); $this->logger->error('Failed to insert ticket message into db', ['exception' => $e]);
}
$this->applyTicketRules($messageId);
return($success);
} }
$this->markTicketMessagesCompleted($ticketNumber);
public function applyTicketRules(int $ticketMessageId): void
{
/* $ticketData = $this->gateway->tryGetTicketDataByByMessage($ticketMessageId); */
$ticketData = $this->db->SelectArr("SELECT t.id, tn.mail as sender_email, tn.verfasser as sender_name, tn.betreff as subject, t.quelle as source_email FROM ticket t INNER JOIN ticket_nachricht tn ON tn.ticket = t.schluessel WHERE tn.id = '".$ticketMessageId."'")[0];
if ($ticketData === null) {
throw new InvalidArgumentException('cannot find ticket by message id');
} }
$ticketId = $ticketData['id'];
$senderMail = $ticketData['sender_email'];
$senderName = $ticketData['sender_name'];
$subject = $ticketData['subject'];
$source = $ticketData['source_email'];
$this->logger->debug('check ticket rules',['tn_id' => $ticketMessageId, 'sender_email' => $senderMail, 'subject' => $subject]);
//TODO: richtig loggen: $this->app->erp->LogFile("Empfaengermail: $quelle Sendermail: $mailadresse Kunde: $kunde Betreff: $betreff");
$ruleArray = $this->getTicketRules($source, $senderMail, $senderName, $subject);
if (empty($ruleArray)) {
return;
}
foreach ($ruleArray as $rule) {
$this->logger->debug('ticket rule applies',['rule_id' => $rule['id']]);
/*
$update = $this->db->update();
$update->table('ticket');
if ($rule['is_spam'] === 1) {
$update->set('inbearbeitung', 0);
$update->set('zugewiesen', 1);
$this->db->perform(
'UPDATE `ticket_nachricht` SET `status` = :status WHERE `ticket` = :ticket_id',
['status' => TicketGateway::STATUS_SPAM, 'ticket_id' => $ticketId]
);
}
$update->set('dsgvo', $rule['is_gdpr_relevant']);
$update->set('privat', $rule['is_private'] );
$update->set('prio', $rule['priority'] );
$update->where('id = :ticket_id');
$sql = $update->getStatement();
$this->db->perform($sql, ['ticket_id' => $ticketId]);
*/
if ($rule['is_spam'] === 1) {
$sql = "UPDATE `ticket_nachricht` SET `status` = \'spam\' WHERE `id` = '".$ticketMessageId."'";
$this->db->Update($sql);
}
$sql = "UPDATE `ticket` SET `dsgvo` = '".$rule['is_gdpr_relevant']."', `privat` = '".$rule['is_private']."', `prio` = '".$rule['priority']."', `warteschlange` = '".$rule['queue_id']."' WHERE `id` = '".$ticketId."'";
$this->db->Update($sql);
}
}
/* End TicketService */ /* End TicketService */
/** /**
@ -355,6 +490,9 @@ class TicketImportHelper
continue; continue;
} }
try { try {
$this->logger->debug('Start import', ['message' => $message->getSubject()]);
$this->importMessage($message); $this->importMessage($message);
$insertedMailsCount++; $insertedMailsCount++;
if ($this->mailAccount->isDeleteAfterImportEnabled()) { if ($this->mailAccount->isDeleteAfterImportEnabled()) {

View File

@ -7084,6 +7084,7 @@ title: 'Abschicken',
$navarray['menu']['admin'][++$menu]['first'] = array('Verwaltung','rechnung','list'); $navarray['menu']['admin'][++$menu]['first'] = array('Verwaltung','rechnung','list');
$navarray['menu']['admin'][$menu]['sec'][] = array('Ticketregeln','ticketregeln','list');
$navarray['menu']['admin'][$menu]['sec'][] = array('Zeitkonten','zeiterfassung','list'); $navarray['menu']['admin'][$menu]['sec'][] = array('Zeitkonten','zeiterfassung','list');
if(!$this->RechteVorhanden('mitarbeiterzeiterfassung','dashboard')){ if(!$this->RechteVorhanden('mitarbeiterzeiterfassung','dashboard')){
$navarray['menu']['admin'][$menu]['sec'][] = array('Antrag einreichen','mitarbeiterzeiterfassung','timemanagementrequest'); $navarray['menu']['admin'][$menu]['sec'][] = array('Antrag einreichen','mitarbeiterzeiterfassung','timemanagementrequest');

View File

@ -0,0 +1,91 @@
<div id="tabs">
<ul>
<li><a href="#tabs-1"></a></li>
</ul>
<!-- Example for multiple tabs
<ul hidden">
<li><a href="#tabs-1">First Tab</a></li>
<li><a href="#tabs-2">Second Tab</a></li>
</ul>
-->
<div id="tabs-1">
[MESSAGE]
<form action="" method="post">
[FORMHANDLEREVENT]
<div class="row">
<div class="row-height">
<div class="col-xs-12 col-md-12 col-md-height">
<div class="inside inside-full-height">
<fieldset>
<legend>{|Ticketregeln|}</legend><i>Ticketregeln f&uuml; die Verarbeitung bei Ticketeingang. Platzhalter werden mit % angegeben.</i>
<table width="100%" border="0" class="mkTableFormular">
<tr><td>{|E-Mail Empf&auml;nger|}:</td><td><input type="text" name="empfaenger_email" value="[EMPFAENGER_EMAIL]" size="40"></td></tr>
<tr><td>{|E-Mail Verfasser|}:</td><td><input type="text" name="sender_email" value="[SENDER_EMAIL]" size="40"></td></tr>
<tr><td>{|Verfasser Name|}:</td><td><input type="text" name="name" value="[NAME]" size="40"></td></tr>
<tr><td>{|Betreff|}:</td><td><input type="text" name="betreff" value="[BETREFF]" size="40"></td></tr>
<tr><td>{|Papierkorb|}:</td><td><input type="text" name="spam" value="[SPAM]" size="40"></td></tr>
<tr><td>{|Pers&ouml;nlich|}:</td><td><input type="text" name="persoenlich" value="[PERSOENLICH]" size="40"></td></tr>
<tr><td>{|Prio|}:</td><td><input type="text" name="prio" value="[PRIO]" size="40"></td></tr>
<tr><td>{|DSGVO|}:</td><td><input type="text" name="dsgvo" value="[DSGVO]" size="40"></td></tr>
<tr><td>{|Verantwortliche Warteschlange|}:</td><td><input type="text" name="warteschlange" id="warteschlange" value="[WARTESCHLANGE]" size="40"></td></tr>
<tr><td>{|Aktiv|}:</td><td><input type="text" name="aktiv" value="[AKTIV]" size="40"></td></tr>
</table>
</fieldset>
</div>
</div>
</div>
</div>
<!-- Example for 2nd row
<div class="row">
<div class="row-height">
<div class="col-xs-12 col-md-12 col-md-height">
<div class="inside inside-full-height">
<fieldset>
<legend>{|Another legend|}</legend>
<table width="100%" border="0" class="mkTableFormular">
<tr><td>{|Empfaenger_email|}:</td><td><input type="text" name="empfaenger_email" value="[EMPFAENGER_EMAIL]" size="40"></td></tr>
<tr><td>{|Sender_email|}:</td><td><input type="text" name="sender_email" value="[SENDER_EMAIL]" size="40"></td></tr>
<tr><td>{|Name|}:</td><td><input type="text" name="name" value="[NAME]" size="40"></td></tr>
<tr><td>{|Betreff|}:</td><td><input type="text" name="betreff" value="[BETREFF]" size="40"></td></tr>
<tr><td>{|Spam|}:</td><td><input type="text" name="spam" value="[SPAM]" size="40"></td></tr>
<tr><td>{|Persoenlich|}:</td><td><input type="text" name="persoenlich" value="[PERSOENLICH]" size="40"></td></tr>
<tr><td>{|Prio|}:</td><td><input type="text" name="prio" value="[PRIO]" size="40"></td></tr>
<tr><td>{|Dsgvo|}:</td><td><input type="text" name="dsgvo" value="[DSGVO]" size="40"></td></tr>
<tr><td>{|Warteschlange|}:</td><td><input type="text" name="warteschlange" value="[WARTESCHLANGE]" size="40"></td></tr>
<tr><td>{|Aktiv|}:</td><td><input type="text" name="aktiv" value="[AKTIV]" size="40"></td></tr>
</table>
</fieldset>
</div>
</div>
</div>
</div> -->
<input type="submit" name="submit" value="Speichern" style="float:right"/>
</form>
</div>
<!-- Example for 2nd tab
<div id="tabs-2">
[MESSAGE]
<form action="" method="post">
[FORMHANDLEREVENT]
<div class="row">
<div class="row-height">
<div class="col-xs-12 col-md-12 col-md-height">
<div class="inside inside-full-height">
<fieldset>
<legend>{|...|}</legend>
<table width="100%" border="0" class="mkTableFormular">
...
</table>
</fieldset>
</div>
</div>
</div>
</div>
<input type="submit" name="submit" value="Speichern" style="float:right"/>
</form>
</div>
-->
</div>

View File

@ -0,0 +1,5 @@
<div id="tabs-1">
[MESSAGE]
[TAB1]
[TAB1NEXT]
</div>

208
www/pages/ticketregeln.php Normal file
View File

@ -0,0 +1,208 @@
<?php
/*
* Copyright (c) 2022 Xenomporio project
*/
use Xentral\Components\Database\Exception\QueryFailureException;
class Ticketregeln {
function __construct($app, $intern = false) {
$this->app = $app;
if ($intern)
return;
$this->app->ActionHandlerInit($this);
$this->app->ActionHandler("list", "ticketregeln_list");
$this->app->ActionHandler("create", "ticketregeln_edit"); // This automatically adds a "New" button
$this->app->ActionHandler("edit", "ticketregeln_edit");
$this->app->ActionHandler("delete", "ticketregeln_delete");
$this->app->DefaultActionHandler("list");
$this->app->ActionHandlerListen($app);
}
public function Install() {
/* Fill out manually later */
}
static function TableSearch(&$app, $name, $erlaubtevars) {
switch ($name) {
case "ticketregeln_list":
$allowed['ticketregeln_list'] = array('list');
$heading = array('E-Mail Empf&auml;nger', 'E-Mail Verfasser', 'Verfasser Name', 'Betreff', 'Papierkorb', 'Pers&ouml;nlich', 'Prio', 'DSGVO', 'Verantw.', 'Aktiv', 'Men&uuml;');
$width = array('10%'); // Fill out manually later
$findcols = array('t.empfaenger_email', 't.sender_email', 't.name', 't.betreff', 't.spam', 't.persoenlich', 't.prio', 't.dsgvo', 't.warteschlange', 't.aktiv');
$searchsql = array('t.empfaenger_email', 't.sender_email', 't.name', 't.betreff', 't.spam', 't.persoenlich', 't.prio', 't.dsgvo', 't.warteschlange', 't.aktiv');
$defaultorder = 1;
$defaultorderdesc = 0;
$menu = "<table cellpadding=0 cellspacing=0><tr><td nowrap>" . "<a href=\"index.php?module=ticketregeln&action=edit&id=%value%\"><img src=\"./themes/{$app->Conf->WFconf['defaulttheme']}/images/edit.svg\" border=\"0\"></a>&nbsp;<a href=\"#\" onclick=DeleteDialog(\"index.php?module=ticketregeln&action=delete&id=%value%\");>" . "<img src=\"themes/{$app->Conf->WFconf['defaulttheme']}/images/delete.svg\" border=\"0\"></a>" . "</td></tr></table>";
$sql = "SELECT t.id, t.empfaenger_email, t.sender_email, t.name, t.betreff, t.spam, t.persoenlich, t.prio, t.dsgvo, w.warteschlange, t.aktiv, t.id FROM ticket_regeln t LEFT JOIN warteschlangen w ON t.warteschlange = w.label";
$where = "1";
$count = "SELECT count(DISTINCT id) FROM ticket_regeln WHERE $where";
// $groupby = "";
break;
}
$erg = false;
foreach ($erlaubtevars as $k => $v) {
if (isset($$v)) {
$erg[$v] = $$v;
}
}
return $erg;
}
function ticketregeln_list() {
$this->app->erp->MenuEintrag("index.php?module=ticketregeln&action=list", "&Uuml;bersicht");
$this->app->erp->MenuEintrag("index.php?module=ticketregeln&action=create", "Neu anlegen");
$this->app->erp->MenuEintrag("index.php", "Zur&uuml;ck");
$this->app->YUI->TableSearch('TAB1', 'ticketregeln_list', "show", "", "", basename(__FILE__), __CLASS__);
$this->app->Tpl->Parse('PAGE', "ticketregeln_list.tpl");
}
public function ticketregeln_delete() {
$id = (int) $this->app->Secure->GetGET('id');
$this->app->DB->Delete("DELETE FROM `ticket_regeln` WHERE `id` = '{$id}'");
$this->app->Tpl->Set('MESSAGE', "<div class=\"error\">Der Eintrag wurde gel&ouml;scht.</div>");
$this->ticketregeln_list();
}
/*
* Edit ticketregeln item
* If id is empty, create a new one
*/
function ticketregeln_edit() {
$id = $this->app->Secure->GetGET('id');
$this->app->Tpl->Set('ID', $id);
$this->app->erp->MenuEintrag("index.php?module=ticketregeln&action=edit&id=$id", "Details");
$this->app->erp->MenuEintrag("index.php?module=ticketregeln&action=list", "Zur&uuml;ck zur &Uuml;bersicht");
$id = $this->app->Secure->GetGET('id');
$input = $this->GetInput();
$submit = $this->app->Secure->GetPOST('submit');
if (empty($id)) {
// New item
$id = 'NULL';
}
if ($submit != '')
{
// Write to database
// Add checks here
$input['warteschlange'] = explode(" ",$input['warteschlange'])[0]; // Just the label
$columns = "id, ";
$values = "$id, ";
$update = "";
$fix = "";
foreach ($input as $key => $value) {
$columns = $columns.$fix.$key;
$values = $values.$fix."'".$value."'";
$update = $update.$fix.$key." = '$value'";
$fix = ", ";
}
// echo($columns."<br>");
// echo($values."<br>");
// echo($update."<br>");
$sql = "INSERT INTO ticket_regeln (".$columns.") VALUES (".$values.") ON DUPLICATE KEY UPDATE ".$update;
// echo($sql);
$this->app->DB->Update($sql);
if ($id == 'NULL') {
$msg = $this->app->erp->base64_url_encode("<div class=\"success\">Das Element wurde erfolgreich angelegt.</div>");
header("Location: index.php?module=ticketregeln&action=list&msg=$msg");
} else {
$this->app->Tpl->Set('MESSAGE', "<div class=\"success\">Die Einstellungen wurden erfolgreich &uuml;bernommen.</div>");
}
}
// Load values again from database
$result = $this->app->DB->SelectArr("SELECT t.id, t.empfaenger_email, t.sender_email, t.name, t.betreff, t.spam, t.persoenlich, t.prio, t.dsgvo, t.warteschlange, t.aktiv, t.id FROM ticket_regeln t"." WHERE id=$id");
foreach ($result[0] as $key => $value) {
$this->app->Tpl->Set(strtoupper($key), $value);
}
/*
* Add displayed items later
*
$this->app->Tpl->Add('KURZUEBERSCHRIFT2', $email);
$this->app->Tpl->Add('EMAIL', $email);
$this->app->Tpl->Add('ANGEZEIGTERNAME', $angezeigtername);
*/
$this->app->YUI->AutoComplete("warteschlange","warteschlangename");
// $this->SetInput($input);
$this->app->Tpl->Parse('PAGE', "ticketregeln_edit.tpl");
}
/**
* Get all paramters from html form and save into $input
*/
public function GetInput(): array {
$input = array();
//$input['EMAIL'] = $this->app->Secure->GetPOST('email');
$input['empfaenger_email'] = $this->app->Secure->GetPOST('empfaenger_email');
$input['sender_email'] = $this->app->Secure->GetPOST('sender_email');
$input['name'] = $this->app->Secure->GetPOST('name');
$input['betreff'] = $this->app->Secure->GetPOST('betreff');
$input['spam'] = $this->app->Secure->GetPOST('spam');
$input['persoenlich'] = $this->app->Secure->GetPOST('persoenlich');
$input['prio'] = $this->app->Secure->GetPOST('prio');
$input['dsgvo'] = $this->app->Secure->GetPOST('dsgvo');
$input['warteschlange'] = $this->app->Secure->GetPOST('warteschlange');
$input['aktiv'] = $this->app->Secure->GetPOST('aktiv');
return $input;
}
/*
* Set all fields in the page corresponding to $input
*/
function SetInput($input) {
// $this->app->Tpl->Set('EMAIL', $input['email']);
$this->app->Tpl->Set('EMPFAENGER_EMAIL', $input['empfaenger_email']);
$this->app->Tpl->Set('SENDER_EMAIL', $input['sender_email']);
$this->app->Tpl->Set('NAME', $input['name']);
$this->app->Tpl->Set('BETREFF', $input['betreff']);
$this->app->Tpl->Set('SPAM', $input['spam']);
$this->app->Tpl->Set('PERSOENLICH', $input['persoenlich']);
$this->app->Tpl->Set('PRIO', $input['prio']);
$this->app->Tpl->Set('DSGVO', $input['dsgvo']);
$this->app->Tpl->Set('WARTESCHLANGE', $input['warteschlange']);
$this->app->Tpl->Set('AKTIV', $input['aktiv']);
}
}