2014-01-02 07:07:43 +01:00
< ? php
2018-10-27 11:46:12 +02:00
/* Copyright ( C ) 2013 - 2018 Jean - François Ferry < hello + jf @ librethic . io >
2016-02-01 16:15:30 +01:00
* Copyright ( C ) 2016 Gilles Poirier < glgpoirier @ gmail . com >
2019-07-29 18:17:48 +02:00
* Copyright ( C ) 2019 Josep Lluís Amador < joseplluis @ lliuretic . cat >
2021-03-31 00:46:47 +02:00
* Copyright ( C ) 2021 Frédéric France < frederic . france @ netlogic . fr >
2014-01-02 07:07:43 +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 />.
2014-01-02 07:07:43 +01:00
*/
/**
2016-01-21 11:18:29 +01:00
* \file resource / element_resource . php
2016-04-29 18:31:11 +02:00
* \ingroup resource
* \brief Page to show and manage linked resources to an element
2014-01-02 07:07:43 +01:00
*/
2018-07-25 10:11:44 +02:00
require '../main.inc.php' ;
2016-12-09 15:59:31 +01:00
require_once DOL_DOCUMENT_ROOT . '/resource/class/dolresource.class.php' ;
2014-04-15 18:01:18 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2016-07-26 16:35:54 +02:00
require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php' ;
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2020-10-31 14:32:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2017-02-22 17:46:54 +01:00
}
2019-11-08 10:53:31 +01:00
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) {
2020-10-31 14:32:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2019-04-07 21:30:13 +02:00
}
2014-01-02 07:07:43 +01:00
2018-05-26 18:41:16 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'resource' , 'other' , 'interventions' ));
2014-01-02 07:07:43 +01:00
/*
2016-01-21 11:18:29 +01:00
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2014-01-02 07:07:43 +01:00
*/
2021-02-26 20:53:03 +01:00
if ( ! $user -> rights -> resource -> read ) {
2020-10-31 14:32:18 +01:00
accessforbidden ();
2021-02-26 20:53:03 +01:00
}
2014-01-02 07:07:43 +01:00
2019-11-08 10:53:31 +01:00
$object = new Dolresource ( $db );
2014-01-02 07:07:43 +01:00
$hookmanager -> initHooks ( array ( 'element_resource' ));
2016-01-21 11:18:29 +01:00
$object -> available_resources = array ( 'dolresource' );
2014-01-02 07:07:43 +01:00
2014-09-07 12:22:04 +02:00
// Get parameters
2019-11-08 10:53:31 +01:00
$id = GETPOST ( 'id' , 'int' ); // resource id
$element_id = GETPOST ( 'element_id' , 'int' ); // element_id
$element_ref = GETPOST ( 'ref' , 'alpha' ); // element ref
$element = GETPOST ( 'element' , 'alpha' ); // element_type
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$mode = GETPOST ( 'mode' , 'alpha' );
$lineid = GETPOST ( 'lineid' , 'int' );
$resource_id = GETPOST ( 'fk_resource' , 'int' );
$resource_type = GETPOST ( 'resource_type' , 'alpha' );
$busy = GETPOST ( 'busy' , 'int' );
$mandatory = GETPOST ( 'mandatory' , 'int' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$socid = GETPOST ( 'socid' , 'int' );
2016-01-21 11:18:29 +01:00
2021-02-26 20:53:03 +01:00
if ( $socid > 0 ) { // Special for thirdparty
2020-10-31 14:32:18 +01:00
$element_id = $socid ;
$element = 'societe' ;
2015-12-05 19:20:39 +01:00
}
2015-05-31 02:05:39 +02:00
2016-01-21 11:18:29 +01:00
2015-05-31 02:05:39 +02:00
/*
* Actions
*/
2019-07-26 17:51:54 +02:00
$parameters = array ( 'resource_id' => $resource_id );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 20:53:03 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2019-07-26 17:51:54 +02:00
2021-02-26 20:53:03 +01:00
if ( empty ( $reshook )) {
2020-10-31 14:32:18 +01:00
$error = 0 ;
2019-09-04 15:14:16 +02:00
2021-02-26 20:53:03 +01:00
if ( $action == 'add_element_resource' && ! $cancel ) {
2019-07-26 17:51:54 +02:00
$res = 0 ;
2021-02-26 20:53:03 +01:00
if ( ! ( $resource_id > 0 )) {
2019-07-26 17:51:54 +02:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Resource " )), null , 'errors' );
2019-11-08 10:53:31 +01:00
$action = '' ;
2020-05-21 15:05:19 +02:00
} else {
2019-07-26 17:51:54 +02:00
$objstat = fetchObjectByElement ( $element_id , $element , $element_ref );
$objstat -> element = $element ; // For externals module, we need to keep @xx
2019-09-04 15:14:16 +02:00
2020-10-31 14:32:18 +01:00
// TODO : add this check at update_linked_resource and when modifying event start or end date
// check if an event resource is already in use
if ( ! empty ( $conf -> global -> RESOURCE_USED_IN_EVENT_CHECK ) && $objstat -> element == 'action' && $resource_type == 'dolresource' && intval ( $busy ) == 1 ) {
$eventDateStart = $objstat -> datep ;
$eventDateEnd = $objstat -> datef ;
$isFullDayEvent = intval ( $objstat -> fulldayevent );
if ( empty ( $eventDateEnd )) {
if ( $isFullDayEvent ) {
$eventDateStartArr = dol_getdate ( $eventDateStart );
$eventDateStart = dol_mktime ( 0 , 0 , 0 , $eventDateStartArr [ 'mon' ], $eventDateStartArr [ 'mday' ], $eventDateStartArr [ 'year' ]);
$eventDateEnd = dol_mktime ( 23 , 59 , 59 , $eventDateStartArr [ 'mon' ], $eventDateStartArr [ 'mday' ], $eventDateStartArr [ 'year' ]);
}
}
$sql = " SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " element_resources as er " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " resource as r ON r.rowid = er.resource_id AND er.resource_type = ' " . $db -> escape ( $resource_type ) . " ' " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " actioncomm as ac ON ac.id = er.element_id AND er.element_type = ' " . $db -> escape ( $objstat -> element ) . " ' " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE er.resource_id = " . (( int ) $resource_id );
2020-10-31 14:32:18 +01:00
$sql .= " AND er.busy = 1 " ;
$sql .= " AND ( " ;
// event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
$sql .= " (ac.datep <= ' " . $db -> idate ( $eventDateStart ) . " ' AND (ac.datep2 IS NULL OR ac.datep2 >= ' " . $db -> idate ( $eventDateStart ) . " ')) " ;
// event date end between ac.datep and ac.datep2
if ( ! empty ( $eventDateEnd )) {
$sql .= " OR (ac.datep <= ' " . $db -> idate ( $eventDateEnd ) . " ' AND (ac.datep2 >= ' " . $db -> idate ( $eventDateEnd ) . " ')) " ;
}
// event date start before ac.datep and event date end after ac.datep2
$sql .= " OR ( " ;
$sql .= " ac.datep >= ' " . $db -> idate ( $eventDateStart ) . " ' " ;
if ( ! empty ( $eventDateEnd )) {
$sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= ' " . $db -> idate ( $eventDateEnd ) . " ') " ;
}
$sql .= " ) " ;
$sql .= " ) " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) {
$error ++ ;
$objstat -> error = $db -> lasterror ();
$objstat -> errors [] = $objstat -> error ;
} else {
if ( $db -> num_rows ( $resql ) > 0 ) {
// already in use
$error ++ ;
$objstat -> error = $langs -> trans ( 'ErrorResourcesAlreadyInUse' ) . ' : ' ;
while ( $obj = $db -> fetch_object ( $resql )) {
$objstat -> error .= '<br> - ' . $langs -> trans ( 'ErrorResourceUseInEvent' , $obj -> r_ref , $obj -> ac_label . ' [' . $obj -> ac_id . ']' );
}
$objstat -> errors [] = $objstat -> error ;
}
$db -> free ( $resql );
}
}
if ( ! $error ) {
$res = $objstat -> add_element_resource ( $resource_id , $resource_type , $busy , $mandatory );
}
2019-07-26 17:51:54 +02:00
}
2019-09-04 15:14:16 +02:00
2021-02-26 20:53:03 +01:00
if ( ! $error && $res > 0 ) {
2019-07-26 17:51:54 +02:00
setEventMessages ( $langs -> trans ( 'ResourceLinkedWithSuccess' ), null , 'mesgs' );
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?element=' . $element . '&element_id=' . $objstat -> id );
exit ;
2021-02-26 20:53:03 +01:00
} elseif ( $objstat ) {
2019-07-26 17:51:54 +02:00
setEventMessages ( $objstat -> error , $objstat -> errors , 'errors' );
}
2016-12-09 15:59:31 +01:00
}
2019-07-26 17:51:54 +02:00
// Update ressource
2021-02-26 20:53:03 +01:00
if ( $action == 'update_linked_resource' && $user -> rights -> resource -> write && ! GETPOST ( 'cancel' , 'alpha' )) {
2019-07-26 17:51:54 +02:00
$res = $object -> fetch_element_resource ( $lineid );
2021-02-26 20:53:03 +01:00
if ( $res ) {
2019-07-26 17:51:54 +02:00
$object -> busy = $busy ;
$object -> mandatory = $mandatory ;
2020-10-31 14:32:18 +01:00
if ( ! empty ( $conf -> global -> RESOURCE_USED_IN_EVENT_CHECK ) && $object -> element_type == 'action' && $object -> resource_type == 'dolresource' && intval ( $object -> busy ) == 1 ) {
$eventDateStart = $object -> objelement -> datep ;
$eventDateEnd = $object -> objelement -> datef ;
$isFullDayEvent = intval ( $objstat -> fulldayevent );
if ( empty ( $eventDateEnd )) {
if ( $isFullDayEvent ) {
$eventDateStartArr = dol_getdate ( $eventDateStart );
$eventDateStart = dol_mktime ( 0 , 0 , 0 , $eventDateStartArr [ 'mon' ], $eventDateStartArr [ 'mday' ], $eventDateStartArr [ 'year' ]);
$eventDateEnd = dol_mktime ( 23 , 59 , 59 , $eventDateStartArr [ 'mon' ], $eventDateStartArr [ 'mday' ], $eventDateStartArr [ 'year' ]);
}
}
$sql = " SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " element_resources as er " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " resource as r ON r.rowid = er.resource_id AND er.resource_type = ' " . $db -> escape ( $object -> resource_type ) . " ' " ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " actioncomm as ac ON ac.id = er.element_id AND er.element_type = ' " . $db -> escape ( $object -> element_type ) . " ' " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE er.resource_id = " . (( int ) $object -> resource_id );
$sql .= " AND ac.id <> " . (( int ) $object -> element_id );
2020-10-31 14:32:18 +01:00
$sql .= " AND er.busy = 1 " ;
$sql .= " AND ( " ;
// event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
$sql .= " (ac.datep <= ' " . $db -> idate ( $eventDateStart ) . " ' AND (ac.datep2 IS NULL OR ac.datep2 >= ' " . $db -> idate ( $eventDateStart ) . " ')) " ;
// event date end between ac.datep and ac.datep2
if ( ! empty ( $eventDateEnd )) {
$sql .= " OR (ac.datep <= ' " . $db -> idate ( $eventDateEnd ) . " ' AND (ac.datep2 IS NULL OR ac.datep2 >= ' " . $db -> idate ( $eventDateEnd ) . " ')) " ;
}
// event date start before ac.datep and event date end after ac.datep2
$sql .= " OR ( " ;
$sql .= " ac.datep >= ' " . $db -> idate ( $eventDateStart ) . " ' " ;
if ( ! empty ( $eventDateEnd )) {
$sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= ' " . $db -> idate ( $eventDateEnd ) . " ') " ;
}
$sql .= " ) " ;
$sql .= " ) " ;
$resql = $db -> query ( $sql );
if ( ! $resql ) {
$error ++ ;
$object -> error = $db -> lasterror ();
$object -> errors [] = $object -> error ;
} else {
if ( $db -> num_rows ( $resql ) > 0 ) {
// already in use
$error ++ ;
$object -> error = $langs -> trans ( 'ErrorResourcesAlreadyInUse' ) . ' : ' ;
while ( $obj = $db -> fetch_object ( $resql )) {
$object -> error .= '<br> - ' . $langs -> trans ( 'ErrorResourceUseInEvent' , $obj -> r_ref , $obj -> ac_label . ' [' . $obj -> ac_id . ']' );
}
$object -> errors [] = $objstat -> error ;
}
$db -> free ( $resql );
}
}
if ( ! $error ) {
$result = $object -> update_element_resource ( $user );
2021-02-26 20:53:03 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2020-10-31 14:32:18 +01:00
}
2019-09-04 15:14:16 +02:00
if ( $error ) {
2020-10-31 14:32:18 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2019-09-04 15:14:16 +02:00
} else {
2019-07-26 17:51:54 +02:00
setEventMessages ( $langs -> trans ( 'RessourceLineSuccessfullyUpdated' ), null , 'mesgs' );
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?element= " . $element . " &element_id= " . $element_id );
exit ;
}
}
2016-12-09 15:59:31 +01:00
}
2014-04-23 19:04:10 +02:00
2019-07-26 17:51:54 +02:00
// Delete a resource linked to an element
2021-02-26 20:53:03 +01:00
if ( $action == 'confirm_delete_linked_resource' && $user -> rights -> resource -> delete && $confirm === 'yes' ) {
2019-07-26 17:51:54 +02:00
$result = $object -> delete_resource ( $lineid , $element );
2016-12-09 15:59:31 +01:00
2021-02-26 20:53:03 +01:00
if ( $result >= 0 ) {
2019-07-26 17:51:54 +02:00
setEventMessages ( $langs -> trans ( 'RessourceLineSuccessfullyDeleted' ), null , 'mesgs' );
2016-12-09 15:59:31 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?element= " . $element . " &element_id= " . $element_id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2016-12-09 15:59:31 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2014-09-07 12:22:04 +02:00
}
2019-11-08 10:53:31 +01:00
$parameters = array ( 'resource_id' => $resource_id );
$reshook = $hookmanager -> executeHooks ( 'getElementResources' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 20:53:03 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2014-01-02 07:07:43 +01:00
2015-05-31 02:05:39 +02:00
/*
* View
*/
2014-01-02 07:07:43 +01:00
2019-11-08 10:53:31 +01:00
$form = new Form ( $db );
2014-01-02 07:07:43 +01:00
2019-11-08 10:53:31 +01:00
$pagetitle = $langs -> trans ( 'ResourceElementPage' );
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $pagetitle , '' );
2015-05-31 02:05:39 +02:00
2014-01-02 07:07:43 +01:00
// Load available resource, declared by modules
2014-04-23 19:04:10 +02:00
$ret = count ( $object -> available_resources );
2019-11-08 10:53:31 +01:00
if ( $ret == - 1 ) {
2020-10-31 14:32:18 +01:00
dol_print_error ( $db , $object -> error );
exit ;
2014-01-02 07:07:43 +01:00
}
2016-06-07 13:15:38 +02:00
if ( ! $ret ) {
2020-10-31 14:32:18 +01:00
print '<div class="warning">' . $langs -> trans ( 'NoResourceInDatabase' ) . '</div>' ;
2020-05-21 15:05:19 +02:00
} else {
2016-12-09 15:59:31 +01:00
// Confirmation suppression resource line
2021-02-26 20:53:03 +01:00
if ( $action == 'delete_resource' ) {
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( " element_resource.php?element= " . $element . " &element_id= " . $element_id . " &id= " . $id . " &lineid= " . $lineid , $langs -> trans ( " DeleteResource " ), $langs -> trans ( " ConfirmDeleteResourceElement " ), " confirm_delete_linked_resource " , '' , '' , 1 );
2016-12-09 15:59:31 +01:00
}
// Specific to agenda module
2021-02-26 20:53:03 +01:00
if (( $element_id || $element_ref ) && $element == 'action' ) {
2016-12-09 15:59:31 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/agenda.lib.php' ;
2019-01-27 11:55:16 +01:00
$act = fetchObjectByElement ( $element_id , $element , $element_ref );
2021-02-26 20:53:03 +01:00
if ( is_object ( $act )) {
2019-11-08 10:53:31 +01:00
$head = actions_prepare_head ( $act );
2016-12-09 15:59:31 +01:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'resources' , $langs -> trans ( " Action " ), - 1 , 'action' );
2016-12-09 15:59:31 +01:00
2019-11-08 10:53:31 +01:00
$linkback = img_picto ( $langs -> trans ( " BackToList " ), 'object_list' , 'class="hideonsmartphone pictoactionview"' );
2020-07-09 12:33:28 +02:00
$linkback .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?action=show_list">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2016-12-09 15:59:31 +01:00
// Link to other agenda views
2019-11-08 10:53:31 +01:00
$out = '' ;
$out .= '</li><li class="noborder litext">' . img_picto ( $langs -> trans ( " ViewPerUser " ), 'object_calendarperuser' , 'class="hideonsmartphone pictoactionview"' );
$out .= '<a href="' . DOL_URL_ROOT . '/comm/action/peruser.php?action=show_peruser&year=' . dol_print_date ( $act -> datep , '%Y' ) . '&month=' . dol_print_date ( $act -> datep , '%m' ) . '&day=' . dol_print_date ( $act -> datep , '%d' ) . '">' . $langs -> trans ( " ViewPerUser " ) . '</a>' ;
$out .= '</li><li class="noborder litext">' . img_picto ( $langs -> trans ( " ViewCal " ), 'object_calendar' , 'class="hideonsmartphone pictoactionview"' );
$out .= '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?action=show_month&year=' . dol_print_date ( $act -> datep , '%Y' ) . '&month=' . dol_print_date ( $act -> datep , '%m' ) . '&day=' . dol_print_date ( $act -> datep , '%d' ) . '">' . $langs -> trans ( " ViewCal " ) . '</a>' ;
$out .= '</li><li class="noborder litext">' . img_picto ( $langs -> trans ( " ViewWeek " ), 'object_calendarweek' , 'class="hideonsmartphone pictoactionview"' );
$out .= '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?action=show_day&year=' . dol_print_date ( $act -> datep , '%Y' ) . '&month=' . dol_print_date ( $act -> datep , '%m' ) . '&day=' . dol_print_date ( $act -> datep , '%d' ) . '">' . $langs -> trans ( " ViewWeek " ) . '</a>' ;
$out .= '</li><li class="noborder litext">' . img_picto ( $langs -> trans ( " ViewDay " ), 'object_calendarday' , 'class="hideonsmartphone pictoactionview"' );
$out .= '<a href="' . DOL_URL_ROOT . '/comm/action/index.php?action=show_day&year=' . dol_print_date ( $act -> datep , '%Y' ) . '&month=' . dol_print_date ( $act -> datep , '%m' ) . '&day=' . dol_print_date ( $act -> datep , '%d' ) . '">' . $langs -> trans ( " ViewDay " ) . '</a>' ;
$linkback .= $out ;
$morehtmlref = '<div class="refidno">' ;
2017-02-22 17:46:54 +01:00
// Thirdparty
//$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
// Project
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2020-10-31 14:32:18 +01:00
$langs -> load ( " projects " );
//$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
$morehtmlref .= $langs -> trans ( 'Project' ) . ': ' ;
if ( ! empty ( $act -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $act -> fk_project );
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $act -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
2021-02-26 20:53:03 +01:00
if ( $proj -> title ) {
$morehtmlref .= ' - ' . $proj -> title ;
}
2020-10-31 14:32:18 +01:00
} else {
$morehtmlref .= '' ;
}
2017-02-22 17:46:54 +01:00
}
2019-11-08 10:53:31 +01:00
$morehtmlref .= '</div>' ;
2017-09-15 23:49:04 +02:00
2019-11-08 10:53:31 +01:00
dol_banner_tab ( $act , 'element_id' , $linkback , ( $user -> socid ? 0 : 1 ), 'id' , 'ref' , $morehtmlref , '&element=' . $element , 0 , '' , '' );
2016-12-09 15:59:31 +01:00
2017-03-31 14:21:51 +02:00
print '<div class="fichecenter">' ;
2017-09-15 23:49:04 +02:00
2016-12-09 15:59:31 +01:00
print '<div class="underbanner clearboth"></div>' ;
2017-09-15 23:49:04 +02:00
2019-03-05 12:18:36 +01:00
print '<table class="border tableforfield" width="100%">' ;
2016-12-09 15:59:31 +01:00
// Type
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> global -> AGENDA_USE_EVENT_TYPE )) {
2021-03-31 00:46:47 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Type " ) . '</td><td>' ;
print $act -> getTypePicto ();
print $langs -> trans ( " Action " . $act -> type_code );
print '</td></tr>' ;
2016-12-09 15:59:31 +01:00
}
// Full day event
print '<tr><td class="titlefield">' . $langs -> trans ( " EventOnFullDay " ) . '</td><td colspan="3">' . yn ( $act -> fulldayevent , 3 ) . '</td></tr>' ;
// Date start
print '<tr><td>' . $langs -> trans ( " DateActionStart " ) . '</td><td colspan="3">' ;
2021-02-26 20:53:03 +01:00
if ( ! $act -> fulldayevent ) {
print dol_print_date ( $act -> datep , 'dayhour' );
} else {
print dol_print_date ( $act -> datep , 'day' );
}
if ( $act -> percentage == 0 && $act -> datep && $act -> datep < ( $now - $delay_warning )) {
print img_warning ( $langs -> trans ( " Late " ));
}
2016-12-09 15:59:31 +01:00
print '</td>' ;
print '</tr>' ;
// Date end
print '<tr><td>' . $langs -> trans ( " DateActionEnd " ) . '</td><td colspan="3">' ;
2021-02-26 20:53:03 +01:00
if ( ! $act -> fulldayevent ) {
print dol_print_date ( $act -> datef , 'dayhour' );
} else {
print dol_print_date ( $act -> datef , 'day' );
}
if ( $act -> percentage > 0 && $act -> percentage < 100 && $act -> datef && $act -> datef < ( $now - $delay_warning )) {
print img_warning ( $langs -> trans ( " Late " ));
}
2016-12-09 15:59:31 +01:00
print '</td></tr>' ;
// Location
2021-02-26 20:53:03 +01:00
if ( empty ( $conf -> global -> AGENDA_DISABLE_LOCATION )) {
2016-12-09 15:59:31 +01:00
print '<tr><td>' . $langs -> trans ( " Location " ) . '</td><td colspan="3">' . $act -> location . '</td></tr>' ;
}
// Assigned to
print '<tr><td class="nowrap">' . $langs -> trans ( " ActionAffectedTo " ) . '</td><td colspan="3">' ;
2019-11-08 10:53:31 +01:00
$listofuserid = array ();
2021-02-26 20:53:03 +01:00
if ( empty ( $donotclearsession )) {
if ( $act -> userownerid > 0 ) {
$listofuserid [ $act -> userownerid ] = array ( 'id' => $act -> userownerid , 'transparency' => $act -> transparency ); // Owner first
}
if ( ! empty ( $act -> userassigned )) { // Now concat assigned users
2016-12-09 15:59:31 +01:00
// Restore array with key with same value than param 'id'
2019-11-08 10:53:31 +01:00
$tmplist1 = $act -> userassigned ; $tmplist2 = array ();
2021-02-26 20:53:03 +01:00
foreach ( $tmplist1 as $key => $val ) {
if ( $val [ 'id' ] && $val [ 'id' ] != $act -> userownerid ) {
$listofuserid [ $val [ 'id' ]] = $val ;
}
2016-12-09 15:59:31 +01:00
}
}
2019-11-08 10:53:31 +01:00
$_SESSION [ 'assignedtouser' ] = json_encode ( $listofuserid );
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 20:53:03 +01:00
if ( ! empty ( $_SESSION [ 'assignedtouser' ])) {
2019-11-08 10:53:31 +01:00
$listofuserid = json_decode ( $_SESSION [ 'assignedtouser' ], true );
2016-12-09 15:59:31 +01:00
}
}
2019-11-08 10:53:31 +01:00
$listofcontactid = array (); // not used yet
$listofotherid = array (); // not used yet
2016-12-09 15:59:31 +01:00
print '<div class="assignedtouser">' ;
2019-11-08 10:53:31 +01:00
print $form -> select_dolusers_forevent ( 'view' , 'assignedtouser' , 1 , '' , 0 , '' , '' , 0 , 0 , 0 , '' , ( $act -> datep != $act -> datef ) ? 1 : 0 , $listofuserid , $listofcontactid , $listofotherid );
2016-12-09 15:59:31 +01:00
print '</div>' ;
2017-11-22 14:42:47 +01:00
/* if ( in_array ( $user -> id , array_keys ( $listofuserid )))
2016-12-09 15:59:31 +01:00
{
print '<div class="myavailability">' ;
print $langs -> trans ( " MyAvailability " ) . ': ' . (( $act -> userassigned [ $user -> id ][ 'transparency' ] > 0 ) ? $langs -> trans ( " Busy " ) : $langs -> trans ( " Available " )); // We show nothing if event is assigned to nobody
print '</div>' ;
2017-11-22 14:42:47 +01:00
} */
2016-12-09 15:59:31 +01:00
print ' </td></tr>' ;
print '</table>' ;
2017-03-31 14:21:51 +02:00
print '</div>' ;
2017-09-15 23:49:04 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-12-09 15:59:31 +01:00
}
}
2020-10-31 14:32:18 +01:00
// Specific to thirdparty module
2021-02-26 20:53:03 +01:00
if (( $element_id || $element_ref ) && $element == 'societe' ) {
2016-12-23 13:04:46 +01:00
$socstatic = fetchObjectByElement ( $element_id , $element , $element_ref );
2016-12-09 15:59:31 +01:00
if ( is_object ( $socstatic )) {
$savobject = $object ;
$object = $socstatic ;
2019-11-08 10:53:31 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2016-12-09 15:59:31 +01:00
$head = societe_prepare_head ( $socstatic );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'resources' , $langs -> trans ( " ThirdParty " ), - 1 , 'company' );
2016-12-09 15:59:31 +01:00
2019-10-31 20:46:31 +01:00
dol_banner_tab ( $socstatic , 'socid' , '' , ( $user -> socid ? 0 : 1 ), 'rowid' , 'nom' , '' , '&element=' . $element );
2016-12-09 15:59:31 +01:00
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2016-12-09 15:59:31 +01:00
// Alias name (commercial, trademark or alias name)
2019-11-08 10:53:31 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'AliasNames' ) . '</td><td colspan="3">' ;
2016-12-09 15:59:31 +01:00
print $socstatic -> name_alias ;
print " </td></tr> " ;
print '</table>' ;
print '</div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-12-09 15:59:31 +01:00
$object = $savobject ;
}
}
// Specific to fichinter module
2021-02-26 20:53:03 +01:00
if (( $element_id || $element_ref ) && $element == 'fichinter' ) {
2016-02-01 16:15:30 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/fichinter.lib.php' ;
2020-10-31 14:32:18 +01:00
$fichinter = new Fichinter ( $db );
$fichinter -> fetch ( $element_id , $element_ref );
$fichinter -> fetch_thirdparty ();
2017-09-15 23:49:04 +02:00
2021-02-26 20:53:03 +01:00
if ( is_object ( $fichinter )) {
2019-11-08 10:53:31 +01:00
$head = fichinter_prepare_head ( $fichinter );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'resource' , $langs -> trans ( " InterventionCard " ), - 1 , 'intervention' );
2016-02-01 16:15:30 +01:00
2016-12-09 15:59:31 +01:00
// Intervention card
2019-11-08 10:53:31 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/fichinter/list.php' . ( ! empty ( $socid ) ? '?socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-09-15 23:49:04 +02:00
2019-11-08 10:53:31 +01:00
$morehtmlref = '<div class="refidno">' ;
2016-12-09 15:59:31 +01:00
// Ref customer
//$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
//$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
// Thirdparty
2019-11-08 10:53:31 +01:00
$morehtmlref .= $langs -> trans ( 'ThirdParty' ) . ' : ' . $fichinter -> thirdparty -> getNomUrl ( 1 );
2016-12-09 15:59:31 +01:00
// Project
2021-02-26 20:53:03 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2016-12-09 15:59:31 +01:00
$langs -> load ( " projects " );
2019-11-08 10:53:31 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-02-26 20:53:03 +01:00
if ( $user -> rights -> commande -> creer ) {
if ( $action != 'classify' ) {
2019-10-06 15:34:22 +02:00
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $fichinter->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
2019-11-08 10:53:31 +01:00
$morehtmlref .= ' : ' ;
2021-02-26 20:53:03 +01:00
}
2016-12-09 15:59:31 +01:00
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $fichinter->id, $fichinter->socid, $fichinter->fk_project, 'projectid', 0, 0, 1, 1);
2019-11-08 10:53:31 +01:00
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $fichinter -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
2019-12-18 23:12:31 +01:00
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-08 10:53:31 +01:00
$morehtmlref .= $formproject -> select_projects ( $fichinter -> socid , $fichinter -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
2016-12-09 15:59:31 +01:00
} else {
2019-11-08 10:53:31 +01:00
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $fichinter -> id , $fichinter -> socid , $fichinter -> fk_project , 'none' , 0 , 0 , 0 , 1 );
2016-12-09 15:59:31 +01:00
}
} else {
2019-11-08 10:53:31 +01:00
if ( ! empty ( $fichinter -> fk_project )) {
2016-12-09 15:59:31 +01:00
$proj = new Project ( $db );
$proj -> fetch ( $fichinter -> fk_project );
2019-11-08 10:53:31 +01:00
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $fichinter -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
2016-12-09 15:59:31 +01:00
} else {
2019-11-08 10:53:31 +01:00
$morehtmlref .= '' ;
2016-12-09 15:59:31 +01:00
}
}
}
2019-11-08 10:53:31 +01:00
$morehtmlref .= '</div>' ;
2017-09-15 23:49:04 +02:00
2016-12-23 13:04:46 +01:00
dol_banner_tab ( $fichinter , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref , '&element=' . $element , 0 , '' , '' , 1 );
2017-09-15 23:49:04 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-02-01 16:15:30 +01:00
}
}
2019-04-09 00:48:12 +02:00
2019-04-07 21:30:13 +02:00
// Specific to product/service module
2021-02-26 20:53:03 +01:00
if (( $element_id || $element_ref ) && ( $element == 'product' || $element == 'service' )) {
2020-10-31 14:32:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
2019-04-07 21:30:13 +02:00
2020-10-31 14:32:18 +01:00
$product = new Product ( $db );
$product -> fetch ( $element_id , $element_ref );
2019-04-07 21:30:13 +02:00
2021-02-26 20:53:03 +01:00
if ( is_object ( $product )) {
2019-04-07 21:30:13 +02:00
$head = product_prepare_head ( $product );
2019-11-08 10:53:31 +01:00
$titre = $langs -> trans ( " CardProduct " . $product -> type );
$picto = ( $product -> type == Product :: TYPE_SERVICE ? 'service' : 'product' );
2019-04-07 21:30:13 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'resources' , $titre , - 1 , $picto );
2019-04-07 21:30:13 +02:00
2020-10-31 14:32:18 +01:00
$shownav = 1 ;
2021-02-26 20:53:03 +01:00
if ( $user -> socid && ! in_array ( 'product' , explode ( ',' , $conf -> global -> MAIN_MODULES_FOR_EXTERNAL ))) {
$shownav = 0 ;
}
2019-04-07 21:30:13 +02:00
dol_banner_tab ( $product , 'ref' , '' , $shownav , 'ref' , 'ref' , '' , '&element=' . $element );
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-10-31 14:32:18 +01:00
}
2019-04-07 21:30:13 +02:00
}
2016-02-01 16:15:30 +01:00
2016-02-01 15:40:16 +01:00
// hook for other elements linked
2019-11-08 10:53:31 +01:00
$parameters = array ( 'element' => $element , 'element_id' => $element_id , 'element_ref' => $element_ref );
$reshook = $hookmanager -> executeHooks ( 'printElementTab' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 20:53:03 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2014-01-02 07:07:43 +01:00
2016-12-09 15:59:31 +01:00
//print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','');
print '<br>' ;
2016-06-07 13:15:38 +02:00
// Show list of resource links
2014-01-02 07:07:43 +01:00
2021-02-26 20:53:03 +01:00
foreach ( $object -> available_resources as $modresources => $resources ) {
2019-11-08 10:53:31 +01:00
$resources = ( array ) $resources ; // To be sure $resources is an array
2021-02-26 20:53:03 +01:00
foreach ( $resources as $resource_obj ) {
2016-12-09 15:59:31 +01:00
$element_prop = getElementProperties ( $resource_obj );
2017-09-15 23:49:04 +02:00
//print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br>';
2016-12-09 15:59:31 +01:00
$path = '' ;
2021-02-26 20:53:03 +01:00
if ( strpos ( $resource_obj , '@' )) {
2016-12-09 15:59:31 +01:00
$path .= '/' . $element_prop [ 'module' ];
2021-02-26 20:53:03 +01:00
}
2016-12-09 15:59:31 +01:00
2019-01-27 11:55:16 +01:00
$linked_resources = $object -> getElementResources ( $element , $element_id , $resource_obj );
2016-12-09 15:59:31 +01:00
2019-07-29 18:17:48 +02:00
// Output template part (modules that overwrite templates must declare this into descriptor)
2019-11-08 10:53:31 +01:00
$defaulttpldir = '/core/tpl' ;
$dirtpls = array_merge ( $conf -> modules_parts [ 'tpl' ], array ( $defaulttpldir ), array ( $path . $defaulttpldir ));
2019-10-06 15:34:22 +02:00
2021-02-26 20:53:03 +01:00
foreach ( $dirtpls as $module => $reldir ) {
if ( file_exists ( dol_buildpath ( $reldir . '/resource_' . $element_prop [ 'element' ] . '_add.tpl.php' ))) {
2019-07-29 18:17:48 +02:00
$tpl = dol_buildpath ( $reldir . '/resource_' . $element_prop [ 'element' ] . '_add.tpl.php' );
2020-05-21 15:05:19 +02:00
} else {
2019-07-29 18:17:48 +02:00
$tpl = DOL_DOCUMENT_ROOT . $reldir . '/resource_add.tpl.php' ;
}
if ( empty ( $conf -> file -> strict_mode )) {
2019-11-08 10:53:31 +01:00
$res = @ include $tpl ;
2019-07-29 18:17:48 +02:00
} else {
2019-11-08 10:53:31 +01:00
$res = include $tpl ; // for debug
2019-07-29 18:17:48 +02:00
}
2021-02-26 20:53:03 +01:00
if ( $res ) {
break ;
}
2016-12-09 15:59:31 +01:00
}
2021-02-26 20:53:03 +01:00
if ( $mode != 'add' || $resource_obj != $resource_type ) {
foreach ( $dirtpls as $module => $reldir ) {
if ( file_exists ( dol_buildpath ( $reldir . '/resource_' . $element_prop [ 'element' ] . '_view.tpl.php' ))) {
2019-07-29 18:17:48 +02:00
$tpl = dol_buildpath ( $reldir . '/resource_' . $element_prop [ 'element' ] . '_view.tpl.php' );
2020-05-21 15:05:19 +02:00
} else {
2019-07-29 18:17:48 +02:00
$tpl = DOL_DOCUMENT_ROOT . $reldir . '/resource_view.tpl.php' ;
}
if ( empty ( $conf -> file -> strict_mode )) {
2019-11-08 10:53:31 +01:00
$res = @ include $tpl ;
2019-07-29 18:17:48 +02:00
} else {
2019-11-08 10:53:31 +01:00
$res = include $tpl ; // for debug
2019-07-29 18:17:48 +02:00
}
2021-02-26 20:53:03 +01:00
if ( $res ) {
break ;
}
2016-12-09 15:59:31 +01:00
}
}
}
}
2014-01-02 07:07:43 +01:00
}
2018-08-17 17:55:00 +02:00
// End of page
2014-01-02 07:07:43 +01:00
llxFooter ();
$db -> close ();