2018-03-10 04:23:59 +01:00
< ? php
2018-03-11 18:59:45 +01:00
/* Copyright ( C ) 2013 - 2018 Jean - François FERRY < hello @ librethic . io >
2018-03-11 18:54:38 +01:00
* Copyright ( C ) 2016 Christophe Battarel < christophe @ altairis . fr >
2020-11-02 00:26:26 +01:00
* Copyright ( C ) 2019 - 2020 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 3 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
*/
/**
2018-06-04 21:49:29 +02:00
* \file core / lib / ticket . lib . php
* \ingroup ticket
* \brief This file is a library for Ticket module
2018-03-11 11:54:30 +01:00
*/
/**
* Build tabs for admin page
2018-03-11 18:54:38 +01:00
*
2018-03-11 11:54:30 +01:00
* @ return array
2018-03-10 04:23:59 +01:00
*/
2018-06-04 21:49:29 +02:00
function ticketAdminPrepareHead ()
2018-03-10 04:23:59 +01:00
{
2020-09-07 10:18:17 +02:00
global $langs , $conf ;
$langs -> load ( " ticket " );
$h = 0 ;
$head = array ();
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/ticket.php' ;
$head [ $h ][ 1 ] = $langs -> trans ( " TicketSettings " );
$head [ $h ][ 2 ] = 'settings' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/ticket_extrafields.php' ;
$head [ $h ][ 1 ] = $langs -> trans ( " ExtraFieldsTicket " );
$head [ $h ][ 2 ] = 'attributes' ;
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/admin/ticket_public.php' ;
$head [ $h ][ 1 ] = $langs -> trans ( " PublicInterface " );
$head [ $h ][ 2 ] = 'public' ;
$h ++ ;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
//$this->tabs = array(
// 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
//); // to add new tab
//$this->tabs = array(
// 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
//); // to remove a tab
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'ticketadmin' );
2018-03-10 04:23:59 +01:00
2020-08-20 22:17:34 +02:00
complete_head_from_modules ( $conf , $langs , null , $head , $h , 'ticketadmin' , 'remove' );
2020-09-07 10:18:17 +02:00
return $head ;
2018-03-10 04:23:59 +01:00
}
/**
2018-06-04 21:49:29 +02:00
* Build tabs for a Ticket object
2018-03-11 16:07:13 +01:00
*
2018-06-04 21:49:29 +02:00
* @ param Ticket $object Object Ticket
2018-03-11 18:12:47 +01:00
* @ return array Array of tabs
2018-03-10 04:23:59 +01:00
*/
2018-06-04 21:49:29 +02:00
function ticket_prepare_head ( $object )
2018-03-10 04:23:59 +01:00
{
2020-09-07 10:18:17 +02:00
global $db , $langs , $conf , $user ;
2018-03-11 11:12:38 +01:00
2020-09-07 10:18:17 +02:00
$h = 0 ;
$head = array ();
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/ticket/card.php?action=view&track_id=' . $object -> track_id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Ticket " );
$head [ $h ][ 2 ] = 'tabTicket' ;
$h ++ ;
2018-03-10 04:23:59 +01:00
2021-05-16 18:48:18 +02:00
if ( empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ) && empty ( $user -> socid ) && $conf -> societe -> enabled ) {
2020-09-07 10:18:17 +02:00
$nbContact = count ( $object -> liste_contact ( - 1 , 'internal' )) + count ( $object -> liste_contact ( - 1 , 'external' ));
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/ticket/contact.php?track_id=' . $object -> track_id ;
$head [ $h ][ 1 ] = $langs -> trans ( 'ContactsAddresses' );
2021-02-23 22:03:23 +01:00
if ( $nbContact > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbContact . '</span>' ;
}
2020-09-07 10:18:17 +02:00
$head [ $h ][ 2 ] = 'contact' ;
$h ++ ;
}
2018-03-10 04:23:59 +01:00
2020-09-07 10:18:17 +02:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'ticket' );
2018-03-11 16:07:13 +01:00
2020-09-07 10:18:17 +02:00
// Attached files
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
$upload_dir = $conf -> ticket -> dir_output . " / " . $object -> ref ;
$nbFiles = count ( dol_dir_list ( $upload_dir , 'files' ));
$head [ $h ][ 0 ] = dol_buildpath ( '/ticket/document.php' , 1 ) . '?id=' . $object -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Documents " );
if ( $nbFiles > 0 ) {
$head [ $h ][ 1 ] .= '<span class="badge marginleftonlyshort">' . $nbFiles . '</span>' ;
}
2018-03-10 04:23:59 +01:00
2020-09-07 10:18:17 +02:00
$head [ $h ][ 2 ] = 'tabTicketDocument' ;
$h ++ ;
2018-03-10 04:23:59 +01:00
2020-09-07 10:18:17 +02:00
// History
2019-09-16 13:56:07 +02:00
$ticketViewType = " messaging " ;
2019-11-13 19:35:39 +01:00
if ( empty ( $_SESSION [ 'ticket-view-type' ])) {
2019-09-16 13:56:07 +02:00
$_SESSION [ 'ticket-view-type' ] = $ticketViewType ;
2020-05-21 15:05:19 +02:00
} else {
2019-09-16 13:56:07 +02:00
$ticketViewType = $_SESSION [ 'ticket-view-type' ];
}
2019-11-13 19:35:39 +01:00
if ( $ticketViewType == " messaging " ) {
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/ticket/messaging.php?track_id=' . $object -> track_id ;
2020-05-21 15:05:19 +02:00
} else {
2019-09-16 13:56:07 +02:00
// $ticketViewType == "list"
2019-11-13 19:35:39 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/ticket/agenda.php?track_id=' . $object -> track_id ;
2019-09-16 13:56:07 +02:00
}
2020-09-07 10:18:17 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( 'Events' );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> agenda -> enabled ) && ( ! empty ( $user -> rights -> agenda -> myactions -> read ) || ! empty ( $user -> rights -> agenda -> allactions -> read ))) {
2020-09-07 10:18:17 +02:00
$head [ $h ][ 1 ] .= '/' ;
$head [ $h ][ 1 ] .= $langs -> trans ( " Agenda " );
}
$head [ $h ][ 2 ] = 'tabTicketLogs' ;
$h ++ ;
2018-03-10 04:23:59 +01:00
2020-09-07 10:18:17 +02:00
complete_head_from_modules ( $conf , $langs , $object , $head , $h , 'ticket' , 'remove' );
2018-03-10 04:23:59 +01:00
2020-09-07 10:18:17 +02:00
return $head ;
2018-03-10 04:23:59 +01:00
}
2019-10-05 11:52:30 +02:00
/**
* Return string with full Url . The file qualified is the one defined by relative path in $object -> last_main_doc
*
* @ param Object $object Object
* @ return string Url string
*/
function showDirectPublicLink ( $object )
{
global $conf , $langs ;
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
$email = CMailFile :: getValidAddress ( $object -> origin_email , 2 );
2019-10-15 02:54:19 +02:00
$url = '' ;
2021-02-23 22:03:23 +01:00
if ( $email ) {
2019-10-05 11:52:30 +02:00
$url = dol_buildpath ( '/public/ticket/view.php' , 3 ) . '?track_id=' . $object -> track_id . '&email=' . $email ;
}
2019-11-13 19:35:39 +01:00
$out = '' ;
2020-11-02 00:26:26 +01:00
if ( empty ( $conf -> global -> TICKET_ENABLE_PUBLIC_INTERFACE )) {
2021-05-16 18:48:18 +02:00
$langs -> load ( 'errors' );
$out .= '<span class="opacitymedium">' . $langs -> trans ( " ErrorPublicInterfaceNotEnabled " ) . '</span>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-04-15 15:54:54 +02:00
$out .= img_picto ( '' , 'object_globe.png' ) . ' <span class="opacitymedium">' . $langs -> trans ( " TicketPublicAccess " ) . '</span><br>' ;
2020-11-02 00:26:26 +01:00
if ( $url ) {
2021-04-15 15:54:54 +02:00
$out .= '<div class="urllink">' ;
2019-11-13 19:35:39 +01:00
$out .= '<input type="text" id="directpubliclink" class="quatrevingtpercent" value="' . $url . '">' ;
2021-04-15 15:54:54 +02:00
$out .= '<a href="' . $url . '" target="_blank" rel="noopener">' . img_picto ( '' , 'object_globe.png' , 'class="paddingleft"' ) . '</a>' ;
$out .= '</div>' ;
2019-11-13 19:35:39 +01:00
$out .= ajax_autoselect ( " directpubliclink " , 0 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$out .= '<span class="opacitymedium">' . $langs -> trans ( " TicketNotCreatedFromPublicInterface " ) . '</span>' ;
2019-10-05 11:52:30 +02:00
}
}
return $out ;
}
2018-03-10 04:23:59 +01:00
/**
2019-11-12 21:53:17 +01:00
* Generate a random id
2018-03-10 04:23:59 +01:00
*
2019-11-12 21:53:17 +01:00
* @ param int $car Length of string to generate key
* @ return string
2018-03-10 04:23:59 +01:00
*/
2019-01-27 15:20:16 +01:00
function generate_random_id ( $car = 16 )
2018-03-10 04:23:59 +01:00
{
2020-09-07 10:18:17 +02:00
$string = " " ;
$chaine = " abcdefghijklmnopqrstuvwxyz123456789 " ;
srand (( double ) microtime () * 1000000 );
for ( $i = 0 ; $i < $car ; $i ++ ) {
$string .= $chaine [ rand () % strlen ( $chaine )];
}
return $string ;
2018-03-10 04:23:59 +01:00
}
/**
* Show header for public pages
*
* @ param string $title Title
* @ param string $head Head array
* @ param int $disablejs More content into html header
* @ param int $disablehead More content into html header
* @ param array $arrayofjs Array of complementary js files
* @ param array $arrayofcss Array of complementary css files
* @ return void
*/
function llxHeaderTicket ( $title , $head = " " , $disablejs = 0 , $disablehead = 0 , $arrayofjs = '' , $arrayofcss = '' )
{
2020-09-08 21:27:28 +02:00
global $user , $conf , $langs , $mysoc ;
2020-11-07 12:47:42 +01:00
top_htmlhead ( $head , $title , $disablejs , $disablehead , $arrayofjs , $arrayofcss , 0 , 1 ); // Show html headers
2020-09-08 21:27:28 +02:00
print '<body id="mainbody" class="publicnewticketform">' ;
print '<div class="center">' ;
// Define urllogo
if ( ! empty ( $conf -> global -> TICKET_SHOW_COMPANY_LOGO ) || ! empty ( $conf -> global -> TICKET_PUBLIC_INTERFACE_TOPIC )) {
// Print logo
2020-11-02 00:26:26 +01:00
if ( ! empty ( $conf -> global -> TICKET_SHOW_COMPANY_LOGO )) {
2020-09-08 21:27:28 +02:00
$urllogo = DOL_URL_ROOT . '/theme/common/login_logo.png' ;
if ( ! empty ( $mysoc -> logo_small ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/thumbs/' . $mysoc -> logo_small )) {
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/thumbs/' . $mysoc -> logo_small );
} elseif ( ! empty ( $mysoc -> logo ) && is_readable ( $conf -> mycompany -> dir_output . '/logos/' . $mysoc -> logo )) {
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=mycompany&entity=' . $conf -> entity . '&file=' . urlencode ( 'logos/' . $mysoc -> logo );
} elseif ( is_readable ( DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.svg' )) {
$urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.svg' ;
}
}
}
// Output html code for logo
2020-11-02 00:26:26 +01:00
if ( $urllogo || ! empty ( $conf -> global -> TICKET_PUBLIC_INTERFACE_TOPIC )) {
2020-09-08 21:27:28 +02:00
print '<div class="backgreypublicpayment">' ;
print '<div class="logopublicpayment">' ;
if ( $urllogo ) {
print '<a href="' . ( $conf -> global -> TICKET_URL_PUBLIC_INTERFACE ? $conf -> global -> TICKET_URL_PUBLIC_INTERFACE : dol_buildpath ( '/public/ticket/index.php' , 1 )) . '">' ;
print '<img id="dolpaymentlogo" src="' . $urllogo . '"' ;
print '>' ;
print '</a>' ;
}
if ( ! empty ( $conf -> global -> TICKET_PUBLIC_INTERFACE_TOPIC )) {
print '<div class="clearboth"></div><strong>' . ( $conf -> global -> TICKET_PUBLIC_INTERFACE_TOPIC ? $conf -> global -> TICKET_PUBLIC_INTERFACE_TOPIC : $langs -> trans ( " TicketSystem " )) . '</strong>' ;
}
print '</div>' ;
if ( empty ( $conf -> global -> MAIN_HIDE_POWERED_BY )) {
2021-04-15 15:54:54 +02:00
print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">' . $langs -> trans ( " PoweredBy " ) . '<br><img src="' . DOL_URL_ROOT . '/theme/dolibarr_logo.svg" width="80px"></a></div>' ;
2020-09-08 21:27:28 +02:00
}
print '</div>' ;
}
2021-06-19 20:05:25 +02:00
if ( ! empty ( $conf -> global -> TICKET_IMAGE_PUBLIC_INTERFACE )) {
print '<div class="backimagepublicticket">' ;
print '<img id="idRECRUITMENT_IMAGE_PUBLIC_INTERFACE" src="' . $conf -> global -> MEMBER_IMAGE_PUBLIC_REGISTRATION . '">' ;
print '</div>' ;
}
2020-09-08 21:27:28 +02:00
print '</div>' ;
print '<div class="ticketlargemargin">' ;
2018-03-10 04:23:59 +01:00
}
2019-09-11 23:30:09 +02:00
/**
* Show html area with actions for ticket messaging .
* Note : Global parameter $param must be defined .
*
* @ param Conf $conf Object conf
* @ param Translate $langs Object langs
* @ param DoliDB $db Object db
* @ param mixed $filterobj Filter on object Adherent | Societe | Project | Product | CommandeFournisseur | Dolresource | Ticket |... to list events linked to an object
* @ param Contact $objcon Filter on object contact to filter events on a contact
* @ param int $noprint Return string but does not output it
* @ param string $actioncode Filter on actioncode
* @ param string $donetodo Filter on event 'done' or 'todo' or '' = nofilter ( all ) .
* @ param array $filters Filter on other fields
* @ param string $sortfield Sort field
* @ param string $sortorder Sort order
* @ return string | void Return html part or void if noprint is 1
*/
function show_ticket_messaging ( $conf , $langs , $db , $filterobj , $objcon = '' , $noprint = 0 , $actioncode = '' , $donetodo = 'done' , $filters = array (), $sortfield = 'a.datep,a.id' , $sortorder = 'DESC' )
{
2020-09-07 10:18:17 +02:00
global $user , $conf ;
global $form ;
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
global $param , $massactionbutton ;
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
dol_include_once ( '/comm/action/class/actioncomm.class.php' );
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
// Check parameters
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $filterobj ) && ! is_object ( $objcon )) {
dol_print_error ( '' , 'BadParameter' );
}
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
$histo = array ();
$numaction = 0 ;
2021-02-02 00:19:41 +01:00
$now = dol_now ();
2020-09-07 10:18:17 +02:00
$sortfield_list = explode ( ',' , $sortfield );
$sortfield_label_list = array ( 'a.id' => 'id' , 'a.datep' => 'dp' , 'a.percent' => 'percent' );
$sortfield_new_list = array ();
foreach ( $sortfield_list as $sortfield_value ) {
$sortfield_new_list [] = $sortfield_label_list [ trim ( $sortfield_value )];
}
$sortfield_new = implode ( ',' , $sortfield_new_list );
2019-09-11 23:30:09 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> agenda -> enabled )) {
2021-03-04 15:57:03 +01:00
// Search histo on actioncomm
2020-09-07 10:18:17 +02:00
if ( is_object ( $objcon ) && $objcon -> id > 0 ) {
$sql = " SELECT DISTINCT a.id, a.label as label, " ;
} else {
$sql = " SELECT a.id, a.label as label, " ;
}
$sql .= " a.datep as dp, " ;
$sql .= " a.note as message, " ;
$sql .= " a.datep2 as dp2, " ;
$sql .= " a.percent as percent, 'action' as type, " ;
$sql .= " a.fk_element, a.elementtype, " ;
$sql .= " a.fk_contact, " ;
$sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto, " ;
$sql .= " u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname " ;
2020-11-02 00:26:26 +01:00
if ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Societe' ) {
$sql .= " , sp.lastname, sp.firstname " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Adherent' ) {
$sql .= " , m.lastname, m.firstname " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'CommandeFournisseur' ) {
$sql .= " , o.ref " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Product' ) {
$sql .= " , o.ref " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Ticket' ) {
$sql .= " , o.ref " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'BOM' ) {
$sql .= " , o.ref " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Contrat' ) {
$sql .= " , o.ref " ;
}
2020-09-07 10:18:17 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm as a " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u on u.rowid = a.fk_user_action " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_actioncomm as c ON a.fk_action = c.id " ;
$force_filter_contact = false ;
if ( is_object ( $objcon ) && $objcon -> id > 0 ) {
$force_filter_contact = true ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " actioncomm_resources as r ON a.id = r.fk_actioncomm " ;
2021-06-09 15:36:47 +02:00
$sql .= " AND r.element_type = ' " . $db -> escape ( $objcon -> table_element ) . " ' AND r.fk_element = " . (( int ) $objcon -> id );
2020-09-07 10:18:17 +02:00
}
2019-09-11 23:30:09 +02:00
2020-11-02 00:26:26 +01:00
if ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Societe' ) {
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " socpeople as sp ON a.fk_contact = sp.rowid " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Dolresource' ) {
2020-09-07 10:18:17 +02:00
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " element_resources as er " ;
$sql .= " ON er.resource_type = 'dolresource' " ;
$sql .= " AND er.element_id = a.id " ;
$sql .= " AND er.resource_id = " . $filterobj -> id ;
2020-11-02 00:26:26 +01:00
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Adherent' ) {
$sql .= " , " . MAIN_DB_PREFIX . " adherent as m " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'CommandeFournisseur' ) {
$sql .= " , " . MAIN_DB_PREFIX . " commande_fournisseur as o " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Product' ) {
$sql .= " , " . MAIN_DB_PREFIX . " product as o " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Ticket' ) {
$sql .= " , " . MAIN_DB_PREFIX . " ticket as o " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'BOM' ) {
$sql .= " , " . MAIN_DB_PREFIX . " bom_bom as o " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Contrat' ) {
$sql .= " , " . MAIN_DB_PREFIX . " contrat as o " ;
}
2020-09-07 10:18:17 +02:00
$sql .= " WHERE a.entity IN ( " . getEntity ( 'agenda' ) . " ) " ;
if ( $force_filter_contact === false ) {
2020-11-02 00:26:26 +01:00
if ( is_object ( $filterobj ) && in_array ( get_class ( $filterobj ), array ( 'Societe' , 'Client' , 'Fournisseur' )) && $filterobj -> id ) {
$sql .= " AND a.fk_soc = " . $filterobj -> id ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Project' && $filterobj -> id ) {
$sql .= " AND a.fk_project = " . $filterobj -> id ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Adherent' ) {
2020-09-07 10:18:17 +02:00
$sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member' " ;
2021-02-23 22:03:23 +01:00
if ( $filterobj -> id ) {
$sql .= " AND a.fk_element = " . $filterobj -> id ;
}
2020-11-02 00:26:26 +01:00
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'CommandeFournisseur' ) {
2020-09-07 10:18:17 +02:00
$sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier' " ;
2021-02-23 22:03:23 +01:00
if ( $filterobj -> id ) {
$sql .= " AND a.fk_element = " . $filterobj -> id ;
}
2020-11-02 00:26:26 +01:00
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Product' ) {
2020-09-07 10:18:17 +02:00
$sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product' " ;
2021-02-23 22:03:23 +01:00
if ( $filterobj -> id ) {
$sql .= " AND a.fk_element = " . $filterobj -> id ;
}
2020-11-02 00:26:26 +01:00
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Ticket' ) {
2020-09-07 10:18:17 +02:00
$sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket' " ;
2021-02-23 22:03:23 +01:00
if ( $filterobj -> id ) {
$sql .= " AND a.fk_element = " . $filterobj -> id ;
}
2020-11-02 00:26:26 +01:00
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'BOM' ) {
2020-09-07 10:18:17 +02:00
$sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom' " ;
2021-02-23 22:03:23 +01:00
if ( $filterobj -> id ) {
$sql .= " AND a.fk_element = " . $filterobj -> id ;
}
2020-11-02 00:26:26 +01:00
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Contrat' ) {
2020-09-07 10:18:17 +02:00
$sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract' " ;
2021-02-23 22:03:23 +01:00
if ( $filterobj -> id ) {
$sql .= " AND a.fk_element = " . $filterobj -> id ;
}
2020-09-07 10:18:17 +02:00
}
}
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
// Condition on actioncode
2020-11-02 00:26:26 +01:00
if ( ! empty ( $actioncode )) {
if ( empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE )) {
if ( $actioncode == 'AC_NON_AUTO' ) {
$sql .= " AND c.type != 'systemauto' " ;
} elseif ( $actioncode == 'AC_ALL_AUTO' ) {
$sql .= " AND c.type = 'systemauto' " ;
} else {
if ( $actioncode == 'AC_OTH' ) {
$sql .= " AND c.type != 'systemauto' " ;
} elseif ( $actioncode == 'AC_OTH_AUTO' ) {
$sql .= " AND c.type = 'systemauto' " ;
}
2020-09-07 10:18:17 +02:00
}
} else {
2021-02-23 22:03:23 +01:00
if ( $actioncode == 'AC_NON_AUTO' ) {
$sql .= " AND c.type != 'systemauto' " ;
} elseif ( $actioncode == 'AC_ALL_AUTO' ) {
$sql .= " AND c.type = 'systemauto' " ;
} else {
$sql .= " AND c.code = ' " . $db -> escape ( $actioncode ) . " ' " ;
}
2020-09-07 10:18:17 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( $donetodo == 'todo' ) {
$sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > ' " . $db -> idate ( $now ) . " ')) " ;
} elseif ( $donetodo == 'done' ) {
$sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= ' " . $db -> idate ( $now ) . " ')) " ;
}
if ( is_array ( $filters ) && $filters [ 'search_agenda_label' ]) {
$sql .= natural_search ( 'a.label' , $filters [ 'search_agenda_label' ]);
}
2020-09-07 10:18:17 +02:00
}
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
// Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
if ( ! empty ( $conf -> mailing -> enabled ) && ! empty ( $objcon -> email )
2021-02-23 22:03:23 +01:00
&& ( empty ( $actioncode ) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING' )) {
2020-09-07 10:18:17 +02:00
$langs -> load ( " mails " );
$sql2 = " SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type " ;
$sql2 .= " , null as fk_element, '' as elementtype, null as contact_id " ;
$sql2 .= " , 'AC_EMAILING' as acode, '' as alabel, '' as apicto " ;
$sql2 .= " , u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname " ; // User that valid action
2020-11-02 00:26:26 +01:00
if ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Societe' ) {
$sql2 .= " , '' as lastname, '' as firstname " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Adherent' ) {
$sql2 .= " , '' as lastname, '' as firstname " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'CommandeFournisseur' ) {
$sql2 .= " , '' as ref " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Product' ) {
$sql2 .= " , '' as ref " ;
} elseif ( is_object ( $filterobj ) && get_class ( $filterobj ) == 'Ticket' ) {
$sql2 .= " , '' as ref " ;
}
2020-09-07 10:18:17 +02:00
$sql2 .= " FROM " . MAIN_DB_PREFIX . " mailing as m, " . MAIN_DB_PREFIX . " mailing_cibles as mc, " . MAIN_DB_PREFIX . " user as u " ;
$sql2 .= " WHERE mc.email = ' " . $db -> escape ( $objcon -> email ) . " ' " ; // Search is done on email.
$sql2 .= " AND mc.statut = 1 " ;
$sql2 .= " AND u.rowid = m.fk_user_valid " ;
$sql2 .= " AND mc.fk_mailing=m.rowid " ;
}
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
if ( ! empty ( $sql ) && ! empty ( $sql2 )) {
$sql = $sql . " UNION " . $sql2 ;
} elseif ( empty ( $sql ) && ! empty ( $sql2 )) {
$sql = $sql2 ;
}
2019-09-11 23:30:09 +02:00
2021-03-04 15:57:03 +01:00
// TODO Add limit in nb of results
if ( $sql ) { // May not be defined if module Agenda is not enabled and mailing module disabled too
$sql .= $db -> order ( $sortfield_new , $sortorder );
dol_syslog ( " company.lib::show_actions_done " , LOG_DEBUG );
$resql = $db -> query ( $sql );
if ( $resql ) {
$i = 0 ;
$num = $db -> num_rows ( $resql );
while ( $i < $num ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj -> type == 'action' ) {
$contactaction = new ActionComm ( $db );
$contactaction -> id = $obj -> id ;
$result = $contactaction -> fetchResources ();
if ( $result < 0 ) {
dol_print_error ( $db );
setEventMessage ( " company.lib::show_actions_done Error fetch ressource " , 'errors' );
}
2019-09-11 23:30:09 +02:00
2021-03-04 15:57:03 +01:00
//if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
//elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
$tododone = '' ;
2021-03-05 19:29:09 +01:00
if (( $obj -> percent >= 0 and $obj -> percent < 100 ) || ( $obj -> percent == - 1 && $obj -> datep > $now )) {
$tododone = 'todo' ;
}
2021-03-04 15:57:03 +01:00
$histo [ $numaction ] = array (
'type' => $obj -> type ,
'tododone' => $tododone ,
'id' => $obj -> id ,
'datestart' => $db -> jdate ( $obj -> dp ),
'dateend' => $db -> jdate ( $obj -> dp2 ),
'note' => $obj -> label ,
'message' => $obj -> message ,
'percent' => $obj -> percent ,
'userid' => $obj -> user_id ,
'login' => $obj -> user_login ,
'userfirstname' => $obj -> user_firstname ,
'userlastname' => $obj -> user_lastname ,
'userphoto' => $obj -> user_photo ,
'contact_id' => $obj -> fk_contact ,
'socpeopleassigned' => $contactaction -> socpeopleassigned ,
'lastname' => $obj -> lastname ,
'firstname' => $obj -> firstname ,
'fk_element' => $obj -> fk_element ,
'elementtype' => $obj -> elementtype ,
// Type of event
'acode' => $obj -> acode ,
'alabel' => $obj -> alabel ,
'libelle' => $obj -> alabel , // deprecated
'apicto' => $obj -> apicto
);
} else {
$histo [ $numaction ] = array (
'type' => $obj -> type ,
'tododone' => 'done' ,
'id' => $obj -> id ,
'datestart' => $db -> jdate ( $obj -> dp ),
'dateend' => $db -> jdate ( $obj -> dp2 ),
'note' => $obj -> label ,
'message' => $obj -> message ,
'percent' => $obj -> percent ,
'acode' => $obj -> acode ,
'userid' => $obj -> user_id ,
'login' => $obj -> user_login ,
'userfirstname' => $obj -> user_firstname ,
'userlastname' => $obj -> user_lastname ,
'userphoto' => $obj -> user_photo
);
2021-02-23 22:03:23 +01:00
}
2020-09-07 10:18:17 +02:00
2021-03-04 15:57:03 +01:00
$numaction ++ ;
$i ++ ;
2020-09-07 10:18:17 +02:00
}
2021-03-04 15:57:03 +01:00
} else {
dol_print_error ( $db );
2020-09-07 10:18:17 +02:00
}
2021-03-04 15:57:03 +01:00
}
// Set $out to sow events
$out = '' ;
if ( empty ( $conf -> agenda -> enabled )) {
$langs -> loadLangs ( array ( " admin " , " errors " ));
$out = info_admin ( $langs -> trans ( " WarningModuleXDisabledSoYouMayMissEventHere " , $langs -> transnoentitiesnoconv ( " Module2400Name " )), 0 , 0 , 'warning' );
2020-09-07 10:18:17 +02:00
}
2020-11-02 00:26:26 +01:00
if ( ! empty ( $conf -> agenda -> enabled ) || ( ! empty ( $conf -> mailing -> enabled ) && ! empty ( $objcon -> email ))) {
2020-09-07 10:18:17 +02:00
$delay_warning = $conf -> global -> MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60 ;
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
$formactions = new FormActions ( $db );
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
$actionstatic = new ActionComm ( $db );
$userstatic = new User ( $db );
$contactstatic = new Contact ( $db );
$userGetNomUrlCache = array ();
2019-09-18 13:43:34 +02:00
2019-11-13 19:35:39 +01:00
$out .= '<div class="filters-container" >' ;
$out .= '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' ;
2020-09-28 16:33:27 +02:00
$out .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-09-18 13:43:34 +02:00
if ( $objcon && get_class ( $objcon ) == 'Contact' &&
2020-11-02 00:26:26 +01:00
( is_null ( $filterobj ) || get_class ( $filterobj ) == 'Societe' )) {
2019-11-13 19:35:39 +01:00
$out .= '<input type="hidden" name="id" value="' . $objcon -> id . '" />' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$out .= '<input type="hidden" name="id" value="' . $filterobj -> id . '" />' ;
2019-09-18 13:43:34 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $filterobj && get_class ( $filterobj ) == 'Societe' ) {
$out .= '<input type="hidden" name="socid" value="' . $filterobj -> id . '" />' ;
}
2019-09-18 13:43:34 +02:00
2019-11-13 19:35:39 +01:00
$out .= " \n " ;
2019-09-18 13:43:34 +02:00
2019-11-13 19:35:39 +01:00
$out .= '<div class="div-table-responsive-no-min">' ;
$out .= '<table class="noborder borderbottom centpercent">' ;
2019-09-18 13:43:34 +02:00
2019-11-13 19:35:39 +01:00
$out .= '<tr class="liste_titre">' ;
2019-09-30 17:08:57 +02:00
2019-10-01 12:02:28 +02:00
//$out.='<td class="liste_titre">';
2019-10-01 12:03:17 +02:00
$out .= getTitleFieldOfList ( 'Date' , 0 , $_SERVER [ " PHP_SELF " ], 'a.datep' , '' , $param , '' , $sortfield , $sortorder , '' ) . " \n " ;
2019-10-01 12:02:28 +02:00
//$out.='</td>';
2019-09-30 17:08:57 +02:00
2020-12-17 12:09:12 +01:00
$out .= '<th class="liste_titre"><strong class="hideonsmartphone">' . $langs -> trans ( " Search " ) . ' : </strong></th>' ;
2020-11-02 00:26:26 +01:00
if ( $donetodo ) {
2019-11-13 19:35:39 +01:00
$out .= '<th class="liste_titre"></th>' ;
2019-09-18 13:43:34 +02:00
}
2019-11-13 19:35:39 +01:00
$out .= '<th class="liste_titre">' . $langs -> trans ( " Type " ) . ' ' ;
2020-12-17 12:09:12 +01:00
$out .= $formactions -> select_type_actions ( $actioncode , " actioncode " , '' , empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE ) ? 1 : - 1 , 0 , 0 , 1 , 'minwidth200imp' );
2019-11-13 19:35:39 +01:00
$out .= '</th>' ;
$out .= '<th class="liste_titre maxwidth100onsmartphone">' ;
2020-12-17 12:09:12 +01:00
$out .= '<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="' . $filters [ 'search_agenda_label' ] . '" placeholder="' . $langs -> trans ( " Label " ) . '">' ;
2019-11-13 19:35:39 +01:00
$out .= '</th>' ;
2019-09-18 13:43:34 +02:00
2019-11-13 19:35:39 +01:00
$out .= '<th class="liste_titre width50 middle">' ;
$searchpicto = $form -> showFilterAndCheckAddButtons ( $massactionbutton ? 1 : 0 , 'checkforselect' , 1 );
$out .= $searchpicto ;
$out .= '</th>' ;
$out .= '</tr>' ;
2019-09-18 13:43:34 +02:00
2019-11-13 19:35:39 +01:00
$out .= '</table>' ;
2019-09-18 13:43:34 +02:00
2020-09-07 10:18:17 +02:00
$out .= '</form>' ;
2019-11-13 19:35:39 +01:00
$out .= '</div>' ;
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
$out .= " \n " ;
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
$out .= '<ul class="timeline">' ;
2019-09-11 23:30:09 +02:00
2020-11-02 00:26:26 +01:00
if ( $donetodo ) {
2020-09-07 10:18:17 +02:00
$tmp = '' ;
2021-02-23 22:03:23 +01:00
if ( get_class ( $filterobj ) == 'Societe' ) {
$tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?action=show_list&socid=' . $filterobj -> id . '&status=done">' ;
}
2020-09-07 10:18:17 +02:00
$tmp .= ( $donetodo != 'done' ? $langs -> trans ( " ActionsToDoShort " ) : '' );
$tmp .= ( $donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '' );
$tmp .= ( $donetodo != 'todo' ? $langs -> trans ( " ActionsDoneShort " ) : '' );
//$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
2021-02-23 22:03:23 +01:00
if ( get_class ( $filterobj ) == 'Societe' ) {
$tmp .= '</a>' ;
}
2020-09-07 10:18:17 +02:00
$out .= getTitleFieldOfList ( $tmp );
}
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
//require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
//$caction=new CActionComm($db);
//$arraylist=$caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:0), '', 1);
$actualCycleDate = false ;
2021-02-23 22:03:23 +01:00
foreach ( $histo as $key => $value ) {
2020-09-07 10:18:17 +02:00
$actionstatic -> fetch ( $histo [ $key ][ 'id' ]); // TODO Do we need this, we already have a lot of data of line into $histo
$actionstatic -> type_picto = $histo [ $key ][ 'apicto' ];
$actionstatic -> type_code = $histo [ $key ][ 'acode' ];
$url = DOL_URL_ROOT . '/comm/action/card.php?id=' . $histo [ $key ][ 'id' ];
$tmpa = dol_getdate ( $histo [ $key ][ 'datestart' ], false );
if ( $actualCycleDate !== $tmpa [ 'year' ] . '-' . $tmpa [ 'yday' ]) {
$actualCycleDate = $tmpa [ 'year' ] . '-' . $tmpa [ 'yday' ];
$out .= '<!-- timeline time label -->' ;
$out .= '<li class="time-label">' ;
$out .= '<span class="timeline-badge-date">' ;
2021-02-02 00:19:41 +01:00
$out .= dol_print_date ( $histo [ $key ][ 'datestart' ], 'daytext' , 'tzuserrel' , $langs );
2020-09-07 10:18:17 +02:00
$out .= '</span>' ;
$out .= '</li>' ;
$out .= '<!-- /.timeline-label -->' ;
}
$out .= '<!-- timeline item -->' . " \n " ;
$out .= '<li class="timeline-code-' . strtolower ( $actionstatic -> code ) . '">' ;
2020-11-02 00:26:26 +01:00
$out .= getTicketTimelineIcon ( $actionstatic , $histo , $key );
2020-09-07 10:18:17 +02:00
$out .= '<div class="timeline-item">' . " \n " ;
$out .= '<span class="timeline-header-action">' ;
2019-09-12 00:37:36 +02:00
2019-11-13 19:35:39 +01:00
if ( isset ( $histo [ $key ][ 'type' ]) && $histo [ $key ][ 'type' ] == 'mailing' ) {
$out .= '<a class="timeline-btn" href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo [ $key ][ 'id' ] . '">' . img_object ( $langs -> trans ( " ShowEMailing " ), " email " ) . ' ' ;
$out .= $histo [ $key ][ 'id' ];
$out .= '</a> ' ;
2019-09-18 13:43:34 +02:00
} else {
2020-05-07 22:52:32 +02:00
$out .= $actionstatic -> getNomUrl ( 1 , - 1 , 'valignmiddle' ) . ' ' ;
2019-09-18 13:43:34 +02:00
}
2020-09-07 10:18:17 +02:00
//if ($user->rights->agenda->allactions->read || $actionstatic->authorid == $user->id)
//{
// $out.='<a href="'.$url.'" class="timeline-btn" title="'.$langs->trans('Show').'" ><i class="fa fa-calendar" ></i>'.$langs->trans('Show').'</a>';
//}
if ( $user -> rights -> agenda -> allactions -> create ||
2021-02-23 22:03:23 +01:00
(( $actionstatic -> authorid == $user -> id || $actionstatic -> userownerid == $user -> id ) && $user -> rights -> agenda -> myactions -> create )) {
2020-09-07 10:18:17 +02:00
$out .= '<a class="timeline-btn" href="' . DOL_MAIN_URL_ROOT . '/comm/action/card.php?action=edit&id=' . $actionstatic -> id . '"><i class="fa fa-pencil" title="' . $langs -> trans ( " Modify " ) . '" ></i></a>' ;
}
$out .= '</span>' ;
// Date
$out .= '<span class="time"><i class="fa fa-clock-o"></i> ' ;
2021-02-02 00:19:41 +01:00
$out .= dol_print_date ( $histo [ $key ][ 'datestart' ], 'dayhour' , 'tzuserrel' );
2020-11-02 00:26:26 +01:00
if ( $histo [ $key ][ 'dateend' ] && $histo [ $key ][ 'dateend' ] != $histo [ $key ][ 'datestart' ]) {
2020-09-07 10:18:17 +02:00
$tmpa = dol_getdate ( $histo [ $key ][ 'datestart' ], true );
$tmpb = dol_getdate ( $histo [ $key ][ 'dateend' ], true );
2020-11-02 00:26:26 +01:00
if ( $tmpa [ 'mday' ] == $tmpb [ 'mday' ] && $tmpa [ 'mon' ] == $tmpb [ 'mon' ] && $tmpa [ 'year' ] == $tmpb [ 'year' ]) {
2021-02-02 00:19:41 +01:00
$out .= '-' . dol_print_date ( $histo [ $key ][ 'dateend' ], 'hour' , 'tzuserrel' );
2020-11-02 00:26:26 +01:00
} else {
2021-02-02 00:19:41 +01:00
$out .= '-' . dol_print_date ( $histo [ $key ][ 'dateend' ], 'dayhour' , 'tzuserrel' );
2020-11-02 00:26:26 +01:00
}
2020-09-07 10:18:17 +02:00
}
$late = 0 ;
2021-02-23 22:03:23 +01:00
if ( $histo [ $key ][ 'percent' ] == 0 && $histo [ $key ][ 'datestart' ] && $histo [ $key ][ 'datestart' ] < ( $now - $delay_warning )) {
$late = 1 ;
}
if ( $histo [ $key ][ 'percent' ] == 0 && ! $histo [ $key ][ 'datestart' ] && $histo [ $key ][ 'dateend' ] && $histo [ $key ][ 'datestart' ] < ( $now - $delay_warning )) {
$late = 1 ;
}
if ( $histo [ $key ][ 'percent' ] > 0 && $histo [ $key ][ 'percent' ] < 100 && $histo [ $key ][ 'dateend' ] && $histo [ $key ][ 'dateend' ] < ( $now - $delay_warning )) {
$late = 1 ;
}
if ( $histo [ $key ][ 'percent' ] > 0 && $histo [ $key ][ 'percent' ] < 100 && ! $histo [ $key ][ 'dateend' ] && $histo [ $key ][ 'datestart' ] && $histo [ $key ][ 'datestart' ] < ( $now - $delay_warning )) {
$late = 1 ;
}
if ( $late ) {
$out .= img_warning ( $langs -> trans ( " Late " )) . ' ' ;
}
2020-09-07 10:18:17 +02:00
$out .= " </span> \n " ;
// Ref
$out .= '<h3 class="timeline-header">' ;
// Author of event
$out .= '<span class="messaging-author">' ;
2021-02-23 22:03:23 +01:00
if ( $histo [ $key ][ 'userid' ] > 0 ) {
2020-09-07 10:18:17 +02:00
if ( ! isset ( $userGetNomUrlCache [ $histo [ $key ][ 'userid' ]])) { // is in cache ?
$userstatic -> fetch ( $histo [ $key ][ 'userid' ]);
$userGetNomUrlCache [ $histo [ $key ][ 'userid' ]] = $userstatic -> getNomUrl ( - 1 , '' , 0 , 0 , 16 , 0 , 'firstelselast' , '' );
}
$out .= $userGetNomUrlCache [ $histo [ $key ][ 'userid' ]];
}
$out .= '</span>' ;
// Title
$out .= ' <span class="messaging-title">' ;
2019-09-12 00:37:36 +02:00
2020-04-10 10:59:32 +02:00
if ( $actionstatic -> code == 'TICKET_MSG' ) {
2019-09-12 18:39:29 +02:00
$out .= $langs -> trans ( 'TicketNewMessage' );
2020-05-21 15:05:19 +02:00
} elseif ( $actionstatic -> code == 'TICKET_MSG_PRIVATE' ) {
2019-09-12 18:39:29 +02:00
$out .= $langs -> trans ( 'TicketNewMessage' ) . ' <em>(' . $langs -> trans ( 'Private' ) . ')</em>' ;
2020-04-10 10:59:32 +02:00
} else {
2020-09-07 10:18:17 +02:00
if ( isset ( $histo [ $key ][ 'type' ]) && $histo [ $key ][ 'type' ] == 'action' ) {
$transcode = $langs -> trans ( " Action " . $histo [ $key ][ 'acode' ]);
$libelle = ( $transcode != " Action " . $histo [ $key ][ 'acode' ] ? $transcode : $histo [ $key ][ 'alabel' ]);
$libelle = $histo [ $key ][ 'note' ];
$actionstatic -> id = $histo [ $key ][ 'id' ];
$out .= dol_trunc ( $libelle , 120 );
}
if ( isset ( $histo [ $key ][ 'type' ]) && $histo [ $key ][ 'type' ] == 'mailing' ) {
$out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo [ $key ][ 'id' ] . '">' . img_object ( $langs -> trans ( " ShowEMailing " ), " email " ) . ' ' ;
$transcode = $langs -> trans ( " Action " . $histo [ $key ][ 'acode' ]);
$libelle = ( $transcode != " Action " . $histo [ $key ][ 'acode' ] ? $transcode : 'Send mass mailing' );
$out .= dol_trunc ( $libelle , 120 );
}
}
$out .= '</span>' ;
$out .= '</h3>' ;
if ( ! empty ( $histo [ $key ][ 'message' ])
&& $actionstatic -> code != 'AC_TICKET_CREATE'
&& $actionstatic -> code != 'AC_TICKET_MODIFY'
2021-02-23 22:03:23 +01:00
) {
2020-09-07 10:18:17 +02:00
$out .= '<div class="timeline-body">' ;
$out .= $histo [ $key ][ 'message' ];
$out .= '</div>' ;
}
// Timeline footer
$footer = '' ;
// Contact for this action
if ( isset ( $histo [ $key ][ 'socpeopleassigned' ]) && is_array ( $histo [ $key ][ 'socpeopleassigned' ]) && count ( $histo [ $key ][ 'socpeopleassigned' ]) > 0 ) {
$contactList = '' ;
foreach ( $histo [ $key ][ 'socpeopleassigned' ] as $cid => $Tab ) {
$contact = new Contact ( $db );
$result = $contact -> fetch ( $cid );
2020-11-02 00:26:26 +01:00
if ( $result < 0 ) {
2020-09-07 10:18:17 +02:00
dol_print_error ( $db , $contact -> error );
2020-11-02 00:26:26 +01:00
}
2020-09-07 10:18:17 +02:00
if ( $result > 0 ) {
$contactList .= ! empty ( $contactList ) ? ', ' : '' ;
$contactList .= $contact -> getNomUrl ( 1 );
if ( isset ( $histo [ $key ][ 'acode' ]) && $histo [ $key ][ 'acode' ] == 'AC_TEL' ) {
2021-02-23 22:03:23 +01:00
if ( ! empty ( $contact -> phone_pro )) {
2020-09-07 10:18:17 +02:00
$contactList .= '(' . dol_print_phone ( $contact -> phone_pro ) . ')' ;
2021-02-23 22:03:23 +01:00
}
2020-09-07 10:18:17 +02:00
}
}
}
$footer .= $langs -> trans ( 'ActionOnContact' ) . ' : ' . $contactList ;
2020-11-02 00:26:26 +01:00
} elseif ( empty ( $objcon -> id ) && isset ( $histo [ $key ][ 'contact_id' ]) && $histo [ $key ][ 'contact_id' ] > 0 ) {
2020-09-07 10:18:17 +02:00
$contact = new Contact ( $db );
$result = $contact -> fetch ( $histo [ $key ][ 'contact_id' ]);
2021-02-23 22:03:23 +01:00
if ( $result < 0 ) {
2020-09-07 10:18:17 +02:00
dol_print_error ( $db , $contact -> error );
2021-02-23 22:03:23 +01:00
}
2020-09-07 10:18:17 +02:00
if ( $result > 0 ) {
$footer .= $contact -> getNomUrl ( 1 );
if ( isset ( $histo [ $key ][ 'acode' ]) && $histo [ $key ][ 'acode' ] == 'AC_TEL' ) {
2021-02-23 22:03:23 +01:00
if ( ! empty ( $contact -> phone_pro )) {
2020-09-07 10:18:17 +02:00
$footer .= '(' . dol_print_phone ( $contact -> phone_pro ) . ')' ;
2021-02-23 22:03:23 +01:00
}
2020-09-07 10:18:17 +02:00
}
}
}
2019-09-11 23:30:09 +02:00
2020-04-10 10:59:32 +02:00
$documents = getTicketActionCommEcmList ( $actionstatic );
2021-02-23 22:03:23 +01:00
if ( ! empty ( $documents )) {
2020-04-10 10:59:32 +02:00
$footer .= '<div class="timeline-documents-container">' ;
2021-02-23 22:03:23 +01:00
foreach ( $documents as $doc ) {
2020-04-10 10:59:32 +02:00
$footer .= '<span id="document_' . $doc -> id . '" class="timeline-documents" ' ;
$footer .= ' data-id="' . $doc -> id . '" ' ;
$footer .= ' data-path="' . $doc -> filepath . '"' ;
$footer .= ' data-filename="' . dol_escape_htmltag ( $doc -> filename ) . '" ' ;
$footer .= '>' ;
2019-10-30 17:46:18 +01:00
2020-04-10 10:59:32 +02:00
$filePath = DOL_DATA_ROOT . '/' . $doc -> filepath . '/' . $doc -> filename ;
2019-10-30 17:46:18 +01:00
$mime = dol_mimetype ( $filePath );
$file = $actionstatic -> id . '/' . $doc -> filename ;
2019-11-04 20:36:55 +01:00
$thumb = $actionstatic -> id . '/thumbs/' . substr ( $doc -> filename , 0 , strrpos ( $doc -> filename , '.' )) . '_mini' . substr ( $doc -> filename , strrpos ( $doc -> filename , '.' ));
2019-10-30 17:46:18 +01:00
$doclink = dol_buildpath ( 'document.php' , 1 ) . '?modulepart=actions&attachment=0&file=' . urlencode ( $file ) . '&entity=' . $conf -> entity ;
$viewlink = dol_buildpath ( 'viewimage.php' , 1 ) . '?modulepart=actions&file=' . urlencode ( $thumb ) . '&entity=' . $conf -> entity ;
$mimeAttr = ' mime="' . $mime . '" ' ;
$class = '' ;
2020-04-10 10:59:32 +02:00
if ( in_array ( $mime , array ( 'image/png' , 'image/jpeg' , 'application/pdf' ))) {
$class .= ' documentpreview' ;
2019-10-30 17:46:18 +01:00
}
2020-04-10 10:59:32 +02:00
$footer .= '<a href="' . $doclink . '" class="btn-link ' . $class . '" target="_blank" ' . $mimeAttr . ' >' ;
$footer .= img_mime ( $filePath ) . ' ' . $doc -> filename ;
$footer .= '</a>' ;
2019-10-30 17:46:18 +01:00
2020-04-10 10:59:32 +02:00
$footer .= '</span>' ;
2019-10-30 17:46:18 +01:00
}
2020-04-10 10:59:32 +02:00
$footer .= '</div>' ;
2019-10-30 17:46:18 +01:00
}
2020-09-07 10:18:17 +02:00
if ( ! empty ( $footer )) {
$out .= '<div class="timeline-footer">' . $footer . '</div>' ;
}
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
$out .= '</div>' . " \n " ; // end timeline-item
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
$out .= '</li>' ;
$out .= '<!-- END timeline item -->' ;
2019-09-11 23:30:09 +02:00
2020-09-07 10:18:17 +02:00
$i ++ ;
}
$out .= " </ul> \n " ;
}
2019-09-11 23:30:09 +02:00
2021-02-23 22:03:23 +01:00
if ( $noprint ) {
return $out ;
} else {
print $out ;
}
2019-09-12 00:44:17 +02:00
}
2019-10-30 17:46:18 +01:00
2020-11-02 00:26:26 +01:00
/**
* Get timeline icon
* @ param ActionComm $actionstatic actioncomm
* @ param array $histo histo
* @ param int $key key
* @ return string
*/
2020-11-02 11:30:07 +01:00
function getTicketTimelineIcon ( $actionstatic , & $histo , $key )
2020-11-02 00:26:26 +01:00
{
global $conf , $langs ;
$out = '<!-- timeline icon -->' . " \n " ;
$iconClass = 'fa fa-comments' ;
$img_picto = '' ;
$colorClass = '' ;
$pictoTitle = '' ;
if ( $histo [ $key ][ 'percent' ] == - 1 ) {
$colorClass = 'timeline-icon-not-applicble' ;
$pictoTitle = $langs -> trans ( 'StatusNotApplicable' );
} elseif ( $histo [ $key ][ 'percent' ] == 0 ) {
$colorClass = 'timeline-icon-todo' ;
$pictoTitle = $langs -> trans ( 'StatusActionToDo' ) . ' (0%)' ;
} elseif ( $histo [ $key ][ 'percent' ] > 0 && $histo [ $key ][ 'percent' ] < 100 ) {
$colorClass = 'timeline-icon-in-progress' ;
$pictoTitle = $langs -> trans ( 'StatusActionInProcess' ) . ' (' . $histo [ $key ][ 'percent' ] . '%)' ;
} elseif ( $histo [ $key ][ 'percent' ] >= 100 ) {
$colorClass = 'timeline-icon-done' ;
$pictoTitle = $langs -> trans ( 'StatusActionDone' ) . ' (100%)' ;
}
if ( $actionstatic -> code == 'AC_TICKET_CREATE' ) {
$iconClass = 'fa fa-ticket' ;
} elseif ( $actionstatic -> code == 'AC_TICKET_MODIFY' ) {
2020-12-17 12:15:34 +01:00
$iconClass = 'fa fa-pencilxxx' ;
2020-11-02 00:26:26 +01:00
} elseif ( $actionstatic -> code == 'TICKET_MSG' ) {
$iconClass = 'fa fa-comments' ;
} elseif ( $actionstatic -> code == 'TICKET_MSG_PRIVATE' ) {
$iconClass = 'fa fa-mask' ;
} elseif ( ! empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE )) {
if ( $actionstatic -> type_picto ) {
$img_picto = img_picto ( '' , $actionstatic -> type_picto );
} else {
if ( $actionstatic -> type_code == 'AC_RDV' ) {
$iconClass = 'fa fa-handshake' ;
} elseif ( $actionstatic -> type_code == 'AC_TEL' ) {
$iconClass = 'fa fa-phone' ;
} elseif ( $actionstatic -> type_code == 'AC_FAX' ) {
$iconClass = 'fa fa-fax' ;
} elseif ( $actionstatic -> type_code == 'AC_EMAIL' ) {
$iconClass = 'fa fa-envelope' ;
} elseif ( $actionstatic -> type_code == 'AC_INT' ) {
$iconClass = 'fa fa-shipping-fast' ;
} elseif ( $actionstatic -> type_code == 'AC_OTH_AUTO' ) {
$iconClass = 'fa fa-robot' ;
} elseif ( ! preg_match ( '/_AUTO/' , $actionstatic -> type_code )) {
$iconClass = 'fa fa-robot' ;
}
}
}
$out .= '<i class="' . $iconClass . ' ' . $colorClass . '" title="' . $pictoTitle . '">' . $img_picto . '</i>' . " \n " ;
return $out ;
}
2019-10-30 17:46:18 +01:00
/**
2019-11-04 20:36:55 +01:00
* getTicketActionCommEcmList
*
2019-11-04 20:37:49 +01:00
* @ param ActionComm $object Object ActionComm
* @ return array Array of documents in index table
2019-10-30 17:46:18 +01:00
*/
function getTicketActionCommEcmList ( $object )
{
global $conf , $db ;
$documents = array ();
$sql = 'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename' ;
2020-04-10 10:59:32 +02:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'ecm_files ecm' ;
$sql .= ' WHERE ecm.filepath = \'agenda/' . $object -> id . '\'' ;
2019-10-30 17:46:18 +01:00
//$sql.= ' ecm.src_object_type = \''.$object->element.'\' AND ecm.src_object_id = '.$object->id; // Actually upload file doesn't add type
2020-04-10 10:59:32 +02:00
$sql .= ' ORDER BY ecm.position ASC' ;
2019-10-30 17:46:18 +01:00
2020-04-10 10:59:32 +02:00
$resql = $db -> query ( $sql );
2019-10-30 17:46:18 +01:00
if ( $resql ) {
if ( $db -> num_rows ( $resql )) {
while ( $obj = $db -> fetch_object ( $resql )) {
$documents [ $obj -> id ] = $obj ;
}
}
}
return $documents ;
}