2008-08-06 16:50:06 +02:00
< ? php
2017-07-12 15:52:58 +02:00
/* Copyright ( C ) 2000 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2017-02-09 05:58:39 +01:00
* Copyright ( C ) 2003 Jean - Louis Bergamo < jlb @ j1b . org >
* Copyright ( C ) 2004 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2017-07-12 15:52:58 +02:00
* Copyright ( C ) 2004 Christophe Combelles < ccomb @ free . fr >
* Copyright ( C ) 2005 - 2017 Regis Houssin < regis . houssin @ capnetworks . com >
2017-02-09 05:58:39 +01:00
* Copyright ( C ) 2008 Raphael Bertrand ( Resultic ) < raphael . bertrand @ resultic . fr >
* Copyright ( C ) 2010 - 2016 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2013 - 2017 Alexandre Spangaro < aspangaro @ zendsi . com >
2017-07-12 15:52:58 +02:00
* Copyright ( C ) 2014 Cédric GROSS < c . gross @ kreiz - it . fr >
2017-02-09 05:58:39 +01:00
* Copyright ( C ) 2014 - 2015 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2008-08-06 16:50:06 +02: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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2008-08-06 16:50:06 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-08-01 01:24:38 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2008-08-06 16:50:06 +02:00
* or see http :// www . gnu . org /
*/
/**
2011-10-24 12:59:44 +02:00
* \file htdocs / core / lib / functions . lib . php
2008-11-16 02:09:04 +01:00
* \brief A set of functions for Dolibarr
* This file contains all frequently used functions .
2008-08-06 16:50:06 +02:00
*/
2014-07-18 11:18:25 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/json.lib.php' ;
2011-11-05 03:15:35 +01:00
2017-12-19 00:15:22 +01:00
2011-12-27 00:07:42 +01:00
/**
2011-12-28 01:19:52 +01:00
* Function to return value of a static property when class
* name is dynamically defined ( not hard coded ) .
* This is because $myclass :: $myvar works from PHP 5.3 . 0 + only
2011-12-29 23:50:02 +01:00
*
2011-12-28 01:19:52 +01:00
* @ param string $class Class name
* @ param string $member Name of property
2013-11-07 21:12:48 +01:00
* @ return mixed Return value of static property
2015-04-23 23:21:06 +02:00
* @ deprecated Dolibarr now requires 5.3 . 0 + , use $class :: $property syntax
* @ see https :// php . net / manual / language . oop5 . static . php
2011-12-27 00:07:42 +01:00
*/
function getStaticMember ( $class , $member )
{
2015-04-23 23:21:06 +02:00
dol_syslog ( __FUNCTION__ . " is deprecated " , LOG_WARNING );
2014-11-07 22:06:51 +01:00
// This part is deprecated. Uncomment if for php 5.2.*, and comment next isset class::member
/* if ( version_compare ( phpversion (), '5.3.0' , '<' ))
2011-12-27 00:07:42 +01:00
{
2014-11-07 22:06:51 +01:00
if ( is_object ( $class )) $class = get_class ( $class );
$classObj = new ReflectionClass ( $class );
$result = null ;
2011-12-29 23:50:02 +01:00
2014-11-07 22:06:51 +01:00
$found = 0 ;
foreach ( $classObj -> getStaticProperties () as $prop => $value )
2011-12-27 00:07:42 +01:00
{
2014-11-07 22:06:51 +01:00
if ( $prop == $member )
{
$result = $value ;
$found ++ ;
break ;
}
2011-12-27 00:07:42 +01:00
}
2011-12-29 23:50:02 +01:00
2014-11-07 22:06:51 +01:00
if ( $found ) return $result ;
} */
if ( isset ( $class :: $member )) return $class :: $member ;
2014-07-22 04:12:45 +02:00
dol_print_error ( '' , 'Try to get a static member "' . $member . '" in class "' . $class . '" that does not exists or is not static.' );
2014-07-22 04:46:17 +02:00
return null ;
2011-12-27 00:07:42 +01:00
}
2011-11-05 03:15:35 +01:00
2011-09-28 16:26:49 +02:00
/**
* Return a DoliDB instance ( database handler ) .
*
* @ param string $type Type of database ( mysql , pgsql ... )
* @ param string $host Address of database server
* @ param string $user Nom de l ' utilisateur autorise
* @ param string $pass Mot de passe
* @ param string $name Nom de la database
* @ param int $port Port of database server
* @ return DoliDB A DoliDB instance
*/
function getDoliDBInstance ( $type , $host , $user , $pass , $name , $port )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . " /core/db/ " . $type . '.class.php' ;
2011-09-28 16:26:49 +02:00
2012-08-03 23:29:08 +02:00
$class = 'DoliDB' . ucfirst ( $type );
$dolidb = new $class ( $type , $host , $user , $pass , $name , $port );
return $dolidb ;
2011-09-28 16:26:49 +02:00
}
2012-01-11 14:14:14 +01:00
/**
2017-05-31 19:20:33 +02:00
* Get list of entity id to use .
2012-01-15 02:39:43 +01:00
*
2017-06-08 10:24:16 +02:00
* @ param string $element Current element
* 'societe' , 'socpeople' , 'actioncomm' , 'agenda' , 'resource' ,
* 'product' , 'productprice' , 'stock' ,
2017-11-23 15:06:16 +01:00
* 'propal' , 'supplier_proposal' , 'facture' , 'facture_fourn' , 'payment_various' ,
2017-06-08 10:24:16 +02:00
* 'categorie' , 'bank_account' , 'bank_account' , 'adherent' , 'user' ,
* 'commande' , 'commande_fournisseur' , 'expedition' , 'intervention' , 'survey' ,
* 'contract' , 'tax' , 'expensereport' , 'holiday' , 'multicurrency' , 'project' ,
2017-11-12 12:39:23 +01:00
* 'email_template' , 'event' , 'donation'
2018-01-30 15:48:09 +01:00
* 'c_paiement' , 'c_payment_term' , ...
2017-06-08 10:24:16 +02:00
* @ param int $shared 0 = Return id of current entity only ,
2017-09-27 17:40:02 +02:00
* 1 = Return id of current entity + shared entities ( default )
2017-06-08 10:24:16 +02:00
* @ param int $forceentity Entity id
2012-01-11 14:14:14 +01:00
* @ return mixed Entity id ( s ) to use
*/
2017-06-11 06:27:49 +02:00
function getEntity ( $element , $shared = 1 , $forceentity = null )
2012-01-11 14:14:14 +01:00
{
global $conf , $mc ;
2012-01-15 02:39:43 +01:00
2016-11-18 12:54:08 +01:00
// For backward compatibilty
if ( $element == 'actioncomm' ) $element = 'agenda' ;
if ( $element == 'fichinter' ) $element = 'intervention' ;
if ( $element == 'categorie' ) $element = 'category' ;
2017-05-25 08:48:59 +02:00
2012-01-11 14:14:14 +01:00
if ( is_object ( $mc ))
{
2017-06-08 10:24:16 +02:00
return $mc -> getEntity ( $element , $shared , $forceentity );
2012-01-11 14:14:14 +01:00
}
else
{
2012-01-11 15:07:17 +01:00
$out = '' ;
2017-09-22 20:18:11 +02:00
$addzero = array ( 'user' , 'usergroup' , 'c_email_templates' , 'email_template' , 'default_values' );
2012-01-11 15:07:17 +01:00
if ( in_array ( $element , $addzero )) $out .= '0,' ;
$out .= $conf -> entity ;
return $out ;
2012-01-11 14:14:14 +01:00
}
}
2011-09-28 16:26:49 +02:00
2012-02-29 19:41:12 +01:00
/**
* Return information about user browser
*
2015-02-25 16:45:14 +01:00
* Returns array with the following format :
* array (
* 'browsername' => Browser name ( firefox | chrome | iceweasel | epiphany | safari | opera | ie | unknown )
* 'browserversion' => Browser version . Empty if unknown
* 'browseros' => Set with mobile OS ( android | blackberry | ios | palm | symbian | webos | maemo | windows | unknown )
* 'layout' => ( tablet | phone | classic )
* 'phone' => empty if not mobile , ( android | blackberry | ios | palm | unknown ) if mobile
* 'tablet' => true / false
* )
*
2015-02-22 12:35:51 +01:00
* @ param string $user_agent Content of $_SERVER [ " HTTP_USER_AGENT " ] variable
2015-02-25 16:45:14 +01:00
* @ return array Check function documentation
2012-02-29 19:41:12 +01:00
*/
2015-02-22 12:35:51 +01:00
function getBrowserInfo ( $user_agent )
2012-02-29 19:41:12 +01:00
{
2015-08-06 16:43:30 +02:00
include_once DOL_DOCUMENT_ROOT . '/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php' ;
2015-02-22 13:17:57 +01:00
$name = 'unknown' ;
$version = '' ;
$os = 'unknown' ;
2015-02-25 16:41:51 +01:00
$phone = '' ;
2015-02-22 13:17:57 +01:00
2015-08-06 18:38:50 +02:00
$detectmobile = new Mobile_Detect ( null , $user_agent );
2015-02-22 13:17:57 +01:00
$tablet = $detectmobile -> isTablet ();
if ( $detectmobile -> isMobile ()) {
2015-02-25 16:41:51 +01:00
$phone = 'unknown' ;
2015-02-22 13:17:57 +01:00
// If phone/smartphone, we set phone os name.
2015-02-23 10:51:43 +01:00
if ( $detectmobile -> is ( 'AndroidOS' )) {
$os = $phone = 'android' ;
} elseif ( $detectmobile -> is ( 'BlackBerryOS' )) {
$os = $phone = 'blackberry' ;
} elseif ( $detectmobile -> is ( 'iOS' )) {
$os = 'ios' ;
$phone = 'iphone' ;
} elseif ( $detectmobile -> is ( 'PalmOS' )) {
$os = $phone = 'palm' ;
} elseif ( $detectmobile -> is ( 'SymbianOS' )) {
$os = 'symbian' ;
} elseif ( $detectmobile -> is ( 'webOS' )) {
$os = 'webos' ;
} elseif ( $detectmobile -> is ( 'MaemoOS' )) {
$os = 'maemo' ;
} elseif ( $detectmobile -> is ( 'WindowsMobileOS' ) || $detectmobile -> is ( 'WindowsPhoneOS' )) {
$os = 'windows' ;
2015-02-22 13:17:57 +01:00
}
}
2014-07-27 14:13:25 +02:00
// OS
2017-08-23 12:32:28 +02:00
if ( preg_match ( '/linux/i' , $user_agent )) { $os = 'linux' ; }
2015-11-01 17:27:41 +01:00
elseif ( preg_match ( '/macintosh/i' , $user_agent )) { $os = 'macintosh' ; }
2017-08-23 12:32:28 +02:00
elseif ( preg_match ( '/windows/i' , $user_agent )) { $os = 'windows' ; }
2014-07-27 14:13:25 +02:00
2012-08-03 23:29:08 +02:00
// Name
2016-07-31 13:07:55 +02:00
if ( preg_match ( '/firefox(\/|\s)([\d\.]*)/i' , $user_agent , $reg )) { $name = 'firefox' ; $version = $reg [ 2 ]; }
2017-11-16 14:44:55 +01:00
elseif ( preg_match ( '/edge(\/|\s)([\d\.]*)/i' , $user_agent , $reg )) { $name = 'edge' ; $version = $reg [ 2 ]; }
2016-07-31 13:07:55 +02:00
elseif ( preg_match ( '/chrome(\/|\s)([\d\.]+)/i' , $user_agent , $reg )) { $name = 'chrome' ; $version = $reg [ 2 ]; } // we can have 'chrome (Mozilla...) chrome x.y' in one string
elseif ( preg_match ( '/chrome/i' , $user_agent , $reg )) { $name = 'chrome' ; }
elseif ( preg_match ( '/iceweasel/i' , $user_agent )) { $name = 'iceweasel' ; }
elseif ( preg_match ( '/epiphany/i' , $user_agent )) { $name = 'epiphany' ; }
elseif ( preg_match ( '/safari(\/|\s)([\d\.]*)/i' , $user_agent , $reg )) { $name = 'safari' ; $version = $reg [ 2 ]; } // Safari is often present in string for mobile but its not.
elseif ( preg_match ( '/opera(\/|\s)([\d\.]*)/i' , $user_agent , $reg )) { $name = 'opera' ; $version = $reg [ 2 ]; }
2017-08-23 12:32:28 +02:00
elseif ( preg_match ( '/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i' , $user_agent , $reg )) { $name = 'ie' ; $version = end ( $reg ); } // MS products at end
elseif ( preg_match ( '/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i' , $user_agent , $reg )) { $name = 'ie' ; $version = end ( $reg ); } // MS products at end
2016-07-31 13:07:55 +02:00
elseif ( preg_match ( '/l(i|y)n(x|ks)(\(|\/|\s)*([\d\.]+)/i' , $user_agent , $reg )) { $name = 'lynxlinks' ; $version = $reg [ 4 ]; }
2016-11-16 09:40:29 +01:00
2015-02-22 13:17:57 +01:00
if ( $tablet ) {
$layout = 'tablet' ;
} elseif ( $phone ) {
$layout = 'phone' ;
} else {
$layout = 'classic' ;
}
2014-07-27 20:56:26 +02:00
2015-02-22 12:35:51 +01:00
return array (
'browsername' => $name ,
'browserversion' => $version ,
'browseros' => $os ,
2015-02-22 13:17:57 +01:00
'layout' => $layout ,
2015-02-22 12:35:51 +01:00
'phone' => $phone ,
'tablet' => $tablet
);
2012-02-29 19:41:12 +01:00
}
2011-03-09 16:02:52 +01:00
/**
* Function called at end of web php process
2011-09-20 13:43:14 +02:00
*
2011-09-17 02:47:01 +02:00
* @ return void
2011-03-09 16:02:52 +01:00
*/
function dol_shutdown ()
{
2012-08-03 23:29:08 +02:00
global $conf , $user , $langs , $db ;
$disconnectdone = false ; $depth = 0 ;
if ( is_object ( $db ) && ! empty ( $db -> connected )) { $depth = $db -> transaction_opened ; $disconnectdone = $db -> close (); }
2015-06-14 16:59:35 +02:00
dol_syslog ( " --- End access to " . $_SERVER [ " PHP_SELF " ] . (( $disconnectdone && $depth ) ? ' (Warn: db disconnection forced, transaction depth was ' . $depth . ')' : '' ), (( $disconnectdone && $depth ) ? LOG_WARNING : LOG_INFO ));
2011-03-09 16:02:52 +01:00
}
2009-08-12 01:42:21 +02:00
2017-10-09 10:43:19 +02:00
/**
* Return true if we are in a context of submitting a parameter
*
* @ param string $paramname Name or parameter to test
* @ return boolean True if we have just submit a POST or GET request with the parameter provided ( even if param is empty )
*/
function GETPOSTISSET ( $paramname )
{
2017-10-09 11:03:16 +02:00
return ( isset ( $_POST [ $paramname ]) || isset ( $_GET [ $paramname ]));
2017-10-09 10:43:19 +02:00
}
2011-11-05 03:15:35 +01:00
2010-08-29 20:29:19 +02:00
/**
2017-05-16 23:38:23 +02:00
* Return value of a param into GET or POST supervariable .
* Use the property $user -> default_values [ path ][ 'creatform' ] and / or $user -> default_values [ path ][ 'filters' ] and / or $user -> default_values [ path ][ 'sortorder' ]
2017-06-01 13:32:20 +02:00
* Note : The property $user -> default_values is loaded by main . php when loading the user .
2017-05-25 08:48:59 +02:00
*
2011-09-17 02:47:01 +02:00
* @ param string $paramname Name of parameter to found
2017-05-16 13:27:32 +02:00
* @ param string $check Type of check
* '' = no check ( deprecated )
* 'none' = no check ( only for param that should have very rich content )
2017-06-27 16:42:11 +02:00
* 'int' = check it ' s numeric ( integer or float )
2017-05-16 13:27:32 +02:00
* 'alpha' = check it ' s text and sign
* 'aZ' = check it ' s a - z only
* 'aZ09' = check it ' s simple alpha string ( recommended for keys )
* 'array' = check it ' s array
* 'san_alpha' = Use filter_var with FILTER_SANITIZE_STRING ( do not use this for free text string )
* 'nohtml' , 'alphanohtml' = check there is no html content
* 'custom' = custom filter specify $filter and $options )
2013-07-29 17:32:43 +02:00
* @ param int $method Type of method ( 0 = get then post , 1 = only get , 2 = only post , 3 = post then get , 4 = post then get then cookie )
2017-05-10 13:46:02 +02:00
* @ param int $filter Filter to apply when $check is set to 'custom' . ( See http :// php . net / manual / en / filter . filters . php for détails )
2017-11-06 17:54:18 +01:00
* @ param mixed $options Options to pass to filter_var when $check is set to 'custom'
* @ param string $noreplace Force disable of replacement of __xxx__ strings .
2015-05-29 18:49:10 +02:00
* @ return string | string [] Value found ( string or array ), or '' if check fails
2010-08-29 20:29:19 +02:00
*/
2017-11-06 21:37:19 +01:00
function GETPOST ( $paramname , $check = 'none' , $method = 0 , $filter = NULL , $options = NULL , $noreplace = 0 )
2010-08-29 20:29:19 +02:00
{
2017-10-13 13:28:26 +02:00
global $mysoc , $user , $conf ;
2017-05-25 08:48:59 +02:00
2017-10-13 13:28:26 +02:00
if ( empty ( $paramname )) return 'BadFirstParameterForGETPOST' ;
if ( empty ( $check ))
{
dol_syslog ( " Deprecated use of GETPOST, called with 1st param = " . $paramname . " and 2nd param is '', when calling page " . $_SERVER [ " PHP_SELF " ], LOG_WARNING );
// Enable this line to know who call the GETPOST with '' $check parameter.
//var_dump(debug_backtrace()[0]);
}
2017-05-25 08:48:59 +02:00
2017-10-13 13:28:26 +02:00
if ( empty ( $method )) $out = isset ( $_GET [ $paramname ]) ? $_GET [ $paramname ] : ( isset ( $_POST [ $paramname ]) ? $_POST [ $paramname ] : '' );
2011-11-25 16:47:57 +01:00
elseif ( $method == 1 ) $out = isset ( $_GET [ $paramname ]) ? $_GET [ $paramname ] : '' ;
elseif ( $method == 2 ) $out = isset ( $_POST [ $paramname ]) ? $_POST [ $paramname ] : '' ;
elseif ( $method == 3 ) $out = isset ( $_POST [ $paramname ]) ? $_POST [ $paramname ] : ( isset ( $_GET [ $paramname ]) ? $_GET [ $paramname ] : '' );
2013-07-29 17:32:43 +02:00
elseif ( $method == 4 ) $out = isset ( $_POST [ $paramname ]) ? $_POST [ $paramname ] : ( isset ( $_GET [ $paramname ]) ? $_GET [ $paramname ] : ( isset ( $_COOKIE [ $paramname ]) ? $_COOKIE [ $paramname ] : '' ));
else return 'BadThirdParameterForGETPOST' ;
2017-05-25 08:48:59 +02:00
2017-05-05 18:42:11 +02:00
if ( empty ( $method ) || $method == 3 || $method == 4 )
{
2017-09-11 00:02:52 +02:00
2017-10-13 13:28:26 +02:00
$relativepathstring = $_SERVER [ " PHP_SELF " ];
// Clean $relativepathstring
if ( constant ( 'DOL_URL_ROOT' )) $relativepathstring = preg_replace ( '/^' . preg_quote ( constant ( 'DOL_URL_ROOT' ), '/' ) . '/' , '' , $relativepathstring );
$relativepathstring = preg_replace ( '/^\//' , '' , $relativepathstring );
$relativepathstring = preg_replace ( '/^custom\//' , '' , $relativepathstring );
2017-09-11 00:02:52 +02:00
//var_dump($relativepathstring);
//var_dump($user->default_values);
2017-05-25 08:48:59 +02:00
2017-10-13 13:28:26 +02:00
// Code for search criteria persistence.
// Retrieve values if restore_lastsearch_values is set and there is saved values
if ( ! empty ( $_GET [ 'restore_lastsearch_values' ]) && ! empty ( $_SESSION [ 'lastsearch_values_' . $relativepathstring ])) // Keep $_GET here
{
$tmp = json_decode ( $_SESSION [ 'lastsearch_values_' . $relativepathstring ], true );
if ( is_array ( $tmp ))
{
foreach ( $tmp as $key => $val )
{
if ( $key == $paramname )
{
$out = $val ;
break ;
}
}
}
}
// Else, retreive default values if we are not doing a sort
2017-10-25 22:02:07 +02:00
elseif ( ! isset ( $_GET [ 'sortfield' ])) // If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
2017-10-13 13:28:26 +02:00
{
if ( ! empty ( $_GET [ 'action' ]) && $_GET [ 'action' ] == 'create' && ! isset ( $_GET [ $paramname ]) && ! isset ( $_POST [ $paramname ]))
{
2017-10-25 22:02:07 +02:00
// Search default value from $object->field
global $object ;
if ( is_object ( $object ) && isset ( $object -> fields [ $paramname ][ 'default' ]))
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
$out = $object -> fields [ $paramname ][ 'default' ];
2017-10-01 14:54:17 +02:00
}
2017-10-13 13:28:26 +02:00
}
2017-10-25 22:02:07 +02:00
if ( ! empty ( $conf -> global -> MAIN_ENABLE_DEFAULT_VALUES ))
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
if ( ! empty ( $_GET [ 'action' ]) && $_GET [ 'action' ] == 'create' && ! isset ( $_GET [ $paramname ]) && ! isset ( $_POST [ $paramname ]))
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
// Now search in setup to overwrite default values
if ( ! empty ( $user -> default_values )) // $user->default_values defined from menu 'Setup - Default values'
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
if ( isset ( $user -> default_values [ $relativepathstring ][ 'createform' ]))
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
foreach ( $user -> default_values [ $relativepathstring ][ 'createform' ] as $defkey => $defval )
2017-10-13 13:28:26 +02:00
{
$qualified = 0 ;
if ( $defkey != '_noquery_' )
{
$tmpqueryarraytohave = explode ( '&' , $defkey );
$tmpqueryarraywehave = explode ( '&' , dol_string_nohtmltag ( $_SERVER [ 'QUERY_STRING' ]));
$foundintru = 0 ;
foreach ( $tmpqueryarraytohave as $tmpquerytohave )
{
if ( ! in_array ( $tmpquerytohave , $tmpqueryarraywehave )) $foundintru = 1 ;
}
if ( ! $foundintru ) $qualified = 1 ;
//var_dump($defkey.'-'.$qualified);
}
else $qualified = 1 ;
if ( $qualified )
{
2017-10-25 22:02:07 +02:00
//var_dump($user->default_values[$relativepathstring][$defkey]['createform']);
if ( isset ( $user -> default_values [ $relativepathstring ][ 'createform' ][ $defkey ][ $paramname ]))
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
$out = $user -> default_values [ $relativepathstring ][ 'createform' ][ $defkey ][ $paramname ];
break ;
}
}
}
}
}
}
// Management of default search_filters and sort order
//elseif (preg_match('/list.php$/', $_SERVER["PHP_SELF"]) && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
elseif ( ! empty ( $paramname ) && ! isset ( $_GET [ $paramname ]) && ! isset ( $_POST [ $paramname ]))
{
if ( ! empty ( $user -> default_values )) // $user->default_values defined from menu 'Setup - Default values'
{
//var_dump($user->default_values[$relativepathstring]);
if ( $paramname == 'sortfield' || $paramname == 'sortorder' ) // Sorted on which fields ? ASC or DESC ?
{
if ( isset ( $user -> default_values [ $relativepathstring ][ 'sortorder' ])) // Even if paramname is sortfield, data are stored into ['sortorder...']
{
foreach ( $user -> default_values [ $relativepathstring ][ 'sortorder' ] as $defkey => $defval )
{
$qualified = 0 ;
if ( $defkey != '_noquery_' )
{
$tmpqueryarraytohave = explode ( '&' , $defkey );
$tmpqueryarraywehave = explode ( '&' , dol_string_nohtmltag ( $_SERVER [ 'QUERY_STRING' ]));
$foundintru = 0 ;
foreach ( $tmpqueryarraytohave as $tmpquerytohave )
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
if ( ! in_array ( $tmpquerytohave , $tmpqueryarraywehave )) $foundintru = 1 ;
2017-10-13 13:28:26 +02:00
}
2017-10-25 22:02:07 +02:00
if ( ! $foundintru ) $qualified = 1 ;
//var_dump($defkey.'-'.$qualified);
}
else $qualified = 1 ;
if ( $qualified )
{
$forbidden_chars_to_replace = array ( " " , " ' " , " / " , " \\ " , " : " , " * " , " ? " , " \" " , " < " , " > " , " | " , " [ " , " ] " , " ; " , " = " ); // we accept _, -, . and ,
foreach ( $user -> default_values [ $relativepathstring ][ 'sortorder' ][ $defkey ] as $key => $val )
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
if ( $out ) $out .= ', ' ;
if ( $paramname == 'sortfield' )
{
$out .= dol_string_nospecial ( $key , '' , $forbidden_chars_to_replace );
}
if ( $paramname == 'sortorder' )
{
$out .= dol_string_nospecial ( $val , '' , $forbidden_chars_to_replace );
}
2017-10-13 13:28:26 +02:00
}
2017-10-25 22:02:07 +02:00
//break; // No break for sortfield and sortorder so we can cumulate fields (is it realy usefull ?)
2017-10-13 13:28:26 +02:00
}
}
}
2017-09-11 00:02:52 +02:00
}
2017-10-25 22:02:07 +02:00
elseif ( isset ( $user -> default_values [ $relativepathstring ][ 'filters' ]))
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
foreach ( $user -> default_values [ $relativepathstring ][ 'filters' ] as $defkey => $defval )
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
$qualified = 0 ;
if ( $defkey != '_noquery_' )
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
$tmpqueryarraytohave = explode ( '&' , $defkey );
$tmpqueryarraywehave = explode ( '&' , dol_string_nohtmltag ( $_SERVER [ 'QUERY_STRING' ]));
$foundintru = 0 ;
foreach ( $tmpqueryarraytohave as $tmpquerytohave )
{
if ( ! in_array ( $tmpquerytohave , $tmpqueryarraywehave )) $foundintru = 1 ;
}
if ( ! $foundintru ) $qualified = 1 ;
//var_dump($defkey.'-'.$qualified);
2017-10-13 13:28:26 +02:00
}
2017-10-25 22:02:07 +02:00
else $qualified = 1 ;
2017-10-01 14:54:17 +02:00
2017-10-25 22:02:07 +02:00
if ( $qualified )
2017-10-13 13:28:26 +02:00
{
2017-10-25 22:02:07 +02:00
if ( isset ( $_POST [ 'sall' ]) || isset ( $_POST [ 'search_all' ]) || isset ( $_GET [ 'sall' ]) || isset ( $_GET [ 'search_all' ]))
{
// We made a search from quick search menu, do we still use default filter ?
if ( empty ( $conf -> global -> MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH ))
{
$forbidden_chars_to_replace = array ( " " , " ' " , " / " , " \\ " , " : " , " * " , " ? " , " \" " , " < " , " > " , " | " , " [ " , " ] " , " ; " , " = " ); // we accept _, -, . and ,
$out = dol_string_nospecial ( $user -> default_values [ $relativepathstring ][ 'filters' ][ $defkey ][ $paramname ], '' , $forbidden_chars_to_replace );
}
}
else
2017-10-13 13:28:26 +02:00
{
$forbidden_chars_to_replace = array ( " " , " ' " , " / " , " \\ " , " : " , " * " , " ? " , " \" " , " < " , " > " , " | " , " [ " , " ] " , " ; " , " = " ); // we accept _, -, . and ,
$out = dol_string_nospecial ( $user -> default_values [ $relativepathstring ][ 'filters' ][ $defkey ][ $paramname ], '' , $forbidden_chars_to_replace );
}
2017-10-25 22:02:07 +02:00
break ;
2017-10-13 13:28:26 +02:00
}
2017-10-01 14:54:17 +02:00
}
2017-10-13 13:28:26 +02:00
}
}
}
}
}
2017-05-25 08:48:59 +02:00
}
2017-10-01 14:54:17 +02:00
// Substitution variables for GETPOST (used to get final url with variable parameters or final default value with variable paramaters)
2017-12-09 15:35:01 +01:00
// Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOMPANY_COUNTRY_ID__, __USER_ID__, ...
2017-10-01 14:54:17 +02:00
// We do this only if var is a GET. If it is a POST, may be we want to post the text with vars as the setup text.
2017-11-06 21:37:19 +01:00
if ( ! is_array ( $out ) && empty ( $_POST [ $paramname ]) && empty ( $noreplace ))
2017-10-01 14:54:17 +02:00
{
2017-10-13 13:28:26 +02:00
$maxloop = 20 ; $loopnb = 0 ; // Protection against infinite loop
while ( preg_match ( '/__([A-Z0-9]+_?[A-Z0-9]+)__/i' , $out , $reg ) && ( $loopnb < $maxloop )) // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side.
{
$loopnb ++ ; $newout = '' ;
if ( $reg [ 1 ] == 'DAY' ) { $tmp = dol_getdate ( dol_now (), true ); $newout = $tmp [ 'mday' ]; }
elseif ( $reg [ 1 ] == 'MONTH' ) { $tmp = dol_getdate ( dol_now (), true ); $newout = $tmp [ 'mon' ]; }
elseif ( $reg [ 1 ] == 'YEAR' ) { $tmp = dol_getdate ( dol_now (), true ); $newout = $tmp [ 'year' ]; }
elseif ( $reg [ 1 ] == 'PREVIOUS_DAY' ) { $tmp = dol_getdate ( dol_now (), true ); $tmp2 = dol_get_prev_day ( $tmp [ 'mday' ], $tmp [ 'mon' ], $tmp [ 'year' ]); $newout = $tmp2 [ 'day' ]; }
elseif ( $reg [ 1 ] == 'PREVIOUS_MONTH' ) { $tmp = dol_getdate ( dol_now (), true ); $tmp2 = dol_get_prev_month ( $tmp [ 'mday' ], $tmp [ 'mon' ], $tmp [ 'year' ]); $newout = $tmp2 [ 'month' ]; }
elseif ( $reg [ 1 ] == 'PREVIOUS_YEAR' ) { $tmp = dol_getdate ( dol_now (), true ); $newout = ( $tmp [ 'year' ] - 1 ); }
elseif ( $reg [ 1 ] == 'NEXT_DAY' ) { $tmp = dol_getdate ( dol_now (), true ); $tmp2 = dol_get_next_day ( $tmp [ 'mday' ], $tmp [ 'mon' ], $tmp [ 'year' ]); $newout = $tmp2 [ 'day' ]; }
elseif ( $reg [ 1 ] == 'NEXT_MONTH' ) { $tmp = dol_getdate ( dol_now (), true ); $tmp2 = dol_get_next_month ( $tmp [ 'mday' ], $tmp [ 'mon' ], $tmp [ 'year' ]); $newout = $tmp2 [ 'month' ]; }
elseif ( $reg [ 1 ] == 'NEXT_YEAR' ) { $tmp = dol_getdate ( dol_now (), true ); $newout = ( $tmp [ 'year' ] + 1 ); }
2017-12-09 15:35:01 +01:00
elseif ( $reg [ 1 ] == 'MYCOMPANY_COUNTRY_ID' || $reg [ 1 ] == 'MYCOUNTRY_ID' || $reg [ 1 ] == 'MYCOUNTRYID' )
2017-10-13 13:28:26 +02:00
{
$newout = $mysoc -> country_id ;
}
elseif ( $reg [ 1 ] == 'USER_ID' || $reg [ 1 ] == 'USERID' )
{
$newout = $user -> id ;
}
2017-12-09 15:35:01 +01:00
elseif ( $reg [ 1 ] == 'USER_SUPERVISOR_ID' || $reg [ 1 ] == 'SUPERVISOR_ID' || $reg [ 1 ] == 'SUPERVISORID' )
2017-10-13 13:28:26 +02:00
{
$newout = $user -> fk_user ;
}
2017-12-09 15:35:01 +01:00
elseif ( $reg [ 1 ] == 'ENTITY_ID' || $reg [ 1 ] == 'ENTITYID' )
2017-10-13 13:28:26 +02:00
{
$newout = $conf -> entity ;
}
else $newout = '' ; // Key not found, we replace with empty string
//var_dump('__'.$reg[1].'__ -> '.$newout);
$out = preg_replace ( '/__' . preg_quote ( $reg [ 1 ], '/' ) . '__/' , $newout , $out );
}
}
// Check is done after replacement
switch ( $check )
{
case 'none' :
break ;
case 'int' : // Check param is a numeric value (integer but also float or hexadecimal)
if ( ! is_numeric ( $out )) { $out = '' ; }
break ;
case 'intcomma' :
2017-12-18 11:32:24 +01:00
if ( preg_match ( '/[^0-9,-]+/i' , $out )) $out = '' ;
2017-10-13 13:28:26 +02:00
break ;
case 'alpha' :
2017-11-02 09:58:22 +01:00
if ( ! is_array ( $out ))
{
$out = trim ( $out );
// '"' is dangerous because param in url can close the href= or src= and add javascript functions.
// '../' is dangerous because it allows dir transversals
if ( preg_match ( '/"/' , $out )) $out = '' ;
else if ( preg_match ( '/\.\.\//' , $out )) $out = '' ;
}
2017-10-13 13:28:26 +02:00
break ;
case 'san_alpha' :
$out = filter_var ( $out , FILTER_SANITIZE_STRING );
break ;
case 'aZ' :
2017-11-02 09:58:22 +01:00
if ( ! is_array ( $out ))
{
$out = trim ( $out );
if ( preg_match ( '/[^a-z]+/i' , $out )) $out = '' ;
}
2017-10-13 13:28:26 +02:00
break ;
case 'aZ09' :
2017-11-02 09:58:22 +01:00
if ( ! is_array ( $out ))
{
$out = trim ( $out );
if ( preg_match ( '/[^a-z0-9_\-\.]+/i' , $out )) $out = '' ;
}
2017-10-13 13:28:26 +02:00
break ;
case 'array' :
if ( ! is_array ( $out ) || empty ( $out )) $out = array ();
break ;
2017-10-01 14:54:17 +02:00
case 'nohtml' :
2018-02-01 15:44:35 +01:00
$out = dol_string_nohtmltag ( $out , 0 );
2017-10-01 14:54:17 +02:00
break ;
case 'alphanohtml' : // Recommended for search params
2017-11-02 09:58:22 +01:00
if ( ! is_array ( $out ))
{
$out = trim ( $out );
// '"' is dangerous because param in url can close the href= or src= and add javascript functions.
// '../' is dangerous because it allows dir transversals
if ( preg_match ( '/"/' , $out )) $out = '' ;
else if ( preg_match ( '/\.\.\//' , $out )) $out = '' ;
$out = dol_string_nohtmltag ( $out );
}
2017-10-01 14:54:17 +02:00
break ;
case 'custom' :
2017-10-13 13:28:26 +02:00
if ( empty ( $filter )) return 'BadFourthParameterForGETPOST' ;
$out = filter_var ( $out , $filter , $options );
break ;
}
2011-11-27 02:23:55 +01:00
2017-10-13 13:28:26 +02:00
// Code for search criteria persistence.
2017-05-16 23:38:23 +02:00
// Save data into session if key start with 'search_' or is 'smonth', 'syear', 'month', 'year'
if ( empty ( $method ) || $method == 3 || $method == 4 )
{
2017-10-13 13:28:26 +02:00
//if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder', 'sortfield", 'smonth', 'syear', 'month', 'year')))
if ( preg_match ( '/^search_/' , $paramname ) || in_array ( $paramname , array ( 'sortorder' , 'sortfield' )))
{
//var_dump($paramname.' - '.$out.' '.$user->default_values[$relativepathstring]['filters'][$paramname]);
2017-05-19 15:34:38 +02:00
2017-10-13 13:28:26 +02:00
// We save search key only if:
// - not empty, or
// - if value is empty and a default value exists that is not empty (it means we did a filter to an empty value when default was not).
2017-05-25 08:48:59 +02:00
2017-10-13 13:28:26 +02:00
//if (! empty($out) || ! empty($user->default_values[$relativepathstring]['filters'][$paramname]))
if ( ! empty ( $out ))
{
$user -> lastsearch_values_tmp [ $relativepathstring ][ $paramname ] = $out ;
}
}
2017-05-16 23:38:23 +02:00
}
2017-05-25 08:48:59 +02:00
2011-11-25 16:47:57 +01:00
return $out ;
2010-08-29 20:29:19 +02:00
}
2010-12-27 20:13:06 +01:00
/**
2017-05-09 21:01:37 +02:00
* Return a prefix to use for this Dolibarr instance , for session / cookie names or email id .
2017-12-19 00:15:22 +01:00
* This prefix is valid in a web context only and is unique for instance and avoid conflict
* between multi - instances , even when having two instances with one root dir or two instances
* in virtual servers .
2011-08-17 18:18:12 +02:00
*
2017-12-19 00:15:22 +01:00
* @ param string $mode '' ( prefix for session name ) or 'email' ( prefix for email id )
* @ return string A calculated prefix
2010-12-27 20:13:06 +01:00
*/
2017-12-19 00:15:22 +01:00
if ( ! function_exists ( 'dol_getprefix' ))
2010-12-27 20:13:06 +01:00
{
2017-12-19 00:15:22 +01:00
function dol_getprefix ( $mode = '' )
2017-10-13 13:28:26 +02:00
{
2017-12-19 00:15:22 +01:00
global $conf ;
2016-12-15 12:11:39 +01:00
2017-12-19 00:15:22 +01:00
// If MAIL_PREFIX_FOR_EMAIL_ID is set and prefix is for email
if ( $mode == 'email' && ! empty ( $conf -> global -> MAIL_PREFIX_FOR_EMAIL_ID ))
{
if ( $conf -> global -> MAIL_PREFIX_FOR_EMAIL_ID != 'SERVER_NAME' ) return $conf -> global -> MAIL_PREFIX_FOR_EMAIL_ID ;
else if ( isset ( $_SERVER [ " SERVER_NAME " ])) return $_SERVER [ " SERVER_NAME " ];
}
if ( isset ( $_SERVER [ " SERVER_NAME " ]) && isset ( $_SERVER [ " DOCUMENT_ROOT " ]))
{
return dol_hash ( $_SERVER [ " SERVER_NAME " ] . $_SERVER [ " DOCUMENT_ROOT " ] . DOL_DOCUMENT_ROOT . DOL_URL_ROOT );
// Use this for a "readable" cookie name
//return dol_sanitizeFileName($_SERVER["SERVER_NAME"].$_SERVER["DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
}
else return dol_hash ( DOL_DOCUMENT_ROOT . DOL_URL_ROOT );
2014-08-08 13:09:06 +02:00
}
2010-12-27 20:13:06 +01:00
}
2010-12-19 03:42:53 +01:00
/**
* Make an include_once using default root and alternate root if it fails .
2010-12-29 11:39:41 +01:00
* To link to a core file , use include ( DOL_DOCUMENT_ROOT . '/pathtofile' )
2012-08-23 02:04:35 +02:00
* To link to a module file from a module file , use include './mymodulefile' ;
2013-05-28 17:54:55 +02:00
* To link to a module file from a core file , then this function can be used ( call by hook / trigger / speciales pages )
2011-08-17 18:18:12 +02:00
*
2011-09-17 02:47:01 +02:00
* @ param string $relpath Relative path to file ( Ie : mydir / myfile , ../ myfile , ... )
2016-01-31 14:58:04 +01:00
* @ param string $classname Class name ( deprecated )
2015-09-01 14:31:32 +02:00
* @ return bool True if load is a success , False if it fails
2010-12-19 03:42:53 +01:00
*/
2012-08-02 08:02:49 +02:00
function dol_include_once ( $relpath , $classname = '' )
2010-12-19 03:42:53 +01:00
{
2014-07-27 20:31:11 +02:00
global $conf , $langs , $user , $mysoc ; // Do not remove this. They must be defined for files we include. Other globals var must be retreived with $GLOBALS['var']
2014-07-17 21:44:59 +02:00
$fullpath = dol_buildpath ( $relpath );
2014-07-15 17:18:41 +02:00
2014-07-17 21:44:59 +02:00
if ( ! file_exists ( $fullpath )) {
2014-07-15 17:18:41 +02:00
dol_syslog ( 'functions::dol_include_once Tried to load unexisting file: ' . $relpath , LOG_ERR );
return false ;
}
2012-12-02 12:59:06 +01:00
2012-08-03 23:29:08 +02:00
if ( ! empty ( $classname ) && ! class_exists ( $classname )) {
2014-07-17 21:44:59 +02:00
return include $fullpath ;
2012-08-03 23:29:08 +02:00
} else {
2014-07-17 21:44:59 +02:00
return include_once $fullpath ;
2012-08-03 23:29:08 +02:00
}
2010-12-19 03:42:53 +01:00
}
2010-12-19 12:05:07 +01:00
/**
2017-03-04 21:45:19 +01:00
* Return path of url or filesystem . Return alternate root if exists .
2011-08-17 18:18:12 +02:00
*
2017-09-23 01:24:31 +02:00
* @ param string $path Relative path to file ( if mode = 0 ) or relative url ( if mode = 1 ) . Ie : mydir / myfile , ../ myfile
* @ param int $type 0 = Used for a Filesystem path , 1 = Used for an URL path ( output relative ), 2 = Used for an URL path ( output full path using same host that current url ), 3 = Used for an URL path ( output full path using host defined into $dolibarr_main_url_root of conf file )
2017-11-05 18:15:59 +01:00
* @ param int $returnemptyifnotfound 0 : If $type == 0 and if file was not found into alternate dir , return default path into main dir ( no test on it )
* 1 : If $type == 0 and if file was not found into alternate dir , return empty string
* 2 : If $type == 0 and if file was not found into alternate dir , test into main dir , return default path if found , empty string if not found
2017-09-23 15:12:25 +02:00
* @ return string Full filesystem path ( if path = 0 ), Full url path ( if mode = 1 )
2010-12-19 12:05:07 +01:00
*/
2017-09-23 01:24:31 +02:00
function dol_buildpath ( $path , $type = 0 , $returnemptyifnotfound = 0 )
2010-12-19 12:05:07 +01:00
{
2013-07-07 03:26:51 +02:00
global $conf ;
$path = preg_replace ( '/^\//' , '' , $path );
2012-08-03 23:29:08 +02:00
if ( empty ( $type )) // For a filesystem path
{
2017-09-23 01:24:31 +02:00
$res = DOL_DOCUMENT_ROOT . '/' . $path ; // Standard default path
2013-07-07 13:17:48 +02:00
foreach ( $conf -> file -> dol_document_root as $key => $dirroot ) // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
{
2013-07-07 03:26:51 +02:00
if ( $key == 'main' ) continue ;
2013-07-07 13:17:48 +02:00
if ( file_exists ( $dirroot . '/' . $path ))
{
$res = $dirroot . '/' . $path ;
2017-09-23 01:24:31 +02:00
return $res ;
2013-07-07 13:17:48 +02:00
}
}
2017-11-05 18:15:59 +01:00
if ( $returnemptyifnotfound ) // Not found into alternate dir
2017-09-23 01:24:31 +02:00
{
2017-11-05 18:15:59 +01:00
if ( $returnemptyifnotfound == 1 || ! file_exists ( $res )) return '' ;
2017-09-23 01:24:31 +02:00
}
2012-08-03 23:29:08 +02:00
}
else // For an url path
{
// We try to get local path of file on filesystem from url
// Note that trying to know if a file on disk exist by forging path on disk from url
// works only for some web server and some setup. This is bugged when
// using proxy, rewriting, virtual path, etc...
2013-07-07 03:26:51 +02:00
$res = '' ;
if ( $type == 1 ) $res = DOL_URL_ROOT . '/' . $path ; // Standard value
if ( $type == 2 ) $res = DOL_MAIN_URL_ROOT . '/' . $path ; // Standard value
2016-08-02 14:33:46 +02:00
if ( $type == 3 ) $res = DOL_URL_ROOT . '/' . $path ;
2016-11-16 09:40:29 +01:00
2013-07-07 13:17:48 +02:00
foreach ( $conf -> file -> dol_document_root as $key => $dirroot ) // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
2012-08-03 23:29:08 +02:00
{
2016-11-16 09:40:29 +01:00
if ( $key == 'main' )
2016-10-31 10:37:58 +01:00
{
2017-10-13 13:28:26 +02:00
if ( $type == 3 )
{
global $dolibarr_main_url_root ;
// Define $urlwithroot
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
$res = ( preg_match ( '/^http/i' , $conf -> file -> dol_url_root [ $key ]) ? '' : $urlwithroot ) . '/' . $path ; // Test on start with http is for old conf syntax
}
continue ;
2016-10-31 10:37:58 +01:00
}
2013-07-07 03:26:51 +02:00
preg_match ( '/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i' , $path , $regs ); // Take part before '?'
if ( ! empty ( $regs [ 1 ]))
2012-08-03 23:29:08 +02:00
{
2013-07-07 03:26:51 +02:00
//print $key.'-'.$dirroot.'/'.$path.'-'.$conf->file->dol_url_root[$type].'<br>'."\n";
2013-07-09 14:19:05 +02:00
if ( file_exists ( $dirroot . '/' . $regs [ 1 ]))
2013-07-07 13:17:48 +02:00
{
2013-07-07 23:37:56 +02:00
if ( $type == 1 )
{
$res = ( preg_match ( '/^http/i' , $conf -> file -> dol_url_root [ $key ]) ? '' : DOL_URL_ROOT ) . $conf -> file -> dol_url_root [ $key ] . '/' . $path ;
}
if ( $type == 2 )
{
2017-10-13 13:28:26 +02:00
$res = ( preg_match ( '/^http/i' , $conf -> file -> dol_url_root [ $key ]) ? '' : DOL_MAIN_URL_ROOT ) . $conf -> file -> dol_url_root [ $key ] . '/' . $path ;
2016-08-02 14:33:46 +02:00
}
if ( $type == 3 )
{
2017-10-13 13:28:26 +02:00
global $dolibarr_main_url_root ;
2016-11-16 09:40:29 +01:00
2017-10-13 13:28:26 +02:00
// Define $urlwithroot
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2016-11-16 09:40:29 +01:00
2017-10-13 13:28:26 +02:00
$res = ( preg_match ( '/^http/i' , $conf -> file -> dol_url_root [ $key ]) ? '' : $urlwithroot ) . $conf -> file -> dol_url_root [ $key ] . '/' . $path ; // Test on start with http is for old conf syntax
2013-07-07 23:37:56 +02:00
}
2013-07-07 13:17:48 +02:00
break ;
2012-08-03 23:29:08 +02:00
}
2013-07-07 13:17:48 +02:00
}
2012-08-03 23:29:08 +02:00
}
}
return $res ;
2010-12-19 12:05:07 +01:00
}
2009-08-12 01:42:21 +02:00
/**
2017-05-22 01:19:16 +02:00
* Create a clone of instance of object ( new instance with same value for properties )
2017-07-23 20:27:30 +02:00
* With native = 0 : Property that are reference are also new object ( true clone ) . This means $this -> db is not valid .
* With native = 1 : Use PHP clone . Property that are reference are same pointer . This means $this -> db is still valid .
2011-08-17 18:18:12 +02:00
*
2011-09-17 02:47:01 +02:00
* @ param object $object Object to clone
2017-07-23 20:27:30 +02:00
* @ param int $native Native method or true method
2011-09-17 02:47:01 +02:00
* @ return object Object clone
2015-04-23 23:21:06 +02:00
* @ see https :// php . net / manual / language . oop5 . cloning . php
2009-08-12 01:42:21 +02:00
*/
2017-07-23 20:27:30 +02:00
function dol_clone ( $object , $native = 0 )
2009-08-12 01:42:21 +02:00
{
2017-05-22 01:19:16 +02:00
//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
2012-08-03 23:29:08 +02:00
2017-07-23 20:27:30 +02:00
if ( empty ( $native ))
{
$myclone = unserialize ( serialize ( $object ));
}
else
{
$myclone = clone $object ; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep references (refer to the same target/variable)
}
2017-05-25 08:48:59 +02:00
2012-08-03 23:29:08 +02:00
return $myclone ;
2009-08-12 01:42:21 +02:00
}
2009-09-15 13:24:00 +02:00
/**
2011-03-09 16:02:52 +01:00
* Optimize a size for some browsers ( phone , smarphone , ... )
2011-08-17 18:18:12 +02:00
*
2011-09-17 02:47:01 +02:00
* @ param int $size Size we want
* @ param string $type Type of optimizing :
2013-04-03 15:20:56 +02:00
* '' = function used to define a size for truncation
* 'width' = function is used to define a width
2011-09-17 02:47:01 +02:00
* @ return int New size after optimizing
2009-09-15 13:24:00 +02:00
*/
function dol_size ( $size , $type = '' )
{
2012-08-03 23:29:08 +02:00
global $conf ;
2013-04-03 15:20:56 +02:00
if ( empty ( $conf -> dol_optimize_smallscreen )) return $size ;
2012-08-03 23:29:08 +02:00
if ( $type == 'width' && $size > 250 ) return 250 ;
else return 10 ;
2009-09-15 13:24:00 +02:00
}
2009-08-12 01:42:21 +02:00
2008-08-06 16:50:06 +02:00
/**
2011-08-17 18:18:12 +02:00
* Clean a string to use it as a file name
*
2011-09-17 02:47:01 +02:00
* @ param string $str String to clean
* @ param string $newstr String to replace bad chars with
2016-09-08 11:05:47 +02:00
* @ param int $unaccent 1 = Remove also accent ( default ), 0 do not remove them
2011-09-17 02:47:01 +02:00
* @ return string String cleaned ( a - zA - Z_ )
*
2016-09-08 11:05:47 +02:00
* @ see dol_string_nospecial , dol_string_unaccent , dol_sanitizePathName
2008-10-25 23:35:27 +02:00
*/
2012-03-21 15:58:04 +01:00
function dol_sanitizeFileName ( $str , $newstr = '_' , $unaccent = 1 )
2008-10-25 23:35:27 +02:00
{
2017-10-02 20:38:15 +02:00
$filesystem_forbidden_chars = array ( '<' , '>' , '/' , '\\' , '?' , '*' , '|' , '"' , '°' );
2012-08-03 23:29:08 +02:00
return dol_string_nospecial ( $unaccent ? dol_string_unaccent ( $str ) : $str , $newstr , $filesystem_forbidden_chars );
2008-10-25 23:35:27 +02:00
}
2016-09-08 11:05:47 +02:00
/**
* Clean a string to use it as a path name
*
* @ param string $str String to clean
* @ param string $newstr String to replace bad chars with
* @ param int $unaccent 1 = Remove also accent ( default ), 0 do not remove them
* @ return string String cleaned ( a - zA - Z_ )
*
* @ see dol_string_nospecial , dol_string_unaccent , dol_sanitizeFileName
*/
function dol_sanitizePathName ( $str , $newstr = '_' , $unaccent = 1 )
{
2017-10-13 13:28:26 +02:00
$filesystem_forbidden_chars = array ( '<' , '>' , '?' , '*' , '|' , '"' , '°' );
return dol_string_nospecial ( $unaccent ? dol_string_unaccent ( $str ) : $str , $newstr , $filesystem_forbidden_chars );
2016-09-08 11:05:47 +02:00
}
2008-10-25 23:35:27 +02:00
/**
2011-08-17 18:18:12 +02:00
* Clean a string from all accent characters to be used as ref , login or by dol_sanitizeFileName
*
2011-09-17 02:47:01 +02:00
* @ param string $str String to clean
* @ return string Cleaned string
*
2010-10-03 17:42:01 +02:00
* @ see dol_sanitizeFilename , dol_string_nospecial
2008-08-06 16:50:06 +02:00
*/
2008-10-25 23:35:27 +02:00
function dol_string_unaccent ( $str )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
if ( utf8_check ( $str ))
{
2014-09-06 14:40:43 +02:00
// See http://www.utf8-chartable.de/
2012-08-03 23:29:08 +02:00
$string = rawurlencode ( $str );
$replacements = array (
2014-09-06 14:40:43 +02:00
'%C3%80' => 'A' , '%C3%81' => 'A' , '%C3%82' => 'A' , '%C3%83' => 'A' , '%C3%84' => 'A' , '%C3%85' => 'A' ,
'%C3%88' => 'E' , '%C3%89' => 'E' , '%C3%8A' => 'E' , '%C3%8B' => 'E' ,
'%C3%8C' => 'I' , '%C3%8D' => 'I' , '%C3%8E' => 'I' , '%C3%8F' => 'I' ,
'%C3%92' => 'O' , '%C3%93' => 'O' , '%C3%94' => 'O' , '%C3%95' => 'O' , '%C3%96' => 'O' ,
'%C3%99' => 'U' , '%C3%9A' => 'U' , '%C3%9B' => 'U' , '%C3%9C' => 'U' ,
'%C3%A0' => 'a' , '%C3%A1' => 'a' , '%C3%A2' => 'a' , '%C3%A3' => 'a' , '%C3%A4' => 'a' , '%C3%A5' => 'a' ,
'%C3%A7' => 'c' ,
2008-11-09 01:08:52 +01:00
'%C3%A8' => 'e' , '%C3%A9' => 'e' , '%C3%AA' => 'e' , '%C3%AB' => 'e' ,
2014-09-06 14:40:43 +02:00
'%C3%AC' => 'i' , '%C3%AD' => 'i' , '%C3%AE' => 'i' , '%C3%AF' => 'i' ,
'%C3%B1' => 'n' ,
'%C3%B2' => 'o' , '%C3%B3' => 'o' , '%C3%B4' => 'o' , '%C3%B5' => 'o' , '%C3%B6' => 'o' ,
'%C3%B9' => 'u' , '%C3%BA' => 'u' , '%C3%BB' => 'u' , '%C3%BC' => 'u' ,
'%C3%BF' => 'y'
2008-10-26 00:23:22 +02:00
);
2008-10-26 00:54:31 +02:00
$string = strtr ( $string , $replacements );
return rawurldecode ( $string );
2012-08-03 23:29:08 +02:00
}
else
{
2014-09-06 14:40:43 +02:00
// See http://www.ascii-code.com/
2012-08-03 23:29:08 +02:00
$string = strtr (
$str ,
2014-09-06 14:40:43 +02:00
" \xC0 \xC1 \xC2 \xC3 \xC4 \xC5 \xC7
2012-08-03 23:29:08 +02:00
\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
2014-09-06 14:40:43 +02:00
\xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
2012-08-03 23:29:08 +02:00
\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
2014-09-06 14:40:43 +02:00
\xF9\xFA\xFB\xFC\xFD\xFF " ,
" AAAAAAC
2012-08-03 23:29:08 +02:00
EEEEIIIIDN
OOOOOUUUY
2014-09-06 14:40:43 +02:00
aaaaaaceeee
2012-08-03 23:29:08 +02:00
iiiidnooooo
2014-09-06 14:40:43 +02:00
uuuuyy "
2012-08-03 23:29:08 +02:00
);
$string = strtr ( $string , array ( " \xC4 " => " Ae " , " \xC6 " => " AE " , " \xD6 " => " Oe " , " \xDC " => " Ue " , " \xDE " => " TH " , " \xDF " => " ss " , " \xE4 " => " ae " , " \xE6 " => " ae " , " \xF6 " => " oe " , " \xFC " => " ue " , " \xFE " => " th " ));
return $string ;
}
2008-08-06 16:50:06 +02:00
}
/**
2017-06-28 19:02:09 +02:00
* Clean a string from all punctuation characters to use it as a ref or login .
* This is a more complete function than dol_sanitizeFileName .
2011-08-17 18:18:12 +02:00
*
2015-02-20 22:51:47 +01:00
* @ param string $str String to clean
* @ param string $newstr String to replace forbidden chars with
* @ param array $badcharstoreplace List of forbidden characters
* @ return string Cleaned string
2011-09-20 13:43:14 +02:00
*
2010-10-03 17:42:01 +02:00
* @ see dol_sanitizeFilename , dol_string_unaccent
2008-08-06 16:50:06 +02:00
*/
2015-02-20 22:51:47 +01:00
function dol_string_nospecial ( $str , $newstr = '_' , $badcharstoreplace = '' )
2008-08-06 16:50:06 +02:00
{
2017-06-28 19:02:09 +02:00
$forbidden_chars_to_replace = array ( " " , " ' " , " / " , " \\ " , " : " , " * " , " ? " , " \" " , " < " , " > " , " | " , " [ " , " ] " , " , " , " ; " , " = " , '°' ); // more complete than dol_sanitizeFileName
2012-08-03 23:29:08 +02:00
$forbidden_chars_to_remove = array ();
2015-02-20 22:51:47 +01:00
if ( is_array ( $badcharstoreplace )) $forbidden_chars_to_replace = $badcharstoreplace ;
2012-08-03 23:29:08 +02:00
//$forbidden_chars_to_remove=array("(",")");
2008-10-09 19:29:32 +02:00
2012-08-03 23:29:08 +02:00
return str_replace ( $forbidden_chars_to_replace , $newstr , str_replace ( $forbidden_chars_to_remove , " " , $str ));
2008-08-06 16:50:06 +02:00
}
2014-10-16 01:01:30 +02:00
/**
* Encode string for xml usage
*
* @ param string $string String to encode
* @ return string String encoded
*/
function dolEscapeXML ( $string )
{
return strtr ( $string , array ( '\'' => ''' , '"' => '"' , '&' => '&' , '<' => '<' , '>' => '>' ));
}
2008-08-06 16:50:06 +02:00
/**
2011-05-01 12:52:10 +02:00
* Returns text escaped for inclusion into javascript code
2011-08-17 18:18:12 +02:00
*
2014-02-13 23:40:39 +01:00
* @ param string $stringtoescape String to escape
2015-02-25 18:24:36 +01:00
* @ param int $mode 0 = Escape also ' and " into ' , 1 = Escape ' but not " for usage into ' string ', 2=Escape " but not ' for usage into " string " , 3 = Escape ' and " with \
* @ param int $noescapebackslashn 0 = Escape also \n . 1 = Do not escape \n .
2014-02-13 23:40:39 +01:00
* @ return string Escaped string . Both ' and " are escaped into ' if they are escaped .
2008-08-06 16:50:06 +02:00
*/
2015-01-25 22:29:36 +01:00
function dol_escape_js ( $stringtoescape , $mode = 0 , $noescapebackslashn = 0 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
// escape quotes and backslashes, newlines, etc.
2015-01-25 22:29:36 +01:00
$substitjs = array ( " ' " => " \\ ' " , " \r " => '\\r' );
2014-02-13 23:40:39 +01:00
//$substitjs['</']='<\/'; // We removed this. Should be useless.
2015-01-25 22:29:36 +01:00
if ( empty ( $noescapebackslashn )) { $substitjs [ " \n " ] = '\\n' ; $substitjs [ '\\' ] = '\\\\' ; }
2014-02-13 23:40:39 +01:00
if ( empty ( $mode )) { $substitjs [ " ' " ] = " \\ ' " ; $substitjs [ '"' ] = " \\ ' " ; }
else if ( $mode == 1 ) $substitjs [ " ' " ] = " \\ ' " ;
else if ( $mode == 2 ) { $substitjs [ '"' ] = '\\"' ; }
2014-02-19 11:08:43 +01:00
else if ( $mode == 3 ) { $substitjs [ " ' " ] = " \\ ' " ; $substitjs [ '"' ] = " \\ \" " ; }
2012-08-03 23:29:08 +02:00
return strtr ( $stringtoescape , $substitjs );
2008-08-06 16:50:06 +02:00
}
2008-10-09 19:29:32 +02:00
2009-01-28 10:00:29 +01:00
/**
2015-06-28 23:32:38 +02:00
* Returns text escaped for inclusion in HTML alt or title tags , or into values of HTML input fields .
2011-08-17 18:18:12 +02:00
*
2011-09-03 01:57:26 +02:00
* @ param string $stringtoescape String to escape
2016-11-16 19:23:32 +01:00
* @ param int $keepb 1 = Preserve b tags ( otherwise , remove them )
2017-10-28 16:00:46 +02:00
* @ param int $keepn 1 = Preserve \r\n strings ( otherwise , replace them with escaped value )
2011-09-03 01:57:26 +02:00
* @ return string Escaped string
2014-06-21 01:26:41 +02:00
* @ see dol_string_nohtmltag
2009-01-28 10:00:29 +01:00
*/
2016-11-16 19:23:32 +01:00
function dol_escape_htmltag ( $stringtoescape , $keepb = 0 , $keepn = 0 )
2009-01-28 10:00:29 +01:00
{
2012-08-03 23:29:08 +02:00
// escape quotes and backslashes, newlines, etc.
2017-11-01 10:09:39 +01:00
$tmp = html_entity_decode ( $stringtoescape , ENT_COMPAT , 'UTF-8' ); // TODO Use htmlspecialchars_decode instead, that make only required change for html tags
2016-11-16 19:23:32 +01:00
if ( ! $keepb ) $tmp = strtr ( $tmp , array ( " <b> " => '' , '</b>' => '' ));
if ( ! $keepn ) $tmp = strtr ( $tmp , array ( " \r " => '\\r' , " \n " => '\\n' ));
2017-11-01 10:09:39 +01:00
return htmlentities ( $tmp , ENT_COMPAT , 'UTF-8' ); // TODO Use htmlspecialchars instead, that make only required change for html tags
2009-01-28 10:00:29 +01:00
}
2012-10-18 16:30:12 +02:00
2012-10-23 09:30:48 +02:00
/**
2012-10-18 16:30:12 +02:00
* Convert a string to lower . Never use strtolower because it does not works with UTF8 strings .
2012-10-23 09:30:48 +02:00
*
2012-10-18 16:30:12 +02:00
* @ param string $utf8_string String to encode
2012-10-23 09:30:48 +02:00
* @ return string String converted
2012-10-18 16:30:12 +02:00
*/
function dol_strtolower ( $utf8_string )
{
return mb_strtolower ( $utf8_string , " UTF-8 " );
}
2012-10-23 09:30:48 +02:00
/**
2012-10-18 16:30:12 +02:00
* Convert a string to upper . Never use strtolower because it does not works with UTF8 strings .
2012-10-23 09:30:48 +02:00
*
2012-10-18 16:30:12 +02:00
* @ param string $utf8_string String to encode
2012-10-23 09:30:48 +02:00
* @ return string String converted
2012-10-18 16:30:12 +02:00
*/
2012-10-28 13:57:21 +01:00
function dol_strtoupper ( $utf8_string )
{
return mb_strtoupper ( $utf8_string , " UTF-8 " );
}
2012-10-18 16:30:12 +02:00
2008-08-06 16:50:06 +02:00
/**
2011-10-03 17:19:39 +02:00
* Write log message into outputs . Possible outputs can be :
2013-01-14 17:12:13 +01:00
* SYSLOG_HANDLERS = [ " mod_syslog_file " ] file name is then defined by SYSLOG_FILE
* SYSLOG_HANDLERS = [ " mod_syslog_syslog " ] facility is then defined by SYSLOG_FACILITY
2012-04-02 18:37:37 +02:00
* Warning , syslog functions are bugged on Windows , generating memory protection faults . To solve
* this , use logging to files instead of syslog ( see setup of module ) .
2017-06-10 22:11:12 +02:00
* Note : If constant 'SYSLOG_FILE_NO_ERROR' defined , we never output any error message when writing to log fails .
2012-02-17 23:24:47 +01:00
* Note : You can get log message into html sources by adding parameter & logtohtml = 1 ( constant MAIN_LOGTOHTML must be set )
2012-04-02 18:37:37 +02:00
* This function works only if syslog module is enabled .
2011-10-03 17:19:39 +02:00
* This must not use any call to other function calling dol_syslog ( avoid infinite loop ) .
2011-08-28 18:22:09 +02:00
*
2016-07-28 14:11:41 +02:00
* @ param string $message Line to log . '' = Show nothing
2015-03-21 01:22:05 +01:00
* @ param int $level Log level
* On Windows LOG_ERR = 4 , LOG_WARNING = 5 , LOG_NOTICE = LOG_INFO = 6 , LOG_DEBUG = 6 si define_syslog_variables ou PHP 5.3 + , 7 si dolibarr
* On Linux LOG_ERR = 3 , LOG_WARNING = 4 , LOG_INFO = 6 , LOG_DEBUG = 7
* @ param int $ident 1 = Increase ident of 1 , - 1 = Decrease ident of 1
* @ param string $suffixinfilename When output is a file , append this suffix into default log filename .
* @ param string $restricttologhandler Output log only for this log handler
2012-04-02 18:37:37 +02:00
* @ return void
2008-08-06 16:50:06 +02:00
*/
2015-03-21 01:22:05 +01:00
function dol_syslog ( $message , $level = LOG_INFO , $ident = 0 , $suffixinfilename = '' , $restricttologhandler = '' )
2008-08-06 16:50:06 +02:00
{
2012-12-02 15:20:45 +01:00
global $conf , $user ;
2012-10-16 02:01:37 +02:00
// If syslog module enabled
2015-02-25 18:24:36 +01:00
if ( empty ( $conf -> syslog -> enabled )) return ;
2012-10-16 02:01:37 +02:00
2016-07-28 14:11:41 +02:00
if ( ! empty ( $message ))
2012-10-16 02:01:37 +02:00
{
2017-10-13 13:28:26 +02:00
// Test log level
$logLevels = array ( LOG_EMERG , LOG_ALERT , LOG_CRIT , LOG_ERR , LOG_WARNING , LOG_NOTICE , LOG_INFO , LOG_DEBUG );
if ( ! in_array ( $level , $logLevels , true ))
{
throw new Exception ( 'Incorrect log level' );
}
if ( $level > $conf -> global -> SYSLOG_LEVEL ) return ;
// If adding log inside HTML page is required
if ( ! empty ( $_REQUEST [ 'logtohtml' ]) && ( ! empty ( $conf -> global -> MAIN_ENABLE_LOG_TO_HTML ) || ! empty ( $conf -> global -> MAIN_LOGTOHTML ))) // MAIN_LOGTOHTML kept for backward compatibility
{
$conf -> logbuffer [] = dol_print_date ( time (), " %Y-%m-%d %H:%M:%S " ) . " " . $message ;
}
//TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output
// If enable html log tag enabled and url parameter log defined, we show output log on HTML comments
if ( ! empty ( $conf -> global -> MAIN_ENABLE_LOG_INLINE_HTML ) && ! empty ( $_GET [ " log " ]))
{
print " \n \n <!-- Log start \n " ;
print $message . " \n " ;
print " Log end --> \n " ;
}
$data = array (
'message' => $message ,
'script' => ( isset ( $_SERVER [ 'PHP_SELF' ]) ? basename ( $_SERVER [ 'PHP_SELF' ], '.php' ) : false ),
'level' => $level ,
'user' => (( is_object ( $user ) && $user -> id ) ? $user -> login : false ),
'ip' => false
);
// This is when server run behind a reverse proxy
if ( ! empty ( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ])) $data [ 'ip' ] = $_SERVER [ 'HTTP_X_FORWARDED_FOR' ] . ( empty ( $_SERVER [ " REMOTE_ADDR " ]) ? '' : '->' . $_SERVER [ 'REMOTE_ADDR' ]);
// This is when server run normally on a server
else if ( ! empty ( $_SERVER [ " REMOTE_ADDR " ])) $data [ 'ip' ] = $_SERVER [ 'REMOTE_ADDR' ];
// This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
else if ( ! empty ( $_SERVER [ 'SERVER_ADDR' ])) $data [ 'ip' ] = $_SERVER [ 'SERVER_ADDR' ];
// This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it).
else if ( ! empty ( $_SERVER [ 'COMPUTERNAME' ])) $data [ 'ip' ] = $_SERVER [ 'COMPUTERNAME' ] . ( empty ( $_SERVER [ 'USERNAME' ]) ? '' : '@' . $_SERVER [ 'USERNAME' ]);
// This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it).
else if ( ! empty ( $_SERVER [ 'LOGNAME' ])) $data [ 'ip' ] = '???@' . $_SERVER [ 'LOGNAME' ];
// Loop on each log handler and send output
foreach ( $conf -> loghandlers as $loghandlerinstance )
{
if ( $restricttologhandler && $loghandlerinstance -> code != $restricttologhandler ) continue ;
$loghandlerinstance -> export ( $data , $suffixinfilename );
}
unset ( $data );
2016-07-19 15:27:03 +02:00
}
2012-08-03 23:29:08 +02:00
2012-12-02 15:20:45 +01:00
if ( ! empty ( $ident ))
2012-10-16 02:01:37 +02:00
{
2012-12-05 11:18:45 +01:00
foreach ( $conf -> loghandlers as $loghandlerinstance )
{
$loghandlerinstance -> setIdent ( $ident );
}
2012-08-03 23:29:08 +02:00
}
2008-08-06 16:50:06 +02:00
}
2009-01-07 11:57:36 +01:00
2008-08-06 16:50:06 +02:00
/**
2010-12-28 01:10:13 +01:00
* Show tab header of a card
2011-09-03 01:57:26 +02:00
*
2016-10-07 17:53:41 +02:00
* @ param array $links Array of tabs . Currently initialized by calling a function xxx_admin_prepare_head
2013-03-10 13:23:55 +01:00
* @ param string $active Active tab name ( document ', ' info ', ' ldap ' , .... )
* @ param string $title Title
2017-03-15 11:13:30 +01:00
* @ param int $notab - 1 or 0 = Add tab header , 1 = no tab header . If you set this to 1 , using dol_fiche_end () to close tab is not required .
2013-03-10 13:23:55 +01:00
* @ param string $picto Add a picto on tab title
2013-11-30 16:57:11 +01:00
* @ param int $pictoisfullpath If 1 , image path is a full path . If you set this to 1 , you can use url returned by dol_buildpath ( '/mymodyle/img/myimg.png' , 1 ) for $picto .
2017-09-24 01:36:20 +02:00
* @ param string $morehtmlright Add more html content on right of tabs title
2018-03-06 21:51:43 +01:00
* @ param string $morecss More Css
2011-09-17 02:47:01 +02:00
* @ return void
2008-08-06 16:50:06 +02:00
*/
2018-03-06 21:51:43 +01:00
function dol_fiche_head ( $links = array (), $active = '0' , $title = '' , $notab = 0 , $picto = '' , $pictoisfullpath = 0 , $morehtmlright = '' , $morecss = '' )
2008-08-06 16:50:06 +02:00
{
2018-03-06 21:51:43 +01:00
print dol_get_fiche_head ( $links , $active , $title , $notab , $picto , $pictoisfullpath , $morehtmlright , $morecss );
2011-07-08 15:07:44 +02:00
}
/**
* Show tab header of a card
2011-09-03 01:57:26 +02:00
*
2013-03-10 13:23:55 +01:00
* @ param array $links Array of tabs
2015-09-23 19:21:59 +02:00
* @ param string $active Active tab name
2013-03-10 13:23:55 +01:00
* @ param string $title Title
2017-03-15 11:13:30 +01:00
* @ param int $notab - 1 or 0 = Add tab header , 1 = no tab header . If you set this to 1 , using dol_fiche_end () to close tab is not required .
2013-03-10 13:23:55 +01:00
* @ param string $picto Add a picto on tab title
2013-11-30 16:57:11 +01:00
* @ param int $pictoisfullpath If 1 , image path is a full path . If you set this to 1 , you can use url returned by dol_buildpath ( '/mymodyle/img/myimg.png' , 1 ) for $picto .
2017-09-24 01:36:20 +02:00
* @ param string $morehtmlright Add more html content on right of tabs title
2018-03-06 21:51:43 +01:00
* @ param string $morecss More Css
2015-02-10 10:45:48 +01:00
* @ return string
2011-07-08 15:07:44 +02:00
*/
2018-03-06 21:51:43 +01:00
function dol_get_fiche_head ( $links = array (), $active = '' , $title = '' , $notab = 0 , $picto = '' , $pictoisfullpath = 0 , $morehtmlright = '' , $morecss = '' )
2011-07-08 15:07:44 +02:00
{
2016-11-12 14:36:52 +01:00
global $conf , $langs , $hookmanager ;
2015-11-01 17:27:41 +01:00
2013-04-24 03:56:13 +02:00
$out = " \n " . '<div class="tabs" data-role="controlgroup" data-type="horizontal">' . " \n " ;
2012-08-03 23:29:08 +02:00
2017-09-24 01:36:20 +02:00
if ( $morehtmlright ) $out .= '<div class="inline-block floatright tabsElem">' . $morehtmlright . '</div>' ; // Output right area first so when space is missing, text is in front of tabs and not under.
2013-04-03 00:36:31 +02:00
// Show title
$showtitle = 1 ;
2013-04-03 15:20:56 +02:00
if ( ! empty ( $conf -> dol_optimize_smallscreen )) $showtitle = 0 ;
2013-04-03 00:36:31 +02:00
if ( ! empty ( $title ) && $showtitle )
2012-08-03 23:29:08 +02:00
{
$limittitle = 30 ;
$out .= '<a class="tabTitle">' ;
2016-05-30 01:30:28 +02:00
if ( $picto ) $out .= img_picto ( $title ,( $pictoisfullpath ? '' : 'object_' ) . $picto , '' , $pictoisfullpath ) . ' ' ;
2016-06-01 13:24:27 +02:00
$out .= '<span class="tabTitleText">' . dol_trunc ( $title , $limittitle ) . '</span>' ;
2012-08-03 23:29:08 +02:00
$out .= '</a>' ;
}
// Define max of key (max may be higher than sizeof because of hole due to module disabling some tabs).
$maxkey =- 1 ;
if ( is_array ( $links ) && ! empty ( $links ))
{
$keys = array_keys ( $links );
if ( count ( $keys )) $maxkey = max ( $keys );
}
2017-11-24 14:23:25 +01:00
if ( ! empty ( $conf -> dol_optimize_smallscreen )) $conf -> global -> MAIN_MAXTABS_IN_CARD = 2 ;
2017-09-24 01:36:20 +02:00
2012-08-03 23:29:08 +02:00
// Show tabs
2014-12-22 12:26:04 +01:00
$bactive = false ;
// if =0 we don't use the feature
2015-04-06 19:31:25 +02:00
$limittoshow = ( empty ( $conf -> global -> MAIN_MAXTABS_IN_CARD ) ? 99 : $conf -> global -> MAIN_MAXTABS_IN_CARD );
2014-12-22 12:26:04 +01:00
$displaytab = 0 ;
2015-09-15 03:33:27 +02:00
$nbintab = 0 ;
2017-10-13 13:28:26 +02:00
$popuptab = 0 ; $outmore = '' ;
2015-11-17 14:42:34 +01:00
for ( $i = 0 ; $i <= $maxkey ; $i ++ )
{
if (( is_numeric ( $active ) && $i == $active ) || ( ! empty ( $links [ $i ][ 2 ]) && ! is_numeric ( $active ) && $active == $links [ $i ][ 2 ]))
{
2017-11-24 14:23:25 +01:00
// If active tab is already present
if ( $i >= $limittoshow ) $limittoshow -- ;
2015-11-17 14:42:34 +01:00
}
}
2015-11-01 17:27:41 +01:00
2012-08-03 23:29:08 +02:00
for ( $i = 0 ; $i <= $maxkey ; $i ++ )
{
2015-04-06 19:46:10 +02:00
if (( is_numeric ( $active ) && $i == $active ) || ( ! empty ( $links [ $i ][ 2 ]) && ! is_numeric ( $active ) && $active == $links [ $i ][ 2 ]))
2012-08-03 23:29:08 +02:00
{
2014-12-22 12:26:04 +01:00
$isactive = true ;
$bactive = true ;
}
else
2017-11-24 14:23:25 +01:00
{
2014-12-22 12:26:04 +01:00
$isactive = false ;
2017-11-24 14:23:25 +01:00
}
2013-12-19 20:57:13 +01:00
2015-11-17 14:42:34 +01:00
if ( $i < $limittoshow || $isactive )
2012-08-03 23:29:08 +02:00
{
2015-04-06 19:46:10 +02:00
$out .= '<div class="inline-block tabsElem' . ( $isactive ? ' tabsElemActive' : '' ) . (( ! $isactive && ! empty ( $conf -> global -> MAIN_HIDE_INACTIVETAB_ON_PRINT )) ? ' hideonprint' : '' ) . '"><!-- id tab = ' . ( empty ( $links [ $i ][ 2 ]) ? '' : $links [ $i ][ 2 ]) . ' -->' ;
2014-12-22 12:26:04 +01:00
if ( isset ( $links [ $i ][ 2 ]) && $links [ $i ][ 2 ] == 'image' )
2012-08-03 23:29:08 +02:00
{
2014-12-22 12:26:04 +01:00
if ( ! empty ( $links [ $i ][ 0 ]))
{
2018-03-06 21:51:43 +01:00
$out .= '<a class="tabimage' . ( $morecss ? ' ' . $morecss : '' ) . '" href="' . $links [ $i ][ 0 ] . '">' . $links [ $i ][ 1 ] . '</a>' . " \n " ;
2014-12-22 12:26:04 +01:00
}
else
{
2017-11-24 14:23:25 +01:00
$out .= '<span class="tabspan">' . $links [ $i ][ 1 ] . '</span>' . " \n " ;
2014-12-22 12:26:04 +01:00
}
2012-08-03 23:29:08 +02:00
}
2014-12-22 12:26:04 +01:00
else if ( ! empty ( $links [ $i ][ 1 ]))
2012-08-03 23:29:08 +02:00
{
2014-12-22 12:26:04 +01:00
//print "x $i $active ".$links[$i][2]." z";
if ( $isactive )
{
2018-03-06 21:51:43 +01:00
$out .= '<a' . ( ! empty ( $links [ $i ][ 2 ]) ? ' id="' . $links [ $i ][ 2 ] . '"' : '' ) . ' class="tabactive tab inline-block' . ( $morecss ? ' ' . $morecss : '' ) . '" href="' . $links [ $i ][ 0 ] . '">' ;
2017-11-24 14:23:25 +01:00
$out .= $links [ $i ][ 1 ];
$out .= '</a>' . " \n " ;
2014-12-22 12:26:04 +01:00
}
else
{
2018-03-06 21:51:43 +01:00
$out .= '<a' . ( ! empty ( $links [ $i ][ 2 ]) ? ' id="' . $links [ $i ][ 2 ] . '"' : '' ) . ' class="tabunactive tab inline-block' . ( $morecss ? ' ' . $morecss : '' ) . '" href="' . $links [ $i ][ 0 ] . '">' ;
2017-11-24 14:23:25 +01:00
$out .= $links [ $i ][ 1 ];
$out .= '</a>' . " \n " ;
2014-12-22 12:26:04 +01:00
}
2012-08-03 23:29:08 +02:00
}
2014-12-22 12:26:04 +01:00
$out .= '</div>' ;
2012-08-03 23:29:08 +02:00
}
2014-12-22 12:26:04 +01:00
else
2012-08-03 23:29:08 +02:00
{
2017-10-13 13:28:26 +02:00
// The popup with the other tabs
2015-11-01 17:27:41 +01:00
if ( ! $popuptab )
2015-10-15 13:31:44 +02:00
{
2017-10-13 13:28:26 +02:00
$popuptab = 1 ;
2017-11-24 14:23:25 +01:00
$outmore .= '<div class="popuptabset wordwrap">' ; // The css used to hide/show popup
2015-10-15 13:31:44 +02:00
}
2017-11-24 14:23:25 +01:00
$outmore .= '<div class="popuptab wordwrap" style="display:inherit;">' ;
2014-12-22 12:26:04 +01:00
if ( isset ( $links [ $i ][ 2 ]) && $links [ $i ][ 2 ] == 'image' )
2012-08-03 23:29:08 +02:00
{
2014-12-22 12:26:04 +01:00
if ( ! empty ( $links [ $i ][ 0 ]))
2018-03-06 21:51:43 +01:00
$outmore .= '<a class="tabimage' . ( $morecss ? ' ' . $morecss : '' ) . '" href="' . $links [ $i ][ 0 ] . '">' . $links [ $i ][ 1 ] . '</a>' . " \n " ;
2014-12-22 12:26:04 +01:00
else
2015-05-30 23:56:42 +02:00
$outmore .= '<span class="tabspan">' . $links [ $i ][ 1 ] . '</span>' . " \n " ;
2014-12-22 12:26:04 +01:00
2012-08-03 23:29:08 +02:00
}
2014-12-22 12:26:04 +01:00
else if ( ! empty ( $links [ $i ][ 1 ]))
2017-11-24 14:23:25 +01:00
{
2018-03-06 21:51:43 +01:00
$outmore .= '<a' . ( ! empty ( $links [ $i ][ 2 ]) ? ' id="' . $links [ $i ][ 2 ] . '"' : '' ) . ' class="wordwrap inline-block' . ( $morecss ? ' ' . $morecss : '' ) . '" href="' . $links [ $i ][ 0 ] . '">' ;
2017-11-24 14:23:25 +01:00
$outmore .= preg_replace ( '/([a-z])\/([a-z])/i' , '\\1 / \\2' , $links [ $i ][ 1 ]); // Replace x/y with x / y to allow wrap on long composed texts.
$outmore .= '</a>' . " \n " ;
}
2014-12-22 12:26:04 +01:00
$outmore .= '</div>' ;
2015-11-01 17:27:41 +01:00
2015-09-15 03:33:27 +02:00
$nbintab ++ ;
2012-08-03 23:29:08 +02:00
}
2014-12-22 12:26:04 +01:00
$displaytab = $i ;
2012-08-03 23:29:08 +02:00
}
2015-10-15 13:31:44 +02:00
if ( $popuptab ) $outmore .= '</div>' ;
2015-11-01 17:27:41 +01:00
2014-12-22 12:26:04 +01:00
if ( $displaytab > $limittoshow )
{
2017-11-24 14:23:25 +01:00
$left = ( $langs -> trans ( " DIRECTION " ) == 'rtl' ? 'right' : 'left' );
$right = ( $langs -> trans ( " DIRECTION " ) == 'rtl' ? 'left' : 'right' );
2015-05-30 23:56:42 +02:00
$tabsname = str_replace ( " @ " , " " , $picto );
2015-05-25 18:14:49 +02:00
$out .= '<div id="moretabs' . $tabsname . '" class="inline-block tabsElem">' ;
2018-03-07 19:13:15 +01:00
$out .= '<a href="#" class="tab moretab inline-block tabunactive reposition">' . $langs -> trans ( " More " ) . '... (' . $nbintab . ')</a>' ;
2017-11-24 14:23:25 +01:00
$out .= '<div id="moretabsList' . $tabsname . '" style="position: absolute; ' . $left . ': -999em; text-align: ' . $left . '; margin:0px; padding:2px">' ;
$out .= $outmore ;
$out .= '</div>' ;
$out .= '<div></div>' ;
2014-12-22 12:26:04 +01:00
$out .= " </div> \n " ;
2014-12-30 21:04:02 +01:00
2014-12-22 12:26:04 +01:00
$out .= " <script> " ;
2017-11-24 14:23:25 +01:00
$out .= " $ ('#moretabs " . $tabsname . " ').mouseenter( function() { console.log('mouseenter " . $left . " '); $ ('#moretabsList " . $tabsname . " ').css(' " . $left . " ','auto');}); " ;
$out .= " $ ('#moretabs " . $tabsname . " ').mouseleave( function() { console.log('mouseleave " . $left . " '); $ ('#moretabsList " . $tabsname . " ').css(' " . $left . " ','-999em');}); " ;
2014-12-22 12:26:04 +01:00
$out .= " </script> " ;
2012-08-03 23:29:08 +02:00
}
2015-09-18 20:23:06 +02:00
$out .= " </div> \n " ;
2015-11-01 17:27:41 +01:00
2017-03-15 11:13:30 +01:00
if ( ! $notab || $notab == - 1 ) $out .= " \n " . '<div class="tabBar' . ( $notab == - 1 ? '' : ' tabBarWithBottom' ) . '">' . " \n " ;
2012-08-03 23:29:08 +02:00
2016-11-12 14:36:52 +01:00
$parameters = array ( 'tabname' => $active , 'out' => $out );
$reshook = $hookmanager -> executeHooks ( 'printTabsHead' , $parameters ); // This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead"
if ( $reshook > 0 )
{
$out = $hookmanager -> resPrint ;
}
2016-11-16 09:40:29 +01:00
2012-08-03 23:29:08 +02:00
return $out ;
2008-08-06 16:50:06 +02:00
}
2010-05-26 16:52:32 +02:00
/**
2011-07-08 15:07:44 +02:00
* Show tab footer of a card
2011-09-03 01:57:26 +02:00
*
2017-03-15 11:13:30 +01:00
* @ param int $notab - 1 or 0 = Add tab footer , 1 = no tab footer
2011-09-20 13:43:14 +02:00
* @ return void
2010-05-26 16:52:32 +02:00
*/
function dol_fiche_end ( $notab = 0 )
{
2012-08-03 23:29:08 +02:00
print dol_get_fiche_end ( $notab );
2011-07-08 15:07:44 +02:00
}
/**
* Return tab footer of a card
2011-09-03 01:57:26 +02:00
*
2017-03-15 11:13:30 +01:00
* @ param int $notab - 1 or 0 = Add tab footer , 1 = no tab footer
2015-02-10 10:45:48 +01:00
* @ return string
2011-07-08 15:07:44 +02:00
*/
function dol_get_fiche_end ( $notab = 0 )
{
2017-03-15 11:13:30 +01:00
if ( ! $notab || $notab == - 1 ) return " \n </div> \n " ;
2012-08-03 23:29:08 +02:00
else return '' ;
2010-05-26 16:52:32 +02:00
}
2015-10-10 12:01:09 +02:00
/**
2017-06-09 10:12:01 +02:00
* Show tab footer of a card .
* Note : $object -> next_prev_filter can be set to restrict select to find next or previous record by $form -> showrefnav .
2015-10-10 12:01:09 +02:00
*
2017-12-22 14:19:12 +01:00
* @ param Object $object Object to show
2015-11-06 18:57:35 +01:00
* @ param string $paramid Name of parameter to use to name the id into the URL next / previous link
2015-10-10 12:01:09 +02:00
* @ param string $morehtml More html content to output just before the nav bar
* @ param int $shownav Show Condition ( navigation is shown if value is 1 )
2017-07-25 23:02:48 +02:00
* @ param string $fieldid Nom du champ en base a utiliser pour select next et previous ( we make the select max and min on this field ) . Use 'none' for no prev / next search .
2015-10-10 12:01:09 +02:00
* @ param string $fieldref Nom du champ objet ref ( object -> ref ) a utiliser pour select next et previous
* @ param string $morehtmlref More html to show after ref
* @ param string $moreparam More param to add in nav link url .
* @ param int $nodbprefix Do not include DB prefix to forge table name
* @ param string $morehtmlleft More html code to show before ref
2016-11-11 23:17:37 +01:00
* @ param string $morehtmlstatus More html code to show under navigation arrows
2017-10-08 20:47:36 +02:00
* @ param int $onlybanner Put this to 1 , if the card will contains only a banner ( this add css 'arearefnobottom' on div )
2016-11-18 13:17:24 +01:00
* @ param string $morehtmlright More html code to show before navigation arrows
2015-10-10 12:01:09 +02:00
* @ return void
*/
2016-11-11 23:17:37 +01:00
function dol_banner_tab ( $object , $paramid , $morehtml = '' , $shownav = 1 , $fieldid = 'rowid' , $fieldref = 'ref' , $morehtmlref = '' , $moreparam = '' , $nodbprefix = 0 , $morehtmlleft = '' , $morehtmlstatus = '' , $onlybanner = 0 , $morehtmlright = '' )
2015-10-10 12:01:09 +02:00
{
2015-10-11 12:27:04 +02:00
global $conf , $form , $user , $langs ;
2015-10-10 12:01:09 +02:00
2017-04-15 03:05:04 +02:00
$error = 0 ;
2017-05-25 08:48:59 +02:00
2015-11-06 18:57:35 +01:00
$maxvisiblephotos = 1 ;
$showimage = 1 ;
2015-10-11 16:32:46 +02:00
$showbarcode = empty ( $conf -> barcode -> enabled ) ? 0 : ( $object -> barcode ? 1 : 0 );
2015-10-10 12:01:09 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && empty ( $user -> rights -> barcode -> lire_advance )) $showbarcode = 0 ;
2015-11-06 18:57:35 +01:00
$modulepart = 'unknown' ;
2017-02-13 01:36:02 +01:00
2017-05-04 19:11:19 +02:00
if ( $object -> element == 'societe' ) $modulepart = 'societe' ;
if ( $object -> element == 'contact' ) $modulepart = 'contact' ;
if ( $object -> element == 'member' ) $modulepart = 'memberphoto' ;
if ( $object -> element == 'user' ) $modulepart = 'userphoto' ;
if ( $object -> element == 'product' ) $modulepart = 'product' ;
2017-05-05 12:33:49 +02:00
2017-04-17 13:02:40 +02:00
if ( class_exists ( " Imagick " ))
{
2017-10-13 13:28:26 +02:00
if ( $object -> element == 'propal' ) $modulepart = 'propal' ;
2017-06-13 15:34:18 +02:00
if ( $object -> element == 'commande' ) $modulepart = 'commande' ;
if ( $object -> element == 'facture' ) $modulepart = 'facture' ;
if ( $object -> element == 'fichinter' ) $modulepart = 'ficheinter' ;
if ( $object -> element == 'contrat' ) $modulepart = 'contract' ;
2017-10-13 13:28:26 +02:00
if ( $object -> element == 'supplier_proposal' ) $modulepart = 'supplier_proposal' ;
2017-05-05 12:33:49 +02:00
if ( $object -> element == 'order_supplier' ) $modulepart = 'supplier_order' ;
2017-10-13 13:28:26 +02:00
if ( $object -> element == 'invoice_supplier' ) $modulepart = 'supplier_invoice' ;
2017-06-13 15:34:18 +02:00
if ( $object -> element == 'expensereport' ) $modulepart = 'expensereport' ;
2017-04-17 13:02:40 +02:00
}
2015-11-06 18:57:35 +01:00
if ( $object -> element == 'product' )
{
2017-10-13 13:28:26 +02:00
$width = 80 ; $cssclass = 'photoref' ;
$showimage = $object -> is_photo_available ( $conf -> product -> multidir_output [ $object -> entity ]);
$maxvisiblephotos = ( isset ( $conf -> global -> PRODUCT_MAX_VISIBLE_PHOTO ) ? $conf -> global -> PRODUCT_MAX_VISIBLE_PHOTO : 5 );
2015-11-06 18:57:35 +01:00
if ( $conf -> browser -> phone ) $maxvisiblephotos = 1 ;
2016-10-17 15:16:21 +02:00
if ( $showimage ) $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object -> show_photos ( $conf -> product -> multidir_output [ $object -> entity ], 'small' , $maxvisiblephotos , 0 , 0 , 0 , $width , 0 ) . '</div>' ;
2017-10-13 13:28:26 +02:00
else
{
2016-06-04 16:34:26 +02:00
if ( ! empty ( $conf -> global -> PRODUCT_NODISPLAYIFNOPHOTO )) {
$nophoto = '' ;
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>' ;
}
2017-08-22 20:20:34 +02:00
//elseif ($conf->browser->layout != 'phone') { // Show no photo link
2016-06-04 16:34:26 +02:00
$nophoto = '/public/theme/common/nophoto.png' ;
2017-04-15 03:05:04 +02:00
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo' . $modulepart . ( $cssclass ? ' ' . $cssclass : '' ) . '" alt="No photo" border="0"' . ( $width ? ' width="' . $width . '"' : '' ) . ' src="' . DOL_URL_ROOT . $nophoto . '"></div>' ;
2017-08-22 20:20:34 +02:00
//}
2017-10-13 13:28:26 +02:00
}
2015-11-06 18:57:35 +01:00
}
2016-11-16 09:40:29 +01:00
else
2015-11-06 18:57:35 +01:00
{
2017-04-17 13:02:40 +02:00
if ( $showimage )
2017-10-13 13:28:26 +02:00
{
if ( $modulepart != 'unknown' )
{
$phototoshow = '' ;
// Check if a preview file is available
if ( in_array ( $modulepart , array ( 'propal' , 'commande' , 'facture' , 'ficheinter' , 'contract' , 'supplier_order' , 'supplier_proposal' , 'supplier_invoice' , 'expensereport' )) && class_exists ( " Imagick " ))
{
$objectref = dol_sanitizeFileName ( $object -> ref );
$dir_output = $conf -> $modulepart -> dir_output . " / " ;
if ( in_array ( $modulepart , array ( 'invoice_supplier' , 'supplier_invoice' )))
{
2018-01-13 16:09:05 +01:00
$subdir = get_exdir ( $object -> id , 2 , 0 , 0 , $object , $modulepart ) . $objectref ; // the objectref dir is not include into get_exdir when used with level=2, so we add it here
2017-10-13 13:28:26 +02:00
}
else
{
2018-01-13 16:09:05 +01:00
$subdir = get_exdir ( $object -> id , 0 , 0 , 0 , $object , $modulepart );
2017-10-13 13:28:26 +02:00
}
2018-01-13 16:09:05 +01:00
2017-10-13 13:28:26 +02:00
$filepath = $dir_output . $subdir . " / " ;
$file = $filepath . $objectref . " .pdf " ;
$relativepath = $subdir . '/' . $objectref . '.pdf' ;
// Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png")
$fileimage = $file . '_preview.png' ; // If PDF has 1 page
$fileimagebis = $file . '_preview-0.png' ; // If PDF has more than one page
$relativepathimage = $relativepath . '_preview.png' ;
// Si fichier PDF existe
if ( file_exists ( $file ))
{
$encfile = urlencode ( $file );
// Conversion du PDF en image png si fichier png non existant
if ( ( ! file_exists ( $fileimage ) || ( filemtime ( $fileimage ) < filemtime ( $file )))
&& ( ! file_exists ( $fileimagebis ) || ( filemtime ( $fileimagebis ) < filemtime ( $file )))
)
{
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_THUMBS )) // If you experienc trouble with pdf thumb generation and imagick, you can disable here.
{
$ret = dol_convert_file ( $file , 'png' , $fileimage );
if ( $ret < 0 ) $error ++ ;
}
}
$heightforphotref = 70 ;
if ( ! empty ( $conf -> dol_optimize_smallscreen )) $heightforphotref = 60 ;
// Si fichier png PDF d'1 page trouve
if ( file_exists ( $fileimage ))
{
$phototoshow = '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">' ;
$phototoshow .= '<img height="' . $heightforphotref . '" class="photo photowithmargin photowithborder" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=apercu' . $modulepart . '&file=' . urlencode ( $relativepathimage ) . '">' ;
$phototoshow .= '</div></div>' ;
}
// Si fichier png PDF de plus d'1 page trouve
elseif ( file_exists ( $fileimagebis ))
{
$preview = preg_replace ( '/\.png/' , '' , $relativepathimage ) . " -0.png " ;
$phototoshow = '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">' ;
$phototoshow .= '<img height="' . $heightforphotref . '" class="photo photowithmargin photowithborder" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=apercu' . $modulepart . '&file=' . urlencode ( $preview ) . '"><p>' ;
$phototoshow .= '</div></div>' ;
}
}
}
else if ( ! $phototoshow )
{
$phototoshow = $form -> showphoto ( $modulepart , $object , 0 , 0 , 0 , 'photoref' , 'small' , 1 , 0 , $maxvisiblephotos );
}
if ( $phototoshow )
{
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' ;
$morehtmlleft .= $phototoshow ;
$morehtmlleft .= '</div>' ;
}
}
if ( ! $phototoshow ) // Show No photo link (picto of pbject)
{
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' ;
if ( $object -> element == 'action' )
{
$width = 80 ;
$cssclass = 'photorefcenter' ;
$nophoto = img_picto ( '' , 'title_agenda' , '' , false , 1 );
}
else
{
$width = 14 ; $cssclass = 'photorefcenter' ;
$picto = $object -> picto ;
if ( $object -> element == 'project' && ! $object -> public ) $picto = 'project' ; // instead of projectpub
$nophoto = img_picto ( '' , 'object_' . $picto , '' , false , 1 );
}
$morehtmlleft .= '<!-- No photo to show -->' ;
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo' . $modulepart . ( $cssclass ? ' ' . $cssclass : '' ) . '" alt="No photo" border="0"' . ( $width ? ' width="' . $width . '"' : '' ) . ' src="' . $nophoto . '"></div></div>' ;
$morehtmlleft .= '</div>' ;
}
}
2015-11-06 18:57:35 +01:00
}
2017-05-25 08:48:59 +02:00
2016-03-25 15:53:44 +01:00
if ( $showbarcode ) $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $form -> showbarcode ( $object ) . '</div>' ;
2017-05-25 08:48:59 +02:00
2017-03-10 16:26:43 +01:00
if ( $object -> element == 'societe' )
{
2017-10-13 13:28:26 +02:00
if ( ! empty ( $conf -> use_javascript_ajax ) && $user -> rights -> societe -> creer && ! empty ( $conf -> global -> MAIN_DIRECT_STATUS_UPDATE ))
{
$morehtmlstatus .= ajax_object_onoff ( $object , 'status' , 'status' , 'InActivity' , 'ActivityCeased' );
}
2017-11-18 01:29:42 +01:00
else {
2017-11-18 01:48:16 +01:00
$morehtmlstatus .= $object -> getLibStatut ( 6 );
2017-11-18 01:29:42 +01:00
}
2016-11-16 09:40:29 +01:00
}
2015-11-06 18:57:35 +01:00
elseif ( $object -> element == 'product' )
{
2017-10-13 13:28:26 +02:00
//$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Sell").') ';
if ( ! empty ( $conf -> use_javascript_ajax ) && $user -> rights -> produit -> creer && ! empty ( $conf -> global -> MAIN_DIRECT_STATUS_UPDATE )) {
$morehtmlstatus .= ajax_object_onoff ( $object , 'status' , 'tosell' , 'ProductStatusOnSell' , 'ProductStatusNotOnSell' );
} else {
$morehtmlstatus .= '<span class="statusrefsell">' . $object -> getLibStatut ( 5 , 0 ) . '</span>' ;
}
$morehtmlstatus .= ' ' ;
//$morehtmlstatus.=$langs->trans("Status").' ('.$langs->trans("Buy").') ';
if ( ! empty ( $conf -> use_javascript_ajax ) && $user -> rights -> produit -> creer && ! empty ( $conf -> global -> MAIN_DIRECT_STATUS_UPDATE )) {
$morehtmlstatus .= ajax_object_onoff ( $object , 'status_buy' , 'tobuy' , 'ProductStatusOnBuy' , 'ProductStatusNotOnBuy' );
} else {
$morehtmlstatus .= '<span class="statusrefbuy">' . $object -> getLibStatut ( 5 , 1 ) . '</span>' ;
}
2015-11-06 18:57:35 +01:00
}
2017-04-13 15:15:44 +02:00
elseif ( in_array ( $object -> element , array ( 'facture' , 'invoice' , 'invoice_supplier' , 'chargesociales' , 'loan' )))
2016-09-21 01:25:34 +02:00
{
2017-10-13 13:28:26 +02:00
$tmptxt = $object -> getLibStatut ( 6 , $object -> totalpaye );
if ( empty ( $tmptxt ) || $tmptxt == $object -> getLibStatut ( 3 ) || $conf -> browser -> layout == 'phone' ) $tmptxt = $object -> getLibStatut ( 5 , $object -> totalpaye );
2016-11-11 23:17:37 +01:00
$morehtmlstatus .= $tmptxt ;
2016-09-21 01:25:34 +02:00
}
2017-05-25 08:48:59 +02:00
elseif ( $object -> element == 'contrat' || $object -> element == 'contract' )
2016-10-04 12:31:45 +02:00
{
2017-11-18 01:29:42 +01:00
if ( $object -> statut == 0 ) $morehtmlstatus .= $object -> getLibStatut ( 5 );
2017-10-13 13:28:26 +02:00
else $morehtmlstatus .= $object -> getLibStatut ( 4 );
2016-10-04 12:31:45 +02:00
}
2017-09-10 20:47:45 +02:00
elseif ( $object -> element == 'facturerec' )
{
2017-11-18 01:29:42 +01:00
if ( $object -> frequency == 0 ) $morehtmlstatus .= $object -> getLibStatut ( 2 );
else $morehtmlstatus .= $object -> getLibStatut ( 5 );
2017-09-10 20:47:45 +02:00
}
2018-03-06 21:51:43 +01:00
elseif ( $object -> element == 'project_task' )
{
$object -> fk_statut = 1 ;
if ( $object -> progress > 0 ) $object -> fk_statut = 2 ;
if ( $object -> progress >= 100 ) $object -> fk_statut = 3 ;
$tmptxt = $object -> getLibStatut ( 5 );
$morehtmlstatus .= $tmptxt ; // No status on task
}
2016-11-11 23:17:37 +01:00
else { // Generic case
2017-10-13 13:28:26 +02:00
$tmptxt = $object -> getLibStatut ( 6 );
if ( empty ( $tmptxt ) || $tmptxt == $object -> getLibStatut ( 3 ) || $conf -> browser -> layout == 'phone' ) $tmptxt = $object -> getLibStatut ( 5 );
2016-11-11 23:17:37 +01:00
$morehtmlstatus .= $tmptxt ;
2015-10-10 12:01:09 +02:00
}
2018-01-22 03:07:11 +01:00
// Add if object was dispatched "into accountancy"
2018-01-22 04:13:29 +01:00
if ( ! empty ( $conf -> accounting -> enabled ) && in_array ( $object -> element , array ( 'bank' , 'facture' , 'invoice' , 'invoice_supplier' , 'expensereport' )))
2018-01-22 03:07:11 +01:00
{
if ( method_exists ( $object , 'getVentilExportCompta' ))
{
$accounted = $object -> getVentilExportCompta ();
$langs -> load ( " accountancy " );
$morehtmlstatus .= '</div><div class="statusref statusrefbis">' . ( $accounted > 0 ? $langs -> trans ( " Accounted " ) : $langs -> trans ( " NotYetAccounted " ));
}
}
// Add alias for thirdparty
if ( ! empty ( $object -> name_alias )) $morehtmlref .= '<div class="refidno">' . $object -> name_alias . '</div>' ;
2017-05-25 08:48:59 +02:00
2017-04-05 14:48:24 +02:00
// Add label
if ( $object -> element == 'product' || $object -> element == 'bank_account' || $object -> element == 'project_task' )
2017-02-09 05:58:39 +01:00
{
2017-03-10 16:26:43 +01:00
if ( ! empty ( $object -> label )) $morehtmlref .= '<div class="refidno">' . $object -> label . '</div>' ;
2017-02-09 05:58:39 +01:00
}
2017-05-25 08:48:59 +02:00
2017-11-10 13:45:38 +01:00
if ( method_exists ( $object , 'getBannerAddress' ) && $object -> element != 'product' && $object -> element != 'bookmark' && $object -> element != 'ecm_directories' && $object -> element != 'ecm_files' )
2015-11-06 18:57:35 +01:00
{
2017-10-13 13:28:26 +02:00
$morehtmlref .= '<div class="refidno">' ;
$morehtmlref .= $object -> getBannerAddress ( 'refaddress' , $object );
$morehtmlref .= '</div>' ;
2015-11-06 18:57:35 +01:00
}
if ( ! empty ( $conf -> global -> MAIN_SHOW_TECHNICAL_ID ) && in_array ( $object -> element , array ( 'societe' , 'contact' , 'member' , 'product' )))
2015-10-11 12:27:04 +02:00
{
$morehtmlref .= '<div style="clear: both;"></div><div class="refidno">' ;
$morehtmlref .= $langs -> trans ( " TechnicalID " ) . ': ' . $object -> id ;
$morehtmlref .= '</div>' ;
}
2017-05-25 08:48:59 +02:00
2016-12-23 13:04:46 +01:00
print '<div class="' . ( $onlybanner ? 'arearefnobottom ' : 'arearef ' ) . 'heightref valignmiddle" width="100%">' ;
2016-11-11 23:17:37 +01:00
print $form -> showrefnav ( $object , $paramid , $morehtml , $shownav , $fieldid , $fieldref , $morehtmlref , $moreparam , $nodbprefix , $morehtmlleft , $morehtmlstatus , $morehtmlright );
2015-10-10 12:01:09 +02:00
print '</div>' ;
print '<div class="underrefbanner clearboth"></div>' ;
}
2015-11-01 17:27:41 +01:00
2015-06-05 14:02:50 +02:00
/**
* Show a string with the label tag dedicated to the HTML edit field .
*
* @ param string $langkey Translation key
* @ param string $fieldkey Key of the html select field the text refers to
* @ param int $fieldrequired 1 = Field is mandatory
2016-03-25 14:49:48 +01:00
* @ deprecated Form :: editfieldkey
2015-06-05 14:02:50 +02:00
*/
function fieldLabel ( $langkey , $fieldkey , $fieldrequired = 0 )
{
global $conf , $langs ;
$ret = '' ;
if ( $fieldrequired ) $ret .= '<span class="fieldrequired">' ;
2016-11-05 03:27:56 +01:00
if (( $conf -> dol_use_jmobile != 4 )) $ret .= '<label for="' . $fieldkey . '">' ;
2015-06-05 14:02:50 +02:00
$ret .= $langs -> trans ( $langkey );
2016-11-05 03:27:56 +01:00
if (( $conf -> dol_use_jmobile != 4 )) $ret .= '</label>' ;
2015-06-05 14:02:50 +02:00
if ( $fieldrequired ) $ret .= '</span>' ;
return $ret ;
}
2013-04-09 01:27:41 +02:00
/**
* Return string to add class property on html element with pair / impair .
2013-04-14 02:09:41 +02:00
*
2013-04-09 01:27:41 +02:00
* @ param string $var 0 or 1
* @ param string $moreclass More class to add
* @ return string String to add class onto HTML element
*/
function dol_bc ( $var , $moreclass = '' )
{
global $bc ;
$ret = ' ' . $bc [ $var ];
if ( $moreclass ) $ret = preg_replace ( '/class=\"/' , 'class="' . $moreclass . ' ' , $ret );
return $ret ;
}
2011-10-12 19:24:27 +02:00
/**
* Return a formated address ( part address / zip / town / state ) according to country rules
*
2017-11-22 09:51:46 +01:00
* @ param Object $object A company or contact object
* @ param int $withcountry 1 = Add country into address string
* @ param string $sep Separator to use to build string
* @ param Translate $outputlangs Object lang that contains language for text translation .
2017-11-22 11:14:52 +01:00
* @ param int $mode 0 = Standard output , 1 = Remove address
2017-11-22 09:51:46 +01:00
* @ return string Formated string
2015-06-14 17:38:28 +02:00
* @ see dol_print_address
2011-10-12 19:24:27 +02:00
*/
2017-11-22 11:14:52 +01:00
function dol_format_address ( $object , $withcountry = 0 , $sep = " \n " , $outputlangs = '' , $mode = 0 )
2011-10-12 19:24:27 +02:00
{
2014-11-25 14:26:45 +01:00
global $conf , $langs ;
2014-04-23 16:03:49 +02:00
2011-10-12 19:24:27 +02:00
$ret = '' ;
2016-07-30 14:49:29 +02:00
$countriesusingstate = array ( 'AU' , 'CA' , 'US' , 'IN' , 'GB' , 'ES' , 'UK' , 'TR' ); // See also MAIN_FORCE_STATE_INTO_ADDRESS
2011-10-12 19:24:27 +02:00
// Address
2017-11-22 11:14:52 +01:00
if ( empty ( $mode )) {
2017-11-22 09:51:46 +01:00
$ret .= $object -> address ;
}
2011-10-12 19:24:27 +02:00
// Zip/Town/State
2016-07-30 14:49:29 +02:00
if ( in_array ( $object -> country_code , array ( 'AU' , 'CA' , 'US' )) || ! empty ( $conf -> global -> MAIN_FORCE_STATE_INTO_ADDRESS )) // US: title firstname name \n address lines \n town, state, zip \n country
2011-10-12 19:24:27 +02:00
{
2013-04-07 17:39:08 +02:00
$ret .= ( $ret ? $sep : '' ) . $object -> town ;
2016-02-22 13:28:08 +01:00
if ( $object -> state )
2011-10-12 19:24:27 +02:00
{
2016-07-30 14:49:29 +02:00
$ret .= ( $ret ? " , " : '' ) . $object -> state ;
2011-10-12 19:24:27 +02:00
}
2016-07-30 14:49:29 +02:00
if ( $object -> zip ) $ret .= ( $ret ? " , " : '' ) . $object -> zip ;
2011-10-12 19:24:27 +02:00
}
2013-04-24 19:14:59 +02:00
else if ( in_array ( $object -> country_code , array ( 'GB' , 'UK' ))) // UK: title firstname name \n address lines \n town state \n zip \n country
2012-09-12 17:39:02 +02:00
{
2013-04-07 17:39:08 +02:00
$ret .= ( $ret ? $sep : '' ) . $object -> town ;
2016-02-22 13:28:08 +01:00
if ( $object -> state )
2012-09-15 09:02:20 +02:00
{
2016-07-30 14:49:29 +02:00
$ret .= ( $ret ? " , " : '' ) . $object -> state ;
2012-09-15 09:02:20 +02:00
}
2013-04-07 17:39:08 +02:00
if ( $object -> zip ) $ret .= ( $ret ? $sep : '' ) . $object -> zip ;
2012-09-12 17:39:02 +02:00
}
2013-07-02 09:58:09 +02:00
else if ( in_array ( $object -> country_code , array ( 'ES' , 'TR' ))) // ES: title firstname name \n address lines \n zip town \n state \n country
2013-02-19 16:02:58 +01:00
{
2013-04-07 17:39:08 +02:00
$ret .= ( $ret ? $sep : '' ) . $object -> zip ;
2015-10-10 02:10:14 +02:00
$ret .= ( $object -> town ? (( $object -> zip ? ' ' : '' ) . $object -> town ) : '' );
2016-02-22 13:28:08 +01:00
if ( $object -> state )
2013-02-19 16:02:58 +01:00
{
$ret .= " \n " . $object -> state ;
}
}
2017-11-08 11:42:02 +01:00
else if ( in_array ( $object -> country_code , array ( 'IT' ))) // IT: tile firstname name\n address lines \n zip (Code Departement) \n country
{
$ret .= ( $ret ? $sep : '' ) . $object -> zip ;
$ret .= ( $object -> town ? (( $object -> zip ? ' ' : '' ) . $object -> town ) : '' );
$ret .= ( $object -> departement_id ? ( ' (' . ( $object -> departement_id ) . ')' ) : '' );
}
2012-09-12 17:39:02 +02:00
else // Other: title firstname name \n address lines \n zip town \n country
2011-10-12 19:24:27 +02:00
{
2015-10-11 15:21:21 +02:00
$ret .= $object -> zip ? (( $ret ? $sep : '' ) . $object -> zip ) : '' ;
2016-08-01 19:37:17 +02:00
$ret .= ( $object -> town ? (( $object -> zip ? ' ' : ( $ret ? $sep : '' )) . $object -> town ) : '' );
2011-10-12 19:24:27 +02:00
if ( $object -> state && in_array ( $object -> country_code , $countriesusingstate ))
{
2015-10-10 02:10:14 +02:00
$ret .= ( $ret ? " , " : '' ) . $object -> state ;
2011-10-12 19:24:27 +02:00
}
}
2014-11-25 14:26:45 +01:00
if ( ! is_object ( $outputlangs )) $outputlangs = $langs ;
2015-01-14 19:17:58 +01:00
if ( $withcountry ) $ret .= ( $object -> country_code ? ( $ret ? $sep : '' ) . $outputlangs -> convToOutputCharset ( $outputlangs -> transnoentitiesnoconv ( " Country " . $object -> country_code )) : '' );
2013-04-07 17:39:08 +02:00
2011-10-12 19:24:27 +02:00
return $ret ;
}
2013-01-18 15:57:11 +01:00
2013-01-19 16:29:16 +01:00
/**
* Format a string .
2013-01-18 15:57:11 +01:00
*
* @ param string $fmt Format of strftime function ( http :// php . net / manual / fr / function . strftime . php )
* @ param int $ts Timesamp ( If is_gmt is true , timestamp is already includes timezone and daylight saving offset , if is_gmt is false , timestamp is a GMT timestamp and we must compensate with server PHP TZ )
* @ param int $is_gmt See comment of timestamp parameter
* @ return string A formatted string
2013-01-19 16:29:16 +01:00
*/
function dol_strftime ( $fmt , $ts = false , $is_gmt = false )
{
if (( abs ( $ts ) <= 0x7FFFFFFF )) { // check if number in 32-bit signed range
return ( $is_gmt ) ? @ gmstrftime ( $fmt , $ts ) : @ strftime ( $fmt , $ts );
2013-01-18 15:57:11 +01:00
}
2013-01-19 16:29:16 +01:00
else return 'Error date into a not supported range' ;
2013-01-18 15:57:11 +01:00
}
2008-08-06 16:50:06 +02:00
/**
2010-11-21 17:11:52 +01:00
* Output date in a string format according to outputlangs ( or langs if not defined ) .
2012-01-22 02:12:11 +01:00
* Return charset is always UTF - 8 , except if encodetoouput is defined . In this case charset is output charset
2011-09-03 01:57:26 +02:00
*
2013-11-07 21:12:11 +01:00
* @ param int $time GM Timestamps date
2013-12-13 17:36:43 +01:00
* @ param string $format Output date format ( tag of strftime function )
2011-10-03 18:10:50 +02:00
* " %d %b %Y " ,
* " %d/%m/%Y %H:%M " ,
* " %d/%m/%Y %H:%M:%S " ,
2016-12-04 21:27:08 +01:00
* " %B " = Long text of month , " %A " = Long text of day , " %b " = Short text of month , " %a " = Short text of day
2016-09-23 10:32:19 +02:00
* " day " , " daytext " , " dayhour " , " dayhourldap " , " dayhourtext " , " dayrfc " , " dayhourrfc " , " ...reduceformat "
2013-01-18 15:57:11 +01:00
* @ param string $tzoutput true or 'gmt' => string is for Greenwich location
2011-10-03 18:10:50 +02:00
* false or 'tzserver' => output string is for local PHP server TZ usage
2017-10-29 17:49:24 +01:00
* 'tzuser' => output string is for user TZ ( current browser TZ with current dst ) => In a future , we should have same behaviour than 'tzuserrel'
2017-10-12 14:59:38 +02:00
* 'tzuserrel' => output string is for user TZ ( current browser TZ with dst or not , depending on date position ) ( TODO not implemented yet )
2014-09-18 15:38:07 +02:00
* @ param Translate $outputlangs Object lang that contains language for text translation .
2011-10-03 18:10:50 +02:00
* @ param boolean $encodetooutput false = no convert into output pagecode
* @ return string Formated date or '' if time is null
*
2011-02-02 16:51:18 +01:00
* @ see dol_mktime , dol_stringtotime , dol_getdate
2008-08-06 16:50:06 +02:00
*/
2010-12-08 14:13:17 +01:00
function dol_print_date ( $time , $format = '' , $tzoutput = 'tzserver' , $outputlangs = '' , $encodetooutput = false )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2013-04-03 15:20:56 +02:00
// Clean parameters
2012-08-03 23:29:08 +02:00
$to_gmt = false ;
$offsettz = $offsetdst = 0 ;
if ( $tzoutput )
{
$to_gmt = true ; // For backward compatibility
if ( is_string ( $tzoutput ))
{
if ( $tzoutput == 'tzserver' )
{
$to_gmt = false ;
2015-07-28 18:12:45 +02:00
$offsettzstring =@ date_default_timezone_get (); // Example 'Europe/Berlin' or 'Indian/Reunion'
$offsettz = 0 ;
$offsetdst = 0 ;
2012-08-03 23:29:08 +02:00
}
2017-10-12 18:14:02 +02:00
elseif ( $tzoutput == 'tzuser' || $tzoutput == 'tzuserrel' )
2012-08-03 23:29:08 +02:00
{
$to_gmt = true ;
2015-07-28 18:12:45 +02:00
$offsettzstring = ( empty ( $_SESSION [ 'dol_tz_string' ]) ? 'UTC' : $_SESSION [ 'dol_tz_string' ]); // Example 'Europe/Berlin' or 'Indian/Reunion'
2017-10-29 17:49:24 +01:00
$offsettz = ( empty ( $_SESSION [ 'dol_tz' ]) ? 0 : $_SESSION [ 'dol_tz' ]) * 60 * 60 ; // Will not be used anymore
$offsetdst = ( empty ( $_SESSION [ 'dol_dst' ]) ? 0 : $_SESSION [ 'dol_dst' ]) * 60 * 60 ; // Will not be used anymore
2012-08-03 23:29:08 +02:00
}
}
}
if ( ! is_object ( $outputlangs )) $outputlangs = $langs ;
2013-04-03 15:20:56 +02:00
if ( ! $format ) $format = 'daytextshort' ;
2013-04-25 20:27:45 +02:00
$reduceformat = ( ! empty ( $conf -> dol_optimize_smallscreen ) && in_array ( $format , array ( 'day' , 'dayhour' ))) ? 1 : 0 ;
2016-01-21 14:55:08 +01:00
$formatwithoutreduce = preg_replace ( '/reduceformat/' , '' , $format );
if ( $formatwithoutreduce != $format ) { $format = $formatwithoutreduce ; $reduceformat = 1 ; } // so format 'dayreduceformat' is processed like day
2016-11-16 09:40:29 +01:00
2012-08-03 23:29:08 +02:00
// Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
2016-11-16 09:40:29 +01:00
// TODO Add format daysmallyear and dayhoursmallyear
2013-04-21 17:56:29 +02:00
if ( $format == 'day' ) $format = ( $outputlangs -> trans ( " FormatDateShort " ) != " FormatDateShort " ? $outputlangs -> trans ( " FormatDateShort " ) : $conf -> format_date_short );
else if ( $format == 'hour' ) $format = ( $outputlangs -> trans ( " FormatHourShort " ) != " FormatHourShort " ? $outputlangs -> trans ( " FormatHourShort " ) : $conf -> format_hour_short );
else if ( $format == 'hourduration' ) $format = ( $outputlangs -> trans ( " FormatHourShortDuration " ) != " FormatHourShortDuration " ? $outputlangs -> trans ( " FormatHourShortDuration " ) : $conf -> format_hour_short_duration );
2013-04-03 15:20:56 +02:00
else if ( $format == 'daytext' ) $format = ( $outputlangs -> trans ( " FormatDateText " ) != " FormatDateText " ? $outputlangs -> trans ( " FormatDateText " ) : $conf -> format_date_text );
2013-04-21 17:56:29 +02:00
else if ( $format == 'daytextshort' ) $format = ( $outputlangs -> trans ( " FormatDateTextShort " ) != " FormatDateTextShort " ? $outputlangs -> trans ( " FormatDateTextShort " ) : $conf -> format_date_text_short );
2013-04-03 15:20:56 +02:00
else if ( $format == 'dayhour' ) $format = ( $outputlangs -> trans ( " FormatDateHourShort " ) != " FormatDateHourShort " ? $outputlangs -> trans ( " FormatDateHourShort " ) : $conf -> format_date_hour_short );
else if ( $format == 'dayhoursec' ) $format = ( $outputlangs -> trans ( " FormatDateHourSecShort " ) != " FormatDateHourSecShort " ? $outputlangs -> trans ( " FormatDateHourSecShort " ) : $conf -> format_date_hour_sec_short );
else if ( $format == 'dayhourtext' ) $format = ( $outputlangs -> trans ( " FormatDateHourText " ) != " FormatDateHourText " ? $outputlangs -> trans ( " FormatDateHourText " ) : $conf -> format_date_hour_text );
else if ( $format == 'dayhourtextshort' ) $format = ( $outputlangs -> trans ( " FormatDateHourTextShort " ) != " FormatDateHourTextShort " ? $outputlangs -> trans ( " FormatDateHourTextShort " ) : $conf -> format_date_hour_text_short );
2012-08-03 23:29:08 +02:00
// Format not sensitive to language
2013-04-03 15:20:56 +02:00
else if ( $format == 'dayhourlog' ) $format = '%Y%m%d%H%M%S' ;
else if ( $format == 'dayhourldap' ) $format = '%Y%m%d%H%M%SZ' ;
2013-04-21 17:56:29 +02:00
else if ( $format == 'dayhourxcard' ) $format = '%Y%m%dT%H%M%SZ' ;
else if ( $format == 'dayxcard' ) $format = '%Y%m%d' ;
2013-04-03 15:20:56 +02:00
else if ( $format == 'dayrfc' ) $format = '%Y-%m-%d' ; // DATE_RFC3339
else if ( $format == 'dayhourrfc' ) $format = '%Y-%m-%dT%H:%M:%SZ' ; // DATETIME RFC3339
2013-06-05 16:24:32 +02:00
else if ( $format == 'standard' ) $format = '%Y-%m-%d %H:%M:%S' ;
2012-08-03 23:29:08 +02:00
2013-04-21 17:56:29 +02:00
if ( $reduceformat )
{
2013-06-05 16:24:32 +02:00
$format = str_replace ( '%Y' , '%y' , $format );
$format = str_replace ( 'yyyy' , 'yy' , $format );
2013-04-21 17:56:29 +02:00
}
2013-04-24 03:56:13 +02:00
2012-08-03 23:29:08 +02:00
// If date undefined or "", we return ""
if ( dol_strlen ( $time ) == 0 ) return '' ; // $time=0 allowed (it means 01/01/1970 00:00:00)
2013-04-03 15:20:56 +02:00
// Clean format
2012-08-03 23:29:08 +02:00
if ( preg_match ( '/%b/i' , $format )) // There is some text to translate
{
// We inhibate translation to text made by strftime functions. We will use trans instead later.
$format = str_replace ( '%b' , '__b__' , $format );
$format = str_replace ( '%B' , '__B__' , $format );
}
if ( preg_match ( '/%a/i' , $format )) // There is some text to translate
{
// We inhibate translation to text made by strftime functions. We will use trans instead later.
$format = str_replace ( '%a' , '__a__' , $format );
$format = str_replace ( '%A' , '__A__' , $format );
}
2015-07-28 18:12:45 +02:00
// Analyze date
2012-08-03 23:29:08 +02:00
if ( preg_match ( '/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i' , $time , $reg )
2015-07-28 18:12:45 +02:00
|| preg_match ( '/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i' , $time , $reg )) // Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
2012-08-03 23:29:08 +02:00
{
2017-10-29 17:49:24 +01:00
// TODO Remove this.
// This part of code should not be used.
dol_syslog ( " Functions.lib::dol_print_date function call with deprecated value of time in page " . $_SERVER [ " PHP_SELF " ], LOG_ERR );
2012-08-03 23:29:08 +02:00
// Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYYMMDDHHMMSS'
$syear = ( ! empty ( $reg [ 1 ]) ? $reg [ 1 ] : '' );
$smonth = ( ! empty ( $reg [ 2 ]) ? $reg [ 2 ] : '' );
$sday = ( ! empty ( $reg [ 3 ]) ? $reg [ 3 ] : '' );
$shour = ( ! empty ( $reg [ 4 ]) ? $reg [ 4 ] : '' );
$smin = ( ! empty ( $reg [ 5 ]) ? $reg [ 5 ] : '' );
$ssec = ( ! empty ( $reg [ 6 ]) ? $reg [ 6 ] : '' );
$time = dol_mktime ( $shour , $smin , $ssec , $smonth , $sday , $syear , true );
2017-10-29 17:49:24 +01:00
$ret = adodb_strftime ( $format , $time + $offsettz + $offsetdst , $to_gmt );
2012-08-03 23:29:08 +02:00
}
else
{
// Date is a timestamps
if ( $time < 100000000000 ) // Protection against bad date values
{
2017-10-29 17:49:24 +01:00
$timetouse = $time + $offsettz + $offsetdst ; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
$ret = adodb_strftime ( $format , $timetouse , $to_gmt );
2012-08-03 23:29:08 +02:00
}
else $ret = 'Bad value ' . $time . ' for date' ;
}
if ( preg_match ( '/__b__/i' , $format ))
{
2017-10-29 17:49:24 +01:00
$timetouse = $time + $offsettz + $offsetdst ; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
2012-08-03 23:29:08 +02:00
// Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs.
2017-10-29 17:49:24 +01:00
$month = adodb_strftime ( '%m' , $timetouse );
2017-10-13 13:28:26 +02:00
$month = sprintf ( " %02d " , $month ); // $month may be return with format '06' on some installation and '6' on other, so we force it to '06'.
2012-08-03 23:29:08 +02:00
if ( $encodetooutput )
{
$monthtext = $outputlangs -> transnoentities ( 'Month' . $month );
$monthtextshort = $outputlangs -> transnoentities ( 'MonthShort' . $month );
}
else
{
$monthtext = $outputlangs -> transnoentitiesnoconv ( 'Month' . $month );
$monthtextshort = $outputlangs -> transnoentitiesnoconv ( 'MonthShort' . $month );
}
//print 'monthtext='.$monthtext.' monthtextshort='.$monthtextshort;
$ret = str_replace ( '__b__' , $monthtextshort , $ret );
$ret = str_replace ( '__B__' , $monthtext , $ret );
//print 'x'.$outputlangs->charset_output.'-'.$ret.'x';
//return $ret;
}
if ( preg_match ( '/__a__/i' , $format ))
{
2017-10-29 17:49:24 +01:00
$timetouse = $time + $offsettz + $offsetdst ; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
$w = adodb_strftime ( '%w' , $timetouse ); // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
2012-08-03 23:29:08 +02:00
$dayweek = $outputlangs -> transnoentitiesnoconv ( 'Day' . $w );
$ret = str_replace ( '__A__' , $dayweek , $ret );
$ret = str_replace ( '__a__' , dol_substr ( $dayweek , 0 , 3 ), $ret );
}
return $ret ;
2008-08-06 16:50:06 +02:00
}
/**
2012-01-22 02:12:11 +01:00
* Return an array with locale date info .
2011-09-03 01:57:26 +02:00
* PHP getdate is restricted to the years 1901 - 2038 on Unix and 1970 - 2038 on Windows
2015-02-03 11:25:51 +01:00
* WARNING : This function always use PHP server timezone to return locale informations !!!
2012-01-22 02:12:11 +01:00
* Usage must be avoid .
2015-02-03 11:25:51 +01:00
* FIXME : Replace this with PHP date function and a parameter $gm
2012-01-22 02:12:11 +01:00
*
2013-11-07 21:12:11 +01:00
* @ param int $timestamp Timestamp
2012-04-02 18:37:37 +02:00
* @ param boolean $fast Fast mode
2011-10-03 18:10:50 +02:00
* @ return array Array of informations
* If no fast mode :
* 'seconds' => $secs ,
* 'minutes' => $min ,
* 'hours' => $hour ,
* 'mday' => $day ,
2015-02-03 11:25:51 +01:00
* 'wday' => $dow , 0 = sunday , 6 = saturday
2011-10-03 18:10:50 +02:00
* 'mon' => $month ,
* 'year' => $year ,
* 'yday' => floor ( $secsInYear / $_day_power ),
* 'weekday' => gmdate ( 'l' , $_day_power * ( 3 + $dow )),
* 'month' => gmdate ( 'F' , mktime ( 0 , 0 , 0 , $month , 2 , 1971 )),
* If fast mode :
* 'seconds' => $secs ,
* 'minutes' => $min ,
* 'hours' => $hour ,
* 'mday' => $day ,
* 'mon' => $month ,
* 'year' => $year ,
* 'yday' => floor ( $secsInYear / $_day_power ),
* 'leap' => $leaf ,
* 'ndays' => $ndays
2012-01-22 02:12:11 +01:00
* @ see dol_print_date , dol_stringtotime , dol_mktime
2008-08-06 16:50:06 +02:00
*/
2009-01-07 11:57:36 +01:00
function dol_getdate ( $timestamp , $fast = false )
2008-08-06 16:50:06 +02:00
{
2014-12-06 11:00:49 +01:00
global $conf ;
2014-12-18 10:09:47 +01:00
2012-08-03 23:29:08 +02:00
$usealternatemethod = false ;
if ( $timestamp <= 0 ) $usealternatemethod = true ; // <= 1970
if ( $timestamp >= 2145913200 ) $usealternatemethod = true ; // >= 2038
if ( $usealternatemethod )
{
$arrayinfo = adodb_getdate ( $timestamp , $fast );
}
else
{
$arrayinfo = getdate ( $timestamp );
}
return $arrayinfo ;
2008-08-06 16:50:06 +02:00
}
/**
2010-02-03 03:22:15 +01:00
* Return a timestamp date built from detailed informations ( by default a local PHP server timestamp )
2009-01-04 23:09:02 +01:00
* Replace function mktime not available under Windows if year < 1970
2008-10-11 00:27:11 +02:00
* PHP mktime is restricted to the years 1901 - 2038 on Unix and 1970 - 2038 on Windows
2011-09-03 01:57:26 +02:00
*
2012-01-22 02:12:11 +01:00
* @ param int $hour Hour ( can be - 1 for undefined )
* @ param int $minute Minute ( can be - 1 for undefined )
* @ param int $second Second ( can be - 1 for undefined )
* @ param int $month Month ( 1 to 12 )
* @ param int $day Day ( 1 to 31 )
* @ param int $year Year
2016-02-22 22:00:59 +01:00
* @ param mixed $gm True or 1 or 'gmt' = Input informations are GMT values
* False or 0 or 'server' = local to server TZ
* 'user' = local to user TZ
* 'tz,TimeZone' = use specified timezone
2012-01-22 02:12:11 +01:00
* @ param int $check 0 = No check on parameters ( Can use day 32 , etc ... )
2015-03-10 14:09:29 +01:00
* @ return int | string Date as a timestamp , '' or false if error
2012-01-22 02:12:11 +01:00
* @ see dol_print_date , dol_stringtotime , dol_getdate
2008-08-06 16:50:06 +02:00
*/
2012-02-05 15:13:31 +01:00
function dol_mktime ( $hour , $minute , $second , $month , $day , $year , $gm = false , $check = 1 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf ;
//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
// Clean parameters
2012-09-27 13:25:31 +02:00
if ( $hour == - 1 || empty ( $hour )) $hour = 0 ;
if ( $minute == - 1 || empty ( $minute )) $minute = 0 ;
if ( $second == - 1 || empty ( $second )) $second = 0 ;
2012-08-03 23:29:08 +02:00
// Check parameters
if ( $check )
{
if ( ! $month || ! $day ) return '' ;
if ( $day > 31 ) return '' ;
if ( $month > 12 ) return '' ;
if ( $hour < 0 || $hour > 24 ) return '' ;
if ( $minute < 0 || $minute > 60 ) return '' ;
if ( $second < 0 || $second > 60 ) return '' ;
}
2014-03-21 15:02:27 +01:00
if ( method_exists ( 'DateTime' , 'getTimestamp' ))
2012-08-03 23:29:08 +02:00
{
2014-03-21 10:13:29 +01:00
if ( empty ( $gm ) || $gm === 'server' )
2014-03-21 09:49:10 +01:00
{
2015-07-28 18:12:45 +02:00
$default_timezone =@ date_default_timezone_get (); // Example 'Europe/Berlin'
2014-03-21 10:13:29 +01:00
$localtz = new DateTimeZone ( $default_timezone );
}
else if ( $gm === 'user' )
{
2015-07-28 18:12:45 +02:00
// We use dol_tz_string first because it is more reliable.
$default_timezone = ( empty ( $_SESSION [ " dol_tz_string " ]) ? @ date_default_timezone_get () : $_SESSION [ " dol_tz_string " ]); // Example 'Europe/Berlin'
2014-07-04 13:07:53 +02:00
try {
$localtz = new DateTimeZone ( $default_timezone );
}
catch ( Exception $e )
{
dol_syslog ( " Warning dol_tz_string contains an invalid value " . $_SESSION [ " dol_tz_string " ], LOG_WARNING );
$default_timezone =@ date_default_timezone_get ();
}
2014-03-21 09:49:10 +01:00
}
2016-02-22 22:00:59 +01:00
else if ( strrpos ( $gm , " tz, " ) !== false )
{
$timezone = str_replace ( " tz, " , " " , $gm ); // Example 'tz,Europe/Berlin'
try
{
$localtz = new DateTimeZone ( $timezone );
}
catch ( Exception $e )
{
dol_syslog ( " Warning passed timezone contains an invalid value " . $timezone , LOG_WARNING );
}
}
2014-12-18 10:09:47 +01:00
2014-11-12 22:53:23 +01:00
if ( empty ( $localtz )) {
$localtz = new DateTimeZone ( 'UTC' );
}
2018-01-14 03:12:22 +01:00
//var_dump($localtz);
//var_dump($year.'-'.$month.'-'.$day.'-'.$hour.'-'.$minute);
2012-08-03 23:29:08 +02:00
$dt = new DateTime ( null , $localtz );
$dt -> setDate ( $year , $month , $day );
$dt -> setTime (( int ) $hour , ( int ) $minute , ( int ) $second );
2014-03-21 16:22:41 +01:00
$date = $dt -> getTimestamp (); // should include daylight saving time
2018-01-14 03:12:22 +01:00
//var_dump($date);
2014-10-05 01:22:17 +02:00
return $date ;
2012-08-03 23:29:08 +02:00
}
else
{
2014-03-21 16:22:41 +01:00
dol_print_error ( '' , 'PHP version must be 5.3+' );
2014-10-05 01:22:17 +02:00
return '' ;
2012-08-03 23:29:08 +02:00
}
2008-08-06 16:50:06 +02:00
}
2012-02-06 05:31:19 +01:00
/**
2017-11-25 12:11:02 +01:00
* Return date for now . In most cases , we use this function without parameters ( that means GMT time ) .
2012-02-06 05:31:19 +01:00
*
* @ param string $mode 'gmt' => we return GMT timestamp ,
* 'tzserver' => we add the PHP server timezone
* 'tzref' => we add the company timezone
* 'tzuser' => we add the user timezone
2013-11-07 21:12:11 +01:00
* @ return int $date Timestamp
2012-02-06 05:31:19 +01:00
*/
function dol_now ( $mode = 'gmt' )
{
2017-11-25 12:11:02 +01:00
$ret = 0 ;
2014-03-29 04:26:44 +01:00
// Note that gmmktime and mktime return same value (GMT) when used without parameters
2012-03-23 18:19:50 +01:00
//if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() function instead
2012-08-03 23:29:08 +02:00
if ( $mode == 'gmt' ) $ret = time (); // Time for now at greenwich.
else if ( $mode == 'tzserver' ) // Time for now with PHP server timezone added
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2012-08-03 23:29:08 +02:00
$tzsecond = getServerTimeZoneInt ( 'now' ); // Contains tz+dayling saving time
2017-11-25 12:11:02 +01:00
$ret = ( int ) dol_now ( 'gmt' ) + ( $tzsecond * 3600 );
2012-08-03 23:29:08 +02:00
}
/* else if ( $mode == 'tzref' ) // Time for now with parent company timezone is added
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2012-08-03 23:29:08 +02:00
$tzsecond = getParentCompanyTimeZoneInt (); // Contains tz+dayling saving time
$ret = dol_now ( 'gmt' ) + ( $tzsecond * 3600 );
} */
2014-03-29 04:26:44 +01:00
else if ( $mode == 'tzuser' ) // Time for now with user timezone added
2012-08-03 23:29:08 +02:00
{
//print 'eeee'.time().'-'.mktime().'-'.gmmktime();
$offsettz = ( empty ( $_SESSION [ 'dol_tz' ]) ? 0 : $_SESSION [ 'dol_tz' ]) * 60 * 60 ;
$offsetdst = ( empty ( $_SESSION [ 'dol_dst' ]) ? 0 : $_SESSION [ 'dol_dst' ]) * 60 * 60 ;
2017-11-25 12:11:02 +01:00
$ret = ( int ) dol_now ( 'gmt' ) + ( $offsettz + $offsetdst );
2012-08-03 23:29:08 +02:00
}
2017-11-25 12:11:02 +01:00
2012-08-03 23:29:08 +02:00
return $ret ;
2012-02-06 05:31:19 +01:00
}
2009-01-07 13:39:40 +01:00
/**
2011-02-02 16:51:18 +01:00
* Return string with formated size
2011-09-03 01:57:26 +02:00
*
2011-09-17 02:47:01 +02:00
* @ param int $size Size to print
* @ param int $shortvalue Tell if we want long value to use another unit ( Ex : 1.5 Kb instead of 1500 b )
* @ param int $shortunit Use short value of size unit
* @ return string Link
2009-01-07 13:39:40 +01:00
*/
2009-10-04 17:52:16 +02:00
function dol_print_size ( $size , $shortvalue = 0 , $shortunit = 0 )
2009-01-07 13:39:40 +01:00
{
2013-04-20 17:49:24 +02:00
global $conf , $langs ;
2012-08-03 23:29:08 +02:00
$level = 1024 ;
2013-04-24 03:56:13 +02:00
2013-04-20 17:49:24 +02:00
if ( ! empty ( $conf -> dol_optimize_smallscreen )) $shortunit = 1 ;
2013-04-24 03:56:13 +02:00
2012-08-03 23:29:08 +02:00
// Set value text
if ( empty ( $shortvalue ) || $size < ( $level * 10 ))
{
$ret = $size ;
$textunitshort = $langs -> trans ( " b " );
$textunitlong = $langs -> trans ( " Bytes " );
}
else
{
$ret = round ( $size / $level , 0 );
$textunitshort = $langs -> trans ( " Kb " );
$textunitlong = $langs -> trans ( " KiloBytes " );
}
// Use long or short text unit
if ( empty ( $shortunit )) { $ret .= ' ' . $textunitlong ; }
else { $ret .= ' ' . $textunitshort ; }
return $ret ;
2009-01-07 13:39:40 +01:00
}
/**
2011-07-04 10:38:51 +02:00
* Show Url link
2011-09-03 01:57:26 +02:00
*
2011-09-17 02:47:01 +02:00
* @ param string $url Url to show
* @ param string $target Target for link
* @ param int $max Max number of characters to show
2015-10-10 01:51:12 +02:00
* @ param int $withpicto With picto
2011-09-17 02:47:01 +02:00
* @ return string HTML Link
2009-01-07 13:39:40 +01:00
*/
2015-10-10 01:51:12 +02:00
function dol_print_url ( $url , $target = '_blank' , $max = 32 , $withpicto = 0 )
2009-01-07 13:39:40 +01:00
{
2015-10-10 01:51:12 +02:00
global $langs ;
2015-11-01 17:27:41 +01:00
2012-08-03 23:29:08 +02:00
if ( empty ( $url )) return '' ;
$link = '<a href="' ;
if ( ! preg_match ( '/^http/i' , $url )) $link .= 'http://' ;
$link .= $url ;
2015-10-10 01:51:12 +02:00
$link .= '"' ;
if ( $target ) $link .= ' target="' . $target . '"' ;
$link .= '>' ;
2012-08-03 23:29:08 +02:00
if ( ! preg_match ( '/^http/i' , $url )) $link .= 'http://' ;
$link .= dol_trunc ( $url , $max );
$link .= '</a>' ;
2015-10-10 01:51:12 +02:00
return '<div class="nospan float" style="margin-right: 10px">' . ( $withpicto ? img_picto ( $langs -> trans ( " Url " ), 'object_globe.png' ) . ' ' : '' ) . $link . '</div>' ;
2009-01-07 13:39:40 +01:00
}
/**
2011-07-04 10:38:51 +02:00
* Show EMail link
2011-09-03 01:57:26 +02:00
*
2011-09-17 02:47:01 +02:00
* @ param string $email EMail to show ( only email , without 'Name of recipient' before )
* @ param int $cid Id of contact if known
* @ param int $socid Id of third party if known
2014-03-26 16:02:22 +01:00
* @ param int $addlink 0 = no link , 1 = email has a html email link ( + link to create action if constant AGENDA_ADDACTIONFOREMAIL is on )
2011-09-17 02:47:01 +02:00
* @ param int $max Max number of characters to show
* @ param int $showinvalid Show warning if syntax email is wrong
2014-12-30 21:24:57 +01:00
* @ param int $withpicto Show picto
2011-09-17 02:47:01 +02:00
* @ return string HTML Link
2009-01-07 13:39:40 +01:00
*/
2014-12-30 21:04:02 +01:00
function dol_print_email ( $email , $cid = 0 , $socid = 0 , $addlink = 0 , $max = 64 , $showinvalid = 1 , $withpicto = 0 )
2009-01-07 13:39:40 +01:00
{
2012-08-03 23:29:08 +02:00
global $conf , $user , $langs ;
$newemail = $email ;
if ( empty ( $email )) return ' ' ;
if ( ! empty ( $addlink ))
{
2013-04-28 01:12:40 +02:00
$newemail = '<a style="text-overflow: ellipsis;" href="' ;
2012-08-03 23:29:08 +02:00
if ( ! preg_match ( '/^mailto:/i' , $email )) $newemail .= 'mailto:' ;
$newemail .= $email ;
$newemail .= '">' ;
$newemail .= dol_trunc ( $email , $max );
$newemail .= '</a>' ;
if ( $showinvalid && ! isValidEmail ( $email ))
{
$langs -> load ( " errors " );
$newemail .= img_warning ( $langs -> trans ( " ErrorBadEMail " , $email ));
}
2012-09-15 11:21:22 +02:00
if (( $cid || $socid ) && ! empty ( $conf -> agenda -> enabled ) && $user -> rights -> agenda -> myactions -> create )
2012-08-03 23:29:08 +02:00
{
$type = 'AC_EMAIL' ; $link = '' ;
2014-09-18 21:18:25 +02:00
if ( ! empty ( $conf -> global -> AGENDA_ADDACTIONFOREMAIL )) $link = '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&backtopage=1&actioncode=' . $type . '&contactid=' . $cid . '&socid=' . $socid . '">' . img_object ( $langs -> trans ( " AddAction " ), " calendar " ) . '</a>' ;
2014-12-30 21:04:02 +01:00
if ( $link ) $newemail = '<div>' . $newemail . ' ' . $link . '</div>' ;
2012-08-03 23:29:08 +02:00
}
}
else
{
if ( $showinvalid && ! isValidEmail ( $email ))
{
$langs -> load ( " errors " );
$newemail .= img_warning ( $langs -> trans ( " ErrorBadEMail " , $email ));
}
}
2014-12-30 21:04:02 +01:00
return '<div class="nospan float" style="margin-right: 10px">' . ( $withpicto ? img_picto ( $langs -> trans ( " EMail " ), 'object_email.png' ) . ' ' : '' ) . $newemail . '</div>' ;
2009-01-07 13:39:40 +01:00
}
2013-11-04 21:41:36 +01:00
/**
* Show Skype link
*
* @ param string $skype Skype to show ( only skype , without 'Name of recipient' before )
2015-01-04 20:17:49 +01:00
* @ param int $cid Id of contact if known
* @ param int $socid Id of third party if known
* @ param int $addlink 0 = no link to create action
* @ param int $max Max number of characters to show
* @ return string HTML Link
2013-11-04 21:41:36 +01:00
*/
function dol_print_skype ( $skype , $cid = 0 , $socid = 0 , $addlink = 0 , $max = 64 )
{
global $conf , $user , $langs ;
$newskype = $skype ;
if ( empty ( $skype )) return ' ' ;
if ( ! empty ( $addlink ))
{
2015-11-28 14:43:16 +01:00
$newskype = img_picto ( $langs -> trans ( " Skype " ), 'object_skype.png' );
$newskype .= ' ' ;
$newskype .= dol_trunc ( $skype , $max );
$newskype .= ' ' ;
$newskype .= '<a href="skype:' ;
2013-11-04 21:41:36 +01:00
$newskype .= dol_trunc ( $skype , $max );
2013-11-24 21:28:15 +01:00
$newskype .= '?call" alt="' . $langs -> trans ( " Call " ) . ' ' . $skype . '" title="' . $langs -> trans ( " Call " ) . ' ' . $skype . '">' ;
2015-11-28 14:43:16 +01:00
$newskype .= '<img src="' . DOL_URL_ROOT . '/theme/common/skype_callbutton.png" border="0">' ;
$newskype .= '</a> <a href="skype:' ;
2013-11-04 21:41:36 +01:00
$newskype .= dol_trunc ( $skype , $max );
2013-11-24 21:28:15 +01:00
$newskype .= '?chat" alt="' . $langs -> trans ( " Chat " ) . ' ' . $skype . '" title="' . $langs -> trans ( " Chat " ) . ' ' . $skype . '">' ;
2015-11-28 14:43:16 +01:00
$newskype .= '<img src="' . DOL_URL_ROOT . '/theme/common/skype_chatbutton.png" border="0">' ;
2013-11-04 21:41:36 +01:00
$newskype .= '</a>' ;
2013-11-18 12:20:53 +01:00
2013-11-04 21:41:36 +01:00
if (( $cid || $socid ) && ! empty ( $conf -> agenda -> enabled ) && $user -> rights -> agenda -> myactions -> create )
{
$type = 'AC_SKYPE' ; $link = '' ;
2014-09-18 21:18:25 +02:00
if ( ! empty ( $conf -> global -> AGENDA_ADDACTIONFORSKYPE )) $link = '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&backtopage=1&actioncode=' . $type . '&contactid=' . $cid . '&socid=' . $socid . '">' . img_object ( $langs -> trans ( " AddAction " ), " calendar " ) . '</a>' ;
2014-12-30 21:04:02 +01:00
$newskype = '<div class="divskype nowrap">' . $newskype . ( $link ? ' ' . $link : '' ) . '</div>' ;
2013-11-04 21:41:36 +01:00
}
}
else
{
$langs -> load ( " errors " );
$newskype .= img_warning ( $langs -> trans ( " ErrorBadSkype " , $skype ));
}
return $newskype ;
}
2008-08-06 16:50:06 +02:00
/**
2010-11-07 12:27:22 +01:00
* Format phone numbers according to country
2011-09-03 01:57:26 +02:00
*
2015-10-16 16:14:33 +02:00
* @ param string $phone Phone number to format
* @ param string $countrycode Country code to use for formatting
* @ param int $cid Id of contact if known
* @ param int $socid Id of third party if known
* @ param string $addlink '' = no link to create action , 'AC_TEL' = add link to clicktodial ( if module enabled ) and add link to create event ( if conf -> global -> AGENDA_ADDACTIONFORPHONE set )
* @ param string $separ Separation between numbers for a better visibility example : xx . xx . xx . xx . xx
* @ param string $withpicto Show picto
* @ param string $titlealt Text to show on alt
2016-01-22 03:07:46 +01:00
* @ param int $adddivfloat Add div float around phone .
2015-10-16 16:14:33 +02:00
* @ return string Formated phone number
2008-08-06 16:50:06 +02:00
*/
2016-01-21 22:42:10 +01:00
function dol_print_phone ( $phone , $countrycode = '' , $cid = 0 , $socid = 0 , $addlink = '' , $separ = " " , $withpicto = '' , $titlealt = '' , $adddivfloat = 0 )
2008-08-06 16:50:06 +02:00
{
2013-03-31 04:03:08 +02:00
global $conf , $user , $langs , $mysoc ;
2012-08-03 23:29:08 +02:00
// Clean phone parameter
$phone = preg_replace ( " /[ \ s.-]/ " , " " , trim ( $phone ));
if ( empty ( $phone )) { return '' ; }
2015-10-16 16:14:33 +02:00
if ( empty ( $countrycode )) $countrycode = $mysoc -> country_code ;
2012-08-03 23:29:08 +02:00
2013-04-15 22:26:03 +02:00
// Short format for small screens
if ( $conf -> dol_optimize_smallscreen ) $separ = '' ;
2012-08-03 23:29:08 +02:00
$newphone = $phone ;
2015-10-16 16:14:33 +02:00
if ( strtoupper ( $countrycode ) == " FR " )
2012-08-03 23:29:08 +02:00
{
// France
if ( dol_strlen ( $phone ) == 10 ) {
$newphone = substr ( $newphone , 0 , 2 ) . $separ . substr ( $newphone , 2 , 2 ) . $separ . substr ( $newphone , 4 , 2 ) . $separ . substr ( $newphone , 6 , 2 ) . $separ . substr ( $newphone , 8 , 2 );
}
elseif ( dol_strlen ( $newphone ) == 7 )
{
$newphone = substr ( $newphone , 0 , 3 ) . $separ . substr ( $newphone , 3 , 2 ) . $separ . substr ( $newphone , 5 , 2 );
}
elseif ( dol_strlen ( $newphone ) == 9 )
{
$newphone = substr ( $newphone , 0 , 2 ) . $separ . substr ( $newphone , 2 , 3 ) . $separ . substr ( $newphone , 5 , 2 ) . $separ . substr ( $newphone , 7 , 2 );
}
elseif ( dol_strlen ( $newphone ) == 11 )
{
$newphone = substr ( $newphone , 0 , 3 ) . $separ . substr ( $newphone , 3 , 2 ) . $separ . substr ( $newphone , 5 , 2 ) . $separ . substr ( $newphone , 7 , 2 ) . $separ . substr ( $newphone , 9 , 2 );
}
elseif ( dol_strlen ( $newphone ) == 12 )
{
$newphone = substr ( $newphone , 0 , 4 ) . $separ . substr ( $newphone , 4 , 2 ) . $separ . substr ( $newphone , 6 , 2 ) . $separ . substr ( $newphone , 8 , 2 ) . $separ . substr ( $newphone , 10 , 2 );
}
}
2016-08-01 20:18:31 +02:00
if ( strtoupper ( $countrycode ) == " CA " )
{
2017-10-13 13:28:26 +02:00
if ( dol_strlen ( $phone ) == 10 ) {
$newphone = ( $separ != '' ? '(' : '' ) . substr ( $newphone , 0 , 3 ) . ( $separ != '' ? ')' : '' ) . $separ . substr ( $newphone , 3 , 3 ) . ( $separ != '' ? '-' : '' ) . substr ( $newphone , 6 , 4 );
}
2016-08-01 20:18:31 +02:00
}
2016-11-16 09:40:29 +01:00
2015-10-26 16:20:09 +01:00
if ( ! empty ( $addlink )) // Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set)
2012-08-03 23:29:08 +02:00
{
2015-10-26 16:20:09 +01:00
if ( ! empty ( $conf -> browser -> phone ) || ( ! empty ( $conf -> clicktodial -> enabled ) && ! empty ( $conf -> global -> CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS ))) // If phone or option for, we use link of phone
2013-04-16 01:13:20 +02:00
{
2013-06-05 16:24:32 +02:00
$newphone = '<a href="tel:' . $phone . '"' ;
$newphone .= '>' . $phone . '</a>' ;
2013-04-16 01:13:20 +02:00
}
else if ( ! empty ( $conf -> clicktodial -> enabled ) && $addlink == 'AC_TEL' ) // If click to dial, we use click to dial url
2012-08-03 23:29:08 +02:00
{
if ( empty ( $user -> clicktodial_loaded )) $user -> fetch_clicktodial ();
2013-03-31 16:44:24 +02:00
// Define urlmask
$urlmask = 'ErrorClickToDialModuleNotConfigured' ;
if ( ! empty ( $conf -> global -> CLICKTODIAL_URL )) $urlmask = $conf -> global -> CLICKTODIAL_URL ;
if ( ! empty ( $user -> clicktodial_url )) $urlmask = $user -> clicktodial_url ;
2012-08-03 23:29:08 +02:00
$clicktodial_poste = ( ! empty ( $user -> clicktodial_poste ) ? urlencode ( $user -> clicktodial_poste ) : '' );
$clicktodial_login = ( ! empty ( $user -> clicktodial_login ) ? urlencode ( $user -> clicktodial_login ) : '' );
$clicktodial_password = ( ! empty ( $user -> clicktodial_password ) ? urlencode ( $user -> clicktodial_password ) : '' );
// This line is for backward compatibility
$url = sprintf ( $urlmask , urlencode ( $phone ), $clicktodial_poste , $clicktodial_login , $clicktodial_password );
// Thoose lines are for substitution
$substitarray = array ( '__PHONEFROM__' => $clicktodial_poste ,
'__PHONETO__' => urlencode ( $phone ),
'__LOGIN__' => $clicktodial_login ,
'__PASS__' => $clicktodial_password );
$url = make_substitutions ( $url , $substitarray );
$newphonesav = $newphone ;
$newphone = '<a href="' . $url . '"' ;
if ( ! empty ( $conf -> global -> CLICKTODIAL_FORCENEWTARGET )) $newphone .= ' target="_blank"' ;
$newphone .= '>' . $newphonesav . '</a>' ;
}
2012-09-15 11:21:22 +02:00
//if (($cid || $socid) && ! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2012-08-03 23:29:08 +02:00
if ( ! empty ( $conf -> agenda -> enabled ) && $user -> rights -> agenda -> myactions -> create )
{
$type = 'AC_TEL' ; $link = '' ;
if ( $addlink == 'AC_FAX' ) $type = 'AC_FAX' ;
2014-09-18 21:18:25 +02:00
if ( ! empty ( $conf -> global -> AGENDA_ADDACTIONFORPHONE )) $link = '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&backtopage=1&actioncode=' . $type . ( $cid ? '&contactid=' . $cid : '' ) . ( $socid ? '&socid=' . $socid : '' ) . '">' . img_object ( $langs -> trans ( " AddAction " ), " calendar " ) . '</a>' ;
2014-12-30 21:04:02 +01:00
if ( $link ) $newphone = '<div>' . $newphone . ' ' . $link . '</div>' ;
2012-08-03 23:29:08 +02:00
}
}
2015-10-11 12:27:04 +02:00
if ( empty ( $titlealt ))
{
$titlealt = ( $withpicto == 'fax' ? $langs -> trans ( " Fax " ) : $langs -> trans ( " Phone " ));
}
2016-01-21 22:42:10 +01:00
$rep = '' ;
2017-10-10 10:19:04 +02:00
$picto = '' ;
if ( $withpicto ){
if ( $withpicto == 'fax' ){
$picto = 'phoning_fax' ;
} elseif ( $withpicto == 'phone' ){
$picto = 'phoning' ;
} elseif ( $withpicto == 'mobile' ){
$picto = 'phoning_mobile' ;
} else {
$picto = '' ;
}
}
2016-01-21 22:42:10 +01:00
if ( $adddivfloat ) $rep .= '<div class="nospan float" style="margin-right: 10px">' ;
else $rep .= '<span style="margin-right: 10px;">' ;
2017-10-10 10:19:04 +02:00
$rep .= ( $withpicto ? img_picto ( $titlealt , 'object_' . $picto . '.png' ) . ' ' : '' ) . $newphone ;
2016-01-21 22:42:10 +01:00
if ( $adddivfloat ) $rep .= '</div>' ;
else $rep .= '</span>' ;
return $rep ;
2008-08-06 16:50:06 +02:00
}
2009-10-14 13:04:09 +02:00
/**
2010-11-07 12:27:22 +01:00
* Return an IP formated to be shown on screen
2011-09-03 01:57:26 +02:00
*
2011-10-03 18:10:50 +02:00
* @ param string $ip IP
2012-01-15 02:39:43 +01:00
* @ param int $mode 0 = return IP + country / flag , 1 = return only country / flag , 2 = return only IP
2011-10-03 18:10:50 +02:00
* @ return string Formated IP , with country if GeoIP module is enabled
2009-10-14 13:04:09 +02:00
*/
function dol_print_ip ( $ip , $mode = 0 )
2009-10-14 00:01:27 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
$ret = '' ;
if ( empty ( $mode )) $ret .= $ip ;
2017-10-28 13:36:23 +02:00
if ( $mode != 2 )
2012-08-03 23:29:08 +02:00
{
2017-10-28 13:36:23 +02:00
$countrycode = dolGetCountryCodeFromIp ( $ip );
2012-08-03 23:29:08 +02:00
if ( $countrycode ) // If success, countrycode is us, fr, ...
{
if ( file_exists ( DOL_DOCUMENT_ROOT . '/theme/common/flags/' . $countrycode . '.png' ))
{
$ret .= ' ' . img_picto ( $countrycode . ' ' . $langs -> trans ( " AccordingToGeoIPDatabase " ), DOL_URL_ROOT . '/theme/common/flags/' . $countrycode . '.png' , '' , 1 );
}
else $ret .= ' (' . $countrycode . ')' ;
}
}
return $ret ;
2011-05-12 21:01:14 +02:00
}
2009-10-17 15:47:17 +02:00
2017-10-28 13:36:23 +02:00
/**
* Return a country code from IP . Empty string if not found .
*
* @ param string $ip IP
* @ return string Country code ( 'us' , 'fr' , ... )
*/
function dolGetCountryCodeFromIp ( $ip )
{
global $conf ;
$countrycode = '' ;
if ( ! empty ( $conf -> geoipmaxmind -> enabled ))
{
$datafile = $conf -> global -> GEOIPMAXMIND_COUNTRY_DATAFILE ;
//$ip='24.24.24.24';
//$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat'; Note that this must be downloaded datafile (not same than datafile provided with ubuntu packages)
include_once DOL_DOCUMENT_ROOT . '/core/class/dolgeoip.class.php' ;
$geoip = new DolGeoIP ( 'country' , $datafile );
//print 'ip='.$ip.' databaseType='.$geoip->gi->databaseType." GEOIP_CITY_EDITION_REV1=".GEOIP_CITY_EDITION_REV1."\n";
//print "geoip_country_id_by_addr=".geoip_country_id_by_addr($geoip->gi,$ip)."\n";
$countrycode = $geoip -> getCountryCodeFromIP ( $ip );
}
return $countrycode ;
}
2011-07-03 20:31:13 +02:00
/**
* Return country code for current user .
* If software is used inside a local network , detection may fails ( we need a public ip )
2011-09-03 01:57:26 +02:00
*
2011-10-03 18:10:50 +02:00
* @ return string Country code ( fr , es , it , us , ... )
2011-07-03 20:31:13 +02:00
*/
function dol_user_country ()
{
2012-08-03 23:29:08 +02:00
global $conf , $langs , $user ;
//$ret=$user->xxx;
$ret = '' ;
if ( ! empty ( $conf -> geoipmaxmind -> enabled ))
{
$ip = $_SERVER [ " REMOTE_ADDR " ];
$datafile = $conf -> global -> GEOIPMAXMIND_COUNTRY_DATAFILE ;
//$ip='24.24.24.24';
//$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat';
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/dolgeoip.class.php' ;
2012-08-03 23:29:08 +02:00
$geoip = new DolGeoIP ( 'country' , $datafile );
$countrycode = $geoip -> getCountryCodeFromIP ( $ip );
$ret = $countrycode ;
}
return $ret ;
2011-07-03 20:31:13 +02:00
}
2011-05-12 21:01:14 +02:00
/**
* Format address string
2011-09-03 01:57:26 +02:00
*
2015-10-10 01:51:12 +02:00
* @ param string $address Address
* @ param int $htmlid Html ID ( for example 'gmap' )
* @ param int $mode thirdparty | contact | member | other
* @ param int $id Id of object
* @ param int $noprint No output . Result is the function return
2016-11-16 09:40:29 +01:00
* @ param string $charfornl Char to use instead of nl2br . '' means we use a standad nl2br .
2015-10-10 01:51:12 +02:00
* @ return string | void Nothing if noprint is 0 , formatted address if noprint is 1
2015-06-14 17:38:28 +02:00
* @ see dol_format_address
2011-05-12 21:01:14 +02:00
*/
2016-09-18 21:13:23 +02:00
function dol_print_address ( $address , $htmlid , $mode , $id , $noprint = 0 , $charfornl = '' )
2011-05-12 21:01:14 +02:00
{
2013-08-05 18:06:57 +02:00
global $conf , $user , $langs , $hookmanager ;
2012-08-03 23:29:08 +02:00
2015-10-10 01:51:12 +02:00
$out = '' ;
2015-11-01 17:27:41 +01:00
2012-08-03 23:29:08 +02:00
if ( $address )
{
2017-10-13 13:28:26 +02:00
if ( $hookmanager ) {
$parameters = array ( 'element' => $mode , 'id' => $id );
$reshook = $hookmanager -> executeHooks ( 'printAddress' , $parameters , $address );
$out .= $hookmanager -> resPrint ;
}
if ( empty ( $reshook ))
{
if ( empty ( $charfornl )) $out .= nl2br ( $address );
else $out .= preg_replace ( '/[\r\n]+/' , $charfornl , $address );
$showgmap = $showomap = 0 ;
// TODO Add a hook here
if (( $mode == 'thirdparty' || $mode == 'societe' ) && ! empty ( $conf -> google -> enabled ) && ! empty ( $conf -> global -> GOOGLE_ENABLE_GMAPS )) $showgmap = 1 ;
if ( $mode == 'contact' && ! empty ( $conf -> google -> enabled ) && ! empty ( $conf -> global -> GOOGLE_ENABLE_GMAPS_CONTACTS )) $showgmap = 1 ;
if ( $mode == 'member' && ! empty ( $conf -> google -> enabled ) && ! empty ( $conf -> global -> GOOGLE_ENABLE_GMAPS_MEMBERS )) $showgmap = 1 ;
if (( $mode == 'thirdparty' || $mode == 'societe' ) && ! empty ( $conf -> openstreetmap -> enabled ) && ! empty ( $conf -> global -> OPENSTREETMAP_ENABLE_MAPS )) $showomap = 1 ;
if ( $mode == 'contact' && ! empty ( $conf -> openstreetmap -> enabled ) && ! empty ( $conf -> global -> OPENSTREETMAP_ENABLE_MAPS_CONTACTS )) $showomap = 1 ;
if ( $mode == 'member' && ! empty ( $conf -> openstreetmap -> enabled ) && ! empty ( $conf -> global -> OPENSTREETMAP_ENABLE_MAPS_MEMBERS )) $showomap = 1 ;
if ( $showgmap )
{
$url = dol_buildpath ( '/google/gmaps.php?mode=' . $mode . '&id=' . $id , 1 );
$out .= ' <a href="' . $url . '" target="_gmaps"><img id="' . $htmlid . '" class="valigntextbottom" src="' . DOL_URL_ROOT . '/theme/common/gmap.png"></a>' ;
}
if ( $showomap )
{
$url = dol_buildpath ( '/openstreetmap/maps.php?mode=' . $mode . '&id=' . $id , 1 );
$out .= ' <a href="' . $url . '" target="_gmaps"><img id="' . $htmlid . '_openstreetmap" class="valigntextbottom" src="' . DOL_URL_ROOT . '/theme/common/gmap.png"></a>' ;
}
}
2012-08-03 23:29:08 +02:00
}
2015-10-10 01:51:12 +02:00
if ( $noprint ) return $out ;
else print $out ;
2009-10-14 00:01:27 +02:00
}
2011-05-12 21:01:14 +02:00
2009-08-11 19:58:25 +02:00
/**
2011-09-03 01:57:26 +02:00
* Return true if email syntax is ok
*
2015-06-08 17:13:23 +02:00
* @ param string $address email ( Ex : " toto@examle.com " , " John Do <johndo@example.com> " )
2015-03-19 11:47:30 +01:00
* @ param int $acceptsupervisorkey If 1 , the special string '__SUPERVISOREMAIL__' is also accepted as valid
* @ return boolean true if email syntax is OK , false if KO or empty string
2009-08-11 19:58:25 +02:00
*/
2015-03-19 11:47:30 +01:00
function isValidEmail ( $address , $acceptsupervisorkey = 0 )
2009-08-11 19:58:25 +02:00
{
2015-03-19 11:47:30 +01:00
if ( $acceptsupervisorkey && $address == '__SUPERVISOREMAIL__' ) return true ;
if ( filter_var ( $address , FILTER_VALIDATE_EMAIL )) return true ;
2014-07-18 11:18:25 +02:00
return false ;
2009-08-11 19:58:25 +02:00
}
2011-03-05 17:27:26 +01:00
/**
2011-09-03 01:57:26 +02:00
* Return true if phone number syntax is ok
2015-04-24 01:15:29 +02:00
* TODO Decide what to do with this
2011-09-03 01:57:26 +02:00
*
2012-03-18 19:23:01 +01:00
* @ param string $phone phone ( Ex : " 0601010101 " )
* @ return boolean true if phone syntax is OK , false if KO or empty string
2011-03-05 17:27:26 +01:00
*/
2012-02-19 18:34:22 +01:00
function isValidPhone ( $phone )
2011-03-05 17:27:26 +01:00
{
2012-08-03 23:29:08 +02:00
return true ;
2011-03-05 17:27:26 +01:00
}
2008-08-06 16:50:06 +02:00
2008-11-17 00:43:10 +01:00
/**
2011-09-03 01:57:26 +02:00
* Make a strlen call . Works even if mbstring module not enabled
*
* @ param string $string String to calculate length
* @ param string $stringencoding Encoding of string
* @ return int Length of string
2008-11-17 00:43:10 +01:00
*/
2010-08-24 23:29:47 +02:00
function dol_strlen ( $string , $stringencoding = 'UTF-8' )
2008-11-17 00:43:10 +01:00
{
2012-08-03 23:29:08 +02:00
if ( function_exists ( 'mb_strlen' )) return mb_strlen ( $string , $stringencoding );
else return strlen ( $string );
2008-11-17 00:43:10 +01:00
}
/**
2011-10-03 18:10:50 +02:00
* Make a substring . Works even in mbstring module is not enabled .
2011-09-03 01:57:26 +02:00
*
2011-10-03 18:10:50 +02:00
* @ param string $string String to scan
* @ param string $start Start position
* @ param int $length Length
* @ param string $stringencoding Page code used for input string encoding
* @ return string substring
2008-11-17 00:43:10 +01:00
*/
function dol_substr ( $string , $start , $length , $stringencoding = '' )
{
2012-08-03 23:29:08 +02:00
global $langs ;
if ( empty ( $stringencoding )) $stringencoding = $langs -> charset_output ;
$ret = '' ;
if ( function_exists ( 'mb_substr' ))
{
$ret = mb_substr ( $string , $start , $length , $stringencoding );
}
else
{
$ret = substr ( $string , $start , $length );
}
return $ret ;
2008-11-17 00:43:10 +01:00
}
2009-01-07 11:57:36 +01:00
2011-05-13 20:08:55 +02:00
/**
2012-02-18 12:54:23 +01:00
* Show a javascript graph .
* Do not use this function anymore . Use DolGraph class instead .
2011-11-27 02:23:55 +01:00
*
2011-11-20 15:25:08 +01:00
* @ param string $htmlid Html id name
* @ param int $width Width in pixel
* @ param int $height Height in pixel
* @ param array $data Data array
* @ param int $showlegend 1 to show legend , 0 otherwise
* @ param string $type Type of graph ( 'pie' , 'barline' )
* @ param int $showpercent Show percent ( with type = 'pie' only )
* @ param string $url Param to add an url to click values
2015-07-15 12:42:50 +02:00
* @ param int $combineother 0 = No combine , 0.05 = Combine if lower than 5 %
2016-04-22 12:11:57 +02:00
* @ param int $shownographyet Show graph to say there is not enough data
2011-11-20 15:25:08 +01:00
* @ return void
2012-02-18 12:54:23 +01:00
* @ deprecated
2015-04-23 23:21:06 +02:00
* @ see DolGraph
2011-05-13 20:08:55 +02:00
*/
2016-04-22 12:11:57 +02:00
function dol_print_graph ( $htmlid , $width , $height , $data , $showlegend = 0 , $type = 'pie' , $showpercent = 0 , $url = '' , $combineother = 0.05 , $shownographyet = 0 )
2011-05-13 20:08:55 +02:00
{
2015-04-23 23:21:06 +02:00
dol_syslog ( __FUNCTION__ . " is deprecated " , LOG_WARNING );
2011-11-20 15:25:08 +01:00
global $conf , $langs ;
global $theme_datacolor ; // To have var kept when function is called several times
2015-04-23 23:21:06 +02:00
2016-04-22 12:11:57 +02:00
if ( $shownographyet )
{
2017-10-13 13:28:26 +02:00
print '<div class="nographyet" style="width:' . $width . 'px;height:' . $height . 'px;"></div>' ;
print '<div class="nographyettext">' . $langs -> trans ( " NotEnoughDataYet " ) . '</div>' ;
return ;
2016-04-22 12:11:57 +02:00
}
2016-11-16 09:40:29 +01:00
2011-11-20 15:25:08 +01:00
if ( empty ( $conf -> use_javascript_ajax )) return ;
$jsgraphlib = 'flot' ;
$datacolor = array ();
2011-11-27 02:23:55 +01:00
2011-05-16 15:59:46 +02:00
// Load colors of theme into $datacolor array
2011-11-20 15:25:08 +01:00
$color_file = DOL_DOCUMENT_ROOT . " /theme/ " . $conf -> theme . " /graph-color.php " ;
if ( is_readable ( $color_file ))
{
2012-08-23 02:04:35 +02:00
include_once $color_file ;
2011-11-20 15:25:08 +01:00
if ( isset ( $theme_datacolor ))
{
$datacolor = array ();
foreach ( $theme_datacolor as $val )
{
$datacolor [] = " # " . sprintf ( " %02x " , $val [ 0 ]) . sprintf ( " %02x " , $val [ 1 ]) . sprintf ( " %02x " , $val [ 2 ]);
}
}
}
print '<div id="' . $htmlid . '" style="width:' . $width . 'px;height:' . $height . 'px;"></div>' ;
2011-11-27 02:23:55 +01:00
2011-11-20 15:25:08 +01:00
// We use Flot js lib
if ( $jsgraphlib == 'flot' )
{
if ( $type == 'pie' )
{
// data is array('series'=>array(serie1,serie2,...),
// 'seriestype'=>array('bar','line',...),
// 'seriescolor'=>array(0=>'#999999',1=>'#999999',...)
// 'xlabel'=>array(0=>labelx1,1=>labelx2,...));
// serieX is array('label'=>'label', data=>val)
print '
< script type = " text/javascript " >
$ ( function () {
var data = '.json_encode($data[' series ']).' ;
2011-11-27 02:23:55 +01:00
2011-11-20 15:25:08 +01:00
function plotWithOptions () {
$ . plot ( $ ( " #'. $htmlid .' " ), data ,
{
series : {
pie : {
show : true ,
2015-07-15 12:42:50 +02:00
radius : 0.8 , ' ;
if ( $combineother )
{
print '
2015-07-05 22:04:30 +02:00
combine : {
2015-07-15 12:42:50 +02:00
threshold : '.$combineother.'
}, ' ;
}
print '
2011-11-20 15:25:08 +01:00
label : {
show : true ,
2015-07-05 22:04:30 +02:00
radius : 0.9 ,
2011-11-20 15:25:08 +01:00
formatter : function ( label , series ) {
var percent = Math . round ( series . percent );
var number = series . data [ 0 ][ 1 ];
return \ '' ;
2015-07-05 22:04:30 +02:00
print '<div style="font-size:8pt;text-align:center;padding:2px;color:black;">' ;
2017-11-15 11:11:45 +01:00
if ( $url ) print '<a style="color: #FFFFFF;" border="0" href="' . $url . '">' ;
2015-07-05 22:04:30 +02:00
print '\'+' . ( $showlegend ? 'number' : 'label+\' \'+number' );
2011-11-20 15:25:08 +01:00
if ( ! empty ( $showpercent )) print '+\'<br/>\'+percent+\'%\'' ;
print '+\'' ;
if ( $url ) print '</a>' ;
print ' </ div > \ ' ;
},
background : {
2015-07-05 22:04:30 +02:00
opacity : 0.0 ,
2011-11-20 15:25:08 +01:00
color : \ ' #000000\'
2015-07-05 22:04:30 +02:00
},
2011-11-20 15:25:08 +01:00
}
}
},
zoom : {
interactive : true
},
pan : {
interactive : true
}, ' ;
if ( count ( $datacolor ))
{
print 'colors: ' . ( ! empty ( $data [ 'seriescolor' ]) ? json_encode ( $data [ 'seriescolor' ]) : json_encode ( $datacolor )) . ',' ;
}
print 'legend: {show: ' . ( $showlegend ? 'true' : 'false' ) . ' , position : \ ' ne\ ' }
});
}
plotWithOptions ();
});
</ script > ' ;
}
else if ( $type == 'barline' )
{
// data is array('series'=>array(serie1,serie2,...),
// 'seriestype'=>array('bar','line',...),
// 'seriescolor'=>array(0=>'#999999',1=>'#999999',...)
// 'xlabel'=>array(0=>labelx1,1=>labelx2,...));
2011-11-20 16:54:41 +01:00
// serieX is array('label'=>'label', data=>array(0=>y1,1=>y2,...)) with same nb of value than into xlabel
2011-11-20 15:25:08 +01:00
print '
< script type = " text/javascript " >
$ ( function () {
var data = [ ' ;
2011-11-20 16:34:30 +01:00
$i = 0 ; $outputserie = 0 ;
2011-11-20 15:25:08 +01:00
foreach ( $data [ 'series' ] as $serie )
{
2011-11-20 16:34:30 +01:00
if ( $data [ 'seriestype' ][ $i ] == 'line' ) { $i ++ ; continue ; };
2011-11-20 15:25:08 +01:00
if ( $outputserie > 0 ) print ',' ;
2011-11-20 16:34:30 +01:00
print '{ bars: { stack: 0, show: true, barWidth: 0.9, align: \'center\' }, label: \'' . dol_escape_js ( $serie [ 'label' ]) . '\', data: ' . json_encode ( $serie [ 'data' ]) . '}' . " \n " ;
2011-11-20 15:25:08 +01:00
$outputserie ++ ; $i ++ ;
}
if ( $outputserie ) print ', ' ;
//print '];
//var datalines = [';
2011-11-20 16:34:30 +01:00
$i = 0 ; $outputserie = 0 ;
2011-11-20 15:25:08 +01:00
foreach ( $data [ 'series' ] as $serie )
{
2011-11-20 16:34:30 +01:00
if ( empty ( $data [ 'seriestype' ][ $i ]) || $data [ 'seriestype' ][ $i ] == 'bar' ) { $i ++ ; continue ; };
2011-11-20 15:25:08 +01:00
if ( $outputserie > 0 ) print ',' ;
2011-11-20 16:34:30 +01:00
print '{ lines: { show: true }, label: \'' . dol_escape_js ( $serie [ 'label' ]) . '\', data: ' . json_encode ( $serie [ 'data' ]) . '}' . " \n " ;
2011-11-20 15:25:08 +01:00
$outputserie ++ ; $i ++ ;
}
print ' ];
2011-11-20 16:34:30 +01:00
var dataticks = '.json_encode($data[' xlabel ']).'
2011-11-27 02:23:55 +01:00
2011-11-20 15:25:08 +01:00
function plotWithOptions () {
$ . plot ( jQuery ( " #'. $htmlid .' " ), data ,
{
series : {
stack : 0
},
zoom : {
interactive : true
},
pan : {
interactive : true
}, ' ;
if ( count ( $datacolor ))
{
print 'colors: ' . json_encode ( $datacolor ) . ',' ;
}
print 'legend: {show: ' . ( $showlegend ? 'true' : 'false' ) . ' },
xaxis : { ticks : dataticks }
});
}
plotWithOptions ();
});
</ script > ' ;
}
2016-04-22 12:11:57 +02:00
else print 'BadValueForParameterType' ;
2011-11-20 15:25:08 +01:00
}
2011-05-13 20:08:55 +02:00
}
2008-08-06 16:50:06 +02:00
/**
2011-05-13 20:08:55 +02:00
* Truncate a string to a particular length adding '...' if string larger than length .
* If length = max length + 1 , we do no truncate to avoid having just 1 char replaced with '...' .
* MAIN_DISABLE_TRUNC = 1 can disable all truncings
2011-08-17 17:56:22 +02:00
*
2011-12-01 22:58:02 +01:00
* @ param string $string String to truncate
2017-06-30 18:30:01 +02:00
* @ param int $size Max string size visible ( excluding ... ) . 0 for no limit . WARNING : Final string size can have 3 more chars ( if we added ... , or if size was max + 1 or max + 2 or max + 3 so it does not worse to replace with ... )
2011-12-17 16:44:48 +01:00
* @ param string $trunc Where to trunc : right , left , middle ( size must be a 2 power ), wrap
2011-12-01 22:58:02 +01:00
* @ param string $stringencoding Tell what is source string encoding
2011-12-17 16:44:48 +01:00
* @ param int $nodot Truncation do not add ... after truncation . So it ' s an exact truncation .
2017-03-03 15:11:41 +01:00
* @ param int $display Trunc is use to display and can be changed for small screen . TODO Remove this param ( must be dealt with CSS )
2017-06-30 18:30:01 +02:00
* @ return string Truncated string . WARNING : length is never higher than $size if $nodot is set , but can be 3 chars higher otherwise .
2008-08-06 16:50:06 +02:00
*/
2014-12-09 20:47:54 +01:00
function dol_trunc ( $string , $size = 40 , $trunc = 'right' , $stringencoding = 'UTF-8' , $nodot = 0 , $display = 0 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf ;
if ( $size == 0 || ! empty ( $conf -> global -> MAIN_DISABLE_TRUNC )) return $string ;
2016-11-16 09:40:29 +01:00
2016-02-09 15:57:24 +01:00
if ( empty ( $stringencoding )) $stringencoding = 'UTF-8' ;
2014-12-09 20:17:13 +01:00
// reduce for small screen
2016-02-09 15:57:24 +01:00
if ( $conf -> dol_optimize_smallscreen == 1 && $display == 1 ) $size = round ( $size / 3 );
2012-08-03 23:29:08 +02:00
// We go always here
if ( $trunc == 'right' )
{
$newstring = dol_textishtml ( $string ) ? dol_string_nohtmltag ( $string , 1 ) : $string ;
2017-06-30 18:30:01 +02:00
if ( dol_strlen ( $newstring , $stringencoding ) > ( $size + ( $nodot ? 0 : 3 ))) // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
2012-08-03 23:29:08 +02:00
return dol_substr ( $newstring , 0 , $size , $stringencoding ) . ( $nodot ? '' : '...' );
else
2017-06-30 18:30:01 +02:00
//return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
2012-08-03 23:29:08 +02:00
return $string ;
}
elseif ( $trunc == 'middle' )
{
$newstring = dol_textishtml ( $string ) ? dol_string_nohtmltag ( $string , 1 ) : $string ;
if ( dol_strlen ( $newstring , $stringencoding ) > 2 && dol_strlen ( $newstring , $stringencoding ) > ( $size + 1 ))
{
$size1 = round ( $size / 2 );
$size2 = round ( $size / 2 );
return dol_substr ( $newstring , 0 , $size1 , $stringencoding ) . '...' . dol_substr ( $newstring , dol_strlen ( $newstring , $stringencoding ) - $size2 , $size2 , $stringencoding );
}
else
return $string ;
}
elseif ( $trunc == 'left' )
{
$newstring = dol_textishtml ( $string ) ? dol_string_nohtmltag ( $string , 1 ) : $string ;
2017-06-30 18:30:01 +02:00
if ( dol_strlen ( $newstring , $stringencoding ) > ( $size + ( $nodot ? 0 : 3 ))) // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
2012-08-03 23:29:08 +02:00
return '...' . dol_substr ( $newstring , dol_strlen ( $newstring , $stringencoding ) - $size , $size , $stringencoding );
else
return $string ;
}
elseif ( $trunc == 'wrap' )
{
$newstring = dol_textishtml ( $string ) ? dol_string_nohtmltag ( $string , 1 ) : $string ;
if ( dol_strlen ( $newstring , $stringencoding ) > ( $size + 1 ))
return dol_substr ( $newstring , 0 , $size , $stringencoding ) . " \n " . dol_trunc ( dol_substr ( $newstring , $size , dol_strlen ( $newstring , $stringencoding ) - $size , $stringencoding ), $size , $trunc );
else
return $string ;
}
else return 'BadParam3CallingDolTrunc' ;
2008-08-06 16:50:06 +02:00
}
/**
2011-07-18 05:49:10 +02:00
* Show picto whatever it ' s its name ( generic function )
2011-08-17 17:56:22 +02:00
*
2017-10-22 21:15:08 +02:00
* @ param string $titlealt Text on title tag for tooltip . Not used if param notitle is set to 1.
2011-09-12 19:08:02 +02:00
* @ param string $picto Name of image file to show ( 'filenew' , ... )
* If no extension provided , we use '.png' . Image must be stored into theme / xxx / img directory .
* Example : picto . png if picto . png is stored into htdocs / theme / mytheme / img
* Example : picto . png @ mymodule if picto . png is stored into htdocs / mymodule / img
* Example : / mydir / mysubdir / picto . png if picto . png is stored into htdocs / mydir / mysubdir ( pictoisfullpath must be set to 1 )
2017-03-31 14:21:51 +02:00
* @ param string $moreatt Add more attribute on img tag ( For example 'style="float: right"' )
2011-09-12 19:08:02 +02:00
* @ param int $pictoisfullpath If 1 , image path is a full path
2013-03-27 20:43:28 +01:00
* @ param int $srconly Return only content of the src attribute of img .
2013-07-26 11:12:29 +02:00
* @ param int $notitle 1 = Disable tag title . Use it if you add js tooltip , to avoid duplicate tooltip .
2017-10-22 21:15:08 +02:00
* @ param string $alt Force alt for bind peoplae
2017-11-03 14:46:45 +01:00
* @ param string $morecss Add more class css on img tag ( For example 'myclascss' )
2011-09-12 19:08:02 +02:00
* @ return string Return img tag
* @ see #img_object, #img_picto_common
2008-08-06 16:50:06 +02:00
*/
2017-11-03 14:46:45 +01:00
function img_picto ( $titlealt , $picto , $moreatt = '' , $pictoisfullpath = false , $srconly = 0 , $notitle = 0 , $alt = '' , $morecss = '' )
2008-08-06 16:50:06 +02:00
{
2017-10-20 21:39:19 +02:00
global $conf , $langs ;
2012-08-03 23:29:08 +02:00
// Define fullpathpicto to use into src
2013-03-02 14:43:36 +01:00
if ( $pictoisfullpath )
{
2012-08-04 08:45:38 +02:00
// Clean parameters
2017-07-25 23:02:48 +02:00
if ( ! preg_match ( '/(\.png|\.gif|\.svg)$/i' , $picto )) $picto .= '.png' ;
2012-08-04 08:45:38 +02:00
$fullpathpicto = $picto ;
}
2012-08-03 23:29:08 +02:00
else
{
2017-10-31 12:32:30 +01:00
//if (in_array($picto, array('switch_off', 'switch_on', 'off', 'on')))
2017-10-31 12:25:06 +01:00
if ( in_array ( $picto , array ( 'switch_off' , 'switch_on' , 'off' , 'on' )))
2017-10-20 21:39:19 +02:00
{
2017-10-31 12:25:06 +01:00
$fakey = $picto ; $facolor = '' ; $fasize = '' ;
if ( $picto == 'switch_off' ) { $fakey = 'fa-toggle-off' ; $facolor = '#999' ; $fasize = '2em' ; }
if ( $picto == 'switch_on' ) { $fakey = 'fa-toggle-on' ; $facolor = '#227722' ; $fasize = '2em' ; }
if ( $picto == 'off' ) { $fakey = 'fa-square-o' ; $fasize = '1.3em' ; }
if ( $picto == 'on' ) { $fakey = 'fa-check-square-o' ; $fasize = '1.3em' ; }
2017-10-20 21:39:19 +02:00
$enabledisablehtml = '' ;
2017-11-03 14:46:45 +01:00
$enabledisablehtml .= '<span class="fa ' . $fakey . ' valignmiddle' . ( $morecss ? ' ' . $morecss : '' ) . '" style="' . ( $fasize ? ( 'font-size: ' . $fasize . ';' ) : '' ) . ( $facolor ? ( ' color: ' . $facolor . ';' ) : '' ) . '" alt="' . dol_escape_htmltag ( $titlealt ) . '" title="' . dol_escape_htmltag ( $titlealt ) . '"' . ( $moreatt ? ' ' . $moreatt : '' ) . '">' ;
2017-10-31 12:25:06 +01:00
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) $enabledisablehtml .= $titlealt ;
2017-10-20 21:39:19 +02:00
$enabledisablehtml .= '</span>' ;
return $enabledisablehtml ;
}
2014-10-08 15:24:35 +02:00
// We forge fullpathpicto for image to $path/img/$picto. By default, we take DOL_URL_ROOT/theme/$conf->theme/img/$picto
2012-08-03 23:29:08 +02:00
$url = DOL_URL_ROOT ;
2013-03-02 14:43:36 +01:00
$theme = $conf -> theme ;
$path = 'theme/' . $theme ;
2014-10-08 14:51:16 +02:00
if ( ! empty ( $conf -> global -> MAIN_OVERWRITE_THEME_PATH )) $path = $conf -> global -> MAIN_OVERWRITE_THEME_PATH . '/theme/' . $theme ; // If the theme does not have the same name as the module
2014-10-08 15:24:35 +02:00
else if ( ! empty ( $conf -> global -> MAIN_OVERWRITE_THEME_RES )) $path = $conf -> global -> MAIN_OVERWRITE_THEME_RES . '/theme/' . $conf -> global -> MAIN_OVERWRITE_THEME_RES ; // To allow an external module to overwrite image resources whatever is activated theme
2014-10-08 14:51:16 +02:00
else if ( ! empty ( $conf -> modules_parts [ 'theme' ]) && array_key_exists ( $theme , $conf -> modules_parts [ 'theme' ])) $path = $theme . '/theme/' . $theme ; // If the theme have the same name as the module
2013-03-02 14:43:36 +01:00
// If we ask an image into $url/$mymodule/img (instead of default path)
2012-08-04 02:15:39 +02:00
if ( preg_match ( '/^([^@]+)@([^@]+)$/i' , $picto , $regs ))
{
$picto = $regs [ 1 ];
2013-03-02 14:43:36 +01:00
$path = $regs [ 2 ]; // $path is $mymodule
2012-08-04 02:15:39 +02:00
}
2017-06-02 20:01:25 +02:00
2012-08-04 08:45:38 +02:00
// Clean parameters
2017-07-25 23:02:48 +02:00
if ( ! preg_match ( '/(\.png|\.gif|\.svg)$/i' , $picto )) $picto .= '.png' ;
2013-07-07 03:26:51 +02:00
// If alt path are defined, define url where img file is, according to physical path
2014-10-08 15:24:35 +02:00
foreach ( $conf -> file -> dol_document_root as $type => $dirroot ) // ex: array(["main"]=>"/home/maindir/htdocs", ["alt0"]=>"/home/moddir0/htdocs", ...)
2013-07-07 03:26:51 +02:00
{
2013-07-07 13:17:48 +02:00
if ( $type == 'main' ) continue ;
2014-10-08 15:24:35 +02:00
if ( file_exists ( $dirroot . '/' . $path . '/img/' . $picto )) // This need a lot of time, that's why enabling alternative dir like "custom" dir is not recommanded
2013-07-07 13:17:48 +02:00
{
2013-07-15 00:58:40 +02:00
$url = DOL_URL_ROOT . $conf -> file -> dol_url_root [ $type ];
2013-07-07 13:17:48 +02:00
break ;
}
}
2012-08-03 23:29:08 +02:00
2013-03-02 14:43:36 +01:00
// $url is '' or '/custom', $path is current theme or
2012-08-04 02:15:39 +02:00
$fullpathpicto = $url . '/' . $path . '/img/' . $picto ;
2012-08-03 23:29:08 +02:00
}
2013-03-27 20:43:28 +01:00
if ( $srconly ) return $fullpathpicto ;
2014-07-29 20:21:01 +02:00
else
{
2017-10-22 21:15:08 +02:00
// tag title is used for tooltip on <a>, tag alt can be used with very simple text on image for bind people
//$tmparray=array(0=>$titlealt);
//if (empty($notitle) && preg_match('/:[^\s0-9]/',$titlealt)) $tmparray=explode(':',$titlealt); // We explode if we have TextA:TextB. Not if we have TextA: TextB
//$title=$tmparray[0];
//$alt=empty($tmparray[1])?'':$tmparray[1];
2017-10-23 10:27:50 +02:00
$title = $titlealt ;
2017-10-22 21:15:08 +02:00
return '<img src="' . $fullpathpicto . '" alt="' . dol_escape_htmltag ( $alt ) . '"' . (( $notitle || empty ( $title )) ? '' : ' title="' . dol_escape_htmltag ( $title ) . '"' ) . ( $moreatt ? ' ' . $moreatt : ' class="inline-block"' ) . '>' ; // Alt is used for accessibility, title for popup
2014-07-29 20:21:01 +02:00
}
2008-08-06 16:50:06 +02:00
}
2012-08-04 02:15:39 +02:00
/**
* Show a picto called object_picto ( generic function )
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-08-04 02:15:39 +02:00
* @ param string $picto Name of image to show object_picto ( example : user , group , action , bill , contract , propal , product , ... )
* For external modules use imagename @ mymodule to search into directory " img " of module .
2017-03-31 14:21:51 +02:00
* @ param string $moreatt Add more attribute on img tag ( ie : class = " datecallink " )
2012-08-04 02:15:39 +02:00
* @ param int $pictoisfullpath If 1 , image path is a full path
2016-10-28 17:43:29 +02:00
* @ param int $srconly Return only content of the src attribute of img .
* @ param int $notitle 1 = Disable tag title . Use it if you add js tooltip , to avoid duplicate tooltip .
2012-08-04 02:15:39 +02:00
* @ return string Return img tag
* @ see #img_picto, #img_picto_common
*/
2017-03-31 14:21:51 +02:00
function img_object ( $titlealt , $picto , $moreatt = '' , $pictoisfullpath = false , $srconly = 0 , $notitle = 0 )
2012-08-04 02:15:39 +02:00
{
2017-03-31 14:21:51 +02:00
return img_picto ( $titlealt , 'object_' . $picto , $moreatt , $pictoisfullpath , $srconly , $notitle );
2012-08-04 02:15:39 +02:00
}
2016-02-13 07:53:50 +01:00
/**
* Show weather picto
*
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
* @ param string $picto Name of image file to show ( If no extension provided , we use '.png' ) . Image must be stored into htdocs / theme / common directory .
2017-03-31 14:21:51 +02:00
* @ param string $moreatt Add more attribute on img tag
2016-02-13 07:53:50 +01:00
* @ param int $pictoisfullpath If 1 , image path is a full path
* @ return string Return img tag
* @ see #img_object, #img_picto
*/
2017-03-31 14:21:51 +02:00
function img_weather ( $titlealt , $picto , $moreatt = '' , $pictoisfullpath = 0 )
2016-02-13 07:53:50 +01:00
{
global $conf ;
if ( ! preg_match ( '/(\.png|\.gif)$/i' , $picto )) $picto .= '.png' ;
$path = DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/weather/' . $picto ;
2017-03-31 14:21:51 +02:00
return img_picto ( $titlealt , $path , $moreatt , 1 );
2016-02-13 07:53:50 +01:00
}
2008-09-02 02:27:05 +02:00
/**
2010-11-13 17:59:53 +01:00
* Show picto ( generic function )
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2011-09-12 19:08:02 +02:00
* @ param string $picto Name of image file to show ( If no extension provided , we use '.png' ) . Image must be stored into htdocs / theme / common directory .
2017-03-31 14:21:51 +02:00
* @ param string $moreatt Add more attribute on img tag
2011-09-12 19:08:02 +02:00
* @ param int $pictoisfullpath If 1 , image path is a full path
* @ return string Return img tag
* @ see #img_object, #img_picto
2008-09-02 02:27:05 +02:00
*/
2017-03-31 14:21:51 +02:00
function img_picto_common ( $titlealt , $picto , $moreatt = '' , $pictoisfullpath = 0 )
2008-09-02 02:27:05 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf ;
2012-07-30 23:23:58 +02:00
2012-08-03 23:29:08 +02:00
if ( ! preg_match ( '/(\.png|\.gif)$/i' , $picto )) $picto .= '.png' ;
2012-07-30 23:23:58 +02:00
2012-08-03 23:29:08 +02:00
if ( $pictoisfullpath ) $path = $picto ;
else
{
$path = DOL_URL_ROOT . '/theme/common/' . $picto ;
2012-08-04 08:45:38 +02:00
2012-08-03 23:29:08 +02:00
if ( ! empty ( $conf -> global -> MAIN_MODULE_CAN_OVERWRITE_COMMONICONS ))
{
$themepath = DOL_DOCUMENT_ROOT . '/theme/' . $conf -> theme . '/img/' . $picto ;
2012-07-30 23:23:58 +02:00
2012-08-04 09:56:25 +02:00
if ( file_exists ( $themepath )) $path = $themepath ;
2012-08-03 23:29:08 +02:00
}
}
2012-07-30 23:23:58 +02:00
2017-03-31 14:21:51 +02:00
return img_picto ( $titlealt , $path , $moreatt , 1 );
2008-09-02 02:27:05 +02:00
}
2008-08-06 16:50:06 +02:00
/**
2011-05-03 21:03:08 +02:00
* Show logo action
2011-08-17 17:56:22 +02:00
*
2015-05-06 23:13:07 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
* @ param string $numaction Action id or code to show
* @ return string Return an img tag
2008-08-06 16:50:06 +02:00
*/
2014-07-29 21:34:23 +02:00
function img_action ( $titlealt , $numaction )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2015-05-06 23:13:07 +02:00
if ( empty ( $titlealt ) || $titlealt == 'default' )
2012-08-03 23:29:08 +02:00
{
2015-05-06 23:13:07 +02:00
if ( $numaction == '-1' || $numaction == 'ST_NO' ) { $numaction = - 1 ; $titlealt = $langs -> transnoentitiesnoconv ( 'ChangeDoNotContact' ); }
elseif ( $numaction == '0' || $numaction == 'ST_NEVER' ) { $numaction = 0 ; $titlealt = $langs -> transnoentitiesnoconv ( 'ChangeNeverContacted' ); }
elseif ( $numaction == '1' || $numaction == 'ST_TODO' ) { $numaction = 1 ; $titlealt = $langs -> transnoentitiesnoconv ( 'ChangeToContact' ); }
elseif ( $numaction == '2' || $numaction == 'ST_PEND' ) { $numaction = 2 ; $titlealt = $langs -> transnoentitiesnoconv ( 'ChangeContactInProcess' ); }
elseif ( $numaction == '3' || $numaction == 'ST_DONE' ) { $numaction = 3 ; $titlealt = $langs -> transnoentitiesnoconv ( 'ChangeContactDone' ); }
else { $titlealt = $langs -> transnoentitiesnoconv ( 'ChangeStatus ' . $numaction ); $numaction = 0 ; }
2012-08-03 23:29:08 +02:00
}
2015-05-06 23:13:07 +02:00
if ( ! is_numeric ( $numaction )) $numaction = 0 ;
2012-08-03 23:29:08 +02:00
2014-07-29 21:34:23 +02:00
return img_picto ( $titlealt , 'stcomm' . $numaction . '.png' );
2008-08-06 16:50:06 +02:00
}
/**
2011-08-17 17:56:22 +02:00
* Show pdf logo
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2011-12-01 22:58:02 +01:00
* @ param int $size Taille de l ' icone : 3 = 16 x16px , 2 = 14 x14px
* @ return string Retourne tag img
2008-08-06 16:50:06 +02:00
*/
2014-07-29 21:34:23 +02:00
function img_pdf ( $titlealt = 'default' , $size = 3 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Show' );
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
return img_picto ( $titlealt , 'pdf' . $size . '.png' );
2008-08-06 16:50:06 +02:00
}
/**
2011-08-17 17:56:22 +02:00
* Show logo +
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2014-09-19 14:36:55 +02:00
* @ param string $other Add more attributes on img
2012-02-04 15:20:32 +01:00
* @ return string Return tag img
2008-08-06 16:50:06 +02:00
*/
2014-09-19 14:36:55 +02:00
function img_edit_add ( $titlealt = 'default' , $other = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Add' );
2012-07-30 22:36:43 +02:00
2014-09-19 14:36:55 +02:00
return img_picto ( $titlealt , 'edit_add.png' , $other );
2008-08-06 16:50:06 +02:00
}
/**
2011-08-17 17:56:22 +02:00
* Show logo -
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2014-09-19 14:36:55 +02:00
* @ param string $other Add more attributes on img
2014-07-29 21:34:23 +02:00
* @ return string Return tag img
2008-08-06 16:50:06 +02:00
*/
2014-09-19 14:36:55 +02:00
function img_edit_remove ( $titlealt = 'default' , $other = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Remove' );
2012-07-30 22:36:43 +02:00
2014-09-19 14:36:55 +02:00
return img_picto ( $titlealt , 'edit_remove.png' , $other );
2008-08-06 16:50:06 +02:00
}
/**
2011-08-17 17:56:22 +02:00
* Show logo editer / modifier fiche
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2015-03-17 00:21:17 +01:00
* @ param integer $float Si il faut y mettre le style " float: right "
2012-02-04 15:20:32 +01:00
* @ param string $other Add more attributes on img
2014-07-29 21:34:23 +02:00
* @ return string Return tag img
2008-08-06 16:50:06 +02:00
*/
2017-03-28 18:42:23 +02:00
function img_edit ( $titlealt = 'default' , $float = 0 , $other = 'class="pictoedit"' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Modify' );
2012-07-30 22:36:43 +02:00
2017-05-20 20:59:54 +02:00
return img_picto ( $titlealt , 'edit.png' , ( $float ? 'style="float: ' . ( $langs -> tab_translate [ " DIRECTION " ] == 'rtl' ? 'left' : 'right' ) . '"' : " " ) . ( $other ? ' ' . $other : '' ));
2008-08-06 16:50:06 +02:00
}
2008-10-03 01:08:14 +02:00
/**
2011-08-17 17:56:22 +02:00
* Show logo view card
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2015-03-17 00:21:17 +01:00
* @ param integer $float Si il faut y mettre le style " float: right "
2012-02-04 15:20:32 +01:00
* @ param string $other Add more attributes on img
2014-07-29 21:34:23 +02:00
* @ return string Return tag img
2008-10-03 01:08:14 +02:00
*/
2014-07-29 21:34:23 +02:00
function img_view ( $titlealt = 'default' , $float = 0 , $other = '' )
2008-10-03 01:08:14 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'View' );
2012-07-30 23:27:12 +02:00
2017-03-31 14:21:51 +02:00
$moreatt = ( $float ? 'style="float: right" ' : '' ) . $other ;
2012-08-04 08:45:38 +02:00
2017-03-31 14:21:51 +02:00
return img_picto ( $titlealt , 'view.png' , $moreatt );
2008-10-03 01:08:14 +02:00
}
2008-08-06 16:50:06 +02:00
/**
2011-03-09 00:50:27 +01:00
* Show delete logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-02-04 15:20:32 +01:00
* @ param string $other Add more attributes on img
* @ return string Retourne tag img
2008-08-06 16:50:06 +02:00
*/
2017-03-28 18:42:23 +02:00
function img_delete ( $titlealt = 'default' , $other = 'class="pictodelete"' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Delete' );
2008-08-06 16:50:06 +02:00
2014-07-29 21:34:23 +02:00
return img_picto ( $titlealt , 'delete.png' , $other );
2012-07-30 22:36:43 +02:00
}
2008-08-06 16:50:06 +02:00
2013-03-08 11:38:30 +01:00
/**
* Show printer logo
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2013-03-08 11:38:30 +01:00
* @ param string $other Add more attributes on img
* @ return string Retourne tag img
*/
2014-07-29 21:34:23 +02:00
function img_printer ( $titlealt = " default " , $other = '' )
2013-03-08 11:38:30 +01:00
{
2017-10-13 13:28:26 +02:00
global $conf , $langs ;
if ( $titlealt == " default " ) $titlealt = $langs -> trans ( " Print " );
return img_picto ( $titlealt , 'printer.png' , $other );
2013-03-08 11:38:30 +01:00
}
2017-04-09 13:12:25 +02:00
/**
2017-06-03 01:55:05 +02:00
* Show split logo
2017-04-09 13:12:25 +02:00
*
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
* @ param string $other Add more attributes on img
* @ return string Retourne tag img
*/
function img_split ( $titlealt = 'default' , $other = 'class="pictosplit"' )
{
global $conf , $langs ;
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Split' );
return img_picto ( $titlealt , 'split.png' , $other );
}
2008-08-06 16:50:06 +02:00
/**
2011-03-09 00:50:27 +01:00
* Show help logo with cursor " ? "
2011-08-17 17:56:22 +02:00
*
2017-02-17 17:11:14 +01:00
* @ param int $usehelpcursor 1 = Use help cursor , 2 = Use click pointer cursor , 0 = No specific cursor
2016-10-21 10:36:11 +02:00
* @ param int | string $usealttitle Text to use as alt title
* @ return string Return tag img
2008-08-06 16:50:06 +02:00
*/
2012-07-30 23:23:58 +02:00
function img_help ( $usehelpcursor = 1 , $usealttitle = 1 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 23:23:58 +02:00
2012-08-03 23:29:08 +02:00
if ( $usealttitle )
{
2012-09-16 15:04:55 +02:00
if ( is_string ( $usealttitle )) $usealttitle = dol_escape_htmltag ( $usealttitle );
else $usealttitle = $langs -> trans ( 'Info' );
2012-08-03 23:29:08 +02:00
}
2012-07-30 23:23:58 +02:00
2017-02-17 17:11:14 +01:00
return img_picto ( $usealttitle , 'info.png' , 'style="vertical-align: middle;' . ( $usehelpcursor == 1 ? ' cursor: help' : ( $usehelpcursor == 2 ? ' cursor: pointer' : '' )) . '"' );
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show info logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2014-07-29 21:34:23 +02:00
function img_info ( $titlealt = 'default' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Informations' );
2012-07-30 22:36:43 +02:00
2015-06-04 10:42:12 +02:00
return img_picto ( $titlealt , 'info.png' , 'style="vertical-align: middle;"' );
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show warning logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2018-01-12 01:10:03 +01:00
* @ param string $moreatt Add more attribute on img tag ( For example 'style="float: right"' ) . If 1 , add float : right . Can ' t be " class " attribute .
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2017-03-31 14:21:51 +02:00
function img_warning ( $titlealt = 'default' , $moreatt = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Warning' );
2012-07-30 22:36:43 +02:00
2017-03-31 14:21:51 +02:00
//return '<div class="imglatecoin">'.img_picto($titlealt, 'warning_white.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')).'</div>';
return img_picto ( $titlealt , 'warning.png' , 'class="pictowarning valignmiddle"' . ( $moreatt ? ( $moreatt == '1' ? ' style="float: right"' : ' ' . $moreatt ) : '' ));
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show error logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2014-07-29 21:34:23 +02:00
function img_error ( $titlealt = 'default' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Error' );
2012-07-30 22:36:43 +02:00
2017-03-30 15:39:50 +02:00
return img_picto ( $titlealt , 'error.png' , 'class="valigntextbottom"' );
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show next logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2017-03-31 14:21:51 +02:00
* @ param string $moreatt Add more attribute on img tag ( For example 'style="float: right"' )
2017-10-13 13:28:26 +02:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2017-03-31 14:21:51 +02:00
function img_next ( $titlealt = 'default' , $moreatt = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2008-08-06 16:50:06 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Next' );
2008-08-06 16:50:06 +02:00
2017-03-31 14:21:51 +02:00
//return img_picto($titlealt, 'next.png', $moreatt);
2017-03-30 15:39:50 +02:00
return '<span class="fa fa-chevron-right paddingright paddingleft" title="' . dol_escape_htmltag ( $titlealt ) . '"></span>' ;
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show previous logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2017-03-31 14:21:51 +02:00
* @ param string $moreatt Add more attribute on img tag ( For example 'style="float: right"' )
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2017-03-31 14:21:51 +02:00
function img_previous ( $titlealt = 'default' , $moreatt = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Previous' );
2012-07-30 22:36:43 +02:00
2017-03-31 14:21:51 +02:00
//return img_picto($titlealt, 'previous.png', $moreatt);
2017-03-30 15:39:50 +02:00
return '<span class="fa fa-chevron-left paddingright paddingleft" title="' . dol_escape_htmltag ( $titlealt ) . '"></span>' ;
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show down arrow logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-02-04 15:20:32 +01:00
* @ param int $selected Selected
2015-03-22 21:18:25 +01:00
* @ param string $moreclass Add more CSS classes
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2015-03-22 21:18:25 +01:00
function img_down ( $titlealt = 'default' , $selected = 0 , $moreclass = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Down' );
2012-07-30 22:36:43 +02:00
2015-03-22 21:18:25 +01:00
return img_picto ( $titlealt , ( $selected ? '1downarrow_selected.png' : '1downarrow.png' ), 'class="imgdown' . ( $moreclass ? " " . $moreclass : " " ) . '"' );
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show top arrow logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-02-04 15:20:32 +01:00
* @ param int $selected Selected
2015-03-22 21:18:25 +01:00
* @ param string $moreclass Add more CSS classes
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2015-03-22 21:18:25 +01:00
function img_up ( $titlealt = 'default' , $selected = 0 , $moreclass = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Up' );
2012-07-30 22:36:43 +02:00
2015-03-22 21:18:25 +01:00
return img_picto ( $titlealt , ( $selected ? '1uparrow_selected.png' : '1uparrow.png' ), 'class="imgup' . ( $moreclass ? " " . $moreclass : " " ) . '"' );
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show left arrow logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-02-04 15:20:32 +01:00
* @ param int $selected Selected
2017-03-31 14:21:51 +02:00
* @ param string $moreatt Add more attribute on img tag ( For example 'style="float: right"' )
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2017-03-31 14:21:51 +02:00
function img_left ( $titlealt = 'default' , $selected = 0 , $moreatt = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Left' );
2012-07-30 22:36:43 +02:00
2017-03-31 14:21:51 +02:00
return img_picto ( $titlealt , ( $selected ? '1leftarrow_selected.png' : '1leftarrow.png' ), $moreatt );
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show right arrow logo
2011-08-17 17:56:22 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-02-04 15:20:32 +01:00
* @ param int $selected Selected
2017-03-31 14:21:51 +02:00
* @ param string $moreatt Add more attribute on img tag ( For example 'style="float: right"' )
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2017-03-31 14:21:51 +02:00
function img_right ( $titlealt = 'default' , $selected = 0 , $moreatt = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Right' );
2012-07-30 22:36:43 +02:00
2017-03-31 14:21:51 +02:00
return img_picto ( $titlealt , ( $selected ? '1rightarrow_selected.png' : '1rightarrow.png' ), $moreatt );
2008-08-06 16:50:06 +02:00
}
/**
2012-07-31 14:41:15 +02:00
* Show tick logo if allowed
2011-08-17 17:56:22 +02:00
*
2012-02-04 15:20:32 +01:00
* @ param string $allow Allow
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-02-04 15:20:32 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2014-07-29 21:34:23 +02:00
function img_allow ( $allow , $titlealt = 'default' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2011-05-12 21:01:14 +02:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Active' );
2012-07-30 22:36:43 +02:00
2014-07-29 21:34:23 +02:00
if ( $allow == 1 ) return img_picto ( $titlealt , 'tick.png' );
2012-08-04 08:45:38 +02:00
2012-08-03 23:29:08 +02:00
return '-' ;
2011-05-12 21:01:14 +02:00
}
2008-08-06 16:50:06 +02:00
/**
2010-11-13 15:34:06 +01:00
* Show MIME img of a file
2012-02-12 16:50:58 +01:00
*
* @ param string $file Filename
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2017-11-10 20:20:59 +01:00
* @ param string $morecss More css
2012-02-12 16:50:58 +01:00
* @ return string Return img tag
2008-08-06 16:50:06 +02:00
*/
2017-11-10 20:20:59 +01:00
function img_mime ( $file , $titlealt = '' , $morecss = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2010-11-20 14:08:44 +01:00
2012-08-03 23:29:08 +02:00
$mimetype = dol_mimetype ( $file , '' , 1 );
$mimeimg = dol_mimetype ( $file , '' , 2 );
2017-11-10 20:20:59 +01:00
$mimefa = dol_mimetype ( $file , '' , 4 );
2009-05-19 02:14:27 +02:00
2014-07-29 21:34:23 +02:00
if ( empty ( $titlealt )) $titlealt = 'Mime type: ' . $mimetype ;
2009-10-23 16:58:33 +02:00
2017-11-10 20:20:59 +01:00
//return img_picto_common($titlealt, 'mime/'.$mimeimg, 'class="'.$morecss.'"');
return '<i class="fa fa-' . $mimefa . ' paddingright"></i>' ;
2008-08-06 16:50:06 +02:00
}
2012-08-03 14:30:11 +02:00
/**
2012-08-03 13:10:15 +02:00
* Show phone logo .
* Use img_picto instead .
2012-08-03 14:30:11 +02:00
*
2014-07-29 21:34:23 +02:00
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
2012-08-03 14:30:11 +02:00
* @ param int $option Option
2012-08-03 13:10:15 +02:00
* @ return string Return img tag
2012-08-03 14:30:11 +02:00
* @ deprecated
2015-04-23 23:21:06 +02:00
* @ see img_picto
2012-08-03 14:30:11 +02:00
*/
2014-07-29 21:34:23 +02:00
function img_phone ( $titlealt = 'default' , $option = 0 )
2008-08-06 16:50:06 +02:00
{
2015-04-23 23:21:06 +02:00
dol_syslog ( __FUNCTION__ . " is deprecated " , LOG_WARNING );
2012-08-03 14:30:11 +02:00
global $conf , $langs ;
2010-11-20 14:08:44 +01:00
2014-07-29 21:34:23 +02:00
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Call' );
2009-05-19 02:14:27 +02:00
2012-08-03 14:31:10 +02:00
if ( $option == 1 ) $img = 'call' ;
2012-08-03 14:30:11 +02:00
else $img = 'call_out' ;
2009-10-23 16:58:33 +02:00
2014-07-29 21:34:23 +02:00
return img_picto ( $titlealt , $img );
2008-08-06 16:50:06 +02:00
}
2014-09-17 17:59:00 +02:00
/**
* Show search logo
*
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
* @ param string $other Add more attributes on img
* @ return string Retourne tag img
*/
function img_search ( $titlealt = 'default' , $other = '' )
{
global $conf , $langs ;
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Search' );
2014-09-19 14:36:55 +02:00
2014-09-17 17:59:00 +02:00
$img = img_picto ( $titlealt , 'search.png' , $other , false , 1 );
2014-09-19 14:36:55 +02:00
2014-09-17 17:59:00 +02:00
$input = '<input type="image" class="liste_titre" name="button_search" src="' . $img . '" ' ;
$input .= 'value="' . dol_escape_htmltag ( $titlealt ) . '" title="' . dol_escape_htmltag ( $titlealt ) . '" >' ;
return $input ;
}
/**
* Show search logo
*
* @ param string $titlealt Text on alt and title of image . Alt only if param notitle is set to 1. If text is " TextA:TextB " , use Text A on alt and Text B on title .
* @ param string $other Add more attributes on img
* @ return string Retourne tag img
*/
function img_searchclear ( $titlealt = 'default' , $other = '' )
{
global $conf , $langs ;
if ( $titlealt == 'default' ) $titlealt = $langs -> trans ( 'Search' );
2014-09-19 14:36:55 +02:00
2014-09-17 17:59:00 +02:00
$img = img_picto ( $titlealt , 'searchclear.png' , $other , false , 1 );
2014-09-19 14:36:55 +02:00
2014-09-17 17:59:00 +02:00
$input = '<input type="image" class="liste_titre" name="button_removefilter" src="' . $img . '" ' ;
$input .= 'value="' . dol_escape_htmltag ( $titlealt ) . '" title="' . dol_escape_htmltag ( $titlealt ) . '" >' ;
return $input ;
}
2008-08-06 16:50:06 +02:00
/**
2016-03-03 10:42:49 +01:00
* Show information for admin users or standard users
2012-02-12 16:50:58 +01:00
*
* @ param string $text Text info
2015-03-17 00:21:17 +01:00
* @ param integer $infoonimgalt Info is shown only on alt of star picto , otherwise it is show on output after the star picto
2013-01-02 18:43:59 +01:00
* @ param int $nodiv No div
2016-07-26 21:12:52 +02:00
* @ param string $admin '1' = Info for admin users . '0' = Info for standard users ( change only the look ), 'xxx' = Other
2018-01-26 23:29:49 +01:00
* @ param string $morecss More CSS
2012-02-12 16:50:58 +01:00
* @ return string String with info text
2008-08-06 16:50:06 +02:00
*/
2018-01-26 23:29:49 +01:00
function info_admin ( $text , $infoonimgalt = 0 , $nodiv = 0 , $admin = '1' , $morecss = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
if ( $infoonimgalt )
{
2018-01-26 23:29:49 +01:00
return img_picto ( $text , 'info' , 'class="hideonsmartphone' . ( $morecss ? ' ' . $morecss : '' ) . '"' );
2012-08-03 23:29:08 +02:00
}
2017-05-25 08:48:59 +02:00
2018-01-26 23:29:49 +01:00
return ( $nodiv ? '' : '<div class="' . ( empty ( $admin ) ? '' : ( $admin == '1' ? 'info' : $admin )) . ' hideonsmartphone' . ( $morecss ? ' ' . $morecss : '' ) . '">' ) . '<span class="fa fa-info-circle" title="' . dol_escape_htmltag ( $admin ? $langs -> trans ( 'InfoAdmin' ) : $langs -> trans ( 'Note' )) . '"></span> ' . $text . ( $nodiv ? '' : '</div>' );
2008-08-06 16:50:06 +02:00
}
/**
2010-12-01 22:16:28 +01:00
* Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remontee des bugs .
* On doit appeler cette fonction quand une erreur technique bloquante est rencontree .
* Toutefois , il faut essayer de ne l 'appeler qu' au sein de pages php , les classes devant
* renvoyer leur erreur par l ' intermediaire de leur propriete " error " .
2012-02-04 14:39:47 +01:00
*
2014-03-16 17:37:54 +01:00
* @ param DoliDB $db Database handler
* @ param mixed $error String or array of errors strings to show
2015-05-03 20:07:16 +02:00
* @ param array $errors Array of errors
2014-03-16 17:37:54 +01:00
* @ return void
* @ see dol_htmloutput_errors
2008-08-06 16:50:06 +02:00
*/
2015-05-03 20:07:16 +02:00
function dol_print_error ( $db = '' , $error = '' , $errors = null )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs , $argv ;
global $dolibarr_main_prod ;
$out = '' ;
$syslog = '' ;
// Si erreur intervenue avant chargement langue
if ( ! $langs )
{
require_once DOL_DOCUMENT_ROOT . '/core/class/translate.class.php' ;
$langs = new Translate ( '' , $conf );
$langs -> load ( " main " );
}
$langs -> load ( " main " );
$langs -> load ( " errors " );
if ( $_SERVER [ 'DOCUMENT_ROOT' ]) // Mode web
{
$out .= $langs -> trans ( " DolibarrHasDetectedError " ) . " .<br> \n " ;
2015-03-13 18:11:31 +01:00
if ( ! empty ( $conf -> global -> MAIN_FEATURES_LEVEL )) $out .= " You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br> \n " ;
2012-08-03 23:29:08 +02:00
$out .= $langs -> trans ( " InformationToHelpDiagnose " ) . " :<br> \n " ;
2015-01-17 16:22:37 +01:00
$out .= " <b> " . $langs -> trans ( " Date " ) . " :</b> " . dol_print_date ( time (), 'dayhourlog' ) . " <br> \n " ;
$out .= " <b> " . $langs -> trans ( " Dolibarr " ) . " :</b> " . DOL_VERSION . " <br> \n " ;
if ( isset ( $conf -> global -> MAIN_FEATURES_LEVEL )) $out .= " <b> " . $langs -> trans ( " LevelOfFeature " ) . " :</b> " . $conf -> global -> MAIN_FEATURES_LEVEL . " <br> \n " ;
2012-08-03 23:29:08 +02:00
if ( function_exists ( " phpversion " ))
{
$out .= " <b> " . $langs -> trans ( " PHP " ) . " :</b> " . phpversion () . " <br> \n " ;
}
2013-05-11 15:12:42 +02:00
$out .= " <b> " . $langs -> trans ( " Server " ) . " :</b> " . $_SERVER [ " SERVER_SOFTWARE " ] . " <br> \n " ;
2015-01-17 16:22:37 +01:00
if ( function_exists ( " php_uname " ))
{
$out .= " <b> " . $langs -> trans ( " OS " ) . " :</b> " . php_uname () . " <br> \n " ;
}
$out .= " <b> " . $langs -> trans ( " UserAgent " ) . " :</b> " . $_SERVER [ " HTTP_USER_AGENT " ] . " <br> \n " ;
2012-08-03 23:29:08 +02:00
$out .= " <br> \n " ;
2013-05-11 15:12:42 +02:00
$out .= " <b> " . $langs -> trans ( " RequestedUrl " ) . " :</b> " . dol_htmlentities ( $_SERVER [ " REQUEST_URI " ], ENT_COMPAT , 'UTF-8' ) . " <br> \n " ;
$out .= " <b> " . $langs -> trans ( " Referer " ) . " :</b> " . ( isset ( $_SERVER [ " HTTP_REFERER " ]) ? dol_htmlentities ( $_SERVER [ " HTTP_REFERER " ], ENT_COMPAT , 'UTF-8' ) : '' ) . " <br> \n " ;
2013-01-28 11:30:28 +01:00
$out .= " <b> " . $langs -> trans ( " MenuManager " ) . " :</b> " . ( isset ( $conf -> standard_menu ) ? $conf -> standard_menu : '' ) . " <br> \n " ;
2012-08-03 23:29:08 +02:00
$out .= " <br> \n " ;
2017-06-18 19:42:59 +02:00
$syslog .= " url= " . dol_escape_htmltag ( $_SERVER [ " REQUEST_URI " ]);
$syslog .= " , query_string= " . dol_escape_htmltag ( $_SERVER [ " QUERY_STRING " ]);
2012-08-03 23:29:08 +02:00
}
else // Mode CLI
{
$out .= '> ' . $langs -> transnoentities ( " ErrorInternalErrorDetected " ) . " : \n " . $argv [ 0 ] . " \n " ;
2014-07-31 10:21:47 +02:00
$syslog .= " pid= " . dol_getmypid ();
2012-08-03 23:29:08 +02:00
}
if ( is_object ( $db ))
{
if ( $_SERVER [ 'DOCUMENT_ROOT' ]) // Mode web
{
$out .= " <b> " . $langs -> trans ( " DatabaseTypeManager " ) . " :</b> " . $db -> type . " <br> \n " ;
2017-05-10 11:47:34 +02:00
$out .= " <b> " . $langs -> trans ( " RequestLastAccessInError " ) . " :</b> " . ( $db -> lastqueryerror () ? dol_escape_htmltag ( $db -> lastqueryerror ()) : $langs -> trans ( " ErrorNoRequestInError " )) . " <br> \n " ;
2017-05-10 12:02:41 +02:00
$out .= " <b> " . $langs -> trans ( " ReturnCodeLastAccessInError " ) . " :</b> " . ( $db -> lasterrno () ? dol_escape_htmltag ( $db -> lasterrno ()) : $langs -> trans ( " ErrorNoRequestInError " )) . " <br> \n " ;
$out .= " <b> " . $langs -> trans ( " InformationLastAccessInError " ) . " :</b> " . ( $db -> lasterror () ? dol_escape_htmltag ( $db -> lasterror ()) : $langs -> trans ( " ErrorNoRequestInError " )) . " <br> \n " ;
2012-08-03 23:29:08 +02:00
$out .= " <br> \n " ;
}
else // Mode CLI
{
2017-10-13 13:28:26 +02:00
// No dol_escape_htmltag for output, we are in CLI mode
$out .= '> ' . $langs -> transnoentities ( " DatabaseTypeManager " ) . " : \n " . $db -> type . " \n " ;
2017-05-10 12:02:41 +02:00
$out .= '> ' . $langs -> transnoentities ( " RequestLastAccessInError " ) . " : \n " . ( $db -> lastqueryerror () ? $db -> lastqueryerror () : $langs -> transnoentities ( " ErrorNoRequestInError " )) . " \n " ;
$out .= '> ' . $langs -> transnoentities ( " ReturnCodeLastAccessInError " ) . " : \n " . ( $db -> lasterrno () ? $db -> lasterrno () : $langs -> transnoentities ( " ErrorNoRequestInError " )) . " \n " ;
$out .= '> ' . $langs -> transnoentities ( " InformationLastAccessInError " ) . " : \n " . ( $db -> lasterror () ? $db -> lasterror () : $langs -> transnoentities ( " ErrorNoRequestInError " )) . " \n " ;
2012-08-03 23:29:08 +02:00
}
$syslog .= " , sql= " . $db -> lastquery ();
$syslog .= " , db_error= " . $db -> lasterror ();
}
2015-05-03 20:07:16 +02:00
if ( $error || $errors )
2012-08-03 23:29:08 +02:00
{
$langs -> load ( " errors " );
2015-05-03 20:07:16 +02:00
// Merge all into $errors array
if ( is_array ( $error ) && is_array ( $errors )) $errors = array_merge ( $error , $errors );
elseif ( is_array ( $error )) $errors = $error ;
elseif ( is_array ( $errors )) $errors = array_merge ( array ( $error ), $errors );
else $errors = array_merge ( array ( $error ));
2012-08-03 23:29:08 +02:00
foreach ( $errors as $msg )
{
2016-05-07 16:38:32 +02:00
if ( empty ( $msg )) continue ;
2012-08-03 23:29:08 +02:00
if ( $_SERVER [ 'DOCUMENT_ROOT' ]) // Mode web
{
2016-05-29 11:56:19 +02:00
$out .= " <b> " . $langs -> trans ( " Message " ) . " :</b> " . dol_escape_htmltag ( $msg ) . " <br> \n " ;
2012-08-03 23:29:08 +02:00
}
2015-05-03 20:07:16 +02:00
else // Mode CLI
2012-08-03 23:29:08 +02:00
{
$out .= '> ' . $langs -> transnoentities ( " Message " ) . " : \n " . $msg . " \n " ;
}
$syslog .= " , msg= " . $msg ;
}
}
if ( empty ( $dolibarr_main_prod ) && $_SERVER [ 'DOCUMENT_ROOT' ] && function_exists ( 'xdebug_print_function_stack' ) && function_exists ( 'xdebug_call_file' ))
{
xdebug_print_function_stack ();
$out .= '<b>XDebug informations:</b>' . " <br> \n " ;
$out .= 'File: ' . xdebug_call_file () . " <br> \n " ;
$out .= 'Line: ' . xdebug_call_line () . " <br> \n " ;
$out .= 'Function: ' . xdebug_call_function () . " <br> \n " ;
$out .= " <br> \n " ;
}
if ( empty ( $dolibarr_main_prod )) print $out ;
2017-09-06 11:39:30 +02:00
else
{
print $langs -> trans ( " DolibarrHasDetectedError " ) . '. ' ;
print $langs -> trans ( " YouCanSetOptionDolibarrMainProdToZero " );
define ( " MAIN_CORE_ERROR " , 1 );
}
2012-08-03 23:29:08 +02:00
//else print 'Sorry, an error occured but the parameter $dolibarr_main_prod is defined in conf file so no message is reported to your browser. Please read the log file for error message.';
dol_syslog ( " Error " . $syslog , LOG_ERR );
2008-08-06 16:50:06 +02:00
}
2009-10-10 17:32:28 +02:00
/**
2012-11-20 11:23:34 +01:00
* Show a public email and error code to contact if technical error
2012-02-04 14:39:47 +01:00
*
2012-12-02 12:59:06 +01:00
* @ param string $prefixcode Prefix of public error code
2017-06-02 09:13:04 +02:00
* @ param string $errormessage Complete error message
2017-12-19 18:26:27 +01:00
* @ param array $errormessages Array of error messages
2012-02-04 15:20:32 +01:00
* @ return void
2009-10-10 17:32:28 +02:00
*/
2017-12-19 18:26:27 +01:00
function dol_print_error_email ( $prefixcode , $errormessage = '' , $errormessages = array ())
2009-10-10 17:32:28 +02:00
{
2012-08-03 23:29:08 +02:00
global $langs , $conf ;
2009-10-10 17:32:28 +02:00
2012-08-03 23:29:08 +02:00
$langs -> load ( " errors " );
$now = dol_now ();
2017-06-02 09:13:04 +02:00
print '<br><div class="center login_main_message"><div class="error">' ;
print $langs -> trans ( " ErrorContactEMail " , $conf -> global -> MAIN_INFO_SOCIETE_MAIL , $prefixcode . dol_print_date ( $now , '%Y%m%d' ));
if ( $errormessage ) print '<br><br>' . $errormessage ;
2017-12-19 18:26:27 +01:00
if ( is_array ( $errormessages ) && count ( $errormessages ))
{
foreach ( $errormessages as $mesgtoshow )
{
print '<br><br>' . $mesgtoshow ;
}
}
2017-06-02 09:13:04 +02:00
print '</div></div>' ;
2009-10-10 17:32:28 +02:00
}
2008-08-06 16:50:06 +02:00
/**
2011-05-03 21:03:08 +02:00
* Show title line of an array
2011-11-02 14:14:46 +01:00
*
2012-02-04 14:39:47 +01:00
* @ param string $name Label of field
* @ param string $file Url used when we click on sort picto
* @ param string $field Field to use for new sorting
* @ param string $begin ( " " by defaut )
* @ param string $moreparam Add more parameters on sort url links ( " " by default )
2017-09-16 10:12:44 +02:00
* @ param string $moreattrib Options of attribute td ( " " by defaut , example : 'align="center"' )
2012-02-04 14:39:47 +01:00
* @ param string $sortfield Current field used to sort
* @ param string $sortorder Current sort order
2015-06-30 13:14:19 +02:00
* @ param string $prefix Prefix for css . Use space after prefix to add your own CSS tag .
2017-08-31 18:29:57 +02:00
* @ param string $tooltip Tooltip
2012-02-04 14:39:47 +01:00
* @ return void
2011-07-06 11:25:05 +02:00
*/
2017-09-16 10:12:44 +02:00
function print_liste_field_titre ( $name , $file = " " , $field = " " , $begin = " " , $moreparam = " " , $moreattrib = " " , $sortfield = " " , $sortorder = " " , $prefix = " " , $tooltip = " " )
2011-08-30 19:56:45 +02:00
{
2017-09-16 10:12:44 +02:00
print getTitleFieldOfList ( $name , 0 , $file , $field , $begin , $moreparam , $moreattrib , $sortfield , $sortorder , $prefix , 0 , $tooltip );
2011-08-30 19:56:45 +02:00
}
/**
* Get title line of an array
2011-09-02 23:56:37 +02:00
*
2017-08-31 18:29:57 +02:00
* @ param string $name Translation key of field
* @ param int $thead 0 = To use with standard table format , 1 = To use inside < thead >< tr > , 2 = To use with < div >
* @ param string $file Url used when we click on sort picto
* @ param string $field Field to use for new sorting . Empty if this field is not sortable .
* @ param string $begin ( " " by defaut )
* @ param string $moreparam Add more parameters on sort url links ( " " by default )
2017-09-05 09:43:22 +02:00
* @ param string $moreattrib Add more attributes on th ( " " by defaut , example : 'align="center"' ) . To add more css class , use param $prefix .
2017-08-31 18:29:57 +02:00
* @ param string $sortfield Current field used to sort ( Ex : 'd.datep,d.id' )
* @ param string $sortorder Current sort order ( Ex : 'asc,desc' )
2017-09-05 09:43:22 +02:00
* @ param string $prefix Prefix for css . Use space after prefix to add your own CSS tag , for example 'mycss ' .
2017-07-16 12:07:59 +02:00
* @ param string $disablesortlink 1 = Disable sort link
2017-08-31 18:29:57 +02:00
* @ param string $tooltip Tooltip
2015-02-10 10:52:48 +01:00
* @ return string
2011-08-30 19:56:45 +02:00
*/
2017-08-31 18:29:57 +02:00
function getTitleFieldOfList ( $name , $thead = 0 , $file = " " , $field = " " , $begin = " " , $moreparam = " " , $moreattrib = " " , $sortfield = " " , $sortorder = " " , $prefix = " " , $disablesortlink = 0 , $tooltip = '' )
2008-08-06 16:50:06 +02:00
{
2017-08-31 18:29:57 +02:00
global $conf , $langs , $form ;
2012-08-03 23:29:08 +02:00
//print "$name, $file, $field, $begin, $options, $moreattrib, $sortfield, $sortorder<br>\n";
2011-09-03 01:57:26 +02:00
2013-04-14 02:09:41 +02:00
$sortorder = strtoupper ( $sortorder );
2012-08-03 23:29:08 +02:00
$out = '' ;
2017-10-13 13:28:26 +02:00
$sortimg = '' ;
2015-11-01 17:27:41 +01:00
2013-10-17 18:37:08 +02:00
$tag = 'th' ;
if ( $thead == 2 ) $tag = 'div' ;
2013-11-18 12:20:53 +01:00
2017-04-29 00:44:25 +02:00
$tmpsortfield = explode ( ',' , $sortfield );
2017-05-16 23:38:23 +02:00
$sortfield1 = trim ( $tmpsortfield [ 0 ]); // If $sortfield is 'd.datep,d.id', it becomes 'd.datep'
$tmpfield = explode ( ',' , $field );
$field1 = trim ( $tmpfield [ 0 ]); // If $field is 'd.datep,d.id', it becomes 'd.datep'
//var_dump('field='.$field.' field1='.$field1.' sortfield='.$sortfield.' sortfield1='.$sortfield1);
// If field is used as sort criteria we use a specific css class liste_titre_sel
2012-08-03 23:29:08 +02:00
// Example if (sortfield,field)=("nom","xxx.nom") or (sortfield,field)=("nom","nom")
2017-05-16 23:38:23 +02:00
if ( $field1 && ( $sortfield1 == $field1 || $sortfield1 == preg_replace ( " /^[^ \ .]+ \ ./ " , " " , $field1 ))) $out .= '<' . $tag . ' class="' . $prefix . 'liste_titre_sel" ' . $moreattrib . '>' ;
2015-06-08 18:17:13 +02:00
else $out .= '<' . $tag . ' class="' . $prefix . 'liste_titre" ' . $moreattrib . '>' ;
2013-04-14 02:09:41 +02:00
2017-07-16 12:07:59 +02:00
if ( empty ( $thead ) && $field && empty ( $disablesortlink )) // If this is a sort field
2012-08-03 23:29:08 +02:00
{
2013-06-05 16:24:32 +02:00
$options = preg_replace ( '/sortfield=([a-zA-Z0-9,\s\.]+)/i' , '' , $moreparam );
$options = preg_replace ( '/sortorder=([a-zA-Z0-9,\s\.]+)/i' , '' , $options );
$options = preg_replace ( '/&+/i' , '&' , $options );
if ( ! preg_match ( '/^&/' , $options )) $options = '&' . $options ;
2013-04-14 02:09:41 +02:00
2017-05-16 23:38:23 +02:00
if ( $field1 != $sortfield1 ) // We are on another field
2015-10-09 13:01:50 +02:00
{
2017-10-13 13:28:26 +02:00
if ( preg_match ( '/^DESC/' , $sortorder )) $out .= '<a class="reposition" href="' . $file . '?sortfield=' . $field . '&sortorder=desc&begin=' . $begin . $options . '">' ;
else $out .= '<a class="reposition" href="' . $file . '?sortfield=' . $field . '&sortorder=asc&begin=' . $begin . $options . '">' ;
2015-10-09 13:01:50 +02:00
}
2017-05-16 23:38:23 +02:00
else // We are of first sorting criteria
2015-10-09 13:01:50 +02:00
{
2017-10-13 13:28:26 +02:00
if ( preg_match ( '/^ASC/' , $sortorder )) $out .= '<a class="reposition" href="' . $file . '?sortfield=' . $sortfield . '&sortorder=desc&begin=' . $begin . $options . '">' ;
else $out .= '<a class="reposition" href="' . $file . '?sortfield=' . $sortfield . '&sortorder=asc&begin=' . $begin . $options . '">' ;
2015-10-09 13:01:50 +02:00
}
2012-08-03 23:29:08 +02:00
}
2013-04-14 02:09:41 +02:00
2017-08-31 18:29:57 +02:00
if ( $tooltip ) $out .= $form -> textwithpicto ( $langs -> trans ( $name ), $langs -> trans ( $tooltip ));
else $out .= $langs -> trans ( $name );
2013-04-14 02:09:41 +02:00
2017-07-16 12:07:59 +02:00
if ( empty ( $thead ) && $field && empty ( $disablesortlink )) // If this is a sort field
2012-08-03 23:29:08 +02:00
{
2013-06-05 16:24:32 +02:00
$out .= '</a>' ;
2012-08-03 23:29:08 +02:00
}
2015-10-09 13:01:50 +02:00
if ( empty ( $thead ) && $field ) // If this is a sort field
2012-08-03 23:29:08 +02:00
{
$options = preg_replace ( '/sortfield=([a-zA-Z0-9,\s\.]+)/i' , '' , $moreparam );
$options = preg_replace ( '/sortorder=([a-zA-Z0-9,\s\.]+)/i' , '' , $options );
$options = preg_replace ( '/&+/i' , '&' , $options );
if ( ! preg_match ( '/^&/' , $options )) $options = '&' . $options ;
//print " ";
2016-05-30 20:50:49 +02:00
//$sortimg.= '<img width="2" src="'.DOL_URL_ROOT.'/theme/common/transparent.png" alt="">';
//$sortimg.= '<span class="nowrap">';
2013-04-14 02:09:41 +02:00
2017-05-16 23:38:23 +02:00
if ( ! $sortorder || $field1 != $sortfield1 )
2012-08-03 23:29:08 +02:00
{
2015-10-09 13:01:50 +02:00
//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">'.img_down("A-Z",0).'</a>';
//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">'.img_up("Z-A",0).'</a>';
2012-08-03 23:29:08 +02:00
}
else
{
2017-04-29 00:44:25 +02:00
if ( preg_match ( '/^DESC/' , $sortorder )) {
2015-10-09 13:01:50 +02:00
//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">'.img_down("A-Z",0).'</a>';
//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">'.img_up("Z-A",1).'</a>';
2016-05-30 20:50:49 +02:00
$sortimg .= '<span class="nowrap">' . img_up ( " Z-A " , 0 ) . '</span>' ;
2012-08-03 23:29:08 +02:00
}
2017-04-29 00:44:25 +02:00
if ( preg_match ( '/^ASC/' , $sortorder )) {
2015-10-09 13:01:50 +02:00
//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">'.img_down("A-Z",1).'</a>';
//$out.= '<a href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">'.img_up("Z-A",0).'</a>';
2016-05-30 20:50:49 +02:00
$sortimg .= '<span class="nowrap">' . img_down ( " A-Z " , 0 ) . '</span>' ;
2012-08-03 23:29:08 +02:00
}
}
2014-01-15 18:35:15 +01:00
2016-05-30 20:50:49 +02:00
//$sortimg.= '</span>';
2012-08-03 23:29:08 +02:00
}
2015-11-01 17:27:41 +01:00
2015-10-09 13:01:50 +02:00
$out .= $sortimg ;
2015-11-01 17:27:41 +01:00
2013-10-17 18:37:08 +02:00
$out .= '</' . $tag . '>' ;
2012-08-03 23:29:08 +02:00
return $out ;
2008-08-06 16:50:06 +02:00
}
/**
2014-12-26 04:44:15 +01:00
* Show a title .
2012-02-04 14:39:47 +01:00
*
* @ param string $title Title to show
* @ return string Title to show
2015-08-15 02:44:05 +02:00
* @ deprecated Use load_fiche_titre instead
2015-09-24 18:33:48 +02:00
* @ see load_fiche_titre
2008-08-06 16:50:06 +02:00
*/
2012-02-04 14:39:47 +01:00
function print_titre ( $title )
2008-08-06 16:50:06 +02:00
{
2015-04-23 23:21:06 +02:00
dol_syslog ( __FUNCTION__ . " is deprecated " , LOG_WARNING );
2012-08-03 23:29:08 +02:00
print '<div class="titre">' . $title . '</div>' ;
2008-08-06 16:50:06 +02:00
}
2010-05-02 09:34:08 +02:00
/**
2010-12-05 21:33:24 +01:00
* Show a title with picto
2012-02-04 15:20:32 +01:00
*
2013-11-18 12:20:53 +01:00
* @ param string $title Title to show
2012-02-04 15:20:32 +01:00
* @ param string $mesg Added message to show on right
* @ param string $picto Icon to use before title ( should be a 32 x32 transparent png file )
* @ param int $pictoisfullpath 1 = Icon name is a full absolute url of image
* @ param int $id To force an id on html objects
* @ return void
2015-06-03 21:01:50 +02:00
* @ deprecated Use print load_fiche_titre instead
2010-05-02 09:34:08 +02:00
*/
2015-04-18 19:47:09 +02:00
function print_fiche_titre ( $title , $mesg = '' , $picto = 'title_generic.png' , $pictoisfullpath = 0 , $id = '' )
2010-05-02 09:34:08 +02:00
{
2013-11-18 12:20:53 +01:00
print load_fiche_titre ( $title , $mesg , $picto , $pictoisfullpath , $id );
2010-05-02 09:34:08 +02:00
}
2008-08-06 16:50:06 +02:00
/**
2010-12-05 21:33:24 +01:00
* Load a title with picto
2011-09-02 23:56:37 +02:00
*
2012-02-04 15:20:32 +01:00
* @ param string $titre Title to show
2016-11-08 14:08:48 +01:00
* @ param string $morehtmlright Added message to show on right
2012-02-04 15:20:32 +01:00
* @ param string $picto Icon to use before title ( should be a 32 x32 transparent png file )
2012-03-17 14:04:16 +01:00
* @ param int $pictoisfullpath 1 = Icon name is a full absolute url of image
2012-02-04 15:20:32 +01:00
* @ param int $id To force an id on html objects
2016-06-06 22:07:35 +02:00
* @ param string $morecssontable More css on table
2017-10-04 12:58:13 +02:00
* @ param string $morehtmlcenter Added message to show on center
2015-02-10 10:45:48 +01:00
* @ return string
2016-02-28 00:00:08 +01:00
* @ see print_barre_liste
2008-08-06 16:50:06 +02:00
*/
2017-10-04 12:58:13 +02:00
function load_fiche_titre ( $titre , $morehtmlright = '' , $picto = 'title_generic.png' , $pictoisfullpath = 0 , $id = 0 , $morecssontable = '' , $morehtmlcenter = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf ;
$return = '' ;
if ( $picto == 'setup' ) $picto = 'title.png' ;
2015-02-16 12:30:10 +01:00
if (( $conf -> browser -> name == 'ie' ) && $picto == 'title.png' ) $picto = 'title.gif' ;
2012-08-03 23:29:08 +02:00
$return .= " \n " ;
2016-06-06 22:07:35 +02:00
$return .= '<table ' . ( $id ? 'id="' . $id . '" ' : '' ) . 'summary="" class="centpercent notopnoleftnoright' . ( $morecssontable ? ' ' . $morecssontable : '' ) . '" style="margin-bottom: 2px;"><tr>' ;
2017-11-06 19:27:10 +01:00
if ( $picto ) $return .= '<td class="nobordernopadding widthpictotitle" valign="middle">' . img_picto ( '' , $picto , 'class="valignmiddle widthpictotitle" id="pictotitle"' , $pictoisfullpath ) . '</td>' ;
2012-08-03 23:29:08 +02:00
$return .= '<td class="nobordernopadding" valign="middle">' ;
$return .= '<div class="titre">' . $titre . '</div>' ;
$return .= '</td>' ;
2017-10-04 12:58:13 +02:00
if ( dol_strlen ( $morehtmlcenter ))
{
$return .= '<td class="nobordernopadding" align="center" valign="middle">' . $morehtmlcenter . '</td>' ;
}
2016-11-08 14:08:48 +01:00
if ( dol_strlen ( $morehtmlright ))
2012-08-03 23:29:08 +02:00
{
2018-03-07 19:13:15 +01:00
$return .= '<td class="nobordernopadding titre_right wordbreak" align="right" valign="middle">' . $morehtmlright . '</td>' ;
2012-08-03 23:29:08 +02:00
}
$return .= '</tr></table>' . " \n " ;
return $return ;
2010-05-02 06:57:15 +02:00
}
2008-08-06 16:50:06 +02:00
/**
2011-05-03 21:03:08 +02:00
* Print a title with navigation controls for pagination
2011-09-02 23:56:37 +02:00
*
2016-02-10 23:37:34 +01:00
* @ param string $titre Title to show ( required )
2016-09-04 13:28:37 +02:00
* @ param int $page Numero of page to show in navigation links ( required )
2016-02-10 23:37:34 +01:00
* @ param string $file Url of page ( required )
2017-06-21 12:03:49 +02:00
* @ param string $options More parameters for links ( '' by default , does not include sortfield neither sortorder ) . Value must be 'urlencoded' before calling function .
2016-09-04 13:28:37 +02:00
* @ param string $sortfield Field to sort on ( '' by default )
* @ param string $sortorder Order to sort ( '' by default )
2017-11-28 11:01:02 +01:00
* @ param string $morehtmlcenter String in the middle ( '' by default ) . We often find here string $massaction comming from $form -> selectMassAction ()
2016-09-04 13:28:37 +02:00
* @ param int $num Number of records found by select with limit + 1
2017-01-15 20:49:20 +01:00
* @ param int | string $totalnboflines Total number of records / lines for all pages ( if known ) . Use a negative value of number to not show number . Use '' if unknown .
2016-02-10 23:37:34 +01:00
* @ param string $picto Icon to use before title ( should be a 32 x32 transparent png file )
* @ param int $pictoisfullpath 1 = Icon name is a full absolute url of image
2017-11-28 11:01:02 +01:00
* @ param string $morehtmlright More html to show
2016-02-10 23:37:34 +01:00
* @ param string $morecss More css to the table
2016-02-11 16:49:13 +01:00
* @ param int $limit Max number of lines ( - 1 = use default , 0 = no limit , > 0 = limit ) .
2016-02-10 23:37:34 +01:00
* @ param int $hideselectlimit Force to hide select limit
2017-10-04 12:58:13 +02:00
* @ param int $hidenavigation Force to hide all navigation tools
2011-10-03 18:10:50 +02:00
* @ return void
2008-08-06 16:50:06 +02:00
*/
2017-11-28 11:01:02 +01:00
function print_barre_liste ( $titre , $page , $file , $options = '' , $sortfield = '' , $sortorder = '' , $morehtmlcenter = '' , $num =- 1 , $totalnboflines = '' , $picto = 'title_generic.png' , $pictoisfullpath = 0 , $morehtmlright = '' , $morecss = '' , $limit =- 1 , $hideselectlimit = 0 , $hidenavigation = 0 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2016-11-16 09:40:29 +01:00
2016-02-10 19:28:10 +01:00
$savlimit = $limit ;
2017-10-13 13:28:26 +02:00
$savtotalnboflines = $totalnboflines ;
$totalnboflines = abs ( $totalnboflines );
2016-11-16 09:40:29 +01:00
2015-04-18 20:33:18 +02:00
if ( $picto == 'setup' ) $picto = 'title_setup.png' ;
if (( $conf -> browser -> name == 'ie' ) && $picto == 'title_generic.png' ) $picto = 'title.gif' ;
2016-02-10 19:28:10 +01:00
if ( $limit < 0 ) $limit = $conf -> liste_limit ;
2016-02-11 16:49:13 +01:00
if ( $savlimit != 0 && (( $num > $limit ) || ( $num == - 1 ) || ( $limit == 0 )))
2012-08-03 23:29:08 +02:00
{
$nextpage = 1 ;
}
else
{
$nextpage = 0 ;
}
2016-02-11 16:49:13 +01:00
//print 'totalnboflines='.$totalnboflines.'-savlimit='.$savlimit.'-limit='.$limit.'-num='.$num.'-nextpage='.$nextpage;
2016-11-16 09:40:29 +01:00
2012-08-03 23:29:08 +02:00
print " \n " ;
print " <!-- Begin title ' " . $titre . " ' --> \n " ;
2015-10-02 16:11:25 +02:00
print '<table width="100%" border="0" class="notopnoleftnoright' . ( $morecss ? ' ' . $morecss : '' ) . '" style="margin-bottom: 6px;"><tr>' ;
2012-08-03 23:29:08 +02:00
// Left
2016-09-20 12:51:09 +02:00
//if ($picto && $titre) print '<td class="nobordernopadding hideonsmartphone" width="40" align="left" valign="middle">'.img_picto('', $picto, 'id="pictotitle"', $pictoisfullpath).'</td>';
2016-11-06 12:16:10 +01:00
print '<td class="nobordernopadding valignmiddle">' ;
2016-09-20 12:51:09 +02:00
if ( $picto && $titre ) print img_picto ( '' , $picto , 'class="hideonsmartphone valignmiddle" id="pictotitle"' , $pictoisfullpath );
print '<div class="titre inline-block">' . $titre ;
2017-01-15 20:49:20 +01:00
if ( ! empty ( $titre ) && $savtotalnboflines >= 0 && ( string ) $savtotalnboflines != '' ) print ' (' . $totalnboflines . ')' ;
2015-12-28 10:20:23 +01:00
print '</div></td>' ;
2013-09-07 19:50:47 +02:00
// Center
2017-11-28 11:01:02 +01:00
if ( $morehtmlcenter )
2013-09-07 19:50:47 +02:00
{
2017-11-28 11:01:02 +01:00
print '<td class="nobordernopadding center valignmiddle">' . $morehtmlcenter . '</td>' ;
2013-09-07 19:50:47 +02:00
}
// Right
2016-11-06 12:16:10 +01:00
print '<td class="nobordernopadding valignmiddle" align="right">' ;
2017-12-15 10:36:35 +01:00
if ( $sortfield ) $options .= " &sortfield= " . urlencode ( $sortfield );
if ( $sortorder ) $options .= " &sortorder= " . urlencode ( $sortorder );
2013-09-07 19:50:47 +02:00
// Show navigation bar
$pagelist = '' ;
2016-02-10 19:28:10 +01:00
if ( $savlimit != 0 && ( $page > 0 || $num > $limit ))
2012-08-03 23:29:08 +02:00
{
2015-05-15 04:33:01 +02:00
if ( $totalnboflines ) // If we know total nb of lines
2012-08-03 23:29:08 +02:00
{
2018-02-15 12:57:04 +01:00
// Define nb of extra page links before and after selected page + ... + first or last
$maxnbofpage = ( empty ( $conf -> dol_optimize_smallscreen ) ? 4 : 1 );
2012-08-03 23:29:08 +02:00
2016-02-10 19:28:10 +01:00
if ( $limit > 0 ) $nbpages = ceil ( $totalnboflines / $limit );
else $nbpages = 1 ;
2012-08-03 23:29:08 +02:00
$cpt = ( $page - $maxnbofpage );
if ( $cpt < 0 ) { $cpt = 0 ; }
2015-05-15 04:33:01 +02:00
2012-08-03 23:29:08 +02:00
if ( $cpt >= 1 )
{
2017-04-06 22:31:45 +02:00
$pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><a href="' . $file . '?page=0' . $options . '">1</a></li>' ;
if ( $cpt > 2 ) $pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><span ' . (( $conf -> dol_use_jmobile != 4 ) ? 'class="inactive"' : '' ) . '>...</span></li>' ;
else if ( $cpt == 2 ) $pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><a href="' . $file . '?page=1' . $options . '">2</a></li>' ;
2012-08-03 23:29:08 +02:00
}
2015-11-01 17:27:41 +01:00
2012-08-03 23:29:08 +02:00
do
{
2013-09-07 19:50:47 +02:00
if ( $cpt == $page )
2012-08-03 23:29:08 +02:00
{
2017-04-06 22:31:45 +02:00
$pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><span ' . (( $conf -> dol_use_jmobile != 4 ) ? 'class="active"' : '' ) . '>' . ( $page + 1 ) . '</span></li>' ;
2012-08-03 23:29:08 +02:00
}
else
{
2017-04-06 22:31:45 +02:00
$pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><a href="' . $file . '?page=' . $cpt . $options . '">' . ( $cpt + 1 ) . '</a></li>' ;
2012-08-03 23:29:08 +02:00
}
$cpt ++ ;
}
while ( $cpt < $nbpages && $cpt <= $page + $maxnbofpage );
2015-11-01 17:27:41 +01:00
2012-08-03 23:29:08 +02:00
if ( $cpt < $nbpages )
{
2017-04-06 22:31:45 +02:00
if ( $cpt < $nbpages - 2 ) $pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><span ' . (( $conf -> dol_use_jmobile != 4 ) ? 'class="inactive"' : '' ) . '>...</span></li>' ;
else if ( $cpt == $nbpages - 2 ) $pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><a href="' . $file . '?page=' . ( $nbpages - 2 ) . $options . '">' . ( $nbpages - 1 ) . '</a></li>' ;
$pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><a href="' . $file . '?page=' . ( $nbpages - 1 ) . $options . '">' . $nbpages . '</a></li>' ;
2012-08-03 23:29:08 +02:00
}
}
else
{
2017-04-06 22:31:45 +02:00
$pagelist .= '<li' . (( $conf -> dol_use_jmobile != 4 ) ? ' class="pagination"' : '' ) . '><span ' . (( $conf -> dol_use_jmobile != 4 ) ? 'class="active"' : '' ) . '>' . ( $page + 1 ) . " </li> " ;
2012-08-03 23:29:08 +02:00
}
}
2017-09-06 19:53:28 +02:00
2017-11-28 11:01:02 +01:00
print_fleche_navigation ( $page , $file , $options , $nextpage , $pagelist , $morehtmlright , $savlimit , $totalnboflines , $hideselectlimit ); // output the div and ul for previous/last completed with page numbers into $pagelist
2017-09-06 19:53:28 +02:00
2012-08-03 23:29:08 +02:00
print '</td>' ;
print '</tr></table>' . " \n " ;
print " <!-- End title --> \n \n " ;
2008-08-06 16:50:06 +02:00
}
/**
2015-05-15 04:33:01 +02:00
* Function to show navigation arrows into lists
2011-09-02 23:56:37 +02:00
*
2014-06-20 13:07:15 +02:00
* @ param int $page Number of page
2015-05-17 19:37:37 +02:00
* @ param string $file Page URL ( in most cases provided with $_SERVER [ " PHP_SELF " ])
2016-09-04 13:28:37 +02:00
* @ param string $options Other url paramaters to propagate ( " " by default , may include sortfield and sortorder )
2015-05-15 04:33:01 +02:00
* @ param integer $nextpage Do we show a next page button
2015-07-04 03:28:52 +02:00
* @ param string $betweenarrows HTML content to show between arrows . MUST contains '<li> </li>' tags or '<li><span> </span></li>' .
2015-05-17 23:47:15 +02:00
* @ param string $afterarrows HTML content to show after arrows . Must NOT contains '<li> </li>' tags .
2016-02-10 19:28:10 +01:00
* @ param int $limit Max nb of record to show ( - 1 = no combo with limit , 0 = no limit , > 0 = limit )
2016-02-09 11:56:12 +01:00
* @ param int $totalnboflines Total number of records / lines for all pages ( if known )
2016-02-10 23:37:34 +01:00
* @ param int $hideselectlimit Force to hide select limit
2011-10-03 18:10:50 +02:00
* @ return void
2008-08-06 16:50:06 +02:00
*/
2016-02-10 23:37:34 +01:00
function print_fleche_navigation ( $page , $file , $options = '' , $nextpage = 0 , $betweenarrows = '' , $afterarrows = '' , $limit =- 1 , $totalnboflines = 0 , $hideselectlimit = 0 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2013-04-27 21:38:49 +02:00
2015-05-05 21:41:08 +02:00
print '<div class="pagination"><ul>' ;
2016-02-10 23:37:34 +01:00
if (( int ) $limit >= 0 && empty ( $hideselectlimit ))
2016-02-09 11:56:12 +01:00
{
2017-10-13 13:28:26 +02:00
$pagesizechoices = '10:10,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000' ;
//$pagesizechoices.=',0:'.$langs->trans("All"); // Not yet supported
//$pagesizechoices.=',2:2';
if ( ! empty ( $conf -> global -> MAIN_PAGESIZE_CHOICES )) $pagesizechoices = $conf -> global -> MAIN_PAGESIZE_CHOICES ;
print '<li class="pagination">' ;
print '<select class="flat selectlimit" name="limit" title="' . dol_escape_htmltag ( $langs -> trans ( " MaxNbOfRecordPerPage " )) . '">' ;
$tmpchoice = explode ( ',' , $pagesizechoices );
$tmpkey = $limit . ':' . $limit ;
if ( ! in_array ( $tmpkey , $tmpchoice )) $tmpchoice [] = $tmpkey ;
$tmpkey = $conf -> liste_limit . ':' . $conf -> liste_limit ;
if ( ! in_array ( $tmpkey , $tmpchoice )) $tmpchoice [] = $tmpkey ;
asort ( $tmpchoice , SORT_NUMERIC );
$found = false ;
foreach ( $tmpchoice as $val )
{
$selected = '' ;
$tmp = explode ( ':' , $val );
$key = $tmp [ 0 ];
$val = $tmp [ 1 ];
if ( $key != '' && $val != '' )
{
if (( int ) $key == ( int ) $limit )
{
$selected = ' selected="selected"' ;
$found = true ;
}
print '<option name="' . $key . '"' . $selected . '>' . dol_escape_htmltag ( $val ) . '</option>' . " \n " ;
}
}
print '</select>' ;
if ( $conf -> use_javascript_ajax )
{
print ' <!-- JS CODE TO ENABLE select limit to launch submit of page -->
2016-02-10 19:28:10 +01:00
< script type = " text/javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( " .selectlimit " ) . change ( function () {
console . log ( " Change limit. Send submit " );
$ ( this ) . parents ( \ ' form : first\ ' ) . submit ();
});
});
</ script >
' ;
2017-10-13 13:28:26 +02:00
}
print '</li>' ;
2016-02-09 11:56:12 +01:00
}
2012-08-03 23:29:08 +02:00
if ( $page > 0 )
{
2017-03-28 18:42:23 +02:00
print '<li class="pagination"><a class="paginationprevious" href="' . $file . '?page=' . ( $page - 1 ) . $options . '"><i class="fa fa-chevron-left" title="' . dol_escape_htmltag ( $langs -> trans ( " Previous " )) . '"></i></a></li>' ;
2012-08-03 23:29:08 +02:00
}
2015-07-04 03:28:52 +02:00
if ( $betweenarrows )
{
print $betweenarrows ;
}
2012-08-03 23:29:08 +02:00
if ( $nextpage > 0 )
{
2017-03-28 18:42:23 +02:00
print '<li class="pagination"><a class="paginationnext" href="' . $file . '?page=' . ( $page + 1 ) . $options . '"><i class="fa fa-chevron-right" title="' . dol_escape_htmltag ( $langs -> trans ( " Next " )) . '"></i></a></li>' ;
2012-08-03 23:29:08 +02:00
}
2015-05-17 19:37:37 +02:00
if ( $afterarrows )
{
print '<li class="paginationafterarrows">' ;
print $afterarrows ;
print '</li>' ;
2012-08-03 23:29:08 +02:00
}
2015-05-15 04:33:01 +02:00
print '</ul></div>' . " \n " ;
2008-08-06 16:50:06 +02:00
}
2008-11-16 19:55:00 +01:00
/**
2011-10-09 17:37:27 +02:00
* Return a string with VAT rate label formated for view output
* Used into pdf and HTML pages
2011-09-02 23:56:37 +02:00
*
2016-10-29 21:02:08 +02:00
* @ param string $rate Rate value to format ( '19.6' , '19,6' , '19.6%' , '19,6%' , '19.6 (CODEX)' , ... )
2011-10-03 18:10:50 +02:00
* @ param boolean $addpercent Add a percent % sign in output
2013-03-24 07:11:44 +01:00
* @ param int $info_bits Miscellaneous information on vat ( 0 = Default , 1 = French NPR vat )
2017-09-27 21:58:42 +02:00
* @ param int $usestarfornpr - 1 = Never show , 0 or 1 = Use '*' for NPR vat rates
2016-10-29 21:02:08 +02:00
* @ return string String with formated amounts ( '19,6' or '19,6%' or '8.5% (NPR)' or '8.5% *' or '19,6 (CODEX)' )
2008-08-06 16:50:06 +02:00
*/
2016-10-29 21:02:08 +02:00
function vatrate ( $rate , $addpercent = false , $info_bits = 0 , $usestarfornpr = 0 )
2008-08-06 16:50:06 +02:00
{
2017-10-13 13:28:26 +02:00
$morelabel = '' ;
2016-11-16 09:40:29 +01:00
2017-10-13 13:28:26 +02:00
if ( preg_match ( '/%/' , $rate ))
2012-08-03 23:29:08 +02:00
{
$rate = str_replace ( '%' , '' , $rate );
$addpercent = true ;
}
2015-11-14 15:28:25 +01:00
if ( preg_match ( '/\((.*)\)/' , $rate , $reg ))
{
2017-10-13 13:28:26 +02:00
$morelabel = ' (' . $reg [ 1 ] . ')' ;
$rate = preg_replace ( '/\s*' . preg_quote ( $morelabel , '/' ) . '/' , '' , $rate );
2015-11-14 15:28:25 +01:00
}
2017-04-29 18:30:36 +02:00
if ( preg_match ( '/\*/' , $rate ))
2012-08-03 23:29:08 +02:00
{
$rate = str_replace ( '*' , '' , $rate );
$info_bits |= 1 ;
}
2017-08-29 20:40:51 +02:00
// If rate is '9/9/9' we don't change it. If rate is '9.000' we apply price()
if ( ! preg_match ( '/\//' , $rate )) $ret = price ( $rate , 0 , '' , 0 , 0 ) . ( $addpercent ? '%' : '' );
else
{
2017-09-25 21:41:53 +02:00
// TODO Split on / and output with a price2num to have clean numbers without ton of 000.
2017-08-29 20:40:51 +02:00
$ret = $rate . ( $addpercent ? '%' : '' );
}
2017-09-27 21:58:42 +02:00
if (( $info_bits & 1 ) && $usestarfornpr >= 0 ) $ret .= ' *' ;
2015-11-14 15:28:25 +01:00
$ret .= $morelabel ;
2012-08-03 23:29:08 +02:00
return $ret ;
2008-08-06 16:50:06 +02:00
}
/**
2013-03-15 15:59:51 +01:00
* Function to format a value into an amount for visual output
* Function used into PDF and HTML pages
*
* @ param float $amount Amount to format
2015-03-17 00:21:17 +01:00
* @ param integer $form Type of format , HTML or not ( not by default )
2013-03-15 15:59:51 +01:00
* @ param Translate $outlangs Object langs for output
2017-10-06 12:08:01 +02:00
* @ param int $trunc 1 = Truncate if there is more decimals than MAIN_MAX_DECIMALS_SHOWN ( default ), 0 = Does not truncate . Deprecated because amount are rounded ( to unit or total amount accurancy ) before beeing inserted into database or after a computation , so this parameter should be useless .
2013-06-17 11:58:55 +02:00
* @ param int $rounding Minimum number of decimal to show . If 0 , no change , if - 1 , we use min ( $conf -> global -> MAIN_MAX_DECIMALS_UNIT , $conf -> global -> MAIN_MAX_DECIMALS_TOTAL )
* @ param int $forcerounding Force the number of decimal to forcerounding decimal ( - 1 = do not force )
2014-03-17 20:43:01 +01:00
* @ param string $currency_code To add currency symbol ( '' = add nothing , 'auto' = Use default currency , 'XXX' = add currency symbols for XXX currency )
2011-10-03 18:10:50 +02:00
* @ return string Chaine avec montant formate
*
* @ see price2num Revert function of price
2010-09-30 10:12:03 +02:00
*/
2013-03-15 15:59:51 +01:00
function price ( $amount , $form = 0 , $outlangs = '' , $trunc = 1 , $rounding =- 1 , $forcerounding =- 1 , $currency_code = '' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $langs , $conf ;
// Clean parameters
if ( empty ( $amount )) $amount = 0 ; // To have a numeric value if amount not defined or = ''
2012-12-07 10:50:16 +01:00
$amount = ( is_numeric ( $amount ) ? $amount : 0 ); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number)
2012-08-03 23:29:08 +02:00
if ( $rounding < 0 ) $rounding = min ( $conf -> global -> MAIN_MAX_DECIMALS_UNIT , $conf -> global -> MAIN_MAX_DECIMALS_TOT );
$nbdecimal = $rounding ;
// Output separators by default (french)
$dec = ',' ; $thousand = ' ' ;
// If $outlangs not forced, we use use language
if ( ! is_object ( $outlangs )) $outlangs = $langs ;
2013-03-24 03:12:40 +01:00
if ( $outlangs -> transnoentitiesnoconv ( " SeparatorDecimal " ) != " SeparatorDecimal " ) $dec = $outlangs -> transnoentitiesnoconv ( " SeparatorDecimal " );
if ( $outlangs -> transnoentitiesnoconv ( " SeparatorThousand " ) != " SeparatorThousand " ) $thousand = $outlangs -> transnoentitiesnoconv ( " SeparatorThousand " );
2012-08-03 23:29:08 +02:00
if ( $thousand == 'None' ) $thousand = '' ;
2014-04-06 21:18:21 +02:00
else if ( $thousand == 'Space' ) $thousand = ' ' ;
2013-06-08 16:29:59 +02:00
//print "outlangs=".$outlangs->defaultlang." amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
2012-08-03 23:29:08 +02:00
//print "amount=".$amount."-";
$amount = str_replace ( ',' , '.' , $amount ); // should be useless
//print $amount."-";
$datas = explode ( '.' , $amount );
$decpart = isset ( $datas [ 1 ]) ? $datas [ 1 ] : '' ;
$decpart = preg_replace ( '/0+$/i' , '' , $decpart ); // Supprime les 0 de fin de partie decimale
//print "decpart=".$decpart."<br>";
$end = '' ;
// We increase nbdecimal if there is more decimal than asked (to not loose information)
if ( dol_strlen ( $decpart ) > $nbdecimal ) $nbdecimal = dol_strlen ( $decpart );
// Si on depasse max
if ( $trunc && $nbdecimal > $conf -> global -> MAIN_MAX_DECIMALS_SHOWN )
{
$nbdecimal = $conf -> global -> MAIN_MAX_DECIMALS_SHOWN ;
if ( preg_match ( '/\.\.\./i' , $conf -> global -> MAIN_MAX_DECIMALS_SHOWN ))
{
// Si un affichage est tronque, on montre des ...
$end = '...' ;
}
}
// If force rounding
if ( $forcerounding >= 0 ) $nbdecimal = $forcerounding ;
// Format number
2013-03-24 03:12:40 +01:00
$output = number_format ( $amount , $nbdecimal , $dec , $thousand );
2012-08-03 23:29:08 +02:00
if ( $form )
{
2013-03-24 03:12:40 +01:00
$output = preg_replace ( '/\s/' , ' ' , $output );
$output = preg_replace ( '/\'/' , ''' , $output );
2012-08-03 23:29:08 +02:00
}
2013-03-15 15:59:51 +01:00
// Add symbol of currency if requested
$cursymbolbefore = $cursymbolafter = '' ;
if ( $currency_code )
{
2014-03-17 20:43:01 +01:00
if ( $currency_code == 'auto' ) $currency_code = $conf -> currency ;
2017-12-15 17:17:35 +01:00
$listofcurrenciesbefore = array ( 'USD' , 'GBP' , 'AUD' , 'MXN' , 'PEN' , 'CNY' );
2013-03-15 15:59:51 +01:00
if ( in_array ( $currency_code , $listofcurrenciesbefore )) $cursymbolbefore .= $outlangs -> getCurrencySymbol ( $currency_code );
2014-11-07 22:06:51 +01:00
else
2014-11-02 11:39:30 +01:00
{
$tmpcur = $outlangs -> getCurrencySymbol ( $currency_code );
$cursymbolafter .= ( $tmpcur == $currency_code ? ' ' . $tmpcur : $tmpcur );
}
2013-03-15 15:59:51 +01:00
}
2015-04-06 16:13:23 +02:00
$output = $cursymbolbefore . $output . $end . ( $cursymbolafter ? ' ' : '' ) . $cursymbolafter ;
2013-03-24 03:12:40 +01:00
2012-08-03 23:29:08 +02:00
return $output ;
2008-08-06 16:50:06 +02:00
}
/**
2015-04-06 16:50:26 +02:00
* Function that return a number with universal decimal format ( decimal separator is '.' ) from an amount typed by a user .
2011-09-02 23:56:37 +02:00
* Function to use on each input amount before any numeric test or database insert
*
2011-10-03 18:10:50 +02:00
* @ param float $amount Amount to convert / clean
* @ param string $rounding '' = No rounding
2009-01-25 17:45:04 +01:00
* 'MU' = Round to Max unit price ( MAIN_MAX_DECIMALS_UNIT )
* 'MT' = Round to Max for totals with Tax ( MAIN_MAX_DECIMALS_TOT )
2016-11-18 16:34:03 +01:00
* 'MS' = Round to Max for stock quantity ( MAIN_MAX_DECIMALS_STOCK )
2011-10-03 18:10:50 +02:00
* @ param int $alreadysqlnb Put 1 if you know that content is already universal format number
2014-11-28 00:37:46 +01:00
* @ return string Amount with universal numeric format ( Example : '99.99999' ) or unchanged text if conversion fails .
2011-10-03 18:10:50 +02:00
*
* @ see price Opposite function of price2num
2009-01-25 17:45:04 +01:00
*/
function price2num ( $amount , $rounding = '' , $alreadysqlnb = 0 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $langs , $conf ;
// Round PHP function does not allow number like '1,234.56' nor '1.234,56' nor '1 234,56'
// Numbers must be '1234.56'
// Decimal delimiter for PHP and database SQL requests must be '.'
$dec = ',' ; $thousand = ' ' ;
2013-03-24 03:12:40 +01:00
if ( $langs -> transnoentitiesnoconv ( " SeparatorDecimal " ) != " SeparatorDecimal " ) $dec = $langs -> transnoentitiesnoconv ( " SeparatorDecimal " );
if ( $langs -> transnoentitiesnoconv ( " SeparatorThousand " ) != " SeparatorThousand " ) $thousand = $langs -> transnoentitiesnoconv ( " SeparatorThousand " );
2012-08-03 23:29:08 +02:00
if ( $thousand == 'None' ) $thousand = '' ;
2014-04-06 21:18:21 +02:00
elseif ( $thousand == 'Space' ) $thousand = ' ' ;
2012-08-03 23:29:08 +02:00
//print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
// Convert value to universal number format (no thousand separator, '.' as decimal separator)
if ( $alreadysqlnb != 1 ) // If not a PHP number or unknown, we change format
{
2013-03-24 03:12:40 +01:00
//print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>';
2012-08-03 23:29:08 +02:00
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
// to format defined by LC_NUMERIC after a calculation and we want source format to be like defined by Dolibarr setup.
if ( is_numeric ( $amount ))
{
// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
$temps = sprintf ( " %0.10F " , $amount - intval ( $amount )); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
$temps = preg_replace ( '/([\.1-9])0+$/' , '\\1' , $temps ); // temps=0. or 0.00002 or 9999.1
$nbofdec = max ( 0 , dol_strlen ( $temps ) - 2 ); // -2 to remove "0."
$amount = number_format ( $amount , $nbofdec , $dec , $thousand );
}
//print "QQ".$amount.'<br>';
// Now make replace (the main goal of function)
if ( $thousand != ',' && $thousand != '.' ) $amount = str_replace ( ',' , '.' , $amount ); // To accept 2 notations for french users
$amount = str_replace ( ' ' , '' , $amount ); // To avoid spaces
$amount = str_replace ( $thousand , '' , $amount ); // Replace of thousand before replace of dec to avoid pb if thousand is .
$amount = str_replace ( $dec , '.' , $amount );
}
// Now, make a rounding if required
if ( $rounding )
{
$nbofdectoround = '' ;
if ( $rounding == 'MU' ) $nbofdectoround = $conf -> global -> MAIN_MAX_DECIMALS_UNIT ;
elseif ( $rounding == 'MT' ) $nbofdectoround = $conf -> global -> MAIN_MAX_DECIMALS_TOT ;
2016-11-18 16:34:03 +01:00
elseif ( $rounding == 'MS' ) $nbofdectoround = empty ( $conf -> global -> MAIN_MAX_DECIMALS_STOCK ) ? 5 : $conf -> global -> MAIN_MAX_DECIMALS_STOCK ;
2012-09-06 23:58:09 +02:00
elseif ( is_numeric ( $rounding )) $nbofdectoround = $rounding ; // For admin info page
2012-08-03 23:29:08 +02:00
//print "RR".$amount.' - '.$nbofdectoround.'<br>';
if ( dol_strlen ( $nbofdectoround )) $amount = round ( $amount , $nbofdectoround ); // $nbofdectoround can be 0.
else return 'ErrorBadParameterProvidedToFunction' ;
//print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
// to format defined by LC_NUMERIC after a calculation and we want source format to be defined by Dolibarr setup.
if ( is_numeric ( $amount ))
{
// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
$temps = sprintf ( " %0.10F " , $amount - intval ( $amount )); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
$temps = preg_replace ( '/([\.1-9])0+$/' , '\\1' , $temps ); // temps=0. or 0.00002 or 9999.1
$nbofdec = max ( 0 , dol_strlen ( $temps ) - 2 ); // -2 to remove "0."
$amount = number_format ( $amount , min ( $nbofdec , $nbofdectoround ), $dec , $thousand ); // Convert amount to format with dolibarr dec and thousand
}
//print "TT".$amount.'<br>';
// Always make replace because each math function (like round) replace
// with local values and we want a number that has a SQL string format x.y
if ( $thousand != ',' && $thousand != '.' ) $amount = str_replace ( ',' , '.' , $amount ); // To accept 2 notations for french users
$amount = str_replace ( ' ' , '' , $amount ); // To avoid spaces
$amount = str_replace ( $thousand , '' , $amount ); // Replace of thousand before replace of dec to avoid pb if thousand is .
$amount = str_replace ( $dec , '.' , $amount );
}
return $amount ;
2008-08-06 16:50:06 +02:00
}
2016-02-25 13:46:38 +01:00
/**
2016-02-26 10:55:47 +01:00
* Output a dimension with best unit
2016-11-16 09:40:29 +01:00
*
2016-02-26 10:55:47 +01:00
* @ param float $dimension Dimension
* @ param int $unit Unit of dimension ( 0 , - 3 , ... )
* @ param string $type 'weight' , 'volume' , ...
* @ param Translate $outputlangs Translate language object
2016-03-09 23:17:46 +01:00
* @ param int $round - 1 = non rounding , x = number of decimal
2016-04-01 18:44:23 +02:00
* @ param string $forceunitoutput 'no' or numeric ( - 3 , - 6 , ... ) compared to $unit
2016-02-26 10:55:47 +01:00
* @ return string String to show dimensions
2016-02-25 13:46:38 +01:00
*/
2016-04-03 10:47:21 +02:00
function showDimensionInBestUnit ( $dimension , $unit , $type , $outputlangs , $round =- 1 , $forceunitoutput = 'no' )
2016-02-25 13:46:38 +01:00
{
2017-10-13 13:28:26 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
2016-11-16 09:40:29 +01:00
2017-10-13 13:28:26 +02:00
if (( $forceunitoutput == 'no' && $dimension < 1 / 10000 ) || ( is_numeric ( $forceunitoutput ) && $forceunitoutput == - 6 ))
{
$dimension = $dimension * 1000000 ;
$unit = $unit - 6 ;
}
elseif (( $forceunitoutput == 'no' && $dimension < 1 / 10 ) || ( is_numeric ( $forceunitoutput ) && $forceunitoutput == - 3 ))
{
$dimension = $dimension * 1000 ;
$unit = $unit - 3 ;
}
elseif (( $forceunitoutput == 'no' && $dimension > 100000000 ) || ( is_numeric ( $forceunitoutput ) && $forceunitoutput == 6 ))
{
$dimension = $dimension / 1000000 ;
$unit = $unit + 6 ;
}
elseif (( $forceunitoutput == 'no' && $dimension > 100000 ) || ( is_numeric ( $forceunitoutput ) && $forceunitoutput == 3 ))
{
$dimension = $dimension / 1000 ;
$unit = $unit + 3 ;
}
2016-11-16 09:40:29 +01:00
2017-10-13 13:28:26 +02:00
$ret = price ( $dimension , 0 , $outputlangs , 0 , 0 , $round ) . ' ' . measuring_units_string ( $unit , $type );
2016-11-16 09:40:29 +01:00
2017-10-13 13:28:26 +02:00
return $ret ;
2016-02-25 13:46:38 +01:00
}
2010-03-28 17:13:17 +02:00
/**
2015-11-14 15:28:25 +01:00
* Return localtax rate for a particular vat , when selling a product with vat $vatrate , from a $thirdparty_buyer to a $thirdparty_seller
2015-02-20 22:51:47 +01:00
* Note : This function applies same rules than get_default_tva
2011-09-02 23:56:37 +02:00
*
2016-02-27 11:32:49 +01:00
* @ param float $vatrate Vat rate . Can be '8.5' or '8.5 (VATCODEX)' for example
2012-09-05 14:05:17 +02:00
* @ param int $local Local tax to search and return ( 1 or 2 return only tax rate 1 or tax rate 2 )
* @ param Societe $thirdparty_buyer Object of buying third party
2016-12-19 02:33:54 +01:00
* @ param Societe $thirdparty_seller Object of selling third party ( $mysoc if not defined )
2016-02-27 11:32:49 +01:00
* @ param int $vatnpr If vat rate is NPR or not
2015-11-14 15:28:25 +01:00
* @ return mixed 0 if not found , localtax rate if found
2012-11-06 23:45:16 +01:00
* @ see get_default_tva
2010-03-28 17:13:17 +02:00
*/
2016-02-27 11:32:49 +01:00
function get_localtax ( $vatrate , $local , $thirdparty_buyer = " " , $thirdparty_seller = " " , $vatnpr = 0 )
2010-03-28 17:13:17 +02:00
{
2012-08-03 23:29:08 +02:00
global $db , $conf , $mysoc ;
2012-09-05 14:05:17 +02:00
if ( empty ( $thirdparty_seller ) || ! is_object ( $thirdparty_seller )) $thirdparty_seller = $mysoc ;
2014-03-01 15:59:09 +01:00
2015-11-14 15:28:25 +01:00
dol_syslog ( " get_localtax tva= " . $vatrate . " local= " . $local . " thirdparty_buyer id= " . ( is_object ( $thirdparty_buyer ) ? $thirdparty_buyer -> id : '' ) . " /country_code= " . ( is_object ( $thirdparty_buyer ) ? $thirdparty_buyer -> country_code : '' ) . " thirdparty_seller id= " . $thirdparty_seller -> id . " /country_code= " . $thirdparty_seller -> country_code . " thirdparty_seller localtax1_assuj= " . $thirdparty_seller -> localtax1_assuj . " thirdparty_seller localtax2_assuj= " . $thirdparty_seller -> localtax2_assuj );
2012-08-03 23:29:08 +02:00
2015-11-14 15:28:25 +01:00
$vatratecleaned = $vatrate ;
if ( preg_match ( '/^(.*)\s*\((.*)\)$/' , $vatrate , $reg )) // If vat is "xx (yy)"
2014-07-03 17:39:31 +02:00
{
2017-10-13 13:28:26 +02:00
$vatratecleaned = trim ( $reg [ 1 ]);
$vatratecode = $reg [ 2 ];
2014-07-03 17:39:31 +02:00
}
2016-11-16 09:40:29 +01:00
2015-11-14 15:28:25 +01:00
/* if ( $thirdparty_buyer -> country_code != $thirdparty_seller -> country_code )
{
return 0 ;
} */
2016-11-16 09:40:29 +01:00
2012-09-05 14:05:17 +02:00
// Some test to guess with no need to make database access
2018-01-05 01:27:48 +01:00
if ( $mysoc -> country_code == 'ES' ) // For spain localtaxes 1 and 2, tax is qualified if buyer use local tax
2012-11-16 16:23:51 +01:00
{
2013-04-07 17:39:08 +02:00
if ( $local == 1 )
2013-04-04 16:32:06 +02:00
{
2016-10-24 02:11:49 +02:00
if ( ! $mysoc -> localtax1_assuj || ( string ) $vatratecleaned == " 0 " ) return 0 ;
2015-11-14 15:28:25 +01:00
if ( $thirdparty_seller -> id == $mysoc -> id )
2013-04-04 16:32:06 +02:00
{
if ( ! $thirdparty_buyer -> localtax1_assuj ) return 0 ;
}
2013-04-07 17:39:08 +02:00
else
2013-04-04 16:32:06 +02:00
{
if ( ! $thirdparty_seller -> localtax1_assuj ) return 0 ;
}
}
2013-04-07 17:39:08 +02:00
2013-06-30 23:01:28 +02:00
if ( $local == 2 )
2013-06-25 11:12:21 +02:00
{
2016-10-24 02:11:49 +02:00
if ( ! $mysoc -> localtax2_assuj || ( string ) $vatratecleaned == " 0 " ) return 0 ;
2015-11-14 15:28:25 +01:00
if ( $thirdparty_seller -> id == $mysoc -> id )
2013-06-25 11:12:21 +02:00
{
if ( ! $thirdparty_buyer -> localtax2_assuj ) return 0 ;
}
else
{
if ( ! $thirdparty_seller -> localtax2_assuj ) return 0 ;
}
}
2012-11-16 16:23:51 +01:00
}
2012-12-02 12:59:06 +01:00
else
2012-11-16 16:23:51 +01:00
{
if ( $local == 1 && ! $thirdparty_seller -> localtax1_assuj ) return 0 ;
if ( $local == 2 && ! $thirdparty_seller -> localtax2_assuj ) return 0 ;
}
2012-09-05 14:05:17 +02:00
2016-12-19 02:33:54 +01:00
// For some country MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY is forced to on.
if ( in_array ( $mysoc -> country_code , array ( 'ES' )))
2012-08-03 23:29:08 +02:00
{
2017-10-13 13:28:26 +02:00
$conf -> global -> MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1 ;
2016-12-19 02:33:54 +01:00
}
2017-05-25 08:48:59 +02:00
2012-08-03 23:29:08 +02:00
// Search local taxes
2016-12-19 02:33:54 +01:00
if ( ! empty ( $conf -> global -> MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY ))
2015-11-14 15:28:25 +01:00
{
2017-10-13 13:28:26 +02:00
if ( $local == 1 )
{
if ( $thirdparty_seller != $mysoc )
{
if ( ! isOnlyOneLocalTax ( $local )) // TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
{
return $thirdparty_seller -> localtax1_value ;
}
}
else // i am the seller
{
if ( ! isOnlyOneLocalTax ( $local )) // TODO If seller is me, why not always returning this, even if there is only one locatax vat.
{
return $conf -> global -> MAIN_INFO_VALUE_LOCALTAX1 ;
}
}
}
if ( $local == 2 )
{
if ( $thirdparty_seller != $mysoc )
{
if ( ! isOnlyOneLocalTax ( $local )) // TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
// TODO We should also return value defined on thirdparty only if defined
{
return $thirdparty_seller -> localtax2_value ;
}
}
else // i am the seller
{
if ( ! isOnlyOneLocalTax ( $local )) // This is for spain only, we don't return value found into datbase even if there is only one locatax vat.
{
return $conf -> global -> MAIN_INFO_VALUE_LOCALTAX2 ;
}
}
}
2015-11-14 15:28:25 +01:00
}
// By default, search value of local tax on line of common tax
2012-11-27 15:33:11 +01:00
$sql = " SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type " ;
2015-11-14 15:28:25 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE t.fk_pays = c.rowid AND c.code = ' " . $thirdparty_seller -> country_code . " ' " ;
$sql .= " AND t.taux = " . (( float ) $vatratecleaned ) . " AND t.active = 1 " ;
2016-02-27 11:32:49 +01:00
if ( $vatratecode ) $sql .= " AND t.code =' " . $vatratecode . " ' " ; // If we have the code, we use it in priority
2017-04-15 03:05:04 +02:00
else $sql .= " AND t.recuperableonly =' " . $vatnpr . " ' " ;
2015-11-14 15:28:25 +01:00
dol_syslog ( " get_localtax " , LOG_DEBUG );
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
if ( $local == 1 ) return $obj -> localtax1 ;
elseif ( $local == 2 ) return $obj -> localtax2 ;
2012-08-03 23:29:08 +02:00
}
2016-11-16 09:40:29 +01:00
2012-08-03 23:29:08 +02:00
return 0 ;
2010-03-28 17:13:17 +02:00
}
2008-08-06 16:50:06 +02:00
2014-07-03 17:39:31 +02:00
/**
2015-11-14 15:28:25 +01:00
* Return true if LocalTax ( 1 or 2 ) is unique .
* Example : If localtax1 is 5 on line with highest common vat rate , return true
* Example : If localtax1 is 5 : 8 : 15 on line with highest common vat rate , return false
2014-07-04 14:19:03 +02:00
*
2015-11-14 15:28:25 +01:00
* @ param int $local Local tax to test ( 1 or 2 )
* @ return boolean True if LocalTax have multiple values , False if not
2014-07-03 17:39:31 +02:00
*/
function isOnlyOneLocalTax ( $local )
{
$tax = get_localtax_by_third ( $local );
$valors = explode ( " : " , $tax );
2014-07-04 14:19:03 +02:00
2015-11-14 15:28:25 +01:00
if ( count ( $valors ) > 1 )
2014-07-03 17:39:31 +02:00
{
return false ;
}
else
{
return true ;
}
}
/**
2015-11-14 15:28:25 +01:00
* Get values of localtaxes ( 1 or 2 ) for company country for the common vat with the highest value
2014-07-04 14:19:03 +02:00
*
2014-07-03 17:39:31 +02:00
* @ param int $local LocalTax to get
* @ return number Values of localtax
*/
function get_localtax_by_third ( $local )
{
global $db , $mysoc ;
2014-08-10 13:37:39 +02:00
$sql = " SELECT t.localtax1, t.localtax2 " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t inner join " . MAIN_DB_PREFIX . " c_country as c ON c.rowid=t.fk_pays " ;
2015-11-14 15:28:25 +01:00
$sql .= " WHERE c.code = ' " . $mysoc -> country_code . " ' AND t.active = 1 AND t.taux=( " ;
$sql .= " SELECT max(tt.taux) FROM " . MAIN_DB_PREFIX . " c_tva as tt inner join " . MAIN_DB_PREFIX . " c_country as c ON c.rowid=tt.fk_pays " ;
$sql .= " WHERE c.code = ' " . $mysoc -> country_code . " ' AND tt.active = 1 " ;
$sql .= " ) " ;
2014-07-03 17:39:31 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
if ( $local == 1 ) return $obj -> localtax1 ;
elseif ( $local == 2 ) return $obj -> localtax2 ;
}
2014-07-04 14:19:03 +02:00
2014-07-03 17:39:31 +02:00
return 0 ;
}
2016-03-19 21:35:03 +01:00
/**
2017-06-15 23:58:56 +02:00
* Get vat main information from Id .
* You can call getLocalTaxesFromRate after to get other fields .
2016-03-19 21:35:03 +01:00
*
2017-06-15 23:58:56 +02:00
* @ param int | string $vatrate VAT ID or Rate . Value can be value or the string with code into parenthesis or rowid if $firstparamisid is 1. Example : '8.5' or '8.5 (8.5NPR)' or 123.
* @ param Societe $buyer Company object
* @ param Societe $seller Company object
* @ param int $firstparamisid 1 if first param is id into table ( use this if you can )
* @ return array array ( 'rowid' => , 'code' => ... )
* @ see getLocalTaxesFromRate
2016-03-19 21:35:03 +01:00
*/
2017-06-15 23:58:56 +02:00
function getTaxesFromId ( $vatrate , $buyer = null , $seller = null , $firstparamisid = 1 )
2016-03-19 21:35:03 +01:00
{
2017-10-13 13:28:26 +02:00
global $db , $mysoc ;
2016-03-19 21:35:03 +01:00
2017-10-13 13:28:26 +02:00
dol_syslog ( " getTaxesFromId vatrowid= " . $vatrate );
2016-03-19 21:35:03 +01:00
2017-10-13 13:28:26 +02:00
// Search local taxes
$sql = " SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t " ;
if ( $firstparamisid ) $sql .= " WHERE t.rowid = " . ( int ) $vatrate ;
else
{
$vatratecleaned = $vatrate ;
$vatratecode = '' ;
if ( preg_match ( '/^(.*)\s*\((.*)\)$/' , $vatrate , $reg )) // If vat is "xx (yy)"
{
$vatratecleaned = $reg [ 1 ];
$vatratecode = $reg [ 2 ];
}
2017-06-15 23:58:56 +02:00
2017-10-13 13:28:26 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " c_country as c " ;
if ( $mysoc -> country_code == 'ES' ) $sql .= " WHERE t.fk_pays = c.rowid AND c.code = ' " . $buyer -> country_code . " ' " ; // local tax in spain use the buyer country ??
else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = ' " . $seller -> country_code . " ' " ;
$sql .= " AND t.taux = " . (( float ) $vatratecleaned ) . " AND t.active = 1 " ;
if ( $vatratecode ) $sql .= " AND t.code = ' " . $vatratecode . " ' " ;
}
2016-03-19 21:35:03 +01:00
2017-10-13 13:28:26 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj ) return array ( 'rowid' => $obj -> rowid , 'code' => $obj -> code , 'rate' => $obj -> rate , 'npr' => $obj -> npr , 'accountancy_code_sell' => $obj -> accountancy_code_sell , 'accountancy_code_buy' => $obj -> accountancy_code_buy );
else return array ();
}
else dol_print_error ( $db );
2016-03-19 21:35:03 +01:00
2017-10-13 13:28:26 +02:00
return array ();
2016-03-19 21:35:03 +01:00
}
2013-01-10 08:27:12 +01:00
/**
2018-01-05 01:27:48 +01:00
* Get type and rate of localtaxes for a particular vat rate / country of a thirdparty .
* This does not take into account the seller setup if subject to vat or not , only country .
2013-09-10 11:39:20 +02:00
* TODO
2016-03-19 21:35:03 +01:00
* This function is ALSO called to retrieve type for building PDF . Such call of function must be removed .
2015-11-14 15:28:25 +01:00
* Instead this function must be called when adding a line to get the array of localtax and type , and then
2013-09-18 16:46:54 +02:00
* provide it to the function calcul_price_total .
2013-09-17 21:12:34 +02:00
*
2018-01-05 01:27:48 +01:00
* @ param int | string $vatrate VAT ID or Rate + Code . Value can be value or the string with code into parenthesis or rowid if $firstparamisid is 1. Example : '8.5' or '8.5 (8.5NPR)' or 123.
2017-06-15 23:58:56 +02:00
* @ param int $local Number of localtax ( 1 or 2 , or 0 to return 1 & 2 )
* @ param Societe $buyer Company object
* @ param Societe $seller Company object
2018-01-05 01:27:48 +01:00
* @ param int $firstparamisid 1 if first param is ID into table instead of Rate + code ( use this if you can )
2017-07-08 18:32:34 +02:00
* @ return array array ( localtax_type1 ( 1 - 6 / 0 if not found ), rate localtax1 , localtax_type2 , rate localtax2 , accountancycodecust , accountancycodesupp )
2017-06-15 23:58:56 +02:00
* @ see getTaxesFromId
2013-01-10 08:27:12 +01:00
*/
2016-03-19 21:35:03 +01:00
function getLocalTaxesFromRate ( $vatrate , $local , $buyer , $seller , $firstparamisid = 0 )
2013-01-10 08:27:12 +01:00
{
2015-11-14 15:28:25 +01:00
global $db , $mysoc ;
2013-01-10 08:27:12 +01:00
2015-02-25 18:06:54 +01:00
dol_syslog ( " getLocalTaxesFromRate vatrate= " . $vatrate . " local= " . $local );
2013-01-10 08:27:12 +01:00
// Search local taxes
2013-09-18 16:46:54 +02:00
$sql = " SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy " ;
2016-03-19 21:35:03 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t " ;
2017-06-15 23:58:56 +02:00
if ( $firstparamisid ) $sql .= " WHERE t.rowid = " . ( int ) $vatrate ;
2016-03-19 21:35:03 +01:00
else
{
2017-10-13 13:28:26 +02:00
$vatratecleaned = $vatrate ;
$vatratecode = '' ;
if ( preg_match ( '/^(.*)\s*\((.*)\)$/' , $vatrate , $reg )) // If vat is "xx (yy)"
{
$vatratecleaned = $reg [ 1 ];
$vatratecode = $reg [ 2 ];
}
2017-06-15 23:58:56 +02:00
2017-10-13 13:28:26 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " c_country as c " ;
if ( $mysoc -> country_code == 'ES' ) $sql .= " WHERE t.fk_pays = c.rowid AND c.code = ' " . $buyer -> country_code . " ' " ; // local tax in spain use the buyer country ??
else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = ' " . $seller -> country_code . " ' " ;
$sql .= " AND t.taux = " . (( float ) $vatratecleaned ) . " AND t.active = 1 " ;
if ( $vatratecode ) $sql .= " AND t.code = ' " . $vatratecode . " ' " ;
2016-03-19 21:35:03 +01:00
}
2016-11-16 09:40:29 +01:00
2013-01-10 08:27:12 +01:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
2014-07-03 17:39:31 +02:00
if ( $local == 1 )
2014-07-04 14:19:03 +02:00
{
2014-07-03 17:39:31 +02:00
if ( ! isOnlyOneLocalTax ( 1 ))
{
2017-06-23 11:12:17 +02:00
return array ( $obj -> localtax1_type , get_localtax ( $vatrate , $local , $buyer , $seller ), $obj -> accountancy_code_sell , $obj -> accountancy_code_buy );
2014-07-03 17:39:31 +02:00
}
else
2014-07-04 14:19:03 +02:00
{
2017-06-23 11:12:17 +02:00
return array ( $obj -> localtax1_type , $obj -> localtax1 , $obj -> accountancy_code_sell , $obj -> accountancy_code_buy );
2014-07-03 17:39:31 +02:00
}
}
elseif ( $local == 2 )
{
if ( ! isOnlyOneLocalTax ( 2 ))
{
2017-06-23 11:12:17 +02:00
return array ( $obj -> localtax2_type , get_localtax ( $vatrate , $local , $buyer , $seller ), $obj -> accountancy_code_sell , $obj -> accountancy_code_buy );
2014-07-03 17:39:31 +02:00
}
else
2014-07-04 14:19:03 +02:00
{
2017-06-23 11:12:17 +02:00
return array ( $obj -> localtax2_type , $obj -> localtax2 , $obj -> accountancy_code_sell , $obj -> accountancy_code_buy );
2014-07-03 17:39:31 +02:00
}
}
else
{
if ( ! isOnlyOneLocalTax ( 1 ))
{
if ( ! isOnlyOneLocalTax ( 2 ))
{
2017-06-23 11:12:17 +02:00
return array ( $obj -> localtax1_type , get_localtax ( $vatrate , 1 , $buyer , $seller ), $obj -> localtax2_type , get_localtax ( $vatrate , 2 , $buyer , $seller ), $obj -> accountancy_code_sell , $obj -> accountancy_code_buy );
2014-07-03 17:39:31 +02:00
}
else
{
2017-06-23 11:12:17 +02:00
return array ( $obj -> localtax1_type , get_localtax ( $vatrate , 1 , $buyer , $seller ), $obj -> localtax2_type , $obj -> localtax2 , $obj -> accountancy_code_sell , $obj -> accountancy_code_buy );
2014-07-03 17:39:31 +02:00
}
}
else
{
if ( ! isOnlyOneLocalTax ( 2 ))
{
2017-06-23 11:12:17 +02:00
return array ( $obj -> localtax1_type , $obj -> localtax1 , $obj -> localtax2_type , get_localtax ( $vatrate , 2 , $buyer , $seller ), $obj -> accountancy_code_sell , $obj -> accountancy_code_buy );
2014-07-03 17:39:31 +02:00
}
else
{
2017-06-23 11:12:17 +02:00
return array ( $obj -> localtax1_type , $obj -> localtax1 , $obj -> localtax2_type , $obj -> localtax2 , $obj -> accountancy_code_sell , $obj -> accountancy_code_buy );
2014-07-03 17:39:31 +02:00
}
2014-07-04 14:19:03 +02:00
}
2014-07-03 17:39:31 +02:00
}
2013-01-10 08:27:12 +01:00
}
return 0 ;
2012-12-19 18:51:49 +01:00
}
2008-08-06 16:50:06 +02:00
/**
2012-11-06 23:45:16 +01:00
* Return vat rate of a product in a particular selling country or default country vat if product is unknown
2017-03-04 21:45:19 +01:00
* Function called by get_default_tva
2017-05-25 08:48:59 +02:00
*
2012-05-08 21:55:52 +02:00
* @ param int $idprod Id of product or 0 if not a predefined product
* @ param Societe $thirdparty_seller Thirdparty with a -> country_code defined ( FR , US , IT , ... )
2013-09-28 13:24:58 +02:00
* @ param int $idprodfournprice Id product_fournisseur_price ( for " supplier " order / invoice )
2017-03-04 21:45:19 +01:00
* @ return float | string Vat rate to use with format 5.0 or '5.0 (XXX)'
2012-11-06 23:45:16 +01:00
* @ see get_product_localtax_for_country
2008-08-06 16:50:06 +02:00
*/
2012-05-08 21:55:52 +02:00
function get_product_vat_for_country ( $idprod , $thirdparty_seller , $idprodfournprice = 0 )
2008-08-06 16:50:06 +02:00
{
2013-09-28 13:24:58 +02:00
global $db , $conf , $mysoc ;
2012-08-03 23:29:08 +02:00
2013-09-28 13:24:58 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2012-08-29 08:17:25 +02:00
2012-08-03 23:29:08 +02:00
$ret = 0 ;
$found = 0 ;
if ( $idprod > 0 )
{
// Load product
$product = new Product ( $db );
$result = $product -> fetch ( $idprod );
2012-09-05 14:05:17 +02:00
if ( $mysoc -> country_code == $thirdparty_seller -> country_code ) // If selling country is ours
2012-08-03 23:29:08 +02:00
{
2013-09-28 13:24:58 +02:00
if ( $idprodfournprice > 0 ) // We want vat for product for a "supplier" order or invoice
2012-08-03 23:29:08 +02:00
{
$product -> get_buyprice ( $idprodfournprice , 0 , 0 , 0 );
$ret = $product -> vatrate_supplier ;
2017-11-14 09:53:06 +01:00
if ( $product -> default_vat_code ) $ret .= ' (' . $product -> default_vat_code . ')' ;
2012-08-03 23:29:08 +02:00
}
else
{
$ret = $product -> tva_tx ; // Default vat of product we defined
2017-03-04 21:45:19 +01:00
if ( $product -> default_vat_code ) $ret .= ' (' . $product -> default_vat_code . ')' ;
2012-08-03 23:29:08 +02:00
}
$found = 1 ;
}
else
{
2017-05-25 08:48:59 +02:00
// TODO Read default product vat according to countrycode and product. Vat for couple countrycode/product is a feature not implemeted yet.
2017-03-04 21:45:19 +01:00
// May be usefull/required if hidden option SERVICE_ARE_ECOMMERCE_200238EC is on
2012-08-03 23:29:08 +02:00
}
}
if ( ! $found )
{
2013-09-28 13:24:58 +02:00
if ( empty ( $conf -> global -> MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS ))
2012-08-03 23:29:08 +02:00
{
2017-03-04 14:18:04 +01:00
// If vat of product for the country not found or not defined, we return the first higher vat of country.
2013-09-28 13:24:58 +02:00
$sql = " SELECT taux as vat_rate " ;
2014-08-10 13:37:39 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code=' " . $thirdparty_seller -> country_code . " ' " ;
2017-03-04 14:18:04 +01:00
$sql .= " ORDER BY t.taux DESC, t.code ASC, t.recuperableonly ASC " ;
2013-09-28 13:24:58 +02:00
$sql .= $db -> plimit ( 1 );
2015-01-30 16:01:56 +01:00
2013-09-28 13:24:58 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
2012-08-03 23:29:08 +02:00
{
2013-09-28 13:24:58 +02:00
$obj = $db -> fetch_object ( $resql );
if ( $obj )
{
$ret = $obj -> vat_rate ;
}
$db -> free ( $sql );
2012-08-03 23:29:08 +02:00
}
2013-09-28 13:24:58 +02:00
else dol_print_error ( $db );
2012-08-03 23:29:08 +02:00
}
2016-02-19 01:47:00 +01:00
else $ret = $conf -> global -> MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS ; // Forced value if autodetect fails
2012-08-03 23:29:08 +02:00
}
dol_syslog ( " get_product_vat_for_country: ret= " . $ret );
return $ret ;
2008-08-06 16:50:06 +02:00
}
2010-03-27 17:18:10 +01:00
/**
2012-11-06 23:45:16 +01:00
* Return localtax vat rate of a product in a particular selling country or default country vat if product is unknown
2011-09-02 23:56:37 +02:00
*
2012-11-06 23:45:16 +01:00
* @ param int $idprod Id of product
* @ param int $local 1 for localtax1 , 2 for localtax 2
* @ param Societe $thirdparty_seller Thirdparty with a -> country_code defined ( FR , US , IT , ... )
* @ return int < 0 if KO , Vat rate if OK
* @ see get_product_vat_for_country
2010-03-27 17:18:10 +01:00
*/
2012-11-06 23:45:16 +01:00
function get_product_localtax_for_country ( $idprod , $local , $thirdparty_seller )
2010-03-27 17:18:10 +01:00
{
2012-11-06 23:45:16 +01:00
global $db , $mysoc ;
2010-03-27 17:18:10 +01:00
2012-11-06 23:45:16 +01:00
if ( ! class_exists ( 'Product' )) {
2016-11-24 17:03:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2012-11-06 23:45:16 +01:00
}
2010-03-29 01:36:52 +02:00
2012-11-14 11:31:08 +01:00
$ret = 0 ;
$found = 0 ;
if ( $idprod > 0 )
{
// Load product
$product = new Product ( $db );
$result = $product -> fetch ( $idprod );
if ( $mysoc -> country_code == $thirdparty_seller -> country_code ) // If selling country is ours
{
2012-11-06 23:45:16 +01:00
/* Not defined yet , so we don ' t use this
if ( $local == 1 ) $ret = $product -> localtax1_tx ;
elseif ( $local == 2 ) $ret = $product -> localtax2_tx ;
$found = 1 ;
2012-11-14 11:31:08 +01:00
*/
}
else
{
// TODO Read default product vat according to countrycode and product
}
}
if ( ! $found )
{
// If vat of product for the country not found or not defined, we return higher vat of country.
$sql = " SELECT taux as vat_rate, localtax1, localtax2 " ;
2014-08-10 13:37:39 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_tva as t, " . MAIN_DB_PREFIX . " c_country as c " ;
$sql .= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code=' " . $thirdparty_seller -> country_code . " ' " ;
2012-11-14 11:31:08 +01:00
$sql .= " ORDER BY t.taux DESC, t.recuperableonly ASC " ;
$sql .= $db -> plimit ( 1 );
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
if ( $obj )
{
if ( $local == 1 ) $ret = $obj -> localtax1 ;
2012-11-06 23:45:16 +01:00
elseif ( $local == 2 ) $ret = $obj -> localtax2 ;
2012-11-14 11:31:08 +01:00
}
}
else dol_print_error ( $db );
}
dol_syslog ( " get_product_localtax_for_country: ret= " . $ret );
2012-11-06 23:45:16 +01:00
return $ret ;
2010-03-27 17:18:10 +01:00
}
2008-08-06 16:50:06 +02:00
/**
2010-09-07 02:38:03 +02:00
* Function that return vat rate of a product line ( according to seller , buyer and product vat rate )
* Si vendeur non assujeti a TVA , TVA par defaut = 0. Fin de regle .
* Si le ( pays vendeur = pays acheteur ) alors TVA par defaut = TVA du produit vendu . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et ( bien vendu = moyen de transports neuf comme auto , bateau , avion ) alors TVA par defaut = 0 ( La TVA doit etre paye par acheteur au centre d ' impots de son pays et non au vendeur ) . Fin de regle .
* Si ( vendeur et acheteur dans Communaute europeenne ) et ( acheteur = particulier ou entreprise sans num TVA intra ) alors TVA par defaut = TVA du produit vendu . Fin de regle
* Si ( vendeur et acheteur dans Communaute europeenne ) et ( acheteur = entreprise avec num TVA ) intra alors TVA par defaut = 0. Fin de regle
* Sinon TVA proposee par defaut = 0. Fin de regle .
2011-10-09 17:37:27 +02:00
*
2012-09-05 14:05:17 +02:00
* @ param Societe $thirdparty_seller Objet societe vendeuse
* @ param Societe $thirdparty_buyer Objet societe acheteuse
2011-10-09 17:37:27 +02:00
* @ param int $idprod Id product
2012-05-08 21:55:52 +02:00
* @ param int $idprodfournprice Id product_fournisseur_price ( for supplier order / invoice )
2017-03-04 21:45:19 +01:00
* @ return float | string Vat rate to use with format 5.0 or '5.0 (XXX)' , - 1 if we can ' t guess it
2013-05-31 21:17:49 +02:00
* @ see get_default_npr , get_default_localtax
2008-08-06 16:50:06 +02:00
*/
2016-04-17 15:05:54 +02:00
function get_default_tva ( Societe $thirdparty_seller , Societe $thirdparty_buyer , $idprod = 0 , $idprodfournprice = 0 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf ;
2018-01-13 19:33:40 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2014-03-01 15:59:09 +01:00
// Note: possible values for tva_assuj are 0/1 or franchise/reel
$seller_use_vat = (( is_numeric ( $thirdparty_seller -> tva_assuj ) && ! $thirdparty_seller -> tva_assuj ) || ( ! is_numeric ( $thirdparty_seller -> tva_assuj ) && $thirdparty_seller -> tva_assuj == 'franchise' )) ? 0 : 1 ;
2018-01-13 19:33:40 +01:00
$seller_country_code = $thirdparty_seller -> country_code ;
$seller_in_cee = isInEEC ( $thirdparty_seller );
2014-03-01 15:59:09 +01:00
2018-01-13 19:33:40 +01:00
$buyer_country_code = $thirdparty_buyer -> country_code ;
$buyer_in_cee = isInEEC ( $thirdparty_buyer );
2014-03-01 15:59:09 +01:00
dol_syslog ( " get_default_tva: seller use vat= " . $seller_use_vat . " , seller country= " . $seller_country_code . " , seller in cee= " . $seller_in_cee . " , buyer country= " . $buyer_country_code . " , buyer in cee= " . $buyer_in_cee . " , idprod= " . $idprod . " , idprodfournprice= " . $idprodfournprice . " , SERVICE_ARE_ECOMMERCE_200238EC= " . ( ! empty ( $conf -> global -> SERVICES_ARE_ECOMMERCE_200238EC ) ? $conf -> global -> SERVICES_ARE_ECOMMERCE_200238EC : '' ));
2012-08-03 23:29:08 +02:00
2013-01-19 16:29:16 +01:00
// If services are eServices according to EU Council Directive 2002/38/EC (http://ec.europa.eu/taxation_customs/taxation/vat/traders/e-commerce/article_1610_en.htm)
// we use the buyer VAT.
if ( ! empty ( $conf -> global -> SERVICE_ARE_ECOMMERCE_200238EC ))
{
2015-01-25 16:04:37 +01:00
if ( $seller_in_cee && $buyer_in_cee && ! $thirdparty_buyer -> isACompany ())
2013-01-19 16:29:16 +01:00
{
2014-03-01 15:59:09 +01:00
//print 'VATRULE 0';
2013-01-19 16:29:16 +01:00
return get_product_vat_for_country ( $idprod , $thirdparty_buyer , $idprodfournprice );
}
}
2014-03-01 15:59:09 +01:00
// If seller does not use VAT
if ( ! $seller_use_vat )
2012-08-03 23:29:08 +02:00
{
//print 'VATRULE 1';
return 0 ;
}
// Le test ci-dessus ne devrait pas etre necessaire. Me signaler l'exemple du cas juridique concerne si le test suivant n'est pas suffisant.
// Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
2014-03-01 15:59:09 +01:00
if (( $seller_country_code == $buyer_country_code )
|| ( in_array ( $seller_country_code , array ( 'FR,MC' )) && in_array ( $buyer_country_code , array ( 'FR' , 'MC' )))) // Warning ->country_code not always defined
2012-08-03 23:29:08 +02:00
{
2014-03-01 15:59:09 +01:00
//print 'VATRULE 2';
2012-09-05 14:05:17 +02:00
return get_product_vat_for_country ( $idprod , $thirdparty_seller , $idprodfournprice );
2012-08-03 23:29:08 +02:00
}
// Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
2014-03-01 15:59:09 +01:00
// Not supported
2012-08-03 23:29:08 +02:00
// Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = entreprise) alors TVA par defaut=0. Fin de regle
// Si (vendeur et acheteur dans Communaute europeenne) et (acheteur = particulier) alors TVA par defaut=TVA du produit vendu. Fin de regle
2014-03-01 15:59:09 +01:00
if (( $seller_in_cee && $buyer_in_cee ))
2012-08-03 23:29:08 +02:00
{
2012-09-05 14:05:17 +02:00
$isacompany = $thirdparty_buyer -> isACompany ();
2012-08-03 23:29:08 +02:00
if ( $isacompany )
{
2014-03-01 15:59:09 +01:00
//print 'VATRULE 3';
2012-08-03 23:29:08 +02:00
return 0 ;
}
else
{
2014-03-01 15:59:09 +01:00
//print 'VATRULE 4';
2012-09-05 14:05:17 +02:00
return get_product_vat_for_country ( $idprod , $thirdparty_seller , $idprodfournprice );
2012-08-03 23:29:08 +02:00
}
}
// Sinon la TVA proposee par defaut=0. Fin de regle.
// Rem: Cela signifie qu'au moins un des 2 est hors Communaute europeenne et que le pays differe
2014-03-01 15:59:09 +01:00
//print 'VATRULE 5';
2012-08-03 23:29:08 +02:00
return 0 ;
2008-08-06 16:50:06 +02:00
}
/**
2011-05-03 21:03:08 +02:00
* Fonction qui renvoie si tva doit etre tva percue recuperable
2011-10-09 17:37:27 +02:00
*
2013-04-05 22:38:46 +02:00
* @ param Societe $thirdparty_seller Thirdparty seller
* @ param Societe $thirdparty_buyer Thirdparty buyer
2011-10-09 17:37:27 +02:00
* @ param int $idprod Id product
2013-04-05 22:38:46 +02:00
* @ param int $idprodfournprice Id supplier price for product
2011-10-09 17:37:27 +02:00
* @ return float 0 or 1
2013-05-31 21:17:49 +02:00
* @ see get_default_tva , get_default_localtax
2008-08-06 16:50:06 +02:00
*/
2016-04-17 15:05:54 +02:00
function get_default_npr ( Societe $thirdparty_seller , Societe $thirdparty_buyer , $idprod = 0 , $idprodfournprice = 0 )
2008-08-06 16:50:06 +02:00
{
2013-03-26 05:47:17 +01:00
global $db ;
2013-04-05 22:38:46 +02:00
if ( $idprodfournprice > 0 )
{
2013-04-18 11:05:31 +02:00
if ( ! class_exists ( 'ProductFournisseur' ))
2016-11-24 17:03:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php' ;
2013-04-05 22:38:46 +02:00
$prodprice = new ProductFournisseur ( $db );
$prodprice -> fetch_product_fournisseur_price ( $idprodfournprice );
return $prodprice -> fourn_tva_npr ;
2013-03-26 05:47:17 +01:00
}
2013-04-05 22:38:46 +02:00
elseif ( $idprod > 0 )
2013-03-26 05:47:17 +01:00
{
2013-04-18 11:05:31 +02:00
if ( ! class_exists ( 'Product' ))
2016-11-24 17:03:18 +01:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2013-03-26 05:47:17 +01:00
$prod = new Product ( $db );
$prod -> fetch ( $idprod );
return $prod -> tva_npr ;
}
2012-08-03 23:29:08 +02:00
return 0 ;
2008-08-06 16:50:06 +02:00
}
2010-03-27 17:18:10 +01:00
/**
2011-05-03 21:03:08 +02:00
* Function that return localtax of a product line ( according to seller , buyer and product vat rate )
2012-11-06 23:45:16 +01:00
* Si vendeur non assujeti a TVA , TVA par defaut = 0. Fin de regle .
* Si le ( pays vendeur = pays acheteur ) alors TVA par defaut = TVA du produit vendu . Fin de regle .
* Sinon TVA proposee par defaut = 0. Fin de regle .
2011-08-30 00:55:04 +02:00
*
2013-04-05 22:38:46 +02:00
* @ param Societe $thirdparty_seller Thirdparty seller
* @ param Societe $thirdparty_buyer Thirdparty buyer
2011-10-09 17:37:27 +02:00
* @ param int $local Localtax to process ( 1 or 2 )
* @ param int $idprod Id product
2015-03-17 00:21:17 +01:00
* @ return integer localtax , - 1 si ne peut etre determine
2013-05-31 21:17:49 +02:00
* @ see get_default_tva , get_default_npr
2010-03-27 17:18:10 +01:00
*/
2012-09-05 14:05:17 +02:00
function get_default_localtax ( $thirdparty_seller , $thirdparty_buyer , $local , $idprod = 0 )
2010-03-27 17:18:10 +01:00
{
2012-12-01 15:45:05 +01:00
global $mysoc ;
2012-12-02 12:59:06 +01:00
2012-09-05 14:05:17 +02:00
if ( ! is_object ( $thirdparty_seller )) return - 1 ;
if ( ! is_object ( $thirdparty_buyer )) return - 1 ;
2012-08-03 23:29:08 +02:00
2012-12-01 15:45:05 +01:00
if ( $local == 1 ) // Localtax 1
2012-08-03 23:29:08 +02:00
{
2012-12-01 15:45:05 +01:00
if ( $mysoc -> country_code == 'ES' )
{
if ( is_numeric ( $thirdparty_buyer -> localtax1_assuj ) && ! $thirdparty_buyer -> localtax1_assuj ) return 0 ;
}
2012-12-02 12:59:06 +01:00
else
2012-12-01 15:45:05 +01:00
{
// Si vendeur non assujeti a Localtax1, localtax1 par default=0
if ( is_numeric ( $thirdparty_seller -> localtax1_assuj ) && ! $thirdparty_seller -> localtax1_assuj ) return 0 ;
if ( ! is_numeric ( $thirdparty_seller -> localtax1_assuj ) && $thirdparty_seller -> localtax1_assuj == 'localtax1off' ) return 0 ;
}
2012-11-06 23:45:16 +01:00
}
2012-12-01 15:45:05 +01:00
elseif ( $local == 2 ) //I Localtax 2
2012-11-06 23:45:16 +01:00
{
2012-12-01 15:45:05 +01:00
// Si vendeur non assujeti a Localtax2, localtax2 par default=0
2012-11-06 23:45:16 +01:00
if ( is_numeric ( $thirdparty_seller -> localtax2_assuj ) && ! $thirdparty_seller -> localtax2_assuj ) return 0 ;
if ( ! is_numeric ( $thirdparty_seller -> localtax2_assuj ) && $thirdparty_seller -> localtax2_assuj == 'localtax2off' ) return 0 ;
}
2012-08-03 23:29:08 +02:00
2012-11-06 23:45:16 +01:00
if ( $thirdparty_seller -> country_code == $thirdparty_buyer -> country_code )
{
return get_product_localtax_for_country ( $idprod , $local , $thirdparty_seller );
2012-08-03 23:29:08 +02:00
}
2012-11-06 23:45:16 +01:00
2012-08-03 23:29:08 +02:00
return 0 ;
2010-03-27 17:18:10 +01:00
}
2008-08-06 16:50:06 +02:00
/**
2011-05-03 21:03:08 +02:00
* Return yes or no in current language
2011-09-02 23:56:37 +02:00
*
2012-02-04 15:20:32 +01:00
* @ param string $yesno Value to test ( 1 , 'yes' , 'true' or 0 , 'no' , 'false' )
2015-03-17 00:21:17 +01:00
* @ param integer $case 1 = Yes / No , 0 = yes / no , 2 = Disabled checkbox , 3 = Disabled checkbox + Yes / No
2012-02-04 15:20:32 +01:00
* @ param int $color 0 = texte only , 1 = Text is formated with a color font style ( 'ok' or 'error' ), 2 = Text is formated with 'ok' color .
* @ return string HTML string
2008-08-06 16:50:06 +02:00
*/
function yn ( $yesno , $case = 1 , $color = 0 )
{
2012-08-03 23:29:08 +02:00
global $langs ;
2017-04-15 03:05:04 +02:00
$result = 'unknown' ; $classname = '' ;
2012-08-03 23:29:08 +02:00
if ( $yesno == 1 || strtolower ( $yesno ) == 'yes' || strtolower ( $yesno ) == 'true' ) // A mettre avant test sur no a cause du == 0
{
2014-12-07 01:57:23 +01:00
$result = $langs -> trans ( 'yes' );
if ( $case == 1 || $case == 3 ) $result = $langs -> trans ( " Yes " );
2015-05-07 11:57:23 +02:00
if ( $case == 2 ) $result = '<input type="checkbox" value="1" checked disabled>' ;
if ( $case == 3 ) $result = '<input type="checkbox" value="1" checked disabled> ' . $result ;
2014-12-07 01:57:23 +01:00
2012-08-03 23:29:08 +02:00
$classname = 'ok' ;
}
elseif ( $yesno == 0 || strtolower ( $yesno ) == 'no' || strtolower ( $yesno ) == 'false' )
{
2014-12-07 01:57:23 +01:00
$result = $langs -> trans ( " no " );
if ( $case == 1 || $case == 3 ) $result = $langs -> trans ( " No " );
2015-05-07 11:57:23 +02:00
if ( $case == 2 ) $result = '<input type="checkbox" value="0" disabled>' ;
if ( $case == 3 ) $result = '<input type="checkbox" value="0" disabled> ' . $result ;
2014-12-07 01:57:23 +01:00
2012-08-03 23:29:08 +02:00
if ( $color == 2 ) $classname = 'ok' ;
else $classname = 'error' ;
}
if ( $color ) return '<font class="' . $classname . '">' . $result . '</font>' ;
return $result ;
2008-08-06 16:50:06 +02:00
}
/**
2018-01-13 16:09:05 +01:00
* Return a path to have a the directory according to object where files are stored .
2017-05-20 15:52:36 +02:00
* New usage : $conf -> module -> multidir_output [ $object -> entity ] . '/' . get_exdir ( 0 , 0 , 0 , 1 , $object , $modulepart )
* or : $conf -> module -> dir_output . '/' . get_exdir ( 0 , 0 , 0 , 1 , $object , $modulepart ) if multidir_output not defined .
2018-01-13 16:09:05 +01:00
* Example our with new usage : $object is invoice -> 'INYYMM-ABCD'
* Example our with old usage : '015' with level 3 -> " 0/1/5/ " , '015' with level 1 -> " 5/ " , 'ABC-1' with level 3 -> " 0/0/1/ "
2015-11-02 17:56:00 +01:00
*
* @ param string $num Id of object ( deprecated , $object will be used in future )
* @ param int $level Level of subdirs to return ( 1 , 2 or 3 levels ) . ( deprecated , global option will be used in future )
* @ param int $alpha 0 = Keep number only to forge path , 1 = Use alpha part afer the - ( By default , use 0 ) . ( deprecated , global option will be used in future )
* @ param int $withoutslash 0 = With slash at end ( except if '/' , we return '' ), 1 = without slash at end
2015-05-18 22:25:51 +02:00
* @ param Object $object Object
* @ param string $modulepart Type of object ( 'invoice_supplier, ' donation ', ' invoice ', ...' )
2015-05-18 21:47:44 +02:00
* @ return string Dir to use ending . Example '' or '1/' or '1/2/'
2008-08-06 16:50:06 +02:00
*/
2016-10-16 17:25:33 +02:00
function get_exdir ( $num , $level , $alpha , $withoutslash , $object , $modulepart )
2008-08-06 16:50:06 +02:00
{
2015-05-18 21:47:44 +02:00
global $conf ;
2012-08-03 23:29:08 +02:00
$path = '' ;
2018-01-02 17:27:05 +01:00
2017-12-22 19:49:31 +01:00
$arrayforoldpath = array ( 'cheque' , 'user' , 'category' , 'holiday' , 'supplier_invoice' , 'invoice_supplier' , 'mailing' , 'supplier_payment' );
2016-11-16 09:40:29 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_OLD_PATH_FOR_PHOTO )) $arrayforoldpath [] = 'product' ;
2016-01-22 14:02:48 +01:00
if ( ! empty ( $level ) && in_array ( $modulepart , $arrayforoldpath ))
2015-05-18 21:47:44 +02:00
{
2017-05-05 12:33:49 +02:00
// This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided.
2015-05-18 21:47:44 +02:00
if ( empty ( $alpha )) $num = preg_replace ( '/([^0-9])/i' , '' , $num );
else $num = preg_replace ( '/^.*\-/i' , '' , $num );
$num = substr ( " 000 " . $num , - $level );
if ( $level == 1 ) $path = substr ( $num , 0 , 1 );
if ( $level == 2 ) $path = substr ( $num , 1 , 1 ) . '/' . substr ( $num , 0 , 1 );
if ( $level == 3 ) $path = substr ( $num , 2 , 1 ) . '/' . substr ( $num , 1 , 1 ) . '/' . substr ( $num , 0 , 1 );
}
else
{
// TODO
2015-12-21 17:32:57 +01:00
// We will enhance here a common way of forging path for document storage
2018-01-13 16:09:05 +01:00
// Here, object->id, object->ref and modulepart are required.
2017-12-22 19:49:31 +01:00
if ( in_array ( $modulepart , array ( 'thirdparty' , 'contact' , 'member' , 'propal' , 'proposal' , 'commande' , 'order' , 'facture' , 'invoice' , 'shipment' )))
2017-10-13 13:28:26 +02:00
{
2018-01-13 16:09:05 +01:00
$path = ( $object -> ref ? $object -> ref : $object -> id );
2017-10-13 13:28:26 +02:00
}
2015-05-18 21:47:44 +02:00
}
if ( empty ( $withoutslash ) && ! empty ( $path )) $path .= '/' ;
2018-01-13 16:09:05 +01:00
2012-08-03 23:29:08 +02:00
return $path ;
2008-08-06 16:50:06 +02:00
}
/**
2011-09-24 04:01:26 +02:00
* Creation of a directory ( this can create recursive subdir )
2011-09-02 23:56:37 +02:00
*
2012-09-02 22:48:52 +02:00
* @ param string $dir Directory to create ( Separator must be '/' . Example : '/mydir/mysubdir' )
2012-09-03 10:17:58 +02:00
* @ param string $dataroot Data root directory ( To avoid having the data root in the loop . Using this will also lost the warning on first dir PHP has no permission when open_basedir is used )
2015-04-30 16:20:24 +02:00
* @ param int $newmask Mask for new file ( Defaults to $conf -> global -> MAIN_UMASK or 0755 if unavailable ) . Example : '0444'
2012-09-02 22:48:52 +02:00
* @ return int < 0 if KO , 0 = already exists , > 0 if OK
2008-08-06 16:50:06 +02:00
*/
2015-04-30 16:20:24 +02:00
function dol_mkdir ( $dir , $dataroot = '' , $newmask = null )
2008-08-06 16:50:06 +02:00
{
2012-09-03 10:17:58 +02:00
global $conf ;
2012-08-03 23:29:08 +02:00
dol_syslog ( " functions.lib::dol_mkdir: dir= " . $dir , LOG_INFO );
$dir_osencoded = dol_osencode ( $dir );
if ( @ is_dir ( $dir_osencoded )) return 0 ;
$nberr = 0 ;
$nbcreated = 0 ;
2012-09-02 22:48:52 +02:00
$ccdir = '' ;
if ( ! empty ( $dataroot )) {
// Remove data root from loop
$dir = str_replace ( $dataroot . '/' , '' , $dir );
$ccdir = $dataroot . '/' ;
}
$cdir = explode ( " / " , $dir );
2012-08-03 23:29:08 +02:00
$num = count ( $cdir );
for ( $i = 0 ; $i < $num ; $i ++ )
{
if ( $i > 0 ) $ccdir .= '/' . $cdir [ $i ];
2012-09-03 17:25:35 +02:00
else $ccdir .= $cdir [ $i ];
2012-08-03 23:29:08 +02:00
if ( preg_match ( " /^.: $ / " , $ccdir , $regs )) continue ; // Si chemin Windows incomplet, on poursuit par rep suivant
// Attention, le is_dir() peut echouer bien que le rep existe.
// (ex selon config de open_basedir)
if ( $ccdir )
{
$ccdir_osencoded = dol_osencode ( $ccdir );
if ( ! @ is_dir ( $ccdir_osencoded ))
{
dol_syslog ( " functions.lib::dol_mkdir: Directory ' " . $ccdir . " ' does not exists or is outside open_basedir PHP setting. " , LOG_DEBUG );
umask ( 0 );
2015-04-04 00:19:03 +02:00
$dirmaskdec = octdec ( $newmask );
2015-04-30 16:20:24 +02:00
if ( empty ( $newmask )) {
$dirmaskdec = empty ( $conf -> global -> MAIN_UMASK ) ? octdec ( '0755' ) : octdec ( $conf -> global -> MAIN_UMASK );
}
2012-08-03 23:29:08 +02:00
$dirmaskdec |= octdec ( '0111' ); // Set x bit required for directories
if ( ! @ mkdir ( $ccdir_osencoded , $dirmaskdec ))
{
// Si le is_dir a renvoye une fausse info, alors on passe ici.
dol_syslog ( " functions.lib::dol_mkdir: Fails to create directory ' " . $ccdir . " ' or directory already exists. " , LOG_WARNING );
$nberr ++ ;
}
else
{
dol_syslog ( " functions.lib::dol_mkdir: Directory ' " . $ccdir . " ' created " , LOG_DEBUG );
$nberr = 0 ; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignore
$nbcreated ++ ;
}
}
else
{
$nberr = 0 ; // On remet a zero car si on arrive ici, cela veut dire que les echecs precedents peuvent etre ignores
}
}
}
return ( $nberr ? - $nberr : $nbcreated );
2008-08-06 16:50:06 +02:00
}
/**
2011-05-03 21:03:08 +02:00
* Return picto saying a field is required
2011-09-02 23:56:37 +02:00
*
2011-05-03 21:03:08 +02:00
* @ return string Chaine avec picto obligatoire
2008-08-06 16:50:06 +02:00
*/
function picto_required ()
{
2012-08-03 23:29:08 +02:00
return '<span class="fieldrequired">*</span>' ;
2008-08-06 16:50:06 +02:00
}
/**
2017-09-16 10:26:27 +02:00
* Clean a string from all HTML tags and entities .
* This function differs from strip_tags because :
* - < br > are replace with \n
* - if entities are found , they are decoded before the strip
* - you can decide to convert line feed into spaces
2011-09-02 23:56:37 +02:00
*
2017-09-16 10:26:27 +02:00
* @ param string $stringtoclean String to clean
2016-11-16 19:23:32 +01:00
* @ param integer $removelinefeed 1 = Replace also new lines by a space , 0 = Only last one are removed
2013-05-15 13:24:18 +02:00
* @ param string $pagecodeto Encoding of input / output string
2011-12-28 01:19:52 +01:00
* @ return string String cleaned
2014-06-21 01:26:41 +02:00
*
2017-09-16 10:26:27 +02:00
* @ see dol_escape_htmltag strip_tags
2008-08-06 16:50:06 +02:00
*/
2017-09-16 10:26:27 +02:00
function dol_string_nohtmltag ( $stringtoclean , $removelinefeed = 1 , $pagecodeto = 'UTF-8' )
2008-08-06 16:50:06 +02:00
{
2017-11-01 10:09:39 +01:00
// TODO Try to replace with strip_tags($stringtoclean)
2014-05-07 19:06:15 +02:00
$pattern = " /<[^<>]+>/ " ;
2017-09-16 10:26:27 +02:00
$stringtoclean = preg_replace ( '/<br[^>]*>/' , " \n " , $stringtoclean );
$temp = dol_html_entity_decode ( $stringtoclean , ENT_COMPAT , $pagecodeto );
2012-08-03 23:29:08 +02:00
2017-10-13 13:28:26 +02:00
// Exemple of $temp: <a href="/myurl" title="<u>A title</u>">0000-021</a>
$temp = preg_replace ( $pattern , " " , $temp ); // pass 1
// $temp after pass 1: <a href="/myurl" title="A title">0000-021
$temp = preg_replace ( $pattern , " " , $temp ); // pass 2
// $temp after pass 2: 0000-021
2017-05-31 19:20:33 +02:00
2012-08-03 23:29:08 +02:00
// Supprime aussi les retours
if ( $removelinefeed ) $temp = str_replace ( array ( " \r \n " , " \r " , " \n " ), " " , $temp );
// et les espaces doubles
while ( strpos ( $temp , " " ))
{
$temp = str_replace ( " " , " " , $temp );
}
2017-09-16 10:26:27 +02:00
return trim ( $temp );
2008-08-06 16:50:06 +02:00
}
2016-04-22 19:07:32 +02:00
/**
* Return first line of text . Cut will depends if content is HTML or not .
*
* @ param string $text Input text
2017-07-22 12:47:35 +02:00
* @ param int $nboflines Nb of lines to get ( default is 1 = first line only )
2016-04-22 19:07:32 +02:00
* @ return string Output text
2016-11-16 19:23:32 +01:00
* @ see dol_nboflines_bis , dol_string_nohtmltag , dol_escape_htmltag
2016-04-22 19:07:32 +02:00
*/
2017-07-22 12:47:35 +02:00
function dolGetFirstLineOfText ( $text , $nboflines = 1 )
2016-04-22 19:07:32 +02:00
{
2017-07-22 12:47:35 +02:00
if ( $nboflines == 1 )
2016-04-22 19:07:32 +02:00
{
2017-07-22 12:47:35 +02:00
if ( dol_textishtml ( $text ))
{
$firstline = preg_replace ( '/<br[^>]*>.*$/s' , '' , $text ); // The s pattern modifier means the . can match newline characters
$firstline = preg_replace ( '/<div[^>]*>.*$/s' , '' , $firstline ); // The s pattern modifier means the . can match newline characters
2016-11-16 09:40:29 +01:00
2017-07-22 12:47:35 +02:00
}
else
{
2017-10-13 13:28:26 +02:00
$firstline = preg_replace ( '/[\n\r].*/' , '' , $text );
2017-07-22 12:47:35 +02:00
}
2017-10-13 13:28:26 +02:00
return $firstline . (( strlen ( $firstline ) != strlen ( $text )) ? '...' : '' );
2016-04-22 19:07:32 +02:00
}
else
{
2017-07-22 12:47:35 +02:00
$ishtml = 0 ;
if ( dol_textishtml ( $text ))
{
$text = preg_replace ( '/\n/' , '' , $text );
$ishtml = 1 ;
$repTable = array ( " \t " => " " , " \n " => " " , " \r " => " " , " \0 " => " " , " \x0B " => " " );
}
else
{
$repTable = array ( " \t " => " " , " \n " => " <br> " , " \r " => " " , " \0 " => " " , " \x0B " => " " );
}
$text = strtr ( $text , $repTable );
if ( $charset == 'UTF-8' ) { $pattern = '/(<br[^>]*>)/Uu' ; } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
else $pattern = '/(<br[^>]*>)/U' ; // /U is to have UNGREEDY regex to limit to one html tag.
$a = preg_split ( $pattern , $text , - 1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
$firstline = '' ;
$i = 0 ;
$nba = count ( $a ); // 2x nb of lines in $a because $a contains also a line for each new line separator
while (( $i < $nba ) && ( $i < ( $nboflines * 2 )))
{
if ( $i % 2 == 0 ) $firstline .= $a [ $i ];
elseif (( $i < (( $nboflines * 2 ) - 1 )) && ( $i < ( $nba - 1 ))) $firstline .= ( $ishtml ? " <br> \n " : " \n " );
$i ++ ;
}
unset ( $a );
2017-10-13 13:28:26 +02:00
return $firstline . (( $i < $nba ) ? '...' : '' );
2016-04-22 19:07:32 +02:00
}
}
2008-08-06 16:50:06 +02:00
/**
2014-07-15 17:35:12 +02:00
* Replace CRLF in string with a HTML BR tag
2011-09-02 23:56:37 +02:00
*
2014-07-15 17:35:12 +02:00
* @ param string $stringtoencode String to encode
* @ param int $nl2brmode 0 = Adding br before \n , 1 = Replacing \n by br
* @ param bool $forxml false = Use < br > , true = Use < br />
* @ return string String encoded
2016-04-22 19:07:32 +02:00
* @ see dol_nboflines , dolGetFirstLineOfText
2008-08-06 16:50:06 +02:00
*/
2010-08-21 20:53:19 +02:00
function dol_nl2br ( $stringtoencode , $nl2brmode = 0 , $forxml = false )
2008-08-06 16:50:06 +02:00
{
2014-07-22 04:07:33 +02:00
if ( ! $nl2brmode ) {
return nl2br ( $stringtoencode , $forxml );
} else {
$ret = preg_replace ( '/(\r\n|\r|\n)/i' , ( $forxml ? '<br />' : '<br>' ), $stringtoencode );
2012-08-03 23:29:08 +02:00
return $ret ;
}
2008-08-06 16:50:06 +02:00
}
2014-10-16 01:01:30 +02:00
2008-08-06 16:50:06 +02:00
/**
2011-05-01 12:24:46 +02:00
* This function is called to encode a string into a HTML string but differs from htmlentities because
2015-03-03 17:47:17 +01:00
* a detection is done before to see if text is already HTML or not . Also , all entities but & , < , > are converted .
* This permits to encode special chars to entities with no double encoding for already encoded HTML strings .
2014-01-10 01:25:28 +01:00
* This function also remove last EOL or BR if $removelasteolbr = 1 ( default ) .
2011-05-01 12:24:46 +02:00
* For PDF usage , you can show text by 2 ways :
* - writeHTMLCell -> param must be encoded into HTML .
* - MultiCell -> param must not be encoded into HTML .
* Because writeHTMLCell convert also \n into < br > , if function
2014-01-10 01:25:28 +01:00
* is used to build PDF , nl2brmode must be 1.
2011-09-02 23:56:37 +02:00
*
2011-12-08 20:16:57 +01:00
* @ param string $stringtoencode String to encode
* @ param int $nl2brmode 0 = Adding br before \n , 1 = Replacing \n by br ( for use with FPDF writeHTMLCell function for example )
* @ param string $pagecodefrom Pagecode stringtoencode is encoded
2014-01-10 03:39:43 +01:00
* @ param int $removelasteolbr 1 = Remove last br or lasts \n ( default ), 0 = Do nothing
2011-12-28 08:32:30 +01:00
* @ return string String encoded
2008-08-06 16:50:06 +02:00
*/
2018-01-02 17:27:05 +01:00
function dol_htmlentitiesbr ( $stringtoencode , $nl2brmode = 0 , $pagecodefrom = 'UTF-8' , $removelasteolbr = 1 )
2008-08-06 16:50:06 +02:00
{
2014-01-10 01:25:28 +01:00
$newstring = $stringtoencode ;
2015-03-03 17:47:17 +01:00
if ( dol_textishtml ( $stringtoencode )) // Check if text is already HTML or not
2012-08-03 23:29:08 +02:00
{
$newstring = preg_replace ( '/<br(\s[\sa-zA-Z_="]*)?\/?>/i' , '<br>' , $newstring ); // Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
2014-01-10 01:25:28 +01:00
if ( $removelasteolbr ) $newstring = preg_replace ( '/<br>$/i' , '' , $newstring ); // Remove last <br> (remove only last one)
2012-08-03 23:29:08 +02:00
$newstring = strtr ( $newstring , array ( '&' => '__and__' , '<' => '__lt__' , '>' => '__gt__' , '"' => '__dquot__' ));
$newstring = dol_htmlentities ( $newstring , ENT_COMPAT , $pagecodefrom ); // Make entity encoding
$newstring = strtr ( $newstring , array ( '__and__' => '&' , '__lt__' => '<' , '__gt__' => '>' , '__dquot__' => '"' ));
}
else
2015-04-16 14:22:48 +02:00
{
2014-01-10 01:25:28 +01:00
if ( $removelasteolbr ) $newstring = preg_replace ( '/(\r\n|\r|\n)$/i' , '' , $newstring ); // Remove last \n (may remove several)
$newstring = dol_nl2br ( dol_htmlentities ( $newstring , ENT_COMPAT , $pagecodefrom ), $nl2brmode );
2012-08-03 23:29:08 +02:00
}
// Other substitutions that htmlentities does not do
//$newstring=str_replace(chr(128),'€',$newstring); // 128 = 0x80. Not in html entity table. // Seems useles with TCPDF. Make bug with UTF8 languages
return $newstring ;
2008-08-06 16:50:06 +02:00
}
2008-10-24 03:01:56 +02:00
/**
2011-05-03 21:03:08 +02:00
* This function is called to decode a HTML string ( it decodes entities and br tags )
2011-09-02 23:56:37 +02:00
*
2011-12-28 01:19:52 +01:00
* @ param string $stringtodecode String to decode
* @ param string $pagecodeto Page code for result
2011-12-28 08:32:30 +01:00
* @ return string String decoded
2008-08-06 16:50:06 +02:00
*/
2008-10-24 03:01:56 +02:00
function dol_htmlentitiesbr_decode ( $stringtodecode , $pagecodeto = 'UTF-8' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
$ret = dol_html_entity_decode ( $stringtodecode , ENT_COMPAT , $pagecodeto );
$ret = preg_replace ( '/' . " \r \n " . '<br(\s[\sa-zA-Z_="]*)?\/?>/i' , " <br> " , $ret );
$ret = preg_replace ( '/<br(\s[\sa-zA-Z_="]*)?\/?>' . " \r \n " . '/i' , " \r \n " , $ret );
$ret = preg_replace ( '/<br(\s[\sa-zA-Z_="]*)?\/?>' . " \n " . '/i' , " \n " , $ret );
$ret = preg_replace ( '/<br(\s[\sa-zA-Z_="]*)?\/?>/i' , " \n " , $ret );
return $ret ;
2008-08-06 16:50:06 +02:00
}
2008-10-25 19:27:15 +02:00
/**
2011-05-03 21:03:08 +02:00
* This function remove all ending \n and br at end
2011-09-02 23:56:37 +02:00
*
2011-12-28 01:19:52 +01:00
* @ param string $stringtodecode String to decode
* @ return string String decoded
2008-10-25 19:27:15 +02:00
*/
function dol_htmlcleanlastbr ( $stringtodecode )
{
2012-08-03 23:29:08 +02:00
$ret = preg_replace ( '/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|' . " \n " . '|' . " \r " . ')+$/i' , " " , $stringtodecode );
return $ret ;
2008-10-25 19:27:15 +02:00
}
2010-08-10 01:57:45 +02:00
/**
* Replace html_entity_decode functions to manage errors
2011-09-02 23:56:37 +02:00
*
2011-12-28 01:19:52 +01:00
* @ param string $a Operand a
2014-05-07 19:06:15 +02:00
* @ param string $b Operand b ( ENT_QUOTES = convert simple and double quotes )
2011-12-28 01:19:52 +01:00
* @ param string $c Operand c
2011-12-28 08:32:30 +01:00
* @ return string String decoded
2010-08-10 01:57:45 +02:00
*/
2012-03-18 00:59:24 +01:00
function dol_html_entity_decode ( $a , $b , $c = 'UTF-8' )
2010-08-10 01:57:45 +02:00
{
2015-03-23 01:39:12 +01:00
return html_entity_decode ( $a , $b , $c );
2010-08-10 01:57:45 +02:00
}
/**
2017-10-03 18:35:35 +02:00
* Replace htmlentities functions .
2015-03-02 00:37:47 +01:00
* Goal of this function is to be sure to have default values of htmlentities that match what we need .
2011-09-02 23:56:37 +02:00
*
2017-10-03 18:35:35 +02:00
* @ param string $string The input string to encode
* @ param int $flags Flags ( see PHP doc above )
* @ param string $encoding Encoding page code
* @ param bool $double_encode When double_encode is turned off , PHP will not encode existing html entities
2013-09-20 10:56:15 +02:00
* @ return string $ret Encoded string
2010-08-10 01:57:45 +02:00
*/
2013-09-18 11:59:51 +02:00
function dol_htmlentities ( $string , $flags = null , $encoding = 'UTF-8' , $double_encode = false )
2010-08-10 01:57:45 +02:00
{
2014-07-15 17:35:12 +02:00
return htmlentities ( $string , $flags , $encoding , $double_encode );
2010-08-10 01:57:45 +02:00
}
2008-08-06 16:50:06 +02:00
/**
2011-05-03 21:03:08 +02:00
* Check if a string is a correct iso string
* If not , it will we considered not HTML encoded even if it is by FPDF .
2011-09-02 23:56:37 +02:00
* Example , if string contains euro symbol that has ascii code 128
*
2011-12-28 01:19:52 +01:00
* @ param string $s String to check
* @ return int 0 if bad iso , 1 if good iso
2008-08-06 16:50:06 +02:00
*/
function dol_string_is_good_iso ( $s )
{
2012-08-03 23:29:08 +02:00
$len = dol_strlen ( $s );
$ok = 1 ;
for ( $scursor = 0 ; $scursor < $len ; $scursor ++ )
{
$ordchar = ord ( $s { $scursor });
//print $scursor.'-'.$ordchar.'<br>';
if ( $ordchar < 32 && $ordchar != 13 && $ordchar != 10 ) { $ok = 0 ; break ; }
if ( $ordchar > 126 && $ordchar < 160 ) { $ok = 0 ; break ; }
}
return $ok ;
2008-08-06 16:50:06 +02:00
}
/**
2011-05-03 21:03:08 +02:00
* Return nb of lines of a clear text
2011-09-02 23:56:37 +02:00
*
2012-02-12 16:50:58 +01:00
* @ param string $s String to check
2014-07-15 17:35:12 +02:00
* @ param int $maxchar Not yet used
2012-02-12 16:50:58 +01:00
* @ return int Number of lines
2016-04-22 19:07:32 +02:00
* @ see dol_nboflines_bis , dolGetFirstLineOfText
2008-08-06 16:50:06 +02:00
*/
function dol_nboflines ( $s , $maxchar = 0 )
{
2012-08-03 23:29:08 +02:00
if ( $s == '' ) return 0 ;
$arraystring = explode ( " \n " , $s );
$nb = count ( $arraystring );
2008-10-09 19:29:32 +02:00
2012-08-03 23:29:08 +02:00
return $nb ;
2008-08-06 16:50:06 +02:00
}
/**
2017-07-22 12:47:35 +02:00
* Return nb of lines of a formated text with \n and < br > ( WARNING : string must not have mixed \n and br separators )
2011-09-02 23:56:37 +02:00
*
2012-02-04 15:20:32 +01:00
* @ param string $text Text
* @ param int $maxlinesize Largeur de ligne en caracteres ( ou 0 si pas de limite - defaut )
* @ param string $charset Give the charset used to encode the $text variable in memory .
* @ return int Number of lines
2015-05-19 00:44:05 +02:00
* @ see dol_nboflines , dolGetFirstLineOfText
2008-08-06 16:50:06 +02:00
*/
2011-07-04 10:38:51 +02:00
function dol_nboflines_bis ( $text , $maxlinesize = 0 , $charset = 'UTF-8' )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
$repTable = array ( " \t " => " " , " \n " => " <br> " , " \r " => " " , " \0 " => " " , " \x0B " => " " );
if ( dol_textishtml ( $text )) $repTable = array ( " \t " => " " , " \n " => " " , " \r " => " " , " \0 " => " " , " \x0B " => " " );
$text = strtr ( $text , $repTable );
if ( $charset == 'UTF-8' ) { $pattern = '/(<br[^>]*>)/Uu' ; } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
else $pattern = '/(<br[^>]*>)/U' ; // /U is to have UNGREEDY regex to limit to one html tag.
$a = preg_split ( $pattern , $text , - 1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
2016-10-21 10:36:11 +02:00
$nblines = ( int ) floor (( count ( $a ) + 1 ) / 2 );
2012-08-03 23:29:08 +02:00
// count possible auto line breaks
if ( $maxlinesize )
{
foreach ( $a as $line )
{
if ( dol_strlen ( $line ) > $maxlinesize )
{
//$line_dec = html_entity_decode(strip_tags($line));
$line_dec = html_entity_decode ( $line );
if ( dol_strlen ( $line_dec ) > $maxlinesize )
{
$line_dec = wordwrap ( $line_dec , $maxlinesize , '\n' , true );
$nblines += substr_count ( $line_dec , '\n' );
}
}
}
}
2017-07-22 12:47:35 +02:00
unset ( $a );
2012-08-03 23:29:08 +02:00
return $nblines ;
2008-08-06 16:50:06 +02:00
}
/**
2011-05-03 21:03:08 +02:00
* Same function than microtime in PHP 5 but compatible with PHP4
2011-09-02 23:56:37 +02:00
*
2014-07-15 17:35:12 +02:00
* @ return float Time ( millisecondes ) with microsecondes in decimal part
* @ deprecated Dolibarr does not support PHP4 , you should use native function
2015-04-23 23:21:06 +02:00
* @ see microtime ()
2008-08-06 16:50:06 +02:00
*/
function dol_microtime_float ()
{
2015-04-23 23:21:06 +02:00
dol_syslog ( __FUNCTION__ . " is deprecated " , LOG_WARNING );
2014-07-18 12:00:01 +02:00
return microtime ( true );
2008-08-06 16:50:06 +02:00
}
2011-05-25 15:27:07 +02:00
/**
2012-09-16 20:23:57 +02:00
* Return if a text is a html content
2011-09-02 23:56:37 +02:00
*
2012-09-16 20:23:57 +02:00
* @ param string $msg Content to check
* @ param int $option 0 = Full detection , 1 = Fast check
* @ return boolean true / false
* @ see dol_concatdesc
2008-08-06 16:50:06 +02:00
*/
function dol_textishtml ( $msg , $option = 0 )
{
2012-08-03 23:29:08 +02:00
if ( $option == 1 )
{
if ( preg_match ( '/<html/i' , $msg )) return true ;
elseif ( preg_match ( '/<body/i' , $msg )) return true ;
elseif ( preg_match ( '/<br/i' , $msg )) return true ;
return false ;
}
else
{
if ( preg_match ( '/<html/i' , $msg )) return true ;
elseif ( preg_match ( '/<body/i' , $msg )) return true ;
2016-07-26 16:11:38 +02:00
elseif ( preg_match ( '/<(b|em|i|u)>/i' , $msg )) return true ;
2016-06-29 13:14:53 +02:00
elseif ( preg_match ( '/<(br|div|font|li|p|span|strong|table)>/i' , $msg )) return true ;
elseif ( preg_match ( '/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i' , $msg )) return true ;
elseif ( preg_match ( '/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i' , $msg )) return true ;
2015-06-08 17:13:23 +02:00
elseif ( preg_match ( '/<img\s+[^<>]*src[^<>]*>/i' , $msg )) return true ; // must accept <img src="http://example.com/aaa.png" />
elseif ( preg_match ( '/<a\s+[^<>]*href[^<>]*>/i' , $msg )) return true ; // must accept <a href="http://example.com/aaa.png" />
2014-05-24 14:57:41 +02:00
elseif ( preg_match ( '/<h[0-9]>/i' , $msg )) return true ;
2012-08-03 23:29:08 +02:00
elseif ( preg_match ( '/&[A-Z0-9]{1,6};/i' , $msg )) return true ; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
elseif ( preg_match ( '/&#[0-9]{2,3};/i' , $msg )) return true ; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
return false ;
}
2008-08-06 16:50:06 +02:00
}
2012-09-16 20:23:57 +02:00
/**
2016-04-07 12:42:18 +02:00
* Concat 2 descriptions with a new line between them ( second operand after first one with appropriate new line separator )
2012-09-16 20:23:57 +02:00
* text1 html + text2 html => text1 + '<br>' + text2
* text1 html + text2 txt => text1 + '<br>' + dol_nl2br ( text2 )
* text1 txt + text2 html => dol_nl2br ( text1 ) + '<br>' + text2
* text1 txt + text2 txt => text1 + '\n' + text2
*
* @ param string $text1 Text 1
* @ param string $text2 Text 2
2015-02-25 18:24:36 +01:00
* @ param bool $forxml false = Use < br > , true = Use < br />
2012-09-16 20:23:57 +02:00
* @ return string Text 1 + new line + Text2
* @ see dol_textishtml
*/
function dol_concatdesc ( $text1 , $text2 , $forxml = false )
{
$ret = '' ;
2012-09-17 19:33:44 +02:00
$ret .= ( ! dol_textishtml ( $text1 ) && dol_textishtml ( $text2 )) ? dol_nl2br ( $text1 , 0 , $forxml ) : $text1 ;
$ret .= ( ! empty ( $text1 ) && ! empty ( $text2 )) ? (( dol_textishtml ( $text1 ) || dol_textishtml ( $text2 )) ? ( $forxml ? " <br \ > \n " : " <br> \n " ) : " \n " ) : " " ;
2012-09-16 20:23:57 +02:00
$ret .= ( dol_textishtml ( $text1 ) && ! dol_textishtml ( $text2 )) ? dol_nl2br ( $text2 , 0 , $forxml ) : $text2 ;
2012-09-17 19:33:44 +02:00
return $ret ;
2012-09-16 20:23:57 +02:00
}
2017-06-01 01:53:55 +02:00
/**
2017-09-16 03:13:44 +02:00
* Return array of possible common substitutions . This includes several families like : 'system' , 'mycompany' , 'object' , 'objectamount' , 'date' , 'user'
2017-06-01 01:53:55 +02:00
*
* @ param Translate $outputlangs Output language
2017-09-16 03:13:44 +02:00
* @ param int $onlykey 1 = Do not calculate some heavy values of keys ( performance enhancement when we need only the keys ), 2 = Values are trunc and html sanitized ( to use for help tooltip )
* @ param array $exclude Array of family keys we want to exclude . For example array ( 'system' , 'mycompany' , 'object' , 'objectamount' , 'date' , 'user' , ... )
2017-06-01 01:53:55 +02:00
* @ param Object $object Object for keys on object
* @ return array Array of substitutions
2017-09-16 03:13:44 +02:00
* @ see setSubstitFromObject
2017-06-01 01:53:55 +02:00
*/
function getCommonSubstitutionArray ( $outputlangs , $onlykey = 0 , $exclude = null , $object = null )
{
2017-10-13 13:28:26 +02:00
global $db , $conf , $mysoc , $user ;
$substitutionarray = array ();
if ( empty ( $exclude ) || ! in_array ( 'system' , $exclude ))
{
2017-11-25 19:55:31 +01:00
$substitutionarray [ '__(AnyTranslationKey)__' ] = $outputlangs -> trans ( 'TranslationOfKey' );
$substitutionarray [ '__[AnyConstantKey]__' ] = $outputlangs -> trans ( 'ValueOfConstant' );
2017-10-13 13:28:26 +02:00
$substitutionarray [ '__DOL_MAIN_URL_ROOT__' ] = DOL_MAIN_URL_ROOT ;
}
2018-01-14 18:55:55 +01:00
if (( empty ( $exclude ) || ! in_array ( 'mycompany' , $exclude )) && is_object ( $mysoc ))
2017-10-13 13:28:26 +02:00
{
$substitutionarray = array_merge ( $substitutionarray , array (
'__MYCOMPANY_NAME__' => $mysoc -> name ,
'__MYCOMPANY_EMAIL__' => $mysoc -> email ,
'__MYCOMPANY_PROFID1__' => $mysoc -> idprof1 ,
'__MYCOMPANY_PROFID2__' => $mysoc -> idprof2 ,
'__MYCOMPANY_PROFID3__' => $mysoc -> idprof3 ,
'__MYCOMPANY_PROFID4__' => $mysoc -> idprof4 ,
'__MYCOMPANY_PROFID5__' => $mysoc -> idprof5 ,
'__MYCOMPANY_PROFID6__' => $mysoc -> idprof6 ,
'__MYCOMPANY_CAPITAL__' => $mysoc -> capital ,
'__MYCOMPANY_FULLADDRESS__' => $mysoc -> getFullAddress ( 1 , ', ' ),
'__MYCOMPANY_ADDRESS__' => $mysoc -> address ,
'__MYCOMPANY_ZIP__' => $mysoc -> zip ,
'__MYCOMPANY_TOWN__' => $mysoc -> town ,
'__MYCOMPANY_COUNTRY__' => $mysoc -> country ,
'__MYCOMPANY_COUNTRY_ID__' => $mysoc -> country_id
));
}
if (( $onlykey || is_object ( $object )) && ( empty ( $exclude ) || ! in_array ( 'object' , $exclude )))
{
if ( $onlykey )
{
$substitutionarray [ '__ID__' ] = '__ID__' ;
$substitutionarray [ '__REF__' ] = '__REF__' ;
$substitutionarray [ '__REFCLIENT__' ] = '__REFCLIENT__' ;
$substitutionarray [ '__REFSUPPLIER__' ] = '__REFSUPPLIER__' ;
$substitutionarray [ '__EXTRAFIELD_XXX__' ] = '__EXTRAFIELD_XXX__' ;
$substitutionarray [ '__THIRDPARTY_ID__' ] = '__THIRDPARTY_ID__' ;
$substitutionarray [ '__THIRDPARTY_NAME__' ] = '__THIRDPARTY_NAME__' ;
2018-02-22 17:05:24 +01:00
$substitutionarray [ '__THIRDPARTY_EMAIL__' ] = '__THIRDPARTY_EMAIL__' ;
2017-10-13 13:28:26 +02:00
if ( is_object ( $object ) && $object -> element == 'shipping' )
{
$substitutionarray [ '__MEMBER_CIVILITY__' ] = '__MEMBER_CIVILITY__' ;
$substitutionarray [ '__MEMBER_FIRSTNAME__' ] = '__MEMBER_FIRSTNAME__' ;
$substitutionarray [ '__MEMBER_LASTNAME__' ] = '__MEMBER_LASTNAME__' ;
}
$substitutionarray [ '__PROJECT_ID__' ] = '__PROJECT_ID__' ;
$substitutionarray [ '__PROJECT_REF__' ] = '__PROJECT_REF__' ;
$substitutionarray [ '__PROJECT_NAME__' ] = '__PROJECT_NAME__' ;
2017-09-22 14:34:31 +02:00
2017-09-22 15:12:36 +02:00
$substitutionarray [ '__CONTRACT_HIGHEST_PLANNED_START_DATE__' ] = 'Highest date planned for a service start' ;
$substitutionarray [ '__CONTRACT_HIGHEST_PLANNED_START_DATETIME__' ] = 'Highest date and hour planned for service start' ;
2017-10-13 13:28:26 +02:00
$substitutionarray [ '__CONTRACT_LOWEST_EXPIRATION_DATE__' ] = 'Lowest data for planned expiration of service' ;
$substitutionarray [ '__CONTRACT_LOWEST_EXPIRATION_DATETIME__' ] = 'Lowest date and hour for planned expiration of service' ;
$substitutionarray [ '__ONLINE_PAYMENT_URL__' ] = 'LinkToPayOnlineIfApplicable' ;
$substitutionarray [ '__SECUREKEYPAYMENT__' ] = 'Security key (if key is not unique per record)' ;
$substitutionarray [ '__SECUREKEYPAYMENT_MEMBER__' ] = 'Security key for payment on a member subscription (one key per member)' ;
$substitutionarray [ '__SECUREKEYPAYMENT_ORDER__' ] = 'Security key for payment on an order' ;
$substitutionarray [ '__SECUREKEYPAYMENT_INVOICE__' ] = 'Security key for payment on an invoice' ;
$substitutionarray [ '__SECUREKEYPAYMENT_CONTRACTLINE__' ] = 'Security key for payment on a a service' ;
if ( is_object ( $object ) && $object -> element == 'shipping' )
{
$substitutionarray [ '__SHIPPINGTRACKNUM__' ] = 'Shipping tacking number' ;
$substitutionarray [ '__SHIPPINGTRACKNUMURL__' ] = 'Shipping tracking url' ;
}
}
else
{
$substitutionarray [ '__ID__' ] = $object -> id ;
$substitutionarray [ '__REF__' ] = $object -> ref ;
$substitutionarray [ '__REFCLIENT__' ] = ( isset ( $object -> ref_client ) ? $object -> ref_client : ( isset ( $object -> ref_customer ) ? $object -> ref_customer : '' ));
$substitutionarray [ '__REFSUPPLIER__' ] = ( isset ( $object -> ref_supplier ) ? $object -> ref_supplier : '' );
// TODO USe this ?
$msgishtml = 0 ;
$birthday = dol_print_date ( $object -> birth , 'day' );
if ( method_exists ( $object , 'getCivilityLabel' )) $substitutionarray [ '__MEMBER_CIVILITY__' ] = $object -> getCivilityLabel ();
$substitutionarray [ '__MEMBER_FIRSTNAME__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> firstname ) : $object -> firstname ;
$substitutionarray [ '__MEMBER_LASTNAME__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> lastname ) : $object -> lastname ;
if ( method_exists ( $object , 'getFullName' )) $substitutionarray [ '__MEMBER_FULLNAME__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> getFullName ( $outputlangs )) : $object -> getFullName ( $outputlangs );
$substitutionarray [ '__MEMBER_COMPANY__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> societe ) : $object -> societe ;
$substitutionarray [ '__MEMBER_ADDRESS__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> address ) : $object -> address ;
$substitutionarray [ '__MEMBER_ZIP__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> zip ) : $object -> zip ;
$substitutionarray [ '__MEMBER_TOWN__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> town ) : $object -> town ;
$substitutionarray [ '__MEMBER_COUNTRY__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> country ) : $object -> country ;
$substitutionarray [ '__MEMBER_EMAIL__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> email ) : $object -> email ;
$substitutionarray [ '__MEMBER_BIRTH__' ] = $msgishtml ? dol_htmlentitiesbr ( $birthday ) : $birthday ;
$substitutionarray [ '__MEMBER_PHOTO__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> photo ) : $object -> photo ;
$substitutionarray [ '__MEMBER_LOGIN__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> login ) : $object -> login ;
$substitutionarray [ '__MEMBER_PASSWORD__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> pass ) : $object -> pass ;
$substitutionarray [ '__MEMBER_PHONE__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> phone ) : $object -> phone ;
$substitutionarray [ '__MEMBER_PHONEPRO__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> phone_perso ) : $object -> phone_perso ;
$substitutionarray [ '__MEMBER_PHONEMOBILE__' ] = $msgishtml ? dol_htmlentitiesbr ( $object -> phone_mobile ) : $object -> phone_mobile ;
2018-01-11 12:25:40 +01:00
if ( is_object ( $object ) && $object -> element == 'societe' )
2018-01-11 12:24:47 +01:00
{
$substitutionarray [ '__THIRDPARTY_ID__' ] = ( is_object ( $object ) ? $object -> id : '' );
$substitutionarray [ '__THIRDPARTY_NAME__' ] = ( is_object ( $object ) ? $object -> name : '' );
2018-02-23 11:03:48 +01:00
$substitutionarray [ '__THIRDPARTY_NAME_ALIAS__' ] = ( is_object ( $object ) ? $object -> name_alias : '' );
2018-02-22 17:05:24 +01:00
$substitutionarray [ '__THIRDPARTY_EMAIL__' ] = ( is_object ( $object ) ? $object -> email : '' );
2018-01-11 12:24:47 +01:00
}
2018-01-11 12:25:40 +01:00
elseif ( is_object ( $object -> thirdparty ) && $object -> thirdparty -> id > 0 )
2017-10-13 13:28:26 +02:00
{
$substitutionarray [ '__THIRDPARTY_ID__' ] = ( is_object ( $object -> thirdparty ) ? $object -> thirdparty -> id : '' );
$substitutionarray [ '__THIRDPARTY_NAME__' ] = ( is_object ( $object -> thirdparty ) ? $object -> thirdparty -> name : '' );
2018-02-23 11:03:48 +01:00
$substitutionarray [ '__THIRDPARTY_NAME_ALIAS__' ] = ( is_object ( $object -> thirdparty ) ? $object -> thirdparty -> name_alias : '' );
2018-02-22 17:05:24 +01:00
$substitutionarray [ '__THIRDPARTY_EMAIL__' ] = ( is_object ( $object -> thirdparty ) ? $object -> thirdparty -> email : '' );
2017-10-13 13:28:26 +02:00
}
if ( is_object ( $object -> projet ) && $object -> projet -> id > 0 )
{
$substitutionarray [ '__PROJECT_ID__' ] = ( is_object ( $object -> projet ) ? $object -> projet -> id : '' );
$substitutionarray [ '__PROJECT_REF__' ] = ( is_object ( $object -> projet ) ? $object -> projet -> ref : '' );
$substitutionarray [ '__PROJECT_NAME__' ] = ( is_object ( $object -> projet ) ? $object -> projet -> title : '' );
}
if ( is_object ( $object ) && $object -> element == 'shipping' )
{
$substitutionarray [ '__SHIPPINGTRACKNUM__' ] = $object -> tracking_number ;
$substitutionarray [ '__SHIPPINGTRACKNUMURL__' ] = $object -> tracking_url ;
}
if ( is_object ( $object ) && $object -> element == 'contrat' && is_array ( $object -> lines ))
{
$dateplannedstart = '' ;
$datenextexpiration = '' ;
foreach ( $object -> lines as $line )
{
if ( $line -> date_ouverture_prevue > $dateplannedstart ) $dateplannedstart = $line -> date_ouverture_prevue ;
if ( $line -> statut == 4 && $line -> date_fin_prevue && ( ! $datenextexpiration || $line -> date_fin_prevue < $datenextexpiration )) $datenextexpiration = $line -> date_fin_prevue ;
}
$substitutionarray [ '__CONTRACT_HIGHEST_PLANNED_START_DATE__' ] = dol_print_date ( $dateplannedstart , 'dayrfc' );
$substitutionarray [ '__CONTRACT_HIGHEST_PLANNED_START_DATETIME__' ] = dol_print_date ( $dateplannedstart , 'standard' );
$substitutionarray [ '__CONTRACT_LOWEST_EXPIRATION_DATE__' ] = dol_print_date ( $datenextexpiration , 'dayrfc' );
$substitutionarray [ '__CONTRACT_LOWEST_EXPIRATION_DATETIME__' ] = dol_print_date ( $datenextexpiration , 'standard' );
}
// Create dynamic tags for __EXTRAFIELD_FIELD__
if ( $object -> table_element && $object -> id > 0 )
{
$extrafieldstmp = new ExtraFields ( $db );
$extralabels = $extrafieldstmp -> fetch_name_optionals_label ( $object -> table_element , true );
$object -> fetch_optionals ( $object -> id , $extralabels );
foreach ( $extrafieldstmp -> attribute_label as $key => $label ) {
$substitutionarray [ '__EXTRAFIELD_' . strtoupper ( $key ) . '__' ] = $object -> array_options [ 'options_' . $key ];
}
}
$substitutionarray [ '__ONLINE_PAYMENT_URL__' ] = 'TODO' ;
}
}
if ( empty ( $exclude ) || ! in_array ( 'objectamount' , $exclude ))
{
2017-09-22 11:28:53 +02:00
$substitutionarray [ '__DATE_YMD__' ] = is_object ( $object ) ? ( isset ( $object -> date ) ? dol_print_date ( $object -> date , 'day' , 0 , $outputlangs ) : '' ) : '' ;
$substitutionarray [ '__DATE_DUE_YMD__' ] = is_object ( $object ) ? ( isset ( $object -> date_lim_reglement ) ? dol_print_date ( $object -> date_lim_reglement , 'day' , 0 , $outputlangs ) : '' ) : '' ;
2017-10-13 13:28:26 +02:00
$substitutionarray [ '__AMOUNT__' ] = is_object ( $object ) ? $object -> total_ttc : '' ;
2017-09-22 11:28:53 +02:00
$substitutionarray [ '__AMOUNT_EXCL_TAX__' ] = is_object ( $object ) ? $object -> total_ht : '' ;
2017-10-13 13:28:26 +02:00
$substitutionarray [ '__AMOUNT_VAT__' ] = is_object ( $object ) ? ( $object -> total_vat ? $object -> total_vat : $object -> total_tva ) : '' ;
2017-10-31 11:17:44 +01:00
if ( $onlykey != 2 || $mysoc -> useLocalTax ( 1 )) $substitutionarray [ '__AMOUNT_TAX2__' ] = is_object ( $object ) ? ( $object -> total_localtax1 ? $object -> total_localtax1 : $object -> total_localtax1 ) : '' ;
if ( $onlykey != 2 || $mysoc -> useLocalTax ( 2 )) $substitutionarray [ '__AMOUNT_TAX3__' ] = is_object ( $object ) ? ( $object -> total_localtax2 ? $object -> total_localtax2 : $object -> total_localtax2 ) : '' ;
2017-10-09 14:51:42 +02:00
/* TODO Add key for multicurrency
$substitutionarray [ '__AMOUNT_FORMATED__' ] = is_object ( $object ) ? price ( $object -> total_ttc , 0 , $outputlangs , 0 , 0 , - 1 , $conf -> currency_code ) : '' ;
$substitutionarray [ '__AMOUNT_EXCL_TAX_FORMATED__' ] = is_object ( $object ) ? price ( $object -> total_ht , 0 , $outputlangs , 0 , 0 , - 1 , $conf -> currency_code ) : '' ;
$substitutionarray [ '__AMOUNT_VAT_FORMATED__' ] = is_object ( $object ) ? ( $object -> total_vat ? price ( $object -> total_vat , 0 , $outputlangs , 0 , 0 , - 1 , $conf -> currency_code ) : price ( $object -> total_tva , 0 , $outputlangs , 0 , 0 , - 1 , $conf -> currency_code )) : '' ;
*/
2017-10-13 13:28:26 +02:00
// For backward compatibility
if ( $onlykey != 2 )
{
$substitutionarray [ '__TOTAL_TTC__' ] = is_object ( $object ) ? $object -> total_ttc : '' ;
$substitutionarray [ '__TOTAL_HT__' ] = is_object ( $object ) ? $object -> total_ht : '' ;
$substitutionarray [ '__TOTAL_VAT__' ] = is_object ( $object ) ? ( $object -> total_vat ? $object -> total_vat : $object -> total_tva ) : '' ;
}
}
if ( empty ( $exclude ) || ! in_array ( 'date' , $exclude ))
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
$tmp = dol_getdate ( dol_now (), true );
$tmp2 = dol_get_prev_day ( $tmp [ 'mday' ], $tmp [ 'mon' ], $tmp [ 'year' ]);
$tmp3 = dol_get_prev_month ( $tmp [ 'mday' ], $tmp [ 'mon' ], $tmp [ 'year' ]);
$tmp4 = dol_get_next_day ( $tmp [ 'mday' ], $tmp [ 'mon' ], $tmp [ 'year' ]);
$tmp5 = dol_get_next_month ( $tmp [ 'mday' ], $tmp [ 'mon' ], $tmp [ 'year' ]);
$substitutionarray = array_merge ( $substitutionarray , array (
'__DAY__' => ( string ) $tmp [ 'mday' ],
'__MONTH__' => ( string ) $tmp [ 'mon' ],
'__YEAR__' => ( string ) $tmp [ 'year' ],
'__PREVIOUS_DAY__' => ( string ) $tmp2 [ 'day' ],
'__PREVIOUS_MONTH__' => ( string ) $tmp3 [ 'month' ],
'__PREVIOUS_YEAR__' => ( string ) ( $tmp [ 'year' ] - 1 ),
'__NEXT_DAY__' => ( string ) $tmp4 [ 'day' ],
'__NEXT_MONTH__' => ( string ) $tmp5 [ 'month' ],
'__NEXT_YEAR__' => ( string ) ( $tmp [ 'year' ] + 1 ),
));
}
if ( empty ( $exclude ) || ! in_array ( 'user' , $exclude ))
{
2018-01-10 10:31:27 +01:00
// Add SIGNATURE into substitutionarray first, so, when we will make the substitution,
// this will also replace var found into content of signature
$signature = $user -> signature ;
$substitutionarray = array_merge ( $substitutionarray , array (
'__USER_SIGNATURE__' => ( string ) (( $signature && empty ( $conf -> global -> MAIN_MAIL_DO_NOT_USE_SIGN )) ? ( $onlykey == 2 ? dol_trunc ( dol_string_nohtmltag ( $signature ), 30 ) : $signature ) : '' )
)
);
// For backward compatibility
if ( $onlykey != 2 )
{
$substitutionarray [ '__SIGNATURE__' ] = ( string ) (( $signature && empty ( $conf -> global -> MAIN_MAIL_DO_NOT_USE_SIGN )) ? ( $onlykey == 2 ? dol_trunc ( dol_string_nohtmltag ( $signature ), 30 ) : $signature ) : '' );
}
2017-10-13 13:28:26 +02:00
$substitutionarray = array_merge ( $substitutionarray , array (
'__USER_ID__' => ( string ) $user -> id ,
'__USER_LOGIN__' => ( string ) $user -> login ,
'__USER_LASTNAME__' => ( string ) $user -> lastname ,
'__USER_FIRSTNAME__' => ( string ) $user -> firstname ,
'__USER_FULLNAME__' => ( string ) $user -> getFullName ( $outputlangs ),
2018-02-26 00:13:16 +01:00
'__USER_SUPERVISOR_ID__' => ( string ) ( $user -> fk_user ? $user -> fk_user : '0' )
2017-10-13 13:28:26 +02:00
)
);
}
if ( ! empty ( $conf -> multicompany -> enabled ))
{
$substitutionarray = array_merge ( $substitutionarray , array ( '__ENTITY_ID__' => $conf -> entity ));
}
return $substitutionarray ;
2017-06-01 01:53:55 +02:00
}
2008-11-16 02:09:04 +01:00
/**
2018-01-21 20:53:36 +01:00
* Make substitution into a text string , replacing keys with vals from $substitutionarray ( oldval => newval ) .
2018-01-25 20:35:25 +01:00
* Texts like __ ( TranslationKey | langfile ) __ and __ [ ConstantKey ] __ are also replaced .
* Example of usage :
* $substitutionarray = getCommonSubstitutionArray ( $langs , 0 , null , $thirdparty );
* complete_substitutions_array ( $substitutionarray , $langs , $thirdparty );
* $mesg = make_substitutions ( $mesg , $substitutionarray , $langs );
2011-10-03 18:10:50 +02:00
*
2017-04-17 13:02:40 +02:00
* @ param string $text Source string in which we must do substitution
2018-01-21 20:53:36 +01:00
* @ param array $substitutionarray Array with key -> val to substitute . Example : array ( '__MYKEY__' => 'MyVal' , ... )
2017-04-17 13:02:40 +02:00
* @ param Translate $outputlangs Output language
* @ return string Output string after substitutions
2012-02-27 00:58:00 +01:00
* @ see complete_substitutions_array
2008-08-06 16:50:06 +02:00
*/
2017-04-17 13:02:40 +02:00
function make_substitutions ( $text , $substitutionarray , $outputlangs = null )
2008-08-06 16:50:06 +02:00
{
2017-04-17 13:02:40 +02:00
global $conf , $langs ;
2012-09-06 19:07:51 +02:00
2012-08-03 23:29:08 +02:00
if ( ! is_array ( $substitutionarray )) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions' ;
2017-05-25 08:48:59 +02:00
2017-04-17 13:02:40 +02:00
if ( empty ( $outputlangs )) $outputlangs = $langs ;
2017-05-25 08:48:59 +02:00
2017-04-17 13:02:40 +02:00
// Make substitution for language keys
if ( is_object ( $outputlangs ))
{
2017-11-25 19:55:31 +01:00
while ( preg_match ( '/__\(([^\)]+)\)__/' , $text , $reg ))
2017-04-17 13:02:40 +02:00
{
2017-11-25 23:16:15 +01:00
$msgishtml = 0 ;
if ( dol_textishtml ( $text , 1 )) $msgishtml = 1 ;
2017-10-13 13:28:26 +02:00
// If key is __(TranslationKey|langfile)__, then force load of langfile.lang
2017-06-01 01:53:55 +02:00
$tmp = explode ( '|' , $reg [ 1 ]);
if ( ! empty ( $tmp [ 1 ])) $outputlangs -> load ( $tmp [ 1 ]);
$text = preg_replace ( '/__\(' . preg_quote ( $reg [ 1 ], '/' ) . '\)__/' , $msgishtml ? dol_htmlentitiesbr ( $outputlangs -> transnoentitiesnoconv ( $reg [ 1 ])) : $outputlangs -> transnoentitiesnoconv ( $reg [ 1 ]), $text );
2017-04-17 13:02:40 +02:00
}
}
2017-05-25 08:48:59 +02:00
2017-11-25 19:55:31 +01:00
// Make substitution for constant keys. Must be after the substitution of translation, so if text of translation contains a constant,
// it is also converted.
while ( preg_match ( '/__\[([^\]]+)\]__/' , $text , $reg ))
{
$msgishtml = 0 ;
if ( dol_textishtml ( $text , 1 )) $msgishtml = 1 ;
2017-11-25 23:16:15 +01:00
$keyfound = $reg [ 1 ];
2018-02-24 14:02:27 +01:00
if ( preg_match ( '/(_pass|password|secret|_key|key$)/i' , $keyfound )) $newval = '*****forbidden*****' ;
else $newval = empty ( $conf -> global -> $keyfound ) ? '' : $conf -> global -> $keyfound ;
2017-11-25 23:16:15 +01:00
$text = preg_replace ( '/__\[' . preg_quote ( $keyfound , '/' ) . '\]__/' , $msgishtml ? dol_htmlentitiesbr ( $newval ) : $newval , $text );
2017-11-25 19:55:31 +01:00
}
2017-04-17 13:02:40 +02:00
// Make substitition for array $substitutionarray
2012-08-03 23:29:08 +02:00
foreach ( $substitutionarray as $key => $value )
{
2017-10-13 10:35:21 +02:00
if ( $key == '__SIGNATURE__' && ( ! empty ( $conf -> global -> MAIN_MAIL_DO_NOT_USE_SIGN ))) $value = '' ; // Protection
if ( $key == '__USER_SIGNATURE__' && ( ! empty ( $conf -> global -> MAIN_MAIL_DO_NOT_USE_SIGN ))) $value = '' ; // Protection
2017-04-17 13:02:40 +02:00
$text = str_replace ( " $key " , " $value " , $text ); // We must keep the " to work when value is 123.5 for example
2012-08-03 23:29:08 +02:00
}
2012-09-06 19:07:51 +02:00
2017-04-17 13:02:40 +02:00
return $text ;
2008-08-06 16:50:06 +02:00
}
2011-06-08 23:11:52 +02:00
/**
2017-09-22 14:34:31 +02:00
* Complete the $substitutionarray with more entries coming from external module that had set the " substitutions=1 " into module_part array .
* In this case , method completesubstitutionarray provided by module is called .
2011-08-17 18:07:41 +02:00
*
2014-09-27 16:00:11 +02:00
* @ param array $substitutionarray Array substitution old value => new value value
2017-04-17 13:02:40 +02:00
* @ param Translate $outputlangs Output language
* @ param Object $object Source object
* @ param mixed $parameters Add more parameters ( useful to pass product lines )
2013-08-22 16:49:23 +02:00
* @ param string $callfunc What is the name of the custom function that will be called ? ( default : completesubstitutionarray )
2012-02-12 16:50:58 +01:00
* @ return void
2012-02-22 16:18:03 +01:00
* @ see make_substitutions
2011-06-08 23:11:52 +02:00
*/
2017-04-17 13:02:40 +02:00
function complete_substitutions_array ( & $substitutionarray , $outputlangs , $object = null , $parameters = null , $callfunc = " completesubstitutionarray " )
2011-06-08 23:11:52 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $user ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2012-08-03 23:29:08 +02:00
2017-04-17 13:02:40 +02:00
// Add a substitution key for each extrafields, using key __EXTRA_XXX__
2017-09-22 14:34:31 +02:00
// TODO Remove this. Already available into the getCommonSubstitutionArray used to build the substitution array.
2017-11-25 19:55:31 +01:00
/* if ( is_object ( $object ) && is_array ( $object -> array_options ))
2017-04-17 13:02:40 +02:00
{
foreach ( $object -> array_options as $key => $val )
{
$keyshort = preg_replace ( '/^(options|extra)_/' , '' , $key );
2017-11-25 19:55:31 +01:00
$substitutionarray [ '__EXTRAFIELD_' . $keyshort . '__' ] = $val ;
2017-04-17 13:02:40 +02:00
// For backward compatibiliy
$substitutionarray [ '%EXTRA_' . $keyshort . '%' ] = $val ;
}
2017-11-25 19:55:31 +01:00
} */
2017-05-25 08:48:59 +02:00
2017-04-17 13:02:40 +02:00
// Check if there is external substitution to do, requested by plugins
2012-08-03 23:29:08 +02:00
$dirsubstitutions = array_merge ( array (),( array ) $conf -> modules_parts [ 'substitutions' ]);
foreach ( $dirsubstitutions as $reldir )
{
$dir = dol_buildpath ( $reldir , 0 );
// Check if directory exists
if ( ! dol_is_dir ( $dir )) continue ;
$substitfiles = dol_dir_list ( $dir , 'files' , 0 , 'functions_' );
foreach ( $substitfiles as $substitfile )
{
if ( preg_match ( '/functions_(.*)\.lib\.php/i' , $substitfile [ 'name' ], $reg ))
{
$module = $reg [ 1 ];
dol_syslog ( " Library functions_ " . $substitfile [ 'name' ] . " found into " . $dir );
2013-04-03 00:57:40 +02:00
// Include the user's functions file
2012-08-22 23:11:24 +02:00
require_once $dir . $substitfile [ 'name' ];
2013-04-03 00:57:40 +02:00
// Call the user's function, and only if it is defined
2012-08-14 16:03:45 +02:00
$function_name = $module . " _ " . $callfunc ;
2012-09-11 20:15:03 +02:00
if ( function_exists ( $function_name )) $function_name ( $substitutionarray , $outputlangs , $object , $parameters );
2012-08-03 23:29:08 +02:00
}
}
}
2011-06-08 23:11:52 +02:00
}
2008-10-17 02:24:44 +02:00
/**
2010-08-29 14:54:39 +02:00
* Format output for start and end date
2011-08-17 18:07:41 +02:00
*
2015-02-25 18:24:36 +01:00
* @ param int $date_start Start date
* @ param int $date_end End date
2011-10-29 18:15:54 +02:00
* @ param string $format Output format
* @ param Translate $outputlangs Output language
2011-10-03 18:10:50 +02:00
* @ return void
2008-08-06 16:50:06 +02:00
*/
2008-10-29 00:36:36 +01:00
function print_date_range ( $date_start , $date_end , $format = '' , $outputlangs = '' )
2010-12-17 11:08:31 +01:00
{
2012-08-03 23:29:08 +02:00
print get_date_range ( $date_start , $date_end , $format , $outputlangs );
2010-12-17 11:08:31 +01:00
}
/**
* Format output for start and end date
2011-08-17 18:07:41 +02:00
*
2015-03-02 03:07:19 +01:00
* @ param int $date_start Start date
* @ param int $date_end End date
2015-02-14 18:39:45 +01:00
* @ param string $format Output format
* @ param Translate $outputlangs Output language
2015-03-17 00:21:17 +01:00
* @ param integer $withparenthesis 1 = Add parenthesis , 0 = non parenthesis
2015-02-14 18:39:45 +01:00
* @ return string String
2010-12-17 11:08:31 +01:00
*/
2015-02-14 18:39:45 +01:00
function get_date_range ( $date_start , $date_end , $format = '' , $outputlangs = '' , $withparenthesis = 1 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $langs ;
$out = '' ;
if ( ! is_object ( $outputlangs )) $outputlangs = $langs ;
if ( $date_start && $date_end )
{
2015-02-21 16:15:54 +01:00
$out .= ( $withparenthesis ? ' (' : '' ) . $outputlangs -> transnoentitiesnoconv ( 'DateFromTo' , dol_print_date ( $date_start , $format , false , $outputlangs ), dol_print_date ( $date_end , $format , false , $outputlangs )) . ( $withparenthesis ? ')' : '' );
2012-08-03 23:29:08 +02:00
}
if ( $date_start && ! $date_end )
{
2015-02-21 16:15:54 +01:00
$out .= ( $withparenthesis ? ' (' : '' ) . $outputlangs -> transnoentitiesnoconv ( 'DateFrom' , dol_print_date ( $date_start , $format , false , $outputlangs )) . ( $withparenthesis ? ')' : '' );
2012-08-03 23:29:08 +02:00
}
if ( ! $date_start && $date_end )
{
2015-02-21 16:15:54 +01:00
$out .= ( $withparenthesis ? ' (' : '' ) . $outputlangs -> transnoentitiesnoconv ( 'DateUntil' , dol_print_date ( $date_end , $format , false , $outputlangs )) . ( $withparenthesis ? ')' : '' );
2012-08-03 23:29:08 +02:00
}
return $out ;
2008-08-06 16:50:06 +02:00
}
2013-03-11 10:11:43 +01:00
/**
* Return firstname and lastname in correct order
*
* @ param string $firstname Firstname
* @ param string $lastname Lastname
2015-10-20 00:47:35 +02:00
* @ param int $nameorder - 1 = Auto , 0 = Lastname + Firstname , 1 = Firstname + Lastname , 2 = Firstname
2013-03-11 10:11:43 +01:00
* @ return string Firstname + lastname or Lastname + firstname
*/
2013-03-11 15:54:01 +01:00
function dolGetFirstLastname ( $firstname , $lastname , $nameorder =- 1 )
2013-03-11 10:11:43 +01:00
{
global $conf ;
2013-03-11 15:54:01 +01:00
2013-03-30 14:27:13 +01:00
$ret = '' ;
// If order not defined, we use the setup
if ( $nameorder < 0 ) $nameorder = ( empty ( $conf -> global -> MAIN_FIRSTNAME_NAME_POSITION ));
2015-09-22 16:21:46 +02:00
if ( $nameorder && (( string ) $nameorder != '2' ))
2013-03-30 14:27:13 +01:00
{
2017-10-13 13:28:26 +02:00
$ret .= $firstname ;
2013-03-30 14:27:13 +01:00
if ( $firstname && $lastname ) $ret .= ' ' ;
$ret .= $lastname ;
}
2015-09-21 17:28:11 +02:00
else if ( $nameorder == 2 )
{
2015-11-01 17:27:41 +01:00
$ret .= $firstname ;
2015-09-21 17:28:11 +02:00
}
2013-03-30 14:27:13 +01:00
else
{
$ret .= $lastname ;
if ( $firstname && $lastname ) $ret .= ' ' ;
$ret .= $firstname ;
}
2013-03-11 15:54:01 +01:00
return $ret ;
2013-03-11 10:11:43 +01:00
}
2012-07-28 22:07:27 +02:00
/**
2014-07-20 14:54:30 +02:00
* Set event message in dol_events session object . Will be output by calling dol_htmloutput_events .
* Note : Calling dol_htmloutput_events is done into pages by standard llxFooter () function .
2015-06-27 11:45:23 +02:00
* Note : Prefer to use setEventMessages instead .
2012-07-28 22:07:27 +02:00
*
2012-10-17 18:47:18 +02:00
* @ param mixed $mesgs Message string or array
2014-07-20 14:54:30 +02:00
* @ param string $style Which style to use ( 'mesgs' by default , 'warnings' , 'errors' )
2012-07-28 22:07:27 +02:00
* @ return void
2012-07-29 08:26:33 +02:00
* @ see dol_htmloutput_events
*/
2012-10-17 18:47:18 +02:00
function setEventMessage ( $mesgs , $style = 'mesgs' )
2012-07-29 08:26:33 +02:00
{
2015-06-27 11:45:23 +02:00
//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING); This is not deprecated, it is used by setEventMessages function
2012-10-17 18:47:18 +02:00
if ( ! is_array ( $mesgs )) // If mesgs is a string
{
2012-10-17 19:02:21 +02:00
if ( $mesgs ) $_SESSION [ 'dol_events' ][ $style ][] = $mesgs ;
2012-10-17 18:47:18 +02:00
}
else // If mesgs is an array
{
foreach ( $mesgs as $mesg )
{
2012-10-17 19:02:21 +02:00
if ( $mesg ) $_SESSION [ 'dol_events' ][ $style ][] = $mesg ;
2012-10-17 18:47:18 +02:00
}
}
2012-07-29 08:26:33 +02:00
}
2014-09-04 14:39:18 +02:00
/**
* Set event messages in dol_events session object . Will be output by calling dol_htmloutput_events .
* Note : Calling dol_htmloutput_events is done into pages by standard llxFooter () function .
*
* @ param string $mesg Message string
* @ param array $mesgs Message array
* @ param string $style Which style to use ( 'mesgs' by default , 'warnings' , 'errors' )
* @ return void
* @ see dol_htmloutput_events
*/
function setEventMessages ( $mesg , $mesgs , $style = 'mesgs' )
{
2016-03-18 11:30:15 +01:00
if ( ! in_array (( string ) $style , array ( 'mesgs' , 'warnings' , 'errors' ))) dol_print_error ( '' , 'Bad parameter style=' . $style . ' for setEventMessages' );
2014-09-04 14:39:18 +02:00
if ( empty ( $mesgs )) setEventMessage ( $mesg , $style );
2014-10-08 15:35:39 +02:00
else
{
if ( ! empty ( $mesg ) && ! in_array ( $mesg , $mesgs )) setEventMessage ( $mesg , $style ); // Add message string if not already into array
setEventMessage ( $mesgs , $style );
}
2012-07-29 08:26:33 +02:00
}
/**
* Print formated messages to output ( Used to show messages on html output ) .
2014-07-20 14:54:30 +02:00
* Note : Calling dol_htmloutput_events is done into pages by standard llxFooter () function , so there is
* no need to call it explicitely .
2012-07-28 22:07:27 +02:00
*
2017-10-28 13:36:23 +02:00
* @ param int $disabledoutputofmessages Clear all messages stored into session without diplaying them
2012-07-29 08:26:33 +02:00
* @ return void
2017-10-28 13:36:23 +02:00
* @ see dol_htmloutput_mesg
2012-07-28 22:07:27 +02:00
*/
2017-10-28 13:36:23 +02:00
function dol_htmloutput_events ( $disabledoutputofmessages = 0 )
2012-07-28 22:07:27 +02:00
{
2012-07-28 22:28:33 +02:00
// Show mesgs
2012-07-29 08:26:33 +02:00
if ( isset ( $_SESSION [ 'dol_events' ][ 'mesgs' ])) {
2017-10-28 13:36:23 +02:00
if ( empty ( $disabledoutputofmessages )) dol_htmloutput_mesg ( '' , $_SESSION [ 'dol_events' ][ 'mesgs' ]);
2012-07-29 08:26:33 +02:00
unset ( $_SESSION [ 'dol_events' ][ 'mesgs' ]);
2012-07-28 22:28:33 +02:00
}
// Show errors
2012-07-29 08:26:33 +02:00
if ( isset ( $_SESSION [ 'dol_events' ][ 'errors' ])) {
2017-10-28 13:36:23 +02:00
if ( empty ( $disabledoutputofmessages )) dol_htmloutput_mesg ( '' , $_SESSION [ 'dol_events' ][ 'errors' ], 'error' );
2012-07-29 08:26:33 +02:00
unset ( $_SESSION [ 'dol_events' ][ 'errors' ]);
2012-07-28 22:28:33 +02:00
}
// Show warnings
2012-07-29 08:26:33 +02:00
if ( isset ( $_SESSION [ 'dol_events' ][ 'warnings' ])) {
2017-10-28 13:36:23 +02:00
if ( empty ( $disabledoutputofmessages )) dol_htmloutput_mesg ( '' , $_SESSION [ 'dol_events' ][ 'warnings' ], 'warning' );
2012-07-29 08:26:33 +02:00
unset ( $_SESSION [ 'dol_events' ][ 'warnings' ]);
2012-07-28 22:07:27 +02:00
}
}
2008-08-06 16:50:06 +02:00
/**
2011-08-17 18:07:41 +02:00
* Get formated messages to output ( Used to show messages on html output ) .
2015-09-12 12:52:07 +02:00
* This include also the translation of the message key .
2011-08-17 18:07:41 +02:00
*
2015-09-12 12:52:07 +02:00
* @ param string $mesgstring Message string or message key
* @ param string [] $mesgarray Array of message strings or message keys
2011-10-03 18:10:50 +02:00
* @ param string $style Style of message output ( 'ok' or 'error' )
* @ param int $keepembedded Set to 1 in error message must be kept embedded into its html place ( this disable jnotify )
* @ return string Return html output
*
2011-12-28 01:19:52 +01:00
* @ see dol_print_error
* @ see dol_htmloutput_errors
2015-09-12 12:52:07 +02:00
* @ see setEventMessages
2008-08-06 16:50:06 +02:00
*/
2011-05-14 13:34:15 +02:00
function get_htmloutput_mesg ( $mesgstring = '' , $mesgarray = '' , $style = 'ok' , $keepembedded = 0 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
global $conf , $langs ;
2017-04-15 03:05:04 +02:00
$ret = 0 ; $return = '' ;
2012-08-03 23:29:08 +02:00
$out = '' ;
$divstart = $divend = '' ;
// If inline message with no format, we add it.
if (( empty ( $conf -> use_javascript_ajax ) || ! empty ( $conf -> global -> MAIN_DISABLE_JQUERY_JNOTIFY ) || $keepembedded ) && ! preg_match ( '/<div class=".*">/i' , $out ))
{
2017-11-14 17:51:04 +01:00
$divstart = '<div class="' . $style . ' clearboth">' ;
2012-08-03 23:29:08 +02:00
$divend = '</div>' ;
}
if (( is_array ( $mesgarray ) && count ( $mesgarray )) || $mesgstring )
{
$langs -> load ( " errors " );
$out .= $divstart ;
if ( is_array ( $mesgarray ) && count ( $mesgarray ))
{
foreach ( $mesgarray as $message )
{
$ret ++ ;
$out .= $langs -> trans ( $message );
if ( $ret < count ( $mesgarray )) $out .= " <br> \n " ;
}
}
if ( $mesgstring )
{
$langs -> load ( " errors " );
$ret ++ ;
$out .= $langs -> trans ( $mesgstring );
}
$out .= $divend ;
}
if ( $out )
{
2012-09-03 22:05:13 +02:00
if ( ! empty ( $conf -> use_javascript_ajax ) && empty ( $conf -> global -> MAIN_DISABLE_JQUERY_JNOTIFY ) && empty ( $keepembedded ))
2012-08-03 23:29:08 +02:00
{
$return = ' < script type = " text/javascript " >
2012-09-03 22:05:13 +02:00
$ ( document ) . ready ( function () {
var block = '.(! empty($conf->global->MAIN_USE_JQUERY_BLOCKUI)?"true":"false").'
if ( block ) {
2012-09-04 09:38:38 +02:00
$ . dolEventValid ( " " , " '.dol_escape_js( $out ).' " );
2012-09-03 22:05:13 +02:00
} else {
2016-06-17 15:51:09 +02:00
/* jnotify(message, preset of message type, keepmessage) */
2012-09-03 22:05:13 +02:00
$ . jnotify ( " '.dol_escape_js( $out ).' " ,
" '.( $style == " ok " ? 3000 : $style ).' " ,
'.($style=="ok" ? "false" : "true").' ,
{ remove : function (){} } );
}
2012-08-03 23:29:08 +02:00
});
</ script > ' ;
}
else
{
$return = $out ;
}
}
return $return ;
2011-05-14 13:34:15 +02:00
}
/**
2011-08-17 18:07:41 +02:00
* Get formated error messages to output ( Used to show messages on html output ) .
*
2011-10-03 18:10:50 +02:00
* @ param string $mesgstring Error message
* @ param array $mesgarray Error messages array
* @ param int $keepembedded Set to 1 in error message must be kept embedded into its html place ( this disable jnotify )
* @ return string Return html output
*
2011-12-28 01:19:52 +01:00
* @ see dol_print_error
* @ see dol_htmloutput_mesg
2011-05-14 13:34:15 +02:00
*/
function get_htmloutput_errors ( $mesgstring = '' , $mesgarray = '' , $keepembedded = 0 )
{
2012-08-03 23:29:08 +02:00
return get_htmloutput_mesg ( $mesgstring , $mesgarray , 'error' , $keepembedded );
2011-05-14 13:34:15 +02:00
}
/**
2011-08-17 18:07:41 +02:00
* Print formated messages to output ( Used to show messages on html output ) .
*
2015-09-12 12:52:07 +02:00
* @ param string $mesgstring Message string or message key
* @ param string [] $mesgarray Array of message strings or message keys
* @ param string $style Which style to use ( 'ok' , 'warning' , 'error' )
* @ param int $keepembedded Set to 1 if message must be kept embedded into its html place ( this disable jnotify )
2011-10-03 18:10:50 +02:00
* @ return void
*
2011-12-28 01:19:52 +01:00
* @ see dol_print_error
* @ see dol_htmloutput_errors
2015-09-12 12:52:07 +02:00
* @ see setEventMessages
2011-05-14 13:34:15 +02:00
*/
function dol_htmloutput_mesg ( $mesgstring = '' , $mesgarray = '' , $style = 'ok' , $keepembedded = 0 )
{
2012-08-03 23:29:08 +02:00
if ( empty ( $mesgstring ) && ( ! is_array ( $mesgarray ) || count ( $mesgarray ) == 0 )) return ;
$iserror = 0 ;
$iswarning = 0 ;
if ( is_array ( $mesgarray ))
{
foreach ( $mesgarray as $val )
{
if ( $val && preg_match ( '/class="error"/i' , $val )) { $iserror ++ ; break ; }
if ( $val && preg_match ( '/class="warning"/i' , $val )) { $iswarning ++ ; break ; }
}
}
else if ( $mesgstring && preg_match ( '/class="error"/i' , $mesgstring )) $iserror ++ ;
else if ( $mesgstring && preg_match ( '/class="warning"/i' , $mesgstring )) $iswarning ++ ;
if ( $style == 'error' ) $iserror ++ ;
if ( $style == 'warning' ) $iswarning ++ ;
if ( $iserror || $iswarning )
{
// Remove div from texts
$mesgstring = preg_replace ( '/<\/div><div class="(error|warning)">/' , '<br>' , $mesgstring );
$mesgstring = preg_replace ( '/<div class="(error|warning)">/' , '' , $mesgstring );
$mesgstring = preg_replace ( '/<\/div>/' , '' , $mesgstring );
// Remove div from texts array
if ( is_array ( $mesgarray ))
{
$newmesgarray = array ();
foreach ( $mesgarray as $val )
{
$tmpmesgstring = preg_replace ( '/<\/div><div class="(error|warning)">/' , '<br>' , $val );
$tmpmesgstring = preg_replace ( '/<div class="(error|warning)">/' , '' , $tmpmesgstring );
$tmpmesgstring = preg_replace ( '/<\/div>/' , '' , $tmpmesgstring );
$newmesgarray [] = $tmpmesgstring ;
}
$mesgarray = $newmesgarray ;
}
print get_htmloutput_mesg ( $mesgstring , $mesgarray ,( $iserror ? 'error' : 'warning' ), $keepembedded );
}
else print get_htmloutput_mesg ( $mesgstring , $mesgarray , 'ok' , $keepembedded );
2008-08-06 16:50:06 +02:00
}
2011-01-30 18:15:51 +01:00
/**
2011-08-17 18:07:41 +02:00
* Print formated error messages to output ( Used to show messages on html output ) .
*
2011-10-03 18:10:50 +02:00
* @ param string $mesgstring Error message
* @ param array $mesgarray Error messages array
* @ param int $keepembedded Set to 1 in error message must be kept embedded into its html place ( this disable jnotify )
* @ return void
*
2011-12-28 01:19:52 +01:00
* @ see dol_print_error
* @ see dol_htmloutput_mesg
2011-01-30 18:15:51 +01:00
*/
2011-05-04 21:06:33 +02:00
function dol_htmloutput_errors ( $mesgstring = '' , $mesgarray = '' , $keepembedded = 0 )
2011-01-30 18:15:51 +01:00
{
2012-08-03 23:29:08 +02:00
dol_htmloutput_mesg ( $mesgstring , $mesgarray , 'error' , $keepembedded );
2011-01-30 18:15:51 +01:00
}
2008-08-06 16:50:06 +02:00
/**
2011-08-29 23:26:42 +02:00
* Advanced sort array by second index function , which produces ascending ( default )
* or descending output and uses optionally natural case insensitive sorting ( which
* can be optionally case sensitive as well ) .
2011-08-17 18:07:41 +02:00
*
2014-09-27 16:00:11 +02:00
* @ param array $array Array to sort ( array of array ( 'key' , 'otherkey1' , 'otherkey2' ... ))
2011-08-29 23:26:42 +02:00
* @ param string $index Key in array to use for sorting criteria
2015-06-21 17:05:49 +02:00
* @ param int $order Sort order ( 'asc' or 'desc' )
2014-05-04 23:46:36 +02:00
* @ param int $natsort 1 = use " natural " sort ( natsort ), 0 = use " standard " sort ( asort )
2011-08-29 23:26:42 +02:00
* @ param int $case_sensitive 1 = sort is case sensitive , 0 = not case sensitive
2015-06-21 17:05:49 +02:00
* @ param int $keepindex If 0 and index key of array to sort is a numeric , than index will be rewrote . If 1 or index key is not numeric , key for index is kept after sorting .
2011-08-29 23:26:42 +02:00
* @ return array Sorted array
*/
2015-06-21 17:05:49 +02:00
function dol_sort_array ( & $array , $index , $order = 'asc' , $natsort = 0 , $case_sensitive = 0 , $keepindex = 0 )
2008-08-06 16:50:06 +02:00
{
2012-08-03 23:29:08 +02:00
// Clean parameters
$order = strtolower ( $order );
$sizearray = count ( $array );
if ( is_array ( $array ) && $sizearray > 0 )
{
2017-10-13 13:28:26 +02:00
$temp = array ();
foreach ( array_keys ( $array ) as $key ) $temp [ $key ] = $array [ $key ][ $index ];
2015-06-21 17:05:49 +02:00
2012-08-03 23:29:08 +02:00
if ( ! $natsort ) ( $order == 'asc' ) ? asort ( $temp ) : arsort ( $temp );
else
{
( $case_sensitive ) ? natsort ( $temp ) : natcasesort ( $temp );
if ( $order != 'asc' ) $temp = array_reverse ( $temp , TRUE );
}
2015-06-21 17:05:49 +02:00
$sorted = array ();
foreach ( array_keys ( $temp ) as $key )
{
( is_numeric ( $key ) && empty ( $keepindex )) ? $sorted [] = $array [ $key ] : $sorted [ $key ] = $array [ $key ];
}
2012-08-03 23:29:08 +02:00
return $sorted ;
}
return $array ;
2008-08-06 16:50:06 +02:00
}
2008-10-09 19:29:32 +02:00
/**
2010-09-29 10:05:22 +02:00
* Check if a string is in UTF8
2011-08-17 18:07:41 +02:00
*
2011-10-03 18:10:50 +02:00
* @ param string $str String to check
* @ return boolean True if string is UTF8 or ISO compatible with UTF8 , False if not ( ISO with special char or Binary )
2008-10-09 19:29:32 +02:00
*/
2010-09-29 10:05:22 +02:00
function utf8_check ( $str )
2008-10-09 19:29:32 +02:00
{
2012-08-03 23:29:08 +02:00
// We must use here a binary strlen function (so not dol_strlen)
$strLength = dol_strlen ( $str );
for ( $i = 0 ; $i < $strLength ; $i ++ )
{
if ( ord ( $str [ $i ]) < 0x80 ) continue ; // 0bbbbbbb
elseif (( ord ( $str [ $i ]) & 0xE0 ) == 0xC0 ) $n = 1 ; // 110bbbbb
elseif (( ord ( $str [ $i ]) & 0xF0 ) == 0xE0 ) $n = 2 ; // 1110bbbb
elseif (( ord ( $str [ $i ]) & 0xF8 ) == 0xF0 ) $n = 3 ; // 11110bbb
elseif (( ord ( $str [ $i ]) & 0xFC ) == 0xF8 ) $n = 4 ; // 111110bb
elseif (( ord ( $str [ $i ]) & 0xFE ) == 0xFC ) $n = 5 ; // 1111110b
else return false ; // Does not match any model
for ( $j = 0 ; $j < $n ; $j ++ ) { // n bytes matching 10bbbbbb follow ?
if (( ++ $i == strlen ( $str )) || (( ord ( $str [ $i ]) & 0xC0 ) != 0x80 ))
return false ;
}
}
return true ;
2008-10-09 19:29:32 +02:00
}
2009-10-20 17:23:32 +02:00
2009-12-14 23:17:50 +01:00
/**
2015-03-14 14:55:41 +01:00
* Return a string encoded into OS filesystem encoding . This function is used to define
2011-03-09 16:48:25 +01:00
* value to pass to filesystem PHP functions .
2011-08-17 18:07:41 +02:00
*
2011-10-03 18:10:50 +02:00
* @ param string $str String to encode ( UTF - 8 )
* @ return string Encoded string ( UTF - 8 , ISO - 8859 - 1 )
2009-12-14 23:17:50 +01:00
*/
function dol_osencode ( $str )
{
2012-08-03 23:29:08 +02:00
global $conf ;
2011-09-20 13:43:14 +02:00
2012-08-03 23:29:08 +02:00
$tmp = ini_get ( " unicode.filesystem_encoding " ); // Disponible avec PHP 6.0
if ( empty ( $tmp ) && ! empty ( $_SERVER [ " WINDIR " ])) $tmp = 'iso-8859-1' ; // By default for windows
if ( empty ( $tmp )) $tmp = 'utf-8' ; // By default for other
if ( ! empty ( $conf -> global -> MAIN_FILESYSTEM_ENCODING )) $tmp = $conf -> global -> MAIN_FILESYSTEM_ENCODING ;
2009-12-14 23:17:50 +01:00
2012-08-03 23:29:08 +02:00
if ( $tmp == 'iso-8859-1' ) return utf8_decode ( $str );
return $str ;
2009-12-14 23:17:50 +01:00
}
2009-10-20 17:23:32 +02:00
/**
2015-07-04 18:20:17 +02:00
* Return an id or code from a code or id .
* Store also Code - Id into a cache to speed up next request on same key .
2011-08-17 18:07:41 +02:00
*
2017-10-02 11:59:17 +02:00
* @ param DoliDB $db Database handler
2017-12-15 15:15:14 +01:00
* @ param string $key Code or Id to get Id or Code
2017-10-02 11:59:17 +02:00
* @ param string $tablename Table name without prefix
2017-12-15 15:15:14 +01:00
* @ param string $fieldkey Field to search the key into
* @ param string $fieldid Field to get
2017-10-02 11:59:17 +02:00
* @ param int $entityfilter Filter by entity
* @ return int < 0 if KO , Id of code if OK
2015-06-30 01:34:17 +02:00
* @ see $langs -> getLabelFromKey
2009-10-20 17:23:32 +02:00
*/
2017-12-15 15:15:14 +01:00
function dol_getIdFromCode ( $db , $key , $tablename , $fieldkey = 'code' , $fieldid = 'id' , $entityfilter = 0 )
2009-10-20 17:23:32 +02:00
{
2012-08-03 23:29:08 +02:00
global $cache_codes ;
// If key empty
if ( $key == '' ) return '' ;
// Check in cache
if ( isset ( $cache_codes [ $tablename ][ $key ])) // Can be defined to 0 or ''
{
return $cache_codes [ $tablename ][ $key ]; // Found in cache
}
2015-06-30 01:34:17 +02:00
$sql = " SELECT " . $fieldid . " as valuetoget " ;
2012-08-03 23:29:08 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . $tablename ;
2016-12-17 19:21:48 +01:00
$sql .= " WHERE " . $fieldkey . " = ' " . $db -> escape ( $key ) . " ' " ;
2017-10-02 11:59:17 +02:00
if ( ! empty ( $entityfilter ))
$sql .= " AND entity IN ( " . getEntity ( $tablename ) . " ) " ;
2018-01-11 00:16:45 +01:00
2014-06-13 01:34:39 +02:00
dol_syslog ( 'dol_getIdFromCode' , LOG_DEBUG );
2012-08-03 23:29:08 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
2015-06-30 01:34:17 +02:00
if ( $obj ) $cache_codes [ $tablename ][ $key ] = $obj -> valuetoget ;
2012-08-03 23:29:08 +02:00
else $cache_codes [ $tablename ][ $key ] = '' ;
$db -> free ( $resql );
return $cache_codes [ $tablename ][ $key ];
}
else
{
return - 1 ;
}
2009-10-20 17:23:32 +02:00
}
2010-03-25 12:16:42 +01:00
/**
* Verify if condition in string is ok or not
2011-08-17 18:07:41 +02:00
*
2011-10-03 18:10:50 +02:00
* @ param string $strRights String with condition to check
2012-02-12 16:41:43 +01:00
* @ return boolean True or False . Return true if strRights is ''
2010-03-25 12:16:42 +01:00
*/
function verifCond ( $strRights )
{
2012-08-03 23:29:08 +02:00
global $user , $conf , $langs ;
global $leftmenu ;
global $rights ; // To export to dol_eval function
//print $strRights."<br>\n";
$rights = true ;
if ( $strRights != '' )
{
//$tab_rights = explode('&&', $strRights);
//$i = 0;
//while (($i < count($tab_rights)) && ($rights == true)) {
$str = 'if(!(' . $strRights . ')) { $rights = false; }' ;
dol_eval ( $str );
// $i++;
//}
}
return $rights ;
2010-03-25 12:16:42 +01:00
}
/**
2011-02-16 23:46:01 +01:00
* Replace eval function to add more security .
2012-11-04 21:19:12 +01:00
* This function is called by verifCond () or trans () and transnoentitiesnoconv () .
2011-09-02 23:56:37 +02:00
*
2012-11-04 21:19:12 +01:00
* @ param string $s String to evaluate
2013-04-26 19:13:39 +02:00
* @ param int $returnvalue 0 = No return ( used to execute eval ( $a = something )) . 1 = Value of eval is returned ( used to eval ( $something )) .
2017-05-24 22:48:44 +02:00
* @ param int $hideerrors 1 = Hide errors
2012-11-04 21:19:12 +01:00
* @ return mixed Nothing or return of eval
2010-03-25 12:16:42 +01:00
*/
2017-05-24 22:48:44 +02:00
function dol_eval ( $s , $returnvalue = 0 , $hideerrors = 1 )
2010-03-25 12:16:42 +01:00
{
2012-08-03 23:29:08 +02:00
// Only global variables can be changed by eval function and returned to caller
2017-05-24 22:48:44 +02:00
global $db , $langs , $user , $conf ;
global $mainmenu , $leftmenu ;
2012-08-03 23:29:08 +02:00
global $rights ;
2014-08-14 15:33:41 +02:00
global $object ;
2017-05-24 22:48:44 +02:00
global $mysoc ;
2017-05-25 08:48:59 +02:00
global $obj ; // To get $obj used into list when dol_eval is used for computed fields and $obj is not yet $object
2017-05-24 22:48:44 +02:00
global $soc ; // For backward compatibility
2010-03-25 12:16:42 +01:00
2012-08-03 23:29:08 +02:00
//print $s."<br>\n";
2017-05-24 22:48:44 +02:00
if ( $returnvalue )
{
2017-10-13 13:28:26 +02:00
if ( $hideerrors ) return @ eval ( 'return ' . $s . ';' );
else return eval ( 'return ' . $s . ';' );
2017-05-24 22:48:44 +02:00
}
else
{
2017-10-13 13:28:26 +02:00
if ( $hideerrors ) @ eval ( $s );
else eval ( $s );
2017-05-24 22:48:44 +02:00
}
2010-03-25 12:16:42 +01:00
}
2011-10-27 10:41:29 +02:00
/**
2013-04-26 19:13:39 +02:00
* Return if var element is ok
*
* @ param string $element Variable to check
* @ return boolean Return true of variable is not empty
*/
2011-10-27 10:41:29 +02:00
function dol_validElement ( $element )
{
return ( trim ( $element ) != '' );
}
2010-08-29 19:43:51 +02:00
2010-06-26 16:35:26 +02:00
/**
2010-08-29 19:43:51 +02:00
* Return img flag of country for a language code or country code
2011-08-17 18:07:41 +02:00
*
2011-10-03 18:10:50 +02:00
* @ param string $codelang Language code ( en_IN , fr_CA ... ) or Country code ( IN , FR )
2017-10-06 20:53:41 +02:00
* @ param string $moreatt Add more attribute on img tag ( For example 'style="float: right"' )
2011-10-03 18:10:50 +02:00
* @ return string HTML img string with flag .
2010-06-26 16:35:26 +02:00
*/
2017-10-06 20:53:41 +02:00
function picto_from_langcode ( $codelang , $moreatt = '' )
2010-06-26 16:35:26 +02:00
{
2012-08-03 23:29:08 +02:00
global $langs ;
2014-10-25 00:42:52 +02:00
if ( empty ( $codelang )) return '' ;
2015-02-20 22:51:47 +01:00
if ( empty ( $codelang )) return '' ;
2012-08-03 23:29:08 +02:00
if ( $codelang == 'auto' )
{
2017-10-06 20:53:41 +02:00
return img_picto_common ( $langs -> trans ( 'AutoDetectLang' ), 'flags/int.png' , $moreatt );
2012-08-03 23:29:08 +02:00
}
$langtocountryflag = array (
'ar_AR' => '' ,
'ca_ES' => 'catalonia' ,
'da_DA' => 'dk' ,
'fr_CA' => 'mq' ,
'sv_SV' => 'se'
);
if ( isset ( $langtocountryflag [ $codelang ])) $flagImage = $langtocountryflag [ $codelang ];
else
{
$tmparray = explode ( '_' , $codelang );
$flagImage = empty ( $tmparray [ 1 ]) ? $tmparray [ 0 ] : $tmparray [ 1 ];
}
2017-10-06 20:53:41 +02:00
return img_picto_common ( $codelang , 'flags/' . strtolower ( $flagImage ) . '.png' , $moreatt );
2010-06-26 16:35:26 +02:00
}
2011-01-25 00:35:21 +01:00
/**
2016-11-16 09:40:29 +01:00
* Complete or removed entries into a head array ( used to build tabs ) .
2016-11-12 14:36:52 +01:00
* For example , with value added by external modules . Such values are declared into $conf -> modules_parts [ 'tab' ] .
* Or by change using hook completeTabsHead
2011-08-17 18:07:41 +02:00
*
2014-12-04 13:20:56 +01:00
* @ param Conf $conf Object conf
* @ param Translate $langs Object langs
2015-02-10 10:45:48 +01:00
* @ param object | null $object Object object
2014-12-04 13:20:56 +01:00
* @ param array $head Object head
* @ param int $h New position to fill
* @ param string $type Value for object where objectvalue can be
* 'thirdparty' to add a tab in third party view
* 'intervention' to add a tab in intervention view
* 'supplier_order' to add a tab in supplier order view
* 'supplier_invoice' to add a tab in supplier invoice view
* 'invoice' to add a tab in customer invoice view
* 'order' to add a tab in customer order view
2017-08-27 19:40:43 +02:00
* 'contract' to add a tabl in contract view
2014-12-04 13:20:56 +01:00
* 'product' to add a tab in product view
* 'propal' to add a tab in propal view
* 'user' to add a tab in user view
* 'group' to add a tab in group view
* 'member' to add a tab in fundation member view
* 'categories_x' to add a tab in category view ( 'x' : type of category ( 0 = product , 1 = supplier , 2 = customer , 3 = member )
* 'ecm' to add a tab for another ecm view
2015-03-04 01:54:26 +01:00
* 'stock' to add a tab for warehouse view
2014-12-04 13:20:56 +01:00
* @ param string $mode 'add' to complete head , 'remove' to remove entries
2011-11-02 14:14:46 +01:00
* @ return void
2011-01-25 00:35:21 +01:00
*/
2011-01-25 00:59:37 +01:00
function complete_head_from_modules ( $conf , $langs , $object , & $head , & $h , $type , $mode = 'add' )
2011-01-25 00:35:21 +01:00
{
2016-11-12 14:36:52 +01:00
global $hookmanager ;
2016-11-16 09:40:29 +01:00
2013-01-07 13:28:14 +01:00
if ( isset ( $conf -> modules_parts [ 'tabs' ][ $type ]) && is_array ( $conf -> modules_parts [ 'tabs' ][ $type ]))
2011-12-20 11:47:35 +01:00
{
2013-01-07 13:28:14 +01:00
foreach ( $conf -> modules_parts [ 'tabs' ][ $type ] as $value )
2011-12-20 11:47:35 +01:00
{
$values = explode ( ':' , $value );
2011-12-21 18:31:39 +01:00
2011-12-20 11:47:35 +01:00
if ( $mode == 'add' && ! preg_match ( '/^\-/' , $values [ 1 ]))
{
2011-12-21 18:31:39 +01:00
if ( count ( $values ) == 6 ) // new declaration with permissions: $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__'
2011-12-20 11:47:35 +01:00
{
if ( $values [ 0 ] != $type ) continue ;
2011-12-21 18:31:39 +01:00
2011-12-20 11:47:35 +01:00
if ( verifCond ( $values [ 4 ]))
{
if ( $values [ 3 ]) $langs -> load ( $values [ 3 ]);
2014-01-12 14:11:03 +01:00
if ( preg_match ( '/SUBSTITUTION_([^_]+)/i' , $values [ 2 ], $reg ))
{
$substitutionarray = array ();
2016-07-13 23:06:41 +02:00
complete_substitutions_array ( $substitutionarray , $langs , $object , array ( 'needforkey' => $values [ 2 ]));
2014-01-12 14:11:03 +01:00
$label = make_substitutions ( $reg [ 1 ], $substitutionarray );
}
else $label = $langs -> trans ( $values [ 2 ]);
2013-03-08 15:52:23 +01:00
$head [ $h ][ 0 ] = dol_buildpath ( preg_replace ( '/__ID__/i' , (( is_object ( $object ) && ! empty ( $object -> id )) ? $object -> id : '' ), $values [ 5 ]), 1 );
2014-01-12 14:11:03 +01:00
$head [ $h ][ 1 ] = $label ;
2011-12-20 11:47:35 +01:00
$head [ $h ][ 2 ] = str_replace ( '+' , '' , $values [ 1 ]);
$h ++ ;
}
}
2014-01-12 14:11:03 +01:00
else if ( count ( $values ) == 5 ) // deprecated
2011-12-20 11:47:35 +01:00
{
2015-09-24 18:47:01 +02:00
dol_syslog ( 'Passing 5 values in tabs module_parts is deprecated. Please update to 6 with permissions.' , LOG_WARNING );
2011-12-20 11:47:35 +01:00
if ( $values [ 0 ] != $type ) continue ;
if ( $values [ 3 ]) $langs -> load ( $values [ 3 ]);
2014-01-12 14:11:03 +01:00
if ( preg_match ( '/SUBSTITUTION_([^_]+)/i' , $values [ 2 ], $reg ))
{
$substitutionarray = array ();
2016-07-13 23:06:41 +02:00
complete_substitutions_array ( $substitutionarray , $langs , $object , array ( 'needforkey' => $values [ 2 ]));
2014-01-12 14:11:03 +01:00
$label = make_substitutions ( $reg [ 1 ], $substitutionarray );
}
else $label = $langs -> trans ( $values [ 2 ]);
2013-03-08 15:52:23 +01:00
$head [ $h ][ 0 ] = dol_buildpath ( preg_replace ( '/__ID__/i' , (( is_object ( $object ) && ! empty ( $object -> id )) ? $object -> id : '' ), $values [ 4 ]), 1 );
2014-01-12 14:11:03 +01:00
$head [ $h ][ 1 ] = $label ;
2011-12-20 11:47:35 +01:00
$head [ $h ][ 2 ] = str_replace ( '+' , '' , $values [ 1 ]);
$h ++ ;
}
}
2011-12-21 18:31:39 +01:00
else if ( $mode == 'remove' && preg_match ( '/^\-/' , $values [ 1 ]))
2011-12-20 11:47:35 +01:00
{
if ( $values [ 0 ] != $type ) continue ;
$tabname = str_replace ( '-' , '' , $values [ 1 ]);
foreach ( $head as $key => $val )
{
$condition = ( ! empty ( $values [ 3 ]) ? verifCond ( $values [ 3 ]) : 1 );
if ( $head [ $key ][ 2 ] == $tabname && $condition )
{
unset ( $head [ $key ]);
break ;
}
}
}
}
}
2016-11-16 09:40:29 +01:00
2016-11-12 14:36:52 +01:00
// No need to make a return $head. Var is modified as a reference
2016-11-13 18:28:06 +01:00
if ( ! empty ( $hookmanager ))
2016-11-12 14:36:52 +01:00
{
$parameters = array ( 'object' => $object , 'mode' => $mode , 'head' => $head );
$reshook = $hookmanager -> executeHooks ( 'completeTabsHead' , $parameters );
if ( $reshook > 0 )
{
$head = $hookmanager -> resArray ;
}
}
2011-01-25 00:35:21 +01:00
}
2011-10-18 16:40:44 +02:00
/**
* Print common footer :
* conf -> global -> MAIN_HTML_FOOTER
2017-11-09 01:21:02 +01:00
* js for switch of menu hider
* js for conf -> global -> MAIN_GOOGLE_AN_ID
* js for conf -> global -> MAIN_SHOW_TUNING_INFO or $_SERVER [ " MAIN_SHOW_TUNING_INFO " ]
* js for conf -> logbuffer
2011-10-18 16:40:44 +02:00
*
* @ param string $zone 'private' ( for private pages ) or 'public' ( for public pages )
* @ return void
*/
function printCommonFooter ( $zone = 'private' )
{
2015-08-05 15:19:00 +02:00
global $conf , $hookmanager ;
2011-12-05 17:13:48 +01:00
global $micro_start_time ;
2011-12-07 18:10:24 +01:00
2012-08-03 23:29:08 +02:00
if ( $zone == 'private' ) print " \n " . '<!-- Common footer for private page -->' . " \n " ;
else print " \n " . '<!-- Common footer for public page -->' . " \n " ;
2017-11-09 01:00:43 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printCommonFooter' , $parameters ); // Note that $action and $object may have been modified by some hooks
if ( empty ( $reshook ))
2013-12-31 10:48:15 +01:00
{
2017-11-09 01:00:43 +01:00
if ( ! empty ( $conf -> global -> MAIN_HTML_FOOTER )) print $conf -> global -> MAIN_HTML_FOOTER . " \n " ;
2017-11-10 20:20:59 +01:00
2017-10-28 16:00:46 +02:00
print " \n " ;
2017-11-09 01:00:43 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ))
2012-08-03 23:29:08 +02:00
{
2017-11-09 01:00:43 +01:00
print '<script type="text/javascript" language="javascript">' . " \n " ;
2017-05-25 08:48:59 +02:00
2017-11-09 01:21:02 +01:00
if ( $zone == 'private' && empty ( $conf -> dol_use_jmobile ))
2017-11-09 01:00:43 +01:00
{
print " \n " ;
2017-11-09 09:50:55 +01:00
print '/* JS CODE TO ENABLE to enable handler to switch left menu page (menuhider) */' . " \n " ;
2017-11-09 01:00:43 +01:00
print 'jQuery(".menuhider").click(function() {' ;
print ' console.log("We click on .menuhider");' . " \n " ;
//print " $('.side-nav').animate({width:'toggle'},200);\n"; // OK with eldy theme but not with md
print " $ ('.side-nav').toggle() \n " ;
print " $ ('.login_block').toggle() \n " ;
print '});' . " \n " ;
}
2017-11-10 20:20:59 +01:00
2017-11-09 01:00:43 +01:00
// Google Analytics (need Google module)
if ( ! empty ( $conf -> google -> enabled ) && ! empty ( $conf -> global -> MAIN_GOOGLE_AN_ID ))
{
if (( $conf -> dol_use_jmobile != 4 ))
{
print " \n " ;
2017-11-09 09:50:55 +01:00
print " /* JS CODE TO ENABLE for google analtics tag */ \n " ;
2017-11-09 01:00:43 +01:00
print ' var _gaq = _gaq || [];' . " \n " ;
print ' _gaq.push([\'_setAccount\', \'' . $conf -> global -> MAIN_GOOGLE_AN_ID . '\']);' . " \n " ;
print ' _gaq.push([\'_trackPageview\']);' . " \n " ;
print '' . " \n " ;
print ' (function() {' . " \n " ;
print ' var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;' . " \n " ;
print ' ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';' . " \n " ;
print ' var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);' . " \n " ;
print ' })();' . " \n " ;
}
}
2017-11-10 20:20:59 +01:00
2017-11-09 01:00:43 +01:00
// End of tuning
if ( ! empty ( $_SERVER [ 'MAIN_SHOW_TUNING_INFO' ]) || ! empty ( $conf -> global -> MAIN_SHOW_TUNING_INFO ))
{
print " \n " ;
2017-11-09 09:50:55 +01:00
print " /* JS CODE TO ENABLE to add memory info */ \n " ;
2017-11-09 01:00:43 +01:00
print 'window.console && console.log("' ;
if ( ! empty ( $conf -> global -> MEMCACHED_SERVER )) print 'MEMCACHED_SERVER=' . $conf -> global -> MEMCACHED_SERVER . ' - ' ;
print 'MAIN_OPTIMIZE_SPEED=' . ( isset ( $conf -> global -> MAIN_OPTIMIZE_SPEED ) ? $conf -> global -> MAIN_OPTIMIZE_SPEED : 'off' );
if ( ! empty ( $micro_start_time )) // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
{
$micro_end_time = microtime ( true );
print ' - Build time: ' . ceil ( 1000 * ( $micro_end_time - $micro_start_time )) . ' ms' ;
}
if ( function_exists ( " memory_get_usage " ))
{
print ' - Mem: ' . memory_get_usage ();
}
if ( function_exists ( " xdebug_memory_usage " ))
{
print ' - XDebug time: ' . ceil ( 1000 * xdebug_time_index ()) . ' ms' ;
print ' - XDebug mem: ' . xdebug_memory_usage ();
print ' - XDebug mem peak: ' . xdebug_peak_memory_usage ();
}
if ( function_exists ( " zend_loader_file_encoded " ))
{
print ' - Zend encoded file: ' . ( zend_loader_file_encoded () ? 'yes' : 'no' );
}
print '");' . " \n " ;
}
2017-11-10 20:20:59 +01:00
2017-11-09 01:00:43 +01:00
print " \n " . '</script>' . " \n " ;
2012-08-03 23:29:08 +02:00
}
// Add Xdebug coverage of code
2015-03-31 16:59:40 +02:00
if ( defined ( 'XDEBUGCOVERAGE' ))
{
print_r ( xdebug_get_code_coverage ());
2012-08-03 23:29:08 +02:00
}
2017-11-10 20:20:59 +01:00
2017-11-09 01:00:43 +01:00
// If there is some logs in buffer to show
if ( count ( $conf -> logbuffer ))
2012-08-03 23:29:08 +02:00
{
2017-11-09 01:00:43 +01:00
print " \n " ;
print " <!-- Start of log output \n " ;
//print '<div class="hidden">'."\n";
foreach ( $conf -> logbuffer as $logline )
{
print $logline . " <br> \n " ;
}
//print '</div>'."\n";
print " End of log output --> \n " ;
2012-08-03 23:29:08 +02:00
}
}
2011-10-18 16:40:44 +02:00
}
2014-04-06 14:22:08 +02:00
/**
* Split a string with 2 keys into key array .
* For example : " A=1;B=2;C=2 " is exploded into array ( 'A' => 1 , 'B' => 2 , 'C' => 3 )
2014-04-06 21:18:21 +02:00
*
2014-04-06 14:22:08 +02:00
* @ param string $string String to explode
* @ param string $delimiter Delimiter between each couple of data
* @ param string $kv Delimiter between key and value
* @ return array Array of data exploded
*/
function dolExplodeIntoArray ( $string , $delimiter = ';' , $kv = '=' )
{
2014-04-06 21:18:21 +02:00
if ( $a = explode ( $delimiter , $string ))
2014-04-06 14:22:08 +02:00
{
2017-10-13 13:28:26 +02:00
$ka = array ();
2014-04-06 14:22:08 +02:00
foreach ( $a as $s ) { // each part
if ( $s ) {
if ( $pos = strpos ( $s , $kv )) { // key/value delimiter
$ka [ trim ( substr ( $s , 0 , $pos ))] = trim ( substr ( $s , $pos + strlen ( $kv )));
} else { // key delimiter not found
$ka [] = trim ( $s );
}
}
}
return $ka ;
}
return array ();
}
2013-03-30 14:27:13 +01:00
/**
2017-10-06 10:46:45 +02:00
* Set focus onto field with selector ( similar behaviour of 'autofocus' HTML5 tag )
2013-03-30 14:27:13 +01:00
*
2017-06-21 11:37:34 +02:00
* @ param string $selector Selector ( '#id' or 'input[name="ref"]' ) to use to find the HTML input field that must get the autofocus . You must use a CSS selector , so unique id preceding with the '#' char .
2013-03-30 14:27:13 +01:00
* @ return string HTML code to set focus
*/
function dol_set_focus ( $selector )
{
2017-06-16 16:06:20 +02:00
print " \n " . '<!-- Set focus onto a specific field -->' . " \n " ;
2017-06-21 11:37:34 +02:00
print '<script type="text/javascript" language="javascript">jQuery(document).ready(function() { jQuery("' . dol_escape_js ( $selector ) . '").focus(); });</script>' . " \n " ;
2013-03-30 14:27:13 +01:00
}
2011-11-27 02:23:55 +01:00
2014-07-31 10:21:47 +02:00
/**
* Return getmypid () or random PID when function is disabled
* Some web hosts disable this php function for security reasons
* and sometimes we can ' t redeclare function
*
* @ return int
*/
function dol_getmypid ()
2011-11-27 02:23:55 +01:00
{
2017-10-13 13:28:26 +02:00
if ( ! function_exists ( 'getmypid' )) {
return mt_rand ( 1 , 32768 );
} else {
return getmypid ();
}
2011-11-27 02:23:55 +01:00
}
2013-09-17 21:12:34 +02:00
2013-09-10 16:43:06 +02:00
/**
2015-05-22 15:19:27 +02:00
* Generate natural SQL search string for a criteria ( this criteria can be tested on one or several fields )
2013-09-17 21:12:34 +02:00
*
2017-12-18 19:04:57 +01:00
* @ param string | string [] $fields String or array of strings , filled with the name of all fields in the SQL query we must check ( combined with a OR ) . Example : array ( " p.field1 " , " p.field2 " )
2015-03-10 10:14:24 +01:00
* @ param string $value The value to look for .
2015-06-18 14:47:33 +02:00
* If param $mode is 0 , can contains several keywords separated with a space or |
* like " keyword1 keyword2 " = We want record field like keyword1 AND field like keyword2
* or like " keyword1|keyword2 " = We want record field like keyword1 OR field like keyword2
2015-05-22 15:19:27 +02:00
* If param $mode is 1 , can contains an operator < , > or = like " <10 " or " >=100.5 < 1000 "
2017-09-07 15:34:25 +02:00
* If param $mode is 2 , can contains a list of int id separated by comma like " 1,3,4 "
2018-01-05 04:31:48 +01:00
* If param $mode is 3 , can contains a list of string separated by comma like " a,b,c "
2017-07-26 20:33:25 +02:00
* @ param integer $mode 0 = value is list of keyword strings , 1 = value is a numeric test ( Example " >5.5 <10 " ), 2 = value is a list of id separated with comma ( Example '1,3,4' )
2017-01-08 01:00:47 +01:00
* @ param integer $nofirstand 1 = Do not output the first 'AND'
2015-03-06 20:34:00 +01:00
* @ return string $res The statement to append to the SQL query
2013-09-17 21:12:34 +02:00
*/
2015-06-22 15:48:48 +02:00
function natural_search ( $fields , $value , $mode = 0 , $nofirstand = 0 )
2013-09-10 16:43:06 +02:00
{
2017-10-13 13:28:26 +02:00
global $db , $langs ;
$value = trim ( $value );
if ( $mode == 0 )
{
$value = preg_replace ( '/\*/' , '%' , $value ); // Replace * with %
}
if ( $mode == 1 )
{
$value = preg_replace ( '/([<>=]+)\s+([0-9' . preg_quote ( $langs -> trans ( " DecimalSeparator " ), '/' ) . '\-])/' , '\1\2' , $value ); // Clean string '< 10' into '<10' so we can the explode on space to get all tests to do
}
$value = preg_replace ( '/\s*\|\s*/' , '|' , $value );
$crits = explode ( ' ' , $value );
$res = '' ;
if ( ! is_array ( $fields )) $fields = array ( $fields );
$nboffields = count ( $fields );
$end2 = count ( $crits );
$j = 0 ;
foreach ( $crits as $crit )
{
$i = 0 ; $i2 = 0 ;
$newres = '' ;
foreach ( $fields as $field )
{
if ( $mode == 1 )
{
$operator = '=' ;
$newcrit = preg_replace ( '/([<>=]+)/' , '' , trim ( $crit ));
preg_match ( '/([<>=]+)/' , trim ( $crit ), $reg );
if ( $reg [ 1 ])
{
$operator = $reg [ 1 ];
}
if ( $newcrit != '' )
{
$numnewcrit = price2num ( $newcrit );
if ( is_numeric ( $numnewcrit ))
{
$newres .= ( $i2 > 0 ? ' OR ' : '' ) . $field . ' ' . $operator . ' ' . $numnewcrit ;
}
else
{
$newres .= ( $i2 > 0 ? ' OR ' : '' ) . '1 = 2' ; // force false
}
$i2 ++ ; // a criteria was added to string
}
}
else if ( $mode == 2 )
{
2015-05-22 15:19:27 +02:00
$newres .= ( $i2 > 0 ? ' OR ' : '' ) . $field . " IN ( " . $db -> escape ( trim ( $crit )) . " ) " ;
2017-10-13 13:28:26 +02:00
$i2 ++ ; // a criteria was added to string
}
2018-01-05 04:31:48 +01:00
else if ( $mode == 3 )
{
$tmparray = explode ( ',' , trim ( $crit ));
if ( count ( $tmparray ))
{
$listofcodes = '' ;
foreach ( $tmparray as $val )
{
if ( $val )
{
$listofcodes .= ( $listofcodes ? ',' : '' );
$listofcodes .= " ' " . $db -> escape ( trim ( $val )) . " ' " ;
}
}
$newres .= ( $i2 > 0 ? ' OR ' : '' ) . $field . " IN ( " . $listofcodes . " ) " ;
$i2 ++ ; // a criteria was added to string
}
}
2017-10-13 13:28:26 +02:00
else // $mode=0
2015-05-22 15:19:27 +02:00
{
2015-06-18 14:47:33 +02:00
$textcrit = '' ;
2017-01-07 21:46:26 +01:00
$tmpcrits = explode ( '|' , $crit );
2015-06-18 14:47:33 +02:00
$i3 = 0 ;
foreach ( $tmpcrits as $tmpcrit )
{
2018-03-07 11:42:47 +01:00
if ( empty ( $tmpcrit )) continue ;
2017-09-14 13:17:31 +02:00
$newres .= (( $i2 > 0 || $i3 > 0 ) ? ' OR ' : '' );
2018-01-05 04:31:48 +01:00
if ( preg_match ( '/\.(id|rowid)$/' , $field )) // Special case for rowid that is sometimes a ref so used as a search field
2017-09-14 13:17:31 +02:00
{
$newres .= $field . " = " . ( is_numeric ( trim ( $tmpcrit )) ? trim ( $tmpcrit ) : '0' );
}
else
{
$newres .= $field . " LIKE ' " ;
2017-10-13 13:28:26 +02:00
$tmpcrit = trim ( $tmpcrit );
$tmpcrit2 = $tmpcrit ;
$tmpbefore = '%' ; $tmpafter = '%' ;
if ( preg_match ( '/^[\^\$]/' , $tmpcrit ))
{
$tmpbefore = '' ;
$tmpcrit2 = preg_replace ( '/^[\^\$]/' , '' , $tmpcrit2 );
}
2017-09-14 13:17:31 +02:00
if ( preg_match ( '/[\^\$]$/' , $tmpcrit ))
2017-10-13 13:28:26 +02:00
{
$tmpafter = '' ;
$tmpcrit2 = preg_replace ( '/[\^\$]$/' , '' , $tmpcrit2 );
}
$newres .= $tmpbefore ;
$newres .= $db -> escape ( $tmpcrit2 );
$newres .= $tmpafter ;
$newres .= " ' " ;
if ( $tmpcrit2 == '' )
{
$newres .= ' OR ' . $field . " IS NULL " ;
}
2017-09-14 13:17:31 +02:00
}
2017-10-13 13:28:26 +02:00
$i3 ++ ;
2015-06-18 14:47:33 +02:00
}
$i2 ++ ; // a criteria was added to string
2017-10-13 13:28:26 +02:00
}
$i ++ ;
}
if ( $newres ) $res = $res . ( $res ? ' AND ' : '' ) . ( $i2 > 1 ? '(' : '' ) . $newres . ( $i2 > 1 ? ')' : '' );
$j ++ ;
}
$res = ( $nofirstand ? " " : " AND " ) . " ( " . $res . " ) " ;
//print 'xx'.$res.'yy';
return $res ;
2013-09-10 16:43:06 +02:00
}
2015-01-26 21:38:02 +01:00
2017-11-04 17:11:58 +01:00
/**
* Return string with full Url
*
* @ param Object $object Object
* @ return string Url string
*/
function showDirectDownloadLink ( $object )
{
global $conf , $langs ;
$out = '' ;
$url = $object -> getLastMainDocLink ( $object -> element );
if ( $url )
{
$out .= img_picto ( '' , 'object_globe.png' ) . ' ' . $langs -> trans ( " DirectDownloadLink " ) . '<br>' ;
$out .= '<input type="text" id="directdownloadlink" class="quatrevingtpercent" value="' . $url . '">' ;
$out .= ajax_autoselect ( " directdownloadlink " , 0 );
}
return $out ;
}
2015-10-25 19:31:13 +01:00
/**
* Return the filename of file to get the thumbs
2015-11-01 17:27:41 +01:00
*
2015-11-06 01:56:56 +01:00
* @ param string $file Original filename ( full or relative path )
2015-10-25 19:31:13 +01:00
* @ param string $extName Extension to differenciate thumb file name ( '' , '_small' , '_mini' )
2016-07-30 14:49:29 +02:00
* @ param string $extImgTarget Force image extension for thumbs . Use '' to keep same extension than original image ( default ) .
2015-11-06 01:56:56 +01:00
* @ return string New file name ( full or relative path , including the thumbs / )
2015-10-25 19:31:13 +01:00
*/
function getImageFileNameForSize ( $file , $extName , $extImgTarget = '' )
{
$dirName = dirname ( $file );
if ( $dirName == '.' ) $dirName = '' ;
2015-11-01 17:27:41 +01:00
2017-10-13 13:28:26 +02:00
$fileName = preg_replace ( '/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i' , '' , $file ); // We remove extension, whatever is its case
2015-10-25 19:31:13 +01:00
$fileName = basename ( $fileName );
2015-11-01 17:27:41 +01:00
2015-10-25 19:31:13 +01:00
if ( empty ( $extImgTarget )) $extImgTarget = ( preg_match ( '/\.jpg$/i' , $file ) ? '.jpg' : '' );
2017-10-13 13:28:26 +02:00
if ( empty ( $extImgTarget )) $extImgTarget = ( preg_match ( '/\.jpeg$/i' , $file ) ? '.jpeg' : '' );
if ( empty ( $extImgTarget )) $extImgTarget = ( preg_match ( '/\.gif$/i' , $file ) ? '.gif' : '' );
if ( empty ( $extImgTarget )) $extImgTarget = ( preg_match ( '/\.png$/i' , $file ) ? '.png' : '' );
if ( empty ( $extImgTarget )) $extImgTarget = ( preg_match ( '/\.bmp$/i' , $file ) ? '.bmp' : '' );
2015-10-25 19:31:13 +01:00
2017-10-13 13:28:26 +02:00
if ( ! $extImgTarget ) return $file ;
2015-11-01 17:27:41 +01:00
2017-10-13 13:28:26 +02:00
$subdir = '' ;
if ( $extName ) $subdir = 'thumbs/' ;
2015-11-01 17:27:41 +01:00
2017-10-13 13:28:26 +02:00
return ( $dirName ? $dirName . '/' : '' ) . $subdir . $fileName . $extName . $extImgTarget ; // New filename for thumb
2015-10-25 19:31:13 +01:00
}
2016-08-05 12:18:51 +02:00
/**
* Return URL we can use for advanced preview links
*
* @ param string $modulepart propal , facture , facture_fourn , ...
2017-03-24 17:32:38 +01:00
* @ param string $relativepath Relative path of docs .
2017-05-25 08:48:59 +02:00
* @ param int $alldata Return array with all components ( 1 is recommended , then use a simple a href link with the class , target and mime attribute added . 'documentpreview' css class is handled by jquery code into main . inc . php )
2017-05-10 19:08:07 +02:00
* @ param string $param More param on http links
2017-03-24 17:32:38 +01:00
* @ return string | array Output string with href link or array with all components of link
2016-08-05 12:18:51 +02:00
*/
2017-05-11 00:03:06 +02:00
function getAdvancedPreviewUrl ( $modulepart , $relativepath , $alldata = 0 , $param = '' )
2016-08-05 12:18:51 +02:00
{
2017-10-13 13:28:26 +02:00
global $conf , $langs ;
2016-11-16 09:40:29 +01:00
2017-10-13 13:28:26 +02:00
if ( empty ( $conf -> use_javascript_ajax )) return '' ;
2016-08-05 12:18:51 +02:00
2018-02-13 16:33:45 +01:00
$mime_preview = array ( 'bmp' , 'jpeg' , 'png' , 'gif' , 'tiff' , 'pdf' , 'plain' , 'css' , 'svg+xml' );
2017-10-13 13:28:26 +02:00
//$mime_preview[]='vnd.oasis.opendocument.presentation';
//$mime_preview[]='archive';
$num_mime = array_search ( dol_mimetype ( $relativepath , '' , 1 ), $mime_preview );
2017-05-25 08:48:59 +02:00
2017-10-13 13:28:26 +02:00
if ( $alldata == 1 )
{
if ( $num_mime !== false ) return array ( 'target' => '_blank' , 'css' => 'documentpreview' , 'url' => DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode ( $relativepath ), 'mime' => dol_mimetype ( $relativepath ), );
else return array ();
}
2016-08-05 12:18:51 +02:00
2017-10-13 13:28:26 +02:00
// old behavior
if ( $num_mime !== false ) return 'javascript:document_preview(\'' . dol_escape_js ( DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode ( $relativepath ) . ( $param ? '&' . $param : '' )) . '\', \'' . dol_mimetype ( $relativepath ) . '\', \'' . dol_escape_js ( $langs -> trans ( 'Preview' )) . '\')' ;
else return '' ;
2016-08-05 12:18:51 +02:00
}
2016-08-05 23:34:59 +02:00
/**
* Return mime type of a file
*
* @ param string $file Filename we looking for MIME type
* @ param string $default Default mime type if extension not found in known list
2017-11-10 20:20:59 +01:00
* @ param int $mode 0 = Return full mime , 1 = otherwise short mime string , 2 = image for mime type , 3 = source language , 4 = css of font fa
2016-08-05 23:34:59 +02:00
* @ return string Return a mime type family ( text / xxx , application / xxx , image / xxx , audio , video , archive )
* @ see image_format_supported ( images . lib . php )
*/
2017-11-10 20:20:59 +01:00
function dol_mimetype ( $file , $default = 'application/octet-stream' , $mode = 0 )
2016-08-05 23:34:59 +02:00
{
2017-10-13 13:28:26 +02:00
$mime = $default ;
$imgmime = 'other.png' ;
2017-11-10 20:20:59 +01:00
$famime = 'file-o' ;
2017-10-13 13:28:26 +02:00
$srclang = '' ;
$tmpfile = preg_replace ( '/\.noexe$/' , '' , $file );
// Text files
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.txt$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $famime = 'file-text-o' ; }
if ( preg_match ( '/\.rtx$/i' , $tmpfile )) { $mime = 'text/richtext' ; $imgmime = 'text.png' ; $famime = 'file-text-o' ; }
if ( preg_match ( '/\.csv$/i' , $tmpfile )) { $mime = 'text/csv' ; $imgmime = 'text.png' ; $famime = 'file-text-o' ; }
if ( preg_match ( '/\.tsv$/i' , $tmpfile )) { $mime = 'text/tab-separated-values' ; $imgmime = 'text.png' ; $famime = 'file-text-o' ; }
if ( preg_match ( '/\.(cf|conf|log)$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $famime = 'file-text-o' ; }
if ( preg_match ( '/\.ini$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $srclang = 'ini' ; $famime = 'file-text-o' ; }
if ( preg_match ( '/\.css$/i' , $tmpfile )) { $mime = 'text/css' ; $imgmime = 'css.png' ; $srclang = 'css' ; $famime = 'file-text-o' ; }
2017-10-13 13:28:26 +02:00
// Certificate files
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.(crt|cer|key|pub)$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $famime = 'file-text-o' ; }
2017-10-13 13:28:26 +02:00
// HTML/XML
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.(html|htm|shtml)$/i' , $tmpfile )) { $mime = 'text/html' ; $imgmime = 'html.png' ; $srclang = 'html' ; $famime = 'file-text-o' ; }
if ( preg_match ( '/\.(xml|xhtml)$/i' , $tmpfile )) { $mime = 'text/xml' ; $imgmime = 'other.png' ; $srclang = 'xml' ; $famime = 'file-text-o' ; }
2017-10-13 13:28:26 +02:00
// Languages
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.bas$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $srclang = 'bas' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.(c)$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $srclang = 'c' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.(cpp)$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $srclang = 'cpp' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.(h)$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $srclang = 'h' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.(java|jsp)$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $srclang = 'java' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.php([0-9]{1})?$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'php.png' ; $srclang = 'php' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.phtml$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'php.png' ; $srclang = 'php' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.(pl|pm)$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'pl.png' ; $srclang = 'perl' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.sql$/i' , $tmpfile )) { $mime = 'text/plain' ; $imgmime = 'text.png' ; $srclang = 'sql' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.js$/i' , $tmpfile )) { $mime = 'text/x-javascript' ; $imgmime = 'jscript.png' ; $srclang = 'js' ; $famime = 'file-code-o' ; }
2017-10-13 13:28:26 +02:00
// Open office
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.odp$/i' , $tmpfile )) { $mime = 'application/vnd.oasis.opendocument.presentation' ; $imgmime = 'ooffice.png' ; $famime = 'file-powerpoint-o' ; }
if ( preg_match ( '/\.ods$/i' , $tmpfile )) { $mime = 'application/vnd.oasis.opendocument.spreadsheet' ; $imgmime = 'ooffice.png' ; $famime = 'file-excel-o' ; }
if ( preg_match ( '/\.odt$/i' , $tmpfile )) { $mime = 'application/vnd.oasis.opendocument.text' ; $imgmime = 'ooffice.png' ; $famime = 'file-word-o' ; }
2017-10-13 13:28:26 +02:00
// MS Office
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.mdb$/i' , $tmpfile )) { $mime = 'application/msaccess' ; $imgmime = 'mdb.png' ; $famime = 'file-o' ; }
if ( preg_match ( '/\.doc(x|m)?$/i' , $tmpfile )) { $mime = 'application/msword' ; $imgmime = 'doc.png' ; $famime = 'file-word-o' ; }
if ( preg_match ( '/\.dot(x|m)?$/i' , $tmpfile )) { $mime = 'application/msword' ; $imgmime = 'doc.png' ; $famime = 'file-word-o' ; }
if ( preg_match ( '/\.xlt(x)?$/i' , $tmpfile )) { $mime = 'application/vnd.ms-excel' ; $imgmime = 'xls.png' ; $famime = 'file-excel-o' ; }
if ( preg_match ( '/\.xla(m)?$/i' , $tmpfile )) { $mime = 'application/vnd.ms-excel' ; $imgmime = 'xls.png' ; $famime = 'file-excel-o' ; }
if ( preg_match ( '/\.xls$/i' , $tmpfile )) { $mime = 'application/vnd.ms-excel' ; $imgmime = 'xls.png' ; $famime = 'file-excel-o' ; }
if ( preg_match ( '/\.xls(b|m|x)$/i' , $tmpfile )) { $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ; $imgmime = 'xls.png' ; $famime = 'file-excel-o' ; }
if ( preg_match ( '/\.pps(m|x)?$/i' , $tmpfile )) { $mime = 'application/vnd.ms-powerpoint' ; $imgmime = 'ppt.png' ; $famime = 'file-powerpoint-o' ; }
if ( preg_match ( '/\.ppt(m|x)?$/i' , $tmpfile )) { $mime = 'application/x-mspowerpoint' ; $imgmime = 'ppt.png' ; $famime = 'file-powerpoint-o' ; }
2017-10-13 13:28:26 +02:00
// Other
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.pdf$/i' , $tmpfile )) { $mime = 'application/pdf' ; $imgmime = 'pdf.png' ; $famime = 'file-pdf-o' ; }
2017-10-13 13:28:26 +02:00
// Scripts
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.bat$/i' , $tmpfile )) { $mime = 'text/x-bat' ; $imgmime = 'script.png' ; $srclang = 'dos' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.sh$/i' , $tmpfile )) { $mime = 'text/x-sh' ; $imgmime = 'script.png' ; $srclang = 'bash' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.ksh$/i' , $tmpfile )) { $mime = 'text/x-ksh' ; $imgmime = 'script.png' ; $srclang = 'bash' ; $famime = 'file-code-o' ; }
if ( preg_match ( '/\.bash$/i' , $tmpfile )) { $mime = 'text/x-bash' ; $imgmime = 'script.png' ; $srclang = 'bash' ; $famime = 'file-code-o' ; }
2017-10-13 13:28:26 +02:00
// Images
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.ico$/i' , $tmpfile )) { $mime = 'image/x-icon' ; $imgmime = 'image.png' ; $famime = 'file-image-o' ; }
if ( preg_match ( '/\.(jpg|jpeg)$/i' , $tmpfile )) { $mime = 'image/jpeg' ; $imgmime = 'image.png' ; $famime = 'file-image-o' ; }
if ( preg_match ( '/\.png$/i' , $tmpfile )) { $mime = 'image/png' ; $imgmime = 'image.png' ; $famime = 'file-image-o' ; }
if ( preg_match ( '/\.gif$/i' , $tmpfile )) { $mime = 'image/gif' ; $imgmime = 'image.png' ; $famime = 'file-image-o' ; }
if ( preg_match ( '/\.bmp$/i' , $tmpfile )) { $mime = 'image/bmp' ; $imgmime = 'image.png' ; $famime = 'file-image-o' ; }
if ( preg_match ( '/\.(tif|tiff)$/i' , $tmpfile )) { $mime = 'image/tiff' ; $imgmime = 'image.png' ; $famime = 'file-image-o' ; }
2018-02-13 16:33:45 +01:00
if ( preg_match ( '/\.svg$/i' , $tmpfile )) { $mime = 'image/svg+xml' ; $imgmime = 'image.png' ; $famime = 'file-image-o' ; }
2017-10-13 13:28:26 +02:00
// Calendar
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.vcs$/i' , $tmpfile )) { $mime = 'text/calendar' ; $imgmime = 'other.png' ; $famime = 'file-text-o' ; }
if ( preg_match ( '/\.ics$/i' , $tmpfile )) { $mime = 'text/calendar' ; $imgmime = 'other.png' ; $famime = 'file-text-o' ; }
2017-10-13 13:28:26 +02:00
// Other
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.torrent$/i' , $tmpfile )) { $mime = 'application/x-bittorrent' ; $imgmime = 'other.png' ; $famime = 'file-o' ; }
2017-10-13 13:28:26 +02:00
// Audio
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.(mp3|ogg|au|wav|wma|mid)$/i' , $tmpfile )) { $mime = 'audio' ; $imgmime = 'audio.png' ; $famime = 'file-audio-o' ; }
2017-10-13 13:28:26 +02:00
// Video
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.ogv$/i' , $tmpfile )) { $mime = 'video/ogg' ; $imgmime = 'video.png' ; $famime = 'file-video-o' ; }
if ( preg_match ( '/\.webm$/i' , $tmpfile )) { $mime = 'video/webm' ; $imgmime = 'video.png' ; $famime = 'file-video-o' ; }
if ( preg_match ( '/\.avi$/i' , $tmpfile )) { $mime = 'video/x-msvideo' ; $imgmime = 'video.png' ; $famime = 'file-video-o' ; }
if ( preg_match ( '/\.divx$/i' , $tmpfile )) { $mime = 'video/divx' ; $imgmime = 'video.png' ; $famime = 'file-video-o' ; }
if ( preg_match ( '/\.xvid$/i' , $tmpfile )) { $mime = 'video/xvid' ; $imgmime = 'video.png' ; $famime = 'file-video-o' ; }
if ( preg_match ( '/\.(wmv|mpg|mpeg)$/i' , $tmpfile )) { $mime = 'video' ; $imgmime = 'video.png' ; $famime = 'file-video-o' ; }
2017-10-13 13:28:26 +02:00
// Archive
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.(zip|rar|gz|tgz|z|cab|bz2|7z|tar|lzh)$/i' , $tmpfile )) { $mime = 'archive' ; $imgmime = 'archive.png' ; $famime = 'file-archive-o' ; } // application/xxx where zzz is zip, ...
2017-10-13 13:28:26 +02:00
// Exe
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.(exe|com)$/i' , $tmpfile )) { $mime = 'application/octet-stream' ; $imgmime = 'other.png' ; $famime = 'file-o' ; }
2017-10-13 13:28:26 +02:00
// Lib
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.(dll|lib|o|so|a)$/i' , $tmpfile )) { $mime = 'library' ; $imgmime = 'library.png' ; $famime = 'file-o' ; }
2017-10-13 13:28:26 +02:00
// Err
2017-11-10 20:20:59 +01:00
if ( preg_match ( '/\.err$/i' , $tmpfile )) { $mime = 'error' ; $imgmime = 'error.png' ; $famime = 'file-text-o' ; }
2017-10-13 13:28:26 +02:00
// Return string
if ( $mode == 1 )
{
$tmp = explode ( '/' , $mime );
return ( ! empty ( $tmp [ 1 ]) ? $tmp [ 1 ] : $tmp [ 0 ]);
}
if ( $mode == 2 )
{
return $imgmime ;
}
if ( $mode == 3 )
{
return $srclang ;
}
2017-11-10 20:20:59 +01:00
if ( $mode == 4 )
{
return $famime ;
}
2017-10-13 13:28:26 +02:00
return $mime ;
2016-08-05 23:34:59 +02:00
}
2017-06-15 11:08:53 +02:00
/**
* Return value from dictionary
2017-08-23 17:02:53 +02:00
*
2017-06-15 11:08:53 +02:00
* @ param string $tablename name of dictionary
* @ param string $field the value to return
* @ param int $id id of line
* @ param bool $checkentity add filter on entity
* @ param string $rowidfield name of the column rowid
*/
function getDictvalue ( $tablename , $field , $id , $checkentity = false , $rowidfield = 'rowid' )
{
global $dictvalues , $db , $langs ;
2017-08-23 17:02:53 +02:00
2017-06-15 11:08:53 +02:00
if ( ! isset ( $dictvalues [ $tablename ]))
{
$dictvalues [ $tablename ] = array ();
$sql = 'SELECT * FROM ' . $tablename . ' WHERE 1' ;
if ( $checkentity ) $sql .= ' entity IN (0,' . getEntity ( '' ) . ')' ;
2017-08-23 17:02:53 +02:00
2017-06-15 11:08:53 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
while ( $obj = $db -> fetch_object ( $resql ))
{
$dictvalues [ $tablename ][ $obj -> { $rowidfield }] = $obj ;
}
}
else
{
dol_print_error ( $db );
}
}
2017-08-23 17:02:53 +02:00
2017-06-15 11:08:53 +02:00
if ( ! empty ( $dictvalues [ $tablename ][ $id ])) return $dictvalues [ $tablename ][ $id ] -> { $field }; // Found
else // Not found
{
if ( $id > 0 ) return $id ;
return '' ;
}
2017-10-10 10:19:04 +02:00
}
2017-10-16 09:29:10 +02:00
/**
* Return true if the color is light
*
* @ param string $stringcolor String with hex ( FFFFFF ) or comma RGB ( '255,255,255' )
* @ return int - 1 : Error with argument passed | 0 : color is dark | 1 : color is light
*/
function colorIsLight ( $stringcolor )
{
$res = - 1 ;
if ( ! empty ( $stringcolor ))
{
$res = 0 ;
$tmp = explode ( ',' , $stringcolor );
if ( count ( $tmp ) > 1 ) // This is a comma RGB ('255','255','255')
{
$r = $tmp [ 0 ];
$g = $tmp [ 1 ];
$b = $tmp [ 2 ];
}
else
{
$hexr = $stringcolor [ 0 ] . $stringcolor [ 1 ];
$hexg = $stringcolor [ 2 ] . $stringcolor [ 3 ];
$hexb = $stringcolor [ 4 ] . $stringcolor [ 5 ];
$r = hexdec ( $hexr );
$g = hexdec ( $hexg );
$b = hexdec ( $hexb );
}
$bright = ( max ( $r , $g , $b ) + min ( $r , $g , $b )) / 510.0 ; // HSL algorithm
if ( $bright > 0.6 ) $res = 1 ;
}
return $res ;
}
2017-12-01 19:29:29 +01:00
/**
* Function to test if an entry is enabled or not
*
* @ param string $type_user 0 = We test for internal user , 1 = We test for external user
* @ param array $menuentry Array for feature entry to test
* @ param array $listofmodulesforexternal Array with list of modules allowed to external users
* @ return int 0 = Hide , 1 = Show , 2 = Show gray
*/
function isVisibleToUserType ( $type_user , & $menuentry , & $listofmodulesforexternal )
{
global $conf ;
//print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
//print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
if ( empty ( $menuentry [ 'enabled' ])) return 0 ; // Entry disabled by condition
if ( $type_user && $menuentry [ 'module' ])
{
$tmploops = explode ( '|' , $menuentry [ 'module' ]);
$found = 0 ;
foreach ( $tmploops as $tmploop )
{
if ( in_array ( $tmploop , $listofmodulesforexternal )) {
$found ++ ; break ;
}
}
if ( ! $found ) return 0 ; // Entry is for menus all excluded to external users
}
if ( ! $menuentry [ 'perms' ] && $type_user ) return 0 ; // No permissions and user is external
if ( ! $menuentry [ 'perms' ] && ! empty ( $conf -> global -> MAIN_MENU_HIDE_UNAUTHORIZED )) return 0 ; // No permissions and option to hide when not allowed, even for internal user, is on
if ( ! $menuentry [ 'perms' ]) return 2 ; // No permissions and user is external
return 1 ;
}