2013-06-12 11:59:55 +02:00
< ? php
/* Copyright ( C ) 2002 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2014-10-05 05:13:46 +02:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2013-11-05 13:11:36 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
* Copyright ( C ) 2011 - 2013 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2014-09-24 13:28:59 +02:00
* Copyright ( C ) 2014 Ferran Marcet < fmarcet @ 2 byte . es >
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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
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' ;
if ( ! empty ( $conf -> projet -> enabled ))
{
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
}
if ( $conf -> contrat -> enabled )
{
require_once DOL_DOCUMENT_ROOT . " /core/class/html.formcontract.class.php " ;
require_once DOL_DOCUMENT_ROOT . " /contrat/class/contrat.class.php " ;
}
if ( ! empty ( $conf -> global -> FICHEINTER_ADDON ) && is_readable ( DOL_DOCUMENT_ROOT . " /core/modules/fichinter/mod_ " . $conf -> global -> FICHEINTER_ADDON . " .php " ))
{
require_once DOL_DOCUMENT_ROOT . " /core/modules/fichinter/mod_ " . $conf -> global -> FICHEINTER_ADDON . '.php' ;
}
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2014-07-06 21:12:16 +02:00
$langs -> load ( " bills " );
2013-06-12 11:59:55 +02:00
$langs -> load ( " companies " );
$langs -> load ( " interventions " );
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
$socid = GETPOST ( 'socid' , 'int' );
$contratid = GETPOST ( 'contratid' , 'int' );
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$mesg = GETPOST ( 'msg' , 'alpha' );
$origin = GETPOST ( 'origin' , 'alpha' );
$originid = ( GETPOST ( 'originid' , 'int' ) ? GETPOST ( 'originid' , 'int' ) : GETPOST ( 'origin_id' , 'int' )); // For backward compatibility
2014-09-04 18:41:28 +02:00
$note_public = GETPOST ( 'note_public' );
2014-09-24 13:28:59 +02:00
$lineid = GETPOST ( 'line_id' , 'int' );
2013-06-12 11:59:55 +02:00
//PDF
$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 ));
// Security check
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'ficheinter' , $id , 'fichinter' );
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
2014-10-06 07:20:58 +02:00
$hookmanager -> initHooks ( array ( 'interventioncard' , 'globalcard' ));
2013-06-12 11:59:55 +02:00
$object = new Fichinter ( $db );
$extrafields = new ExtraFields ( $db );
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2013-11-05 13:11:36 +01:00
// Load object
if ( $id > 0 || ! empty ( $ref ))
{
$ret = $object -> fetch ( $id , $ref );
if ( $ret > 0 ) $ret = $object -> fetch_thirdparty ();
if ( $ret < 0 ) dol_print_error ( '' , $object -> error );
}
2014-01-11 13:33:30 +01:00
$permissionnote = $user -> rights -> ficheinter -> creer ; // Used by the include of actions_setnotes.inc.php
2013-11-05 13:11:36 +01:00
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
2014-09-24 13:28:59 +02:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2014-09-28 03:41:32 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php' ; // Must be include, not include_once
2014-01-11 13:33:30 +01:00
2013-06-12 11:59:55 +02:00
if ( $action == 'confirm_validate' && $confirm == 'yes' && $user -> rights -> ficheinter -> creer )
{
$result = $object -> setValid ( $user );
if ( $result >= 0 )
{
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2014-02-08 02:46:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) $result = fichinter_create ( $db , $object , GETPOST ( 'model' , 'alpha' ), $outputlangs );
2013-06-12 11:59:55 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
else
{
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
}
else if ( $action == 'confirm_modify' && $confirm == 'yes' && $user -> rights -> ficheinter -> creer )
{
$result = $object -> setDraft ( $user );
if ( $result >= 0 )
{
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2014-02-08 02:46:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) $result = fichinter_create ( $db , $object , ( ! GETPOST ( 'model' , 'alpha' )) ? $object -> model : GETPOST ( 'model' , 'apha' ), $outputlangs );
2013-06-12 11:59:55 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
else
{
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
}
else if ( $action == 'add' && $user -> rights -> ficheinter -> creer )
{
$object -> socid = $socid ;
$object -> duree = GETPOST ( 'duree' , 'int' );
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> fk_contrat = GETPOST ( 'contratid' , 'int' );
$object -> author = $user -> id ;
$object -> description = GETPOST ( 'description' );
$object -> ref = $ref ;
$object -> modelpdf = GETPOST ( 'model' , 'alpha' );
$object -> note_private = GETPOST ( 'note_private' );
$object -> note_public = GETPOST ( 'note_public' );
if ( $object -> socid > 0 )
{
// If creation from another object of another module (Example: origin=propal, originid=1)
if ( ! empty ( $origin ) && ! empty ( $originid ) )
{
// Parse element/subelement (ex: project_task)
$element = $subelement = $_POST [ 'origin' ];
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , $_POST [ 'origin' ], $regs ))
{
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
// For compatibility
if ( $element == 'order' ) {
$element = $subelement = 'commande' ;
}
if ( $element == 'propal' ) {
$element = 'comm/propal' ; $subelement = 'propal' ;
}
if ( $element == 'contract' ) {
$element = $subelement = 'contrat' ;
}
$object -> origin = $origin ;
$object -> origin_id = $originid ;
// Possibility to add external linked objects with hooks
$object -> linked_objects [ $object -> origin ] = $object -> origin_id ;
if ( is_array ( $_POST [ 'other_linked_objects' ]) && ! empty ( $_POST [ 'other_linked_objects' ]))
{
$object -> linked_objects = array_merge ( $object -> linked_objects , $_POST [ 'other_linked_objects' ]);
}
2014-08-26 17:25:13 +02:00
// Extrafields
$extrafields = new ExtraFields ( $db );
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2015-02-28 04:59:27 +01:00
$array_options = $extrafields -> getOptionalsFromPost ( $extralabels );
2014-08-30 20:05:16 +02:00
2015-02-28 04:59:27 +01:00
$object -> array_options = $array_options ;
2014-08-26 17:25:13 +02:00
2013-06-12 11:59:55 +02:00
$id = $object -> create ( $user );
if ( $id > 0 )
{
dol_include_once ( '/' . $element . '/class/' . $subelement . '.class.php' );
$classname = ucfirst ( $subelement );
$srcobject = new $classname ( $db );
dol_syslog ( " Try to find source object origin= " . $object -> origin . " originid= " . $object -> origin_id . " to add lines " );
$result = $srcobject -> fetch ( $object -> origin_id );
if ( $result > 0 )
{
$srcobject -> fetch_thirdparty ();
$lines = $srcobject -> lines ;
2014-09-04 18:58:33 +02:00
if ( empty ( $lines ) && method_exists ( $srcobject , 'fetch_lines' ))
{
$srcobject -> fetch_lines ();
$lines = $srcobject -> lines ;
}
2013-06-12 11:59:55 +02:00
$fk_parent_line = 0 ;
$num = count ( $lines );
for ( $i = 0 ; $i < $num ; $i ++ )
{
$product_type = ( $lines [ $i ] -> product_type ? $lines [ $i ] -> product_type : 0 );
if ( $product_type == 1 || ! empty ( $conf -> global -> FICHINTER_PRINT_PRODUCTS )) { //only services except if config includes products
// service prédéfini
if ( $lines [ $i ] -> fk_product > 0 )
{
// Define output language
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && ! empty ( $conf -> global -> PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE ))
{
2014-03-12 01:21:18 +01:00
$prod = new Product ( $db );
$prod -> id = $lines [ $i ] -> fk_product ;
$prod -> getMultiLangs ();
2013-06-12 11:59:55 +02:00
$outputlangs = $langs ;
$newlang = '' ;
if ( empty ( $newlang ) && GETPOST ( 'lang_id' )) $newlang = GETPOST ( 'lang_id' );
if ( empty ( $newlang )) $newlang = $srcobject -> client -> default_lang ;
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
{
$label = $lines [ $i ] -> product_label ;
}
$desc = $label ;
$desc .= ' (' . $langs -> trans ( 'Quantity' ) . ': ' . $lines [ $i ] -> qty . ')' ;
}
else {
$desc = dol_htmlentitiesbr ( $lines [ $i ] -> desc );
$desc .= ' (' . $langs -> trans ( 'Quantity' ) . ': ' . $lines [ $i ] -> qty . ')' ;
}
$timearray = dol_getdate ( mktime ());
$date_intervention = dol_mktime ( 0 , 0 , 0 , $timearray [ 'mon' ], $timearray [ 'mday' ], $timearray [ 'year' ]);
if ( $product_type == 1 )
{ //service
$duration = 3600 ;
}
else
{ //product
$duration = 0 ;
}
2014-08-26 17:08:03 +02:00
$predef = '' ;
// Extrafields
$extrafieldsline = new ExtraFields ( $db );
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
2015-02-28 04:59:27 +01:00
$array_options = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline , $predef );
2014-08-30 20:05:16 +02:00
2014-08-26 17:08:03 +02:00
2013-06-12 11:59:55 +02:00
$result = $object -> addline (
$user ,
$id ,
$desc ,
$date_intervention ,
2014-08-26 17:08:03 +02:00
$duration ,
2015-02-28 04:59:27 +01:00
$array_options
2013-06-12 11:59:55 +02:00
);
if ( $result < 0 )
{
$error ++ ;
break ;
}
}
}
}
else
{
$mesg = $srcobject -> error ;
$error ++ ;
}
}
else
{
$mesg = $object -> error ;
$error ++ ;
}
}
else
{
2014-08-26 17:25:13 +02:00
// Extrafields
$extrafields = new ExtraFields ( $db );
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2015-02-28 04:59:27 +01:00
$array_options = $extrafields -> getOptionalsFromPost ( $extralabels );
2014-08-30 20:05:16 +02:00
2015-02-28 04:59:27 +01:00
$object -> array_options = $array_options ;
2014-08-30 20:05:16 +02:00
2013-06-12 11:59:55 +02:00
$result = $object -> create ( $user );
if ( $result > 0 )
{
$id = $result ; // Force raffraichissement sur fiche venant d'etre cree
}
else
{
$langs -> load ( " errors " );
2014-09-04 14:39:18 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2013-06-12 11:59:55 +02:00
$action = 'create' ;
}
}
}
else
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " ThirdParty " )) . '</div>' ;
$action = 'create' ;
}
}
else if ( $action == 'update' && $user -> rights -> ficheinter -> creer )
{
$object -> socid = $socid ;
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> fk_contrat = GETPOST ( 'contratid' , 'int' );
$object -> author = $user -> id ;
$object -> description = GETPOST ( 'description' , 'alpha' );
$object -> ref = $ref ;
$result = $object -> update ( $user );
if ( $result < 0 ) {
setEventMessage ( $object -> error , 'errors' );
}
}
/*
* Build doc
2013-11-05 13:11:36 +01:00
*/
2013-06-12 11:59:55 +02:00
else if ( $action == 'builddoc' && $user -> rights -> ficheinter -> creer ) // En get ou en post
{
$object -> fetch_lines ();
2013-09-06 13:25:45 +02:00
// Save last template used to generate document
if ( GETPOST ( 'model' )) $object -> setDocModel ( $user , GETPOST ( 'model' , 'alpha' ));
2013-06-12 11:59:55 +02:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$result = fichinter_create ( $db , $object , GETPOST ( 'model' , 'alpha' ), $outputlangs );
if ( $result <= 0 )
{
dol_print_error ( $db , $result );
exit ;
}
}
// Remove file in doc form
else if ( $action == 'remove_file' )
{
2013-11-05 13:11:36 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2013-06-12 11:59:55 +02:00
2013-11-05 13:11:36 +01:00
$object -> fetch_thirdparty ();
2013-06-12 11:59:55 +02:00
2013-11-05 13:11:36 +01:00
$langs -> load ( " other " );
$upload_dir = $conf -> ficheinter -> dir_output ;
$file = $upload_dir . '/' . GETPOST ( 'file' );
$ret = dol_delete_file ( $file , 0 , 0 , 0 , $object );
if ( $ret ) setEventMessage ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )));
else setEventMessage ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), 'errors' );
2013-06-12 11:59:55 +02:00
}
// Set into a project
else if ( $action == 'classin' && $user -> rights -> ficheinter -> creer )
{
$result = $object -> setProject ( GETPOST ( 'projectid' , 'int' ));
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
}
// Set into a contract
else if ( $action == 'setcontrat' && $user -> rights -> contrat -> creer )
{
$result = $object -> set_contrat ( $user , GETPOST ( 'contratid' , 'int' ));
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
}
else if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> ficheinter -> supprimer )
{
$result = $object -> delete ( $user );
if ( $result < 0 ) {
setEventMessage ( $object -> error , 'errors' );
}
header ( 'Location: ' . DOL_URL_ROOT . '/fichinter/list.php?leftmenu=ficheinter' );
exit ;
}
else if ( $action == 'setdescription' && $user -> rights -> ficheinter -> creer )
{
$result = $object -> set_description ( $user , GETPOST ( 'description' ));
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
}
// Add line
else if ( $action == " addline " && $user -> rights -> ficheinter -> creer )
{
if ( ! GETPOST ( 'np_desc' ))
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Description " )) . '</div>' ;
$error ++ ;
}
if ( ! GETPOST ( 'durationhour' , 'int' ) && ! GETPOST ( 'durationmin' , 'int' ))
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Duration " )) . '</div>' ;
$error ++ ;
}
2013-11-05 13:11:36 +01:00
if ( GETPOST ( 'durationhour' , 'int' ) >= 24 && GETPOST ( 'durationmin' , 'int' ) > 0 )
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorValueTooHigh " ) . '</div>' ;
$error ++ ;
}
2013-06-12 11:59:55 +02:00
if ( ! $error )
{
$db -> begin ();
$desc = GETPOST ( 'np_desc' );
$date_intervention = 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' ));
2014-08-30 20:05:16 +02:00
2014-08-26 17:08:03 +02:00
// Extrafields
$extrafieldsline = new ExtraFields ( $db );
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
2015-02-28 04:59:27 +01:00
$array_options = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline );
2014-08-26 17:08:03 +02:00
2013-06-12 11:59:55 +02:00
$result = $object -> addline (
$user ,
$id ,
$desc ,
$date_intervention ,
2014-08-26 17:08:03 +02:00
$duration ,
2015-02-28 04:59:27 +01:00
$array_options
2013-06-12 11:59:55 +02:00
);
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
if ( $result >= 0 )
{
$db -> commit ();
2014-02-08 02:46:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) fichinter_create ( $db , $object , $object -> modelpdf , $outputlangs );
2013-06-12 11:59:55 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
else
{
$mesg = $object -> error ;
$db -> rollback ();
}
}
}
// Classify Billed
else if ( $action == 'classifybilled' && $user -> rights -> ficheinter -> creer )
{
2014-08-15 23:20:31 +02:00
$result = $object -> setStatut ( 2 );
if ( $result > 0 )
{
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
else
{
2014-09-22 20:16:58 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-08-15 23:20:31 +02:00
}
}
// Classify Billed
else if ( $action == 'classifyunbilled' && $user -> rights -> ficheinter -> creer )
{
$result = $object -> setStatut ( 1 );
2013-06-12 11:59:55 +02:00
if ( $result > 0 )
{
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
else
{
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
}
/*
* Mise a jour d 'une ligne d' intervention
2014-08-15 23:20:31 +02:00
*/
2013-06-12 11:59:55 +02:00
else if ( $action == 'updateline' && $user -> rights -> ficheinter -> creer && GETPOST ( 'save' , 'alpha' ) == $langs -> trans ( " Save " ))
{
$objectline = new FichinterLigne ( $db );
2014-09-24 13:28:59 +02:00
if ( $objectline -> fetch ( $lineid ) <= 0 )
2013-06-12 11:59:55 +02:00
{
dol_print_error ( $db );
exit ;
}
if ( $object -> fetch ( $objectline -> fk_fichinter ) <= 0 )
{
dol_print_error ( $db );
exit ;
}
$object -> fetch_thirdparty ();
$desc = GETPOST ( 'np_desc' );
$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' ));
$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
$extrafieldsline = new ExtraFields ( $db );
$extralabelsline = $extrafieldsline -> fetch_name_optionals_label ( $object -> table_element_line );
2015-02-28 04:59:27 +01:00
$array_options = $extrafieldsline -> getOptionalsFromPost ( $extralabelsline );
$objectline -> array_options = $array_options ;
2014-08-26 17:08:03 +02:00
2013-06-12 11:59:55 +02:00
$result = $objectline -> update ( $user );
if ( $result < 0 )
{
dol_print_error ( $db );
exit ;
}
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2014-02-08 02:46:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) fichinter_create ( $db , $object , $object -> modelpdf , $outputlangs );
2013-06-12 11:59:55 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
/*
* Supprime une ligne d ' intervention AVEC confirmation
*/
else if ( $action == 'confirm_deleteline' && $confirm == 'yes' && $user -> rights -> ficheinter -> creer )
{
$objectline = new FichinterLigne ( $db );
2014-09-24 13:28:59 +02:00
if ( $objectline -> fetch ( $lineid ) <= 0 )
2013-06-12 11:59:55 +02:00
{
dol_print_error ( $db );
exit ;
}
$result = $objectline -> deleteline ( $user );
if ( $object -> fetch ( $objectline -> fk_fichinter ) <= 0 )
{
dol_print_error ( $db );
exit ;
}
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2014-02-08 02:46:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) fichinter_create ( $db , $object , $object -> modelpdf , $outputlangs );
2013-06-12 11:59:55 +02:00
}
/*
* Ordonnancement des lignes
*/
else if ( $action == 'up' && $user -> rights -> ficheinter -> creer )
{
2014-09-24 13:28:59 +02:00
$object -> line_up ( $lineid );
2013-06-12 11:59:55 +02:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2014-02-08 02:46:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) fichinter_create ( $db , $object , $object -> modelpdf , $outputlangs );
2014-09-24 13:28:59 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '#' . $lineid );
2013-06-12 11:59:55 +02:00
exit ;
}
else if ( $action == 'down' && $user -> rights -> ficheinter -> creer )
{
2014-09-24 13:28:59 +02:00
$object -> line_down ( $lineid );
2013-06-12 11:59:55 +02:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'alpha' )) $newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2014-02-08 02:46:05 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) fichinter_create ( $db , $object , $object -> modelpdf , $outputlangs );
2014-09-24 13:28:59 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '#' . $lineid );
2013-06-12 11:59:55 +02:00
exit ;
}
/*
* Add file in email form
*/
if ( GETPOST ( 'addfile' , 'alpha' ))
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
// Set tmp user directory TODO Use a dedicated directory for temp mails files
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
$upload_dir_tmp = $vardir . '/temp' ;
dol_add_file_process ( $upload_dir_tmp , 0 , 0 );
$action = 'presend' ;
}
/*
* Remove file in email form
*/
if ( GETPOST ( 'removedfile' , 'alpha' ))
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
// Set tmp user directory
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
$upload_dir_tmp = $vardir . '/temp' ;
// TODO Delete only files that was uploaded from email form
dol_remove_file_process ( GETPOST ( 'removedfile' , 'alpha' ), 0 );
$action = 'presend' ;
}
/*
* Send mail
*/
if ( $action == 'send' && ! GETPOST ( 'cancel' , 'alpha' ) && ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> ficheinter -> ficheinter_advance -> send ))
{
$langs -> load ( 'mails' );
2013-11-05 13:11:36 +01:00
if ( GETPOST ( 'sendto' , 'alpha' ))
2013-06-12 11:59:55 +02:00
{
2013-11-05 13:11:36 +01:00
// Le destinataire a ete fourni via le champ libre
$sendto = GETPOST ( 'sendto' , 'alpha' );
$sendtoid = 0 ;
}
elseif ( GETPOST ( 'receiver' , 'alpha' ) != '-1' )
{
// Recipient was provided from combo list
if ( GETPOST ( 'receiver' , 'alpha' ) == 'thirdparty' ) // Id of third party
2013-06-12 11:59:55 +02:00
{
2013-11-05 13:11:36 +01:00
$sendto = $object -> client -> email ;
2013-06-12 11:59:55 +02:00
$sendtoid = 0 ;
}
2013-11-05 13:11:36 +01:00
else // Id du contact
2013-06-12 11:59:55 +02:00
{
2013-11-05 13:11:36 +01:00
$sendto = $object -> client -> contact_get_property ( GETPOST ( 'receiver' ), 'email' );
$sendtoid = GETPOST ( 'receiver' , 'alpha' );
2013-06-12 11:59:55 +02:00
}
2013-11-05 13:11:36 +01:00
}
2013-06-12 11:59:55 +02:00
2013-11-05 13:11:36 +01:00
if ( dol_strlen ( $sendto ))
{
$langs -> load ( " commercial " );
2013-06-12 11:59:55 +02:00
2013-11-05 13:11:36 +01:00
$from = GETPOST ( 'fromname' , 'alpha' ) . ' <' . GETPOST ( 'frommail' , 'alpha' ) . '>' ;
$replyto = GETPOST ( 'replytoname' , 'alpha' ) . ' <' . GETPOST ( 'replytomail' , 'alpha' ) . '>' ;
$message = GETPOST ( 'message' );
$sendtocc = GETPOST ( 'sendtocc' , 'alpha' );
$deliveryreceipt = GETPOST ( 'deliveryreceipt' , 'alpha' );
2013-06-12 11:59:55 +02:00
2013-11-05 13:11:36 +01:00
if ( $action == 'send' )
{
if ( strlen ( GETPOST ( 'subject' , 'alphs' ))) $subject = GETPOST ( 'subject' , 'alpha' );
else $subject = $langs -> transnoentities ( 'Intervention' ) . ' ' . $object -> ref ;
$actiontypecode = 'AC_OTH_AUTO' ;
2014-11-02 12:32:38 +01:00
$actionmsg = $langs -> transnoentities ( 'MailSentBy' ) . ' ' . $from . ' ' . $langs -> transnoentities ( 'To' ) . ' ' . $sendto ;
2013-11-05 13:11:36 +01:00
if ( $message )
2013-06-12 11:59:55 +02:00
{
2014-11-03 21:58:14 +01:00
if ( $sendtocc ) $actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'Bcc' ) . " : " . $sendtocc );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'MailTopic' ) . " : " . $subject );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'TextUsedInTheMessageBody' ) . " : " );
$actionmsg = dol_concatdesc ( $actionmsg , $message );
2013-06-12 11:59:55 +02:00
}
2014-10-20 11:35:34 +02:00
$actionmsg2 = $langs -> transnoentities ( " InterventionSentByEMail " , $object -> ref );
2013-11-05 13:11:36 +01:00
}
2013-06-12 11:59:55 +02:00
2013-11-05 13:11:36 +01:00
// Create form object
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
2013-06-12 11:59:55 +02:00
2013-11-05 13:11:36 +01:00
$attachedfiles = $formmail -> get_attached_files ();
$filepath = $attachedfiles [ 'paths' ];
$filename = $attachedfiles [ 'names' ];
$mimetype = $attachedfiles [ 'mimes' ];
2013-06-12 11:59:55 +02:00
2014-06-28 18:43:36 +02:00
// Send by email
2013-11-05 13:11:36 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , '' , $deliveryreceipt , - 1 );
if ( $mailfile -> error )
{
$mesg = '<div class="error">' . $mailfile -> error . '</div>' ;
}
else
{
$result = $mailfile -> sendfile ();
if ( $result )
2013-06-12 11:59:55 +02:00
{
2013-11-05 13:11:36 +01:00
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $from , 2 ), $mailfile -> getValidAddress ( $sendto , 2 ));
setEventMessage ( $mesg );
$error = 0 ;
// Initialisation donnees
$object -> sendtoid = $sendtoid ;
$object -> actiontypecode = $actiontypecode ;
$object -> actionmsg = $actionmsg ;
$object -> actionmsg2 = $actionmsg2 ;
$object -> fk_element = $object -> id ;
$object -> elementtype = $object -> element ;
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $db );
$result = $interface -> run_triggers ( 'FICHINTER_SENTBYMAIL' , $object , $user , $langs , $conf );
if ( $result < 0 ) {
2014-06-14 11:42:17 +02:00
$error ++ ; $object -> errors = $interface -> errors ;
2013-11-05 13:11:36 +01:00
}
// Fin appel triggers
if ( $error )
{
dol_print_error ( $db );
}
else
{
// Redirect here
// This avoid sending mail twice if going out and then back to page
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
2013-06-12 11:59:55 +02:00
}
else
{
2013-11-05 13:11:36 +01:00
$langs -> load ( " other " );
$mesg = '<div class="error">' ;
if ( $mailfile -> error )
2013-06-12 11:59:55 +02:00
{
2013-11-05 13:11:36 +01:00
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $from , $sendto );
$mesg .= '<br>' . $mailfile -> error ;
}
else
{
$mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' ;
}
$mesg .= '</div>' ;
}
}
}
else
{
$langs -> load ( " other " );
$mesg = '<div class="error">' . $langs -> trans ( 'ErrorMailRecipientIsEmpty' ) . ' !</div>' ;
dol_syslog ( 'Recipient email is empty' );
}
2013-06-12 11:59:55 +02:00
$action = 'presend' ;
}
else if ( $action == 'update_extras' )
{
// Fill array 'array_options' with data from update form
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2013-11-05 13:11:36 +01:00
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object , GETPOST ( 'attribute' ));
if ( $ret < 0 ) $error ++ ;
2014-01-11 13:33:30 +01:00
2013-11-05 13:11:36 +01:00
if ( ! $error )
2013-06-12 11:59:55 +02:00
{
2013-11-05 13:11:36 +01:00
// Actions on extra fields (by external module or standard code)
2015-04-12 04:01:28 +02:00
// TODO le hook fait double emploi avec le trigger !!
2013-11-05 13:11:36 +01:00
$hookmanager -> initHooks ( array ( 'interventiondao' ));
$parameters = array ( 'id' => $object -> id );
$reshook = $hookmanager -> executeHooks ( 'insertExtraFields' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( empty ( $reshook ))
2013-06-12 11:59:55 +02:00
{
$result = $object -> insertExtraFields ();
if ( $result < 0 )
{
$error ++ ;
}
}
2013-11-05 13:11:36 +01:00
else if ( $reshook < 0 ) $error ++ ;
2013-06-12 11:59:55 +02:00
}
2014-01-11 13:33:30 +01:00
2013-11-05 13:11:36 +01:00
if ( $error ) $action = 'edit_extras' ;
2013-06-12 11:59:55 +02:00
}
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ) && $user -> rights -> ficheinter -> creer )
{
if ( $action == 'addcontact' )
{
if ( $result > 0 && $id > 0 )
{
$contactid = ( GETPOST ( 'userid' , 'int' ) ? GETPOST ( 'userid' , 'int' ) : GETPOST ( 'contactid' , 'int' ));
$result = $object -> add_contact ( $contactid , GETPOST ( 'type' , 'int' ), GETPOST ( 'source' , 'alpha' ));
}
if ( $result >= 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
else
{
if ( $object -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
{
$langs -> load ( " errors " );
$mesg = '<div class="error">' . $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " ) . '</div>' ;
}
else
{
$mesg = '<div class="error">' . $object -> error . '</div>' ;
}
}
}
// bascule du statut d'un contact
else if ( $action == 'swapstatut' )
{
2013-11-05 13:11:36 +01:00
$result = $object -> swapContactStatus ( GETPOST ( 'ligne' , 'int' ));
2013-06-12 11:59:55 +02:00
}
// Efface un contact
else if ( $action == 'deletecontact' )
{
$result = $object -> delete_contact ( GETPOST ( 'lineid' , 'int' ));
if ( $result >= 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
exit ;
}
else {
dol_print_error ( $db );
}
}
}
/*
* View
*/
$form = new Form ( $db );
$formfile = new FormFile ( $db );
2014-02-18 15:49:16 +01:00
if ( $conf -> contrat -> enabled )
$formcontract = new FormContract ( $db );
2013-06-12 11:59:55 +02:00
llxHeader ( '' , $langs -> trans ( " Fichinter " ));
if ( $action == 'create' )
{
/*
* Mode creation
2013-11-05 13:11:36 +01:00
* Creation d 'une nouvelle fiche d' intervention
*/
2013-06-12 11:59:55 +02:00
$soc = new Societe ( $db );
print_fiche_titre ( $langs -> trans ( " AddIntervention " ));
dol_htmloutput_mesg ( $mesg );
if ( $socid ) $res = $soc -> fetch ( $socid );
if ( GETPOST ( 'origin' ) && GETPOST ( 'originid' ))
{
// Parse element/subelement (ex: project_task)
$element = $subelement = GETPOST ( 'origin' );
if ( preg_match ( '/^([^_]+)_([^_]+)/i' , GETPOST ( 'origin' ), $regs ))
{
$element = $regs [ 1 ];
$subelement = $regs [ 2 ];
}
if ( $element == 'project' )
{
$projectid = GETPOST ( 'originid' );
}
else
{
// For compatibility
if ( $element == 'order' || $element == 'commande' ) {
$element = $subelement = 'commande' ;
}
if ( $element == 'propal' ) {
$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' ));
2014-09-04 18:58:33 +02:00
if ( empty ( $objectsrc -> lines ) && method_exists ( $objectsrc , 'fetch_lines' ))
{
$objectsrc -> fetch_lines ();
$lines = $objectsrc -> lines ;
}
2013-06-12 11:59:55 +02:00
$objectsrc -> fetch_thirdparty ();
$projectid = ( ! empty ( $objectsrc -> fk_project ) ? $objectsrc -> fk_project : '' );
$soc = $objectsrc -> client ;
2014-09-04 18:41:28 +02:00
$note_private = ( ! empty ( $objectsrc -> note ) ? $objectsrc -> note : ( ! empty ( $objectsrc -> note_private ) ? $objectsrc -> note_private : GETPOST ( 'note_private' )));
$note_public = ( ! empty ( $objectsrc -> note_public ) ? $objectsrc -> note_public : GETPOST ( 'note_public' ));
2013-06-12 11:59:55 +02:00
// Object source contacts list
$srccontactslist = $objectsrc -> liste_contact ( - 1 , 'external' , 1 );
}
}
else {
$projectid = GETPOST ( 'projectid' , 'int' );
}
if ( ! $conf -> global -> FICHEINTER_ADDON )
{
dol_print_error ( $db , $langs -> trans ( " Error " ) . " " . $langs -> trans ( " Error_FICHEINTER_ADDON_NotDefined " ));
exit ;
}
$object -> date = dol_now ();
$obj = $conf -> global -> FICHEINTER_ADDON ;
$obj = " mod_ " . $obj ;
//$modFicheinter = new $obj;
//$numpr = $modFicheinter->getNextValue($soc, $object);
if ( $socid > 0 )
{
$soc -> fetch ( $socid );
print '<form name="fichinter" action="' . $_SERVER [ 'PHP_SELF' ] . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<table class="border" width="100%">' ;
print '<input type="hidden" name="socid" value=' . $soc -> id . '>' ;
print '<tr><td class="fieldrequired">' . $langs -> trans ( " ThirdParty " ) . '</td><td>' . $soc -> getNomUrl ( 1 ) . '</td></tr>' ;
print '<input type="hidden" name="action" value="add">' ;
// Ref
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Ref' ) . '</td><td colspan="2">' . $langs -> trans ( " Draft " ) . '</td></tr>' ;
// Description (must be a textarea and not html must be allowed (used in list view)
print '<tr><td valign="top">' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td>' ;
2014-09-04 18:41:28 +02:00
print '<textarea name="description" cols="80" rows="' . ROWS_3 . '">' . GETPOST ( 'description' ) . '</textarea>' ;
2013-06-12 11:59:55 +02:00
print '</td></tr>' ;
// Project
if ( ! empty ( $conf -> projet -> enabled ))
{
2013-06-14 22:33:01 +02:00
$formproject = new FormProjets ( $db );
2014-01-11 13:33:30 +01:00
2013-06-12 11:59:55 +02:00
$langs -> load ( " project " );
print '<tr><td valign="top">' . $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
if ( $societe -> fournisseur == 1 )
$numprojet = select_projects ( - 1 , $_POST [ " projectid " ], 'projectid' );
else
$numprojet = select_projects ( $societe -> id , $_POST [ " projectid " ], 'projectid' );
*/
2013-06-14 22:33:01 +02:00
$numprojet = $formproject -> select_projects ( $soc -> id , GETPOST ( 'projectid' , 'int' ), 'projectid' );
2013-06-12 11:59:55 +02:00
if ( $numprojet == 0 )
{
2014-09-18 21:18:25 +02:00
print ' <a href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $soc -> id . '&action=create">' . $langs -> trans ( " AddProject " ) . '</a>' ;
2013-06-12 11:59:55 +02:00
}
print '</td></tr>' ;
}
// Contract
if ( $conf -> contrat -> enabled )
{
2014-03-01 15:21:11 +01:00
$langs -> load ( " contracts " );
2013-06-12 11:59:55 +02:00
print '<tr><td valign="top">' . $langs -> trans ( " Contract " ) . '</td><td>' ;
$numcontrat = $formcontract -> select_contract ( $soc -> id , GETPOST ( 'contratid' , 'int' ), 'contratid' , 0 , 1 );
if ( $numcontrat == 0 )
{
2014-09-18 21:18:25 +02:00
print ' <a href="' . DOL_URL_ROOT . '/contrat/card.php?socid=' . $soc -> id . '&action=create">' . $langs -> trans ( " AddContract " ) . '</a>' ;
2013-06-12 11:59:55 +02:00
}
print '</td></tr>' ;
}
// Model
print '<tr>' ;
print '<td>' . $langs -> trans ( " DefaultModel " ) . '</td>' ;
print '<td colspan="2">' ;
$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="border" valign="top">' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
print '<td valign="top" colspan="2">' ;
$doleditor = new DolEditor ( 'note_public' , $note_public , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , 70 );
print $doleditor -> Create ( 1 );
//print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
print '</td></tr>' ;
// Private note
if ( ! empty ( $user -> societe_id ))
{
print '<tr>' ;
print '<td class="border" valign="top">' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
print '<td valign="top" colspan="2">' ;
$doleditor = new DolEditor ( 'note_private' , $note_private , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , 70 );
print $doleditor -> Create ( 1 );
//print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
print '</td></tr>' ;
}
// Other attributes
$parameters = array ( 'colspan' => ' colspan="2"' );
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
if ( empty ( $reshook ) && ! empty ( $extrafields -> attribute_label ))
{
print $object -> showOptionals ( $extrafields , 'edit' );
}
// Show link to origin object
if ( ! empty ( $origin ) && ! empty ( $originid ) && is_object ( $objectsrc ))
{
$newclassname = $classname ;
if ( $newclassname == 'Propal' ) $newclassname = 'CommercialProposal' ;
print '<tr><td>' . $langs -> trans ( $newclassname ) . '</td><td colspan="2">' . $objectsrc -> getNomUrl ( 1 ) . '</td></tr>' ;
}
print '</table>' ;
if ( is_object ( $objectsrc ))
{
print '<input type="hidden" name="origin" value="' . $objectsrc -> element . '">' ;
print '<input type="hidden" name="originid" value="' . $objectsrc -> id . '">' ;
}
2014-11-25 20:13:43 +01:00
print '<br><div class="center">' ;
2013-06-12 11:59:55 +02:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " CreateDraftIntervention " ) . '">' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2013-06-12 11:59:55 +02:00
print '</form>' ;
}
else
{
print '<form name="fichinter" action="' . $_SERVER [ 'PHP_SELF' ] . '" method="POST">' ;
print '<table class="border" width="100%">' ;
print '<tr><td class="fieldrequired">' . $langs -> trans ( " ThirdParty " ) . '</td><td>' ;
print $form -> select_company ( '' , 'socid' , '' , 1 , 1 );
print '</td></tr>' ;
print '</table>' ;
2014-11-25 20:13:43 +01:00
print '<br><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 " ) . '">' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2013-06-12 11:59:55 +02:00
print '</form>' ;
}
}
else if ( $id > 0 || ! empty ( $ref ))
{
/*
* Affichage en mode visu
*/
$object -> fetch ( $id , $ref );
$object -> fetch_thirdparty ();
$soc = new Societe ( $db );
$soc -> fetch ( $object -> socid );
dol_htmloutput_mesg ( $mesg );
$head = fichinter_prepare_head ( $object );
dol_fiche_head ( $head , 'card' , $langs -> trans ( " InterventionCard " ), 0 , 'intervention' );
2014-09-24 17:43:38 +02:00
$formconfirm = '' ;
2014-10-20 23:37:28 +02:00
// Confirm deletion of intervention
2013-06-12 11:59:55 +02:00
if ( $action == 'delete' )
{
2014-09-24 13:28:59 +02: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
2013-06-12 11:59:55 +02:00
if ( $action == 'validate' )
{
// on verifie si l'objet est en numerotation provisoire
$ref = substr ( $object -> ref , 1 , 4 );
if ( $ref == 'PROV' )
{
$numref = $object -> getNextNumRef ( $soc );
if ( empty ( $numref ))
{
$error ++ ;
2014-07-20 01:43:46 +02:00
setEventMessage ( $object -> error , 'errors' );
2013-06-12 11:59:55 +02:00
}
}
else
{
$numref = $object -> ref ;
}
$text = $langs -> trans ( 'ConfirmValidateIntervention' , $numref );
2014-10-20 23:37:28 +02: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
2013-06-12 11:59:55 +02:00
if ( $action == 'modify' )
{
2014-09-24 13:28:59 +02: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
}
2014-10-20 23:37:28 +02:00
// Confirm deletion of line
2013-06-12 11:59:55 +02:00
if ( $action == 'ask_deleteline' )
{
2014-09-24 13:28:59 +02: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
if ( ! $formconfirm )
{
2014-09-24 13:28:59 +02:00
$parameters = array ( '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
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
2014-07-06 21:12:16 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="POST" name="formfichinter">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
if ( $action == 'edit_extras' ) print '<input type="hidden" name="action" value="update_extras">' ;
if ( $action == 'contrat' ) print '<input type="hidden" name="action" value="setcontrat">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2013-06-12 11:59:55 +02:00
print '<table class="border" width="100%">' ;
$linkback = '<a href="' . DOL_URL_ROOT . '/fichinter/list.php' . ( ! empty ( $socid ) ? '?socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
// Ref
2014-09-28 02:46:20 +02:00
print '<tr><td width="25%">' . $langs -> trans ( " Ref " ) . '</td><td colspan="3">' ;
2013-06-12 11:59:55 +02:00
print $form -> showrefnav ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' );
print '</td></tr>' ;
// Third party
2014-09-28 02:46:20 +02:00
print " <tr><td> " . $langs -> trans ( " Company " ) . '</td><td colspan="3">' . $object -> client -> getNomUrl ( 1 ) . " </td></tr> " ;
2013-06-12 11:59:55 +02:00
2014-09-04 14:39:18 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS ))
{
// Duration
print '<tr><td>' . $langs -> trans ( " TotalDuration " ) . '</td>' ;
2014-09-28 02:46:20 +02:00
print '<td colspan="3">' . convertSecondToTime ( $object -> duree , 'all' , $conf -> global -> MAIN_DURATION_OF_WORKDAY ) . '</td>' ;
2014-09-04 14:39:18 +02:00
print '</tr>' ;
}
2013-06-12 11:59:55 +02:00
// Description (must be a textarea and not html must be allowed (used in list view)
print '<tr><td valign="top">' ;
print $form -> editfieldkey ( " Description " , 'description' , $object -> description , $object , $user -> rights -> ficheinter -> creer , 'textarea' );
print '</td><td colspan="3">' ;
print $form -> editfieldval ( " Description " , 'description' , $object -> description , $object , $user -> rights -> ficheinter -> creer , 'textarea:8:80' );
print '</td>' ;
print '</tr>' ;
// Project
if ( ! empty ( $conf -> projet -> enabled ))
{
$langs -> load ( 'projects' );
print '<tr>' ;
print '<td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'Project' );
print '</td>' ;
if ( $action != 'classify' )
{
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=classify&id=' . $object -> id . '">' ;
print img_edit ( $langs -> trans ( 'SetProject' ), 1 );
print '</a></td>' ;
}
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $action == 'classify' )
{
2015-01-30 19:57:38 +01:00
$form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'projectid' , 0 , 0 , 1 );
2013-06-12 11:59:55 +02:00
}
else
{
2015-01-30 19:57:38 +01:00
$form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 );
2013-06-12 11:59:55 +02:00
}
print '</td>' ;
print '</tr>' ;
}
// Contrat
if ( $conf -> contrat -> enabled )
{
$langs -> load ( 'contrat' );
print '<tr>' ;
print '<td>' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'Contract' );
print '</td>' ;
if ( $action != 'contrat' )
{
print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=contrat&id=' . $object -> id . '">' ;
print img_edit ( $langs -> trans ( 'SetContract' ), 1 );
print '</a></td>' ;
}
print '</tr></table>' ;
print '</td><td colspan="3">' ;
if ( $action == 'contrat' )
{
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">' ;
print '<tr><td>' ;
$htmlcontract = new Formcontract ( $db );
//print "$socid,$selected,$htmlname";
$htmlcontract -> select_contract ( $object -> socid , $object -> fk_contrat , 'contratid' );
print '</td>' ;
print '<td align="left"><input type="submit" class="button" value="' . $langs -> trans ( " Modify " ) . '"></td>' ;
2014-07-06 21:12:16 +02:00
print '</tr></table>' ;
2013-06-12 11:59:55 +02:00
}
else
{
if ( $object -> fk_contrat )
{
$contratstatic = new Contrat ( $db );
$contratstatic -> fetch ( $object -> fk_contrat );
2014-09-18 21:18:25 +02:00
//print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
2013-06-12 11:59:55 +02:00
print $contratstatic -> getNomUrl ( 0 , '' , 1 );
}
else
{
print " " ;
}
}
print '</td>' ;
print '</tr>' ;
}
// Statut
2014-09-28 02:46:20 +02:00
print '<tr><td>' . $langs -> trans ( " Status " ) . '</td><td colspan="3">' . $object -> getLibStatut ( 4 ) . '</td></tr>' ;
2013-06-12 11:59:55 +02:00
2014-10-14 17:00:06 +02:00
// Other attributes
$cols = 3 ;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2013-06-12 11:59:55 +02:00
2014-08-15 21:18:56 +02:00
print " </table> " ;
2014-07-08 01:12:55 +02:00
2014-07-06 21:12:16 +02:00
print '</form>' ;
2013-06-12 11:59:55 +02:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ))
{
$blocname = 'contacts' ;
$title = $langs -> trans ( 'ContactsAddresses' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB ))
{
$blocname = 'notes' ;
$title = $langs -> trans ( 'Notes' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2014-08-15 23:20:31 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS ))
{
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" name="addinter" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
if ( $action == 'editline' )
2013-06-12 11:59:55 +02:00
{
2014-08-15 23:20:31 +02:00
print '<input type="hidden" name="action" value="updateline">' ;
print '<input type="hidden" name="line_id" value="' . GETPOST ( 'line_id' , 'int' ) . '">' ;
2013-06-12 11:59:55 +02:00
}
2014-08-15 23:20:31 +02:00
else
{
print '<input type="hidden" name="action" value="addline">' ;
}
// Intervention lines
$sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,' ;
$sql .= ' ft.date as date_intervention' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'fichinterdet as ft' ;
$sql .= ' WHERE ft.fk_fichinter = ' . $object -> id ;
2014-12-28 13:20:51 +01:00
if ( ! empty ( $conf -> global -> FICHINTER_HIDE_EMPTY_DURATION ))
$sql .= ' AND ft.duree <> 0' ;
2014-08-15 23:20:31 +02:00
$sql .= ' ORDER BY ft.rang ASC, ft.rowid' ;
$resql = $db -> query ( $sql );
if ( $resql )
2013-06-12 11:59:55 +02:00
{
2014-08-15 23:20:31 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2013-06-12 11:59:55 +02:00
2014-08-15 23:20:31 +02:00
if ( $num )
2013-06-12 11:59:55 +02:00
{
2014-08-15 23:20:31 +02:00
print '<br>' ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Description' ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Duration' ) . '</td>' ;
print '<td width="48" colspan="3"> </td>' ;
print " </tr> \n " ;
}
$var = true ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
2013-06-12 11:59:55 +02:00
2014-08-15 23:20:31 +02:00
// Ligne en mode visu
if ( $action != 'editline' || GETPOST ( 'line_id' , 'int' ) != $objp -> rowid )
{
print '<tr ' . $bc [ $var ] . '>' ;
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
print '<td align="center" width="150">' . dol_print_date ( $db -> jdate ( $objp -> date_intervention ), 'dayhour' ) . '</td>' ;
2013-06-12 11:59:55 +02:00
2014-08-15 23:20:31 +02:00
// Duration
print '<td align="right" width="150">' . 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
2014-08-15 23:20:31 +02:00
// Icone d'edition et suppression
if ( $object -> statut == 0 && $user -> rights -> ficheinter -> creer )
2013-06-12 11:59:55 +02:00
{
print '<td align="center">' ;
2014-08-15 23:20:31 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=editline&line_id=' . $objp -> rowid . '#' . $objp -> rowid . '">' ;
print img_edit ();
print '</a>' ;
print '</td>' ;
print '<td align="center">' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=ask_deleteline&line_id=' . $objp -> rowid . '">' ;
print img_delete ();
print '</a></td>' ;
if ( $num > 1 )
2013-06-12 11:59:55 +02:00
{
2014-08-15 23:20:31 +02:00
print '<td align="center">' ;
if ( $i > 0 )
{
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=up&line_id=' . $objp -> rowid . '">' ;
print img_up ();
print '</a>' ;
}
if ( $i < $num - 1 )
{
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=down&line_id=' . $objp -> rowid . '">' ;
print img_down ();
print '</a>' ;
}
print '</td>' ;
2013-06-12 11:59:55 +02:00
}
}
2014-08-15 23:20:31 +02:00
else
{
print '<td colspan="3"> </td>' ;
}
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
2014-08-26 17:25:13 +02:00
$extrafieldsline = new ExtraFields ( $db );
$extralabelslines = $extrafieldsline -> fetch_name_optionals_label ( $line -> table_element );
2014-08-30 20:05:16 +02:00
2014-08-26 17:25:13 +02:00
$line -> fetch_optionals ( $line -> rowid , $extralabelslines );
2014-08-30 20:05:16 +02:00
2014-08-26 17:25:13 +02:00
print $line -> showOptionals ( $extrafieldsline , 'view' , array ( 'style' => $bc [ $var ], 'colspan' => 5 ));
2014-08-30 20:05:16 +02:00
2013-06-12 11:59:55 +02:00
}
2014-08-15 23:20:31 +02:00
// Line in update mode
if ( $object -> statut == 0 && $action == 'editline' && $user -> rights -> ficheinter -> creer && GETPOST ( 'line_id' , 'int' ) == $objp -> rowid )
2013-06-12 11:59:55 +02:00
{
2014-08-15 23:20:31 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
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' ;
$doleditor = new DolEditor ( 'np_desc' , $objp -> description , '' , 164 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_DETAILS , ROWS_2 , 70 );
$doleditor -> Create ();
print '</td>' ;
// Date d'intervention
print '<td align="center" class="nowrap">' ;
$form -> select_date ( $db -> jdate ( $objp -> date_intervention ), 'di' , 1 , 1 , 0 , " date_intervention " );
print '</td>' ;
// Duration
print '<td align="right">' ;
2014-12-14 17:04:56 +01:00
$selectmode = 'select' ;
if ( ! empty ( $conf -> global -> INTERVENTION_ADDLINE_FREEDUREATION )) $selectmode = 'text' ;
$form -> select_duration ( 'duration' , $objp -> duree , $selectmode );
2014-08-15 23:20:31 +02:00
print '</td>' ;
print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="' . $langs -> trans ( " Save " ) . '">' ;
print '<br><input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"></td>' ;
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
2014-08-26 17:25:13 +02:00
$extrafieldsline = new ExtraFields ( $db );
$extralabelslines = $extrafieldsline -> fetch_name_optionals_label ( $line -> table_element );
$line -> fetch_optionals ( $line -> rowid , $extralabelslines );
2014-08-30 20:05:16 +02:00
2014-08-26 17:25:13 +02:00
print $line -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bc [ $var ], 'colspan' => 5 ));
2014-08-30 20:05:16 +02:00
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
if ( $object -> statut == 0 && $user -> rights -> ficheinter -> creer && $action <> 'editline' && empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS ))
2013-06-12 11:59:55 +02:00
{
2014-08-15 23:20:31 +02:00
if ( ! $num ) print '<br><table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2013-06-12 11:59:55 +02:00
print '<td>' ;
2014-08-15 23:20:31 +02:00
print '<a name="add"></a>' ; // ancre
print $langs -> trans ( 'Description' ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Duration' ) . '</td>' ;
print '<td colspan="4"> </td>' ;
print " </tr> \n " ;
$var = false ;
2013-06-12 11:59:55 +02:00
2014-08-15 23:20:31 +02:00
print '<tr ' . $bc [ $var ] . " > \n " ;
print '<td>' ;
// editeur wysiwyg
2013-06-12 11:59:55 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2014-08-15 23:20:31 +02:00
$doleditor = new DolEditor ( 'np_desc' , GETPOST ( 'np_desc' , 'alpha' ), '' , 100 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_DETAILS , ROWS_2 , 70 );
2013-06-12 11:59:55 +02:00
$doleditor -> Create ();
print '</td>' ;
2014-08-15 23:20:31 +02:00
// Date intervention
2013-06-12 11:59:55 +02:00
print '<td align="center" class="nowrap">' ;
2014-08-15 23:20:31 +02:00
$now = dol_now ();
$timearray = dol_getdate ( $now );
if ( ! GETPOST ( 'diday' , 'int' )) $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' ));
$form -> select_date ( $timewithnohour , 'di' , 1 , 1 , 0 , " addinter " );
2013-06-12 11:59:55 +02:00
print '</td>' ;
// Duration
print '<td align="right">' ;
2014-08-15 23:20:31 +02:00
$selectmode = 'select' ;
if ( ! empty ( $conf -> global -> INTERVENTION_ADDLINE_FREEDUREATION )) $selectmode = 'text' ;
2015-04-18 11:25:15 +02:00
$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>' ;
2014-08-15 23:20:31 +02:00
print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="' . $langs -> trans ( 'Add' ) . '" name="addline"></td>' ;
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
2014-08-26 12:11:34 +02:00
$extrafieldsline = new ExtraFields ( $db );
$extralabelslines = $extrafieldsline -> fetch_name_optionals_label ( $lineadd -> table_element );
2014-08-30 20:05:16 +02:00
2014-08-26 17:25:13 +02:00
print $lineadd -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bc [ $var ], 'colspan' => 5 ));
2014-08-30 20:05:16 +02:00
2014-08-15 23:20:31 +02:00
if ( ! $num ) print '</table>' ;
2013-06-12 11:59:55 +02:00
}
2014-08-15 23:20:31 +02:00
if ( $num ) print '</table>' ;
2013-06-12 11:59:55 +02:00
}
2014-08-15 23:20:31 +02:00
else
2013-06-12 11:59:55 +02:00
{
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 " ;
}
2013-06-12 11:59:55 +02:00
2014-08-15 23:20:31 +02:00
dol_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
// modified by hook
if ( empty ( $reshook ))
2013-06-12 11:59:55 +02:00
{
2014-09-22 20:16:58 +02:00
if ( $user -> societe_id == 0 )
2013-06-12 11:59:55 +02:00
{
2014-09-22 20:16:58 +02:00
if ( $action != 'editdescription' && ( $action != 'presend' ))
2013-06-12 11:59:55 +02:00
{
2014-09-22 20:16:58 +02:00
// Validate
if ( $object -> statut == 0 && $user -> rights -> ficheinter -> creer && ( count ( $object -> lines ) > 0 || ! empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )))
{
2014-09-22 23:39:26 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id=' . $object -> id . '&action=validate"' ;
2014-10-20 23:37:28 +02:00
print '>' . $langs -> trans ( " Validate " ) . '</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
// Modify
if ( $object -> statut == 1 && $user -> rights -> ficheinter -> creer )
2013-06-12 11:59:55 +02:00
{
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">' ;
2014-09-22 20:16:58 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) print $langs -> trans ( " Modify " );
else print $langs -> trans ( " SetToDraft " );
print '</a></div>' ;
2013-06-12 11:59:55 +02:00
}
2014-09-22 20:16:58 +02:00
// Send
if ( $object -> statut > 0 )
2014-09-15 19:04:30 +02:00
{
2014-09-22 20:16:58 +02:00
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || $user -> rights -> ficheinter -> ficheinter_advance -> send )
2014-09-15 19:04:30 +02:00
{
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=presend&mode=init">' . $langs -> trans ( 'SendByMail' ) . '</a></div>' ;
2014-09-15 19:04:30 +02:00
}
2014-09-22 20:16:58 +02:00
else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs -> trans ( 'SendByMail' ) . '</a></div>' ;
2014-09-15 19:04:30 +02:00
}
2014-09-22 20:16:58 +02:00
// Event agenda
if ( ! empty ( $conf -> global -> FICHINTER_ADDLINK_TO_EVENT ))
2014-06-28 19:47:51 +02:00
{
2014-09-22 20:16:58 +02:00
if ( ! empty ( $conf -> agenda -> enabled ) && $object -> statut > 0 )
{
$langs -> load ( " agenda " );
if ( $object -> statut < 2 )
{
2014-09-22 23:39:26 +02:00
if ( $user -> rights -> agenda -> myactions -> create ) print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> socid . '&backtopage=' . urlencode ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id ) . '">' . $langs -> trans ( " AddEvent " ) . '</a></div>' ;
2014-09-22 20:16:58 +02:00
else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '">' . $langs -> trans ( " AddEvent " ) . '</a></div>' ;
}
}
2014-06-28 19:47:51 +02:00
}
2014-09-22 20:16:58 +02:00
// Proposal
if ( ! empty ( $conf -> propal -> enabled ) && $object -> statut > 0 )
2013-06-12 11:59:55 +02:00
{
2014-09-22 20:16:58 +02:00
$langs -> load ( " propal " );
if ( $object -> statut < 2 )
{
if ( $user -> rights -> propal -> creer ) print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/comm/propal.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" href="#" title="' . $langs -> trans ( " NotEnoughPermissions " ) . '">' . $langs -> trans ( " AddProp " ) . '</a></div>' ;
}
2013-06-12 11:59:55 +02:00
}
2014-09-22 20:16:58 +02:00
// Invoicing
if ( ! empty ( $conf -> facture -> enabled ) && $object -> statut > 0 )
2013-06-12 11:59:55 +02:00
{
2014-09-22 20:16:58 +02:00
$langs -> load ( " bills " );
if ( $object -> statut < 2 )
2013-06-12 11:59:55 +02:00
{
2014-10-05 05:13:46 +02:00
if ( $user -> rights -> facture -> creer ) print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture.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" 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
if ( ! empty ( $conf -> global -> FICHINTER_CLASSIFY_BILLED ))
2014-08-15 23:20:31 +02:00
{
2014-09-22 20:16:58 +02:00
if ( $object -> statut != 2 )
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=classifybilled">' . $langs -> trans ( " InterventionClassifyBilled " ) . '</a></div>' ;
}
else
{
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
}
}
2014-09-22 20:16:58 +02:00
// Delete
if (( $object -> statut == 0 && $user -> rights -> ficheinter -> creer ) || $user -> rights -> ficheinter -> supprimer )
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete"' ;
print '>' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
}
2013-06-12 11:59:55 +02:00
2014-09-22 20:16:58 +02:00
}
2013-06-12 11:59:55 +02:00
}
}
print '</div>' ;
print '<br>' ;
if ( $action != 'presend' )
{
print '<div class="fichecenter"><div class="fichehalfleft">' ;
//print '<table width="100%"><tr><td width="50%" valign="top">';
/*
* Built documents
2014-06-28 19:47:51 +02:00
*/
2013-06-12 11:59:55 +02:00
$filename = dol_sanitizeFileName ( $object -> ref );
$filedir = $conf -> ficheinter -> dir_output . " / " . $object -> ref ;
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
$genallowed = $user -> rights -> ficheinter -> creer ;
$delallowed = $user -> rights -> ficheinter -> supprimer ;
$genallowed = 1 ;
$delallowed = 1 ;
$var = true ;
//print "<br>\n";
$somethingshown = $formfile -> show_documents ( 'ficheinter' , $filename , $filedir , $urlsource , $genallowed , $delallowed , $object -> modelpdf , 1 , 0 , 0 , 28 , 0 , '' , '' , '' , $soc -> default_lang );
/*
* Linked object block
*/
$somethingshown = $object -> showLinkedObjectBlock ();
//print '</td><td valign="top" width="50%">';
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
$formactions = new FormActions ( $db );
$somethingshown = $formactions -> showactions ( $object , 'fichinter' , $socid );
print '</div></div></div>' ;
//print "</td></tr></table>\n";
}
/*
* Action presend
2014-06-28 19:47:51 +02:00
*/
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
if ( $action == 'presend' )
{
$ref = dol_sanitizeFileName ( $object -> ref );
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
$fileparams = dol_most_recent_file ( $conf -> ficheinter -> dir_output . '/' . $ref , preg_quote ( $ref , '/' ));
$file = $fileparams [ 'fullname' ];
2014-06-28 18:43:36 +02:00
2014-06-18 09:59:15 +02:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $_REQUEST [ 'lang_id' ]))
$newlang = $_REQUEST [ 'lang_id' ];
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ))
$newlang = $object -> client -> default_lang ;
2013-06-12 11:59:55 +02:00
2014-07-28 02:45:58 +02:00
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( '' , $conf );
$outputlangs -> setDefaultLang ( $newlang );
$outputlangs -> load ( 'interventions' );
}
2013-06-12 11:59:55 +02:00
// Build document if it not exists
if ( ! $file || ! is_readable ( $file ))
{
$result = fichinter_create ( $db , $object , GETPOST ( 'model' ) ? GETPOST ( 'model' ) : $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
if ( $result <= 0 )
{
dol_print_error ( $db , $result );
exit ;
}
$fileparams = dol_most_recent_file ( $conf -> ficheinter -> dir_output . '/' . $ref , preg_quote ( $ref , '/' ));
$file = $fileparams [ 'fullname' ];
}
print '<br>' ;
print_titre ( $langs -> trans ( 'SendInterventionByMail' ));
// Create form object
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
$formmail = new FormMail ( $db );
2014-06-18 09:59:15 +02:00
$formmail -> param [ 'langsmodels' ] = ( empty ( $newlang ) ? $langs -> defaultlang : $newlang );
2013-06-12 11:59:55 +02:00
$formmail -> fromtype = 'user' ;
$formmail -> fromid = $user -> id ;
$formmail -> fromname = $user -> getFullName ( $langs );
$formmail -> frommail = $user -> email ;
$formmail -> withfrom = 1 ;
$liste = array ();
foreach ( $object -> thirdparty -> thirdparty_and_contact_email_array ( 1 ) as $key => $value ) $liste [ $key ] = $value ;
2013-09-05 18:06:51 +02:00
$formmail -> withto = GETPOST ( " sendto " ) ? GETPOST ( " sendto " ) : $liste ;
2013-06-12 11:59:55 +02:00
$formmail -> withtocc = $liste ;
$formmail -> withtoccc = $conf -> global -> MAIN_EMAIL_USECCC ;
2014-07-28 02:45:58 +02:00
$formmail -> withtopic = $outputlangs -> trans ( 'SendInterventionRef' , '__FICHINTERREF__' );
2013-06-12 11:59:55 +02:00
$formmail -> withfile = 2 ;
$formmail -> withbody = 1 ;
$formmail -> withdeliveryreceipt = 1 ;
$formmail -> withcancel = 1 ;
// Tableau des substitutions
$formmail -> substit [ '__FICHINTERREF__' ] = $object -> ref ;
$formmail -> substit [ '__SIGNATURE__' ] = $user -> signature ;
$formmail -> substit [ '__PERSONALIZED__' ] = '' ;
$formmail -> substit [ '__CONTACTCIVNAME__' ] = '' ;
//Find the good contact adress
$custcontact = '' ;
$contactarr = array ();
$contactarr = $object -> liste_contact ( - 1 , 'external' );
if ( is_array ( $contactarr ) && count ( $contactarr ) > 0 ) {
foreach ( $contactarr as $contact ) {
if ( $contact [ 'libelle' ] == $langs -> trans ( 'TypeContact_fichinter_external_CUSTOMER' )) {
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
$contactstatic = new Contact ( $db );
$contactstatic -> fetch ( $contact [ 'id' ]);
$custcontact = $contactstatic -> getFullName ( $langs , 1 );
}
}
if ( ! empty ( $custcontact )) {
$formmail -> substit [ '__CONTACTCIVNAME__' ] = $custcontact ;
}
}
// Tableau des parametres complementaires
$formmail -> param [ 'action' ] = 'send' ;
$formmail -> param [ 'models' ] = 'fichinter_send' ;
2015-04-18 17:15:36 +02:00
$formmail -> param [ 'models_id' ] = GETPOST ( 'modelmailselected' , 'int' );
2013-06-12 11:59:55 +02:00
$formmail -> param [ 'fichinter_id' ] = $object -> id ;
$formmail -> param [ 'returnurl' ] = $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id ;
// Init list of files
if ( GETPOST ( " mode " ) == 'init' )
{
$formmail -> clear_attached_files ();
$formmail -> add_attached_files ( $file , basename ( $file ), dol_mimetype ( $file ));
}
2014-02-19 20:23:02 +01:00
print $formmail -> get_form ();
2013-06-12 11:59:55 +02:00
print '<br>' ;
}
}
llxFooter ();
$db -> close ();