2018-03-10 04:23:59 +01:00
< ? php
2019-02-26 22:56:50 +01:00
/* Copyright ( C ) 2013 - 2015 Jean - François FERRY < hello @ librethic . io >
* Copyright ( C ) 2016 Christophe Battarel < christophe @ altairis . fr >
* Copyright ( C ) 2019 Frédéric France < frederic . france @ netlogic . fr >
2018-03-10 04:23:59 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-03-10 04:23:59 +01:00
*/
/**
2019-12-11 22:53:57 +01:00
* \file htdocs / core / class / html . formticket . class . php
2018-06-04 21:49:29 +02:00
* \ingroup ticket
2018-03-10 04:23:59 +01:00
* \brief Fichier de la classe permettant la generation du formulaire html d ' envoi de mail unitaire
*/
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . " /core/class/html.form.class.php " ;
require_once DOL_DOCUMENT_ROOT . " /core/class/html.formmail.class.php " ;
require_once DOL_DOCUMENT_ROOT . " /core/class/html.formprojet.class.php " ;
2018-03-10 04:23:59 +01:00
if ( ! class_exists ( 'FormCompany' )) {
2019-11-13 19:35:39 +01:00
include DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php' ;
2018-03-10 04:23:59 +01:00
}
/**
2018-03-11 11:33:24 +01:00
* Classe permettant la generation du formulaire d ' un nouveau ticket .
2018-03-10 04:23:59 +01:00
*
2018-06-04 21:49:29 +02:00
* @ package Ticket
2018-03-11 11:54:30 +01:00
2018-06-04 21:49:29 +02:00
* \remarks Utilisation : $formticket = new FormTicket ( $db )
* \remarks $formticket -> proprietes = 1 ou chaine ou tableau de valeurs
* \remarks $formticket -> show_form () affiche le formulaire
2018-03-10 04:23:59 +01:00
*/
2018-06-04 21:49:29 +02:00
class FormTicket
2018-03-10 04:23:59 +01:00
{
2018-08-23 11:11:46 +02:00
/**
* @ var DoliDB Database handler .
*/
2018-03-10 04:23:59 +01:00
public $db ;
public $track_id ;
2018-10-10 09:16:01 +02:00
/**
* @ var int ID
*/
2018-03-10 04:23:59 +01:00
public $fk_user_create ;
public $message ;
public $topic_title ;
public $action ;
public $withtopic ;
public $withemail ;
/**
*
* @ var int $withsubstit Show substitution array
*/
public $withsubstit ;
public $withfile ;
2019-10-16 22:56:29 +02:00
public $withfilereadonly ;
2018-03-10 04:23:59 +01:00
public $ispublic ; // To show information or not into public form
public $withtitletopic ;
public $withcompany ; // affiche liste déroulante company
public $withfromsocid ;
public $withfromcontactid ;
2019-10-16 23:18:14 +02:00
public $withnotifytiersatcreate ;
2018-03-10 04:23:59 +01:00
public $withusercreate ; // Show name of creating user in form
public $withcreatereadonly ;
public $withref ; // Show ref field
public $withcancel ;
/**
2018-03-11 11:54:30 +01:00
*
2018-03-10 04:23:59 +01:00
* @ var array $substit Substitutions
*/
public $substit = array ();
public $param = array ();
2018-08-23 11:34:55 +02:00
/**
* @ var string Error code ( or message )
*/
public $error ;
2018-03-10 04:23:59 +01:00
/**
* Constructor
*
2018-03-11 11:33:24 +01:00
* @ param DoliDB $db Database handler
2018-03-10 04:23:59 +01:00
*/
public function __construct ( $db )
{
$this -> db = $db ;
2019-03-05 12:18:36 +01:00
$this -> action = 'add' ;
2018-03-10 04:23:59 +01:00
$this -> withcompany = 1 ;
$this -> withfromsocid = 0 ;
$this -> withfromcontactid = 0 ;
//$this->withthreadid=0;
//$this->withtitletopic='';
2019-10-16 23:18:14 +02:00
$this -> withnotifytiersatcreate = 0 ;
2018-03-10 04:23:59 +01:00
$this -> withusercreate = 1 ;
$this -> withcreatereadonly = 1 ;
$this -> withemail = 0 ;
$this -> withref = 0 ;
2019-11-13 19:35:39 +01:00
$this -> withextrafields = 0 ; // Show extrafields or not
2018-03-10 04:23:59 +01:00
//$this->withtopicreadonly=0;
}
/**
* Show the form to input ticket
*
2018-04-19 14:44:21 +02:00
* @ param int $withdolfichehead With dol_fiche_head
2018-03-10 04:23:59 +01:00
* @ return void
*/
2019-01-27 15:20:16 +01:00
public function showForm ( $withdolfichehead = 0 )
2018-03-10 04:23:59 +01:00
{
global $conf , $langs , $user , $hookmanager ;
2018-09-11 10:36:39 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'other' , 'mails' , 'ticket' ));
2018-03-10 04:23:59 +01:00
$form = new Form ( $this -> db );
$formcompany = new FormCompany ( $this -> db );
2018-06-04 21:49:29 +02:00
$ticketstatic = new Ticket ( $this -> db );
2018-03-10 04:23:59 +01:00
$soc = new Societe ( $this -> db );
if ( ! empty ( $this -> withfromsocid ) && $this -> withfromsocid > 0 ) {
$soc -> fetch ( $this -> withfromsocid );
}
2018-06-04 21:49:29 +02:00
$ticketstat = new Ticket ( $this -> db );
2018-03-10 04:23:59 +01:00
$extrafields = new ExtraFields ( $this -> db );
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $ticketstat -> table_element );
2018-03-10 04:23:59 +01:00
2019-10-01 11:28:10 +02:00
print " \n <!-- Begin form TICKET --> \n " ;
2018-03-10 04:23:59 +01:00
2018-04-19 14:44:21 +02:00
if ( $withdolfichehead ) dol_fiche_head ( null , 'card' , '' , 0 , '' );
2019-11-13 19:35:39 +01:00
print '<form method="POST" ' . ( $withdolfichehead ? '' : 'style="margin-bottom: 30px;" ' ) . 'name="ticket" id="form_create_ticket" enctype="multipart/form-data" action="' . $this -> param [ " returnurl " ] . '">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-13 19:35:39 +01:00
print '<input type="hidden" name="action" value="' . $this -> action . '">' ;
2018-03-10 04:23:59 +01:00
foreach ( $this -> param as $key => $value ) {
2019-11-13 19:35:39 +01:00
print '<input type="hidden" name="' . $key . '" value="' . $value . '">' ;
2018-03-10 04:23:59 +01:00
}
2019-11-13 19:35:39 +01:00
print '<input type="hidden" name="fk_user_create" value="' . $this -> fk_user_create . '">' ;
2018-03-10 04:23:59 +01:00
2019-02-11 14:51:59 +01:00
print '<table class="border centpercent">' ;
2018-03-10 04:23:59 +01:00
if ( $this -> withref ) {
// Ref
$defaultref = $ticketstat -> getDefaultRef ();
2019-11-13 19:35:39 +01:00
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">' . $langs -> trans ( " Ref " ) . '</span></td><td><input size="18" type="text" name="ref" value="' . ( GETPOST ( " ref " , 'alpha' ) ? GETPOST ( " ref " , 'alpha' ) : $defaultref ) . '"></td></tr>' ;
2018-03-10 04:23:59 +01:00
}
2019-04-10 11:39:54 +02:00
// TITLE
if ( $this -> withemail ) {
2019-11-13 19:35:39 +01:00
print '<tr><td class="titlefield"><label for="email"><span class="fieldrequired">' . $langs -> trans ( " Email " ) . '</span></label></td><td>' ;
print '<input class="text minwidth200" id="email" name="email" value="' . ( GETPOST ( 'email' , 'alpha' ) ? GETPOST ( 'email' , 'alpha' ) : $subject ) . '" />' ;
2019-04-10 11:39:54 +02:00
print '</td></tr>' ;
}
// Si origin du ticket
if ( isset ( $this -> param [ 'origin' ]) && $this -> param [ 'originid' ] > 0 ) {
// Parse element/subelement (ex: project_task)
$element = $subelement = $this -> param [ 'origin' ];
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , $this -> param [ 'origin' ], $regs )) {
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
2019-11-13 19:35:39 +01:00
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
2019-04-10 11:39:54 +02:00
$classname = ucfirst ( $subelement );
$objectsrc = new $classname ( $this -> db );
$objectsrc -> fetch ( GETPOST ( 'originid' , 'int' ));
if ( empty ( $objectsrc -> lines ) && method_exists ( $objectsrc , 'fetch_lines' )) {
$objectsrc -> fetch_lines ();
}
$objectsrc -> fetch_thirdparty ();
$newclassname = $classname ;
2019-11-13 19:35:39 +01:00
print '<tr><td>' . $langs -> trans ( $newclassname ) . '</td><td colspan="2"><input name="' . $subelement . 'id" value="' . GETPOST ( 'originid' ) . '" type="hidden" />' . $objectsrc -> getNomUrl ( 1 ) . '</td></tr>' ;
2019-04-10 11:39:54 +02:00
}
// Type
2019-11-13 19:35:39 +01:00
print '<tr><td class="titlefield"><span class="fieldrequired"><label for="selecttype_code">' . $langs -> trans ( " TicketTypeRequest " ) . '</span></label></td><td>' ;
2019-12-04 16:23:31 +01:00
$this -> selectTypesTickets (( GETPOST ( 'type_code' , 'alpha' ) ? GETPOST ( 'type_code' , 'alpha' ) : $this -> type_code ), 'type_code' , '' , '2' , 0 , 0 , 0 , 'minwidth150' );
2019-04-10 11:39:54 +02:00
print '</td></tr>' ;
// Severity
2019-11-13 19:35:39 +01:00
print '<tr><td><span class="fieldrequired"><label for="selectseverity_code">' . $langs -> trans ( " TicketSeverity " ) . '</span></label></td><td>' ;
2019-04-10 11:39:54 +02:00
$this -> selectSeveritiesTickets (( GETPOST ( 'severity_code' ) ? GETPOST ( 'severity_code' ) : $this -> severity_code ), 'severity_code' , '' , '2' );
print '</td></tr>' ;
// Group
2019-11-13 19:35:39 +01:00
print '<tr><td><span class="fieldrequired"><label for="selectcategory_code">' . $langs -> trans ( " TicketGroup " ) . '</span></label></td><td>' ;
2019-04-10 11:39:54 +02:00
$this -> selectGroupTickets (( GETPOST ( 'category_code' ) ? GETPOST ( 'category_code' ) : $this -> category_code ), 'category_code' , '' , '2' );
print '</td></tr>' ;
// Subject
if ( $this -> withtitletopic ) {
2019-11-13 19:35:39 +01:00
print '<tr><td><label for="subject"><span class="fieldrequired">' . $langs -> trans ( " Subject " ) . '</span></label></td><td>' ;
2019-04-10 11:39:54 +02:00
// Réponse à un ticket : affichage du titre du thread en readonly
if ( $this -> withtopicreadonly ) {
2019-11-13 19:35:39 +01:00
print $langs -> trans ( 'SubjectAnswerToTicket' ) . ' ' . $this -> topic_title ;
2019-04-10 11:39:54 +02:00
print '</td></tr>' ;
} else {
if ( $this -> withthreadid > 0 ) {
2019-11-13 19:35:39 +01:00
$subject = $langs -> trans ( 'SubjectAnswerToTicket' ) . ' ' . $this -> withthreadid . ' : ' . $this -> topic_title . '' ;
2019-04-10 11:39:54 +02:00
}
2019-12-04 16:23:31 +01:00
print '<input class="text minwidth300" id="subject" name="subject" value="' . ( GETPOST ( 'subject' , 'alpha' ) ? GETPOST ( 'subject' , 'alpha' ) : $subject ) . '" />' ;
2019-04-10 11:39:54 +02:00
print '</td></tr>' ;
}
}
// MESSAGE
$msg = GETPOSTISSET ( 'message' ) ? GETPOST ( 'message' , 'none' ) : '' ;
2019-11-13 19:35:39 +01:00
print '<tr><td><label for="message"><span class="fieldrequired">' . $langs -> trans ( " Message " ) . '</span></label></td><td>' ;
2019-04-10 11:39:54 +02:00
// If public form, display more information
$toolbarname = 'dolibarr_notes' ;
if ( $this -> ispublic )
{
$toolbarname = 'dolibarr_details' ;
2019-11-13 19:35:39 +01:00
print '<div class="warning">' . ( $conf -> global -> TICKET_PUBLIC_TEXT_HELP_MESSAGE ? $conf -> global -> TICKET_PUBLIC_TEXT_HELP_MESSAGE : $langs -> trans ( 'TicketPublicPleaseBeAccuratelyDescribe' )) . '</div>' ;
2019-04-10 11:39:54 +02:00
}
2019-11-13 19:35:39 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-04-10 11:39:54 +02:00
$uselocalbrowser = true ;
2019-11-05 13:41:01 +01:00
$doleditor = new DolEditor ( 'message' , $msg , '100%' , 230 , $toolbarname , 'In' , true , $uselocalbrowser , $conf -> global -> FCKEDITOR_ENABLE_TICKET , ROWS_8 , '90%' );
2019-04-10 11:39:54 +02:00
$doleditor -> Create ();
print '</td></tr>' ;
2018-03-10 04:23:59 +01:00
// FK_USER_CREATE
if ( $this -> withusercreate > 0 && $this -> fk_user_create ) {
2019-11-13 19:35:39 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " CreatedBy " ) . '</td><td>' ;
2018-03-10 04:23:59 +01:00
$langs -> load ( " users " );
$fuser = new User ( $this -> db );
if ( $this -> withcreatereadonly ) {
if ( $res = $fuser -> fetch ( $this -> fk_user_create )) {
print $fuser -> getNomUrl ( 1 );
}
}
print ' ' ;
print " </td></tr> \n " ;
}
2018-03-18 19:13:42 +01:00
// Customer or supplier
2018-03-10 04:23:59 +01:00
if ( $this -> withcompany ) {
// altairis: force company and contact id for external user
if ( empty ( $user -> socid )) {
// Company
2019-11-13 19:35:39 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " ThirdParty " ) . '</td><td>' ;
2018-03-10 04:23:59 +01:00
$events = array ();
$events [] = array ( 'method' => 'getContacts' , 'url' => dol_buildpath ( '/core/ajax/contacts.php' , 1 ), 'htmlname' => 'contactid' , 'params' => array ( 'add-customer-contact' => 'disabled' ));
2018-04-18 09:27:54 +02:00
print $form -> select_company ( $this -> withfromsocid , 'socid' , '' , 1 , 1 , '' , $events , 0 , 'minwidth200' );
2018-03-10 04:23:59 +01:00
print '</td></tr>' ;
2019-11-13 19:35:39 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && ! empty ( $conf -> global -> COMPANY_USE_SEARCH_TO_SELECT )) {
2018-03-10 04:23:59 +01:00
$htmlname = 'socid' ;
print ' < script type = " text/javascript " >
$ ( document ) . ready ( function () {
jQuery ( " #'. $htmlname .' " ) . change ( function () {
var obj = '.json_encode($events).' ;
$ . each ( obj , function ( key , values ) {
if ( values . method . length ) {
runJsCodeForEvent '.$htmlname.' ( values );
}
});
});
2018-03-11 23:40:25 +01:00
2018-03-10 04:23:59 +01:00
function runJsCodeForEvent '.$htmlname.' ( obj ) {
console . log ( " Run runJsCodeForEvent'. $htmlname .' " );
var id = $ ( " #'. $htmlname .' " ) . val ();
var method = obj . method ;
var url = obj . url ;
var htmlname = obj . htmlname ;
var showempty = obj . showempty ;
$ . getJSON ( url ,
{
action : method ,
id : id ,
htmlname : htmlname ,
showempty : showempty
},
function ( response ) {
$ . each ( obj . params , function ( key , action ) {
if ( key . length ) {
var num = response . num ;
if ( num > 0 ) {
$ ( " # " + key ) . removeAttr ( action );
} else {
$ ( " # " + key ) . attr ( action , action );
}
}
});
$ ( " select# " + htmlname ) . html ( response . value );
if ( response . num ) {
var selecthtml_str = response . value ;
var selecthtml_dom = $ . parseHTML ( selecthtml_str );
$ ( " #inputautocomplete " + htmlname ) . val ( selecthtml_dom [ 0 ][ 0 ] . innerHTML );
} else {
$ ( " #inputautocomplete " + htmlname ) . val ( " " );
}
$ ( " select# " + htmlname ) . change (); /* Trigger event change */
}
);
}
});
</ script > ' ;
}
// Contact and type
2019-11-13 19:35:39 +01:00
print '<tr><td>' . $langs -> trans ( " Contact " ) . '</td><td>' ;
2018-07-16 10:46:10 +02:00
// If no socid, set to -1 to avoid full contacts list
$selectedCompany = ( $this -> withfromsocid > 0 ) ? $this -> withfromsocid : - 1 ;
$nbofcontacts = $form -> select_contacts ( $selectedCompany , $this -> withfromcontactid , 'contactid' , 3 , '' , '' , 0 , 'minwidth200' );
2019-02-11 14:51:59 +01:00
print ' ' ;
2018-03-18 19:13:42 +01:00
$formcompany -> selectTypeContact ( $ticketstatic , '' , 'type' , 'external' , '' , 0 , 'maginleftonly' );
2018-03-10 04:23:59 +01:00
print '</td></tr>' ;
} else {
2019-11-13 19:35:39 +01:00
print '<tr><td class="titlefield"><input type="hidden" name="socid" value="' . $user -> socid . '"/></td>' ;
print '<td><input type="hidden" name="contactid" value="' . $user -> contactid . '"/></td>' ;
2018-03-10 04:23:59 +01:00
print '<td><input type="hidden" name="type" value="Z"/></td></tr>' ;
}
2019-03-05 12:18:36 +01:00
// Notify thirdparty at creation
if ( empty ( $this -> ispublic ))
{
2019-11-13 19:35:39 +01:00
print '<tr><td><label for="notify_tiers_at_create">' . $langs -> trans ( " TicketNotifyTiersAtCreation " ) . '</label></td><td>' ;
print '<input type="checkbox" id="notify_tiers_at_create" name="notify_tiers_at_create"' . ( $this -> withnotifytiersatcreate ? ' checked="checked"' : '' ) . '>' ;
2019-03-05 12:18:36 +01:00
print '</td></tr>' ;
}
2018-03-10 04:23:59 +01:00
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $conf -> projet -> enabled ) && ! $this -> ispublic )
2019-03-05 12:18:36 +01:00
{
2019-11-13 19:35:39 +01:00
$formproject = new FormProjets ( $this -> db );
print '<tr><td><label for="project"><span class="">' . $langs -> trans ( " Project " ) . '</span></label></td><td>' ;
2019-03-05 16:27:19 +01:00
print $formproject -> select_projects ( - 1 , GETPOST ( 'projectid' , 'int' ), 'projectid' , 0 , 0 , 1 , 1 );
2019-03-05 12:18:36 +01:00
print '</td></tr>' ;
}
2018-03-10 04:23:59 +01:00
// Attached files
if ( ! empty ( $this -> withfile )) {
// Define list of attached files
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
if ( ! empty ( $_SESSION [ " listofpaths " ])) {
$listofpaths = explode ( ';' , $_SESSION [ " listofpaths " ]);
}
if ( ! empty ( $_SESSION [ " listofnames " ])) {
$listofnames = explode ( ';' , $_SESSION [ " listofnames " ]);
}
if ( ! empty ( $_SESSION [ " listofmimes " ])) {
$listofmimes = explode ( ';' , $_SESSION [ " listofmimes " ]);
}
2019-10-16 22:56:29 +02:00
$out = '<tr>' ;
2019-12-06 09:26:49 +01:00
$out .= '<td>' . $langs -> trans ( " MailFile " ) . '</td>' ;
2019-12-04 16:23:31 +01:00
$out .= '<td>' ;
2018-03-10 04:23:59 +01:00
// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
2019-12-06 09:26:49 +01:00
$out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . " \n " ;
2018-03-10 04:23:59 +01:00
$out .= '<script type="text/javascript" language="javascript">' ;
$out .= 'jQuery(document).ready(function () {' ;
$out .= ' jQuery(".removedfile").click(function() {' ;
$out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());' ;
$out .= ' });' ;
$out .= '})' ;
2019-12-06 09:26:49 +01:00
$out .= '</script>' . " \n " ;
2018-03-10 04:23:59 +01:00
if ( count ( $listofpaths )) {
foreach ( $listofpaths as $key => $val ) {
2019-12-06 09:26:49 +01:00
$out .= '<div id="attachfile_' . $key . '">' ;
$out .= img_mime ( $listofnames [ $key ]) . ' ' . $listofnames [ $key ];
2018-03-10 04:23:59 +01:00
if ( ! $this -> withfilereadonly ) {
2019-12-06 09:26:49 +01:00
$out .= ' <input type="image" style="border: 0px;" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/delete.png" value="' . ( $key + 1 ) . '" class="removedfile" id="removedfile_' . $key . '" name="removedfile_' . $key . '" />' ;
2018-03-10 04:23:59 +01:00
}
$out .= '<br></div>' ;
}
} else {
2019-12-06 09:26:49 +01:00
$out .= $langs -> trans ( " NoAttachedFiles " ) . '<br>' ;
2018-03-10 04:23:59 +01:00
}
if ( $this -> withfile == 2 ) { // Can add other files
2019-12-06 09:26:49 +01:00
$out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs -> trans ( " Upload " ) . '" />' ;
2018-03-10 04:23:59 +01:00
$out .= ' ' ;
2019-12-06 09:26:49 +01:00
$out .= '<input type="submit" class="button" id="addfile" name="addfile" value="' . $langs -> trans ( " MailingAddFile " ) . '" />' ;
2018-03-10 04:23:59 +01:00
}
$out .= " </td></tr> \n " ;
print $out ;
}
// Other attributes
2019-10-16 22:56:29 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $ticketstat , $this -> action ); // Note that $action and $object may have been modified by hook
2018-04-13 13:28:48 +02:00
if ( empty ( $reshook ))
2018-04-12 23:17:46 +02:00
{
print $ticketstat -> showOptionals ( $extrafields , 'edit' );
2018-03-10 04:23:59 +01:00
}
print '</table>' ;
2018-04-19 14:44:21 +02:00
if ( $withdolfichehead ) dol_fiche_end ();
2019-11-26 04:32:38 +01:00
print '<div class="center">' ;
2019-11-13 19:35:39 +01:00
print '<input class="button" type="submit" name="add" value="' . $langs -> trans (( $this -> withthreadid > 0 ? " SendResponse " : " NewTicket " )) . '" />' ;
2018-03-10 04:23:59 +01:00
if ( $this -> withcancel ) {
2019-11-26 04:32:38 +01:00
print " " ;
2019-11-13 19:35:39 +01:00
print " <input class= \" button \" type= \" submit \" name= \" cancel \" value= \" " . $langs -> trans ( " Cancel " ) . " \" > " ;
2018-03-10 04:23:59 +01:00
}
2019-11-26 04:32:38 +01:00
print '</div>' ;
2018-03-10 04:23:59 +01:00
print " </form> \n " ;
print " <!-- End form TICKET --> \n " ;
}
/**
* Return html list of tickets type
*
* @ param string $selected Id du type pre - selectionne
* @ param string $htmlname Nom de la zone select
2018-06-04 21:49:29 +02:00
* @ param string $filtertype To filter on field type in llx_c_ticket_type ( array ( 'code' => xx , 'label' => zz ))
2018-03-10 04:23:59 +01:00
* @ param int $format 0 = id + libelle , 1 = code + code , 2 = code + libelle , 3 = id + code
* @ param int $empty 1 = peut etre vide , 0 sinon
2018-03-11 11:12:38 +01:00
* @ param int $noadmininfo 0 = Add admin info , 1 = Disable admin info
2018-03-10 04:23:59 +01:00
* @ param int $maxlength Max length of label
2018-03-13 13:26:03 +01:00
* @ param string $morecss More CSS
2018-03-11 11:12:38 +01:00
* @ return void
2018-03-10 04:23:59 +01:00
*/
2019-01-27 15:20:16 +01:00
public function selectTypesTickets ( $selected = '' , $htmlname = 'tickettype' , $filtertype = '' , $format = 0 , $empty = 0 , $noadmininfo = 0 , $maxlength = 0 , $morecss = '' )
2018-03-10 04:23:59 +01:00
{
global $langs , $user ;
2018-06-04 21:49:29 +02:00
$ticketstat = new Ticket ( $this -> db );
2018-03-10 04:23:59 +01:00
2019-11-13 19:35:39 +01:00
dol_syslog ( get_class ( $this ) . " ::select_types_tickets " . $selected . " , " . $htmlname . " , " . $filtertype . " , " . $format , LOG_DEBUG );
2018-03-10 04:23:59 +01:00
$filterarray = array ();
if ( $filtertype != '' && $filtertype != '-1' ) {
$filterarray = explode ( ',' , $filtertype );
}
2018-03-11 11:12:38 +01:00
$ticketstat -> loadCacheTypesTickets ();
2018-03-10 04:23:59 +01:00
2019-11-13 19:35:39 +01:00
print '<select id="select' . $htmlname . '" class="flat minwidth100' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '">' ;
2018-03-10 04:23:59 +01:00
if ( $empty ) {
print '<option value=""> </option>' ;
}
if ( is_array ( $ticketstat -> cache_types_tickets ) && count ( $ticketstat -> cache_types_tickets )) {
foreach ( $ticketstat -> cache_types_tickets as $id => $arraytypes ) {
// On passe si on a demande de filtrer sur des modes de paiments particuliers
if ( count ( $filterarray ) && ! in_array ( $arraytypes [ 'type' ], $filterarray )) {
continue ;
}
// We discard empty line if showempty is on because an empty line has already been output.
if ( $empty && empty ( $arraytypes [ 'code' ])) {
continue ;
}
if ( $format == 0 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $id . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 1 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $arraytypes [ 'code' ] . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 2 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $arraytypes [ 'code' ] . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 3 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $id . '"' ;
2018-03-10 04:23:59 +01:00
}
// Si selected est text, on compare avec code, sinon avec id
if ( preg_match ( '/[a-z]/i' , $selected ) && $selected == $arraytypes [ 'code' ]) {
print ' selected="selected"' ;
} elseif ( $selected == $id ) {
print ' selected="selected"' ;
} elseif ( $arraytypes [ 'use_default' ] == " 1 " && ! $empty ) {
print ' selected="selected"' ;
}
print '>' ;
2019-10-16 22:56:29 +02:00
$value = ' ' ;
2018-03-10 04:23:59 +01:00
if ( $format == 0 ) {
$value = ( $maxlength ? dol_trunc ( $arraytypes [ 'label' ], $maxlength ) : $arraytypes [ 'label' ]);
2019-10-16 22:56:29 +02:00
} elseif ( $format == 1 ) {
2018-03-10 04:23:59 +01:00
$value = $arraytypes [ 'code' ];
2019-10-16 22:56:29 +02:00
} elseif ( $format == 2 ) {
2018-03-10 04:23:59 +01:00
$value = ( $maxlength ? dol_trunc ( $arraytypes [ 'label' ], $maxlength ) : $arraytypes [ 'label' ]);
2019-10-16 22:56:29 +02:00
} elseif ( $format == 3 ) {
2018-03-10 04:23:59 +01:00
$value = $arraytypes [ 'code' ];
}
2019-10-16 22:56:29 +02:00
print $value ;
2018-03-10 04:23:59 +01:00
print '</option>' ;
}
}
print '</select>' ;
if ( $user -> admin && ! $noadmininfo ) {
2018-03-11 21:00:39 +01:00
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2018-03-10 04:23:59 +01:00
}
2018-03-13 13:26:03 +01:00
print ajax_combobox ( 'select' . $htmlname );
2018-03-10 04:23:59 +01:00
}
/**
2019-02-11 19:16:37 +01:00
* Return html list of ticket anaytic codes
2018-03-10 04:23:59 +01:00
*
* @ param string $selected Id categorie pre - selectionnée
* @ param string $htmlname Nom de la zone select
2018-06-04 21:49:29 +02:00
* @ param string $filtertype To filter on field type in llx_c_ticket_category ( array ( 'code' => xx , 'label' => zz ))
2018-03-10 04:23:59 +01:00
* @ param int $format 0 = id + libelle , 1 = code + code , 2 = code + libelle , 3 = id + code
* @ param int $empty 1 = peut etre vide , 0 sinon
2018-03-13 13:26:03 +01:00
* @ param int $noadmininfo 0 = Add admin info , 1 = Disable admin info
2018-03-10 04:23:59 +01:00
* @ param int $maxlength Max length of label
2018-03-13 13:26:03 +01:00
* @ param string $morecss More CSS
* @ return void
2018-03-10 04:23:59 +01:00
*/
2019-02-26 13:20:58 +01:00
public function selectGroupTickets ( $selected = '' , $htmlname = 'ticketcategory' , $filtertype = '' , $format = 0 , $empty = 0 , $noadmininfo = 0 , $maxlength = 0 , $morecss = '' )
2018-03-10 04:23:59 +01:00
{
global $langs , $user ;
2018-06-04 21:49:29 +02:00
$ticketstat = new Ticket ( $this -> db );
2018-03-10 04:23:59 +01:00
2019-11-13 19:35:39 +01:00
dol_syslog ( get_class ( $this ) . " ::selectCategoryTickets " . $selected . " , " . $htmlname . " , " . $filtertype . " , " . $format , LOG_DEBUG );
2018-03-10 04:23:59 +01:00
$filterarray = array ();
if ( $filtertype != '' && $filtertype != '-1' ) {
$filterarray = explode ( ',' , $filtertype );
}
2018-03-11 11:54:30 +01:00
$ticketstat -> loadCacheCategoriesTickets ();
2018-03-10 04:23:59 +01:00
2019-11-13 19:35:39 +01:00
print '<select id="select' . $htmlname . '" class="flat minwidth100' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '">' ;
2018-03-10 04:23:59 +01:00
if ( $empty ) {
print '<option value=""> </option>' ;
}
if ( is_array ( $ticketstat -> cache_category_tickets ) && count ( $ticketstat -> cache_category_tickets )) {
foreach ( $ticketstat -> cache_category_tickets as $id => $arraycategories ) {
// On passe si on a demande de filtrer sur des modes de paiments particuliers
if ( count ( $filterarray ) && ! in_array ( $arraycategories [ 'type' ], $filterarray )) {
continue ;
}
// We discard empty line if showempty is on because an empty line has already been output.
if ( $empty && empty ( $arraycategories [ 'code' ])) {
continue ;
}
if ( $format == 0 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $id . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 1 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $arraycategories [ 'code' ] . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 2 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $arraycategories [ 'code' ] . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 3 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $id . '"' ;
2018-03-10 04:23:59 +01:00
}
// Si selected est text, on compare avec code, sinon avec id
if ( preg_match ( '/[a-z]/i' , $selected ) && $selected == $arraycategories [ 'code' ]) {
print ' selected="selected"' ;
} elseif ( $selected == $id ) {
print ' selected="selected"' ;
} elseif ( $arraycategories [ 'use_default' ] == " 1 " && ! $empty ) {
print ' selected="selected"' ;
}
print '>' ;
if ( $format == 0 ) {
$value = ( $maxlength ? dol_trunc ( $arraycategories [ 'label' ], $maxlength ) : $arraycategories [ 'label' ]);
}
if ( $format == 1 ) {
$value = $arraycategories [ 'code' ];
}
if ( $format == 2 ) {
$value = ( $maxlength ? dol_trunc ( $arraycategories [ 'label' ], $maxlength ) : $arraycategories [ 'label' ]);
}
if ( $format == 3 ) {
$value = $arraycategories [ 'code' ];
}
print $value ? $value : ' ' ;
print '</option>' ;
}
}
print '</select>' ;
if ( $user -> admin && ! $noadmininfo ) {
2018-03-11 21:00:39 +01:00
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2018-03-10 04:23:59 +01:00
}
2018-03-13 13:26:03 +01:00
2018-04-30 10:33:36 +02:00
print ajax_combobox ( 'select' . $htmlname );
2018-03-10 04:23:59 +01:00
}
/**
* Return html list of ticket severitys
*
* @ param string $selected Id severity pre - selectionnée
* @ param string $htmlname Nom de la zone select
2018-06-04 21:49:29 +02:00
* @ param string $filtertype To filter on field type in llx_c_ticket_severity ( array ( 'code' => xx , 'label' => zz ))
2018-03-10 04:23:59 +01:00
* @ param int $format 0 = id + libelle , 1 = code + code , 2 = code + libelle , 3 = id + code
* @ param int $empty 1 = peut etre vide , 0 sinon
2018-03-13 13:26:03 +01:00
* @ param int $noadmininfo 0 = Add admin info , 1 = Disable admin info
2018-03-10 04:23:59 +01:00
* @ param int $maxlength Max length of label
2018-03-13 13:26:03 +01:00
* @ param string $morecss More CSS
* @ return void
2018-03-10 04:23:59 +01:00
*/
2019-01-27 15:20:16 +01:00
public function selectSeveritiesTickets ( $selected = '' , $htmlname = 'ticketseverity' , $filtertype = '' , $format = 0 , $empty = 0 , $noadmininfo = 0 , $maxlength = 0 , $morecss = '' )
2018-03-10 04:23:59 +01:00
{
global $langs , $user ;
2018-06-04 21:49:29 +02:00
$ticketstat = new Ticket ( $this -> db );
2018-03-10 04:23:59 +01:00
2019-11-13 19:35:39 +01:00
dol_syslog ( get_class ( $this ) . " ::selectSeveritiesTickets " . $selected . " , " . $htmlname . " , " . $filtertype . " , " . $format , LOG_DEBUG );
2018-03-10 04:23:59 +01:00
$filterarray = array ();
if ( $filtertype != '' && $filtertype != '-1' ) {
$filterarray = explode ( ',' , $filtertype );
}
2018-03-11 11:54:30 +01:00
$ticketstat -> loadCacheSeveritiesTickets ();
2018-03-10 04:23:59 +01:00
2019-11-13 19:35:39 +01:00
print '<select id="select' . $htmlname . '" class="flat minwidth100' . ( $morecss ? ' ' . $morecss : '' ) . '" name="' . $htmlname . '">' ;
2018-03-10 04:23:59 +01:00
if ( $empty ) {
print '<option value=""> </option>' ;
}
if ( is_array ( $ticketstat -> cache_severity_tickets ) && count ( $ticketstat -> cache_severity_tickets )) {
foreach ( $ticketstat -> cache_severity_tickets as $id => $arrayseverities ) {
// On passe si on a demande de filtrer sur des modes de paiments particuliers
if ( count ( $filterarray ) && ! in_array ( $arrayseverities [ 'type' ], $filterarray )) {
continue ;
}
// We discard empty line if showempty is on because an empty line has already been output.
if ( $empty && empty ( $arrayseverities [ 'code' ])) {
continue ;
}
if ( $format == 0 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $id . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 1 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $arrayseverities [ 'code' ] . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 2 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $arrayseverities [ 'code' ] . '"' ;
2018-03-10 04:23:59 +01:00
}
if ( $format == 3 ) {
2019-11-13 19:35:39 +01:00
print '<option value="' . $id . '"' ;
2018-03-10 04:23:59 +01:00
}
// Si selected est text, on compare avec code, sinon avec id
if ( preg_match ( '/[a-z]/i' , $selected ) && $selected == $arrayseverities [ 'code' ]) {
print ' selected="selected"' ;
} elseif ( $selected == $id ) {
print ' selected="selected"' ;
} elseif ( $arrayseverities [ 'use_default' ] == " 1 " && ! $empty ) {
print ' selected="selected"' ;
}
print '>' ;
if ( $format == 0 ) {
$value = ( $maxlength ? dol_trunc ( $arrayseverities [ 'label' ], $maxlength ) : $arrayseverities [ 'label' ]);
}
if ( $format == 1 ) {
$value = $arrayseverities [ 'code' ];
}
if ( $format == 2 ) {
$value = ( $maxlength ? dol_trunc ( $arrayseverities [ 'label' ], $maxlength ) : $arrayseverities [ 'label' ]);
}
if ( $format == 3 ) {
$value = $arrayseverities [ 'code' ];
}
print $value ? $value : ' ' ;
print '</option>' ;
}
}
print '</select>' ;
if ( $user -> admin && ! $noadmininfo ) {
2018-03-11 21:00:39 +01:00
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
2018-03-10 04:23:59 +01:00
}
2018-03-13 13:26:03 +01:00
print ajax_combobox ( 'select' . $htmlname );
2018-03-10 04:23:59 +01:00
}
2019-07-19 23:11:00 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Clear list of attached files in send mail form ( also stored in session )
*
* @ return void
*/
public function clear_attached_files ()
{
// phpcs:enable
2019-11-13 19:35:39 +01:00
global $conf , $user ;
2019-07-19 23:11:00 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
// Set tmp user directory
2019-11-13 19:35:39 +01:00
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
$upload_dir = $vardir . '/temp/' ; // TODO Add $keytoavoidconflict in upload_dir path
2019-07-19 23:11:00 +02:00
if ( is_dir ( $upload_dir )) dol_delete_dir_recursive ( $upload_dir );
2019-11-13 19:35:39 +01:00
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
2019-07-19 23:11:00 +02:00
unset ( $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
unset ( $_SESSION [ " listofnames " . $keytoavoidconflict ]);
unset ( $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
}
2018-03-10 04:23:59 +01:00
/**
* Show the form to add message on ticket
*
2019-07-19 23:11:00 +02:00
* @ param string $width Width of form
* @ return void
2018-03-10 04:23:59 +01:00
*/
public function showMessageForm ( $width = '40%' )
{
2019-07-19 23:11:00 +02:00
global $conf , $langs , $user , $hookmanager , $form , $mysoc ;
$formmail = new FormMail ( $this -> db );
$addfileaction = 'addfile' ;
2019-11-13 19:35:39 +01:00
if ( ! is_object ( $form )) $form = new Form ( $this -> db );
2018-03-10 04:23:59 +01:00
2018-09-14 10:20:21 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'other' , 'mails' ));
2018-03-10 04:23:59 +01:00
2019-07-19 23:11:00 +02:00
// Clear temp files. Must be done at beginning, before call of triggers
if ( GETPOST ( 'mode' , 'alpha' ) == 'init' || ( GETPOST ( 'modelmailselected' , 'alpha' ) && GETPOST ( 'modelmailselected' , 'alpha' ) != '-1' ))
{
$this -> clear_attached_files ();
}
2018-03-10 04:23:59 +01:00
2019-07-19 23:11:00 +02:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $this -> param [ 'langsmodels' ];
2019-11-13 19:35:39 +01:00
if ( ! empty ( $newlang ))
2019-07-19 23:11:00 +02:00
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
$outputlangs -> load ( 'other' );
}
2018-03-10 04:23:59 +01:00
2019-07-19 23:11:00 +02:00
// Get message template for $this->param["models"] into c_email_templates
$arraydefaultmessage = - 1 ;
if ( $this -> param [ 'models' ] != 'none' )
{
2019-11-13 19:35:39 +01:00
$model_id = 0 ;
2019-07-19 23:11:00 +02:00
if ( array_key_exists ( 'models_id' , $this -> param ))
{
2019-11-13 19:35:39 +01:00
$model_id = $this -> param [ " models_id " ];
2019-07-19 23:11:00 +02:00
}
2019-11-13 19:35:39 +01:00
$arraydefaultmessage = $formmail -> getEMailTemplate ( $this -> db , $this -> param [ " models " ], $user , $outputlangs , $model_id ); // If $model_id is empty, preselect the first one
2019-07-19 23:11:00 +02:00
}
2018-03-10 04:23:59 +01:00
// Define list of attached files
$listofpaths = array ();
$listofnames = array ();
$listofmimes = array ();
2019-11-13 19:35:39 +01:00
$keytoavoidconflict = empty ( $this -> trackid ) ? '' : '-' . $this -> trackid ; // this->trackid must be defined
2018-03-10 04:23:59 +01:00
2019-07-19 23:11:00 +02:00
if ( GETPOST ( 'mode' , 'alpha' ) == 'init' || ( GETPOST ( 'modelmailselected' , 'alpha' ) && GETPOST ( 'modelmailselected' , 'alpha' ) != '-1' ))
{
2019-11-13 19:35:39 +01:00
if ( ! empty ( $arraydefaultmessage -> joinfiles ) && is_array ( $this -> param [ 'fileinit' ]))
2019-07-19 23:11:00 +02:00
{
2019-11-13 19:35:39 +01:00
foreach ( $this -> param [ 'fileinit' ] as $file )
2019-07-19 23:11:00 +02:00
{
$this -> add_attached_files ( $file , basename ( $file ), dol_mimetype ( $file ));
}
}
2018-03-10 04:23:59 +01:00
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $_SESSION [ " listofpaths " . $keytoavoidconflict ])) $listofpaths = explode ( ';' , $_SESSION [ " listofpaths " . $keytoavoidconflict ]);
if ( ! empty ( $_SESSION [ " listofnames " . $keytoavoidconflict ])) $listofnames = explode ( ';' , $_SESSION [ " listofnames " . $keytoavoidconflict ]);
if ( ! empty ( $_SESSION [ " listofmimes " . $keytoavoidconflict ])) $listofmimes = explode ( ';' , $_SESSION [ " listofmimes " . $keytoavoidconflict ]);
2018-03-10 04:23:59 +01:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $this -> param [ 'langsmodels' ];
}
2019-11-13 19:35:39 +01:00
if ( ! empty ( $newlang )) {
2018-03-10 04:23:59 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
$outputlangs -> load ( 'other' );
}
2019-10-01 11:28:10 +02:00
print " \n <!-- Begin message_form TICKET --> \n " ;
2018-03-10 04:23:59 +01:00
$send_email = GETPOST ( 'send_email' , 'int' ) ? GETPOST ( 'send_email' , 'int' ) : 0 ;
// Example 1 : Adding jquery code
print ' < script type = " text/javascript " language = " javascript " >
jQuery ( document ) . ready ( function () {
2019-11-13 19:35:39 +01:00
send_email = ' . $send_email.' ;
2018-03-10 04:23:59 +01:00
if ( send_email ) {
jQuery ( " .email_line " ) . show ();
} else {
jQuery ( " .email_line " ) . hide ();
}
jQuery ( " #send_msg_email " ) . click ( function () {
if ( jQuery ( this ) . is ( " :checked " )) {
jQuery ( " .email_line " ) . show ();
}
else {
jQuery ( " .email_line " ) . hide ();
}
}); ' ;
print ' });
</ script > ' ;
2019-11-13 19:35:39 +01:00
print '<form method="post" name="ticket" enctype="multipart/form-data" action="' . $this -> param [ " returnurl " ] . '">' ;
2019-12-01 10:20:11 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-13 19:35:39 +01:00
print '<input type="hidden" name="action" value="' . $this -> action . '">' ;
2019-07-19 23:11:00 +02:00
print '<input type="hidden" name="actionbis" value="add_message">' ;
2018-03-10 04:23:59 +01:00
foreach ( $this -> param as $key => $value ) {
2019-11-13 19:35:39 +01:00
print '<input type="hidden" name="' . $key . '" value="' . $value . '">' ;
2018-03-10 04:23:59 +01:00
}
// Get message template
2019-11-13 19:35:39 +01:00
$model_id = 0 ;
2018-03-10 04:23:59 +01:00
if ( array_key_exists ( 'models_id' , $this -> param )) {
2019-11-13 19:35:39 +01:00
$model_id = $this -> param [ " models_id " ];
$arraydefaultmessage = $formmail -> getEMailTemplate ( $this -> db , $this -> param [ " models " ], $user , $outputlangs , $model_id );
2018-03-10 04:23:59 +01:00
}
$result = $formmail -> fetchAllEMailTemplate ( $this -> param [ " models " ], $user , $outputlangs );
2019-11-13 19:35:39 +01:00
if ( $result < 0 ) {
2018-03-10 04:23:59 +01:00
setEventMessages ( $this -> error , $this -> errors , 'errors' );
}
2019-11-13 19:35:39 +01:00
$modelmail_array = array ();
2018-03-10 04:23:59 +01:00
foreach ( $formmail -> lines_model as $line ) {
2019-11-13 19:35:39 +01:00
$modelmail_array [ $line -> id ] = $line -> label ;
2018-03-10 04:23:59 +01:00
}
2019-11-13 19:35:39 +01:00
print '<table class="border" width="' . $width . '">' ;
2018-03-10 04:23:59 +01:00
// External users can't send message email
2019-04-10 11:39:54 +02:00
if ( $user -> rights -> ticket -> write && ! $user -> socid )
{
2018-03-10 04:23:59 +01:00
print '<tr><td width="30%"></td><td colspan="2">' ;
2019-05-01 17:15:42 +02:00
$checkbox_selected = ( GETPOST ( 'send_email' ) == " 1 " ? ' checked' : '' );
2018-03-10 04:23:59 +01:00
print '<input type="checkbox" name="send_email" value="1" id="send_msg_email" ' . $checkbox_selected . '/> ' ;
2019-11-13 19:35:39 +01:00
print '<label for="send_msg_email">' . $langs -> trans ( 'SendMessageByEmail' ) . '</label>' ;
2018-03-10 04:23:59 +01:00
print '</td></tr>' ;
// Zone to select its email template
2019-11-13 19:35:39 +01:00
if ( count ( $modelmail_array ) > 0 ) {
2018-03-10 04:23:59 +01:00
print '<tr class="email_line"><td></td><td colspan="2"><div style="padding: 3px 0 3px 0">' . " \n " ;
print $langs -> trans ( 'SelectMailModel' ) . ': ' . $formmail -> selectarray ( 'modelmailselected' , $modelmail_array , $this -> param [ 'models_id' ], 1 );
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
print ' ' ;
print '<input class="button" type="submit" value="' . $langs -> trans ( 'Use' ) . '" name="modelselected" id="modelselected">' ;
print ' ' ;
print '</div></td>' ;
}
2019-05-01 17:53:41 +02:00
// Private message (not visible by customer/external user)
2019-11-13 19:35:39 +01:00
if ( ! $user -> socid ) {
2018-03-10 04:23:59 +01:00
print '<tr><td width="30%"></td><td>' ;
2019-05-01 17:15:42 +02:00
$checkbox_selected = ( GETPOST ( 'private_message' , 'alpha' ) == " 1 " ? ' checked' : '' );
2018-03-10 04:23:59 +01:00
print '<input type="checkbox" name="private_message" value="1" id="private_message" ' . $checkbox_selected . '/> ' ;
2019-11-13 19:35:39 +01:00
print '<label for="private_message">' . $langs -> trans ( 'MarkMessageAsPrivate' ) . '</label>' ;
2019-12-12 10:31:08 +01:00
print '</td><td class="center">' ;
2018-03-10 04:23:59 +01:00
print $form -> textwithpicto ( '' , $langs -> trans ( " TicketMessagePrivateHelp " ), 1 , 'help' );
print '</td></tr>' ;
2019-05-01 17:53:41 +02:00
}
2018-03-10 04:23:59 +01:00
2019-11-13 19:35:39 +01:00
print '<tr class="email_line"><td class="titlefieldcreate">' . $langs -> trans ( 'Subject' ) . '</td>' ;
2018-03-10 04:23:59 +01:00
$label_title = empty ( $conf -> global -> MAIN_APPLICATION_TITLE ) ? $mysoc -> name : $conf -> global -> MAIN_APPLICATION_TITLE ;
2020-02-07 11:52:55 +01:00
print '<td colspan="2"><input type="text" class="text" size="80" name="subject" value="[' . $label_title . ' - ' . $langs -> trans ( " Ticket " ) . ' #' . $this -> ref . '] ' . $langs -> trans ( 'TicketNewMessage' ) . '" />' ;
2018-03-10 04:23:59 +01:00
print '</td></tr>' ;
// Destinataires
2019-11-13 19:35:39 +01:00
print '<tr class="email_line"><td>' . $langs -> trans ( 'MailRecipients' ) . '</td><td colspan="2">' ;
2018-06-04 21:49:29 +02:00
$ticketstat = new Ticket ( $this -> db );
2018-04-18 10:13:20 +02:00
$res = $ticketstat -> fetch ( '' , '' , $this -> track_id );
2018-03-10 04:23:59 +01:00
if ( $res ) {
// Retrieve email of all contacts (internal and external)
$contacts = $ticketstat -> getInfosTicketInternalContact ();
$contacts = array_merge ( $contacts , $ticketstat -> getInfosTicketExternalContact ());
// Build array to display recipient list
if ( is_array ( $contacts ) && count ( $contacts ) > 0 ) {
foreach ( $contacts as $key => $info_sendto ) {
if ( $info_sendto [ 'email' ] != '' ) {
2020-02-07 11:52:55 +01:00
$sendto [] = dol_escape_htmltag ( trim ( $info_sendto [ 'firstname' ] . " " . $info_sendto [ 'lastname' ]) . " < " . $info_sendto [ 'email' ] . " > " ) . ' <small class="opacitymedium">(' . dol_escape_htmltag ( $info_sendto [ 'libelle' ]) . " )</small> " ;
2018-03-10 04:23:59 +01:00
}
}
}
if ( $ticketstat -> origin_email && ! in_array ( $this -> dao -> origin_email , $sendto )) {
2020-02-07 11:52:55 +01:00
$sendto [] = dol_escape_htmltag ( $ticketstat -> origin_email ) . ' <small class="opacitymedium">(' . $langs -> trans ( " TicketEmailOriginIssuer " ) . " )</small> " ;
2018-03-10 04:23:59 +01:00
}
if ( $ticketstat -> fk_soc > 0 ) {
$ticketstat -> socid = $ticketstat -> fk_soc ;
$ticketstat -> fetch_thirdparty ();
2018-04-18 10:13:20 +02:00
if ( is_array ( $ticketstat -> thirdparty -> email ) && ! in_array ( $ticketstat -> thirdparty -> email , $sendto )) {
2020-02-07 11:52:55 +01:00
$sendto [] = $ticketstat -> thirdparty -> email . ' <small class="opacitymedium">(' . $langs -> trans ( 'Customer' ) . ')</small>' ;
2018-03-10 04:23:59 +01:00
}
}
2018-07-06 13:09:07 +02:00
if ( $conf -> global -> TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS ) {
2020-02-07 11:52:55 +01:00
$sendto [] = $conf -> global -> TICKET_NOTIFICATION_EMAIL_TO . ' <small class="opacitymedium">(generic email)</small>' ;
2018-03-10 04:23:59 +01:00
}
// Print recipient list
if ( is_array ( $sendto ) && count ( $sendto ) > 0 ) {
print implode ( ', ' , $sendto );
} else {
2019-11-13 19:35:39 +01:00
print '<div class="warning">' . $langs -> trans ( 'WarningNoEMailsAdded' ) . ' ' . $langs -> trans ( 'TicketGoIntoContactTab' ) . '</div>' ;
2018-03-10 04:23:59 +01:00
}
}
print '</td></tr>' ;
}
// Intro
// External users can't send message email
2018-06-04 21:49:29 +02:00
if ( $user -> rights -> ticket -> write && ! $user -> socid ) {
2018-07-06 13:09:07 +02:00
$mail_intro = GETPOST ( 'mail_intro' ) ? GETPOST ( 'mail_intro' ) : $conf -> global -> TICKET_MESSAGE_MAIL_INTRO ;
2019-11-13 19:35:39 +01:00
print '<tr class="email_line"><td><label for="mail_intro">' . $langs -> trans ( " TicketMessageMailIntro " ) . '</label>' ;
2018-03-10 04:23:59 +01:00
print '</td><td>' ;
2019-11-13 19:35:39 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2018-03-10 04:23:59 +01:00
$uselocalbrowser = true ;
2019-09-30 17:22:22 +02:00
$doleditor = new DolEditor ( 'mail_intro' , $mail_intro , '100%' , 90 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_SOCIETE , ROWS_2 , 70 );
2018-03-10 04:23:59 +01:00
$doleditor -> Create ();
2019-12-12 10:31:08 +01:00
print '</td><td class="center">' ;
2018-03-10 04:23:59 +01:00
print $form -> textwithpicto ( '' , $langs -> trans ( " TicketMessageMailIntroHelp " ), 1 , 'help' );
print '</td></tr>' ;
}
// MESSAGE
2019-11-13 19:35:39 +01:00
$defaultmessage = " " ;
2018-03-15 18:43:47 +01:00
if ( is_array ( $arraydefaultmessage ) && count ( $arraydefaultmessage ) > 0 && $arraydefaultmessage -> content ) {
2019-11-13 19:35:39 +01:00
$defaultmessage = $arraydefaultmessage -> content ;
2018-03-10 04:23:59 +01:00
}
2019-11-13 19:35:39 +01:00
$defaultmessage = str_replace ( '\n' , " \n " , $defaultmessage );
2018-03-10 04:23:59 +01:00
// Deal with format differences between message and signature (text / HTML)
if ( dol_textishtml ( $defaultmessage ) && ! dol_textishtml ( $this -> substit [ '__SIGNATURE__' ])) {
$this -> substit [ '__SIGNATURE__' ] = dol_nl2br ( $this -> substit [ '__SIGNATURE__' ]);
} elseif ( ! dol_textishtml ( $defaultmessage ) && dol_textishtml ( $this -> substit [ '__SIGNATURE__' ])) {
$defaultmessage = dol_nl2br ( $defaultmessage );
}
2019-11-13 19:35:39 +01:00
if ( isset ( $_POST [ " message " ]) && ! $_POST [ 'modelselected' ]) {
$defaultmessage = GETPOST ( 'message' );
2018-03-10 04:23:59 +01:00
} else {
2019-11-13 19:35:39 +01:00
$defaultmessage = make_substitutions ( $defaultmessage , $this -> substit );
2018-03-10 04:23:59 +01:00
// Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
2019-11-13 19:35:39 +01:00
$defaultmessage = preg_replace ( " /^(<br>)+/ " , " " , $defaultmessage );
$defaultmessage = preg_replace ( " /^ \n +/ " , " " , $defaultmessage );
2018-03-10 04:23:59 +01:00
}
2019-11-13 19:35:39 +01:00
print '<tr><td class="tdtop"><label for="message"><span class="fieldrequired">' . $langs -> trans ( " Message " ) . '</span></label></td><td>' ;
2019-03-05 12:18:36 +01:00
//$toolbarname = 'dolibarr_details';
$toolbarname = 'dolibarr_notes' ;
2019-11-13 19:35:39 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-03-05 12:18:36 +01:00
$doleditor = new DolEditor ( 'message' , $defaultmessage , '100%' , 200 , $toolbarname , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_SOCIETE , ROWS_5 , 70 );
2018-03-10 04:23:59 +01:00
$doleditor -> Create ();
2019-12-12 10:31:08 +01:00
print '</td><td class="center">' ;
2018-06-04 21:49:29 +02:00
if ( $user -> rights -> ticket -> write && ! $user -> socid ) {
2018-03-10 04:23:59 +01:00
print $form -> textwithpicto ( '' , $langs -> trans ( " TicketMessageHelp " ), 1 , 'help' );
}
print '</td></tr>' ;
// Signature
// External users can't send message email
2018-06-04 21:49:29 +02:00
if ( $user -> rights -> ticket -> write && ! $user -> socid ) {
2018-07-06 13:09:07 +02:00
$mail_signature = GETPOST ( 'mail_signature' ) ? GETPOST ( 'mail_signature' ) : $conf -> global -> TICKET_MESSAGE_MAIL_SIGNATURE ;
2019-11-13 19:35:39 +01:00
print '<tr class="email_line"><td><label for="mail_intro">' . $langs -> trans ( " TicketMessageMailSignature " ) . '</label>' ;
2018-03-10 04:23:59 +01:00
print '</td><td>' ;
2019-11-13 19:35:39 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2018-03-10 04:23:59 +01:00
$doleditor = new DolEditor ( 'mail_signature' , $mail_signature , '100%' , 150 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_SOCIETE , ROWS_2 , 70 );
$doleditor -> Create ();
2019-12-12 10:31:08 +01:00
print '</td><td class="center">' ;
2018-03-10 04:23:59 +01:00
print $form -> textwithpicto ( '' , $langs -> trans ( " TicketMessageMailSignatureHelp " ), 1 , 'help' );
print '</td></tr>' ;
}
// Attached files
if ( ! empty ( $this -> withfile )) {
2019-10-01 13:45:18 +02:00
$out = '<tr>' ;
2019-11-13 19:35:39 +01:00
$out .= '<td width="180">' . $langs -> trans ( " MailFile " ) . '</td>' ;
2018-03-10 04:23:59 +01:00
$out .= '<td colspan="2">' ;
// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
2019-11-13 19:35:39 +01:00
$out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">' . " \n " ;
2018-03-10 04:23:59 +01:00
$out .= '<script type="text/javascript" language="javascript">' ;
$out .= 'jQuery(document).ready(function () {' ;
$out .= ' jQuery(".removedfile").click(function() {' ;
$out .= ' jQuery(".removedfilehidden").val(jQuery(this).val());' ;
$out .= ' });' ;
$out .= '})' ;
2019-11-13 19:35:39 +01:00
$out .= '</script>' . " \n " ;
2018-03-10 04:23:59 +01:00
if ( count ( $listofpaths )) {
foreach ( $listofpaths as $key => $val ) {
2019-11-13 19:35:39 +01:00
$out .= '<div id="attachfile_' . $key . '">' ;
$out .= img_mime ( $listofnames [ $key ]) . ' ' . $listofnames [ $key ];
2018-03-10 04:23:59 +01:00
if ( ! $this -> withfilereadonly ) {
2019-11-13 19:35:39 +01:00
$out .= ' <input type="image" style="border: 0px;" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/delete.png" value="' . ( $key + 1 ) . '" class="removedfile reposition" id="removedfile_' . $key . '" name="removedfile_' . $key . '" />' ;
2018-03-10 04:23:59 +01:00
}
$out .= '<br></div>' ;
}
} else {
2019-11-13 19:35:39 +01:00
$out .= $langs -> trans ( " NoAttachedFiles " ) . '<br>' ;
2018-03-10 04:23:59 +01:00
}
if ( $this -> withfile == 2 ) { // Can add other files
2019-11-13 19:35:39 +01:00
$out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="' . $langs -> trans ( " Upload " ) . '" />' ;
2018-03-10 04:23:59 +01:00
$out .= ' ' ;
2019-11-13 19:35:39 +01:00
$out .= '<input type="submit" class="button" id="' . $addfileaction . '" name="' . $addfileaction . '" value="' . $langs -> trans ( " MailingAddFile " ) . '" />' ;
2018-03-10 04:23:59 +01:00
}
$out .= " </td></tr> \n " ;
print $out ;
}
2019-03-05 12:18:36 +01:00
print '</table>' ;
2018-03-10 04:23:59 +01:00
2019-03-05 12:18:36 +01:00
print '<center><br>' ;
2019-11-13 19:35:39 +01:00
print '<input class="button" type="submit" name="btn_add_message" value="' . $langs -> trans ( " AddMessage " ) . '" />' ;
2018-03-10 04:23:59 +01:00
if ( $this -> withcancel ) {
print " " ;
2019-11-13 19:35:39 +01:00
print " <input class= \" button \" type= \" submit \" name= \" cancel \" value= \" " . $langs -> trans ( " Cancel " ) . " \" > " ;
2018-03-10 04:23:59 +01:00
}
print " </center> \n " ;
print " </form> \n " ;
print " <!-- End form TICKET --> \n " ;
}
}