2018-03-10 04:23:59 +01:00
< ? php
2018-04-18 09:27:54 +02:00
/* Copyright ( C ) 2013 - 2018 Jean - François FERRY < hello @ librethic . io >
* Copyright ( C ) 2016 Christophe Battarel < christophe @ altairis . fr >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2018 Regis Houssin < regis . houssin @ inodbox . com >
2021-01-04 10:59:45 +01:00
* Copyright ( C ) 2019 - 2021 Juanjo Menent < jmenent @ 2 byte . es >
2020-06-26 19:35:09 +02:00
* Copyright ( C ) 2019 - 2020 Laurent Destailleur < eldy @ users . sourceforge . net >
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
2018-07-16 12:13:34 +02:00
* the Free Software Foundation ; either version 3 of the License , or
2018-03-10 04:23:59 +01:00
* ( 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 htdocs / ticket / list . php
* \ingroup ticket
2018-07-16 12:13:34 +02:00
* \brief List page for tickets
2018-03-10 04:23:59 +01:00
*/
2018-03-11 10:34:21 +01:00
require '../main.inc.php' ;
2019-11-12 09:46:08 +01:00
require_once DOL_DOCUMENT_ROOT . '/ticket/class/actions_ticket.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formticket.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
include_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php' ;
2018-03-10 04:23:59 +01:00
2018-05-26 16:35:29 +02:00
// Load translation files required by the page
2019-05-21 13:27:45 +02:00
$langs -> loadLangs ( array ( " ticket " , " companies " , " other " , " projects " ));
2018-03-10 04:23:59 +01:00
// Get parameters
2019-11-12 09:46:08 +01:00
$action = GETPOST ( 'action' , 'aZ09' ) ? GETPOST ( 'action' , 'aZ09' ) : 'view' ; // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST ( 'massaction' , 'alpha' ); // The bulk action (combo box choice into lists)
$show_files = GETPOST ( 'show_files' , 'int' ); // Show files area generated by bulk actions ?
$confirm = GETPOST ( 'confirm' , 'alpha' ); // Result of a confirmation
$cancel = GETPOST ( 'cancel' , 'alpha' ); // We click on a Cancel button
$toselect = GETPOST ( 'toselect' , 'array' ); // Array of ids of elements selected into a list
2021-10-03 19:17:23 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'ticketlist' ; // To manage different context of search
2019-11-12 09:46:08 +01:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' ); // Go back to a dedicated page
2021-07-30 01:10:15 +02:00
$optioncss = GETPOST ( 'optioncss' , 'aZ' ); // Option for the css output (always '' except when 'print')
2019-11-12 09:46:08 +01:00
$id = GETPOST ( 'id' , 'int' );
2019-03-05 12:18:36 +01:00
$msg_id = GETPOST ( 'msg_id' , 'int' );
$socid = GETPOST ( 'socid' , 'int' );
$projectid = GETPOST ( 'projectid' , 'int' );
2019-11-12 09:46:08 +01:00
$project_ref = GETPOST ( 'project_ref' , 'alpha' );
2019-04-29 11:43:25 +02:00
$search_societe = GETPOST ( 'search_societe' , 'alpha' );
2019-11-12 09:46:08 +01:00
$search_fk_project = GETPOST ( 'search_fk_project' , 'int' ) ? GETPOST ( 'search_fk_project' , 'int' ) : GETPOST ( 'projectid' , 'int' );
2021-01-04 10:59:45 +01:00
$search_date_start = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_date_startmonth' , 'int' ), GETPOST ( 'search_date_startday' , 'int' ), GETPOST ( 'search_date_startyear' , 'int' ));
$search_date_end = dol_mktime ( 23 , 59 , 59 , GETPOST ( 'search_date_endmonth' , 'int' ), GETPOST ( 'search_date_endday' , 'int' ), GETPOST ( 'search_date_endyear' , 'int' ));
$search_dateread_start = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_dateread_startmonth' , 'int' ), GETPOST ( 'search_dateread_startday' , 'int' ), GETPOST ( 'search_dateread_startyear' , 'int' ));
$search_dateread_end = dol_mktime ( 23 , 59 , 59 , GETPOST ( 'search_dateread_endmonth' , 'int' ), GETPOST ( 'search_dateread_endday' , 'int' ), GETPOST ( 'search_dateread_endyear' , 'int' ));
$search_dateclose_start = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_dateclose_startmonth' , 'int' ), GETPOST ( 'search_dateclose_startday' , 'int' ), GETPOST ( 'search_dateclose_startyear' , 'int' ));
$search_dateclose_end = dol_mktime ( 23 , 59 , 59 , GETPOST ( 'search_dateclose_endmonth' , 'int' ), GETPOST ( 'search_dateclose_endday' , 'int' ), GETPOST ( 'search_dateclose_endyear' , 'int' ));
2019-11-12 09:46:08 +01:00
$mode = GETPOST ( 'mode' , 'alpha' );
2018-03-10 04:23:59 +01:00
// Load variable for pagination
2019-11-12 09:46:08 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-26 13:27:00 +01:00
if ( empty ( $page ) || $page < 0 || GETPOST ( 'button_search' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) {
2021-07-30 01:10:15 +02:00
// If $page is not defined, or '' or -1 or if we click on clear filters
2021-02-26 13:27:00 +01:00
$page = 0 ;
2021-07-30 01:10:15 +02:00
}
2018-03-10 04:23:59 +01:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
// Initialize technical objects
2019-11-12 09:46:08 +01:00
$object = new Ticket ( $db );
2018-03-10 04:23:59 +01:00
$extrafields = new ExtraFields ( $db );
2019-11-12 09:46:08 +01:00
$diroutputmassaction = $conf -> ticket -> dir_output . '/temp/massgeneration/' . $user -> id ;
2021-02-26 13:27:00 +01:00
if ( $socid > 0 ) {
$hookmanager -> initHooks ( array ( 'thirdpartyticket' ));
} elseif ( $projectid > 0 ) {
$hookmanager -> initHooks ( array ( 'projectticket' ));
} else {
$hookmanager -> initHooks ( array ( 'ticketlist' ));
}
2018-03-10 04:23:59 +01:00
// Fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2019-11-12 09:46:08 +01:00
$search_array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element , '' , 'search_' );
2018-03-10 04:23:59 +01:00
// Default sort order (if not yet defined by previous GETPOST)
2021-02-26 13:27:00 +01:00
if ( ! $sortfield ) {
$sortfield = " t.datec " ;
}
if ( ! $sortorder ) {
$sortorder = " DESC " ;
}
2018-03-10 04:23:59 +01:00
2021-02-26 13:27:00 +01:00
if ( GETPOST ( 'search_fk_status' , 'alpha' ) == 'non_closed' ) {
$_GET [ 'search_fk_statut' ][] = 'openall' ; // For backward compatibility
}
2019-02-26 13:20:58 +01:00
2018-03-10 04:23:59 +01:00
// Initialize array of search criterias
2021-07-30 01:10:15 +02:00
$search_all = ( GETPOSTISSET ( " search_all " ) ? GETPOST ( " search_all " , 'alpha' ) : GETPOST ( 'sall' ));
2019-11-12 09:46:08 +01:00
$search = array ();
2021-02-26 13:27:00 +01:00
foreach ( $object -> fields as $key => $val ) {
2021-07-30 01:10:15 +02:00
if ( GETPOST ( 'search_' . $key , 'alpha' ) !== '' ) {
2021-02-26 13:27:00 +01:00
$search [ $key ] = GETPOST ( 'search_' . $key , 'alpha' );
}
2021-07-30 01:10:15 +02:00
if ( preg_match ( '/^(date|timestamp|datetime)/' , $val [ 'type' ])) {
$search [ $key . '_dtstart' ] = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_' . $key . '_dtstartmonth' , 'int' ), GETPOST ( 'search_' . $key . '_dtstartday' , 'int' ), GETPOST ( 'search_' . $key . '_dtstartyear' , 'int' ));
$search [ $key . '_dtend' ] = dol_mktime ( 23 , 59 , 59 , GETPOST ( 'search_' . $key . '_dtendmonth' , 'int' ), GETPOST ( 'search_' . $key . '_dtendday' , 'int' ), GETPOST ( 'search_' . $key . '_dtendyear' , 'int' ));
}
2018-03-10 04:23:59 +01:00
}
// List of fields to search into when doing a "search in all"
2020-09-08 02:11:09 +02:00
$fieldstosearchall = array ();
2021-02-26 13:27:00 +01:00
foreach ( $object -> fields as $key => $val ) {
2021-05-11 08:20:31 +02:00
if ( ! empty ( $val [ 'searchall' ])) {
2021-02-26 13:27:00 +01:00
$fieldstosearchall [ 't.' . $key ] = $val [ 'label' ];
}
2018-03-10 04:23:59 +01:00
}
2020-09-08 21:27:28 +02:00
$fieldstosearchall [ 's.name_alias' ] = " AliasNameShort " ;
$fieldstosearchall [ 's.zip' ] = " Zip " ;
$fieldstosearchall [ 's.town' ] = " Town " ;
2018-03-10 04:23:59 +01:00
2021-07-30 01:10:15 +02:00
// Definition of array of fields for columns
2019-11-12 09:46:08 +01:00
$arrayfields = array ();
2021-02-26 13:27:00 +01:00
foreach ( $object -> fields as $key => $val ) {
2018-04-13 12:52:23 +02:00
// If $val['visible']==0, then we never show the field
2021-02-26 13:27:00 +01:00
if ( ! empty ( $val [ 'visible' ])) {
2022-03-01 16:38:06 +01:00
$visible = ( int ) dol_eval ( $val [ 'visible' ], 1 , 1 , '1' );
2021-07-30 01:10:15 +02:00
$arrayfields [ 't.' . $key ] = array (
'label' => $val [ 'label' ],
'checked' => (( $visible < 0 ) ? 0 : 1 ),
2022-09-01 11:18:46 +02:00
'enabled' => ( $visible != 3 && dol_eval ( $val [ 'enabled' ], 1 )),
2021-07-30 01:10:15 +02:00
'position' => $val [ 'position' ],
'help' => isset ( $val [ 'help' ]) ? $val [ 'help' ] : ''
);
2021-02-26 13:27:00 +01:00
}
2018-03-10 04:23:59 +01:00
}
// Extra fields
2020-12-01 02:41:19 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php' ;
2020-11-06 12:19:45 +01:00
2018-03-10 04:23:59 +01:00
$object -> fields = dol_sort_array ( $object -> fields , 'position' );
$arrayfields = dol_sort_array ( $arrayfields , 'position' );
// Security check
2018-06-04 21:49:29 +02:00
if ( ! $user -> rights -> ticket -> read ) {
2020-10-31 14:32:18 +01:00
accessforbidden ();
2018-03-10 04:23:59 +01:00
}
2022-01-25 15:12:32 +01:00
// restrict view to current user's company
if ( $user -> socid > 0 ) $socid = $user -> socid ;
2018-03-10 04:23:59 +01:00
// Store current page url
2021-09-18 19:34:46 +02:00
$url_page_current = DOL_URL_ROOT . '/ticket/list.php' ;
2018-03-10 04:23:59 +01:00
2021-02-26 13:27:00 +01:00
if ( $project_ref ) {
2019-10-01 12:36:22 +02:00
$tmpproject = new Project ( $db );
$tmpproject -> fetch ( 0 , $project_ref );
$projectid = $tmpproject -> id ;
$search_fk_project = $projectid ;
}
2018-03-10 04:23:59 +01:00
2020-06-26 19:35:09 +02:00
$permissiontoread = $user -> rights -> ticket -> read ;
$permissiontoadd = $user -> rights -> ticket -> write ;
$permissiontodelete = $user -> rights -> ticket -> delete ;
$error = 0 ;
2018-03-10 04:23:59 +01:00
/*
* Actions
*/
2021-02-26 13:27:00 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
2022-01-02 18:22:18 +01:00
$action = 'list' ;
$massaction = '' ;
2021-02-26 13:27:00 +01:00
}
2022-02-28 15:11:45 +01:00
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'presendonclose' && $massaction != 'close' ) {
2021-02-26 13:27:00 +01:00
$massaction = '' ;
}
2018-03-10 04:23:59 +01:00
2019-11-12 09:46:08 +01:00
$parameters = array ();
2021-02-26 13:27:00 +01:00
if ( $socid > 0 ) {
$parameters [ 'socid' ] = $socid ;
}
if ( $projectid > 0 ) {
$parameters [ 'projectid' ] = $projectid ;
}
2019-11-12 09:46:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 13:27:00 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2018-03-10 04:23:59 +01:00
2021-02-26 13:27:00 +01:00
if ( empty ( $reshook )) {
2018-04-13 12:52:23 +02:00
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2021-02-26 13:27:00 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All tests are required to be compatible with all browsers
foreach ( $object -> fields as $key => $val ) {
2019-11-12 09:46:08 +01:00
$search [ $key ] = '' ;
2022-01-02 18:22:18 +01:00
if ( preg_match ( '/^(date|timestamp|datetime)/' , $val [ 'type' ])) {
$search [ $key . '_dtstart' ] = '' ;
$search [ $key . '_dtend' ] = '' ;
}
2018-04-13 12:52:23 +02:00
}
2022-01-02 18:22:18 +01:00
$toselect = array ();
2019-11-12 09:46:08 +01:00
$search_array_options = array ();
2021-01-04 10:59:45 +01:00
$search_date_start = '' ;
$search_date_end = '' ;
$search_dateread_start = '' ;
$search_dateread_end = '' ;
$search_dateclose_start = '' ;
$search_dateclose_end = '' ;
2018-04-13 12:52:23 +02:00
}
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )
2021-02-26 13:27:00 +01:00
|| GETPOST ( 'button_search_x' , 'alpha' ) || GETPOST ( 'button_search.x' , 'alpha' ) || GETPOST ( 'button_search' , 'alpha' )) {
2019-11-12 09:46:08 +01:00
$massaction = '' ; // Protection to avoid mass action if we force a new search during a mass action confirmation
2018-04-13 12:52:23 +02:00
}
2018-04-15 16:35:18 +02:00
2018-04-13 12:52:23 +02:00
// Mass actions
2019-11-12 09:46:08 +01:00
$objectclass = 'Ticket' ;
$objectlabel = 'Ticket' ;
2018-06-04 21:49:29 +02:00
$uploaddir = $conf -> ticket -> dir_output ;
2018-04-13 12:52:23 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
2020-06-26 19:35:09 +02:00
// Close records
2021-02-26 13:27:00 +01:00
if ( ! $error && $massaction == 'close' && $permissiontoadd ) {
2020-06-26 19:35:09 +02:00
$objecttmp = new $objectclass ( $db );
2021-02-26 13:27:00 +01:00
if ( ! $error ) {
2020-06-26 19:35:09 +02:00
$db -> begin ();
$nbok = 0 ;
2021-02-26 13:27:00 +01:00
foreach ( $toselect as $toselectid ) {
2020-06-26 19:35:09 +02:00
$result = $objecttmp -> fetch ( $toselectid );
2021-02-26 13:27:00 +01:00
if ( $result > 0 ) {
2020-06-26 19:35:09 +02:00
$result = $objecttmp -> close ( $user );
2021-02-26 13:27:00 +01:00
if ( $result < 0 ) {
2020-06-26 19:35:09 +02:00
setEventMessages ( $objecttmp -> error , $objecttmp -> errors , 'errors' );
$error ++ ;
break ;
2021-02-26 13:27:00 +01:00
} else {
$nbok ++ ;
}
2020-06-26 19:35:09 +02:00
} else {
setEventMessages ( $objecttmp -> error , $objecttmp -> errors , 'errors' );
$error ++ ;
break ;
}
}
2021-02-26 13:27:00 +01:00
if ( ! $error ) {
if ( $nbok > 1 ) {
setEventMessages ( $langs -> trans ( " RecordsModified " , $nbok ), null , 'mesgs' );
} else {
setEventMessages ( $langs -> trans ( " RecordsModified " , $nbok ), null , 'mesgs' );
}
2020-06-26 19:35:09 +02:00
$db -> commit ();
} else {
$db -> rollback ();
}
//var_dump($listofobjectthirdparties);exit;
}
}
// Reopen records
2021-02-26 13:27:00 +01:00
if ( ! $error && $massaction == 'reopen' && $permissiontoadd ) {
2020-06-26 19:35:09 +02:00
$objecttmp = new $objectclass ( $db );
2021-02-26 13:27:00 +01:00
if ( ! $error ) {
2020-06-26 19:35:09 +02:00
$db -> begin ();
$nbok = 0 ;
2021-02-26 13:27:00 +01:00
foreach ( $toselect as $toselectid ) {
2020-06-26 19:35:09 +02:00
$result = $objecttmp -> fetch ( $toselectid );
2021-02-26 13:27:00 +01:00
if ( $result > 0 ) {
2020-06-26 19:35:09 +02:00
if ( $objecttmp -> status == Ticket :: STATUS_CLOSED || $objecttmp -> status == Ticket :: STATUS_CANCELED ) {
$result = $objecttmp -> setStatut ( Ticket :: STATUS_ASSIGNED );
2021-02-26 13:27:00 +01:00
if ( $result < 0 ) {
2020-06-26 19:35:09 +02:00
setEventMessages ( $objecttmp -> error , $objecttmp -> errors , 'errors' );
$error ++ ;
break ;
2021-02-26 13:27:00 +01:00
} else {
$nbok ++ ;
}
2020-06-26 19:35:09 +02:00
} else {
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " ErrorObjectMustHaveStatusClosedToBeReOpened " , $objecttmp -> ref ), null , 'errors' );
$error ++ ;
break ;
}
} else {
setEventMessages ( $objecttmp -> error , $objecttmp -> errors , 'errors' );
$error ++ ;
break ;
}
}
2021-02-26 13:27:00 +01:00
if ( ! $error ) {
if ( $nbok > 1 ) {
setEventMessages ( $langs -> trans ( " RecordsModified " , $nbok ), null , 'mesgs' );
} else {
setEventMessages ( $langs -> trans ( " RecordsModified " , $nbok ), null , 'mesgs' );
}
2020-06-26 19:35:09 +02:00
$db -> commit ();
} else {
$db -> rollback ();
}
//var_dump($listofobjectthirdparties);exit;
}
}
2018-03-10 04:23:59 +01:00
}
2018-03-11 23:40:25 +01:00
/*
* View
*/
2019-11-12 09:46:08 +01:00
$form = new Form ( $db );
2018-06-04 21:49:29 +02:00
$formTicket = new FormTicket ( $db );
2018-03-10 04:23:59 +01:00
2021-06-26 15:39:52 +02:00
$user_temp = new User ( $db );
2018-03-10 04:23:59 +01:00
$socstatic = new Societe ( $db );
2018-11-11 15:06:08 +01:00
$help_url = '' ;
2022-05-17 23:23:50 +02:00
$title = $langs -> trans ( 'Tickets' );
2022-01-02 18:22:18 +01:00
$morejs = array ();
$morecss = array ();
2018-07-16 12:13:34 +02:00
2018-03-10 04:23:59 +01:00
// Build and execute select
// --------------------------------------------------------------------
$sql = 'SELECT ' ;
2021-11-01 03:14:54 +01:00
$sql .= $object -> getFieldList ( 't' );
2018-03-10 04:23:59 +01:00
// Add fields from extrafields
2021-02-26 13:27:00 +01:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) {
2021-11-01 03:14:54 +01:00
$sql .= ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] != 'separate' ? " , ef. " . $key . " as options_ " . $key : '' );
2021-02-26 13:27:00 +01:00
}
}
2018-03-10 04:23:59 +01:00
// Add fields from hooks
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2022-01-02 18:22:18 +01:00
$sql .= preg_replace ( '/^,/' , '' , $hookmanager -> resPrint );
2021-11-01 03:14:54 +01:00
$sql = preg_replace ( '/,\s*$/' , '' , $sql );
2019-11-12 09:46:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . $object -> table_element . " as t " ;
2021-05-11 08:20:31 +02:00
if ( isset ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) && is_array ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
2021-02-26 13:27:00 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object -> table_element . " _extrafields as ef on (t.rowid = ef.fk_object) " ;
}
2022-01-02 18:22:18 +01:00
// Add table from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListFrom' , $parameters , $object ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2019-11-12 09:46:08 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON (t.fk_soc = s.rowid) " ;
$sql .= " WHERE t.entity IN ( " . getEntity ( $object -> element ) . " ) " ;
2021-02-26 13:27:00 +01:00
if ( $socid > 0 ) {
2021-03-22 13:31:06 +01:00
$sql .= " AND t.fk_soc = " . (( int ) $socid );
2019-09-02 17:38:59 +02:00
}
2021-02-26 13:27:00 +01:00
foreach ( $search as $key => $val ) {
if ( $key == 'fk_statut' && ! empty ( $search [ 'fk_statut' ])) {
2020-06-26 19:35:09 +02:00
$newarrayofstatus = array ();
2020-06-27 01:59:08 +02:00
foreach ( $search [ 'fk_statut' ] as $key2 => $val2 ) {
2021-02-26 13:27:00 +01:00
if ( in_array ( $val2 , array ( 'openall' , 'closeall' ))) {
continue ;
}
2020-06-26 19:35:09 +02:00
$newarrayofstatus [] = $val2 ;
}
2020-10-31 14:32:18 +01:00
if ( $search [ 'fk_statut' ] == 'openall' || in_array ( 'openall' , $search [ 'fk_statut' ])) {
$newarrayofstatus [] = Ticket :: STATUS_NOT_READ ;
2021-01-15 09:55:42 +01:00
$newarrayofstatus [] = Ticket :: STATUS_READ ;
2020-10-31 14:32:18 +01:00
$newarrayofstatus [] = Ticket :: STATUS_ASSIGNED ;
$newarrayofstatus [] = Ticket :: STATUS_IN_PROGRESS ;
$newarrayofstatus [] = Ticket :: STATUS_NEED_MORE_INFO ;
$newarrayofstatus [] = Ticket :: STATUS_WAITING ;
}
if ( $search [ 'fk_statut' ] == 'closeall' || in_array ( 'closeall' , $search [ 'fk_statut' ])) {
$newarrayofstatus [] = Ticket :: STATUS_CLOSED ;
$newarrayofstatus [] = Ticket :: STATUS_CANCELED ;
}
2021-02-26 13:27:00 +01:00
if ( count ( $newarrayofstatus )) {
$sql .= natural_search ( $key , join ( ',' , $newarrayofstatus ), 2 );
}
2020-10-31 14:32:18 +01:00
continue ;
2021-11-01 02:28:41 +01:00
} elseif ( $key == 'fk_user_assign' || $key == 'fk_user_create' || $key == 'fk_project' ) {
2021-02-26 13:27:00 +01:00
if ( $search [ $key ] > 0 ) {
$sql .= natural_search ( $key , $search [ $key ], 2 );
}
2020-10-31 14:32:18 +01:00
continue ;
2019-04-10 12:43:26 +02:00
}
2021-11-01 02:28:41 +01:00
2021-10-24 09:46:58 +02:00
$mode_search = (( ! empty ( $object -> fields [ $key ]) && ( $object -> isInt ( $object -> fields [ $key ]) || $object -> isFloat ( $object -> fields [ $key ]))) ? 1 : 0 );
2021-11-01 02:28:41 +01:00
// $search[$key] can be an array of values, or a string. We add filter if array not empty or if it is a string.
if (( is_array ( $search [ $key ]) && ! empty ( $search [ $key ])) || ( ! is_array ( $search [ $key ]) && $search [ $key ] != '' )) {
2021-02-26 13:27:00 +01:00
$sql .= natural_search ( $key , $search [ $key ], $mode_search );
}
}
if ( $search_all ) {
$sql .= natural_search ( array_keys ( $fieldstosearchall ), $search_all );
}
if ( $search_societe ) {
$sql .= natural_search ( 's.nom' , $search_societe );
2018-03-10 04:23:59 +01:00
}
2021-03-02 15:27:20 +01:00
if ( $search_fk_project > 0 ) {
$sql .= natural_search ( 'fk_project' , $search_fk_project , 2 );
}
2021-02-26 13:27:00 +01:00
if ( $search_date_start ) {
$sql .= " AND t.datec >= ' " . $db -> idate ( $search_date_start ) . " ' " ;
}
if ( $search_date_end ) {
$sql .= " AND t.datec <= ' " . $db -> idate ( $search_date_end ) . " ' " ;
}
if ( $search_dateread_start ) {
$sql .= " AND t.date_read >= ' " . $db -> idate ( $search_dateread_start ) . " ' " ;
}
if ( $search_dateread_end ) {
$sql .= " AND t.date_read <= ' " . $db -> idate ( $search_dateread_end ) . " ' " ;
}
if ( $search_dateclose_start ) {
$sql .= " AND t.date_close >= ' " . $db -> idate ( $search_dateclose_start ) . " ' " ;
}
if ( $search_dateclose_end ) {
$sql .= " AND t.date_close <= ' " . $db -> idate ( $search_dateclose_end ) . " ' " ;
}
2021-01-04 10:59:45 +01:00
2019-11-12 09:46:08 +01:00
if ( ! $user -> socid && ( $mode == " mine " || ( ! $user -> admin && $conf -> global -> TICKET_LIMIT_VIEW_ASSIGNED_ONLY ))) {
2021-08-23 19:33:24 +02:00
$sql .= " AND (t.fk_user_assign = " . (( int ) $user -> id );
2021-02-26 13:27:00 +01:00
if ( empty ( $conf -> global -> TICKET_LIMIT_VIEW_ASSIGNED_ONLY )) {
2021-08-23 19:33:24 +02:00
$sql .= " OR t.fk_user_create = " . (( int ) $user -> id );
2021-02-26 13:27:00 +01:00
}
2020-10-31 14:32:18 +01:00
$sql .= " ) " ;
2018-03-10 04:23:59 +01:00
}
// Add where from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php' ;
// Add where from hooks
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $object ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2018-03-10 04:23:59 +01:00
// Count total nb of records
$nbtotalofrecords = '' ;
2021-02-26 13:27:00 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2022-01-02 18:22:18 +01:00
/* The fast and low memory method to get and count full list converts the sql into a sql count */
$sqlforcount = preg_replace ( '/^SELECT[a-z0-9\._\s\(\),]+FROM/i' , 'SELECT COUNT(*) as nbtotalofrecords FROM' , $sql );
$resql = $db -> query ( $sqlforcount );
$objforcount = $db -> fetch_object ( $resql );
$nbtotalofrecords = $objforcount -> nbtotalofrecords ;
2021-02-26 13:27:00 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total of record found is smaller than page * limit, goto and load page 0
2018-04-24 11:37:57 +02:00
$page = 0 ;
$offset = 0 ;
}
2022-01-02 18:22:18 +01:00
$db -> free ( $resql );
2018-03-10 04:23:59 +01:00
}
2018-03-11 18:28:27 +01:00
2022-01-02 18:22:18 +01:00
// Complete request and execute it with limit
$sql .= $db -> order ( $sortfield , $sortorder );
if ( $limit ) {
$sql .= $db -> plimit ( $limit + 1 , $offset );
}
2018-03-11 18:28:27 +01:00
2022-01-02 18:22:18 +01:00
$resql = $db -> query ( $sql );
if ( ! $resql ) {
dol_print_error ( $db );
exit ;
2018-03-10 04:23:59 +01:00
}
2022-01-02 18:22:18 +01:00
$num = $db -> num_rows ( $resql );
2018-03-10 04:23:59 +01:00
// Direct jump if only one record found
2022-01-02 18:22:18 +01:00
if ( $num == 1 && ! empty ( $conf -> global -> MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE ) && $search_all && ! $page ) {
2018-04-13 12:52:23 +02:00
$obj = $db -> fetch_object ( $resql );
$id = $obj -> rowid ;
2018-06-04 21:49:29 +02:00
header ( " Location: " . DOL_URL_ROOT . '/ticket/card.php?id=' . $id );
2018-04-13 12:52:23 +02:00
exit ;
2018-03-10 04:23:59 +01:00
}
// Output page
// --------------------------------------------------------------------
2022-01-02 18:22:18 +01:00
llxHeader ( '' , $title , $help_url , '' , 0 , 0 , $morejs , $morecss , '' , '' );
2019-04-10 15:11:38 +02:00
2019-11-12 09:46:08 +01:00
if ( $socid && ! $projectid && ! $project_ref && $user -> rights -> societe -> lire ) {
2020-10-31 14:32:18 +01:00
$socstat = new Societe ( $db );
$res = $socstat -> fetch ( $socid );
if ( $res > 0 ) {
$tmpobject = $object ;
$object = $socstat ; // $object must be of type Societe when calling societe_prepare_head
$head = societe_prepare_head ( $socstat );
2018-03-13 13:26:03 +01:00
$object = $tmpobject ;
2020-10-31 14:32:18 +01:00
print dol_get_fiche_head ( $head , 'ticket' , $langs -> trans ( " ThirdParty " ), - 1 , 'company' );
dol_banner_tab ( $socstat , 'socid' , '' , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' );
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border centpercent tableforfield">' ;
2021-06-23 19:02:14 +02:00
// Type Prospect/Customer/Supplier
print '<tr><td class="titlefield">' . $langs -> trans ( 'NatureOfThirdParty' ) . '</td><td>' ;
print $socstat -> getTypeUrl ( 1 );
print '</td></tr>' ;
2021-02-26 13:27:00 +01:00
// Customer code
if ( $socstat -> client && ! empty ( $socstat -> code_client )) {
print '<tr><td class="titlefield">' ;
print $langs -> trans ( 'CustomerCode' ) . '</td><td>' ;
2021-02-27 03:06:21 +01:00
print showValueWithClipboardCPButton ( dol_escape_htmltag ( $socstat -> code_client ));
2021-02-26 13:27:00 +01:00
$tmpcheck = $socstat -> check_codeclient ();
if ( $tmpcheck != 0 && $tmpcheck != - 5 ) {
2021-10-05 11:44:48 +02:00
print ' <span class="error">(' . $langs -> trans ( " WrongCustomerCode " ) . ')</span>' ;
2021-02-26 13:27:00 +01:00
}
print '</td>' ;
print '</tr>' ;
}
// Supplier code
if ( $socstat -> fournisseur && ! empty ( $socstat -> code_fournisseur )) {
print '<tr><td class="titlefield">' ;
print $langs -> trans ( 'SupplierCode' ) . '</td><td>' ;
2021-02-27 03:06:21 +01:00
print showValueWithClipboardCPButton ( dol_escape_htmltag ( $socstat -> code_fournisseur ));
2021-02-26 13:27:00 +01:00
$tmpcheck = $socstat -> check_codefournisseur ();
if ( $tmpcheck != 0 && $tmpcheck != - 5 ) {
2021-10-05 11:44:48 +02:00
print ' <span class="error">(' . $langs -> trans ( " WrongSupplierCode " ) . ')</span>' ;
2021-02-26 13:27:00 +01:00
}
print '</td>' ;
print '</tr>' ;
}
2020-10-31 14:32:18 +01:00
print '</table>' ;
print '</div>' ;
print dol_get_fiche_end ();
}
2018-03-10 04:23:59 +01:00
}
2019-10-01 12:28:56 +02:00
if ( $projectid > 0 || $project_ref ) {
2020-10-31 14:32:18 +01:00
$projectstat = new Project ( $db );
if ( $projectstat -> fetch ( $projectid , $project_ref ) > 0 ) {
$projectid = $projectstat -> id ;
$projectstat -> fetch_thirdparty ();
$savobject = $object ;
$object = $projectstat ;
// To verify role of users
//$userAccess = $object->restrictedProjectArea($user,'read');
$userWrite = $projectstat -> restrictedProjectArea ( $user , 'write' );
//$userDelete = $object->restrictedProjectArea($user,'delete');
//print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
$head = project_prepare_head ( $projectstat );
print dol_get_fiche_head ( $head , 'ticket' , $langs -> trans ( " Project " ), - 1 , ( $projectstat -> public ? 'projectpub' : 'project' ));
// Project card
$linkback = '<a href="' . DOL_URL_ROOT . '/projet/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
$morehtmlref = '<div class="refidno">' ;
// Title
$morehtmlref .= $object -> title ;
// Thirdparty
2021-10-24 09:48:30 +02:00
if ( ! empty ( $object -> thirdparty -> id ) && $object -> thirdparty -> id > 0 ) {
2020-10-31 14:32:18 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 , 'project' );
}
$morehtmlref .= '</div>' ;
// Define a complementary filter for search of next/prev ref.
2021-10-24 10:02:12 +02:00
if ( empty ( $user -> rights -> projet -> all -> lire )) {
2020-10-31 14:32:18 +01:00
$objectsListId = $object -> getProjectsAuthorizedForUser ( $user , 0 , 0 );
2021-03-22 12:47:23 +01:00
$object -> next_prev_filter = " rowid IN ( " . $db -> sanitize ( count ( $objectsListId ) ? join ( ',' , array_keys ( $objectsListId )) : '0' ) . " ) " ;
2020-10-31 14:32:18 +01:00
}
dol_banner_tab ( $object , 'project_ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border tableforfield" width="100%">' ;
// Visibility
print '<tr><td class="titlefield">' . $langs -> trans ( " Visibility " ) . '</td><td>' ;
if ( $projectstat -> public ) {
2022-05-16 18:00:59 +02:00
print img_picto ( $langs -> trans ( 'SharedProject' ), 'world' , 'class="paddingrightonly"' );
2020-10-31 14:32:18 +01:00
print $langs -> trans ( 'SharedProject' );
} else {
2022-05-16 18:00:59 +02:00
print img_picto ( $langs -> trans ( 'PrivateProject' ), 'private' , 'class="paddingrightonly"' );
2020-10-31 14:32:18 +01:00
print $langs -> trans ( 'PrivateProject' );
}
print '</td></tr>' ;
print " </table> " ;
print '</div>' ;
print dol_get_fiche_end ();
$object = $savobject ;
} else {
print " ErrorRecordNotFound " ;
}
2018-03-10 04:23:59 +01:00
}
2019-11-12 09:46:08 +01:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2018-03-10 04:23:59 +01:00
2019-11-12 09:46:08 +01:00
$param = '' ;
2021-02-26 13:27:00 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
foreach ( $search as $key => $val ) {
2022-09-01 11:18:46 +02:00
if ( is_array ( $search [ $key ])) {
foreach ( $search [ $key ] as $skey ) {
2022-01-02 18:22:18 +01:00
if ( $skey != '' ) {
2022-02-16 20:31:55 +01:00
$param .= ( ! empty ( $val )) ? '&search_' . $key . '[]=' . urlencode ( $skey ) : " " ;
2022-01-02 18:22:18 +01:00
}
2021-02-26 13:27:00 +01:00
}
2022-01-02 18:22:18 +01:00
} elseif ( $search [ $key ] != '' ) {
2021-02-26 13:27:00 +01:00
$param .= '&search_' . $key . '=' . urlencode ( $search [ $key ]);
}
}
if ( $optioncss != '' ) {
$param .= '&optioncss=' . urlencode ( $optioncss );
}
2018-03-10 04:23:59 +01:00
// Add $param from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
2022-01-02 18:22:18 +01:00
// Add $param from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSearchParam' , $parameters , $object ); // Note that $action and $object may have been modified by hook
$param .= $hookmanager -> resPrint ;
2021-03-25 01:03:18 +01:00
if ( $socid > 0 ) {
2021-02-26 13:27:00 +01:00
$param .= '&socid=' . urlencode ( $socid );
}
2021-03-25 01:03:18 +01:00
if ( $search_societe ) {
$param .= '&search_societe=' . urlencode ( $search_societe );
}
if ( $projectid > 0 ) {
2021-02-26 13:27:00 +01:00
$param .= '&projectid=' . urlencode ( $projectid );
}
if ( $search_date_start ) {
2021-03-25 01:03:18 +01:00
$tmparray = dol_getdate ( $search_date_start );
$param .= '&search_date_startday=' . urlencode ( $tmparray [ 'mday' ]);
$param .= '&search_date_startmonth=' . urlencode ( $tmparray [ 'mon' ]);
$param .= '&search_date_startyear=' . urlencode ( $tmparray [ 'year' ]);
2021-02-26 13:27:00 +01:00
}
if ( $search_date_end ) {
2021-03-25 01:03:18 +01:00
$tmparray = dol_getdate ( $search_date_end );
$param .= '&search_date_endday=' . urlencode ( $tmparray [ 'mday' ]);
$param .= '&search_date_endmonth=' . urlencode ( $tmparray [ 'mon' ]);
$param .= '&search_date_endyear=' . urlencode ( $tmparray [ 'year' ]);
2021-02-26 13:27:00 +01:00
}
if ( $search_dateread_start ) {
2021-03-25 01:03:18 +01:00
$tmparray = dol_getdate ( $search_dateread_start );
$param .= '&search_dateread_startday=' . urlencode ( $tmparray [ 'mday' ]);
$param .= '&search_dateread_startmonth=' . urlencode ( $tmparray [ 'mon' ]);
$param .= '&search_dateread_startyear=' . urlencode ( $tmparray [ 'year' ]);
2021-02-26 13:27:00 +01:00
}
if ( $search_dateread_end ) {
2021-03-25 01:03:18 +01:00
$tmparray = dol_getdate ( $search_dateread_end );
$param .= '&search_dateread_endday=' . urlencode ( $tmparray [ 'mday' ]);
$param .= '&search_dateread_endmonth=' . urlencode ( $tmparray [ 'mon' ]);
$param .= '&search_dateread_endyear=' . urlencode ( $tmparray [ 'year' ]);
2021-02-26 13:27:00 +01:00
}
if ( $search_dateclose_start ) {
2021-03-25 01:03:18 +01:00
$tmparray = dol_getdate ( $search_dateclose_start );
$param .= '&search_dateclose_startday=' . urlencode ( $tmparray [ 'mday' ]);
$param .= '&search_dateclose_startmonth=' . urlencode ( $tmparray [ 'mon' ]);
$param .= '&search_dateclose_startyear=' . urlencode ( $tmparray [ 'year' ]);
2021-02-26 13:27:00 +01:00
}
if ( $search_dateclose_end ) {
2021-03-25 01:03:18 +01:00
$tmparray = dol_getdate ( $search_dateclose_end );
$param .= '&search_date_endday=' . urlencode ( $tmparray [ 'mday' ]);
$param .= '&search_date_endmonth=' . urlencode ( $tmparray [ 'mon' ]);
$param .= '&search_date_endyear=' . urlencode ( $tmparray [ 'year' ]);
2021-02-26 13:27:00 +01:00
}
2021-01-04 10:59:45 +01:00
2018-03-10 04:23:59 +01:00
// List of mass actions available
2019-11-12 09:46:08 +01:00
$arrayofmassactions = array (
2021-04-14 12:28:01 +02:00
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
2018-03-10 04:23:59 +01:00
);
2022-01-02 18:22:18 +01:00
if ( $permissiontoadd ) {
2022-02-28 15:11:45 +01:00
$arrayofmassactions [ 'presendonclose' ] = img_picto ( '' , 'close_title' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Close " );
2021-04-14 12:28:01 +02:00
$arrayofmassactions [ 'reopen' ] = img_picto ( '' , 'folder-open' , 'class="pictofixedwidth"' ) . $langs -> trans ( " ReOpen " );
2021-02-26 13:27:00 +01:00
}
2022-01-02 18:22:18 +01:00
if ( $permissiontodelete ) {
2021-04-14 12:28:01 +02:00
$arrayofmassactions [ 'predelete' ] = img_picto ( '' , 'delete' , 'class="pictofixedwidth"' ) . $langs -> trans ( " Delete " );
2021-02-26 13:27:00 +01:00
}
if ( GETPOST ( 'nomassaction' , 'int' ) || in_array ( $massaction , array ( 'presend' , 'predelete' ))) {
$arrayofmassactions = array ();
}
2019-11-12 09:46:08 +01:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
2018-03-10 04:23:59 +01:00
2022-01-02 18:22:18 +01:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
2021-02-26 13:27:00 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2018-03-10 04:23:59 +01:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2019-11-12 09:46:08 +01:00
print '<input type="hidden" name="mode" value="' . $mode . '" >' ;
2021-10-03 19:17:23 +02:00
2021-02-26 13:27:00 +01:00
if ( $socid ) {
print '<input type="hidden" name="socid" value="' . $socid . '" >' ;
}
if ( $projectid ) {
print '<input type="hidden" name="projectid" value="' . $projectid . '" >' ;
}
2018-03-10 04:23:59 +01:00
2020-09-18 10:36:40 +02:00
$url = DOL_URL_ROOT . '/ticket/card.php?action=create' . ( $socid ? '&socid=' . $socid : '' ) . ( $projectid ? '&origin=projet_project&originid=' . $projectid : '' );
2021-02-26 13:27:00 +01:00
if ( ! empty ( $socid )) {
$url .= '&socid=' . $socid ;
}
2020-09-18 10:52:17 +02:00
$newcardbutton = dolGetButtonTitle ( $langs -> trans ( 'NewTicket' ), '' , 'fa fa-plus-circle' , $url , '' , $user -> rights -> ticket -> write );
2019-04-16 21:49:26 +02:00
2019-10-02 18:55:18 +02:00
$picto = 'ticket' ;
2021-02-26 13:27:00 +01:00
if ( $socid > 0 ) {
$picto = '' ;
}
2018-03-10 04:23:59 +01:00
2020-04-12 18:13:43 +02:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , $picto , 0 , $newcardbutton , '' , $limit , 0 , 0 , 1 );
2018-03-10 04:23:59 +01:00
2019-02-26 13:20:58 +01:00
if ( $mode == 'mine' ) {
2020-10-31 14:32:18 +01:00
print '<div class="opacitymedium">' . $langs -> trans ( 'TicketAssignedToMeInfos' ) . '</div><br>' ;
2018-03-10 04:23:59 +01:00
}
// Add code for pre mass action (confirmation or email presend form)
2019-11-12 09:46:08 +01:00
$topicmail = " SendTicketRef " ;
$modelmail = " ticket " ;
$objecttmp = new Ticket ( $db );
2020-11-08 14:39:20 +01:00
$trackid = 'tic' . $object -> id ;
2018-03-10 04:23:59 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php' ;
2022-02-28 15:11:45 +01:00
// confirm auto send on close
if ( $massaction == 'presendonclose' ) {
$hidden_form = array ([
" type " => " hidden " ,
" name " => " massaction " ,
" value " => " close "
]);
$selectedchoice = ( ! empty ( $conf -> global -> TICKET_NOTIFY_AT_CLOSING )) ? " yes " : " no " ;
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ], $langs -> trans ( " ConfirmMassTicketClosingSendEmail " ), $langs -> trans ( " ConfirmMassTicketClosingSendEmailQuestion " ), 'confirm_send_close' , $hidden_form , $selectedchoice , 0 , 200 , 500 , 1 );
}
2021-02-26 13:27:00 +01:00
if ( $search_all ) {
2022-09-01 11:18:46 +02:00
$setupstring = '' ;
2021-02-26 13:27:00 +01:00
foreach ( $fieldstosearchall as $key => $val ) {
$fieldstosearchall [ $key ] = $langs -> trans ( $val );
2022-09-01 11:18:46 +02:00
$setupstring .= $key . " = " . $val . " ; " ;
2021-02-26 13:27:00 +01:00
}
2022-09-01 11:18:46 +02:00
print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = ' . $setupstring . ' -->' . " \n " ;
print '<div class="divsearchfieldfilter">' . $langs -> trans ( " FilterOnInto " , $search_all ) . join ( ', ' , $fieldstosearchall ) . '</div>' . " \n " ;
2018-03-10 04:23:59 +01:00
}
$moreforfilter = '' ;
/* $moreforfilter .= '<div class="divsearchfield">' ;
2018-04-13 12:52:23 +02:00
$moreforfilter .= $langs -> trans ( 'MyFilter' ) . ': <input type="text" name="search_myfield" value="' . dol_escape_htmltag ( $search_myfield ) . '">' ;
$moreforfilter .= '</div>' ; */
2018-03-10 04:23:59 +01:00
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2021-02-26 13:27:00 +01:00
if ( empty ( $reshook )) {
$moreforfilter .= $hookmanager -> resPrint ;
} else {
$moreforfilter = $hookmanager -> resPrint ;
}
2018-03-10 04:23:59 +01:00
2021-02-26 13:27:00 +01:00
if ( ! empty ( $moreforfilter )) {
2018-04-13 12:52:23 +02:00
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
print '</div>' ;
2018-03-10 04:23:59 +01:00
}
2019-11-12 09:46:08 +01:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
$selectedfields .= ( count ( $arrayofmassactions ) ? $form -> showCheckAddButtons ( 'checkforselect' , 1 ) : '' );
2018-03-10 04:23:59 +01:00
2019-11-12 09:46:08 +01:00
print '<div class="div-table-responsive">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2021-10-03 19:17:23 +02:00
print '<div class="div-table-responsive-inside">' ;
2022-01-02 18:22:18 +01:00
print '<table class="tagtable nobottomiftotal liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2018-03-10 04:23:59 +01:00
// Fields title search
// --------------------------------------------------------------------
print '<tr class="liste_titre">' ;
2021-02-26 13:27:00 +01:00
foreach ( $object -> fields as $key => $val ) {
2021-11-01 03:14:54 +01:00
$cssforfield = ( empty ( $val [ 'csslist' ]) ? ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]) : $val [ 'csslist' ]);
2021-02-26 13:27:00 +01:00
if ( $key == 'fk_statut' ) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
} elseif ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
} elseif ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
2021-11-01 03:14:54 +01:00
} elseif ( in_array ( $val [ 'type' ], array ( 'double(24,8)' , 'double(6,3)' , 'integer' , 'real' , 'price' )) && $val [ 'label' ] != 'TechnicalID' && empty ( $val [ 'arrayofkeyval' ])) {
2021-02-26 13:27:00 +01:00
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'right' ;
}
2019-11-12 09:46:08 +01:00
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ])) {
2021-11-01 03:14:54 +01:00
if ( $key == 'progress' ) {
print '<td class="liste_titre right' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
print '<input type="text" class="flat maxwidth50" name="search_' . $key . '" value="' . dol_escape_htmltag ( empty ( $search [ $key ]) ? '' : $search [ $key ]) . '">' ;
print '</td>' ;
} elseif ( $key == 'type_code' ) {
2019-11-12 09:46:08 +01:00
print '<td class="liste_titre' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
2021-06-13 15:47:42 +02:00
$formTicket -> selectTypesTickets ( dol_escape_htmltag ( empty ( $search [ $key ]) ? '' : $search [ $key ]), 'search_' . $key . '' , '' , 2 , 1 , 1 , 0 , ( $val [ 'css' ] ? $val [ 'css' ] : 'maxwidth150' ));
2018-04-13 12:52:23 +02:00
print '</td>' ;
} elseif ( $key == 'category_code' ) {
2019-11-12 09:46:08 +01:00
print '<td class="liste_titre' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
2021-06-13 15:47:42 +02:00
$formTicket -> selectGroupTickets ( dol_escape_htmltag ( empty ( $search [ $key ]) ? '' : $search [ $key ]), 'search_' . $key . '' , '' , 2 , 1 , 1 , 0 , ( $val [ 'css' ] ? $val [ 'css' ] : 'maxwidth150' ));
2018-04-13 12:52:23 +02:00
print '</td>' ;
} elseif ( $key == 'severity_code' ) {
2020-10-02 14:26:16 +02:00
print '<td class="liste_titre center' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
2021-06-13 15:47:42 +02:00
$formTicket -> selectSeveritiesTickets ( dol_escape_htmltag ( empty ( $search [ $key ]) ? '' : $search [ $key ]), 'search_' . $key . '' , '' , 2 , 1 , 1 , 0 , ( $val [ 'css' ] ? $val [ 'css' ] : 'maxwidth150' ));
2018-04-13 12:52:23 +02:00
print '</td>' ;
2020-11-15 10:42:15 +01:00
} elseif ( $key == 'fk_user_assign' || $key == 'fk_user_create' ) {
2020-12-01 02:41:19 +01:00
print '<td class="liste_titre' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
2022-08-02 22:39:18 +02:00
print $form -> select_dolusers (( empty ( $search [ $key ]) ? '' : $search [ $key ]), 'search_' . $key , 1 , null , 0 , '' , '' , '0' , 0 , 0 , '' , 0 , '' , ( $val [ 'css' ] ? $val [ 'css' ] : 'maxwidth100' ));
2020-12-01 02:41:19 +01:00
print '</td>' ;
2018-04-13 12:52:23 +02:00
} elseif ( $key == 'fk_statut' ) {
2020-10-31 14:32:18 +01:00
$arrayofstatus = array ();
$arrayofstatus [ 'openall' ] = '-- ' . $langs -> trans ( 'OpenAll' ) . ' --' ;
2021-02-26 13:27:00 +01:00
foreach ( $object -> statuts_short as $key2 => $val2 ) {
if ( $key2 == Ticket :: STATUS_CLOSED ) {
$arrayofstatus [ 'closeall' ] = '-- ' . $langs -> trans ( 'ClosedAll' ) . ' --' ;
}
2020-10-31 14:32:18 +01:00
$arrayofstatus [ $key2 ] = $val2 ;
}
print '<td class="liste_titre' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
2022-05-17 14:55:38 +02:00
//var_dump($arrayofstatus);
//var_dump($search['fk_statut']);
//var_dump(array_values($search[$key]));
2020-10-31 14:32:18 +01:00
$selectedarray = null ;
2021-06-13 15:47:42 +02:00
if ( ! empty ( $search [ $key ])) {
2021-02-26 13:27:00 +01:00
$selectedarray = array_values ( $search [ $key ]);
}
2021-07-23 00:02:14 +02:00
print Form :: multiselectarray ( 'search_fk_statut' , $arrayofstatus , $selectedarray , 0 , 0 , 'minwidth100imp maxwidth150' , 1 , 0 , '' , '' , '' );
2018-04-13 12:52:23 +02:00
print '</td>' ;
2020-09-25 14:16:59 +02:00
} elseif ( $key == " fk_soc " ) {
2019-11-12 09:46:08 +01:00
print '<td class="liste_titre' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '"><input type="text" class="flat maxwidth75" name="search_societe" value="' . dol_escape_htmltag ( $search_societe ) . '"></td>' ;
2021-02-26 13:27:00 +01:00
} elseif ( $key == " datec " || $key == 'date_read' || $key == 'date_close' ) {
2021-01-04 10:59:45 +01:00
print '<td class="liste_titre center">' ;
print '<div class="nowrap">' ;
2021-02-26 13:27:00 +01:00
switch ( $key ) {
2021-01-04 10:59:45 +01:00
case 'datec' :
2021-01-04 12:17:59 +01:00
print $form -> selectDate ( $search_date_start ? : - 1 , 'search_date_start' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " From " ));
2021-01-04 10:59:45 +01:00
break ;
case 'date_read' :
2021-01-04 12:17:59 +01:00
print $form -> selectDate ( $search_dateread_start ? : - 1 , 'search_dateread_start' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " From " ));
2021-01-04 10:59:45 +01:00
break ;
case 'date_close' :
2021-01-04 12:17:59 +01:00
print $form -> selectDate ( $search_dateclose_start ? : - 1 , 'search_dateclose_start' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " From " ));
2021-01-04 10:59:45 +01:00
}
print '</div>' ;
print '<div class="nowrap">' ;
2021-02-26 13:27:00 +01:00
switch ( $key ) {
2021-01-04 10:59:45 +01:00
case 'datec' :
2021-01-04 12:17:59 +01:00
print $form -> selectDate ( $search_date_end ? : - 1 , 'search_date_end' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " to " ));
2021-01-04 10:59:45 +01:00
break ;
case 'date_read' :
2021-01-04 12:17:59 +01:00
print $form -> selectDate ( $search_dateread_end ? : - 1 , 'search_dateread_end' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " to " ));
2021-01-04 10:59:45 +01:00
break ;
case 'date_close' :
2021-01-04 12:17:59 +01:00
print $form -> selectDate ( $search_dateclose_end ? : - 1 , 'search_dateclose_end' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " to " ));
2021-01-04 10:59:45 +01:00
}
print '</div>' ;
print '</td>' ;
2021-02-26 13:27:00 +01:00
} else {
2020-09-25 14:16:59 +02:00
print '<td class="liste_titre' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
2021-02-26 13:27:00 +01:00
if ( ! empty ( $val [ 'arrayofkeyval' ]) && is_array ( $val [ 'arrayofkeyval' ])) {
print $form -> selectarray ( 'search_' . $key , $val [ 'arrayofkeyval' ], $search [ $key ], $val [ 'notnull' ], 0 , 0 , '' , 1 , 0 , 0 , '' , 'maxwidth100' , 1 );
} elseif ( strpos ( $val [ 'type' ], 'integer:' ) === 0 ) {
2020-09-25 14:16:59 +02:00
print $object -> showInputField ( $val , $key , $search [ $key ], '' , '' , 'search_' , 'maxwidth150' , 1 );
2021-02-26 13:27:00 +01:00
} elseif ( ! preg_match ( '/^(date|timestamp)/' , $val [ 'type' ])) {
2021-06-13 15:47:42 +02:00
print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag ( empty ( $search [ $key ]) ? '' : $search [ $key ]) . '">' ;
2021-02-26 13:27:00 +01:00
}
2020-09-25 14:16:59 +02:00
print '</td>' ;
2018-04-13 12:52:23 +02:00
}
}
2018-03-10 04:23:59 +01:00
}
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php' ;
// Fields from hook
2019-11-12 09:46:08 +01:00
$parameters = array ( 'arrayfields' => $arrayfields );
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2018-03-10 04:23:59 +01:00
print $hookmanager -> resPrint ;
// Action column
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">' ;
2019-11-12 09:46:08 +01:00
$searchpicto = $form -> showFilterButtons ();
2018-03-10 04:23:59 +01:00
print $searchpicto ;
print '</td>' ;
print '</tr>' . " \n " ;
// Fields title label
// --------------------------------------------------------------------
print '<tr class="liste_titre">' ;
2021-02-26 13:27:00 +01:00
foreach ( $object -> fields as $key => $val ) {
2021-11-01 03:14:54 +01:00
$cssforfield = ( empty ( $val [ 'csslist' ]) ? ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]) : $val [ 'csslist' ]);
2021-02-26 13:27:00 +01:00
if ( $key == 'fk_statut' || $key == 'severity_code' ) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
} elseif ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
} elseif ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
2021-11-01 03:14:54 +01:00
} elseif ( in_array ( $val [ 'type' ], array ( 'double(24,8)' , 'double(6,3)' , 'integer' , 'real' , 'price' )) && $val [ 'label' ] != 'TechnicalID' && empty ( $val [ 'arrayofkeyval' ])) {
2021-02-26 13:27:00 +01:00
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'right' ;
}
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ])) {
2021-11-01 03:14:54 +01:00
print getTitleFieldOfList ( $arrayfields [ 't.' . $key ][ 'label' ], 0 , $_SERVER [ 'PHP_SELF' ], 't.' . $key , '' , $param , ( $cssforfield ? 'class="' . $cssforfield . '"' : '' ), $sortfield , $sortorder , ( $cssforfield ? $cssforfield . ' ' : '' )) . " \n " ;
2018-11-11 15:06:08 +01:00
}
2018-03-10 04:23:59 +01:00
}
2021-10-25 20:48:45 +02:00
$totalarray = array (
'nbfield' => 0 ,
);
2018-03-10 04:23:59 +01:00
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php' ;
// Hook fields
2021-10-25 20:48:45 +02:00
$parameters = array (
'arrayfields' => $arrayfields ,
'param' => $param ,
'sortfield' => $sortfield ,
'sortorder' => $sortorder ,
'totalarray' => & $totalarray ,
);
2019-11-12 09:46:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2018-03-10 04:23:59 +01:00
print $hookmanager -> resPrint ;
2022-01-02 18:22:18 +01:00
print getTitleFieldOfList ( $selectedfields , 0 , $_SERVER [ " PHP_SELF " ], '' , '' , '' , '' , $sortfield , $sortorder , 'center maxwidthsearch ' ) . " \n " ;
2018-03-10 04:23:59 +01:00
print '</tr>' . " \n " ;
// Detect if we need a fetch on each output line
2019-11-12 09:46:08 +01:00
$needToFetchEachLine = 0 ;
2022-01-02 18:22:18 +01:00
if ( isset ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) && is_array ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) > 0 ) {
2021-02-26 13:27:00 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ] as $key => $val ) {
if ( preg_match ( '/\$object/' , $val )) {
$needToFetchEachLine ++ ; // There is at least one compute field that use $object
}
2018-04-18 09:27:54 +02:00
}
2018-03-10 04:23:59 +01:00
}
2018-07-16 12:13:34 +02:00
2018-03-10 04:23:59 +01:00
// Loop on record
// --------------------------------------------------------------------
2019-11-12 09:46:08 +01:00
$i = 0 ;
2022-01-02 18:22:18 +01:00
$totalarray = array ();
$totalarray [ 'nbfield' ] = 0 ;
2022-02-07 12:30:47 +01:00
$now = dol_now ();
2021-10-31 17:54:32 +01:00
2020-09-08 04:21:35 +02:00
$cacheofoutputfield = array ();
2022-01-02 18:22:18 +01:00
while ( $i < ( $limit ? min ( $num , $limit ) : $num )) {
2018-04-13 12:52:23 +02:00
$obj = $db -> fetch_object ( $resql );
2021-02-26 13:27:00 +01:00
if ( empty ( $obj )) {
break ; // Should not happen
}
2018-04-13 12:52:23 +02:00
// Store properties in $object
2022-01-02 18:22:18 +01:00
$object -> setVarsFromFetchObj ( $obj );
2022-02-10 11:15:11 +01:00
$object -> status = $object -> fk_statut ; // fk_statut is deprecated
2018-04-13 12:52:23 +02:00
// Show here line of result
print '<tr class="oddeven">' ;
2021-02-26 13:27:00 +01:00
foreach ( $object -> fields as $key => $val ) {
2022-01-02 18:22:18 +01:00
$cssforfield = ( empty ( $val [ 'csslist' ]) ? ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]) : $val [ 'csslist' ]);
2021-02-26 13:27:00 +01:00
if ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
}
if ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
}
if ( in_array ( $key , array ( 'ref' , 'fk_project' ))) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowraponall' ;
}
if ( $key == 'fk_statut' || $key == 'severity_code' ) {
$cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
}
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ])) {
2018-04-13 12:52:23 +02:00
print '<td' ;
2021-10-22 17:42:57 +02:00
if ( $cssforfield || ( array_key_exists ( 'css' , $val ) && $val [ 'css' ])) {
2021-02-26 13:27:00 +01:00
print ' class="' ;
}
2018-11-11 15:06:08 +01:00
print $cssforfield ;
2021-10-22 17:42:57 +02:00
if ( $cssforfield && array_key_exists ( 'css' , $val ) && $val [ 'css' ]) {
2021-02-26 13:27:00 +01:00
print ' ' ;
}
2021-10-22 17:42:57 +02:00
if ( array_key_exists ( 'css' , $val )) {
print $val [ 'css' ];
}
if ( $cssforfield || ( array_key_exists ( 'css' , $val ) && $val [ 'css' ])) {
2021-02-26 13:27:00 +01:00
print '"' ;
}
2018-04-13 12:52:23 +02:00
print '>' ;
2021-02-26 13:27:00 +01:00
if ( $key == 'fk_statut' ) {
print $object -> getLibStatut ( 5 );
} elseif ( $key == 'subject' ) {
2021-02-02 00:19:41 +01:00
$s = $obj -> subject ;
2021-06-26 16:42:35 +02:00
print '<span title="' . dol_escape_htmltag ( $s ) . '">' ;
2022-08-02 22:39:18 +02:00
print dol_escape_htmltag ( $s );
2021-02-02 00:19:41 +01:00
print '</span>' ;
2021-02-26 13:27:00 +01:00
} elseif ( $key == 'type_code' ) {
2020-09-08 21:27:28 +02:00
$s = $langs -> getLabelFromKey ( $db , 'TicketTypeShort' . $object -> type_code , 'c_ticket_type' , 'code' , 'label' , $object -> type_code );
2021-06-26 16:42:35 +02:00
print '<span title="' . dol_escape_htmltag ( $s ) . '">' ;
2020-09-08 04:21:35 +02:00
print $s ;
print '</span>' ;
2021-02-26 13:27:00 +01:00
} elseif ( $key == 'category_code' ) {
2020-10-16 15:40:52 +02:00
$s = $langs -> getLabelFromKey ( $db , 'TicketCategoryShort' . $object -> category_code , 'c_ticket_category' , 'code' , 'label' , $object -> category_code );
2021-06-26 16:42:35 +02:00
print '<span title="' . dol_escape_htmltag ( $s ) . '">' ;
2020-10-16 15:40:52 +02:00
print $s ;
print '</span>' ;
2021-02-26 13:27:00 +01:00
} elseif ( $key == 'severity_code' ) {
2020-10-16 15:40:52 +02:00
$s = $langs -> getLabelFromKey ( $db , 'TicketSeverityShort' . $object -> severity_code , 'c_ticket_severity' , 'code' , 'label' , $object -> severity_code );
2021-06-26 16:42:35 +02:00
print '<span title="' . dol_escape_htmltag ( $s ) . '">' ;
2020-10-16 15:40:52 +02:00
print $s ;
print '</span>' ;
2021-02-26 13:27:00 +01:00
} elseif ( $key == 'tms' ) {
print dol_print_date ( $db -> jdate ( $obj -> $key ), 'dayhour' , 'tzuser' );
} elseif ( $key == 'fk_user_create' ) {
2020-04-10 12:27:34 +02:00
if ( $object -> fk_user_create > 0 ) {
2021-06-26 15:39:52 +02:00
if ( isset ( $conf -> cache [ 'user' ][ $object -> fk_user_create ])) {
$user_temp = $conf -> cache [ 'user' ][ $object -> fk_user_create ];
} else {
$user_temp = new User ( $db );
$user_temp -> fetch ( $object -> fk_user_create );
$conf -> cache [ 'user' ][ $object -> fk_user_create ] = $user_temp ;
}
print $user_temp -> getNomUrl ( - 1 );
}
} elseif ( $key == 'fk_user_assign' ) {
if ( $object -> fk_user_assign > 0 ) {
if ( isset ( $conf -> cache [ 'user' ][ $object -> fk_user_assign ])) {
$user_temp = $conf -> cache [ 'user' ][ $object -> fk_user_assign ];
} else {
$user_temp = new User ( $db );
$user_temp -> fetch ( $object -> fk_user_assign );
$conf -> cache [ 'user' ][ $object -> fk_user_assign ] = $user_temp ;
}
print $user_temp -> getNomUrl ( - 1 );
2020-04-10 12:27:34 +02:00
}
2021-02-26 13:27:00 +01:00
} elseif ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) {
print $object -> showOutputField ( $val , $key , $db -> jdate ( $obj -> $key ), '' );
2022-02-07 12:30:47 +01:00
} elseif ( $key == 'ref' ) {
print $object -> showOutputField ( $val , $key , $obj -> $key , '' );
// display a warning on untreated tickets
$is_open = ( $object -> status != Ticket :: STATUS_CLOSED && $object -> status != Ticket :: STATUS_CANCELED );
$should_show_warning = ( ! empty ( $conf -> global -> TICKET_DELAY_SINCE_LAST_RESPONSE ) || ! empty ( $conf -> global -> TICKET_DELAY_BEFORE_FIRST_RESPONSE ));
if ( $is_open && $should_show_warning ) {
$date_last_msg_sent = ( int ) $object -> date_last_msg_sent ;
$hour_diff = ( $now - $date_last_msg_sent ) / 3600 ;
if ( ! empty ( $conf -> global -> TICKET_DELAY_BEFORE_FIRST_RESPONSE && $date_last_msg_sent == 0 )) {
$creation_date = $object -> datec ;
$hour_diff_creation = ( $now - $creation_date ) / 3600 ;
if ( $hour_diff_creation > $conf -> global -> TICKET_DELAY_BEFORE_FIRST_RESPONSE ) {
print " " . img_picto ( $langs -> trans ( 'Late' ) . ' : ' . $langs -> trans ( 'TicketsDelayForFirstResponseTooLong' , $conf -> global -> TICKET_DELAY_BEFORE_FIRST_RESPONSE ), 'warning' , 'style="color: red;"' , false , 0 , 0 , '' , '' );
}
} elseif ( ! empty ( $conf -> global -> TICKET_DELAY_SINCE_LAST_RESPONSE ) && $hour_diff > $conf -> global -> TICKET_DELAY_SINCE_LAST_RESPONSE ) {
print " " . img_picto ( $langs -> trans ( 'Late' ) . ' : ' . $langs -> trans ( 'TicketsDelayFromLastResponseTooLong' , $conf -> global -> TICKET_DELAY_SINCE_LAST_RESPONSE ), 'warning' );
}
}
2021-02-26 13:27:00 +01:00
} else { // Example: key=fk_soc, obj->key=123 val=array('type'=>'integer', ...
2020-09-08 04:21:35 +02:00
$tmp = explode ( ':' , $val [ 'type' ]);
if ( $tmp [ 0 ] == 'integer' && ! empty ( $tmp [ 1 ]) && class_exists ( $tmp [ 1 ])) {
// It is a type of an foreign field. We will try to reduce the number of fetch that the showOutputField is making.
//var_dump('eeee-'.$key.'-'.$obj->$key.'-'.$val['type']);
if ( $key && $obj -> $key && $val [ 'type' ] && array_key_exists ( $key . '-' . $obj -> $key . '-' . $val [ 'type' ], $cacheofoutputfield )) {
$result = $cacheofoutputfield [ $key . '-' . $obj -> $key . '-' . $val [ 'type' ]];
} else {
$result = $object -> showOutputField ( $val , $key , $obj -> $key , '' );
$cacheofoutputfield [ $key . '-' . $obj -> $key . '-' . $val [ 'type' ]] = $result ;
}
} else {
$result = $object -> showOutputField ( $val , $key , $obj -> $key , '' );
}
print $result ;
}
2018-04-13 12:52:23 +02:00
print '</td>' ;
2021-02-26 13:27:00 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2021-10-19 16:26:43 +02:00
if ( ! empty ( $val [ 'isameasure' ]) && $val [ 'isameasure' ] == 1 ) {
2021-02-26 13:27:00 +01:00
if ( ! $i ) {
$totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 't.' . $key ;
}
2021-06-14 01:55:58 +02:00
if ( ! isset ( $totalarray [ 'val' ])) {
$totalarray [ 'val' ] = array ();
}
if ( ! isset ( $totalarray [ 'val' ][ 't.' . $key ])) {
$totalarray [ 'val' ][ 't.' . $key ] = 0 ;
}
2021-10-19 16:26:43 +02:00
$totalarray [ 'val' ][ 't.' . $key ] += $object -> $key ;
2018-04-13 12:52:23 +02:00
}
}
}
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
// Fields from hook
2022-01-02 18:22:18 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'object' => $object , 'obj' => $obj , 'i' => $i , 'totalarray' =>& $totalarray );
2019-11-12 09:46:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2018-04-13 12:52:23 +02:00
print $hookmanager -> resPrint ;
// Action column
2019-02-23 19:27:42 +01:00
print '<td class="nowrap center">' ;
2021-02-26 13:27:00 +01:00
if ( $massactionbutton || $massaction ) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2019-11-12 09:46:08 +01:00
$selected = 0 ;
2021-02-26 13:27:00 +01:00
if ( in_array ( $obj -> rowid , $arrayofselected )) {
$selected = 1 ;
}
2019-11-12 09:46:08 +01:00
print '<input id="cb' . $obj -> rowid . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $obj -> rowid . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
2018-04-13 12:52:23 +02:00
}
print '</td>' ;
2021-02-26 13:27:00 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2018-04-13 12:52:23 +02:00
2022-01-02 18:22:18 +01:00
print '</tr>' . " \n " ;
2018-04-13 12:52:23 +02:00
$i ++ ;
2018-03-10 04:23:59 +01:00
}
// Show total line
2019-11-05 12:47:38 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php' ;
2018-03-10 04:23:59 +01:00
// If no record found
2021-02-26 13:27:00 +01:00
if ( $num == 0 ) {
2019-11-12 09:46:08 +01:00
$colspan = 1 ;
2021-02-26 13:27:00 +01:00
foreach ( $arrayfields as $key => $val ) {
if ( ! empty ( $val [ 'checked' ])) {
$colspan ++ ;
}
}
2021-10-10 21:25:46 +02:00
print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</span></td></tr>' ;
2018-03-10 04:23:59 +01:00
}
$db -> free ( $resql );
2019-11-12 09:46:08 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'sql' => $sql );
$reshook = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2018-03-10 04:23:59 +01:00
print $hookmanager -> resPrint ;
print '</table>' . " \n " ;
print '</div>' . " \n " ;
2022-01-02 18:22:18 +01:00
print '</div>' . " \n " ; // end div-responsive-inside
2018-03-10 04:23:59 +01:00
print '</form>' . " \n " ;
2019-02-11 15:41:07 +01:00
2021-02-26 13:27:00 +01:00
if ( in_array ( 'builddoc' , $arrayofmassactions ) && ( $nbtotalofrecords === '' || $nbtotalofrecords )) {
2019-11-12 09:46:08 +01:00
$hidegeneratedfilelistifempty = 1 ;
2021-02-26 13:27:00 +01:00
if ( $massaction == 'builddoc' || $action == 'remove_file' || $show_files ) {
$hidegeneratedfilelistifempty = 0 ;
}
2018-04-15 16:35:18 +02:00
2018-07-25 10:15:34 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2018-04-13 12:52:23 +02:00
$formfile = new FormFile ( $db );
2018-04-15 16:35:18 +02:00
2018-04-13 12:52:23 +02:00
// Show list of available documents
2019-11-12 09:46:08 +01:00
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder ;
$urlsource .= str_replace ( '&' , '&' , $param );
2018-04-15 16:35:18 +02:00
2019-11-12 09:46:08 +01:00
$filedir = $diroutputmassaction ;
2022-01-02 18:22:18 +01:00
$genallowed = $permissiontoread ;
$delallowed = $permissiontoadd ;
2018-04-15 16:35:18 +02:00
2019-01-27 11:55:16 +01:00
print $formfile -> showdocuments ( 'massfilesarea_ticket' , '' , $filedir , $urlsource , 0 , $delallowed , '' , 1 , 1 , 0 , 48 , 1 , $param , $title , '' , '' , '' , null , $hidegeneratedfilelistifempty );
2018-03-10 04:23:59 +01:00
}
// End of page
2018-04-13 12:52:23 +02:00
llxFooter ();
2018-03-10 04:23:59 +01:00
$db -> close ();