2022-07-22 17:42:03 +02:00
< ? php
/*
2022-10-14 14:18:26 +02:00
* Copyright ( c ) 2022 OpenXE project
2022-07-22 17:42:03 +02:00
*/
use Xentral\Components\Database\Exception\QueryFailureException ;
2022-07-29 14:45:16 +02:00
use Xentral\Modules\Ticket\Task ;
2022-07-22 17:42:03 +02:00
class Ticket {
function __construct ( $app , $intern = false ) {
$this -> app = $app ;
if ( $intern )
return ;
$this -> app -> ActionHandlerInit ( $this );
$this -> app -> ActionHandler ( " list " , " ticket_list " );
2022-07-29 14:45:16 +02:00
$this -> app -> ActionHandler ( " create " , " ticket_create " ); // This automatically adds a "New" button
2022-07-22 17:42:03 +02:00
$this -> app -> ActionHandler ( " edit " , " ticket_edit " );
2022-07-30 14:29:02 +02:00
$this -> app -> ActionHandler ( " minidetail " , " ticket_minidetail " );
2022-08-17 15:07:13 +02:00
$this -> app -> ActionHandler ( " text " , " ticket_text " ); // Output text for iframe display
$this -> app -> ActionHandler ( " text_ausgang " , " ticket_text_ausgang " ); // Output text for iframe display
2022-08-18 20:45:09 +02:00
$this -> app -> ActionHandler ( " statusfix " , " ticket_statusfix " ); // Xentral 20 compatibility set all ticket status to latest ticket_nachricht status
2022-08-18 21:36:42 +02:00
$this -> app -> ActionHandler ( " datefix " , " ticket_datefix " ); // Xentral 20 compatibility set all ticket dates to latest ticket_nachricht date
2022-07-22 17:42:03 +02:00
$this -> app -> DefaultActionHandler ( " list " );
$this -> app -> ActionHandlerListen ( $app );
}
public function Install () {
/* Fill out manually later */
}
2022-07-24 21:10:33 +02:00
function ticket_status_icon ( string $status ) {
return ( '<img src="./themes/new/images/status_' . $status . '.png" style="margin-right:1px" title="' . $status . '" border="0">' );
}
2022-07-22 17:42:03 +02:00
2022-07-31 18:23:43 +02:00
public function TableSearch ( & $app , $name , $erlaubtevars ) {
2022-07-22 17:42:03 +02:00
function ticket_iconssql () {
return " CONCAT('<img src= \" ./themes/new/images/status_',`t`.`status`,'.png \" style= \" margin-right:1px \" title= \" ',`t`.`status`,' \" border= \" 0 \" >') " ;
}
2022-07-24 21:10:33 +02:00
2022-07-22 17:42:03 +02:00
switch ( $name ) {
case " ticket_list " :
2022-07-31 21:45:38 +02:00
2022-07-22 17:42:03 +02:00
$allowed [ 'ticket_list' ] = array ( 'list' );
2023-01-16 17:45:23 +01:00
$heading = array ( '' , '' , 'Ticket #' , 'Aktion' , 'Adresse' , 'Betreff' , 'Tags' , 'Verant.' , 'Nachr.' , 'Status' , 'Projekt' , 'Menü' );
$width = array ( '1%' , '1%' , '5%' , '5%' , '5%' , '30%' , '1%' , '5%' , '1%' , '1%' , '1%' , '1%' );
2022-07-22 17:42:03 +02:00
2023-01-16 17:45:23 +01:00
$findcols = array ( 't.id' , 't.id' , 't.schluessel' , 't.zeit' , 'a.name' , 't.betreff' , 't.tags' , 'w.warteschlange' , 'nachrichten_anz' , 't.status' , 'p.abkuerzung' );
$searchsql = array ( 't.schluessel' , 't.zeit' , 'a.name' , 't.betreff' , 't.notiz' , 't.tags' , 'w.warteschlange' , 't.status' , 'p.abkuerzung' , '(SELECT mail FROM ticket_nachricht tn WHERE tn.ticket = t.schluessel AND tn.versendet <> 1 LIMIT 1)' );
2022-07-22 17:42:03 +02:00
$defaultorder = 1 ;
$defaultorderdesc = 0 ;
2022-08-06 11:31:43 +02:00
$menu = " <table cellpadding=0 cellspacing=0><tr><td nowrap> " . " <a href= \" index.php?module=ticket&action=edit&id=%value% \" ><img src= \" ./themes/ { $app -> Conf -> WFconf [ 'defaulttheme' ] } /images/edit.svg \" border= \" 0 \" ></a> " . " </td></tr></table> " ;
2022-07-22 17:42:03 +02:00
$timedifference = " if (
2022-07-31 18:23:43 +02:00
TIMESTAMPDIFF ( hour , t . zeit , NOW ()) < 24 ,
CONCAT ( TIMESTAMPDIFF ( hour , t . zeit , NOW ()), 'h' ),
CONCAT ( TIMESTAMPDIFF ( day , t . zeit , NOW ()), 'd ' , MOD ( TIMESTAMPDIFF ( hour , t . zeit , NOW ()), 24 ), 'h' )) " ;
2022-07-22 17:42:03 +02:00
2023-01-16 17:45:23 +01:00
$dropnbox = " '<img src=./themes/new/images/details_open.png class=details>' AS `open`,
CONCAT ( '<input type=\"checkbox\" name=\"auswahl[]\" value=\"' , t . id , '\" />' ) AS `auswahl` " ;
2022-07-22 17:42:03 +02:00
2022-07-30 13:36:18 +02:00
$priobetreff = " if(t.prio!=1,t.betreff,CONCAT('<b><font color=red>',t.betreff,'</font></b>')) " ;
2022-07-30 14:29:02 +02:00
$anzahlnachrichten = " (SELECT COUNT(n.id) FROM ticket_nachricht n WHERE n.ticket = t.schluessel) " ;
2023-01-16 17:45:23 +01:00
$letztemail = $app -> erp -> FormatDateTimeShort ( " (SELECT MAX(n.zeit) FROM ticket_nachricht n WHERE n.ticket = t.schluessel AND n.zeit IS NOT NULL) " );
2022-07-31 21:45:38 +02:00
$tagstart = " <li class= \" tag-editor-tag \" > " ;
$tagend = " </li> " ;
2022-08-08 14:06:22 +02:00
$sql = " SELECT SQL_CALC_FOUND_ROWS
2022-07-31 21:45:38 +02:00
t . id ,
" . $dropnbox . " ,
2023-01-16 17:45:23 +01:00
CONCAT ( '<a href=\"index.php?module=ticket&action=edit&id=' , t . id , '\">' , t . schluessel , '</a>' ), " .
$app -> erp -> FormatDateTimeShort ( 'zeit' ) . " as aktion,
CONCAT ( COALESCE ( CONCAT ( a . name , '<br>' ), '' ), COALESCE (( SELECT mail FROM ticket_nachricht tn WHERE tn . ticket = t . schluessel AND tn . versendet <> 1 LIMIT 1 ), '' )) as combiadresse ,
2022-08-15 23:43:36 +02:00
CONCAT ( '<b>' , " . $priobetreff . " , '</b><br/><i>' , replace ( substring ( ifnull ( t . notiz , '' ), 1 , 500 ), '\n' , '<br/>' ), '</i>' ),
CONCAT ( '<div class=\"ticketoffene\"><ul class=\"tag-editor\">' \n , '".$tagstart."' , replace ( t . tags , ',' , '".$tagend."<div class=\"tag-editor-spacer\"> </div>".$tagstart."' ), '".$tagend."' , '</ul></div>' ),
2022-07-31 21:45:38 +02:00
w . warteschlange ,
2023-01-16 17:45:23 +01:00
" . $anzahlnachrichten . " as `nachrichten_anz` ,
2022-07-31 21:45:38 +02:00
" .ticket_iconssql(). " ,
p . abkuerzung ,
t . id
2022-07-22 17:42:03 +02:00
FROM ticket t
LEFT JOIN adresse a ON t . adresse = a . id
2022-07-24 21:10:33 +02:00
LEFT JOIN warteschlangen w ON t . warteschlange = w . label
2022-07-22 17:42:03 +02:00
LEFT JOIN projekt p on t . projekt = p . id " ;
$where = " 1 " ;
2022-07-31 18:23:43 +02:00
// Toggle filters
$this -> app -> Tpl -> Add ( 'JQUERYREADY' , " $ ('#meinetickets').click( function() { fnFilterColumn1( 0 ); } ); " );
$this -> app -> Tpl -> Add ( 'JQUERYREADY' , " $ ('#prio').click( function() { fnFilterColumn2( 0 ); } ); " );
$this -> app -> Tpl -> Add ( 'JQUERYREADY' , " $ ('#geschlossene').click( function() { fnFilterColumn3( 0 ); } ); " );
2022-08-01 22:55:52 +02:00
$this -> app -> Tpl -> Add ( 'JQUERYREADY' , " $ ('#spam').click( function() { fnFilterColumn4( 0 ); } ); " );
2022-07-31 18:23:43 +02:00
for ( $r = 1 ; $r <= 4 ; $r ++ ) {
$this -> app -> Tpl -> Add ( 'JAVASCRIPT' , '
function fnFilterColumn ' . $r . ' ( i )
{
if ( oMoreData ' . $r . $name . ' == 1 )
oMoreData ' . $r . $name . ' = 0 ;
else
oMoreData ' . $r . $name . ' = 1 ;
$ ( \ '#' . $name . ' \ ' ) . dataTable () . fnFilter (
\ ' \ ' ,
i ,
0 , 0
);
}
' );
}
$more_data1 = $this -> app -> Secure -> GetGET ( " more_data1 " );
if ( $more_data1 == 1 ) {
$where .= " AND t.warteschlange IN (SELECT w.label FROM warteschlangen w WHERE adresse= " . $this -> app -> User -> GetAdresse () . " ) " ; // Queues of user
} else {
}
$more_data2 = $this -> app -> Secure -> GetGET ( " more_data2 " );
if ( $more_data2 == 1 ) {
$where .= " AND t.prio = '1' " ;
}
else {
}
$more_data3 = $this -> app -> Secure -> GetGET ( " more_data3 " );
if ( $more_data3 == 1 ) {
}
else {
2022-08-01 22:55:52 +02:00
$where .= " AND (t.status <> 'abgeschlossen') " ; // Exclude and geschlossen
2022-07-31 18:23:43 +02:00
}
$more_data4 = $this -> app -> Secure -> GetGET ( " more_data4 " );
if ( $more_data4 == 1 ) {
}
else {
2022-08-01 22:55:52 +02:00
$where .= " AND (t.status <> 'spam') " ;
2022-07-31 18:23:43 +02:00
}
// END Toggle filters
2022-07-22 17:42:03 +02:00
$moreinfo = true ; // Allow drop down details
2023-01-16 17:45:23 +01:00
$menucol = 11 ; // For moredata
2022-07-22 17:42:03 +02:00
2022-07-31 18:23:43 +02:00
$count = " SELECT count(DISTINCT id) FROM ticket t WHERE $where " ;
// echo(htmlentities($sql." ".$where));
2022-07-22 17:42:03 +02:00
// $groupby = "";
break ;
}
$erg = false ;
foreach ( $erlaubtevars as $k => $v ) {
if ( isset ( $$v )) {
$erg [ $v ] = $$v ;
}
}
return $erg ;
}
function ticket_list () {
2022-07-31 22:32:36 +02:00
// Process multi action
$auswahl = $this -> app -> Secure -> GetPOST ( 'auswahl' );
$selectedIds = [];
if ( ! empty ( $auswahl )) {
foreach ( $auswahl as $selectedId ) {
$selectedId = ( int ) $selectedId ;
if ( $selectedId > 0 ) {
$selectedIds [] = $selectedId ;
}
}
$status = $this -> app -> Secure -> GetPOST ( 'status' );
$warteschlange = $this -> app -> Secure -> GetPOST ( 'warteschlange' );
2022-08-03 17:43:45 +02:00
$sql = " UPDATE ticket SET status = ' " . $status . " ', zeit = NOW() " ;
2022-07-31 22:32:36 +02:00
if ( $warteschlange != '' ) {
$sql .= " , warteschlange = ' " . explode ( " " , $warteschlange )[ 0 ] . " ' " ;
}
$sql .= " WHERE id IN ( " . implode ( " , " , $selectedIds ) . " ) " ;
$this -> app -> DB -> Update ( $sql );
}
// List
$this -> app -> YUI -> TagEditor ( 'taglist' , array ( 'width' => 370 ));
$this -> app -> Tpl -> Add ( 'SCRIPTJAVASCRIPT' , '<link rel="stylesheet" type="text/css" href="./css/jquery.tag-editor.css">' );
2022-07-22 17:42:03 +02:00
$this -> app -> erp -> MenuEintrag ( " index.php?module=ticket&action=list " , " Übersicht " );
$this -> app -> erp -> MenuEintrag ( " index.php?module=ticket&action=create " , " Neu anlegen " );
$this -> app -> erp -> MenuEintrag ( " index.php " , " Zurück " );
2022-07-31 22:32:36 +02:00
$this -> app -> Tpl -> Set ( 'STATUS' , $this -> app -> erp -> GetStatusTicketSelect ( 'neu' ));
$this -> app -> YUI -> AutoComplete ( " warteschlange " , " warteschlangename " );
2022-07-22 17:42:03 +02:00
$this -> app -> YUI -> TableSearch ( 'TAB1' , 'ticket_list' , " show " , " " , " " , basename ( __FILE__ ), __CLASS__ );
$this -> app -> Tpl -> Parse ( 'PAGE' , " ticket_list.tpl " );
}
2022-07-30 14:29:02 +02:00
function get_messages_of_ticket ( $ticket_id , $where , $limit ) {
2022-07-22 17:42:03 +02:00
2022-07-30 14:29:02 +02:00
if ( $limit ) {
$limitsql = " LIMIT " . (( int ) $limit );
} else {
$limitsql = " " ;
}
2022-07-22 17:42:03 +02:00
2022-08-17 15:07:13 +02:00
if ( empty ( $ticket_id )) {
$ticket_where = " " ;
} else {
$ticket_where = " AND t.id = " . $ticket_id ;
}
if ( empty ( $where )) {
$where = " 1 " ;
}
2022-08-01 22:55:52 +02:00
// $sql = "SELECT n.id, n.betreff, n.verfasser, n.mail, n.mail_cc, n.zeit, n.zeitausgang, n.versendet, n.text, n.verfasser_replyto, mail_replyto, (SELECT GROUP_CONCAT(value SEPARATOR ', ' FROM ticket_header th WHERE th.ticket_nachricht = n.id AND th.type = 'cc') value from) as cc FROM ticket_nachricht n INNER JOIN ticket t ON t.schluessel = n.ticket WHERE (".$where.") AND t.id = ".$ticket_id." ORDER BY n.zeit DESC ".$limitsql;
$sql = " SELECT n.id,
n . betreff ,
2022-08-15 18:52:36 +02:00
n . bearbeiter ,
2022-08-01 22:55:52 +02:00
n . verfasser ,
n . mail ,
2022-08-15 18:52:36 +02:00
t . quelle ,
2023-01-16 17:45:23 +01:00
" . $this->app ->erp->FormatDateTimeShort('n.zeit','zeit'). " ,
" . $this->app ->erp->FormatDateTimeShort('n.zeitausgang','zeitausgang'). " ,
2022-08-01 22:55:52 +02:00
n . versendet ,
n . text ,
2022-08-15 18:52:36 +02:00
n . textausgang ,
2022-08-01 22:55:52 +02:00
n . verfasser_replyto ,
n . mail_replyto ,
n . mail_cc ,
( SELECT GROUP_CONCAT ( value SEPARATOR ', ' ) FROM ticket_header th WHERE th . ticket_nachricht = n . id AND th . type = 'cc' ) as mail_cc_recipients ,
( SELECT GROUP_CONCAT ( value SEPARATOR ', ' ) FROM ticket_header th WHERE th . ticket_nachricht = n . id AND th . type = 'to' ) as mail_recipients
FROM ticket_nachricht n INNER JOIN ticket t ON t . schluessel = n . ticket
2022-08-17 15:07:13 +02:00
WHERE ( " . $where . " ) " . $ticket_where . " ORDER BY n . zeit DESC " . $limitsql ;
2022-08-01 22:55:52 +02:00
2022-07-30 14:29:02 +02:00
return $this -> app -> DB -> SelectArr ( $sql );
2022-07-27 18:05:24 +02:00
}
2022-07-30 10:49:47 +02:00
function add_attachments_html ( $ticket_id , $message_id , $templatepos , $showdelete ) {
$file_attachments = $this -> app -> erp -> GetDateiSubjektObjekt ( 'Anhang' , 'Ticket' , $message_id );
if ( ! empty ( $file_attachments )) {
$this -> app -> Tpl -> Add ( 'NACHRICHT_ANHANG' , " <hr style= \" border-style:solid; border-width:1px \" > " );
foreach ( $file_attachments as $file_attachment ) {
if ( $showdelete ) {
$deletetext = '<a href=index.php?module=ticket&action=edit&id=' . $ticket_id . '&cmd=deleteattachment' . '&fileid=' . $file_attachment . '>' .
2022-08-12 20:13:15 +02:00
'<img src="./themes/' . $this -> app -> Conf -> WFconf [ 'defaulttheme' ] . '/images/delete.svg" /></a>' ;
2022-07-30 10:49:47 +02:00
} else {
$deletetext = " " ;
2022-08-12 20:13:15 +02:00
}
$attachtext = " " ;
/* Not implemented -> Attachment of ticket_nachricht to business object is the better option -> implement later
$attachtext = '<a href=index.php?module=dateien&action=edit&id=' . $file_attachment . '>' .
'<img src="./themes/' . $this -> app -> Conf -> WFconf [ 'defaulttheme' ] . '/images/copy.svg" /></a>' ; */
2022-07-30 10:49:47 +02:00
$this -> app -> Tpl -> Add ( $templatepos ,
" <a href= \" index.php?module=dateien&action=send&id= " . $file_attachment .
" \" > " .
htmlentities ( $this -> app -> erp -> GetDateiName ( $file_attachment )) .
" ( " .
$this -> app -> erp -> GetDateiSize ( $file_attachment ) .
" ) " .
" </a> " .
$deletetext .
2022-08-12 20:13:15 +02:00
$attachtext .
" <br> " );
2022-07-30 10:49:47 +02:00
}
}
}
2022-07-30 14:29:02 +02:00
function add_messages_tpl ( $messages , $showdrafts ) {
// Add Messages now
foreach ( $messages as $message ) {
2022-08-15 18:52:36 +02:00
// Clear this first
$this -> app -> Tpl -> Set ( 'NACHRICHT_ANHANG' , " " );
// Xentral 20 compatibility
if ( $message [ 'textausgang' ] != '' ) {
// Sent message
2022-08-17 15:07:13 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_BETREFF " , '<a href="index.php?module=ticket&action=text_ausgang&mid=' . $message [ 'id' ] . '" target="_blank">' . htmlentities ( $message [ 'betreff' ]) . '</a>' );
2022-08-15 18:52:36 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_ZEIT " , $message [ 'zeitausgang' ]);
$this -> app -> Tpl -> Set ( " NACHRICHT_FLOAT " , " right " );
2022-12-20 09:37:27 +01:00
$this -> app -> Tpl -> Set ( " META_FLOAT " , " left " );
2022-08-15 18:52:36 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_TEXT " , $message [ 'textausgang' ]);
$this -> app -> Tpl -> Set ( " NACHRICHT_SENDER " , htmlentities ( $message [ 'bearbeiter' ]));
$this -> app -> Tpl -> Set ( " NACHRICHT_RECIPIENTS " , htmlentities ( $message [ 'verfasser' ] . " < " . $message [ 'mail' ] . " > " ));
2022-08-17 15:07:13 +02:00
// $this->app->Tpl->Set("NACHRICHT_TEXT",$message['textausgang']);
$this -> app -> Tpl -> Set ( " NACHRICHT_TEXT " , '<iframe class="ticket_text" src="index.php?module=ticket&action=text_ausgang&mid=' . $message [ 'id' ] . '"></iframe>' );
2022-08-15 18:52:36 +02:00
$this -> app -> Tpl -> Parse ( 'MESSAGES' , " ticket_nachricht.tpl " );
}
if ( $message [ 'versendet' ] == '1' && empty ( $message [ 'textausgang' ])) { // textausgang is always empty, except for old Xentral 20 tickets
// Sent message
2022-07-30 14:29:02 +02:00
if ( is_null ( $message [ 'zeitausgang' ])) {
if ( ! $showdrafts ) {
continue ;
}
2022-08-04 17:58:09 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_BETREFF " , htmlentities ( $message [ 'betreff' ] . " (Entwurf) " ));
2022-08-04 16:50:22 +02:00
} else {
2022-12-23 19:55:48 +01:00
$this -> app -> Tpl -> Set ( " NACHRICHT_BETREFF " , '<a href="index.php?module=ticket&action=text&mid=' . $message [ 'id' ] . '" target="_blank">' . htmlentities ( $message [ 'betreff' ]) . '</a>' );
2022-07-30 14:29:02 +02:00
}
2022-08-04 16:50:22 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_SENDER " , htmlentities ( $message [ 'verfasser' ] . " < " . $message [ 'mail_replyto' ] . " > " ));
$this -> app -> Tpl -> Set ( " NACHRICHT_RECIPIENTS " , htmlentities ( $message [ 'mail' ]));
$this -> app -> Tpl -> Set ( " NACHRICHT_CC_RECIPIENTS " , htmlentities ( $message [ 'mail_cc' ]));
2022-07-30 14:29:02 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_FLOAT " , " right " );
2022-12-20 09:37:27 +01:00
$this -> app -> Tpl -> Set ( " META_FLOAT " , " left " );
2022-07-30 14:29:02 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_ZEIT " , $message [ 'zeitausgang' ]);
2022-08-04 17:58:09 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_NAME " , htmlentities ( $message [ 'verfasser' ]));
2022-07-30 14:29:02 +02:00
} else {
2022-08-15 18:52:36 +02:00
// Received message
2022-08-04 17:58:09 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_SENDER " , htmlentities ( $message [ 'verfasser' ] . " < " . $message [ 'mail' ] . " > " ));
2022-08-15 18:52:36 +02:00
if ( $message [ 'mail_recipients' ] != '' ) {
$this -> app -> Tpl -> Set ( " NACHRICHT_RECIPIENTS " , htmlentities ( $message [ 'mail_recipients' ]));
}
else {
// Xentral 20 compatibility
$this -> app -> Tpl -> Set ( " NACHRICHT_RECIPIENTS " , htmlentities ( $message [ 'quelle' ]));
}
2022-08-04 17:58:09 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_CC_RECIPIENTS " , htmlentities ( $message [ 'mail_cc_recipients' ]));
2023-01-12 00:01:20 +01:00
$this -> app -> Tpl -> Set ( " NACHRICHT_BETREFF " , '<a href="index.php?module=ticket&action=text&mid=' . $message [ 'id' ] . '&insecure=1" target="_blank">' . htmlentities ( $message [ 'betreff' ]) . '</a>' );
2022-07-30 14:29:02 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_FLOAT " , " left " );
2022-12-20 09:37:27 +01:00
$this -> app -> Tpl -> Set ( " META_FLOAT " , " right " );
2022-07-30 14:29:02 +02:00
$this -> app -> Tpl -> Set ( " NACHRICHT_ZEIT " , $message [ 'zeit' ]);
}
2022-08-17 15:07:13 +02:00
// $this->app->Tpl->Set("NACHRICHT_TEXT",$message['text']);
$this -> app -> Tpl -> Set ( " NACHRICHT_TEXT " , '<iframe class="ticket_text" src="index.php?module=ticket&action=text&mid=' . $message [ 'id' ] . '"></iframe>' );
2022-07-30 14:29:02 +02:00
$this -> add_attachments_html ( $id , $message [ 'id' ], 'NACHRICHT_ANHANG' , false );
$this -> app -> Tpl -> Parse ( 'MESSAGES' , " ticket_nachricht.tpl " );
2022-08-15 18:52:36 +02:00
2022-07-30 14:29:02 +02:00
}
}
2023-01-12 00:01:20 +01:00
function ticket_text () {
$secure_html_tags = array (
'<br>' ,
'<p>' ,
'<strong>' ,
'<b>' ,
'<table>' ,
'<tr>' ,
'<td>' ,
'<style>'
);
2022-07-22 17:42:03 +02:00
2022-08-17 15:07:13 +02:00
$mid = $this -> app -> Secure -> GetGET ( 'mid' );
2023-01-12 00:01:20 +01:00
$insecure = $this -> app -> Secure -> GetGET ( 'insecure' );
2022-08-17 15:07:13 +02:00
if ( empty ( $mid )) {
return ;
}
$messages = $this -> get_messages_of_ticket ( " " , " n.id = " . $mid , NULL );
if ( empty ( $messages )) {
}
2023-01-12 00:01:20 +01:00
if ( $insecure ) {
$this -> app -> Tpl -> Set ( " TEXT " , $messages [ 0 ][ 'text' ]);
} else {
$secure_text = strip_tags ( $messages [ 0 ][ 'text' ], $secure_html_tags );
if ( strlen ( $secure_text ) != strlen ( $messages [ 0 ][ 'text' ])) {
// $secure_text = "<p style=\"all: initial;border-bottom-color:black;border-bottom-style:solid;border-bottom-width:1px;display:block;font-size:small;\">Einige Elemente wurden durch OpenXE blockiert.</p>".$secure_text;
$secure_text = " <img src= \" ./themes/ { $this -> app -> Conf -> WFconf [ 'defaulttheme' ] } /images/icon-invisible.svg \" alt= \" Einige Elemente wurden durch OpenXE blockiert. \" title= \" Einige Elemente wurden durch OpenXE blockiert. \" border= \" 0 \" style= \" all: initial;display:block;float:right;font-size:small; \" > " . $secure_text ;
}
$this -> app -> Tpl -> Set ( " TEXT " , $secure_text );
}
2022-08-17 15:07:13 +02:00
$this -> app -> Tpl -> Output ( 'ticket_text.tpl' );
$this -> app -> ExitXentral ();
}
function ticket_text_ausgang () {
$mid = $this -> app -> Secure -> GetGET ( 'mid' );
if ( empty ( $mid )) {
return ;
}
$messages = $this -> get_messages_of_ticket ( " " , " n.id = " . $mid , NULL );
if ( empty ( $messages )) {
}
$this -> app -> Tpl -> Set ( " TEXT " , $messages [ 0 ][ 'textausgang' ]);
$this -> app -> Tpl -> Output ( 'ticket_text.tpl' );
$this -> app -> ExitXentral ();
}
2022-07-29 14:45:16 +02:00
/**
* @ throws NumberGeneratorException
*
* @ return string
*/
private function generateRandomTicketNumber () : string
{
$random = rand ( 300 , 700 );
$loopCounter = 0 ;
while ( true ) {
$candidate = sprintf ( '%s%04d' , date ( 'Ymd' ), $random ++ );
if ( ! $this -> app -> DB -> Select ( 'SELECT id FROM ticket WHERE schluessel = ' . $candidate )) {
return ( $candidate );
}
if ( $loopCounter > 99 ) {
throw new NumberGeneratorException ( 'ticket number generation failed' );
}
$loopCounter ++ ;
}
}
function ticket_save_to_db ( $id , $input ) {
// Write to database
// Add checks here
2022-07-22 17:42:03 +02:00
if ( empty ( $id )) {
// New item
$id = 'NULL' ;
}
2022-07-31 18:23:43 +02:00
if ( $input [ 'betreff' ] == '' ) {
$input [ 'betreff' ] = " ... " ;
}
2022-07-29 14:45:16 +02:00
$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
2022-07-31 18:23:43 +02:00
$input [ 'zeit' ] = date ( 'Y-m-d H:i:s' , time ());
2022-07-22 17:42:03 +02:00
2022-07-29 14:45:16 +02:00
$columns = " id, " ;
$values = " $id , " ;
$update = " " ;
2022-07-22 17:42:03 +02:00
2022-07-29 14:45:16 +02:00
$fix = " " ;
2022-07-24 21:10:33 +02:00
2022-07-29 14:45:16 +02:00
foreach ( $input as $key => $value ) {
2022-07-22 17:42:03 +02:00
2022-07-29 14:45:16 +02:00
if ( $this -> app -> DB -> ColumnExists ( 'ticket' , $key )) {
$columns = $columns . $fix . $key ;
$values = $values . $fix . " ' " . $value . " ' " ;
$update = $update . $fix . $key . " = ' $value ' " ;
$fix = " , " ;
}
}
2022-07-26 17:36:24 +02:00
2022-07-29 14:45:16 +02:00
$sql = " INSERT INTO ticket ( " . $columns . " ) VALUES ( " . $values . " ) ON DUPLICATE KEY UPDATE " . $update ;
$this -> app -> DB -> Update ( $sql );
$id = $this -> app -> DB -> GetInsertID ();
return ( $id );
}
2022-07-22 17:42:03 +02:00
2022-07-29 14:45:16 +02:00
function save_draft ( $id , $input ) {
$columns = " id, " ;
$values = " $id , " ;
$update = " " ;
2022-07-22 17:42:03 +02:00
2022-07-29 14:45:16 +02:00
$fix = " " ;
// Translate form to table
$input [ 'betreff' ] = $input [ 'email_betreff' ];
$input [ 'mail' ] = $input [ 'email_an' ];
$input [ 'mail_cc' ] = $input [ 'email_cc' ];
$input [ 'text' ] = $input [ 'email_text' ];
foreach ( $input as $key => $value ) {
if ( $this -> app -> DB -> ColumnExists ( 'ticket_nachricht' , $key )) {
$columns = $columns . $fix . $key ;
$values = $values . $fix . " ' " . $value . " ' " ;
$update = $update . $fix . $key . " = ' $value ' " ;
$fix = " , " ;
}
}
$sql = " INSERT INTO ticket_nachricht ( " . $columns . " ) VALUES ( " . $values . " ) ON DUPLICATE KEY UPDATE " . $update ;
$this -> app -> DB -> Update ( $sql );
}
function ticket_create () {
$submit = $this -> app -> Secure -> GetPOST ( 'submit' );
$input = $this -> GetInput ();
2022-08-03 17:43:45 +02:00
$projekt_id = $this -> app -> User -> DefaultProjekt ();
$projekt = $this -> app -> DB -> Select ( " SELECT abkuerzung FROM projekt WHERE id = " . $projekt_id );
2022-07-29 14:45:16 +02:00
if ( $submit != '' ) {
$input [ 'schluessel' ] = $this -> generateRandomTicketNumber ();
$input [ 'kunde' ] = $this -> app -> User -> GetName ();
2022-07-31 18:23:43 +02:00
2022-07-29 14:45:16 +02:00
$id = $this -> ticket_save_to_db ( $id , $input );
header ( " Location: index.php?module=ticket&action=edit&id= $id " );
exit ();
}
2022-08-03 17:43:45 +02:00
$this -> app -> Tpl -> Set ( 'PROJEKT' , $projekt );
2022-07-29 14:45:16 +02:00
$this -> app -> Tpl -> Set ( 'STATUSICON' , $this -> ticket_status_icon ( 'neu' ) . " " );
$this -> app -> YUI -> AutoComplete ( " adresse " , " adresse " );
$this -> app -> YUI -> AutoComplete ( " projekt " , " projektname " , 1 );
$this -> app -> YUI -> AutoComplete ( " status " , " ticketstatus " , 1 );
$this -> app -> Tpl -> Set ( 'STATUS' , $this -> app -> erp -> GetStatusTicketSelect ( 'neu' ));
$this -> app -> YUI -> AutoComplete ( " warteschlange " , " warteschlangename " );
$this -> app -> Tpl -> Parse ( 'PAGE' , " ticket_create.tpl " );
}
function ticket_edit () {
$id = $this -> app -> Secure -> GetGET ( 'id' );
2022-07-30 10:49:47 +02:00
if ( empty ( $id )) {
return ;
}
2022-07-29 14:45:16 +02:00
$this -> app -> Tpl -> Set ( 'ID' , $id );
$this -> app -> erp -> MenuEintrag ( " index.php?module=ticket&action=edit&id= $id " , " Details " );
$this -> app -> erp -> MenuEintrag ( " index.php?module=ticket&action=list " , " Zurück zur Übersicht " );
$id = $this -> app -> Secure -> GetGET ( 'id' );
2022-07-30 10:49:47 +02:00
$cmd = $this -> app -> Secure -> GetGET ( 'cmd' );
2022-07-29 14:45:16 +02:00
$input = $this -> GetInput ();
$submit = $this -> app -> Secure -> GetPOST ( 'submit' );
$msg = $this -> app -> erp -> base64_url_decode ( $this -> app -> Secure -> GetGET ( 'msg' ));
2022-07-31 18:23:43 +02:00
if ( $input [ 'neue_notiz' ] != '' ) {
$input [ 'notiz' ] = $this -> app -> User -> GetName () . " " . date ( " d.m.Y H:i " ) . " : " . $input [ 'neue_notiz' ] . " \r \n " . $input [ 'notiz' ];
}
2022-07-29 14:45:16 +02:00
// Always save
if ( $submit != '' )
{
$this -> ticket_save_to_db ( $id , $input );
$msg = " <div class= \" success \" >Die Einstellungen wurden erfolgreich übernommen.</div> " ;
2022-07-22 17:42:03 +02:00
}
// Load values again from database
2023-01-16 17:45:23 +01:00
2023-01-17 10:31:10 +01:00
$sql = " SELECT t.id, t.schluessel, " . $this -> app -> erp -> FormatDateTimeShort ( " zeit " , 'zeit' ) . " , p.abkuerzung as projekt, t.bearbeiter, t.quelle, t.status, t.prio, t.adresse, t.kunde, CONCAT(w.label,' ',w.warteschlange) as warteschlange, t.mailadresse, 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 " ;
2023-01-16 17:45:23 +01:00
$ticket_from_db = $this -> app -> DB -> SelectArr ( $sql )[ 0 ];
2022-07-22 17:42:03 +02:00
2022-08-05 17:19:01 +02:00
foreach ( $ticket_from_db as $key => $value ) {
2022-07-22 17:42:03 +02:00
$this -> app -> Tpl -> Set ( strtoupper ( $key ), $value );
}
2022-07-26 17:36:24 +02:00
2022-08-05 17:19:01 +02:00
$this -> app -> Tpl -> Set ( 'PRIO' , $ticket_from_db [ 'prio' ] == 1 ? " checked " : " " );
$this -> app -> Tpl -> Set ( 'STATUSICON' , $this -> ticket_status_icon ( $ticket_from_db [ 'status' ]) . " " );
2022-07-24 21:10:33 +02:00
$this -> app -> YUI -> AutoComplete ( " adresse " , " adresse " );
2022-08-05 17:19:01 +02:00
$this -> app -> Tpl -> Set ( 'ADRESSE' , $this -> app -> erp -> ReplaceAdresse ( false , $ticket_from_db [ 'adresse' ], false )); // Convert ID to form display
2022-08-06 11:31:43 +02:00
2022-12-23 19:55:48 +01:00
if ( $ticket_from_db [ 'mailadresse' ] != " " ) {
$this -> app -> Tpl -> Set ( 'MAILADRESSE' , " < " . $ticket_from_db [ 'mailadresse' ] . " > " );
}
2022-08-06 11:31:43 +02:00
$this -> app -> Tpl -> Set ( 'ADRESSE_ID' , $ticket_from_db [ 'adresse' ]);
2022-07-24 21:10:33 +02:00
$this -> app -> YUI -> AutoComplete ( " projekt " , " projektname " , 1 );
2022-07-26 17:36:24 +02:00
$this -> app -> YUI -> AutoComplete ( " status " , " ticketstatus " , 1 );
2022-07-31 21:45:38 +02:00
$this -> app -> YUI -> TagEditor ( 'tags' , array ( 'width' => 370 ));
2022-07-26 17:36:24 +02:00
2022-08-05 17:19:01 +02:00
$this -> app -> Tpl -> Set ( 'STATUS' , $this -> app -> erp -> GetStatusTicketSelect ( $ticket_from_db [ 'status' ]));
2022-07-24 21:10:33 +02:00
$input [ 'projekt' ] = $this -> app -> erp -> ReplaceProjekt ( false , $input [ 'projekt' ], false ); // Parameters: Target db?, value, from form?
$this -> app -> YUI -> AutoComplete ( " warteschlange " , " warteschlangename " );
2022-07-29 14:45:16 +02:00
// END Header
// Check for draft
2022-07-30 14:29:02 +02:00
$drafted_messages = $this -> get_messages_of_ticket ( $id , " zeitausgang IS NULL AND versendet = '1' " , NULL );
2022-07-29 14:45:16 +02:00
if ( ! empty ( $drafted_messages )) {
// Draft from form?
if ( $submit != '' ) {
$this -> save_draft ( $drafted_messages [ 0 ][ 'id' ], $input );
// Reload
2022-07-30 14:29:02 +02:00
$drafted_messages = $this -> get_messages_of_ticket ( $id , " zeitausgang IS NULL AND versendet = '1' " , NULL );
2022-07-29 14:45:16 +02:00
}
// Load the draft for editing
2022-08-04 17:58:09 +02:00
$this -> app -> Tpl -> Set ( 'EMAIL_AN' , htmlentities ( $drafted_messages [ 0 ][ 'mail' ]));
$this -> app -> Tpl -> Set ( 'EMAIL_CC' , htmlentities ( $drafted_messages [ 0 ][ 'mail_cc' ]));
$this -> app -> Tpl -> Set ( 'EMAIL_BCC' , htmlentities ( $drafted_messages [ 0 ][ 'mail_bcc' ]));
$this -> app -> Tpl -> Set ( 'EMAIL_BETREFF' , htmlentities ( $drafted_messages [ 0 ][ 'betreff' ]));
2022-08-05 21:16:58 +02:00
$this -> app -> Tpl -> Set ( 'EMAIL_TEXT' , htmlentities ( $drafted_messages [ 0 ][ 'text' ]));
2022-07-29 14:45:16 +02:00
// Show new message dialog
$this -> app -> Tpl -> Set ( 'EMAIL_SENDER' , $this -> app -> erp -> GetSelectEmailMitName ( $dokument [ 'von' ]));
$this -> app -> YUI -> AutoComplete ( " email_an " , " emailname " );
$this -> app -> YUI -> AutoComplete ( " email_cc " , " emailname " );
$this -> app -> YUI -> AutoComplete ( " email_bcc " , " emailname " );
$this -> app -> YUI -> CkEditor ( " email_text " , " internal " , null , 'JQUERY' );
2022-07-30 10:49:47 +02:00
// Delete attachment from draft
if ( $cmd == 'deleteattachment' ) {
$fileid = $this -> app -> Secure -> GetGET ( 'fileid' );
// Check if this file is only attached to this draft and nowhere else
$check = $this -> app -> erp -> GetDateiStichwoerter ( $fileid );
$save_to_delete = true ;
foreach ( $check as $stichwort ) {
if ( $stichwort [ 'subjekt' ] != 'anhang' || $stichwort [ 'objekt' ] != 'Ticket' || $stichwort [ 'parameter' ] != $drafted_messages [ 0 ][ 'id' ]) {
$save_to_delete = false ;
break ;
}
}
if ( $save_to_delete ) {
$this -> app -> erp -> DeleteDatei ( $fileid );
} else {
$msg .= " <div class= \" success \" >Fehler beim Löschen der Datei: In Verwendung.</div> " ;
}
}
// Upload of attachments
if ( isset ( $_FILES [ 'upload' ]) && is_array ( $_FILES [ 'upload' ]))
{
foreach ( $_FILES [ 'upload' ][ 'tmp_name' ] as $key => $file )
{
if ( $file != " " )
{
$fileid = $this -> app -> erp -> CreateDatei ( $_FILES [ 'upload' ][ 'name' ][ $key ], $_FILES [ 'upload' ][ 'name' ][ $key ], " " , " " , $_FILES [ 'upload' ][ 'tmp_name' ][ $key ], $this -> app -> User -> GetName ());
// stichwoerter hinzufuegen
$this -> app -> erp -> AddDateiStichwort ( $fileid , " anhang " , " Ticket " , $drafted_messages [ 0 ][ 'id' ]);
}
}
}
$this -> add_attachments_html ( $id , $drafted_messages [ 0 ][ 'id' ], 'ANHAENGE' , true );
2022-07-29 14:45:16 +02:00
$this -> app -> Tpl -> Parse ( 'NEW_MESSAGE' , " ticket_new_message.tpl " );
}
2022-07-30 10:49:47 +02:00
// END Draft
2022-07-24 21:10:33 +02:00
2022-07-29 14:45:16 +02:00
// Get all messsages
2022-07-30 14:29:02 +02:00
$messages = $this -> get_messages_of_ticket ( $id , 1 , NULL );
2022-08-01 22:55:52 +02:00
$recv_messages = $this -> get_messages_of_ticket ( $id , " n.versendet != 1 " , NULL );
2022-07-24 21:10:33 +02:00
2022-07-26 17:36:24 +02:00
switch ( $submit ) {
case 'neue_email' :
2023-01-16 18:37:32 +01:00
$senderName = $this -> app -> User -> GetName () . " ( " . $this -> app -> erp -> GetFirmaAbsender () . " ) " ;
$senderAddress = $this -> app -> erp -> GetFirmaMail ();
2022-07-29 14:45:16 +02:00
if ( empty ( $drafted_messages )) {
// Create new message and save it for editing
2022-07-26 17:36:24 +02:00
2022-08-04 17:58:09 +02:00
$this -> app -> Tpl -> Set ( 'EMAIL_AN' , htmlentities ( $recv_messages [ 0 ][ 'mail' ]));
2022-08-01 22:55:52 +02:00
2022-08-05 17:19:01 +02:00
$to = " " ;
2022-08-01 22:55:52 +02:00
$cc = " " ;
2022-07-30 10:49:47 +02:00
if ( ! empty ( $recv_messages )) {
if ( ! str_starts_with ( strtoupper ( $recv_messages [ 0 ][ 'betreff' ]), " RE: " )) {
$betreff = " RE: " . $recv_messages [ 0 ][ 'betreff' ];
}
else {
$betreff = $recv_messages [ 0 ][ 'betreff' ];
}
2022-08-01 22:55:52 +02:00
$sql = " SELECT GROUP_CONCAT(DISTINCT `value` ORDER BY `value` SEPARATOR ', ') FROM ticket_header th WHERE th.ticket_nachricht = " . $recv_messages [ 0 ][ 'id' ] . " AND `value` <> ' " . $senderAddress . " ' AND type='to' " ;
2022-08-03 10:30:05 +02:00
2022-08-05 17:19:01 +02:00
$to = $recv_messages [ 0 ][ 'mail' ];
2022-08-03 10:30:05 +02:00
$to_additional = $this -> app -> DB -> Select ( $sql );
if ( ! empty ( $to_additional )) {
$to .= " , " . $to_additional ;
}
2022-08-01 22:55:52 +02:00
$sql = " SELECT GROUP_CONCAT(DISTINCT `value` ORDER BY `value` SEPARATOR ', ') FROM ticket_header th WHERE th.ticket_nachricht = " . $recv_messages [ 0 ][ 'id' ] . " AND `value` <> ' " . $senderAddress . " ' AND type='cc' " ;
$cc = $this -> app -> DB -> Select ( $sql );
2022-07-30 10:49:47 +02:00
}
else {
2022-08-05 17:19:01 +02:00
$betreff = $ticket_from_db [ 'betreff' ];
$sql = " SELECT email FROM adresse WHERE id = " . $ticket_from_db [ 'adresse' ];
$to = $this -> app -> DB -> Select ( $sql );
2022-07-29 14:45:16 +02:00
}
2022-07-27 21:26:59 +02:00
2022-08-05 17:19:01 +02:00
$anschreiben = $this -> app -> DB -> Select ( " SELECT anschreiben FROM adresse WHERE id=' " . $ticket_from_db [ 'adresse' ] . " ' LIMIT 1 " );
2022-07-29 14:45:16 +02:00
if ( $anschreiben == " " )
{
2023-01-03 12:33:18 +01:00
$anschreiben = $this -> app -> erp -> Beschriftung ( " dokument_anschreiben " );
2022-07-29 14:45:16 +02:00
}
2022-07-26 17:36:24 +02:00
2023-01-03 12:33:18 +01:00
$anschreiben = $anschreiben . " ,<br> " . $this -> app -> erp -> Grussformel ( $projekt , $sprache );
2022-07-29 14:45:16 +02:00
$sql = " INSERT INTO `ticket_nachricht` (
`ticket` , `zeit` , `text` , `betreff` , `medium` , `versendet` ,
2022-08-01 22:55:52 +02:00
`verfasser` , `mail` , `status` , `verfasser_replyto` , `mail_replyto` , `mail_cc`
2022-08-05 17:19:01 +02:00
) VALUES ( '".$ticket_from_db[' schluessel ']."' , NOW (), '".$anschreiben."' , '".$betreff."' , 'email' , '1' , '".$senderName."' , '".$to."' , 'neu' , '".$senderName."' , '".$senderAddress."' , '".$cc."' ); " ;
2022-07-26 17:36:24 +02:00
2022-07-29 14:45:16 +02:00
$this -> app -> DB -> Insert ( $sql );
2022-07-30 10:49:47 +02:00
// Show new message dialog
header ( " Location: index.php?module=ticket&action=edit&id= $id " );
$this -> app -> ExitXentral ();
2022-07-29 14:45:16 +02:00
}
2022-08-01 22:55:52 +02:00
break ;
2022-07-29 14:45:16 +02:00
case 'entwurfloeschen' :
if ( ! empty ( $drafted_messages )) {
$sql = " UPDATE ticket_nachricht SET ticket = '' WHERE id= " . $drafted_messages [ 0 ][ 'id' ];
2022-07-30 10:49:47 +02:00
$this -> app -> DB -> Update ( $sql );
$msg = $this -> app -> erp -> base64_url_encode ( " <div class= \" success \" >Der Entwurf wurde gelöscht.</div> " );
2022-07-29 14:45:16 +02:00
header ( " Location: index.php?module=ticket&action=edit&msg= $msg &id= $id " );
2022-07-30 10:49:47 +02:00
$this -> app -> ExitXentral ();
2022-07-29 14:45:16 +02:00
}
break ;
2022-08-01 22:55:52 +02:00
case 'zitat' :
if ( ! empty ( $drafted_messages ) && ! empty ( $recv_messages )) {
2022-08-06 10:40:58 +02:00
$nl = " <br /> " ;
$citation_info = $recv_messages [ 0 ][ 'zeit' ] . " " . $recv_messages [ 0 ][ 'verfasser' ] . " < " . $recv_messages [ 0 ][ 'mail' ] . " > " ;
$text = $drafted_messages [ 0 ][ 'text' ] . $nl . $nl . $citation_info . " : " . $nl . " <blockquote type= \" cite \" > " . $recv_messages [ 0 ][ 'text' ] . " </blockquote> " ;
2023-01-09 11:16:39 +01:00
$sql = " UPDATE ticket_nachricht SET text=' " . $this -> app -> DB -> real_escape_string ( $text ) . " ' WHERE id= " . $drafted_messages [ 0 ][ 'id' ];
2022-08-01 22:55:52 +02:00
$this -> app -> DB -> Update ( $sql );
header ( " Location: index.php?module=ticket&action=edit&id= $id " );
$this -> app -> ExitXentral ();
}
break ;
2022-07-29 14:45:16 +02:00
case 'absenden' :
if ( empty ( $drafted_messages )) {
break ;
}
2022-07-26 17:36:24 +02:00
2022-08-01 22:55:52 +02:00
$msg = " " ;
2022-07-26 17:36:24 +02:00
// Enforce Ticket #
2022-07-29 14:45:16 +02:00
if ( ! preg_match ( " /Ticket #[0-9] { 12}/i " , $drafted_messages [ 0 ][ 'betreff' ])) {
2022-08-05 17:19:01 +02:00
$drafted_messages [ 0 ][ 'betreff' ] .= " Ticket # " . $ticket_from_db [ 'schluessel' ];
2022-07-26 17:36:24 +02:00
}
2022-07-30 10:49:47 +02:00
// Attachments
$files = $this -> app -> erp -> GetDateiSubjektObjektDateiname ( 'Anhang' , 'Ticket' , $drafted_messages [ 0 ][ 'id' ], " " );
2022-07-26 17:36:24 +02:00
2022-08-04 16:50:22 +02:00
$pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i' ;
preg_match_all ( $pattern , $drafted_messages [ 0 ][ 'mail' ], $matches );
$to = $matches [ 0 ];
2022-08-03 10:30:05 +02:00
if ( $drafted_messages [ 0 ][ 'mail_cc' ] != '' ) {
2022-08-04 16:50:22 +02:00
$pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i' ;
preg_match_all ( $pattern , $drafted_messages [ 0 ][ 'mail_cc' ], $matches );
$cc = $matches [ 0 ];
2022-08-03 10:30:05 +02:00
} else {
$cc = null ;
2022-07-30 10:49:47 +02:00
}
2022-08-01 22:55:52 +02:00
2023-01-12 17:58:54 +01:00
$senderName = $this -> app -> User -> GetName () . " ( " . $this -> app -> erp -> GetFirmaAbsender () . " ) " ;
$senderAddress = $this -> app -> erp -> GetFirmaMail ();
2022-08-05 19:02:50 +02:00
// function MailSend($from,$from_name,$to,$to_name,$betreff,$text,$files="",$projekt="",$signature=true,$cc="",$bcc="", $system = false)
2022-07-26 17:36:24 +02:00
if (
$this -> app -> erp -> MailSend (
2023-01-12 17:58:54 +01:00
$senderAddress ,
$senderName ,
2022-08-04 16:50:22 +02:00
$to ,
$to ,
2022-08-06 10:40:58 +02:00
htmlentities ( $drafted_messages [ 0 ][ 'betreff' ]),
htmlentities ( $drafted_messages [ 0 ][ 'text' ]),
2022-07-30 10:49:47 +02:00
$files ,
2022-08-05 19:02:50 +02:00
0 ,
true ,
2022-08-01 22:55:52 +02:00
$cc ,
'' ,
2022-07-26 17:36:24 +02:00
true
) != 0
) {
2022-07-29 14:45:16 +02:00
// Update message in ticket_nachricht
2023-01-12 17:58:54 +01:00
$sql = " UPDATE `ticket_nachricht` SET `zeitausgang` = NOW(), `betreff` = ' " . $drafted_messages [ 0 ][ 'betreff' ] . " ', `verfasser` = ' $senderName ', `verfasser_replyto` = ' $senderName ', `mail_replyto` = ' $senderAddress ' WHERE id = " . $drafted_messages [ 0 ][ 'id' ];
2022-07-26 17:36:24 +02:00
$this -> app -> DB -> Insert ( $sql );
2022-08-01 22:55:52 +02:00
$msg .= '<div class="info">Die E-Mail wurde erfolgreich versendet an ' . $input [ 'email_an' ] . '.' ;
if ( $drafted_messages [ 0 ][ 'mail_cc' ] != '' ) {
$msg .= ' (CC: ' . $drafted_messages [ 0 ][ 'mail_cc' ] . ')</div>' ;
}
else {
$msg .= '</div>' ;
}
2022-07-27 18:05:24 +02:00
header ( " Location: index.php?module=ticket&action=edit&id= " . $id . " &msg= " . $this -> app -> erp -> base64_url_encode ( $msg ));
2022-07-26 17:36:24 +02:00
}
else {
$msg = '<div class="error">Fehler beim Versenden der E-Mail: ' . $this -> app -> erp -> mail_error . '</div>' ;
}
// Get messsages again
2022-07-31 18:23:43 +02:00
$messages = $this -> get_messages_of_ticket ( $id , 1 , NULL );
2022-07-26 17:36:24 +02:00
break ;
2022-07-29 14:45:16 +02:00
}
2022-07-26 17:36:24 +02:00
2022-07-30 14:29:02 +02:00
$this -> add_messages_tpl ( $messages , false );
2022-07-24 21:10:33 +02:00
2022-07-26 17:36:24 +02:00
$this -> app -> Tpl -> Set ( 'MESSAGE' , $msg );
2022-07-22 17:42:03 +02:00
$this -> app -> Tpl -> Parse ( 'PAGE' , " ticket_edit.tpl " );
}
2022-08-18 20:45:09 +02:00
/**
* Get all paramters from html form and save into $input
*/
public function GetInput () : array {
$input = array ();
//$input['EMAIL'] = $this->app->Secure->GetPOST('email');
$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' ] = ! empty ( $this -> app -> Secure -> GetPOST ( 'prio' )) ? " 1 " : " 0 " ;
$input [ 'neue_notiz' ] = $this -> app -> Secure -> GetPOST ( 'neue_notiz' );
$input [ 'notiz' ] = $this -> app -> Secure -> GetPOST ( 'notiz' );
$input [ 'tags' ] = $this -> app -> Secure -> GetPOST ( 'tags' );
$input [ 'betreff' ] = $this -> app -> Secure -> GetPOST ( 'betreff' );
$input [ 'email_sender' ] = $this -> app -> Secure -> GetPOST ( 'email_sender' );
$input [ 'email_an' ] = $this -> app -> Secure -> GetPOST ( 'email_an' );
$input [ 'email_cc' ] = $this -> app -> Secure -> GetPOST ( 'email_cc' );
$input [ 'email_bcc' ] = $this -> app -> Secure -> GetPOST ( 'email_bcc' );
$input [ 'email_betreff' ] = $this -> app -> Secure -> GetPOST ( 'email_betreff' );
$input [ 'email_text' ] = $this -> app -> Secure -> GetPOST ( 'email_text' );
return $input ;
}
public function ticket_minidetail ( $parsetarget = '' , $menu = true ) {
$id = $this -> app -> Secure -> GetGET ( 'id' );
// Get last 3 messages
$messages = $this -> get_messages_of_ticket ( $id , " 1 " , 3 );
if ( ! empty ( $messages )) {
$this -> add_messages_tpl ( $messages , true ); // With drafts
$render = true ;
} else {
}
if ( $parsetarget == '' )
{
2022-07-30 14:29:02 +02:00
if ( $render ) {
2022-08-18 20:45:09 +02:00
$this -> app -> Tpl -> Output ( 'ticket_minidetail.tpl' );
2022-07-30 14:29:02 +02:00
}
2022-08-18 20:45:09 +02:00
$this -> app -> ExitXentral ();
}
if ( $render ) {
$this -> app -> Tpl -> Parse ( $parsetarget , 'ticket_minidetail.tpl' );
}
}
/*
* After import of Xentral 20 ticket system
* Set all ticket status to the status of the latest ticket_nachricht
*/
function ticket_statusfix () {
$confirmed = $this -> app -> Secure -> GetGET ( 'confirmed' );
if ( $confirmed == " yes " ) {
$sql = " UPDATE
ticket
SET
STATUS
= ifnull ((
SELECT
tn . status
FROM
ticket_nachricht tn
INNER JOIN (
SELECT
ticket ,
MAX ( zeit ) AS lastzeit
FROM
ticket_nachricht
GROUP BY
ticket
) l
ON
tn . ticket = l . ticket AND tn . zeit = l . lastzeit
WHERE
ticket . schluessel = tn . ticket
LIMIT 1
), 'abgeschlossen' )
WHERE ticket . status = 'neu' " ;
$this -> app -> DB -> Update ( $sql );
2022-08-19 14:24:13 +02:00
$this -> app -> Tpl -> Set ( 'TEXT' , " Status fix abgeschlossen. " );
2022-08-18 20:45:09 +02:00
$this -> app -> Tpl -> Parse ( 'PAGE' , 'ticket_text.tpl' );
}
else {
2022-08-19 14:24:13 +02:00
// $this->app->Tpl->Set('TEXT', "This will replace all ticket status with the status of the latest ticket_nachricht. To confirm, press here: ");
$this -> app -> Tpl -> Set ( 'TEXT' , " Dieser Assistent ersetzt den Status aller offenen Tickets (Weder abgeschlossen noch Spam) mit dem Status der letzten Nachricht im Ticket. Hier starten: " );
$this -> app -> Tpl -> Add ( 'TEXT' , '<a href="index.php?module=ticket&action=statusfix&confirmed=yes"><button>OK</button></a>' );
2022-08-18 20:45:09 +02:00
$this -> app -> Tpl -> Parse ( 'PAGE' , 'ticket_text.tpl' );
2022-07-30 14:29:02 +02:00
}
2022-08-18 20:45:09 +02:00
}
2022-08-18 21:36:42 +02:00
/*
* After import of Xentral 20 ticket system
* Set all ticket dates to the date of the latest ticket_nachricht
*/
function ticket_datefix () {
$confirmed = $this -> app -> Secure -> GetGET ( 'confirmed' );
if ( $confirmed == " yes " ) {
$sql = " UPDATE ticket set zeit =
( SELECT
MAX ( zeit ) AS lastzeit
FROM
ticket_nachricht
WHERE ticket . schluessel = ticket_nachricht . ticket AND ticket . schluessel
LIMIT 1
)
WHERE ticket . status <> 'abgeschlossen' AND ticket . status <> 'spam' " ;
$this -> app -> DB -> Update ( $sql );
2022-08-19 14:24:13 +02:00
$this -> app -> Tpl -> Set ( 'TEXT' , " Datum fix abgeschlossen. " );
2022-08-18 21:36:42 +02:00
$this -> app -> Tpl -> Parse ( 'PAGE' , 'ticket_text.tpl' );
}
else {
2022-08-19 14:24:13 +02:00
// $this->app->Tpl->Set('TEXT', "This will replace all open ticket dates with the date of the latest ticket_nachricht. To confirm, press here: ");
$this -> app -> Tpl -> Set ( 'TEXT' , " Dieser Assistent ersetzt das Datum aller offenen Tickets (Weder abgeschlossen noch Spam) mit dem Datum der letzten Nachricht im Ticket. Hier starten: " );
$this -> app -> Tpl -> Add ( 'TEXT' , '<a href="index.php?module=ticket&action=datefix&confirmed=yes"><button>OK</button></a>' );
2022-08-18 21:36:42 +02:00
$this -> app -> Tpl -> Parse ( 'PAGE' , 'ticket_text.tpl' );
}
}
2022-07-22 17:42:03 +02:00
}
2022-07-30 14:29:02 +02:00