2013-06-12 11:59:55 +02:00
< ? php
/* Copyright ( C ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2016-01-08 23:54:40 +01:00
* Copyright ( C ) 2004 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2018 Regis Houssin < regis . houssin @ inodbox . com >
2020-08-18 13:44:50 +02:00
* Copyright ( C ) 2011 - 2020 Juanjo Menent < jmenent @ 2 byte . es >
2013-11-05 13:11:36 +01:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2018-01-10 16:40:43 +01:00
* Copyright ( C ) 2014 - 2018 Ferran Marcet < fmarcet @ 2 byte . es >
2018-05-28 16:44:49 +02:00
* Copyright ( C ) 2014 - 2018 Charlene Benke < charlies @ patas - monkey . com >
2016-03-03 21:16:51 +01:00
* Copyright ( C ) 2015 - 2016 Abbes Bahfir < bafbes @ gmail . com >
2018-11-07 15:07:57 +01:00
* Copyright ( C ) 2018 Philippe Grand < philippe . grand @ atoo - net . com >
2020-11-19 20:57:26 +01:00
* Copyright ( C ) 2020 Frédéric France < frederic . france @ netlogic . fr >
2013-11-05 13:11:36 +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 />.
2013-11-05 13:11:36 +01:00
*/
2013-06-12 11:59:55 +02:00
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / fichinter / card . php
2014-08-30 20:05:16 +02:00
* \brief Page of intervention
2013-11-05 13:11:36 +01:00
* \ingroup ficheinter
*/
2013-06-12 11:59:55 +02:00
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/fichinter/modules_fichinter.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/fichinter.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2013-06-12 11:59:55 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2013-06-14 22:33:01 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2013-06-12 11:59:55 +02:00
}
2021-02-25 23:00:32 +01:00
if ( $conf -> contrat -> enabled ) {
2013-06-12 11:59:55 +02:00
require_once DOL_DOCUMENT_ROOT . " /core/class/html.formcontract.class.php " ;
require_once DOL_DOCUMENT_ROOT . " /contrat/class/contrat.class.php " ;
}
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> global -> FICHEINTER_ADDON ) && is_readable ( DOL_DOCUMENT_ROOT . " /core/modules/fichinter/mod_ " . $conf -> global -> FICHEINTER_ADDON . " .php " )) {
2019-11-13 19:35:02 +01:00
require_once DOL_DOCUMENT_ROOT . " /core/modules/fichinter/mod_ " . $conf -> global -> FICHEINTER_ADDON . '.php' ;
2013-06-12 11:59:55 +02:00
}
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2018-05-26 17:57:30 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'bills' , 'companies' , 'interventions' ));
2013-06-12 11:59:55 +02:00
2019-01-27 11:55:16 +01:00
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
2020-11-19 20:57:26 +01:00
$socid = ( int ) GETPOST ( 'socid' , 'int' );
$contratid = ( int ) GETPOST ( 'contratid' , 'int' );
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2020-04-10 10:59:32 +02:00
$mesg = GETPOST ( 'msg' , 'alpha' );
2019-11-13 19:35:02 +01:00
$origin = GETPOST ( 'origin' , 'alpha' );
$originid = ( GETPOST ( 'originid' , 'int' ) ? GETPOST ( 'originid' , 'int' ) : GETPOST ( 'origin_id' , 'int' )); // For backward compatibility
2020-09-18 01:29:17 +02:00
$note_public = GETPOST ( 'note_public' , 'restricthtml' );
2019-01-27 11:55:16 +01:00
$lineid = GETPOST ( 'line_id' , 'int' );
2013-06-12 11:59:55 +02:00
//PDF
2019-11-13 19:35:02 +01:00
$hidedetails = ( GETPOST ( 'hidedetails' , 'int' ) ? GETPOST ( 'hidedetails' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ));
$hidedesc = ( GETPOST ( 'hidedesc' , 'int' ) ? GETPOST ( 'hidedesc' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ));
$hideref = ( GETPOST ( 'hideref' , 'int' ) ? GETPOST ( 'hideref' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ));
2013-06-12 11:59:55 +02:00
// Security check
2021-02-25 23:00:32 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2013-06-12 11:59:55 +02:00
$result = restrictedArea ( $user , 'ficheinter' , $id , 'fichinter' );
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2019-11-13 19:35:02 +01:00
$hookmanager -> initHooks ( array ( 'interventioncard' , 'globalcard' ));
2013-06-12 11:59:55 +02:00
$object = new Fichinter ( $db );
$extrafields = new ExtraFields ( $db );
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2013-06-12 11:59:55 +02:00
2013-11-05 13:11:36 +01:00
// Load object
2021-02-25 23:00:32 +01:00
if ( $id > 0 || ! empty ( $ref )) {
2019-11-13 19:35:02 +01:00
$ret = $object -> fetch ( $id , $ref );
2021-02-25 23:00:32 +01:00
if ( $ret > 0 ) {
$ret = $object -> fetch_thirdparty ();
}
if ( $ret < 0 ) {
dol_print_error ( '' , $object -> error );
}
2013-11-05 13:11:36 +01:00
}
2019-11-13 19:35:02 +01:00
$permissionnote = $user -> rights -> ficheinter -> creer ; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user -> rights -> ficheinter -> creer ; // Used by the include of actions_dellink.inc.php
2013-11-05 13:11:36 +01:00
2020-02-13 11:57:13 +01:00
$error = 0 ;
2013-06-12 11:59:55 +02:00
/*
* Actions
2013-11-05 13:11:36 +01:00
*/
2014-09-28 03:41:32 +02:00
2019-11-13 19:35:02 +01:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-25 23:00:32 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
if ( empty ( $reshook )) {
if ( $cancel ) {
if ( ! empty ( $backtopage )) {
2017-10-17 10:44:18 +02:00
header ( " Location: " . $backtopage );
exit ;
}
2019-11-13 19:35:02 +01:00
$action = '' ;
2017-10-17 10:44:18 +02:00
}
2019-11-13 19:35:02 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php' ; // Must be include, not include_once
2015-07-28 14:13:16 +02:00
2019-11-13 19:35:02 +01:00
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php' ; // Must be include, not include_once
2015-07-28 14:13:16 +02:00
2016-07-01 18:12:37 +02:00
// Action clone object
2021-02-25 23:00:32 +01:00
if ( $action == 'confirm_clone' && $confirm == 'yes' && $user -> rights -> ficheinter -> creer ) {
if ( 1 == 0 && ! GETPOST ( 'clone_content' ) && ! GETPOST ( 'clone_receivers' )) {
2016-07-01 18:12:37 +02:00
setEventMessages ( $langs -> trans ( " NoCloneOptionsSpecified " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2021-02-25 23:00:32 +01:00
if ( $object -> id > 0 ) {
2016-07-01 18:12:37 +02:00
// Because createFromClone modifies the object, we must clone it so that we can restore it later
$orig = clone $object ;
2019-11-13 19:35:02 +01:00
$result = $object -> createFromClone ( $user , $socid );
2021-02-25 23:00:32 +01:00
if ( $result > 0 ) {
2016-07-01 18:12:37 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $result );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2016-07-01 18:12:37 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$object = $orig ;
2019-11-13 19:35:02 +01:00
$action = '' ;
2016-07-01 18:12:37 +02:00
}
}
}
}
2016-08-10 11:54:49 +02:00
2021-02-25 23:00:32 +01:00
if ( $action == 'confirm_validate' && $confirm == 'yes' && $user -> rights -> ficheinter -> creer ) {
2015-07-28 14:13:16 +02:00
$result = $object -> setValid ( $user );
2015-11-13 12:18:46 +01:00
2021-02-25 23:00:32 +01:00
if ( $result >= 0 ) {
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2016-03-04 11:48:46 +01:00
// Define output language
$outputlangs = $langs ;
2019-11-13 19:35:02 +01:00
$newlang = '' ;
2021-02-25 23:00:32 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2016-03-04 11:48:46 +01:00
$outputlangs -> setDefaultLang ( $newlang );
}
2020-09-10 01:49:09 +02:00
$result = fichinter_create ( $db , $object , ( ! GETPOST ( 'model' , 'alpha' )) ? $object -> model_pdf : GETPOST ( 'model' , 'alpha' ), $outputlangs );
2015-07-28 14:13:16 +02:00
}
2014-02-08 02:46:05 +01:00
2015-07-28 14:13:16 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-24 13:15:51 +02:00
$mesg = $object -> error ;
2015-07-28 14:13:16 +02:00
}
2020-11-19 20:57:26 +01:00
} elseif ( $action == 'confirm_modify' && $confirm == 'yes' && $user -> rights -> ficheinter -> creer ) {
2015-07-28 14:13:16 +02:00
$result = $object -> setDraft ( $user );
2021-02-25 23:00:32 +01:00
if ( $result >= 0 ) {
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
2016-03-04 11:48:46 +01:00
// Define output language
$outputlangs = $langs ;
2019-11-13 19:35:02 +01:00
$newlang = '' ;
2021-02-25 23:00:32 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
2020-11-19 20:57:26 +01:00
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2016-03-04 11:48:46 +01:00
$outputlangs -> setDefaultLang ( $newlang );
}
2020-09-10 01:49:09 +02:00
$result = fichinter_create ( $db , $object , ( ! GETPOST ( 'model' , 'alpha' )) ? $object -> model_pdf : GETPOST ( 'model' , 'alpha' ), $outputlangs );
2015-07-28 14:13:16 +02:00
}
2014-02-08 02:46:05 +01:00
2015-07-28 14:13:16 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-24 13:15:51 +02:00
$mesg = $object -> error ;
2015-07-28 14:13:16 +02:00
}
2020-11-19 20:57:26 +01:00
} elseif ( $action == 'add' && $user -> rights -> ficheinter -> creer ) {
2021-02-05 09:48:08 +01:00
$selectedLines = GETPOST ( 'toselect' , 'array' );
2020-10-07 15:01:28 +02:00
$object -> socid = $socid ;
2020-11-19 20:57:26 +01:00
$object -> duration = ( int ) GETPOST ( 'duration' , 'int' );
$object -> fk_project = ( int ) GETPOST ( 'projectid' , 'int' );
$object -> fk_contrat = ( int ) GETPOST ( 'contratid' , 'int' );
2020-10-07 15:01:28 +02:00
$object -> author = $user -> id ;
2020-11-19 20:57:26 +01:00
$object -> description = GETPOST ( 'description' , 'restricthtml' );
2020-10-07 15:01:28 +02:00
$object -> ref = $ref ;
$object -> model_pdf = GETPOST ( 'model' , 'alpha' );
$object -> note_private = GETPOST ( 'note_private' , 'restricthtml' );
$object -> note_public = GETPOST ( 'note_public' , 'restricthtml' );
2015-07-28 14:13:16 +02:00
2021-02-25 23:00:32 +01:00
if ( $object -> socid > 0 ) {
2015-07-28 14:13:16 +02:00
// If creation from another object of another module (Example: origin=propal, originid=1)
2021-02-25 23:00:32 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid )) {
2015-07-28 14:13:16 +02:00
// Parse element/subelement (ex: project_task)
2021-01-28 10:30:09 +01:00
$regs = array ();
$element = $subelement = GETPOST ( 'origin' , 'alphanohtml' );
2021-02-25 23:00:32 +01:00
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , GETPOST ( 'origin' , 'alphanohtml' ), $regs )) {
2015-07-28 14:13:16 +02:00
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
// For compatibility
2019-11-13 19:35:02 +01:00
if ( $element == 'order' ) {
2015-07-28 14:13:16 +02:00
$element = $subelement = 'commande' ;
}
2019-11-13 19:35:02 +01:00
if ( $element == 'propal' ) {
2015-07-28 14:13:16 +02:00
$element = 'comm/propal' ; $subelement = 'propal' ;
}
if ( $element == 'contract' ) {
$element = $subelement = 'contrat' ;
}
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
$object -> origin = $origin ;
$object -> origin_id = $originid ;
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
// Possibility to add external linked objects with hooks
$object -> linked_objects [ $object -> origin ] = $object -> origin_id ;
2021-02-25 23:00:32 +01:00
if ( is_array ( $_POST [ 'other_linked_objects' ]) && ! empty ( $_POST [ 'other_linked_objects' ])) {
2015-07-28 14:13:16 +02:00
$object -> linked_objects = array_merge ( $object -> linked_objects , $_POST [ 'other_linked_objects' ]);
}
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
// Extrafields
2021-01-26 12:42:04 +01:00
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
if ( $ret < 0 ) {
$error ++ ;
$action = 'create' ;
}
2018-11-07 12:49:17 +01:00
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element );
2014-08-30 20:05:16 +02:00
2020-10-07 15:01:28 +02:00
$object -> array_options = $array_options ;
2014-08-26 17:25:13 +02:00
2015-07-28 14:13:16 +02:00
$id = $object -> create ( $user );
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( $id > 0 ) {
2015-07-28 14:13:16 +02:00
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
$classname = ucfirst ( $subelement );
$srcobject = new $classname ( $db );
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
dol_syslog ( " Try to find source object origin= " . $object -> origin . " originid= " . $object -> origin_id . " to add lines " );
2019-11-13 19:35:02 +01:00
$result = $srcobject -> fetch ( $object -> origin_id );
2021-02-25 23:00:32 +01:00
if ( $result > 0 ) {
2015-07-28 14:13:16 +02:00
$srcobject -> fetch_thirdparty ();
2014-09-04 18:58:33 +02:00
$lines = $srcobject -> lines ;
2021-02-25 23:00:32 +01:00
if ( empty ( $lines ) && method_exists ( $srcobject , 'fetch_lines' )) {
2015-07-28 14:13:16 +02:00
$srcobject -> fetch_lines ();
$lines = $srcobject -> lines ;
}
2013-06-12 11:59:55 +02:00
2020-02-24 23:14:15 +01:00
if ( is_array ( $lines )) {
$num = count ( $lines );
2021-02-25 23:00:32 +01:00
for ( $i = 0 ; $i < $num ; $i ++ ) {
if ( ! in_array ( $lines [ $i ] -> id , $selectedLines )) {
continue ; // Skip unselected lines
}
2021-02-05 09:48:08 +01:00
2020-02-24 23:14:15 +01:00
$product_type = ( $lines [ $i ] -> product_type ? $lines [ $i ] -> product_type : Product :: TYPE_PRODUCT );
if ( $product_type == Product :: TYPE_SERVICE || ! empty ( $conf -> global -> FICHINTER_PRINT_PRODUCTS )) { //only services except if config includes products
$duration = 3600 ; // Default to one hour
// Predefined products & services
2021-02-25 23:00:32 +01:00
if ( $lines [ $i ] -> fk_product > 0 ) {
2020-02-24 23:14:15 +01:00
$prod = new Product ( $db );
$prod -> id = $lines [ $i ] -> fk_product ;
// Define output language
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE )) {
$prod -> getMultiLangs ();
// We show if duration is present on service (so we get it)
$prod -> fetch ( $lines [ $i ] -> fk_product );
$outputlangs = $langs ;
$newlang = '' ;
2021-02-25 23:00:32 +01:00
if ( empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( empty ( $newlang )) {
$newlang = $srcobject -> thirdparty -> default_lang ;
}
2020-02-24 23:14:15 +01:00
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$label = ( ! empty ( $prod -> multilangs [ $outputlangs -> defaultlang ][ " libelle " ])) ? $prod -> multilangs [ $outputlangs -> defaultlang ][ " libelle " ] : $lines [ $i ] -> product_label ;
} else {
$prod -> fetch ( $lines [ $i ] -> fk_product );
$label = $lines [ $i ] -> product_label ;
2015-07-28 14:13:16 +02:00
}
2016-07-25 17:18:13 +02:00
2020-02-24 23:14:15 +01:00
if ( $prod -> duration_value && $conf -> global -> FICHINTER_USE_SERVICE_DURATION ) {
switch ( $prod -> duration_unit ) {
default :
case 'h' :
$mult = 3600 ;
break ;
case 'd' :
$mult = 3600 * 24 ;
break ;
case 'w' :
$mult = 3600 * 24 * 7 ;
break ;
case 'm' :
$mult = ( int ) 3600 * 24 * ( 365 / 12 ); // Average month duration
break ;
case 'y' :
$mult = 3600 * 24 * 365 ;
break ;
}
$duration = $prod -> duration_value * $mult * $lines [ $i ] -> qty ;
2016-07-25 17:18:13 +02:00
}
2013-06-12 11:59:55 +02:00
2020-02-24 23:14:15 +01:00
$desc = $lines [ $i ] -> product_ref ;
$desc .= ' - ' ;
$desc .= $label ;
$desc .= '<br>' ;
}
// Common part (predefined or free line)
$desc .= dol_htmlentitiesbr ( $lines [ $i ] -> desc );
2016-07-25 17:18:13 +02:00
$desc .= '<br>' ;
2020-02-24 23:14:15 +01:00
$desc .= ' (' . $langs -> trans ( 'Quantity' ) . ': ' . $lines [ $i ] -> qty . ')' ;
2016-07-25 17:18:13 +02:00
2020-02-24 23:14:15 +01:00
$timearray = dol_getdate ( dol_now ());
$date_intervention = dol_mktime ( 0 , 0 , 0 , $timearray [ 'mon' ], $timearray [ 'mday' ], $timearray [ 'year' ]);
2016-07-25 17:18:13 +02:00
2020-02-24 23:14:15 +01:00
if ( $product_type == Product :: TYPE_PRODUCT ) {
$duration = 0 ;
}
2013-06-12 11:59:55 +02:00
2020-02-24 23:14:15 +01:00
$predef = '' ;
// Extrafields
$extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line , $predef );
$result = $object -> addline (
$user ,
2020-10-07 15:01:28 +02:00
$id ,
$desc ,
$date_intervention ,
2021-02-25 23:00:32 +01:00
$duration ,
$array_options
2020-10-07 15:01:28 +02:00
);
2020-02-24 23:14:15 +01:00
2021-02-25 23:00:32 +01:00
if ( $result < 0 ) {
2020-02-24 23:14:15 +01:00
$error ++ ;
break ;
}
2015-07-28 14:13:16 +02:00
}
}
2013-06-12 11:59:55 +02:00
}
2020-10-07 15:01:28 +02:00
} else {
2020-09-24 13:15:51 +02:00
$mesg = $srcobject -> error ;
2020-10-07 15:01:28 +02:00
$error ++ ;
}
} else {
2020-09-24 13:15:51 +02:00
$mesg = $object -> error ;
2020-10-07 15:01:28 +02:00
$error ++ ;
}
} else {
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( null , $object );
if ( $ret < 0 ) {
$error ++ ;
$action = 'create' ;
}
2021-02-25 23:00:32 +01:00
if ( ! $error ) {
2020-10-07 15:01:28 +02:00
// Extrafields
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element );
$object -> array_options = $array_options ;
$result = $object -> create ( $user );
2021-02-25 23:00:32 +01:00
if ( $result > 0 ) {
2020-10-07 15:01:28 +02:00
$id = $result ; // Force raffraichissement sur fiche venant d'etre cree
} else {
$langs -> load ( " errors " );
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = 'create' ;
}
}
}
} else {
2020-09-24 13:15:51 +02:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ThirdParty " ));
2020-10-07 15:01:28 +02:00
$action = 'create' ;
}
2020-11-19 20:57:26 +01:00
} elseif ( $action == 'update' && $user -> rights -> ficheinter -> creer ) {
2019-11-13 19:35:02 +01:00
$object -> socid = $socid ;
2020-11-19 20:57:26 +01:00
$object -> fk_project = ( int ) GETPOST ( 'projectid' , 'int' );
$object -> fk_contrat = ( int ) GETPOST ( 'contratid' , 'int' );
2019-11-13 19:35:02 +01:00
$object -> author = $user -> id ;
2020-11-19 20:57:26 +01:00
$object -> description = GETPOST ( 'description' , 'restricthtml' );
2019-11-13 19:35:02 +01:00
$object -> ref = $ref ;
2015-07-28 14:13:16 +02:00
2019-11-13 19:35:02 +01:00
$result = $object -> update ( $user );
if ( $result < 0 ) {
2015-12-08 11:35:08 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-07-28 14:13:16 +02:00
}
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'classin' && $user -> rights -> ficheinter -> creer ) {
// Set into a project
2019-11-13 19:35:02 +01:00
$result = $object -> setProject ( GETPOST ( 'projectid' , 'int' ));
2021-02-25 23:00:32 +01:00
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
} elseif ( $action == 'setcontract' && $user -> rights -> contrat -> creer ) {
// Set into a contract
2019-11-13 19:35:02 +01:00
$result = $object -> set_contrat ( $user , GETPOST ( 'contratid' , 'int' ));
2021-02-25 23:00:32 +01:00
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
} elseif ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> ficheinter -> supprimer ) {
2019-11-13 19:35:02 +01:00
$result = $object -> delete ( $user );
if ( $result < 0 ) {
2015-12-08 11:35:08 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-07-28 14:13:16 +02:00
}
2013-06-12 11:59:55 +02:00
2018-02-26 21:16:40 +01:00
header ( 'Location: ' . DOL_URL_ROOT . '/fichinter/list.php?leftmenu=ficheinter&restore_lastsearch_values=1' );
2015-07-28 14:13:16 +02:00
exit ;
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'setdescription' && $user -> rights -> ficheinter -> creer ) {
2019-11-13 19:35:02 +01:00
$result = $object -> set_description ( $user , GETPOST ( 'description' ));
2021-02-25 23:00:32 +01:00
if ( $result < 0 ) {
dol_print_error ( $db , $object -> error );
}
} elseif ( $action == " addline " && $user -> rights -> ficheinter -> creer ) {
// Add line
if ( ! GETPOST ( 'np_desc' , 'restricthtml' ) && empty ( $conf -> global -> FICHINTER_EMPTY_LINE_DESC )) {
2020-09-24 13:15:51 +02:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Description " ));
2015-07-28 14:13:16 +02:00
$error ++ ;
}
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> FICHINTER_WITHOUT_DURATION ) && ! GETPOST ( 'durationhour' , 'int' ) && ! GETPOST ( 'durationmin' , 'int' )) {
2020-09-24 13:15:51 +02:00
$mesg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Duration " ));
2015-07-28 14:13:16 +02:00
$error ++ ;
}
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> FICHINTER_WITHOUT_DURATION ) && GETPOST ( 'durationhour' , 'int' ) >= 24 && GETPOST ( 'durationmin' , 'int' ) > 0 ) {
2020-09-24 13:15:51 +02:00
$mesg = $langs -> trans ( " ErrorValueTooHigh " );
2015-07-28 14:13:16 +02:00
$error ++ ;
}
2021-02-25 23:00:32 +01:00
if ( ! $error ) {
2015-07-28 14:13:16 +02:00
$db -> begin ();
2013-06-12 11:59:55 +02:00
2020-09-18 01:29:17 +02:00
$desc = GETPOST ( 'np_desc' , 'restricthtml' );
2019-01-27 11:55:16 +01:00
$date_intervention = dol_mktime ( GETPOST ( 'dihour' , 'int' ), GETPOST ( 'dimin' , 'int' ), 0 , GETPOST ( 'dimonth' , 'int' ), GETPOST ( 'diday' , 'int' ), GETPOST ( 'diyear' , 'int' ));
2021-01-28 10:30:09 +01:00
$duration = empty ( $conf -> global -> FICHINTER_WITHOUT_DURATION ) ? convertTime2Seconds ( GETPOST ( 'durationhour' , 'int' ), GETPOST ( 'durationmin' , 'int' )) : 0 ;
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
// Extrafields
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line );
2015-07-28 14:13:16 +02:00
2020-10-07 15:01:28 +02:00
$result = $object -> addline (
2015-07-28 14:13:16 +02:00
$user ,
2020-10-07 15:01:28 +02:00
$id ,
$desc ,
$date_intervention ,
$duration ,
$array_options
);
2015-07-28 14:13:16 +02:00
// Define output language
$outputlangs = $langs ;
2019-11-13 19:35:02 +01:00
$newlang = '' ;
2021-02-25 23:00:32 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2015-07-28 14:13:16 +02:00
$outputlangs -> setDefaultLang ( $newlang );
}
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( $result >= 0 ) {
2015-07-28 14:13:16 +02:00
$db -> commit ();
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
fichinter_create ( $db , $object , $object -> model_pdf , $outputlangs );
}
2015-07-28 14:13:16 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:02 +01:00
$mesg = $object -> error ;
2015-07-28 14:13:16 +02:00
$db -> rollback ();
}
}
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'classifybilled' && $user -> rights -> ficheinter -> creer ) {
// Classify Billed
2021-03-10 15:43:50 +01:00
$result = $object -> setStatut ( Fichinter :: STATUS_BILLED );
2020-11-19 20:57:26 +01:00
if ( $result > 0 ) {
2015-07-28 14:13:16 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-07-28 14:13:16 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'classifyunbilled' && $user -> rights -> ficheinter -> creer ) {
// Classify unbilled
2021-03-10 15:43:50 +01:00
$result = $object -> setStatut ( Fichinter :: STATUS_VALIDATED );
2021-02-25 23:00:32 +01:00
if ( $result > 0 ) {
2015-07-28 14:13:16 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2020-09-24 13:15:51 +02:00
$mesg = $object -> error ;
2015-07-28 14:13:16 +02:00
}
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'classifydone' && $user -> rights -> ficheinter -> creer ) {
// Classify Done
2021-03-10 15:43:50 +01:00
$result = $object -> setStatut ( Fichinter :: STATUS_CLOSED );
2021-02-25 23:00:32 +01:00
if ( $result > 0 ) {
2020-10-07 15:01:28 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'confirm_reopen' && $user -> rights -> ficheinter -> creer ) {
// Reopen
2020-09-25 08:10:48 +02:00
$result = $object -> setStatut ( Fichinter :: STATUS_VALIDATED );
2021-02-25 23:00:32 +01:00
if ( $result > 0 ) {
2020-09-25 08:10:48 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
2021-02-25 23:00:32 +01:00
} else {
2020-09-25 08:10:48 +02:00
$mesg = $object -> error ;
}
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'updateline' && $user -> rights -> ficheinter -> creer && GETPOST ( 'save' , 'alpha' ) == $langs -> trans ( " Save " )) {
// Mise a jour d'une ligne d'intervention
2015-07-28 14:13:16 +02:00
$objectline = new FichinterLigne ( $db );
2021-02-25 23:00:32 +01:00
if ( $objectline -> fetch ( $lineid ) <= 0 ) {
2015-07-28 14:13:16 +02:00
dol_print_error ( $db );
exit ;
}
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( $object -> fetch ( $objectline -> fk_fichinter ) <= 0 ) {
2015-07-28 14:13:16 +02:00
dol_print_error ( $db );
exit ;
}
$object -> fetch_thirdparty ();
2013-06-12 11:59:55 +02:00
2020-10-03 11:31:56 +02:00
$desc = GETPOST ( 'np_desc' , 'restricthtml' );
2019-11-13 19:35:02 +01:00
$date_inter = dol_mktime ( GETPOST ( 'dihour' , 'int' ), GETPOST ( 'dimin' , 'int' ), 0 , GETPOST ( 'dimonth' , 'int' ), GETPOST ( 'diday' , 'int' ), GETPOST ( 'diyear' , 'int' ));
$duration = convertTime2Seconds ( GETPOST ( 'durationhour' , 'int' ), GETPOST ( 'durationmin' , 'int' ));
2015-07-28 14:13:16 +02:00
2020-10-07 15:01:28 +02:00
$objectline -> datei = $date_inter ;
$objectline -> desc = $desc ;
$objectline -> duration = $duration ;
2014-08-30 20:05:16 +02:00
2014-08-26 17:08:03 +02:00
// Extrafields
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element_line );
$array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element_line );
2015-07-28 14:13:16 +02:00
$objectline -> array_options = $array_options ;
2014-08-26 17:08:03 +02:00
2015-07-28 14:13:16 +02:00
$result = $objectline -> update ( $user );
2021-02-25 23:00:32 +01:00
if ( $result < 0 ) {
2020-10-07 15:01:28 +02:00
dol_print_error ( $db );
exit ;
}
2013-06-12 11:59:55 +02:00
// Define output language
$outputlangs = $langs ;
2019-11-13 19:35:02 +01:00
$newlang = '' ;
2021-02-25 23:00:32 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2013-06-12 11:59:55 +02:00
$outputlangs -> setDefaultLang ( $newlang );
}
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
fichinter_create ( $db , $object , $object -> model_pdf , $outputlangs );
}
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'confirm_deleteline' && $confirm == 'yes' && $user -> rights -> ficheinter -> creer ) {
// Supprime une ligne d'intervention AVEC confirmation
2015-07-28 14:13:16 +02:00
$objectline = new FichinterLigne ( $db );
2021-02-25 23:00:32 +01:00
if ( $objectline -> fetch ( $lineid ) <= 0 ) {
2015-07-28 14:13:16 +02:00
dol_print_error ( $db );
exit ;
}
2019-11-13 19:35:02 +01:00
$result = $objectline -> deleteline ( $user );
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( $object -> fetch ( $objectline -> fk_fichinter ) <= 0 ) {
2015-07-28 14:13:16 +02:00
dol_print_error ( $db );
2013-06-12 11:59:55 +02:00
exit ;
}
2015-07-28 14:13:16 +02:00
// Define output language
$outputlangs = $langs ;
2019-11-13 19:35:02 +01:00
$newlang = '' ;
2021-02-25 23:00:32 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2015-07-28 14:13:16 +02:00
$outputlangs -> setDefaultLang ( $newlang );
2013-06-12 11:59:55 +02:00
}
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
fichinter_create ( $db , $object , $object -> model_pdf , $outputlangs );
}
} elseif ( $action == 'up' && $user -> rights -> ficheinter -> creer ) {
// Set position of lines
2015-07-28 14:13:16 +02:00
$object -> line_up ( $lineid );
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
// Define output language
$outputlangs = $langs ;
2019-11-13 19:35:02 +01:00
$newlang = '' ;
2021-02-25 23:00:32 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2015-07-28 14:13:16 +02:00
$outputlangs -> setDefaultLang ( $newlang );
}
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
fichinter_create ( $db , $object , $object -> model_pdf , $outputlangs );
}
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '#' . $lineid );
2013-06-12 11:59:55 +02:00
exit ;
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'down' && $user -> rights -> ficheinter -> creer ) {
2015-07-28 14:13:16 +02:00
$object -> line_down ( $lineid );
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
// Define output language
$outputlangs = $langs ;
2019-11-13 19:35:02 +01:00
$newlang = '' ;
2021-02-25 23:00:32 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) {
$newlang = GETPOST ( 'lang_id' , 'aZ09' );
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $object -> thirdparty -> default_lang ;
}
if ( ! empty ( $newlang )) {
2019-01-27 11:55:16 +01:00
$outputlangs = new Translate ( " " , $conf );
2015-07-28 14:13:16 +02:00
$outputlangs -> setDefaultLang ( $newlang );
}
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
fichinter_create ( $db , $object , $object -> model_pdf , $outputlangs );
}
2013-06-12 11:59:55 +02:00
2015-07-28 14:13:16 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '#' . $lineid );
2013-06-12 11:59:55 +02:00
exit ;
}
2017-09-17 15:38:50 +02:00
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php' ;
2016-08-10 11:54:49 +02:00
2016-06-24 16:10:52 +02:00
// Actions to send emails
2019-12-02 09:38:16 +01:00
$triggersendname = 'FICHINTER_SENTBYMAIL' ;
2019-11-13 19:35:02 +01:00
$autocopy = 'MAIN_MAIL_AUTOCOPY_FICHINTER_TO' ;
$trackid = 'int' . $object -> id ;
2016-06-24 16:10:52 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
2016-08-10 11:54:49 +02:00
2017-09-17 15:38:50 +02:00
// Actions to build doc
$upload_dir = $conf -> ficheinter -> dir_output ;
2019-11-05 19:41:30 +01:00
$permissiontoadd = $user -> rights -> ficheinter -> creer ;
2017-09-17 15:38:50 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
2016-06-24 16:10:52 +02:00
2021-02-25 23:00:32 +01:00
if ( $action == 'update_extras' ) {
2018-02-23 16:11:00 +01:00
$object -> oldcopy = dol_clone ( $object );
2015-07-28 14:13:16 +02:00
// Fill array 'array_options' with data from update form
2020-09-18 01:29:17 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , GETPOST ( 'attribute' , 'restricthtml' ));
2021-02-25 23:00:32 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2015-07-28 14:13:16 +02:00
2021-02-25 23:00:32 +01:00
if ( ! $error ) {
2018-04-10 12:03:01 +02:00
// Actions on extra fields
2019-11-13 19:35:02 +01:00
$result = $object -> insertExtraFields ( 'INTERVENTION_MODIFY' );
2021-02-25 23:00:32 +01:00
if ( $result < 0 ) {
2018-04-10 12:03:01 +02:00
$error ++ ;
2013-06-12 11:59:55 +02:00
}
}
2014-01-11 13:33:30 +01:00
2021-02-25 23:00:32 +01:00
if ( $error ) {
$action = 'edit_extras' ;
}
2015-07-28 14:13:16 +02:00
}
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ) && $user -> rights -> ficheinter -> creer ) {
if ( $action == 'addcontact' ) {
if ( $result > 0 && $id > 0 ) {
2019-01-27 11:55:16 +01:00
$contactid = ( GETPOST ( 'userid' , 'int' ) ? GETPOST ( 'userid' , 'int' ) : GETPOST ( 'contactid' , 'int' ));
2020-11-30 15:18:58 +01:00
$typeid = ( GETPOST ( 'typecontact' ) ? GETPOST ( 'typecontact' ) : GETPOST ( 'type' ));
$result = $object -> add_contact ( $contactid , $typeid , GETPOST ( " source " , 'aZ09' ));
2015-07-28 14:13:16 +02:00
}
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( $result >= 0 ) {
2015-07-28 14:13:16 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-25 23:00:32 +01:00
if ( $object -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
2015-07-28 14:13:16 +02:00
$langs -> load ( " errors " );
2020-09-24 13:15:51 +02:00
$mesg = $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " );
2020-05-21 15:05:19 +02:00
} else {
2020-09-24 13:15:51 +02:00
$mesg = $object -> error ;
2015-07-28 14:13:16 +02:00
}
2013-06-12 11:59:55 +02:00
}
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'swapstatut' ) {
// bascule du statut d'un contact
2019-11-13 19:35:02 +01:00
$result = $object -> swapContactStatus ( GETPOST ( 'ligne' , 'int' ));
2021-02-25 23:00:32 +01:00
} elseif ( $action == 'deletecontact' ) {
// Efface un contact
2019-01-27 11:55:16 +01:00
$result = $object -> delete_contact ( GETPOST ( 'lineid' , 'int' ));
2015-07-28 14:13:16 +02:00
2021-02-25 23:00:32 +01:00
if ( $result >= 0 ) {
2015-07-28 14:13:16 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2015-07-28 14:13:16 +02:00
dol_print_error ( $db );
}
2013-06-12 11:59:55 +02:00
}
}
}
/*
* View
*/
$form = new Form ( $db );
$formfile = new FormFile ( $db );
2021-02-25 23:00:32 +01:00
if ( $conf -> contrat -> enabled ) {
$formcontract = new FormContract ( $db );
}
if ( ! empty ( $conf -> projet -> enabled )) {
$formproject = new FormProjets ( $db );
}
2013-06-12 11:59:55 +02:00
2021-03-16 13:49:34 +01:00
$help_url = 'EN:Module_Interventions' ;
llxHeader ( '' , $langs -> trans ( " Intervention " ), $help_url );
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( $action == 'create' ) {
2020-02-08 18:18:41 +01:00
// Create new intervention
2013-06-12 11:59:55 +02:00
2019-11-13 19:35:02 +01:00
$soc = new Societe ( $db );
2013-06-12 11:59:55 +02:00
2020-04-25 13:49:44 +02:00
print load_fiche_titre ( $langs -> trans ( " AddIntervention " ), '' , 'intervention' );
2013-06-12 11:59:55 +02:00
2020-09-24 13:29:30 +02:00
if ( $error > 0 ) {
2020-09-24 13:25:40 +02:00
dol_htmloutput_errors ( $mesg );
} else {
dol_htmloutput_mesg ( $mesg );
}
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( $socid ) {
$res = $soc -> fetch ( $socid );
}
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( GETPOST ( 'origin' , 'alphanohtml' ) && GETPOST ( 'originid' , 'int' )) {
2013-06-12 11:59:55 +02:00
// Parse element/subelement (ex: project_task)
2020-02-08 18:18:41 +01:00
$regs = array ();
$element = $subelement = GETPOST ( 'origin' , 'alphanohtml' );
2021-02-25 23:00:32 +01:00
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , GETPOST ( 'origin' , 'alphanohtml' ), $regs )) {
2013-06-12 11:59:55 +02:00
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
2021-02-25 23:00:32 +01:00
if ( $element == 'project' ) {
2020-10-07 15:01:28 +02:00
$projectid = GETPOST ( 'originid' , 'int' );
} else {
// For compatibility
2019-11-13 19:35:02 +01:00
if ( $element == 'order' || $element == 'commande' ) {
2013-06-12 11:59:55 +02:00
$element = $subelement = 'commande' ;
}
2019-11-13 19:35:02 +01:00
if ( $element == 'propal' ) {
2013-06-12 11:59:55 +02:00
$element = 'comm/propal' ; $subelement = 'propal' ;
}
if ( $element == 'contract' ) {
$element = $subelement = 'contrat' ;
}
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
$classname = ucfirst ( $subelement );
$objectsrc = new $classname ( $db );
$objectsrc -> fetch ( GETPOST ( 'originid' ));
2021-02-25 23:00:32 +01:00
if ( empty ( $objectsrc -> lines ) && method_exists ( $objectsrc , 'fetch_lines' )) {
2014-09-04 18:58:33 +02:00
$objectsrc -> fetch_lines ();
$lines = $objectsrc -> lines ;
}
2013-06-12 11:59:55 +02:00
$objectsrc -> fetch_thirdparty ();
2019-11-13 19:35:02 +01:00
$projectid = ( ! empty ( $objectsrc -> fk_project ) ? $objectsrc -> fk_project : '' );
2013-06-12 11:59:55 +02:00
2018-01-10 16:40:43 +01:00
$soc = $objectsrc -> thirdparty ;
2013-06-12 11:59:55 +02:00
2020-09-18 01:29:17 +02:00
$note_private = ( ! empty ( $objectsrc -> note ) ? $objectsrc -> note : ( ! empty ( $objectsrc -> note_private ) ? $objectsrc -> note_private : GETPOST ( 'note_private' , 'restricthtml' )));
$note_public = ( ! empty ( $objectsrc -> note_public ) ? $objectsrc -> note_public : GETPOST ( 'note_public' , 'restricthtml' ));
2013-06-12 11:59:55 +02:00
// Object source contacts list
2019-01-27 11:55:16 +01:00
$srccontactslist = $objectsrc -> liste_contact ( - 1 , 'external' , 1 );
2013-06-12 11:59:55 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
$projectid = GETPOST ( 'projectid' , 'int' );
2013-06-12 11:59:55 +02:00
}
2021-02-25 23:00:32 +01:00
if ( ! $conf -> global -> FICHEINTER_ADDON ) {
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , $langs -> trans ( " Error " ) . " " . $langs -> trans ( " Error_FICHEINTER_ADDON_NotDefined " ));
2013-06-12 11:59:55 +02:00
exit ;
}
$object -> date = dol_now ();
$obj = $conf -> global -> FICHEINTER_ADDON ;
$obj = " mod_ " . $obj ;
//$modFicheinter = new $obj;
//$numpr = $modFicheinter->getNextValue($soc, $object);
2021-02-25 23:00:32 +01:00
if ( $socid > 0 ) {
2019-11-13 19:35:02 +01:00
$soc = new Societe ( $db );
2013-06-12 11:59:55 +02:00
$soc -> fetch ( $socid );
print '<form name="fichinter" action="' . $_SERVER [ 'PHP_SELF' ] . '" method="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-16 14:38:05 +01:00
print '<input type="hidden" name="socid" value=' . $soc -> id . '>' ;
print '<input type="hidden" name="action" value="add">' ;
2013-06-12 11:59:55 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' );
2015-06-06 12:26:47 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2013-06-12 11:59:55 +02:00
2016-04-04 15:20:21 +02:00
print '<tr><td class="fieldrequired titlefieldcreate">' . $langs -> trans ( " ThirdParty " ) . '</td><td>' . $soc -> getNomUrl ( 1 ) . '</td></tr>' ;
2013-06-12 11:59:55 +02:00
// Ref
2019-11-16 14:38:05 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Ref' ) . '</td><td>' . $langs -> trans ( " Draft " ) . '</td></tr>' ;
2013-06-12 11:59:55 +02:00
// Description (must be a textarea and not html must be allowed (used in list view)
2016-01-08 23:54:40 +01:00
print '<tr><td class="tdtop">' . $langs -> trans ( " Description " ) . '</td>' ;
2013-06-12 11:59:55 +02:00
print '<td>' ;
2017-01-22 13:19:07 +01:00
print '<textarea name="description" class="quatrevingtpercent" rows="' . ROWS_3 . '">' . GETPOST ( 'description' ) . '</textarea>' ;
2013-06-12 11:59:55 +02:00
print '</td></tr>' ;
// Project
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2019-11-13 19:35:02 +01:00
$formproject = new FormProjets ( $db );
2014-01-11 13:33:30 +01:00
2013-06-12 11:59:55 +02:00
$langs -> load ( " project " );
2020-10-07 15:01:28 +02:00
print '<tr><td>' . $langs -> trans ( " Project " ) . '</td><td>' ;
/* Fix : If a project must be linked to any companies ( suppliers or not ), project must be not be set as limited to customer but must be not linked to any particular thirdparty
2021-02-25 23:00:32 +01:00
if ( $societe -> fournisseur == 1 )
2021-03-24 19:53:31 +01:00
$numprojet = select_projects ( - 1 , GETPOST ( " projectid " , 'int' ), 'projectid' );
2021-02-25 23:00:32 +01:00
else
2021-03-24 19:53:31 +01:00
$numprojet = select_projects ( $societe -> id , GETPOST ( " projectid " , 'int' ), 'projectid' );
2021-02-25 23:00:32 +01:00
*/
2020-10-07 15:01:28 +02:00
$numprojet = $formproject -> select_projects ( $soc -> id , $projectid , 'projectid' );
2021-02-25 23:00:32 +01:00
if ( $numprojet == 0 ) {
2020-10-07 15:01:28 +02:00
print ' <a href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc -> id . '&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs -> trans ( " AddProject " ) . '"></span></a>' ;
}
print '</td></tr>' ;
}
2013-06-12 11:59:55 +02:00
// Contract
2021-02-25 23:00:32 +01:00
if ( $conf -> contrat -> enabled ) {
2014-03-01 15:21:11 +01:00
$langs -> load ( " contracts " );
2016-01-08 23:54:40 +01:00
print '<tr><td>' . $langs -> trans ( " Contract " ) . '</td><td>' ;
2020-08-27 10:11:18 +02:00
$numcontrat = $formcontract -> select_contract ( $soc -> id , GETPOST ( 'contratid' , 'int' ), 'contratid' , 0 , 1 , 1 );
2021-02-25 23:00:32 +01:00
if ( $numcontrat == 0 ) {
2020-02-08 18:18:41 +01:00
print ' <a href="' . DOL_URL_ROOT . '/contrat/card.php?socid=' . $soc -> id . '&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs -> trans ( " AddContract " ) . '"></span></a>' ;
2013-06-12 11:59:55 +02:00
}
print '</td></tr>' ;
}
2020-10-07 15:01:28 +02:00
// Model
print '<tr>' ;
print '<td>' . $langs -> trans ( " DefaultModel " ) . '</td>' ;
print '<td>' ;
$liste = ModelePDFFicheinter :: liste_modeles ( $db );
print $form -> selectarray ( 'model' , $liste , $conf -> global -> FICHEINTER_ADDON_PDF );
print " </td></tr> " ;
// Public note
print '<tr>' ;
print '<td class="tdtop">' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
print '<td>' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_public' , $note_public , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PUBLIC ) ? 0 : 1 , ROWS_3 , '90%' );
2020-10-07 15:01:28 +02:00
print $doleditor -> Create ( 1 );
//print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
print '</td></tr>' ;
// Private note
2021-02-25 23:00:32 +01:00
if ( empty ( $user -> socid )) {
2020-10-07 15:01:28 +02:00
print '<tr>' ;
print '<td class="tdtop">' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
print '<td>' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_private' , $note_private , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PRIVATE ) ? 0 : 1 , ROWS_3 , '90%' );
2020-10-07 15:01:28 +02:00
print $doleditor -> Create ( 1 );
//print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
print '</td></tr>' ;
}
// Other attributes
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2021-02-25 23:00:32 +01:00
if ( empty ( $reshook )) {
2019-01-27 11:55:16 +01:00
print $object -> showOptionals ( $extrafields , 'edit' );
2013-06-12 11:59:55 +02:00
}
2020-10-07 15:01:28 +02:00
// Show link to origin object
2021-02-25 23:00:32 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid ) && is_object ( $objectsrc )) {
2020-10-07 15:01:28 +02:00
$newclassname = $classname ;
2021-02-25 23:00:32 +01:00
if ( $newclassname == 'Propal' ) {
$newclassname = 'CommercialProposal' ;
}
2020-10-07 15:01:28 +02:00
print '<tr><td>' . $langs -> trans ( $newclassname ) . '</td><td colspan="2">' . $objectsrc -> getNomUrl ( 1 ) . '</td></tr>' ;
2017-10-17 10:44:18 +02:00
2020-10-07 15:01:28 +02:00
// Amount
/* Hide amount because we only copy services so amount may differ than source
2021-02-25 23:00:32 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountHT' ) . '</td><td>' . price ( $objectsrc -> total_ht ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td>' . price ( $objectsrc -> total_tva ) . " </td></tr> " ;
if ( $mysoc -> localtax1_assuj == " 1 " || $objectsrc -> total_localtax1 != 0 ) // Localtax1 RE
{
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> country_code ) . '</td><td>' . price ( $objectsrc -> total_localtax1 ) . " </td></tr> " ;
}
if ( $mysoc -> localtax2_assuj == " 1 " || $objectsrc -> total_localtax2 != 0 ) // Localtax2 IRPF
{
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> country_code ) . '</td><td>' . price ( $objectsrc -> total_localtax2 ) . " </td></tr> " ;
}
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td>' . price ( $objectsrc -> total_ttc ) . " </td></tr> " ;
if ( ! empty ( $conf -> multicurrency -> enabled ))
{
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountHT' ) . '</td><td>' . price ( $objectsrc -> multicurrency_total_ht ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountVAT' ) . '</td><td>' . price ( $objectsrc -> multicurrency_total_tva ) . " </td></tr> " ;
print '<tr><td>' . $langs -> trans ( 'MulticurrencyAmountTTC' ) . '</td><td>' . price ( $objectsrc -> multicurrency_total_ttc ) . " </td></tr> " ;
}
*/
2020-10-07 15:01:28 +02:00
}
2013-06-12 11:59:55 +02:00
2020-10-07 15:01:28 +02:00
print '</table>' ;
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( is_object ( $objectsrc )) {
2020-10-07 15:01:28 +02:00
print '<input type="hidden" name="origin" value="' . $objectsrc -> element . '">' ;
print '<input type="hidden" name="originid" value="' . $objectsrc -> id . '">' ;
2016-08-10 11:54:49 +02:00
} elseif ( $origin == 'project' && ! empty ( $projectid )) {
2019-11-13 19:35:02 +01:00
print '<input type="hidden" name="projectid" value="' . $projectid . '">' ;
2013-06-12 11:59:55 +02:00
}
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-06-06 12:26:47 +02:00
2015-05-13 17:53:25 +02:00
print '<div class="center">' ;
2013-06-12 11:59:55 +02:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " CreateDraftIntervention " ) . '">' ;
2020-10-07 15:01:28 +02:00
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input type="button" class="button button-cancel" value="' . $langs -> trans ( " Cancel " ) . '" onClick="javascript:history.go(-1)">' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2013-06-12 11:59:55 +02:00
2017-10-17 10:44:18 +02:00
// Show origin lines
2019-11-13 19:35:02 +01:00
if ( ! empty ( $origin ) && ! empty ( $originid ) && is_object ( $objectsrc )) {
2017-10-17 10:44:18 +02:00
$title = $langs -> trans ( 'Services' );
print load_fiche_titre ( $title );
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2017-10-17 10:44:18 +02:00
2019-11-13 19:35:02 +01:00
$objectsrc -> printOriginLinesList ( empty ( $conf -> global -> FICHINTER_PRINT_PRODUCTS ) ? 'services' : '' ); // Show only service, except if option FICHINTER_PRINT_PRODUCTS is on
2017-10-17 10:44:18 +02:00
print '</table>' ;
}
2021-02-05 09:48:08 +01:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-03-09 20:19:28 +01:00
print '<form name="fichinter" action="' . $_SERVER [ 'PHP_SELF' ] . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' );
2015-06-06 12:26:47 +02:00
2021-02-25 23:00:32 +01:00
if ( is_object ( $objectsrc )) {
2016-08-10 11:54:49 +02:00
print '<input type="hidden" name="origin" value="' . $objectsrc -> element . '">' ;
print '<input type="hidden" name="originid" value="' . $objectsrc -> id . '">' ;
} elseif ( $origin == 'project' && ! empty ( $projectid )) {
2019-11-13 19:35:02 +01:00
print '<input type="hidden" name="projectid" value="' . $projectid . '">' ;
2016-08-10 11:54:49 +02:00
}
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2013-06-12 11:59:55 +02:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " ThirdParty " ) . '</td><td>' ;
2017-06-21 11:37:34 +02:00
print $form -> select_company ( '' , 'socid' , '' , 'SelectThirdParty' , 1 , 0 , null , 0 , 'minwidth300' );
2020-02-13 11:57:13 +01:00
print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?action=create' ) . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs -> trans ( " AddThirdParty " ) . '"></span></a>' ;
2013-06-12 11:59:55 +02:00
print '</td></tr>' ;
print '</table>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-06-06 12:26:47 +02:00
2015-05-13 17:53:25 +02:00
print '<div class="center">' ;
2013-06-12 11:59:55 +02:00
print '<input type="hidden" name="action" value="create">' ;
print '<input type="submit" class="button" value="' . $langs -> trans ( " CreateDraftIntervention " ) . '">' ;
2020-10-07 15:01:28 +02:00
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input type="button" class="button button-cancel" value="' . $langs -> trans ( " Cancel " ) . '" onClick="javascript:history.go(-1)">' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2013-06-12 11:59:55 +02:00
print '</form>' ;
}
2021-02-25 23:00:32 +01:00
} elseif ( $id > 0 || ! empty ( $ref )) {
2013-06-12 11:59:55 +02:00
/*
* Affichage en mode visu
2021-02-25 23:00:32 +01:00
*/
2013-06-12 11:59:55 +02:00
$object -> fetch ( $id , $ref );
$object -> fetch_thirdparty ();
2019-11-13 19:35:02 +01:00
$soc = new Societe ( $db );
2013-06-12 11:59:55 +02:00
$soc -> fetch ( $object -> socid );
2020-09-24 13:29:30 +02:00
if ( $error > 0 ) {
2020-09-24 13:25:40 +02:00
dol_htmloutput_errors ( $mesg );
} else {
dol_htmloutput_mesg ( $mesg );
}
2013-06-12 11:59:55 +02:00
$head = fichinter_prepare_head ( $object );
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $langs -> trans ( " InterventionCard " ), - 1 , 'intervention' );
2013-06-12 11:59:55 +02:00
2019-11-13 19:35:02 +01:00
$formconfirm = '' ;
2014-09-24 17:43:38 +02:00
2014-10-20 23:37:28 +02:00
// Confirm deletion of intervention
2021-02-25 23:00:32 +01:00
if ( $action == 'delete' ) {
2019-01-27 11:55:16 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'DeleteIntervention' ), $langs -> trans ( 'ConfirmDeleteIntervention' ), 'confirm_delete' , '' , 0 , 1 );
2013-06-12 11:59:55 +02:00
}
2014-10-20 23:37:28 +02:00
// Confirm validation
2021-02-25 23:00:32 +01:00
if ( $action == 'validate' ) {
2013-06-12 11:59:55 +02:00
// on verifie si l'objet est en numerotation provisoire
$ref = substr ( $object -> ref , 1 , 4 );
2021-02-25 23:00:32 +01:00
if ( $ref == 'PROV' ) {
2013-06-12 11:59:55 +02:00
$numref = $object -> getNextNumRef ( $soc );
2021-02-25 23:00:32 +01:00
if ( empty ( $numref )) {
2013-06-12 11:59:55 +02:00
$error ++ ;
2015-12-08 11:35:08 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2013-06-12 11:59:55 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2013-06-12 11:59:55 +02:00
$numref = $object -> ref ;
}
2019-11-13 19:35:02 +01:00
$text = $langs -> trans ( 'ConfirmValidateIntervention' , $numref );
2013-06-12 11:59:55 +02:00
2019-01-27 11:55:16 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ValidateIntervention' ), $text , 'confirm_validate' , '' , 1 , 1 );
2013-06-12 11:59:55 +02:00
}
2014-10-20 23:37:28 +02:00
// Confirm back to draft
2021-02-25 23:00:32 +01:00
if ( $action == 'modify' ) {
2019-01-27 11:55:16 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ModifyIntervention' ), $langs -> trans ( 'ConfirmModifyIntervention' ), 'confirm_modify' , '' , 0 , 1 );
2013-06-12 11:59:55 +02:00
}
2020-09-25 08:10:48 +02:00
// Confirm back to open
2021-02-25 23:00:32 +01:00
if ( $action == 'reopen' ) {
2020-09-25 08:10:48 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'Reopen' ), $langs -> trans ( 'ConfirmReopenIntervention' , $object -> ref ), 'confirm_reopen' , '' , 0 , 1 );
}
2014-10-20 23:37:28 +02:00
// Confirm deletion of line
2021-02-25 23:00:32 +01:00
if ( $action == 'ask_deleteline' ) {
2019-01-27 11:55:16 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&line_id=' . $lineid , $langs -> trans ( 'DeleteInterventionLine' ), $langs -> trans ( 'ConfirmDeleteInterventionLine' ), 'confirm_deleteline' , '' , 0 , 1 );
2013-06-12 11:59:55 +02:00
}
2014-09-24 17:43:38 +02:00
2016-07-01 18:12:37 +02:00
// Clone confirmation
if ( $action == 'clone' ) {
// Create an array for form
$formquestion = array (
// 'text' => $langs->trans("ConfirmClone"),
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
// 1),
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
// => 1),
2019-11-13 19:35:02 +01:00
array ( 'type' => 'other' , 'name' => 'socid' , 'label' => $langs -> trans ( " SelectThirdParty " ), 'value' => $form -> select_company ( GETPOST ( 'socid' , 'int' ), 'socid' , '' , '' , 0 , 0 , null , 0 , 'minwidth200' )));
2016-07-01 18:12:37 +02:00
// Paiement incomplet. On demande si motif = escompte ou autre
2019-11-13 19:35:02 +01:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ToClone' ), $langs -> trans ( 'ConfirmCloneIntervention' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 );
2016-07-01 18:12:37 +02:00
}
2016-08-10 11:54:49 +02:00
2021-02-25 23:00:32 +01:00
if ( ! $formconfirm ) {
2020-01-28 12:00:27 +01:00
$parameters = array ( 'formConfirm' => $formconfirm , 'lineid' => $lineid );
2015-03-18 14:31:37 +01:00
$reshook = $hookmanager -> executeHooks ( 'formConfirm' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-02-25 23:00:32 +01:00
if ( empty ( $reshook )) {
$formconfirm .= $hookmanager -> resPrint ;
} elseif ( $reshook > 0 ) {
$formconfirm = $hookmanager -> resPrint ;
}
2014-09-24 13:28:59 +02:00
}
// Print form confirm
print $formconfirm ;
2013-06-12 11:59:55 +02:00
2017-06-11 10:37:58 +02:00
2016-09-19 13:09:50 +02:00
// Intervention card
2019-11-13 19:35:02 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/fichinter/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-06-11 10:37:58 +02:00
2019-11-13 19:35:02 +01:00
$morehtmlref = '<div class="refidno">' ;
2016-09-19 13:09:50 +02:00
// Ref customer
2016-12-09 15:59:31 +01:00
//$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', 0, 1);
//$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', null, null, '', 1);
2016-09-19 13:09:50 +02:00
// Thirdparty
2019-11-13 19:35:02 +01:00
$morehtmlref .= $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
2016-09-19 13:09:50 +02:00
// Project
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> projet -> enabled )) {
2020-10-07 15:01:28 +02:00
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-02-25 23:00:32 +01:00
if ( $user -> rights -> ficheinter -> creer ) {
2020-10-07 15:01:28 +02:00
if ( $action != 'classify' ) {
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
}
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
} else {
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
}
} else {
if ( ! empty ( $object -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $object -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
} else {
$morehtmlref .= '' ;
}
}
2016-09-19 13:09:50 +02:00
}
2019-11-13 19:35:02 +01:00
$morehtmlref .= '</div>' ;
2017-06-11 10:37:58 +02:00
2020-10-07 15:01:28 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2017-06-11 10:37:58 +02:00
2020-10-07 15:01:28 +02:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-11 10:37:58 +02:00
2020-10-07 15:01:28 +02:00
print '<table class="border tableforfield" width="100%">' ;
2017-06-11 10:37:58 +02:00
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> global -> FICHINTER_USE_PLANNED_AND_DONE_DATES )) {
2015-12-04 11:25:07 +01:00
// Date Start
2016-09-19 13:09:50 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Dateo " ) . '</td>' ;
print '<td>' ;
2015-12-04 11:25:07 +01:00
print $object -> dateo ? dol_print_date ( $object -> dateo , 'daytext' ) : ' ' ;
print '</td>' ;
print '</tr>' ;
2016-08-10 11:54:49 +02:00
2015-12-04 11:25:07 +01:00
// Date End
print '<tr><td>' . $langs -> trans ( " Datee " ) . '</td>' ;
2016-09-19 13:09:50 +02:00
print '<td>' ;
2015-12-04 11:25:07 +01:00
print $object -> datee ? dol_print_date ( $object -> datee , 'daytext' ) : ' ' ;
print '</td>' ;
print '</tr>' ;
2016-08-10 11:54:49 +02:00
2015-12-15 11:54:00 +01:00
// Date Terminate/close
print '<tr><td>' . $langs -> trans ( " Datet " ) . '</td>' ;
2016-09-19 13:09:50 +02:00
print '<td>' ;
2015-12-15 11:54:00 +01:00
print $object -> datet ? dol_print_date ( $object -> datet , 'daytext' ) : ' ' ;
print '</td>' ;
print '</tr>' ;
2014-09-04 14:39:18 +02:00
}
2013-06-12 11:59:55 +02:00
// Description (must be a textarea and not html must be allowed (used in list view)
2016-09-19 13:09:50 +02:00
print '<tr><td class="titlefield">' ;
2019-01-27 11:55:16 +01:00
print $form -> editfieldkey ( " Description " , 'description' , $object -> description , $object , $user -> rights -> ficheinter -> creer , 'textarea' );
2016-09-19 13:09:50 +02:00
print '</td><td>' ;
2019-01-27 11:55:16 +01:00
print $form -> editfieldval ( " Description " , 'description' , $object -> description , $object , $user -> rights -> ficheinter -> creer , 'textarea:8:80' );
2013-06-12 11:59:55 +02:00
print '</td>' ;
print '</tr>' ;
2019-01-16 13:44:49 +01:00
// Contract
2021-02-25 23:00:32 +01:00
if ( $conf -> contrat -> enabled ) {
2019-01-16 13:44:49 +01:00
$langs -> load ( 'contracts' );
2013-06-12 11:59:55 +02:00
print '<tr>' ;
print '<td>' ;
2019-10-24 15:57:48 +02:00
print '<table class="nobordernopadding centpercent"><tr><td>' ;
2013-06-12 11:59:55 +02:00
print $langs -> trans ( 'Contract' );
print '</td>' ;
2021-02-25 23:00:32 +01:00
if ( $action != 'contrat' ) {
2019-10-24 15:57:48 +02:00
print '<td class="right"><a class="editfielda" href="' . $_SERVER [ " PHP_SELF " ] . '?action=contrat&id=' . $object -> id . '">' ;
2019-01-27 11:55:16 +01:00
print img_edit ( $langs -> trans ( 'SetContract' ), 1 );
2013-06-12 11:59:55 +02:00
print '</a></td>' ;
}
print '</tr></table>' ;
2016-09-19 13:09:50 +02:00
print '</td><td>' ;
2021-02-25 23:00:32 +01:00
if ( $action == 'contrat' ) {
2019-11-13 19:35:02 +01:00
$formcontract = new Formcontract ( $db );
2020-08-27 10:11:18 +02:00
$formcontract -> formSelectContract ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $object -> socid , $object -> fk_contrat , 'contratid' , 0 , 1 , 1 );
2020-05-21 15:05:19 +02:00
} else {
2021-02-25 23:00:32 +01:00
if ( $object -> fk_contrat ) {
2020-10-07 15:01:28 +02:00
$contratstatic = new Contrat ( $db );
$contratstatic -> fetch ( $object -> fk_contrat );
//print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
print $contratstatic -> getNomUrl ( 0 , '' , 1 );
} else {
print " " ;
}
2013-06-12 11:59:55 +02:00
}
print '</td>' ;
print '</tr>' ;
}
2020-10-07 15:01:28 +02:00
// Other attributes
$cols = 2 ;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2013-06-12 11:59:55 +02:00
2020-10-07 15:01:28 +02:00
print '</table>' ;
2017-06-11 10:37:58 +02:00
2020-10-07 15:01:28 +02:00
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="ficheaddleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-11 10:37:58 +02:00
2020-10-07 15:01:28 +02:00
print '<table class="border tableforfield centpercent">' ;
2017-06-11 10:37:58 +02:00
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) {
2020-10-07 15:01:28 +02:00
// Duration
print '<tr><td class="titlefield">' . $langs -> trans ( " TotalDuration " ) . '</td>' ;
print '<td>' . convertSecondToTime ( $object -> duration , 'all' , $conf -> global -> MAIN_DURATION_OF_WORKDAY ) . '</td>' ;
print '</tr>' ;
}
2017-06-11 10:37:58 +02:00
2014-08-15 21:18:56 +02:00
print " </table> " ;
2017-06-11 10:37:58 +02:00
2016-09-19 13:09:50 +02:00
print '</div>' ;
2020-10-07 15:01:28 +02:00
print '</div>' ;
print '</div>' ;
2017-06-11 10:37:58 +02:00
2020-10-07 15:01:28 +02:00
print '<div class="clearboth"></div><br>' ;
2017-06-11 10:37:58 +02:00
2014-07-08 01:12:55 +02:00
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB )) {
2013-06-12 11:59:55 +02:00
$blocname = 'contacts' ;
$title = $langs -> trans ( 'ContactsAddresses' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB )) {
2013-06-12 11:59:55 +02:00
$blocname = 'notes' ;
$title = $langs -> trans ( 'Notes' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2015-07-12 18:05:56 +02:00
// Line of interventions
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) {
2014-08-15 23:20:31 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" name="addinter" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2014-08-15 23:20:31 +02:00
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
2021-01-28 10:30:09 +01:00
if ( $action == 'editline' ) {
2014-08-15 23:20:31 +02:00
print '<input type="hidden" name="action" value="updateline">' ;
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="line_id" value="' . GETPOST ( 'line_id' , 'int' ) . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2014-08-15 23:20:31 +02:00
print '<input type="hidden" name="action" value="addline">' ;
}
// Intervention lines
$sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,' ;
2019-11-13 19:35:02 +01:00
$sql .= ' ft.date as date_intervention' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'fichinterdet as ft' ;
$sql .= ' WHERE ft.fk_fichinter = ' . $object -> id ;
2021-01-28 10:30:09 +01:00
if ( ! empty ( $conf -> global -> FICHINTER_HIDE_EMPTY_DURATION )) {
2019-11-13 19:35:02 +01:00
$sql .= ' AND ft.duree <> 0' ;
2021-01-28 10:30:09 +01:00
}
2019-11-13 19:35:02 +01:00
$sql .= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid' ;
2014-08-15 23:20:31 +02:00
$resql = $db -> query ( $sql );
2021-02-25 23:00:32 +01:00
if ( $resql ) {
2014-08-15 23:20:31 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2013-06-12 11:59:55 +02:00
2021-02-25 23:00:32 +01:00
if ( $num ) {
2014-08-15 23:20:31 +02:00
print '<br>' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2014-08-15 23:20:31 +02:00
print '<tr class="liste_titre">' ;
2020-09-25 08:25:24 +02:00
// No.
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
print '<td width="5" class="center linecolnum"></td>' ;
}
2016-12-23 13:04:46 +01:00
print '<td class="liste_titre">' . $langs -> trans ( 'Description' ) . '</td>' ;
2019-03-07 21:29:15 +01:00
print '<td class="liste_titre center">' . $langs -> trans ( 'Date' ) . '</td>' ;
2019-11-13 19:35:02 +01:00
print '<td class="liste_titre right">' . ( empty ( $conf -> global -> FICHINTER_WITHOUT_DURATION ) ? $langs -> trans ( 'Duration' ) : '' ) . '</td>' ;
2016-12-23 13:04:46 +01:00
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre"> </td>' ;
2014-08-15 23:20:31 +02:00
print " </tr> \n " ;
}
2021-01-28 10:30:09 +01:00
while ( $i < $num ) {
2014-08-15 23:20:31 +02:00
$objp = $db -> fetch_object ( $resql );
2017-06-11 10:37:58 +02:00
2014-08-15 23:20:31 +02:00
// Ligne en mode visu
2021-01-28 10:30:09 +01:00
if ( $action != 'editline' || GETPOST ( 'line_id' , 'int' ) != $objp -> rowid ) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2020-09-25 08:25:24 +02:00
// No.
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
print '<td class="center linecolnum">' . ( $i + 1 ) . '</td>' ;
}
2014-08-15 23:20:31 +02:00
print '<td>' ;
print '<a name="' . $objp -> rowid . '"></a>' ; // ancre pour retourner sur la ligne
print dol_htmlentitiesbr ( $objp -> description );
2013-06-12 11:59:55 +02:00
2014-08-15 23:20:31 +02:00
// Date
2019-11-13 19:35:02 +01:00
print '<td class="center" width="150">' . ( empty ( $conf -> global -> FICHINTER_DATE_WITHOUT_HOUR ) ? dol_print_date ( $db -> jdate ( $objp -> date_intervention ), 'dayhour' ) : dol_print_date ( $db -> jdate ( $objp -> date_intervention ), 'day' )) . '</td>' ;
2013-06-12 11:59:55 +02:00
2014-08-15 23:20:31 +02:00
// Duration
2019-11-13 19:35:02 +01:00
print '<td class="right" width="150">' . ( empty ( $conf -> global -> FICHINTER_WITHOUT_DURATION ) ? convertSecondToTime ( $objp -> duree ) : '' ) . '</td>' ;
2013-06-12 11:59:55 +02:00
2014-08-15 23:20:31 +02:00
print " </td> \n " ;
2013-06-12 11:59:55 +02:00
2021-01-28 10:30:09 +01:00
// Icon to edit and delete
2021-02-25 23:00:32 +01:00
if ( $object -> statut == 0 && $user -> rights -> ficheinter -> creer ) {
2019-03-07 21:29:15 +01:00
print '<td class="center">' ;
2020-04-20 02:14:43 +02:00
print '<a class="editfielda marginrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=editline&line_id=' . $objp -> rowid . '#' . $objp -> rowid . '">' ;
2014-08-15 23:20:31 +02:00
print img_edit ();
print '</a>' ;
2020-04-20 02:14:43 +02:00
print '<a class="marginleftonly" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=ask_deleteline&line_id=' . $objp -> rowid . '">' ;
2014-08-15 23:20:31 +02:00
print img_delete ();
print '</a></td>' ;
2019-03-07 21:29:15 +01:00
print '<td class="center">' ;
2021-02-25 23:00:32 +01:00
if ( $num > 1 ) {
if ( $i > 0 ) {
2020-04-20 02:14:43 +02:00
print '<a class="marginleftonly" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=up&line_id=' . $objp -> rowid . '">' ;
2014-08-15 23:20:31 +02:00
print img_up ();
print '</a>' ;
}
2021-02-25 23:00:32 +01:00
if ( $i < $num - 1 ) {
2020-04-20 02:14:43 +02:00
print '<a class="marginleftonly" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=down&line_id=' . $objp -> rowid . '">' ;
2014-08-15 23:20:31 +02:00
print img_down ();
print '</a>' ;
}
2013-06-12 11:59:55 +02:00
}
2017-04-12 19:30:01 +02:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-20 02:14:43 +02:00
print '<td colspan="2"> </td>' ;
2014-08-15 23:20:31 +02:00
}
print '</tr>' ;
2014-08-30 20:05:16 +02:00
2014-08-26 17:25:13 +02:00
$line = new FichinterLigne ( $db );
$line -> fetch ( $objp -> rowid );
2014-08-30 20:05:16 +02:00
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $line -> table_element );
2014-08-30 20:05:16 +02:00
2018-02-21 14:48:25 +01:00
$line -> fetch_optionals ();
2014-08-30 20:05:16 +02:00
2019-10-06 14:41:52 +02:00
print $line -> showOptionals ( $extrafields , 'view' , array ( 'colspan' => 5 ));
2013-06-12 11:59:55 +02:00
}
2014-08-15 23:20:31 +02:00
// Line in update mode
2021-02-25 23:00:32 +01:00
if ( $object -> statut == 0 && $action == 'editline' && $user -> rights -> ficheinter -> creer && GETPOST ( 'line_id' , 'int' ) == $objp -> rowid ) {
2020-04-20 02:14:43 +02:00
print '<tr class="oddeven nohover">' ;
2020-09-25 08:25:24 +02:00
// No.
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
print '<td class="center linecolnum">' . ( $i + 1 ) . '</td>' ;
}
2014-08-15 23:20:31 +02:00
print '<td>' ;
print '<a name="' . $objp -> rowid . '"></a>' ; // ancre pour retourner sur la ligne
// Editeur wysiwyg
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-11-13 19:35:02 +01:00
$doleditor = new DolEditor ( 'np_desc' , $objp -> description , '' , 164 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_DETAILS , ROWS_2 , '90%' );
2014-08-15 23:20:31 +02:00
$doleditor -> Create ();
print '</td>' ;
// Date d'intervention
2019-03-07 21:29:15 +01:00
print '<td class="center nowrap">' ;
2020-10-07 15:01:28 +02:00
if ( ! empty ( $conf -> global -> FICHINTER_DATE_WITHOUT_HOUR )) {
print $form -> selectDate ( $db -> jdate ( $objp -> date_intervention ), 'di' , 0 , 0 , 0 , " date_intervention " );
} else {
print $form -> selectDate ( $db -> jdate ( $objp -> date_intervention ), 'di' , 1 , 1 , 0 , " date_intervention " );
}
print '</td>' ;
// Duration
print '<td class="right">' ;
if ( empty ( $conf -> global -> FICHINTER_WITHOUT_DURATION )) {
$selectmode = 'select' ;
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> global -> INTERVENTION_ADDLINE_FREEDUREATION )) {
2020-10-07 15:01:28 +02:00
$selectmode = 'text' ;
2021-02-25 23:00:32 +01:00
}
2020-10-07 15:01:28 +02:00
$form -> select_duration ( 'duration' , $objp -> duree , 0 , $selectmode );
}
2014-08-15 23:20:31 +02:00
print '</td>' ;
2016-08-10 11:54:49 +02:00
2020-10-07 15:01:28 +02:00
print '<td class="center" colspan="5" valign="center">' ;
2020-11-19 20:23:38 +01:00
print '<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="' . $langs -> trans ( " Save " ) . '">' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"></td>' ;
2019-11-13 19:35:02 +01:00
print '</tr>' . " \n " ;
2014-08-30 20:05:16 +02:00
2014-08-26 17:25:13 +02:00
$line = new FichinterLigne ( $db );
$line -> fetch ( $objp -> rowid );
2014-08-30 20:05:16 +02:00
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $line -> table_element );
2018-02-21 14:48:25 +01:00
$line -> fetch_optionals ();
2014-08-30 20:05:16 +02:00
2019-10-06 14:41:52 +02:00
print $line -> showOptionals ( $extrafields , 'edit' , array ( 'colspan' => 5 ));
2013-06-12 11:59:55 +02:00
}
2014-08-15 23:20:31 +02:00
$i ++ ;
2013-06-12 11:59:55 +02:00
}
2014-08-15 23:20:31 +02:00
$db -> free ( $resql );
// Add new line
2021-02-25 23:00:32 +01:00
if ( $object -> statut == 0 && $user -> rights -> ficheinter -> creer && $action <> 'editline' && empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) {
if ( ! $num ) {
2020-09-25 08:25:24 +02:00
print '<br>' ;
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
// No.
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
print '<td width="5" class="center linecolnum"></td>' ;
}
2017-04-12 19:30:01 +02:00
2020-10-07 15:01:28 +02:00
print '<td>' ;
print '<a name="add"></a>' ; // ancre
print $langs -> trans ( 'Description' ) . '</td>' ;
print '<td class="center">' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td class="right">' . ( empty ( $conf -> global -> FICHINTER_WITHOUT_DURATION ) ? $langs -> trans ( 'Duration' ) : '' ) . '</td>' ;
2021-02-25 23:00:32 +01:00
print '<td colspan="3"> </td>' ;
2020-10-07 15:01:28 +02:00
print " </tr> \n " ;
2017-04-12 19:30:01 +02:00
}
2017-06-11 10:37:58 +02:00
2020-04-20 02:14:43 +02:00
print '<tr class="oddeven nohover">' . " \n " ;
2020-09-25 08:25:24 +02:00
// No.
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
print '<td class="center linecolnum">' . ( $i + 1 ) . '</td>' ;
}
2020-10-07 15:01:28 +02:00
print '<td>' ;
// editeur wysiwyg
if ( empty ( $conf -> global -> FICHINTER_EMPTY_LINE_DESC )) {
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
$doleditor = new DolEditor ( 'np_desc' , GETPOST ( 'np_desc' , 'restricthtml' ), '' , 100 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_DETAILS , ROWS_2 , '90%' );
$doleditor -> Create ();
}
print '</td>' ;
// Date intervention
print '<td class="center nowrap">' ;
2019-11-13 19:35:02 +01:00
$now = dol_now ();
$timearray = dol_getdate ( $now );
if ( ! GETPOST ( 'diday' , 'int' )) {
2020-10-07 15:01:28 +02:00
$timewithnohour = dol_mktime ( 0 , 0 , 0 , $timearray [ 'mon' ], $timearray [ 'mday' ], $timearray [ 'year' ]);
} else {
$timewithnohour = dol_mktime ( GETPOST ( 'dihour' , 'int' ), GETPOST ( 'dimin' , 'int' ), 0 , GETPOST ( 'dimonth' , 'int' ), GETPOST ( 'diday' , 'int' ), GETPOST ( 'diyear' , 'int' ));
}
if ( ! empty ( $conf -> global -> FICHINTER_DATE_WITHOUT_HOUR )) {
print $form -> selectDate ( $timewithnohour , 'di' , 0 , 0 , 0 , " addinter " );
} else {
print $form -> selectDate ( $timewithnohour , 'di' , 1 , 1 , 0 , " addinter " );
}
print '</td>' ;
// Duration
print '<td class="right">' ;
if ( empty ( $conf -> global -> FICHINTER_WITHOUT_DURATION )) {
$selectmode = 'select' ;
if ( ! empty ( $conf -> global -> INTERVENTION_ADDLINE_FREEDUREATION )) {
$selectmode = 'text' ;
}
$form -> select_duration ( 'duration' , ( ! GETPOST ( 'durationhour' , 'int' ) && ! GETPOST ( 'durationmin' , 'int' )) ? 3600 : ( 60 * 60 * GETPOST ( 'durationhour' , 'int' ) + 60 * GETPOST ( 'durationmin' , 'int' )), 0 , $selectmode );
}
2013-06-12 11:59:55 +02:00
print '</td>' ;
2020-10-07 15:01:28 +02:00
print '<td class="center" valign="middle" colspan="3"><input type="submit" class="button" value="' . $langs -> trans ( 'Add' ) . '" name="addline"></td>' ;
2014-08-15 23:20:31 +02:00
print '</tr>' ;
2014-08-30 20:05:16 +02:00
2014-08-26 12:11:34 +02:00
//Line extrafield
2014-08-30 20:05:16 +02:00
2014-08-26 12:11:34 +02:00
$lineadd = new FichinterLigne ( $db );
2014-08-30 20:05:16 +02:00
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $lineadd -> table_element );
2014-08-30 20:05:16 +02:00
2019-10-06 14:41:52 +02:00
print $lineadd -> showOptionals ( $extrafields , 'edit' , array ( 'colspan' => 5 ));
2014-08-30 20:05:16 +02:00
2021-02-25 23:00:32 +01:00
if ( ! $num ) {
print '</table>' ;
}
2013-06-12 11:59:55 +02:00
}
2021-02-25 23:00:32 +01:00
if ( $num ) {
print '</table>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2014-08-15 23:20:31 +02:00
dol_print_error ( $db );
2013-06-12 11:59:55 +02:00
}
2014-08-15 23:20:31 +02:00
print '</form>' . " \n " ;
2021-02-25 23:00:32 +01:00
}
2013-06-12 11:59:55 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2014-02-12 18:36:49 +01:00
2013-06-12 11:59:55 +02:00
print " \n " ;
/*
2014-06-21 16:06:59 +02:00
* Actions buttons
*/
2014-09-22 20:16:58 +02:00
2013-06-12 11:59:55 +02:00
print '<div class="tabsAction">' ;
2014-09-22 20:16:58 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been
2020-10-07 15:01:28 +02:00
// modified by hook
2021-02-25 23:00:32 +01:00
if ( empty ( $reshook )) {
if ( $user -> socid == 0 ) {
2020-10-07 15:01:28 +02:00
if ( $action != 'editdescription' && ( $action != 'presend' )) {
// Validate
if ( $object -> statut == Fichinter :: STATUS_DRAFT && ( count ( $object -> lines ) > 0 || ! empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS ))) {
if (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && $user -> rights -> ficheinter -> creer ) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && $user -> rights -> ficheinter -> ficheinter_advance -> validate )) {
2021-05-29 02:22:30 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id=' . $object -> id . '&action=validate">' . $langs -> trans ( " Validate " ) . '</a></div>' ;
} else {
print '<div class="inline-block divButActionRefused"><span class="butActionRefused" href="#" title="' . dol_escape_htmltag ( $langs -> trans ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " Validate " ) . '</span></div>' ;
2020-10-07 15:01:28 +02:00
}
}
// Modify
2021-02-25 23:00:32 +01:00
if ( $object -> statut == Fichinter :: STATUS_VALIDATED && (( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && $user -> rights -> ficheinter -> creer ) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && $user -> rights -> ficheinter -> ficheinter_advance -> unvalidate ))) {
2014-09-22 23:39:26 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id=' . $object -> id . '&action=modify">' ;
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) {
print $langs -> trans ( " Modify " );
} else {
print $langs -> trans ( " SetToDraft " );
}
2014-09-22 20:16:58 +02:00
print '</a></div>' ;
2013-06-12 11:59:55 +02:00
}
2020-09-25 08:10:48 +02:00
// Reopen
2021-02-25 23:00:32 +01:00
if ( $object -> statut >= Fichinter :: STATUS_CLOSED ) {
if ( $user -> rights -> ficheinter -> creer ) {
2020-09-25 08:10:48 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen">' . $langs -> trans ( 'Reopen' ) . '</a></div>' ;
2021-02-25 23:00:32 +01:00
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">' . $langs -> trans ( 'Reopen' ) . '</a></div>' ;
}
2020-09-25 08:10:48 +02:00
}
2014-09-22 20:16:58 +02:00
// Send
2020-04-10 01:37:04 +02:00
if ( empty ( $user -> socid )) {
2021-02-25 23:00:32 +01:00
if ( $object -> statut > Fichinter :: STATUS_DRAFT ) {
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> ficheinter -> ficheinter_advance -> send ) {
2020-04-10 01:37:04 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=presend&mode=init#formmailbeforetitle">' . $langs -> trans ( 'SendMail' ) . '</a></div>' ;
2021-02-25 23:00:32 +01:00
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">' . $langs -> trans ( 'SendMail' ) . '</a></div>' ;
}
2014-09-15 19:04:30 +02:00
}
}
2021-05-29 02:22:30 +02:00
// Create intervention model
2020-10-06 09:53:10 +02:00
if ( $conf -> global -> MAIN_FEATURES_LEVEL >= 1 && $object -> statut == Fichinter :: STATUS_DRAFT && $user -> rights -> ficheinter -> creer && ( count ( $object -> lines ) > 0 )) {
2018-05-28 16:44:49 +02:00
print '<div class="inline-block divButAction">' ;
2019-10-02 22:41:14 +02:00
print '<a class="butAction" href="' . DOL_URL_ROOT . '/fichinter/card-rec.php?id=' . $object -> id . '&action=create">' . $langs -> trans ( " ChangeIntoRepeatableIntervention " ) . '</a>' ;
2018-06-30 17:03:00 +02:00
print '</div>' ;
2018-05-28 16:44:49 +02:00
}
2014-09-22 20:16:58 +02:00
// Proposal
2021-02-25 23:00:32 +01:00
if ( $conf -> service -> enabled && ! empty ( $conf -> propal -> enabled ) && $object -> statut > Fichinter :: STATUS_DRAFT ) {
2014-09-22 20:16:58 +02:00
$langs -> load ( " propal " );
2021-02-25 23:00:32 +01:00
if ( $object -> statut < Fichinter :: STATUS_BILLED ) {
if ( $user -> rights -> propal -> creer ) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/comm/propal/card.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> socid . '">' . $langs -> trans ( " AddProp " ) . '</a></div>' ;
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '">' . $langs -> trans ( " AddProp " ) . '</a></div>' ;
}
2014-09-22 20:16:58 +02:00
}
2013-06-12 11:59:55 +02:00
}
2014-09-22 20:16:58 +02:00
// Invoicing
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> facture -> enabled ) && $object -> statut > Fichinter :: STATUS_DRAFT ) {
2014-09-22 20:16:58 +02:00
$langs -> load ( " bills " );
2021-02-25 23:00:32 +01:00
if ( $object -> statut < Fichinter :: STATUS_BILLED ) {
if ( $user -> rights -> facture -> creer ) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture/card.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> socid . '">' . $langs -> trans ( " AddBill " ) . '</a></div>' ;
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '">' . $langs -> trans ( " AddBill " ) . '</a></div>' ;
}
2014-08-15 23:20:31 +02:00
}
2014-09-22 20:16:58 +02:00
2021-02-25 23:00:32 +01:00
if ( ! empty ( $conf -> global -> FICHINTER_CLASSIFY_BILLED )) { // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
if ( $object -> statut != Fichinter :: STATUS_BILLED ) {
2014-09-22 20:16:58 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=classifybilled">' . $langs -> trans ( " InterventionClassifyBilled " ) . '</a></div>' ;
2020-05-21 15:05:19 +02:00
} else {
2014-09-22 20:16:58 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=classifyunbilled">' . $langs -> trans ( " InterventionClassifyUnBilled " ) . '</a></div>' ;
}
2013-06-12 11:59:55 +02:00
}
}
2016-09-19 13:09:50 +02:00
// Done
2021-02-25 23:00:32 +01:00
if ( empty ( $conf -> global -> FICHINTER_CLASSIFY_BILLED ) && $object -> statut > Fichinter :: STATUS_DRAFT && $object -> statut < Fichinter :: STATUS_CLOSED ) {
2016-09-19 13:09:50 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=classifydone">' . $langs -> trans ( " InterventionClassifyDone " ) . '</a></div>' ;
}
2017-06-11 10:37:58 +02:00
2016-07-01 18:12:37 +02:00
// Clone
if ( $user -> rights -> ficheinter -> creer ) {
2019-11-13 19:35:02 +01:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&socid=' . $object -> socid . '&action=clone&object=ficheinter">' . $langs -> trans ( " ToClone " ) . '</a></div>' ;
2016-07-01 18:12:37 +02:00
}
2016-08-10 11:54:49 +02:00
2014-09-22 20:16:58 +02:00
// Delete
2021-02-25 23:00:32 +01:00
if (( $object -> statut == Fichinter :: STATUS_DRAFT && $user -> rights -> ficheinter -> creer ) || $user -> rights -> ficheinter -> supprimer ) {
2020-10-01 10:50:54 +02:00
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete&token=' . newToken () . '"' ;
2014-09-22 20:16:58 +02:00
print '>' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
}
}
2013-06-12 11:59:55 +02:00
}
}
print '</div>' ;
2021-02-25 23:00:32 +01:00
if ( $action != 'presend' ) {
2013-06-12 11:59:55 +02:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
/*
* Built documents
2014-06-28 19:47:51 +02:00
*/
2019-11-13 19:35:02 +01:00
$filename = dol_sanitizeFileName ( $object -> ref );
$filedir = $conf -> ficheinter -> dir_output . " / " . $filename ;
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
$genallowed = $user -> rights -> ficheinter -> lire ;
$delallowed = $user -> rights -> ficheinter -> creer ;
2020-09-10 01:49:09 +02:00
print $formfile -> showdocuments ( 'ficheinter' , $filename , $filedir , $urlsource , $genallowed , $delallowed , $object -> model_pdf , 1 , 0 , 0 , 28 , 0 , '' , '' , '' , $soc -> default_lang );
2015-06-06 15:57:59 +02:00
// Show links to link elements
2016-08-04 11:57:37 +02:00
$linktoelem = $form -> showLinkToObjectBlock ( $object , null , array ( 'fichinter' ));
2016-08-05 15:30:28 +02:00
$somethingshown = $form -> showLinkedObjectBlock ( $object , $linktoelem );
2017-06-11 10:37:58 +02:00
2013-06-12 11:59:55 +02:00
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
2019-11-13 19:35:02 +01:00
$formactions = new FormActions ( $db );
2019-01-27 11:55:16 +01:00
$somethingshown = $formactions -> showactions ( $object , 'fichinter' , $socid , 1 );
2013-06-12 11:59:55 +02:00
print '</div></div></div>' ;
}
2017-09-17 15:38:50 +02:00
// Select mail models is same action as presend
2015-04-18 22:59:20 +02:00
if ( GETPOST ( 'modelselected' )) {
2015-04-18 17:15:36 +02:00
$action = 'presend' ;
}
2013-06-12 11:59:55 +02:00
2017-09-17 15:38:50 +02:00
// Presend form
2019-11-13 19:35:02 +01:00
$modelmail = 'fichinter_send' ;
$defaulttopic = 'SendInterventionRef' ;
2017-09-17 15:38:50 +02:00
$diroutput = $conf -> ficheinter -> dir_output ;
$trackid = 'int' . $object -> id ;
2014-07-28 02:45:58 +02:00
2017-09-17 15:38:50 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
2013-06-12 11:59:55 +02:00
}
llxFooter ();
$db -> close ();