From a5be988a4311f39d44b23b4f69f80f713b012cae Mon Sep 17 00:00:00 2001
From: Xenomporio <>
Date: Sun, 24 Jul 2022 21:10:33 +0200
Subject: [PATCH] Ticketsystem reading of mails and import
Todo frontend details and sending. Also there is a no timestamp error at import on some mails (error returns e.g.)
---
.../Ticket/Task/TicketImportHelper.php | 17 ++-
database/struktur.sql | 10 +-
www/pages/ajax.php | 9 +-
www/pages/content/ticket_edit.tpl | 107 ++++++----------
www/pages/content/ticket_nachricht.tpl | 18 +++
www/pages/ticket.php | 117 ++++++++++++------
6 files changed, 158 insertions(+), 120 deletions(-)
create mode 100644 www/pages/content/ticket_nachricht.tpl
diff --git a/classes/Modules/Ticket/Task/TicketImportHelper.php b/classes/Modules/Ticket/Task/TicketImportHelper.php
index ec5106ab..59135e7b 100644
--- a/classes/Modules/Ticket/Task/TicketImportHelper.php
+++ b/classes/Modules/Ticket/Task/TicketImportHelper.php
@@ -292,7 +292,6 @@ class TicketImportHelper
{
// $this->db->beginTransaction();
try {
- $this->markTicketMessagesCompleted($ticketNumber);
$sql = "INSERT INTO `ticket_nachricht` (
`ticket`, `zeit`, `text`, `betreff`, `medium`,
`verfasser`, `mail`,`status`, `verfasser_replyto`, `mail_replyto`
@@ -325,6 +324,7 @@ class TicketImportHelper
$this->logger->error('Failed to insert ticket message into db', ['exception' => $e]);
}
+ $this->markTicketMessagesCompleted($ticketNumber);
}
/* End TicketService */
@@ -403,8 +403,13 @@ class TicketImportHelper
//check if email exists in database
$date = $message->getDate();
- $timestamp = $date->getTimestamp();
- $frommd5 = md5($from . $subject . $timestamp);
+ if (is_null($date)) { // This should not be happening -> Todo check getDate function
+ $this->logger->debug('Null date',['subject' => $message->getSubject()]);
+ $frommd5 = md5($from . $subject);
+ } else {
+ $timestamp = $date->getTimestamp();
+ $frommd5 = md5($from . $subject . $timestamp);
+ }
$empfang = $date->format('Y-m-d H:i:s');
$sql = "SELECT COUNT(id)
FROM `emailbackup_mails`
@@ -492,13 +497,13 @@ class TicketImportHelper
$from
);
+ } else {
+ $this->logger->debug('Add message to existing ticket',['ticketnummer' => $schluessel]);
}
- $this->logger->debug('Add message to ticket',['']);
-
// Add message to new or existing ticket
$ticketnachricht = $this->addTicketMessage(
- (string) $ticketNumber,
+ (string) $schluessel,
$timestamp,
$action_html, //?
$subject,
diff --git a/database/struktur.sql b/database/struktur.sql
index 2aca7598..b6394126 100755
--- a/database/struktur.sql
+++ b/database/struktur.sql
@@ -14355,16 +14355,16 @@ CREATE TABLE IF NOT EXISTS `ticket_nachricht` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ticket` varchar(255) NOT NULL,
`verfasser` varchar(255) NOT NULL,
- `bearbeiter` varchar(255) NOT NULL,
+ `bearbeiter` varchar(255) NOT NULL DEFAULT '',
`mail` varchar(255) NOT NULL,
`zeit` datetime NOT NULL,
- `zeitausgang` datetime NOT NULL,
+ `zeitausgang` datetime NULL,
`text` longtext NOT NULL,
- `textausgang` longtext NOT NULL,
+ `textausgang` longtext NOT NULL DEFAULT '',
`betreff` varchar(255) NOT NULL,
- `bemerkung` text NOT NULL,
+ `bemerkung` text NOT NULL DEFAULT '',
`medium` varchar(255) NOT NULL,
- `versendet` varchar(255) NOT NULL,
+ `versendet` varchar(255) NOT NULL DEFAULT '',
`status` varchar(64) NOT NULL,
`mail_cc` varchar(128) NOT NULL DEFAULT '',
`verfasser_replyto` varchar(255) NOT NULL,
diff --git a/www/pages/ajax.php b/www/pages/ajax.php
index 258b8527..e17fd730 100644
--- a/www/pages/ajax.php
+++ b/www/pages/ajax.php
@@ -1287,7 +1287,14 @@ class Ajax {
for($i = 0; $i < $carr; $i++) {
$newarr[] = "{$arr[$i]['name2']}";
}
- break;
+ break;
+ case 'warteschlangename':
+ $arr = $this->app->DB->SelectArr("SELECT CONCAT(label, ' ', warteschlange) as result from warteschlangen");
+ $carr = !empty($arr)?count($arr):0;
+ for($i = 0; $i < $carr; $i++) {
+ $newarr[] = "{$arr[$i]['result']}";
+ }
+ break;
/*
select a.kundennummer, (SELECT name FROM adresse a2 WHERE a2.kundennummer = a.kundennummer order by a2.projekt = 13 DESC, a2.projekt = 0 DESC, projekt LIMIT 1) as name FROM adresse a WHERE a.kundennummer like '10500' group by a.kundennummer
diff --git a/www/pages/content/ticket_edit.tpl b/www/pages/content/ticket_edit.tpl
index 6391fe05..ac5e93ce 100644
--- a/www/pages/content/ticket_edit.tpl
+++ b/www/pages/content/ticket_edit.tpl
@@ -14,84 +14,50 @@
[FORMHANDLEREVENT]
-
+
+
+
+
+
-
-
-
-
+
+ [MESSAGES]
+
diff --git a/www/pages/content/ticket_nachricht.tpl b/www/pages/content/ticket_nachricht.tpl
new file mode 100644
index 00000000..fefb7179
--- /dev/null
+++ b/www/pages/content/ticket_nachricht.tpl
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/www/pages/ticket.php b/www/pages/ticket.php
index e9ccf91a..aae59bf1 100644
--- a/www/pages/ticket.php
+++ b/www/pages/ticket.php
@@ -17,6 +17,7 @@ class Ticket {
$this->app->ActionHandler("list", "ticket_list");
$this->app->ActionHandler("create", "ticket_edit"); // This automatically adds a "New" button
$this->app->ActionHandler("edit", "ticket_edit");
+ $this->app->ActionHandler("edit_raw", "ticket_edit_raw");
$this->app->ActionHandler("delete", "ticket_delete");
$this->app->DefaultActionHandler("list");
$this->app->ActionHandlerListen($app);
@@ -26,6 +27,10 @@ class Ticket {
/* Fill out manually later */
}
+ function ticket_status_icon(string $status) {
+ return('');
+ }
+
static function TableSearch(&$app, $name, $erlaubtevars) {
@@ -34,14 +39,15 @@ class Ticket {
return "CONCAT('')";
}
+
switch ($name) {
case "ticket_list":
$allowed['ticket_list'] = array('list');
$heading = array('','','Ticket #', 'Datum', 'Adresse', 'Betreff', 'Notiz', 'Tags', 'Verantwortlich', 'Anzahl Nachrichten', 'Status', 'Alter', 'Projekt', 'Menü');
$width = array('1%','1%','5%', '5%', '5%', '20%', '20%', '5%', '5%', '1%', '1%', '5%', '5%', '5%');
- $findcols = array('t.id','t.id','t.schluessel', 't.zeit', 't.bearbeiter', 'a.name', 't.betreff', 't.notiz', 't.tags', 'w.warteschlange', 't.nachichten_anz', 't.status', 't.projekt');
- $searchsql = array('t.schluessel', 't.zeit', 't.bearbeiter', 'a.name', 't.betreff', 't.notiz', 't.tags', 'w.warteschlange', 't.nachichten_anz', 't.status', 't.projekt');
+ $findcols = array('t.id','t.id','t.schluessel', 't.zeit', 't.bearbeiter', 'a.name', 't.betreff', 't.notiz', 't.tags', 'w.warteschlange', 't.nachrichten_anz', 't.status', 't.projekt');
+ $searchsql = array('t.schluessel', 't.zeit', 't.bearbeiter', 'a.name', 't.betreff', 't.notiz', 't.tags', 'w.warteschlange', 't.status', 't.projekt');
$defaultorder = 1;
$defaultorderdesc = 0;
@@ -60,7 +66,7 @@ class Ticket {
$sql = "SELECT t.id,".$dropnbox.", t.schluessel, t.zeit, a.name, t.betreff, t.notiz, t.tags, w.warteschlange, t.nachrichten_anz, ".ticket_iconssql().", ".$timedifference.", p.abkuerzung, t.id
FROM ticket t
LEFT JOIN adresse a ON t.adresse = a.id
- LEFT JOIN warteschlangen w ON t.warteschlange = w.id
+ LEFT JOIN warteschlangen w ON t.warteschlange = w.label
LEFT JOIN projekt p on t.projekt = p.id";
$where = "1";
@@ -103,11 +109,6 @@ class Ticket {
$this->ticket_list();
}
- /*
- * Edit ticket item
- * If id is empty, create a new one
- */
-
function ticket_edit() {
$id = $this->app->Secure->GetGET('id');
@@ -131,6 +132,10 @@ class Ticket {
// Add checks here
+ $input['projekt'] = $this->app->erp->ReplaceProjekt(true,$input['projekt'],true); // Parameters: Target db?, value, from form?
+ $input['adresse'] = $this->app->erp->ReplaceAdresse(true,$input['adresse'],true); // Parameters: Target db?, value, from form?
+ $input['warteschlange'] = explode(" ",$input['warteschlange'])[0]; // Just the label
+
$columns = "id, ";
$values = "$id, ";
$update = "";
@@ -151,8 +156,6 @@ class Ticket {
$sql = "INSERT INTO ticket (".$columns.") VALUES (".$values.") ON DUPLICATE KEY UPDATE ".$update;
-// echo($sql);
-
$this->app->DB->Update($sql);
if ($id == 'NULL') {
@@ -165,7 +168,9 @@ class Ticket {
// Load values again from database
- $result = $this->app->DB->SelectArr("SELECT t.id, t.schluessel, t.zeit, t.projekt, t.bearbeiter, t.quelle, t.status, t.adresse, t.kunde, t.warteschlange, t.mailadresse, t.prio, t.betreff, t.zugewiesen, t.inbearbeitung, t.inbearbeitung_user, t.firma, t.notiz, t.bitteantworten, t.service, t.kommentar, t.privat, t.dsgvo, t.tags, t.nachrichten_anz, t.id FROM ticket t"." WHERE id=$id");
+// $result = $this->app->DB->SelectArr("SELECT t.id, t.schluessel, t.zeit, t.projekt, t.bearbeiter, t.quelle, t.status, t.adresse, t.kunde, t.warteschlange, t.mailadresse, t.prio, t.betreff, t.zugewiesen, t.inbearbeitung, t.inbearbeitung_user, t.firma, t.notiz, t.bitteantworten, t.service, t.kommentar, t.privat, t.dsgvo, t.tags, t.nachrichten_anz, t.id FROM ticket t"." WHERE id=$id");
+
+ $result = $this->app->DB->SelectArr("SELECT t.id, t.schluessel, t.zeit, p.abkuerzung as projekt, t.bearbeiter, t.quelle, t.status, t.adresse, t.kunde, CONCAT(w.label,' ',w.warteschlange) as warteschlange, t.mailadresse, t.prio, t.betreff, t.zugewiesen, t.inbearbeitung, t.inbearbeitung_user, t.firma, t.notiz, t.bitteantworten, t.service, t.kommentar, t.privat, t.dsgvo, t.tags, t.nachrichten_anz, t.id FROM ticket t LEFT JOIN adresse a ON t.adresse = a.id LEFT JOIN projekt p on t.projekt = p.id LEFT JOIN warteschlangen w on t.warteschlange = w.label WHERE t.id=$id");
foreach ($result[0] as $key => $value) {
$this->app->Tpl->Set(strtoupper($key), $value);
@@ -180,7 +185,33 @@ class Ticket {
$this->app->Tpl->Add('ANGEZEIGTERNAME', $angezeigtername);
*/
-// $this->SetInput($input);
+ $this->app->Tpl->Set('STATUSICON', $this->ticket_status_icon($result[0]['status'])." ");
+ $this->app->YUI->AutoComplete("adresse","adresse");
+ $this->app->Tpl->Set('ADRESSE', $this->app->erp->ReplaceAdresse(false,$result[0]['adresse'],false)); // Convert ID to form display
+ $this->app->YUI->AutoComplete("projekt","projektname",1);
+ $input['projekt'] = $this->app->erp->ReplaceProjekt(false,$input['projekt'],false); // Parameters: Target db?, value, from form?
+ $this->app->YUI->AutoComplete("warteschlange","warteschlangename");
+
+ // Add Messages now
+
+ $messages = $this->app->DB->SelectArr("SELECT n.betreff, n.verfasser, n.mail, n.zeit, n.versendet, n.text FROM ticket_nachricht n INNER JOIN ticket t ON t.schluessel = n.ticket WHERE t.id = ".$id." ORDER BY n.zeit DESC");
+
+ foreach ($messages as $message) {
+ $this->app->Tpl->Set("NACHRICHT_BETREFF",$message['betreff']);
+ $this->app->Tpl->Set("NACHRICHT_ZEIT",$message['zeit']);
+ if ($message['versendet'] == '1') {
+ $this->app->Tpl->Set("NACHRICHT_RICHTUNG","An");
+ $this->app->Tpl->Set("NACHRICHT_FLOAT","right");
+ } else {
+ $this->app->Tpl->Set("NACHRICHT_RICHTUNG","Von");
+ $this->app->Tpl->Set("NACHRICHT_FLOAT","left");
+ }
+ $this->app->Tpl->Set("NACHRICHT_NAME",$message['verfasser']);
+ $this->app->Tpl->Set("NACHRICHT_EMAILADRESSE",$message['mail']);
+ $this->app->Tpl->Set("NACHRICHT_TEXT",$message['text']);
+ $this->app->Tpl->Parse('MESSAGES', "ticket_nachricht.tpl");
+ }
+
$this->app->Tpl->Parse('PAGE', "ticket_edit.tpl");
}
@@ -191,32 +222,44 @@ class Ticket {
$input = array();
//$input['EMAIL'] = $this->app->Secure->GetPOST('email');
- $input['schluessel'] = $this->app->Secure->GetPOST('schluessel');
- $input['zeit'] = $this->app->Secure->GetPOST('zeit');
- $input['projekt'] = $this->app->Secure->GetPOST('projekt');
- $input['bearbeiter'] = $this->app->Secure->GetPOST('bearbeiter');
- $input['quelle'] = $this->app->Secure->GetPOST('quelle');
- $input['status'] = $this->app->Secure->GetPOST('status');
- $input['adresse'] = $this->app->Secure->GetPOST('adresse');
- $input['kunde'] = $this->app->Secure->GetPOST('kunde');
- $input['warteschlange'] = $this->app->Secure->GetPOST('warteschlange');
- $input['mailadresse'] = $this->app->Secure->GetPOST('mailadresse');
- $input['prio'] = $this->app->Secure->GetPOST('prio');
- $input['betreff'] = $this->app->Secure->GetPOST('betreff');
- $input['zugewiesen'] = $this->app->Secure->GetPOST('zugewiesen');
- $input['inbearbeitung'] = $this->app->Secure->GetPOST('inbearbeitung');
- $input['inbearbeitung_user'] = $this->app->Secure->GetPOST('inbearbeitung_user');
- $input['firma'] = $this->app->Secure->GetPOST('firma');
- $input['notiz'] = $this->app->Secure->GetPOST('notiz');
- $input['bitteantworten'] = $this->app->Secure->GetPOST('bitteantworten');
- $input['service'] = $this->app->Secure->GetPOST('service');
- $input['kommentar'] = $this->app->Secure->GetPOST('kommentar');
- $input['privat'] = $this->app->Secure->GetPOST('privat');
- $input['dsgvo'] = $this->app->Secure->GetPOST('dsgvo');
- $input['tags'] = $this->app->Secure->GetPOST('tags');
- $input['nachrichten_anz'] = $this->app->Secure->GetPOST('nachrichten_anz');
-
+ $input['projekt'] = $this->app->Secure->GetPOST('projekt');
+ $input['status'] = $this->app->Secure->GetPOST('status');
+ $input['adresse'] = $this->app->Secure->GetPOST('adresse');
+ $input['warteschlange'] = $this->app->Secure->GetPOST('warteschlange');
+ $input['prio'] = $this->app->Secure->GetPOST('prio');
+ $input['notiz'] = $this->app->Secure->GetPOST('notiz');
+ $input['tags'] = $this->app->Secure->GetPOST('tags');
+ return $input;
+ }
+ public function GetInput_raw(): array {
+ $input = array();
+ //$input['EMAIL'] = $this->app->Secure->GetPOST('email');
+
+ $input['schluessel'] = $this->app->Secure->GetPOST('schluessel');
+ $input['zeit'] = $this->app->Secure->GetPOST('zeit');
+ $input['projekt'] = $this->app->Secure->GetPOST('projekt');
+ $input['bearbeiter'] = $this->app->Secure->GetPOST('bearbeiter');
+ $input['quelle'] = $this->app->Secure->GetPOST('quelle');
+ $input['status'] = $this->app->Secure->GetPOST('status');
+ $input['adresse'] = $this->app->Secure->GetPOST('adresse');
+ $input['kunde'] = $this->app->Secure->GetPOST('kunde');
+ $input['warteschlange'] = $this->app->Secure->GetPOST('warteschlange');
+ $input['mailadresse'] = $this->app->Secure->GetPOST('mailadresse');
+ $input['prio'] = $this->app->Secure->GetPOST('prio');
+ $input['betreff'] = $this->app->Secure->GetPOST('betreff');
+ $input['zugewiesen'] = $this->app->Secure->GetPOST('zugewiesen');
+ $input['inbearbeitung'] = $this->app->Secure->GetPOST('inbearbeitung');
+ $input['inbearbeitung_user'] = $this->app->Secure->GetPOST('inbearbeitung_user');
+ $input['firma'] = $this->app->Secure->GetPOST('firma');
+ $input['notiz'] = $this->app->Secure->GetPOST('notiz');
+ $input['bitteantworten'] = $this->app->Secure->GetPOST('bitteantworten');
+ $input['service'] = $this->app->Secure->GetPOST('service');
+ $input['kommentar'] = $this->app->Secure->GetPOST('kommentar');
+ $input['privat'] = $this->app->Secure->GetPOST('privat');
+ $input['dsgvo'] = $this->app->Secure->GetPOST('dsgvo');
+ $input['tags'] = $this->app->Secure->GetPOST('tags');
+ $input['nachrichten_anz'] = $this->app->Secure->GetPOST('nachrichten_anz');
return $input;
}