2005-12-03 18:18:35 +01:00
< ? php
2007-01-05 10:06:47 +01:00
/* Copyright ( C ) 2000 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-02-02 21:52:56 +01:00
* Copyright ( C ) 2003 Jean - Louis Bergamo < jlb @ j1b . org >
2007-06-02 19:44:41 +02:00
* Copyright ( C ) 2004 - 2007 Laurent Destailleur < eldy @ users . sourceforge . net >
2004-09-02 23:14:20 +02:00
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
2004-10-31 14:34:08 +01:00
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2004-09-23 20:51:34 +02:00
* Copyright ( C ) 2004 Christophe Combelles < ccomb @ free . fr >
2007-03-19 17:42:39 +01:00
* Copyright ( C ) 2005 - 2007 Regis Houssin < regis . houssin @ cap - networks . com >
2002-04-30 12:44:42 +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
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
* or see http :// www . gnu . org /
2002-05-29 17:28:31 +02:00
*
2002-04-30 12:44:42 +02:00
* $Id $
* $Source $
*/
2002-12-17 21:57:07 +01:00
2005-03-20 03:26:59 +01:00
/**
2007-01-05 10:11:01 +01:00
\file htdocs / lib / functions . inc . php
\brief Ensemble de fonctions de base de dolibarr sous forme d ' include
\author Rodolphe Quiedeville
\author Jean - Louis Bergamo
\author Laurent Destailleur
\author Sebastien Di Cintio
\author Benoit Mortier
\version $Revision $
Ensemble de fonctions de base de dolibarr sous forme d ' include
2004-07-16 00:17:39 +02:00
*/
2004-10-07 17:22:17 +02:00
2005-10-18 23:29:45 +02:00
/**
2007-01-05 10:11:01 +01:00
\brief Renvoi une version en chaine depuis une version en tableau
\param versionarray Tableau de version ( vermajeur , vermineur , autre )
\return string Chaine version
2005-10-18 23:29:45 +02:00
*/
function versiontostring ( $versionarray )
{
2007-01-05 10:11:01 +01:00
$string = '?' ;
if ( isset ( $versionarray [ 0 ])) $string = $versionarray [ 0 ];
if ( isset ( $versionarray [ 1 ])) $string .= '.' . $versionarray [ 1 ];
if ( isset ( $versionarray [ 2 ])) $string .= '.' . $versionarray [ 2 ];
return $string ;
2005-10-18 23:29:45 +02:00
}
/**
2007-01-05 10:11:01 +01:00
\brief Compare 2 versions
\param versionarray1 Tableau de version ( vermajeur , vermineur , autre )
\param versionarray2 Tableau de version ( vermajeur , vermineur , autre )
\return int < 0 si versionarray1 < versionarray2 , 0 si = , > 0 si versionarray1 > versionarray2
2005-10-18 23:29:45 +02:00
*/
function versioncompare ( $versionarray1 , $versionarray2 )
{
2005-10-22 19:25:30 +02:00
$ret = 0 ;
$i = 0 ;
while ( $i < max ( sizeof ( $versionarray1 ), sizeof ( $versionarray1 )))
{
$operande1 = isset ( $versionarray1 [ $i ]) ? $versionarray1 [ $i ] : 0 ;
$operande2 = isset ( $versionarray2 [ $i ]) ? $versionarray2 [ $i ] : 0 ;
if ( $operande1 < $operande2 ) { $ret = - 1 ; break ; }
if ( $operande1 > $operande2 ) { $ret = 1 ; break ; }
$i ++ ;
2006-11-11 16:52:17 +01:00
}
2005-10-22 19:25:30 +02:00
return $ret ;
2005-10-18 23:29:45 +02:00
}
/**
2007-01-05 10:11:01 +01:00
\brief Renvoie version PHP
\return array Tableau de version ( vermajeur , vermineur , autre )
2005-10-18 23:29:45 +02:00
*/
function versionphp ()
{
2007-01-05 10:11:01 +01:00
return split ( '\.' , PHP_VERSION );
2005-10-18 23:29:45 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2007-01-05 10:11:01 +01:00
\brief Renvoi vrai si l ' email est syntaxiquement valide
\param address adresse email ( Ex : " toto@titi.com " , " John Do <johndo@titi.com> " )
\return boolean true si email valide , false sinon
2004-10-07 17:22:17 +02:00
*/
function ValidEmail ( $address )
{
2004-10-23 02:47:51 +02:00
if ( ereg ( " .*<(.+)> " , $address , $regs )) {
2004-10-07 17:22:17 +02:00
$address = $regs [ 1 ];
}
2007-05-09 12:34:08 +02:00
if ( ereg ( " ^[^@ ]+@([a-zA-Z0-9 \ -]+ \ .)+([a-zA-Z0-9 \ -] { 2}|aero|biz|com|edu|gov|info|int|mil|name|net|org) \$ " , $address ))
2004-10-07 17:22:17 +02:00
{
2004-10-23 02:47:51 +02:00
return true ;
2004-10-07 17:22:17 +02:00
}
else
{
2004-10-23 02:47:51 +02:00
return false ;
2004-10-07 17:22:17 +02:00
}
}
2004-12-28 16:36:40 +01:00
/**
2007-01-05 10:11:01 +01:00
\brief Renvoi vrai si l ' email a un nom de domaine qui r<EFBFBD> soud via dns
\param mail adresse email ( Ex : " toto@titi.com " , " John Do <johndo@titi.com> " )
\return boolean true si email valide , false sinon
2004-12-28 16:36:40 +01:00
*/
2004-10-07 17:22:17 +02:00
function check_mail ( $mail )
{
list ( $user , $domain ) = split ( " @ " , $mail , 2 );
if ( checkdnsrr ( $domain , " MX " ))
{
return true ;
}
else
{
return false ;
}
}
2005-07-03 18:16:44 +02:00
/**
\brief Nettoie chaine de caract<EFBFBD> re des accents
\param str Chaine a nettoyer
\return string Chaine nettoy<EFBFBD>
*/
2005-05-24 13:44:07 +02:00
function unaccent ( $str )
{
2005-05-24 15:47:50 +02:00
$acc = array ( " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " <EFBFBD> " , " ' " );
$uac = array ( " a " , " a " , " e " , " e " , " e " , " i " , " i " , " o " , " o " , " u " , " u " , " " );
2005-05-24 13:44:07 +02:00
return str_replace ( $acc , $uac , $str );
}
2004-10-07 17:22:17 +02:00
2005-07-03 18:16:44 +02:00
/**
\brief Nettoie chaine de caract<EFBFBD> re de caract<EFBFBD> res sp<EFBFBD> ciaux
\param str Chaine a nettoyer
\return string Chaine nettoy<EFBFBD>
*/
function sanitize_string ( $str )
{
2006-11-11 16:52:17 +01:00
$forbidden_chars_to_underscore = array ( " " , " ' " , " / " , " \\ " , " : " , " * " , " ? " , " \" " , " < " , " > " , " | " , " [ " , " ] " , " , " , " ; " , " = " );
//$forbidden_chars_to_remove=array("(",")");
2006-05-31 23:39:54 +02:00
$forbidden_chars_to_remove = array ();
return str_replace ( $forbidden_chars_to_underscore , " _ " , str_replace ( $forbidden_chars_to_remove , " " , $str ));
2005-07-03 18:16:44 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Envoi des messages dolibarr dans un fichier ou dans syslog
Pour fichier : fichier d<EFBFBD> fini par SYSLOG_FILE
Pour syslog : facility d<EFBFBD> fini par SYSLOG_FACILITY
\param message Message a tracer
\param level Niveau de l ' erreur
\remarks Cette fonction n ' a un effet que si le module syslog est activ<EFBFBD> .
Warning , les fonctions syslog sont buggu<EFBFBD> s sous Windows et g<EFBFBD> n<EFBFBD> rent des
fautes de protection m<EFBFBD> moire . Pour r<EFBFBD> soudre , utiliser le loggage fichier ,
au lieu du loggage syslog ( configuration du module ) .
Si SYSLOG_FILE_NO_ERROR d<EFBFBD> fini , on ne g<EFBFBD> re pas erreur ecriture log
\remarks On windows LOG_ERROR = 4 , LOG_WARNING = 5 , LOG_NOTICE = LOG_DEBUG = 6
2004-07-16 00:17:39 +02:00
*/
2006-06-18 14:56:57 +02:00
function dolibarr_syslog ( $message , $level = LOG_INFO )
2004-02-10 20:23:08 +01:00
{
2007-02-27 23:00:59 +01:00
global $conf , $user , $langs ;
if ( $conf -> syslog -> enabled )
{
2007-05-10 20:25:19 +02:00
//print $level.' - '.$conf->global->SYSLOG_LEVEL.' - '.$conf->syslog->enabled;
if ( $level > $conf -> global -> SYSLOG_LEVEL ) return ;
2007-02-27 23:00:59 +01:00
// Ajout user a la log
$login = '???' ;
if ( is_object ( $user ) && $user -> id ) $login = $user -> login ;
$message = sprintf ( " %-8s " , $login ) . " " . $message ;
if ( defined ( " SYSLOG_FILE " ) && SYSLOG_FILE )
{
if ( defined ( " SYSLOG_FILE_NO_ERROR " )) $file =@ fopen ( SYSLOG_FILE , " a+ " );
else $file = fopen ( SYSLOG_FILE , " a+ " );
if ( $file )
{
fwrite ( $file , strftime ( " %Y-%m-%d %H:%M:%S " , time ()) . " " . $level . " " . $message . " \n " );
fclose ( $file );
}
elseif ( ! defined ( " SYSLOG_FILE_NO_ERROR " ))
{
$langs -> load ( " main " );
print $langs -> trans ( " ErrorFailedToOpenFile " , SYSLOG_FILE );
}
}
else
{
//define_syslog_variables(); d<> j<EFBFBD> d<> finit dans master.inc.php
if ( defined ( " MAIN_SYSLOG_FACILITY " ) && MAIN_SYSLOG_FACILITY )
{
$facility = MAIN_SYSLOG_FACILITY ;
}
elseif ( defined ( " SYSLOG_FACILITY " ) && SYSLOG_FACILITY && defined ( SYSLOG_FACILITY ))
{
// Exemple: SYSLOG_FACILITY vaut LOG_USER qui vaut 8. On a besoin de 8 dans $facility.
$facility = constant ( SYSLOG_FACILITY );
}
else
{
$facility = LOG_USER ;
}
openlog ( " dolibarr " , LOG_PID | LOG_PERROR , $facility );
if ( ! $level )
{
syslog ( LOG_ERR , $message );
}
else
{
syslog ( $level , $message );
}
closelog ();
}
}
2004-02-10 20:23:08 +01:00
}
2007-02-27 23:00:59 +01:00
2004-12-28 16:36:40 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Affiche le header d ' une fiche
\param links Tableau de titre d ' onglets
\param active 0 = onglet non actif , 1 = onglet actif
\param title Titre tabelau ( " " par defaut )
\param notab 0 = Add tab header , 1 = no tab header
2004-07-16 00:17:39 +02:00
*/
2006-08-13 02:34:16 +02:00
function dolibarr_fiche_head ( $links , $active = '0' , $title = '' , $notab = 0 )
2004-02-08 12:56:38 +01:00
{
2006-08-13 02:34:16 +02:00
print " \n " . '<div class="tabs">' . " \n " ;
2004-02-08 12:56:38 +01:00
2005-12-03 04:49:00 +01:00
// Affichage titre
if ( $title )
2004-07-19 11:22:17 +02:00
{
2004-12-22 22:38:30 +01:00
$limittitle = 30 ;
2005-12-03 04:49:00 +01:00
print '<a class="tabTitle">' ;
2006-11-11 16:52:17 +01:00
print
2005-12-06 16:26:39 +01:00
(( ! defined ( 'MAIN_USE_SHORT_TITLE' )) || ( defined ( 'MAIN_USE_SHORT_TITLE' ) && MAIN_USE_SHORT_TITLE ))
? dolibarr_trunc ( $title , $limittitle )
: $title ;
2005-12-03 04:49:00 +01:00
print '</a>' ;
2004-07-19 11:22:17 +02:00
}
2005-12-03 04:49:00 +01:00
// Affichage onglets
2005-09-11 18:29:14 +02:00
for ( $i = 0 ; $i < sizeof ( $links ) ; $i ++ )
2004-02-08 12:56:38 +01:00
{
2005-09-11 18:29:14 +02:00
if ( $links [ $i ][ 2 ] == 'image' )
{
print '<a class="tabimage" href="' . $links [ $i ][ 0 ] . '">' . $links [ $i ][ 1 ] . '</a>' . " \n " ;
}
else
{
2006-04-09 00:47:51 +02:00
//print "x $i $active ".$links[$i][2]." z";
if (( is_numeric ( $active ) && $i == $active )
|| ( ! is_numeric ( $active ) && $active == $links [ $i ][ 2 ]))
2005-09-11 18:29:14 +02:00
{
print '<a id="active" class="tab" href="' . $links [ $i ][ 0 ] . '">' . $links [ $i ][ 1 ] . '</a>' . " \n " ;
}
else
{
print '<a class="tab" href="' . $links [ $i ][ 0 ] . '">' . $links [ $i ][ 1 ] . '</a>' . " \n " ;
}
}
2004-02-08 12:56:38 +01:00
}
2005-09-11 18:29:14 +02:00
print " </div> \n " ;
2006-11-11 16:52:17 +01:00
2006-08-13 02:34:16 +02:00
if ( ! $notab ) print '<div class="tabBar">' . " \n \n " ;
2004-02-08 12:56:38 +01:00
}
2005-06-11 13:38:19 +02:00
/**
\brief R<EFBFBD> cup<EFBFBD> re une constante depuis la base de donn<EFBFBD> es .
2005-08-20 16:36:32 +02:00
\see dolibarr_del_const , dolibarr_set_const
2005-06-11 13:38:19 +02:00
\param db Handler d ' acc<EFBFBD> s base
\param name Nom de la constante
\return string Valeur de la constante
*/
function dolibarr_get_const ( $db , $name )
{
2005-09-11 18:29:14 +02:00
$value = '' ;
2006-11-11 16:52:17 +01:00
2005-09-11 18:29:14 +02:00
$sql = " SELECT value " ;
$sql .= " FROM llx_const " ;
2006-11-11 16:52:17 +01:00
$sql .= " WHERE name = ' $name '; " ;
$resql = $db -> query ( $sql );
2005-09-11 18:29:14 +02:00
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
2006-02-12 16:54:21 +01:00
$value = $obj -> value ;
2005-09-11 18:29:14 +02:00
}
return $value ;
2005-06-11 13:38:19 +02:00
}
2005-08-11 22:23:34 +02:00
2004-12-28 16:36:40 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Insertion d ' une constante dans la base de donn<EFBFBD> es .
\see dolibarr_del_const , dolibarr_get_const
\param db Handler d ' acc<EFBFBD> s base
\param name Nom de la constante
\param value Valeur de la constante
\param type Type de constante ( chaine par d<EFBFBD> faut )
\param visible La constante est elle visible ( 0 par d<EFBFBD> faut )
\param note Explication de la constante
\return int < 0 si ko , > 0 si ok
2004-07-16 00:17:39 +02:00
*/
function dolibarr_set_const ( $db , $name , $value , $type = 'chaine' , $visible = 0 , $note = '' )
2004-02-05 19:39:38 +01:00
{
2005-09-11 18:29:14 +02:00
global $conf ;
2006-11-11 16:52:17 +01:00
2005-09-11 18:29:14 +02:00
$db -> begin ();
2006-11-11 16:52:17 +01:00
if ( ! $name )
2006-09-03 15:57:44 +02:00
{
dolibarr_print_error ( " Error: Call to function dolibarr_set_const with wrong parameters " );
exit ;
}
2006-11-11 16:52:17 +01:00
2005-09-11 18:29:14 +02:00
//dolibarr_syslog("dolibarr_set_const name=$name, value=$value");
2006-11-11 16:52:17 +01:00
$sql = " DELETE FROM llx_const WHERE name = ' $name '; " ;
$resql = $db -> query ( $sql );
2005-09-11 18:29:14 +02:00
$sql = " INSERT INTO llx_const(name,value,type,visible,note) " ;
$sql .= " VALUES (' $name ',' " . addslashes ( $value ) . " ',' $type ', $visible ,' " . addslashes ( $note ) . " '); " ;
2006-11-11 16:52:17 +01:00
$resql = $db -> query ( $sql );
2005-04-11 19:21:24 +02:00
2005-09-11 18:29:14 +02:00
if ( $resql )
{
$db -> commit ();
$conf -> global -> $name = $value ;
return 1 ;
}
else
{
$db -> rollback ();
return - 1 ;
}
2004-02-21 00:41:53 +01:00
}
2004-02-05 19:39:38 +01:00
2004-12-28 16:36:40 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Effacement d ' une constante dans la base de donn<EFBFBD> es
\see dolibarr_get_const , dolibarr_sel_const
\param db Handler d ' acc<EFBFBD> s base
\param name Nom ou rowid de la constante
\return int < 0 si ko , > 0 si ok
2004-07-16 00:17:39 +02:00
*/
function dolibarr_del_const ( $db , $name )
2004-02-21 00:41:53 +01:00
{
2006-12-22 23:05:44 +01:00
$sql = " DELETE FROM llx_const WHERE name=' $name ' or rowid=' $name ' " ;
$resql = $db -> query ( $sql );
if ( $resql )
2004-02-21 00:41:53 +01:00
{
2006-12-22 23:05:44 +01:00
return 1 ;
2004-02-21 00:41:53 +01:00
}
2006-12-22 23:05:44 +01:00
else
2004-02-21 00:41:53 +01:00
{
2006-12-22 23:05:44 +01:00
return - 1 ;
2004-02-21 00:41:53 +01:00
}
2004-02-05 19:39:38 +01:00
}
2006-11-05 19:21:28 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Sauvegarde parametrage personnel
\param db Handler d ' acc<EFBFBD> s base
\param user Objet utilisateur
\param url Si defini , on sauve parametre du tableau tab dont cl<EFBFBD> = ( url avec sortfield , sortorder , begin et page )
Si non defini on sauve tous parametres du tableau tab
\param tab Tableau ( cl<EFBFBD> => valeur ) des param<EFBFBD> tres <EFBFBD> sauvegarder
\return int < 0 si ko , > 0 si ok
2006-11-05 19:21:28 +01:00
*/
function dolibarr_set_user_page_param ( $db , & $user , $url = '' , $tab )
{
2006-11-12 17:57:50 +01:00
// Verification parametres
if ( sizeof ( $tab ) < 1 ) return - 1 ;
2006-11-05 19:21:28 +01:00
$db -> begin ();
2006-11-11 16:52:17 +01:00
2006-11-12 17:57:50 +01:00
// On efface anciens param<61> tres pour toutes les cl<63> dans $tab
2006-11-05 19:21:28 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " user_param " ;
$sql .= " WHERE fk_user = " . $user -> id ;
if ( $url ) $sql .= " AND page=' " . $url . " ' " ;
2006-11-12 17:57:50 +01:00
else $sql .= " AND page='' " ; // Page ne peut etre null
$sql .= " AND param in ( " ;
$i = 0 ;
foreach ( $tab as $key => $value )
{
if ( $i > 0 ) $sql .= ',' ;
$sql .= " ' " . $key . " ' " ;
$i ++ ;
}
$sql .= " ) " ;
2006-11-05 19:21:28 +01:00
dolibarr_syslog ( " functions.inc.php::dolibarr_set_user_page_param $sql " );
$resql = $db -> query ( $sql );
if ( ! $resql )
{
dolibarr_print_error ( $db );
2006-11-12 17:57:50 +01:00
$db -> rollback ();
2006-11-05 19:21:28 +01:00
exit ;
}
2006-11-12 17:57:50 +01:00
foreach ( $tab as $key => $value )
2006-11-05 19:21:28 +01:00
{
// On positionne nouveaux param<61> tres
if ( $value && ( ! $url || in_array ( $key , array ( 'sortfield' , 'sortorder' , 'begin' , 'page' ))))
{
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " user_param(fk_user,page,param,value) " ;
$sql .= " VALUES ( " . $user -> id . " , " ;
if ( $url ) $sql .= " ' " . urlencode ( $url ) . " ', " ;
else $sql .= " '', " ;
$sql .= " ' " . $key . " ',' " . addslashes ( $value ) . " '); " ;
dolibarr_syslog ( " functions.inc.php::dolibarr_set_user_page_param $sql " );
2006-11-12 17:57:50 +01:00
$result = $db -> query ( $sql );
if ( ! $result )
{
dolibarr_print_error ( $db );
$db -> rollback ();
exit ;
}
2006-11-05 19:21:28 +01:00
$user -> page_param [ $key ] = $value ;
}
}
$db -> commit ();
return 1 ;
}
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Formattage des nombres
2004-07-16 00:17:39 +02:00
\param ca valeur a formater
2004-08-07 16:41:29 +02:00
\return int valeur format<EFBFBD> e
2004-07-16 00:17:39 +02:00
*/
function dolibarr_print_ca ( $ca )
2004-02-18 16:20:12 +01:00
{
2005-07-10 17:46:19 +02:00
global $langs , $conf ;
2006-11-11 16:52:17 +01:00
2004-05-01 02:32:11 +02:00
if ( $ca > 1000 )
2004-02-18 16:20:12 +01:00
{
$cat = round (( $ca / 1000 ), 2 );
2005-07-10 17:46:19 +02:00
$cat = " $cat K " . $langs -> trans ( " Currency " . $conf -> monnaie );
2004-02-18 16:20:12 +01:00
}
2004-05-01 02:32:11 +02:00
else
2004-02-18 16:20:12 +01:00
{
$cat = round ( $ca , 2 );
2005-07-10 17:46:19 +02:00
$cat = " $cat " . $langs -> trans ( " Currency " . $conf -> monnaie );
2004-02-18 16:20:12 +01:00
}
2004-07-16 00:17:39 +02:00
2004-05-01 02:32:11 +02:00
if ( $ca > 1000000 )
2004-02-18 16:20:12 +01:00
{
$cat = round (( $ca / 1000000 ), 2 );
2005-07-10 17:46:19 +02:00
$cat = " $cat M " . $langs -> trans ( " Currency " . $conf -> monnaie );
2004-02-18 16:20:12 +01:00
}
2004-05-01 02:32:11 +02:00
return $cat ;
}
2005-06-11 13:38:19 +02:00
/**
\brief Effectue un d<EFBFBD> calage de date par rapport <EFBFBD> une dur<EFBFBD> e
\param time Date timestamp ou au format YYYY - MM - DD
\param duration_value Valeur de la dur<EFBFBD> e <EFBFBD> ajouter
\param duration_unit Unit<EFBFBD> de la dur<EFBFBD> e <EFBFBD> ajouter ( d , m , y )
\return int Nouveau timestamp
*/
function dolibarr_time_plus_duree ( $time , $duration_value , $duration_unit )
{
2006-11-26 19:24:53 +01:00
if ( $duration_value == 0 ) return $time ;
if ( $duration_value > 0 ) $deltastring = " + " . abs ( $duration_value );
if ( $duration_value < 0 ) $deltastring = " - " . abs ( $duration_value );
2005-06-11 13:38:19 +02:00
if ( $duration_unit == 'd' ) { $deltastring .= " day " ; }
if ( $duration_unit == 'm' ) { $deltastring .= " month " ; }
if ( $duration_unit == 'y' ) { $deltastring .= " year " ; }
return strtotime ( $deltastring , $time );
}
2004-12-28 16:36:40 +01:00
/**
2005-07-02 15:19:18 +02:00
\brief Formattage de la date en fonction de la langue $conf -> langage
2005-08-15 23:36:13 +02:00
\param time Date 'timestamp' ou format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS'
2006-08-14 23:23:42 +02:00
\param format Format d ' affichage de la date
" %d %b %Y " ,
2007-02-07 01:07:29 +01:00
" %d/%m/%Y %H:%M " ,
2006-11-26 08:00:14 +01:00
" %d/%m/%Y %H:%M:%S " ,
2007-05-01 18:26:12 +02:00
" day " , " daytext " , " dayhour " , " dayhourldap " , " dayhourtext "
2006-03-18 20:58:33 +01:00
\return string Date format<EFBFBD> e ou '' si time null
2004-07-16 00:17:39 +02:00
*/
2005-10-31 04:15:42 +01:00
function dolibarr_print_date ( $time , $format = '' )
2004-05-01 02:32:11 +02:00
{
2005-10-31 04:15:42 +01:00
global $conf ;
2006-11-11 16:52:17 +01:00
2005-10-31 04:15:42 +01:00
// Si format non d<> fini, on prend $conf->format_date_text_short
if ( ! $format ) $format = $conf -> format_date_text_short ;
2006-08-14 23:23:42 +02:00
if ( $format == 'day' ) $format = $conf -> format_date_short ;
if ( $format == 'daytext' ) $format = $conf -> format_date_text_short ;
if ( $format == 'dayhour' ) $format = $conf -> format_date_hour_short ;
2007-05-01 18:26:12 +02:00
if ( $format == 'dayhourldap' ) $format = '%Y%m%d%H%M%SZ' ;
2006-08-14 23:23:42 +02:00
if ( $format == 'dayhourtext' ) $format = $conf -> format_date_hour_text_short ;
2007-05-14 22:35:04 +02:00
if ( ! $format ) $format = '%Y-%m-%d %H:%M:%S' ;
2007-05-14 22:58:59 +02:00
2006-03-18 20:58:33 +01:00
// Si date non d<> finie, on renvoie ''
if ( ! $time ) return '' ;
2005-08-15 23:36:13 +02:00
2005-07-02 15:19:18 +02:00
// Analyse de la date
2007-06-15 01:24:09 +02:00
if ( eregi ( '^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?' , $time , $reg ))
2005-10-31 04:15:42 +01:00
{
// Date est au format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS'
2005-07-02 15:19:18 +02:00
$syear = $reg [ 1 ];
$smonth = $reg [ 2 ];
$sday = $reg [ 3 ];
$shour = $reg [ 4 ];
$smin = $reg [ 5 ];
2007-05-14 22:58:59 +02:00
2005-10-31 04:15:42 +01:00
if ( $syear < 1970 && isset ( $_SERVER [ " WINDIR " ]))
2005-07-02 15:19:18 +02:00
{
2007-01-16 23:02:36 +01:00
return strftime ( $format , dolibarr_mktime ( $shour , $smin , 0 , $smonth , $sday , $syear ));
2005-07-02 15:19:18 +02:00
}
else
{
return strftime ( $format , mktime ( $shour , $smin , 0 , $smonth , $sday , $syear ));
}
}
2005-10-31 04:15:42 +01:00
else
{
2005-07-02 15:19:18 +02:00
// Date est un timestamps
return strftime ( $format , $time );
}
2004-05-01 02:32:11 +02:00
}
2004-02-18 16:20:12 +01:00
2004-07-16 00:17:39 +02:00
2006-11-26 08:00:14 +01:00
/**
2007-01-16 20:43:02 +01:00
\brief Retourne une date fabriqu<EFBFBD> e depuis une chaine
2006-11-26 08:00:14 +01:00
\param string Date format<EFBFBD> e en chaine ( YYYYMMDD ou YYYYMMDDHHMMSS )
\return date Date
*/
2007-01-16 20:43:02 +01:00
function dolibarr_stringtotime ( $string )
2006-11-26 08:00:14 +01:00
{
$string = eregi_replace ( '[^0-9]' , '' , $string );
$tmp = $string . '000000' ; // Si date YYYYMMDD
$date = mktime ( substr ( $tmp , 8 , 2 ), substr ( $tmp , 10 , 2 ), substr ( $tmp , 12 , 2 ), substr ( $tmp , 4 , 2 ), substr ( $tmp , 6 , 2 ), substr ( $tmp , 0 , 4 ));
return $date ;
}
2007-01-16 20:43:02 +01:00
/**
\brief Retourne une date fabriqu<EFBFBD> e depuis infos .
Remplace la fonction mktime non impl<EFBFBD> ment<EFBFBD> e sous Windows si ann<EFBFBD> e < 1970
2007-06-04 17:44:49 +02:00
\param hour Heure
\param minute Minute
\param second Seconde
2007-01-16 20:43:02 +01:00
\param month Mois
\param day Jour
\param year Ann<EFBFBD> e
\return date Date
*/
2007-06-04 17:44:49 +02:00
function dolibarr_mktime ( $hour , $minute , $second , $month , $day , $year )
2007-01-16 20:43:02 +01:00
{
2007-01-16 23:02:36 +01:00
$montharray = array ( 1 => 'january' , 2 => 'february' , 3 => 'march' , 4 => 'april' , 5 => 'may' , 6 => 'june' ,
7 => 'july' , 8 => 'august' , 9 => 'september' , 10 => 'october' , 11 => 'november' , 12 => 'december' );
2007-01-16 20:43:02 +01:00
if ( $year <= 1970 && $_SERVER [ " WINDIR " ])
{
2007-01-16 23:02:36 +01:00
// Sous Windows, mktime ne fonctionne pas quand ann<6E> e < 1970.
// On utilise strtotime pour obtenir la traduction.
$string = $day . " " . $montharray [ 0 + $month ] . " " . $year ;
$date = strtotime ( $string );
//print "x".($month)."y".(0+$month)." ".$string." ".$date."e";
//print "eee".$db->idate($date);
return $date ;
2007-01-16 20:43:02 +01:00
}
else
{
2007-06-04 17:44:49 +02:00
return mktime ( $hour , $minute , $second , $month , $day , $year );
2007-01-16 20:43:02 +01:00
}
}
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Affiche les informations d ' un objet
2004-07-16 00:17:39 +02:00
\param object objet a afficher
*/
function dolibarr_print_object_info ( $object )
2004-05-01 02:32:11 +02:00
{
2004-09-18 14:45:37 +02:00
global $langs ;
2006-10-11 10:19:40 +02:00
$langs -> load ( " other " );
2006-11-11 16:52:17 +01:00
2005-07-03 15:05:13 +02:00
if ( isset ( $object -> user_creation ) && $object -> user_creation -> fullname )
2004-09-18 14:45:37 +02:00
print $langs -> trans ( " CreatedBy " ) . " : " . $object -> user_creation -> fullname . '<br>' ;
if ( isset ( $object -> date_creation ))
2007-06-16 15:56:05 +02:00
print $langs -> trans ( " DateCreation " ) . " : " . dolibarr_print_date ( $object -> date_creation , " dayhourtext " ) . '<br>' ;
2006-11-11 16:52:17 +01:00
2005-07-03 15:05:13 +02:00
if ( isset ( $object -> user_modification ) && $object -> user_modification -> fullname )
2004-09-18 14:45:37 +02:00
print $langs -> trans ( " ModifiedBy " ) . " : " . $object -> user_modification -> fullname . '<br>' ;
2006-11-11 16:52:17 +01:00
2004-09-18 14:45:37 +02:00
if ( isset ( $object -> date_modification ))
2007-06-16 15:56:05 +02:00
print $langs -> trans ( " DateLastModification " ) . " : " . dolibarr_print_date ( $object -> date_modification , " dayhourtext " ) . '<br>' ;
2006-11-11 16:52:17 +01:00
2005-07-03 15:05:13 +02:00
if ( isset ( $object -> user_validation ) && $object -> user_validation -> fullname )
2004-09-18 14:45:37 +02:00
print $langs -> trans ( " ValidatedBy " ) . " : " . $object -> user_validation -> fullname . '<br>' ;
2006-11-11 16:52:17 +01:00
2004-09-18 14:45:37 +02:00
if ( isset ( $object -> date_validation ))
2007-06-16 15:56:05 +02:00
print $langs -> trans ( " DateValidation " ) . " : " . dolibarr_print_date ( $object -> date_validation , " dayhourtext " ) . '<br>' ;
2004-09-18 14:45:37 +02:00
2005-07-03 15:05:13 +02:00
if ( isset ( $object -> user_cloture ) && $object -> user_cloture -> fullname )
2004-09-18 14:45:37 +02:00
print $langs -> trans ( " ClosedBy " ) . " : " . $object -> user_cloture -> fullname . '<br>' ;
if ( isset ( $object -> date_cloture ))
2007-06-16 15:56:05 +02:00
print $langs -> trans ( " DateClosing " ) . " : " . dolibarr_print_date ( $object -> date_cloture , " dayhourtext " ) . '<br>' ;
2005-10-15 17:32:01 +02:00
if ( isset ( $object -> user_rappro ) && $object -> user_rappro -> fullname )
print $langs -> trans ( " ConciliatedBy " ) . " : " . $object -> user_rappro -> fullname . '<br>' ;
if ( isset ( $object -> date_rappro ))
2007-06-16 15:56:05 +02:00
print $langs -> trans ( " DateConciliating " ) . " : " . dolibarr_print_date ( $object -> date_rappro , " dayhourtext " ) . '<br>' ;
2004-02-18 16:20:12 +01:00
}
2004-12-28 16:36:40 +01:00
/**
2005-04-08 23:31:03 +02:00
\brief Formatage des num<EFBFBD> ros de telephone en fonction du format d ' un pays
\param phone Num<EFBFBD> ro de telephone <EFBFBD> formater
\param country Pays selon lequel formatter
\return string Num<EFBFBD> ro de t<EFBFBD> l<EFBFBD> phone format<EFBFBD>
2004-07-16 00:17:39 +02:00
*/
2005-01-30 20:42:33 +01:00
function dolibarr_print_phone ( $phone , $country = " FR " )
2004-05-01 02:32:11 +02:00
{
2005-01-30 20:42:33 +01:00
$phone = trim ( $phone );
2004-09-25 02:12:49 +02:00
if ( strstr ( $phone , ' ' )) { return $phone ; }
2005-01-30 20:42:33 +01:00
if ( strtoupper ( $country ) == " FR " ) {
// France
if ( strlen ( $phone ) == 10 ) {
return substr ( $phone , 0 , 2 ) . " " . substr ( $phone , 2 , 2 ) . " " . substr ( $phone , 4 , 2 ) . " " . substr ( $phone , 6 , 2 ) . " " . substr ( $phone , 8 , 2 );
}
elseif ( strlen ( $phone ) == 7 )
{
2006-06-20 12:37:05 +02:00
2005-01-30 20:42:33 +01:00
return substr ( $phone , 0 , 3 ) . " " . substr ( $phone , 3 , 2 ) . " " . substr ( $phone , 5 , 2 );
}
elseif ( strlen ( $phone ) == 9 )
{
return substr ( $phone , 0 , 2 ) . " " . substr ( $phone , 2 , 3 ) . " " . substr ( $phone , 5 , 2 ) . " " . substr ( $phone , 7 , 2 );
}
elseif ( strlen ( $phone ) == 11 )
{
return substr ( $phone , 0 , 3 ) . " " . substr ( $phone , 3 , 2 ) . " " . substr ( $phone , 5 , 2 ) . " " . substr ( $phone , 7 , 2 ) . " " . substr ( $phone , 9 , 2 );
}
elseif ( strlen ( $phone ) == 12 )
{
return substr ( $phone , 0 , 4 ) . " " . substr ( $phone , 4 , 2 ) . " " . substr ( $phone , 6 , 2 ) . " " . substr ( $phone , 8 , 2 ) . " " . substr ( $phone , 10 , 2 );
}
2004-09-25 02:12:49 +02:00
}
return $phone ;
2004-05-01 02:32:11 +02:00
}
2004-02-18 16:20:12 +01:00
2005-04-08 23:31:03 +02:00
/**
\brief Tronque une chaine <EFBFBD> une taille donn<EFBFBD> e en ajoutant les points de suspension si cela d<EFBFBD> passe
2005-07-03 15:05:13 +02:00
\param string Chaine <EFBFBD> tronquer
2006-04-06 20:54:10 +02:00
\param size Longueur max de la chaine . Si 0 , pas de limite .
2005-07-03 15:05:13 +02:00
\return string Chaine tronqu<EFBFBD> e
2005-04-08 23:31:03 +02:00
*/
function dolibarr_trunc ( $string , $size = 40 )
{
2006-04-06 20:54:10 +02:00
if ( $size == 0 ) return $string ;
2006-06-20 12:37:05 +02:00
if (( ! defined ( 'USE_SHORT_TITLE' )) || defined ( 'USE_SHORT_TITLE' ) && USE_SHORT_TITLE )
{
if ( strlen ( $string ) > $size )
return substr ( $string , 0 , $size ) . '...' ;
else
return $string ;
}
2005-12-06 16:26:39 +01:00
else
return $string ;
2005-04-08 23:31:03 +02:00
}
2004-09-23 20:51:34 +02:00
2006-06-04 00:01:38 +02:00
/**
\brief Compl<EFBFBD> te une chaine <EFBFBD> une taille donn<EFBFBD> e par des espaces
\param string Chaine <EFBFBD> compl<EFBFBD> ter
\param size Longueur de la chaine .
\param side 0 = Compl<EFBFBD> tion <EFBFBD> droite , 1 = Compl<EFBFBD> tion <EFBFBD> gauche
\param char Chaine de compl<EFBFBD> tion
\return string Chaine compl<EFBFBD> t<EFBFBD> e
*/
function dolibarr_pad ( $string , $size , $side , $char = ' ' )
{
$taille = sizeof ( $string );
$i = 0 ;
while ( $i < ( $size - $taille ))
{
if ( $side > 0 ) $string .= $char ;
else $string = $char . $string ;
$i ++ ;
}
return $string ;
}
2004-12-28 16:36:40 +01:00
/**
2005-07-09 12:55:21 +02:00
\brief Affiche picto propre <EFBFBD> une notion / module ( fonction g<EFBFBD> n<EFBFBD> rique )
2005-07-03 15:05:13 +02:00
\param alt Texte sur le alt de l ' image
\param object Objet pour lequel il faut afficher le logo ( exemple : user , group , action , bill , contract , propal , product , ... )
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-08-07 01:39:54 +02:00
*/
2005-01-30 20:42:33 +01:00
function img_object ( $alt , $object )
2004-08-07 01:39:54 +02:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
2005-01-30 20:42:33 +01:00
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/object_' . $object . '.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-08-07 01:39:54 +02:00
}
2005-07-09 12:55:21 +02:00
/**
\brief Affiche picto ( fonction g<EFBFBD> n<EFBFBD> rique )
\param alt Texte sur le alt de l ' image
2007-06-16 12:07:20 +02:00
\param picto Nom de l 'image a afficher (Si pas d' extension , on met '.png' )
2007-08-09 17:50:35 +02:00
\param options Attribut suppl<EFBFBD> mentaire a la balise img
\return string Retourne tag img
2005-07-09 12:55:21 +02:00
*/
2006-11-05 19:21:28 +01:00
function img_picto ( $alt , $picto , $options = '' )
2005-07-09 12:55:21 +02:00
{
2007-06-16 12:07:20 +02:00
global $conf ;
if ( ! eregi ( '(\.png|\.gif)$' , $picto )) $picto .= '.png' ;
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/' . $picto . '" border="0" alt="' . $alt . '" title="' . $alt . '"' . ( $options ? ' ' . $options : '' ) . '>' ;
2005-07-09 12:55:21 +02:00
}
2005-04-08 21:51:34 +02:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo action
\param alt Texte sur le alt de l ' image
\param numaction Determine image action
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2005-04-08 21:51:34 +02:00
*/
function img_action ( $alt = " default " , $numaction )
{
global $conf , $langs ;
if ( $alt == " default " ) {
if ( $numaction == - 1 ) $alt = $langs -> trans ( " ChangeDoNotContact " );
if ( $numaction == 0 ) $alt = $langs -> trans ( " ChangeNeverContacted " );
if ( $numaction == 1 ) $alt = $langs -> trans ( " ChangeToContact " );
2005-04-09 01:16:23 +02:00
if ( $numaction == 2 ) $alt = $langs -> trans ( " ChangeContactInProcess " );
if ( $numaction == 3 ) $alt = $langs -> trans ( " ChangeContactDone " );
2005-04-08 21:51:34 +02:00
}
2005-04-09 01:16:23 +02:00
return '<img align="absmiddle" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/stcomm' . $numaction . '.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2005-04-08 21:51:34 +02:00
}
2005-07-03 15:05:13 +02:00
/**
\brief Affiche logo fichier
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_file ( $alt = " default " )
2003-10-28 15:13:01 +01:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Show " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/file.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2003-10-28 15:13:01 +01:00
}
2007-07-30 12:51:41 +02:00
/**
\brief Affiche logo refresh
\param alt Texte sur le alt de l ' image
\return string Retourne tag img
*/
function img_refresh ( $alt = " default " )
{
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Refresh " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/refresh.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo dossier
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-12-09 10:36:32 +01:00
*/
function img_folder ( $alt = " default " )
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Dossier " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/folder.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-12-09 10:36:32 +01:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo nouveau fichier
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_file_new ( $alt = " default " )
2004-02-18 16:20:12 +01:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Show " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/filenew.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-02-18 16:20:12 +01:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo pdf
\param alt Texte sur le alt de l ' image
2007-07-13 17:45:51 +02:00
\param $size Taille de l ' icone : 3 = 16 x16px , 2 = 14 x14px
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2007-07-13 17:45:51 +02:00
function img_pdf ( $alt = " default " , $size = 3 )
2004-02-16 19:09:12 +01:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Show " );
2007-07-13 17:45:51 +02:00
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/pdf' . $size . '.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-02-16 19:09:12 +01:00
}
2007-07-14 16:38:23 +02:00
/**
\brief Affiche logo vcard
\param alt Texte sur le alt de l ' image
\return string Retourne tag img
*/
function img_vcard ( $alt = " default " )
{
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " VCard " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/vcard.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo +
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
function img_edit_add ( $alt = " default " )
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Add " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/edit_add.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-07-31 14:52:37 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo -
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-31 17:27:37 +02:00
function img_edit_remove ( $alt = " default " )
2004-07-31 14:52:37 +02:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Remove " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/edit_remove.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-07-31 14:52:37 +02:00
}
2004-07-17 14:52:41 +02:00
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo editer / modifier fiche
\param alt Texte sur le alt de l ' image
2005-10-11 23:14:34 +02:00
\param float Si il faut y mettre le style " float: right "
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2005-10-11 23:14:34 +02:00
function img_edit ( $alt = " default " , $float = 0 )
2004-06-30 16:59:08 +02:00
{
2005-10-11 23:14:34 +02:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Modify " );
$img = '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/edit.png" border="0" alt="' . $alt . '" title="' . $alt . '"' ;
if ( $float ) $img .= ' style="float: right"' ;
$img .= '>' ;
return $img ;
2004-06-30 16:59:08 +02:00
}
2004-02-16 19:09:12 +01:00
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo effacer
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_delete ( $alt = " default " )
2003-11-08 17:49:52 +01:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Delete " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/delete.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2003-11-08 17:49:52 +01:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo d<EFBFBD> sactiver
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_disable ( $alt = " default " )
2004-02-14 15:14:38 +01:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Disable " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/disable.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-02-14 15:14:38 +01:00
}
2005-12-03 21:43:33 +01:00
/**
\brief Affiche logo help avec curseur " ? "
\return string Retourne tag img
*/
2006-06-11 02:36:17 +02:00
function img_help ( $usehelpcursor = 1 , $usealttitle = 1 )
{
global $conf , $langs ;
$s = '<img ' ;
if ( $usehelpcursor ) $s .= 'style="cursor: help;" ' ;
2006-08-20 04:26:11 +02:00
$s .= 'src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/info.png" border="0"' ;
2006-08-27 00:45:32 +02:00
if ( $usealttitle ) $s .= ' alt="' . $langs -> trans ( " Info " ) . '" title="' . $langs -> trans ( " Info " ) . '"' ;
$s .= '>' ;
2006-06-11 02:36:17 +02:00
return $s ;
2005-12-03 21:43:33 +01:00
}
2006-04-29 00:54:02 +02:00
2006-03-01 11:52:26 +01:00
/**
\brief Affiche picto calendrier " ? "
\return string Retourne tag img
*/
function img_cal ()
{
global $conf , $langs ;
return '<img style="vertical-align:middle" src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/calendar.png" border="0" alt="" title="">' ;
}
2005-12-03 21:43:33 +01:00
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo info
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-10-23 01:16:32 +02:00
function img_info ( $alt = " default " )
2004-07-31 14:52:37 +02:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Informations " );
2006-04-04 02:12:45 +02:00
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/info.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-07-31 14:52:37 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo warning
\param alt Texte sur le alt de l ' image
2005-10-11 23:14:34 +02:00
\param float Si il faut afficher le style " float: right "
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2005-10-11 23:14:34 +02:00
function img_warning ( $alt = " default " , $float = 0 )
2004-07-17 14:52:41 +02:00
{
2005-10-11 23:14:34 +02:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Warning " );
$img = '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/warning.png" border="0" alt="' . $alt . '" title="' . $alt . '"' ;
if ( $float ) $img .= ' style="float: right"' ;
$img .= '>' ;
2006-11-11 16:52:17 +01:00
2005-10-11 23:14:34 +02:00
return $img ;
2004-07-17 14:52:41 +02:00
}
2005-04-30 19:27:06 +02:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo warning
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2005-04-30 19:27:06 +02:00
*/
function img_error ( $alt = " default " )
{
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Error " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/error.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo alerte
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_alerte ( $alt = " default " )
2004-07-17 14:52:41 +02:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Alert " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/alerte.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-07-17 14:52:41 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo t<EFBFBD> l<EFBFBD> phone in
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_phone_in ( $alt = " default " )
2004-05-25 16:31:18 +02:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Modify " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/call.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-05-25 16:31:18 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo t<EFBFBD> l<EFBFBD> phone out
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_phone_out ( $alt = " default " )
2004-05-25 16:31:18 +02:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Modify " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/call.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-05-25 16:31:18 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo suivant
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_next ( $alt = " default " )
2004-04-02 11:40:17 +02:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
2004-10-23 01:16:32 +02:00
if ( $alt == " default " ) {
2004-07-25 19:43:23 +02:00
$alt = $langs -> trans ( " Next " );
}
2005-01-18 22:09:16 +01:00
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/next.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-04-02 11:40:17 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo pr<EFBFBD> c<EFBFBD> dent
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2004-07-31 14:52:37 +02:00
*/
2004-07-25 19:43:23 +02:00
function img_previous ( $alt = " default " )
2004-04-02 11:40:17 +02:00
{
2005-01-18 22:09:16 +01:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Previous " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/previous.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
}
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo bas
\param alt Texte sur le alt de l ' image
\param selected Affiche version " selected " du logo
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2005-01-18 22:09:16 +01:00
*/
2005-06-11 13:38:19 +02:00
function img_down ( $alt = " default " , $selected = 1 )
2005-01-18 22:09:16 +01:00
{
2005-06-11 13:38:19 +02:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Down " );
if ( $selected ) return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/1downarrow.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
else return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/1downarrow_notselected.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2005-01-18 22:09:16 +01:00
}
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo haut
\param alt Texte sur le alt de l ' image
\param selected Affiche version " selected " du logo
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2005-01-18 22:09:16 +01:00
*/
2005-06-11 13:38:19 +02:00
function img_up ( $alt = " default " , $selected = 1 )
2005-01-18 22:09:16 +01:00
{
2005-06-11 13:38:19 +02:00
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Up " );
if ( $selected ) return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/1uparrow.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
else return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/1uparrow_notselected.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
2004-04-02 11:40:17 +02:00
}
2006-01-08 18:08:20 +01:00
/**
\brief Affiche logo gauche
\param alt Texte sur le alt de l ' image
\param selected Affiche version " selected " du logo
\return string Retourne tag img
*/
function img_left ( $alt = " default " , $selected = 1 )
{
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Left " );
if ( $selected ) return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/1leftarrow.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
else return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/1leftarrow_notselected.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
}
/**
\brief Affiche logo droite
\param alt Texte sur le alt de l ' image
\param selected Affiche version " selected " du logo
\return string Retourne tag img
*/
function img_right ( $alt = " default " , $selected = 1 )
{
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Right " );
if ( $selected ) return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/1rightarrow.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
else return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/1rightarrow_notselected.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
}
2005-03-06 16:39:32 +01:00
/**
2005-07-03 15:05:13 +02:00
\brief Affiche logo tick
\param alt Texte sur le alt de l ' image
2005-07-10 21:54:48 +02:00
\return string Retourne tag img
2005-03-06 16:39:32 +01:00
*/
function img_tick ( $alt = " default " )
{
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Active " );
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/tick.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
}
2005-08-30 16:15:28 +02:00
/**
\brief Affiche le logo tick si allow
\param allow Authorise ou non
\return string Retourne tag img
*/
function img_allow ( $allow )
{
global $conf , $langs ;
if ( $alt == " default " ) $alt = $langs -> trans ( " Active " );
if ( $allow == 1 )
{
return '<img src="' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/tick.png" border="0" alt="' . $alt . '" title="' . $alt . '">' ;
}
else
{
return " - " ;
}
}
2005-07-03 15:05:13 +02:00
2006-06-25 19:15:07 +02:00
/**
\brief Affiche info admin
\param text Texte info
*/
function info_admin ( $texte )
{
global $conf , $langs ;
$s = '<div class="info">' ;
$s .= img_picto ( $langs -> trans ( " InfoAdmin " ), 'star' );
$s .= ' ' ;
$s .= $texte ;
$s .= '</div>' ;
return $s ;
}
2004-12-28 16:36:40 +01:00
/**
2006-09-02 03:17:50 +02:00
\brief Affiche formulaire de login PEAR
\remarks Il faut changer le code html dans cette fonction pour changer le design
2004-07-16 00:17:39 +02:00
*/
2006-09-02 03:17:50 +02:00
function dol_loginfunction ( $notused , $pearstatus )
2003-08-30 12:48:01 +02:00
{
2007-08-08 02:51:26 +02:00
global $langs , $conf , $mysoc ;
$langs -> load ( " main " );
$langs -> load ( " other " );
2006-11-11 16:52:17 +01:00
2007-08-08 02:51:26 +02:00
$conf -> css = " theme/ " . $conf -> theme . " / " . $conf -> theme . " .css " ;
// Si feuille de style en php existe
if ( file_exists ( DOL_DOCUMENT_ROOT . '/' . $conf -> css . " .php " )) $conf -> css .= " .php " ;
2006-11-11 16:52:17 +01:00
2007-08-08 02:51:26 +02:00
// Ce DTD est KO car inhibe document.body.scrollTop
//print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
// Ce DTD est OK
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' . " \n " ;
2006-07-29 20:27:36 +02:00
2007-06-02 03:53:54 +02:00
// En tete html
2007-08-08 02:51:26 +02:00
print " <html> \n " ;
print " <head> \n " ;
print '<meta name="robots" content="noindex,nofollow">' . " \n " ; // Evite indexation par robots
2007-05-29 20:17:39 +02:00
print " <title>Dolibarr Authentification</title> \n " ;
2006-11-11 16:52:17 +01:00
2007-08-08 02:51:26 +02:00
print '<link rel="stylesheet" type="text/css" href="' . DOL_URL_ROOT . '/' . $conf -> css . '">' . " \n " ;
print '<style type="text/css">' . " \n " ;
print '<!--' . " \n " ;
print '#login {' ;
print ' margin-top: 70px;' ;
print ' margin-bottom: 30px;' ;
print ' text-align: center;' ;
print ' font: 12px arial,helvetica;' ;
print '}' . " \n " ;
print '#login table {' ;
print ' border: 1px solid #C0C0C0;' ;
if ( file_exists ( DOL_DOCUMENT_ROOT . '/theme/' . $conf -> theme . '/img/login_background.png' ))
{
print 'background: #F0F0F0 url(' . DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/login_background.png) repeat-x;' ;
}
else
{
print 'background: #F0F0F0 url(' . DOL_URL_ROOT . '/theme/login_background.png) repeat-x;' ;
}
print 'font-size: 12px;' ;
print '}' . " \n " ;
print '-->' . " \n " ;
print '</style>' . " \n " ;
print '<script language="javascript" type="text/javascript">' . " \n " ;
print " function donnefocus() { \n " ;
print " document.getElementsByTagName('INPUT')[0].focus(); " ;
print " } \n " ;
print '</script>' . " \n " ;
print '</head>' . " \n " ;
// Body
2007-06-02 03:53:54 +02:00
print '<body class="body" onload="donnefocus();">' ;
2006-09-02 03:17:50 +02:00
2007-06-02 03:53:54 +02:00
// Start Form
2007-08-08 02:51:26 +02:00
print '<form id="login" name="login" method="post" action="' ;
print $_SERVER [ 'PHP_SELF' ];
print $_SERVER [ " QUERY_STRING " ] ? '?' . $_SERVER [ " QUERY_STRING " ] : '' ;
print '">' ;
2006-11-11 16:52:17 +01:00
2007-06-02 03:53:54 +02:00
// Table 1
2007-08-09 20:22:39 +02:00
print '<table cellpadding="0" cellspacing="0" border="0" align="center" width="450">' ;
2007-08-08 02:51:26 +02:00
if ( file_exists ( DOL_DOCUMENT_ROOT . '/logo.png' ))
{
// Cas qui ne devrait pas arriver (pour compatibilit<69> )
print '<tr><td colspan="3" style="text-align:center;">' ;
print '<img src="/logo.png"></td></tr>' ;
}
else
{
print '<tr class="vmenu"><td align="center">Dolibarr ' . DOL_VERSION . '</td></tr>' ;
}
print '</table>' ;
2007-06-02 03:53:54 +02:00
print '<br>' ;
2006-11-11 16:52:17 +01:00
2007-06-02 03:53:54 +02:00
// Table 2
2007-08-09 20:22:39 +02:00
print '<table cellpadding="2" align="center" width="450">' ;
2005-07-02 14:16:33 +02:00
2007-06-02 03:53:54 +02:00
print '<tr><td colspan="3"> </td></tr>' ;
2005-07-02 14:16:33 +02:00
2007-06-02 03:53:54 +02:00
print '<tr><td align="left"><br> <b>' . $langs -> trans ( " Login " ) . '</b> </td>' ;
print '<td><input name="username" class="flat" size="15" maxlength="25" value="" tabindex="1" /></td>' ;
2005-07-02 14:16:33 +02:00
2007-08-08 02:51:26 +02:00
if ( $conf -> main_authentication ) $title .= $langs -> trans ( " AuthenticationMode " ) . ': ' . $conf -> main_authentication ;
// Affiche logo du theme si existe, sinon logo commun
$urllogo = DOL_URL_ROOT . '/theme/login_logo.png' ;
2007-08-09 20:22:39 +02:00
if ( is_readable ( $conf -> societe -> dir_logos . '/thumbs/' . $mysoc -> logo_small ))
2007-08-08 02:51:26 +02:00
{
2007-08-09 20:22:39 +02:00
$urllogo = DOL_URL_ROOT . '/viewimage.php?modulepart=companylogo&file=' . urlencode ( $mysoc -> logo_small );
2007-08-08 02:51:26 +02:00
}
elseif ( is_readable ( DOL_DOCUMENT_ROOT . '/theme/' . $conf -> theme . '/img/login_logo.png' ))
{
$urllogo = DOL_URL_ROOT . '/theme/' . $conf -> theme . '/img/login_logo.png' ;
}
2007-08-09 20:22:39 +02:00
print '<td rowspan="2"><img title="' . $title . '" src="' . $urllogo . '"></td>' ;
2005-07-02 14:16:33 +02:00
2007-08-08 02:51:26 +02:00
print '</tr>' ;
2005-07-02 14:16:33 +02:00
2007-08-08 02:51:26 +02:00
print '<tr><td align="left" valign="top"> <b>' . $langs -> trans ( " Password " ) . '</b> </td>' ;
print '<td valign="top" nowrap="nowrap"><input name="password" class="flat" type="password" size="15" maxlength="30" tabindex="2">' ;
2007-06-02 03:53:54 +02:00
print '</td></tr>' ;
2005-07-02 14:16:33 +02:00
2007-08-08 02:51:26 +02:00
print '<tr><td colspan="3" style="text-align:center;"><br>' ;
print '<input type="submit" class="button" value=" ' . $langs -> trans ( " Connection " ) . ' " tabindex="4" />' ;
print '</td></tr>' ;
2007-05-29 20:17:39 +02:00
2007-06-02 03:53:54 +02:00
if ( ! $conf -> global -> MAIN_SECURITY_DISABLEFORGETPASSLINK )
{
print '<tr><td colspan="3" align="center"><a style="color: #888888; font-size: 10px" href="' . DOL_URL_ROOT . '/user/passwordforgotten.php">(' . $langs -> trans ( " PasswordForgotten " ) . ')</a></td></tr>' ;
}
2007-05-29 20:17:39 +02:00
2007-08-08 02:51:26 +02:00
print '</table>' ;
print '<input type="hidden" name="loginfunction" value="loginfunction" />' ;
2005-07-02 14:16:33 +02:00
2007-08-08 02:51:26 +02:00
print '</form>' ;
2005-09-06 15:56:40 +02:00
2006-09-02 03:17:50 +02:00
// Message
2007-08-08 02:51:26 +02:00
if ( $_SESSION [ " loginmesg " ] || ! empty ( $pearstatus ))
{
print '<center><table width="60%"><tr><td align="center" class="small"><div class="error">' ;
2006-09-02 03:17:50 +02:00
if ( $pearstatus == AUTH_EXPIRED ) print " <i>Your session expired. Please login again!</i> \n " ;
elseif ( $pearstatus == AUTH_IDLED ) print " <i>You have been idle for too long. Please login again!</i> \n " ;
elseif ( $pearstatus == AUTH_WRONG_LOGIN ) print $langs -> trans ( " ErrorBadLoginPassword " );
elseif ( $_SESSION [ " loginmesg " ])
{
print $_SESSION [ " loginmesg " ];
$_SESSION [ " loginmesg " ] = " " ;
}
print '</div></td></tr></table></center>' ;
}
2007-06-02 03:53:54 +02:00
if ( $conf -> global -> MAIN_HOME )
2007-04-30 12:53:58 +02:00
{
2007-08-08 02:51:26 +02:00
print '<center><table cellpadding="0" cellspacing="0" border="0" align="center" width="750"><tr><td align="center">' ;
print nl2br ( $conf -> global -> MAIN_HOME );
print '</td></tr></table></center><br>' ;
2007-04-30 12:53:58 +02:00
}
2007-08-08 02:51:26 +02:00
2007-06-02 03:53:54 +02:00
// Fin entete html
print " \n </body> \n </html> " ;
2003-08-30 12:48:01 +02:00
}
2004-07-16 00:17:39 +02:00
2007-06-07 14:55:38 +02:00
/*
* \brief V<EFBFBD> rifie les droits de l ' utilisateur
* \param user Utilisateur courant
* \param module Module <EFBFBD> v<EFBFBD> rifier
* \param objectid ID du document
* \param dbtable Table de la base correspondant au module ( optionnel )
2007-06-08 10:38:02 +02:00
* \param list D<EFBFBD> fini si la page sert de liste et donc ne fonctionne pas avec un id
2007-06-07 14:55:38 +02:00
*/
2007-06-07 17:59:19 +02:00
function restrictedArea ( $user , $modulename , $objectid = '' , $dbtablename = '' , $list = 0 )
2007-06-07 14:55:38 +02:00
{
global $db ;
2007-06-21 19:28:38 +02:00
if ( ! $modulename )
{
$modulename = 'societe' ;
$list = 1 ;
}
2007-06-07 14:55:38 +02:00
$user -> getrights ( $modulename );
2007-06-07 15:50:18 +02:00
$user -> getrights ( 'commercial' );
2007-06-07 17:59:19 +02:00
2007-06-07 14:55:38 +02:00
$socid = 0 ;
2007-06-08 10:38:02 +02:00
$nocreate = 0 ;
2007-06-07 14:55:38 +02:00
//si dbtable non d<> fini, m<> me nom que le module
2007-06-21 19:28:38 +02:00
if ( ! $dbtablename ) $dbtablename = $modulename ;
2007-06-07 14:55:38 +02:00
if ( ! $user -> rights -> $modulename -> lire )
{
accessforbidden ();
2007-06-07 15:50:18 +02:00
}
else if ( ! $user -> rights -> $modulename -> creer )
{
2007-06-08 09:57:14 +02:00
$nocreate = 1 ;
2007-06-07 15:50:18 +02:00
if ( $_GET [ " action " ] == 'create' || $_POST [ " action " ] == 'create' )
{
accessforbidden ();
}
2007-06-07 14:55:38 +02:00
}
if ( $user -> societe_id > 0 )
{
2007-06-07 15:50:18 +02:00
$_GET [ " action " ] = '' ;
$_POST [ " action " ] = '' ;
2007-06-07 16:01:35 +02:00
$socid = $user -> societe_id ;
2007-06-21 19:28:38 +02:00
if ( ! $objectid ) $objectid = $socid ;
if ( $modulename == 'societe' && $socid <> $objectid ) accessforbidden ();
2007-06-07 14:55:38 +02:00
}
2007-06-07 17:59:19 +02:00
2007-06-07 15:50:18 +02:00
if ( $objectid )
2007-06-07 14:55:38 +02:00
{
2007-06-07 16:01:35 +02:00
if ( $modulename == 'societe' && ! $user -> rights -> commercial -> client -> voir && ! $socid > 0 )
2007-06-07 15:50:18 +02:00
{
$sql = " SELECT sc.fk_soc " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
$sql .= " WHERE sc.fk_soc = " . $objectid . " AND sc.fk_user = " . $user -> id ;
}
2007-06-07 17:59:19 +02:00
else if ( ! $user -> rights -> commercial -> client -> voir || $socid > 0 )
2007-06-07 14:55:38 +02:00
{
2007-06-07 15:50:18 +02:00
$sql = " SELECT sc.fk_soc, dbt.fk_soc " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_commerciaux as sc, " . MAIN_DB_PREFIX . $dbtablename . " as dbt " ;
$sql .= " WHERE dbt.rowid = " . $objectid ;
2007-06-07 16:01:35 +02:00
if ( ! $user -> rights -> commercial -> client -> voir && ! $socid > 0 )
2007-06-07 15:50:18 +02:00
{
$sql .= " AND sc.fk_soc = dbt.fk_soc AND sc.fk_user = " . $user -> id ;
}
2007-06-07 16:01:35 +02:00
if ( $socid > 0 ) $sql .= " AND dbt.fk_soc = " . $socid ;
2007-06-07 14:55:38 +02:00
}
2007-06-12 00:51:47 +02:00
//print $sql;
2007-06-08 10:54:00 +02:00
if ( $sql && $db -> query ( $sql ))
2007-06-07 14:55:38 +02:00
{
if ( $db -> num_rows () == 0 )
{
accessforbidden ();
}
}
}
2007-06-12 00:51:47 +02:00
else if (( ! $objectid && $list == 0 ) && $nocreate == 1 )
2007-06-07 17:59:19 +02:00
{
accessforbidden ();
}
2007-06-08 10:38:02 +02:00
return $objectid ;
2007-06-07 14:55:38 +02:00
}
2005-01-02 14:57:45 +01:00
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Affiche message erreur de type acces interdit et arrete le programme
2006-09-02 03:17:50 +02:00
\param message Force error message
2007-01-31 18:52:54 +01:00
\param printheader Affiche avant le header
2005-01-02 14:57:45 +01:00
\remarks L ' appel a cette fonction termine le code .
2004-07-16 00:17:39 +02:00
*/
2007-01-31 18:52:54 +01:00
function accessforbidden ( $message = '' , $printheader = 1 )
2003-03-23 16:22:32 +01:00
{
2005-01-02 14:57:45 +01:00
global $user , $langs ;
$langs -> load ( " other " );
2006-11-11 16:52:17 +01:00
2007-01-31 18:52:54 +01:00
if ( $printheader ) llxHeader ();
2006-09-02 03:17:50 +02:00
print '<div class="error">' ;
if ( ! $message ) print $langs -> trans ( " ErrorForbidden " );
else print $message ;
print '</div>' ;
2005-01-02 14:57:45 +01:00
print '<br>' ;
2005-03-26 14:40:07 +01:00
if ( $user -> login )
{
print $langs -> trans ( " CurrentLogin " ) . ': <font class="error">' . $user -> login . '</font><br>' ;
2005-01-02 14:57:45 +01:00
print $langs -> trans ( " ErrorForbidden2 " , $langs -> trans ( " Home " ), $langs -> trans ( " Users " ));
}
2005-03-26 14:40:07 +01:00
elseif ( ! empty ( $_SERVER [ " REMOTE_USER " ]))
{
print $langs -> trans ( " CurrentLogin " ) . ': <font class="error">' . $_SERVER [ " REMOTE_USER " ] . " </font><br> " ;
print $langs -> trans ( " ErrorForbidden2 " , $langs -> trans ( " Home " ), $langs -> trans ( " Users " ));
}
else
{
2005-01-02 14:57:45 +01:00
print $langs -> trans ( " ErrorForbidden3 " );
}
2003-03-23 16:22:32 +01:00
llxFooter ();
exit ( 0 );
}
2005-01-02 14:57:45 +01:00
2004-12-28 16:36:40 +01:00
/**
2005-08-16 15:14:13 +02:00
\brief Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remont<EFBFBD> e des bugs .
2005-01-02 14:57:45 +01:00
On doit appeler cette fonction quand une erreur technique bloquante est rencontr<EFBFBD> e .
2005-08-16 15:14:13 +02:00
Toutefois , il faut essayer de ne l 'appeler qu' au sein de pages php , les classes devant
2005-01-02 14:57:45 +01:00
renvoyer leur erreur par l ' interm<EFBFBD> diaire de leur propri<EFBFBD> t<EFBFBD> " error " .
\param db Handler de base utilis<EFBFBD>
2007-02-27 21:40:19 +01:00
\param error Chaine erreur ou tableau de chaines erreur compl<EFBFBD> mentaires <EFBFBD> afficher
2004-07-24 21:11:01 +02:00
*/
2007-02-27 21:40:19 +01:00
function dolibarr_print_error ( $db = '' , $error = '' )
2004-07-24 21:11:01 +02:00
{
2007-05-25 22:43:47 +02:00
global $conf , $langs , $argv ;
2005-04-30 03:47:42 +02:00
$syslog = '' ;
2006-11-11 16:52:17 +01:00
2005-08-11 21:13:08 +02:00
// Si erreur intervenue avant chargement langue
2006-07-02 00:49:54 +02:00
if ( ! $langs )
{
2005-04-30 03:47:42 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /translate.class.php " );
2007-05-25 22:02:23 +02:00
$langs = new Translate ( DOL_DOCUMENT_ROOT . " /langs " , $conf );
2005-04-30 03:47:42 +02:00
}
2006-07-02 00:49:54 +02:00
$langs -> load ( " main " );
2006-11-11 16:52:17 +01:00
2005-04-30 03:47:42 +02:00
if ( $_SERVER [ 'DOCUMENT_ROOT' ]) // Mode web
{
print $langs -> trans ( " DolibarrHasDetectedError " ) . " .<br> \n " ;
print $langs -> trans ( " InformationToHelpDiagnose " ) . " :<br><br> \n " ;
2006-11-11 16:52:17 +01:00
2005-01-02 14:57:45 +01:00
print " <b> " . $langs -> trans ( " Server " ) . " :</b> " . $_SERVER [ " SERVER_SOFTWARE " ] . " <br> \n " ;;
2006-02-21 01:51:52 +01:00
print " <b> " . $langs -> trans ( " Dolibarr " ) . " :</b> " . DOL_VERSION . " <br> \n " ;;
2005-04-30 03:47:42 +02:00
print " <b> " . $langs -> trans ( " RequestedUrl " ) . " :</b> " . $_SERVER [ " REQUEST_URI " ] . " <br> \n " ;;
2004-09-22 21:20:19 +02:00
print " <b>QUERY_STRING:</b> " . $_SERVER [ " QUERY_STRING " ] . " <br> \n " ;;
2005-04-30 03:47:42 +02:00
print " <b> " . $langs -> trans ( " Referer " ) . " :</b> " . $_SERVER [ " HTTP_REFERER " ] . " <br> \n " ;;
2004-09-22 21:20:19 +02:00
$syslog .= " url= " . $_SERVER [ " REQUEST_URI " ];
$syslog .= " , query_string= " . $_SERVER [ " QUERY_STRING " ];
}
2005-04-30 03:47:42 +02:00
else // Mode CLI
2005-01-02 14:57:45 +01:00
{
2006-11-11 16:52:17 +01:00
2007-02-11 18:05:36 +01:00
print $langs -> transnoentities ( " ErrorInternalErrorDetected " ) . " : " . $argv [ 0 ] . " \n " ;
2005-04-30 03:47:42 +02:00
$syslog .= " pid= " . getmypid ();
2004-09-22 21:20:19 +02:00
}
2006-11-11 16:52:17 +01:00
2006-04-23 16:01:42 +02:00
if ( is_object ( $db ))
2005-08-11 21:13:08 +02:00
{
2005-04-30 03:47:42 +02:00
if ( $_SERVER [ 'DOCUMENT_ROOT' ]) // Mode web
{
print " <br> \n " ;
print " <b> " . $langs -> trans ( " DatabaseTypeManager " ) . " :</b> " . $db -> type . " <br> \n " ;
2006-06-17 16:13:49 +02:00
print " <b> " . $langs -> trans ( " RequestLastAccessInError " ) . " :</b> " . ( $db -> lastqueryerror () ? $db -> lastqueryerror () : $langs -> trans ( " ErrorNoRequestInError " )) . " <br> \n " ;
2005-04-30 03:47:42 +02:00
print " <b> " . $langs -> trans ( " ReturnCodeLastAccess " ) . " :</b> " . $db -> errno () . " <br> \n " ;
print " <b> " . $langs -> trans ( " InformationLastAccess " ) . " :</b> " . $db -> error () . " <br> \n " ;
}
else // Mode CLI
{
2007-02-11 18:05:36 +01:00
print $langs -> transnoentities ( " DatabaseTypeManager " ) . " : \n " . $db -> type . " \n " ;
print $langs -> transnoentities ( " RequestLastAccessInError " ) . " : \n " . ( $db -> lastqueryerror () ? $db -> lastqueryerror () : $langs -> trans ( " ErrorNoRequestInError " )) . " \n " ;
print $langs -> transnoentities ( " ReturnCodeLastAccess " ) . " : \n " . $db -> errno () . " \n " ;
print $langs -> transnoentities ( " InformationLastAccess " ) . " : \n " . $db -> error () . " \n " ;
2006-11-11 16:52:17 +01:00
2005-04-30 03:47:42 +02:00
}
$syslog .= " , sql= " . $db -> lastquery ();
$syslog .= " , db_error= " . $db -> error ();
2005-01-02 14:57:45 +01:00
}
2006-11-11 16:52:17 +01:00
2007-02-27 21:40:19 +01:00
if ( $error )
2006-11-26 08:00:14 +01:00
{
2007-02-27 21:40:19 +01:00
if ( is_array ( $error )) $errors = $error ;
else $errors = array ( $error );
foreach ( $errors as $msg )
{
if ( $_SERVER [ 'DOCUMENT_ROOT' ]) // Mode web
{
print " <b> " . $langs -> trans ( " Message " ) . " :</b> " . $msg . " <br> \n " ;
}
else // Mode CLI
{
print $langs -> transnoentities ( " Message " ) . " : \n " . $msg . " \n " ;
}
$syslog .= " , msg= " . $msg ;
}
}
2006-11-11 16:52:17 +01:00
2005-04-30 03:47:42 +02:00
dolibarr_syslog ( " Error $syslog " );
2004-07-24 21:11:01 +02:00
}
2004-12-04 17:33:12 +01:00
2004-12-28 16:36:40 +01:00
/**
2006-05-08 19:22:53 +02:00
\brief Deplacer les fichiers telecharg<EFBFBD> s , apres quelques controles divers
2004-07-16 00:17:39 +02:00
\param src_file fichier source
\param dest_file fichier de destination
2007-04-12 22:25:12 +02:00
\return int true = Deplacement OK , false = Pas de deplacement ou KO
2004-07-16 00:17:39 +02:00
*/
2003-09-12 18:45:27 +02:00
function doliMoveFileUpload ( $src_file , $dest_file )
{
2006-05-08 19:22:53 +02:00
$file_name = $dest_file ;
2006-11-11 16:52:17 +01:00
2007-04-12 22:25:12 +02:00
// Security:
// On renomme les fichiers avec extention executable car si on a mis le rep
2006-10-30 00:18:52 +01:00
// documents dans un rep de la racine web (pas bien), cela permet d'executer
// du code a la demande.
2007-07-30 11:01:27 +02:00
if ( eregi ( '\.htm|\.html|\.php|\.pl|\.cgi$' , $file_name ))
2006-05-08 19:22:53 +02:00
{
2006-10-30 00:18:52 +01:00
$file_name .= '.txt' ;
2006-05-08 19:22:53 +02:00
}
2006-11-11 16:52:17 +01:00
2007-04-12 22:25:12 +02:00
// Security:
// On interdit les remont<6E> es de repertoire ainsi que les pipe dans
// les noms de fichiers.
if ( eregi ( '\.\.' , $src_file ) || eregi ( '[<>|]' , $src_file ))
{
dolibarr_syslog ( " Refused to deliver file " . $src_file );
return false ;
}
// Security:
// On interdit les remont<6E> es de repertoire ainsi que les pipe dans
// les noms de fichiers.
if ( eregi ( '\.\.' , $dest_file ) || eregi ( '[<>|]' , $dest_file ))
{
dolibarr_syslog ( " Refused to deliver file " . $dest_file );
return false ;
}
2006-05-08 19:22:53 +02:00
return move_uploaded_file ( $src_file , $file_name );
2003-09-12 18:45:27 +02:00
}
2004-07-16 00:17:39 +02:00
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Transcodage de francs en euros
2004-07-16 00:17:39 +02:00
\param zonein zone de depart
\param devise type de devise
2004-08-07 16:41:29 +02:00
\return r resultat transcod<EFBFBD>
2004-07-16 00:17:39 +02:00
*/
2002-12-17 21:57:07 +01:00
function transcoS2L ( $zonein , $devise )
2004-07-16 00:17:39 +02:00
{
2002-12-17 21:57:07 +01:00
// Open source offert par <A HREF="mailto:alainfloch@free.fr?subject=chif2let">alainfloch@free.fr</A> 28/10/2001, sans garantie.
// d<> but de la fonction de transcodification de somme en toutes lettres
2004-07-16 00:17:39 +02:00
/* $zonein = " 123,56 " ;
2002-12-17 21:57:07 +01:00
* $devise = " E " ; // pr<70> ciser F si francs , sinon ce sera de l'euro
* $r = transcoS2L ( $zonein , $devise ); // appeler la fonction
* echo " r<EFBFBD> sultat vaut $r <br> " ;
* $zonelettresM = strtoupper ( $r ); // si vous voulez la m<> me zone mais tout en majuscules
* echo " r<EFBFBD> sultat en Majuscules vaut $zonelettresM <br> " ;
* $zonein = " 1,01 " ;
* $r = transcoS2L ( $zonein , $devise );
* echo " r<EFBFBD> sultat vaut $r <br> " ;
*/
if ( $devise == " F " )
2002-12-17 21:57:32 +01:00
{
$unite_singulier = " franc " ;
$unite_pluriel = " francs " ;
$cent_singulier = " centime " ;
}
2002-12-17 21:57:07 +01:00
else
{
$unite_singulier = " euro " ;
$unite_pluriel = " euros " ;
$cent_singulier = " centime " ;
}
2004-07-16 00:17:39 +02:00
2002-12-17 21:57:07 +01:00
$arr1_99 = array ( " z<EFBFBD> ro " , " un " , " deux " , " trois " ,
" quatre " , " cinq " , " six " , " sept " ,
" huit " , " neuf " , " dix " , " onze " , " douze " ,
" treize " , " quatorze " , " quinze " , " seize " ,
" dix-sept " , " dix-huit " , " dix-neuf " , " vingt " );
$arr1_99 [ 30 ] = " trente " ;
$arr1_99 [ 40 ] = " quarante " ;
$arr1_99 [ 50 ] = " cinquante " ;
$arr1_99 [ 60 ] = " soixante " ;
$arr1_99 [ 70 ] = " soixante-dix " ;
$arr1_99 [ 71 ] = " soixante et onze " ;
$arr1_99 [ 80 ] = " quatre-vingts " ;
$i = 22 ;
while ( $i < 63 ) { // initialise la table
$arr1_99 [ $i - 1 ] = $arr1_99 [ $i - 2 ] . " et un " ;
$j = 0 ;
while ( $j < 8 ) {
$k = $i + $j ;
$arr1_99 [ $k ] = $arr1_99 [ $i - 2 ] . $arr1_99 [ $j + 2 ];
$j ++ ;
}
$i = $i + 10 ;
} // fin initialise la table
$i = 12 ;
while ( $i < 20 ) { // initialise la table (suite)
$j = 60 + $i ;
$arr1_99 [ $j ] = " soixante- " . $arr1_99 [ $i ];
$i ++ ;
} // fin initialise la table (suite)
$i = 1 ;
while ( $i < 20 ) { // initialise la table (fin)
$j = 80 + $i ;
$arr1_99 [ $j ] = " quatre-vingt- " . $arr1_99 [ $i ];
$i ++ ;
} // fin initialise la table (fin)
2003-02-10 18:25:06 +01:00
// echo "Pour une valeur en entr<74> e = $zonein<br>"; //pour ceux qui ne croient que ce qu'ils voient !
2006-11-11 16:52:17 +01:00
// quelques petits controles s'imposent !!
2002-12-17 21:57:07 +01:00
$valid = " [a-zA-Z \ & \ <EFBFBD> \" \ ' \ ( \ - \ <EFBFBD> \ _ \ <EFBFBD> \ <EFBFBD> \ ) \ = \ ; \ : \ ! \ * \$ \ ^ \ < \ >] " ;
if ( ereg ( $valid , $zonein ))
{
$r = " <b>la cha<68> ne " . $zonein . " n'est pas valide</b> " ;
return ( $r );
}
$zone = explode ( " " , $zonein ); // supprimer les blancs s<> parateurs
$zonein = implode ( " " , $zone ); // reconcat<61> ne la zone input
$zone = explode ( " . " , $zonein ); // supprimer les points s<> parateurs
$zonein = implode ( " " , $zone ); // reconcat<61> ne la zone input, <20> a c'est fort ! merci PHP
$virg = strpos ( $zonein , " , " , 1 ); // <20> la poursuite de la virgule
$i = strlen ( $zonein ); // et de la longueur de la zone input
if ( $virg == 0 ) { // ya pas de virgule
if ( $i > 7 )
{
$r = " <b>la cha<68> ne " . $zonein . " est trop longue (maxi = 9 millions)</b> " ;
return ( $r );
}
$deb = 7 - $i ;
$zoneanaly = substr ( $zonechiffres , 0 , $deb ) . $zonein . " ,00 " ;
}
else
{ //ya une virgule
$ti = explode ( " , " , $zonein ); // mettre de c<> t<EFBFBD> ce qu'il y a devant la virgule
$i = strlen ( $ti [ 0 ]); // en controler la longueur
$zonechiffres = " 0000000,00 " ;
if ( $i > 7 )
{
$r = " <b>la cha<68> ne " . $zonein . " est trop longue (maxi = 9 millions,00)</b> " ;
return ( $r );
}
$deb = 7 - $i ;
$zoneanaly = substr ( $zonechiffres , 0 , $deb ) . $zonein ;
}
$M = substr ( $zoneanaly , 0 , 1 );
if ( $M != 0 )
{ // qui veut gagner des millions
$r = $arr1_99 [ $M ] . " million " ;
if ( $M == 1 ) $r = $r . " " ;
else $r = $r . " s " ;
if ( substr ( $zoneanaly , 1 , 6 ) == 0 )
{
if ( $devise == 'F' ) $r = $r . " de " ;
else $r = $r . " d' " ;
}
}
$CM = substr ( $zoneanaly , 1 , 1 );
if ( $CM == 1 )
{ // qui veut gagner des centaines de mille
$r = $r . " cent " ;
}
else
{ // ya des centaines de mille
if ( $CM > 1 )
{
$r = $r . $arr1_99 [ $CM ] . " cent " ;
}
} // fin du else ya des centaines de mille
$MM = substr ( $zoneanaly , 2 , 2 );
if ( substr ( $zoneanaly , 2 , 1 ) == 0 ){ $MM = substr ( $zoneanaly , 3 , 1 );} // enlever le z<> ro des milliers cause indexation
if ( $MM == 0 && $CM > 0 )
{
$r = $r . " mille " ;
}
if ( $MM != 0 )
{
if ( $MM == 80 )
{
$r = $r . " quatre-vingt mille " ;
}
else
{
if ( $MM > 1 )
{
$r = $r . $arr1_99 [ $MM ] . " mille " ;
}
else
{
if ( $CM == 0 ) $r = $r . " mille " ;
else
{
$r = $r . $arr1_99 [ $MM ] . " mille " ;
}
}
}
}
$C2 = substr ( $zoneanaly , 5 , 2 );
if ( substr ( $zoneanaly , 5 , 1 ) == 0 ){ $C2 = substr ( $zoneanaly , 6 , 1 );} // enlever le z<> ro des centaines cause indexation
$C1 = substr ( $zoneanaly , 4 , 1 );
if ( $C2 == 0 && $C1 > 1 )
{
$r = $r . $arr1_99 [ $C1 ] . " cents " ;
}
else
{
if ( $C1 == 1 ) $r = $r . " cent " ;
else
{
if ( $C1 > 1 ) $r = $r . $arr1_99 [ $C1 ] . " cent " ;
}
}
2004-07-16 00:17:39 +02:00
if ( $C2 != 0 )
2002-12-17 21:57:07 +01:00
{
$r = $r . $arr1_99 [ $C2 ];
}
if ( $virg != 0 )
{
if ( $ti [ 0 ] > 1 ) $r = $r . $unite_pluriel ; else $r = " un " . $unite_singulier ;
}
else
{
if ( $zonein > 1 ) $r = $r . $unite_pluriel ; else $r = " un " . $unite_singulier ;
}
$UN = substr ( $zoneanaly , 8 , 2 );
if ( $UN != " 00 " )
{
$cts = $UN ;
if ( substr ( $UN , 0 , 1 ) == 0 ){ $cts = substr ( $UN , 1 , 1 );} // enlever le z<> ro des centimes cause indexation
$r = $r . " et " . $arr1_99 [ $cts ] . $cent_singulier ;
if ( $UN > 1 ) $r = $r . " s " ; // accorde au pluriel
}
$r1 = ltrim ( $r ); // enleve quelques blancs possibles en d<> but de zone
$r = ucfirst ( $r1 ); // met le 1er caract<63> re en Majuscule, c'est + zoli
return ( $r ); // retourne le r<> sultat
} // fin fonction transcoS2L
2004-07-25 19:43:23 +02:00
2004-12-28 16:36:40 +01:00
/**
\brief Affichage de la ligne de titre d ' un tabelau
2005-06-11 13:38:19 +02:00
\param name libelle champ
\param file url pour clic sur tri
\param field champ de tri
2004-12-28 16:36:40 +01:00
\param begin ( " " par defaut )
\param options ( " " par defaut )
2005-06-11 13:38:19 +02:00
\param td options de l ' attribut td ( " " par defaut )
2004-12-28 16:36:40 +01:00
\param sortfield nom du champ sur lequel est effectu<EFBFBD> le tri du tableau
2005-06-11 13:38:19 +02:00
\param sortorder ordre du tri
2004-07-16 00:17:39 +02:00
*/
2005-06-11 13:38:19 +02:00
function print_liste_field_titre ( $name , $file , $field , $begin = " " , $options = " " , $td = " " , $sortfield = " " , $sortorder = " " )
2004-10-31 14:34:08 +01:00
{
global $conf ;
2005-01-08 23:44:50 +01:00
// Le champ de tri est mis en <20> vidence.
// Exemple si (sortfield,field)=("nom","xxx.nom") ou (sortfield,field)=("nom","nom")
if ( $sortfield == $field || $sortfield == ereg_replace ( " ^[^ \ .]+ \ . " , " " , $field ))
2003-06-21 16:56:42 +02:00
{
2005-05-07 16:59:43 +02:00
print '<td class="liste_titre_sel" ' . $td . '>' ;
2003-06-21 16:56:42 +02:00
}
2004-10-31 14:34:08 +01:00
else
2003-06-21 16:56:42 +02:00
{
2005-05-07 16:59:43 +02:00
print '<td class="liste_titre" ' . $td . '>' ;
2003-06-21 16:56:42 +02:00
}
2004-10-31 14:34:08 +01:00
print $name . " " ;
2005-06-11 13:38:19 +02:00
if ( ! $sortorder )
{
print '<a href="' . $file . '?sortfield=' . $field . '&sortorder=asc&begin=' . $begin . $options . '">' . img_down ( " A-Z " , 1 ) . '</a>' ;
print '<a href="' . $file . '?sortfield=' . $field . '&sortorder=desc&begin=' . $begin . $options . '">' . img_up ( " Z-A " , 1 ) . '</a>' ;
}
else
{
if ( $field != $sortfield ) {
print '<a href="' . $file . '?sortfield=' . $field . '&sortorder=asc&begin=' . $begin . $options . '">' . img_down ( " A-Z " , 1 ) . '</a>' ;
print '<a href="' . $file . '?sortfield=' . $field . '&sortorder=desc&begin=' . $begin . $options . '">' . img_up ( " Z-A " , 1 ) . '</a>' ;
}
else {
if ( $sortorder == 'DESC' ) {
print '<a href="' . $file . '?sortfield=' . $field . '&sortorder=asc&begin=' . $begin . $options . '">' . img_down ( " A-Z " , 1 ) . '</a>' ;
print '<a href="' . $file . '?sortfield=' . $field . '&sortorder=desc&begin=' . $begin . $options . '">' . img_up ( " Z-A " , 0 ) . '</a>' ;
}
if ( $sortorder == 'ASC' ) {
print '<a href="' . $file . '?sortfield=' . $field . '&sortorder=asc&begin=' . $begin . $options . '">' . img_down ( " A-Z " , 0 ) . '</a>' ;
print '<a href="' . $file . '?sortfield=' . $field . '&sortorder=desc&begin=' . $begin . $options . '">' . img_up ( " Z-A " , 1 ) . '</a>' ;
}
}
}
2004-10-31 14:34:08 +01:00
print " </td> " ;
2003-06-21 16:56:42 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Affichage d ' un titre
2005-01-18 22:09:16 +01:00
\param titre Le titre a afficher
2004-07-16 00:17:39 +02:00
*/
2002-12-23 15:10:24 +01:00
function print_titre ( $titre )
2003-04-26 16:25:47 +02:00
{
2005-08-11 21:13:08 +02:00
print '<div class="titre">' . $titre . '</div>' ;
2002-05-06 21:10:48 +02:00
}
2004-07-16 00:17:39 +02:00
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Affichage d 'un titre d' une fiche , align<EFBFBD> a gauche
2005-01-18 22:09:16 +01:00
\param titre Le titre a afficher
\param mesg Message supl<EFBFBD> mentaire <EFBFBD> afficher <EFBFBD> droite
2006-08-12 17:32:57 +02:00
\param picto Picto pour ligne de titre
2004-07-16 00:17:39 +02:00
*/
2006-08-12 17:32:57 +02:00
function print_fiche_titre ( $titre , $mesg = '' , $picto = '' )
2003-06-28 16:05:03 +02:00
{
2005-08-11 21:13:08 +02:00
print " \n " ;
2006-08-12 17:32:57 +02:00
print '<table width="100%" border="0" class="notopnoleftnoright"><tr>' ;
if ( $picto ) print '<td width="24" align="left" valign="middle">' . img_picto ( '' , $picto ) . '</td>' ;
print '<td class="notopnoleftnoright" valign="middle">' ;
print '<div class="titre">' . $titre . '</div>' ;
print '</td>' ;
2005-08-11 21:13:08 +02:00
if ( strlen ( $mesg ))
2003-06-28 16:05:03 +02:00
{
2005-08-11 21:13:08 +02:00
print '<td align="right" valign="middle"><b>' . $mesg . '</b></td>' ;
2003-06-28 16:05:03 +02:00
}
2005-08-11 21:13:08 +02:00
print '</tr></table>' . " \n " ;
2003-06-28 16:05:03 +02:00
}
2004-06-08 13:14:42 +02:00
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Effacement d ' un fichier
2006-06-08 00:15:17 +02:00
\param file Fichier a effacer ou masque de fichier a effacer
2007-05-14 21:27:20 +02:00
\param boolean true if file deleted , false if error
2004-07-16 00:17:39 +02:00
*/
2003-06-17 16:36:13 +02:00
function dol_delete_file ( $file )
{
2006-06-08 00:15:17 +02:00
$ok = true ;
foreach ( glob ( $file ) as $filename )
{
$ok = unlink ( $filename );
if ( $ok ) dolibarr_syslog ( " Removed file $filename " );
else dolibarr_syslog ( " Failed to remove file $filename " );
}
return $ok ;
2003-06-17 16:36:13 +02:00
}
2004-06-08 13:14:42 +02:00
2006-05-31 12:43:59 +02:00
/**
2006-11-11 01:46:15 +01:00
\brief Effacement d ' un r<EFBFBD> pertoire
\param file R<EFBFBD> pertoire a effacer
2006-05-31 12:43:59 +02:00
*/
function dol_delete_dir ( $dir )
{
2006-11-11 01:46:15 +01:00
return rmdir ( $dir );
}
/**
2006-11-11 16:52:17 +01:00
\brief Effacement d ' un r<EFBFBD> pertoire $dir et de son arborescence
2006-11-11 01:46:15 +01:00
\param file R<EFBFBD> pertoire a effacer
\return int Nombre de fichier + rep<EFBFBD> rtoires supprim<EFBFBD> s
*/
2006-11-11 16:52:17 +01:00
function dol_delete_dir_recursive ( $dir , $count = 0 )
2006-11-11 01:46:15 +01:00
{
if ( $handle = opendir ( " $dir " ))
{
while ( false !== ( $item = readdir ( $handle )))
{
if ( $item != " . " && $item != " .. " )
{
if ( is_dir ( " $dir / $item " ))
{
2006-11-11 16:52:17 +01:00
$count = dol_delete_dir_recursive ( " $dir / $item " , $count );
2006-11-11 01:46:15 +01:00
}
else
{
2006-11-11 16:52:17 +01:00
unlink ( " $dir / $item " );
$count ++ ;
//echo " removing $dir/$item<br>\n";
2006-11-11 01:46:15 +01:00
}
}
}
closedir ( $handle );
rmdir ( $dir );
$count ++ ;
//echo "removing $dir<br>\n";
}
2006-11-11 16:52:17 +01:00
2006-11-11 01:46:15 +01:00
//echo "return=".$count;
return $count ;
2006-05-31 12:43:59 +02:00
}
2003-04-26 16:25:47 +02:00
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Fonction print_barre_liste
2004-07-28 00:50:27 +02:00
\param titre titre de la page
\param page num<EFBFBD> ro de la page
\param file lien
2006-08-13 02:34:16 +02:00
\param options parametres complementaires lien ( '' par defaut )
2005-08-11 21:13:08 +02:00
\param sortfield champ de tri ( '' par defaut )
\param sortorder ordre de tri ( '' par defaut )
\param center chaine du centre ( '' par defaut )
2004-08-07 16:41:29 +02:00
\param num nombre d ' <EFBFBD> l<EFBFBD> ment total
2004-07-28 00:50:27 +02:00
*/
2005-08-11 21:13:08 +02:00
function print_barre_liste ( $titre , $page , $file , $options = '' , $sortfield = '' , $sortorder = '' , $center = '' , $num =- 1 )
2005-06-11 13:38:19 +02:00
{
2007-08-10 10:19:35 +02:00
global $conf , $langs ;
2003-07-10 15:07:56 +02:00
2005-06-11 13:38:19 +02:00
if ( $num > $conf -> liste_limit or $num == - 1 )
2003-07-10 15:07:56 +02:00
{
2005-06-11 13:38:19 +02:00
$nextpage = 1 ;
2003-07-10 15:07:56 +02:00
}
2005-06-11 13:38:19 +02:00
else
2003-07-10 15:07:56 +02:00
{
2005-06-11 13:38:19 +02:00
$nextpage = 0 ;
2003-07-10 15:07:56 +02:00
}
2005-08-11 21:13:08 +02:00
print '<table width="100%" border="0" class="notopnoleftnoright">' ;
2003-03-27 23:13:57 +01:00
2005-06-11 13:38:19 +02:00
if ( $page > 0 || $num > $conf -> liste_limit )
2003-03-25 22:46:18 +01:00
{
2007-08-10 10:19:35 +02:00
print '<tr><td class="notopnoleftnoright"><div class="titre">' . $titre . ' - ' . $langs -> trans ( 'page' ) . ' ' . ( $page + 1 );
2005-06-11 13:38:19 +02:00
print '</div></td>' ;
}
else
{
2005-10-16 04:09:54 +02:00
print '<tr><td class="notopnoleftnoright"><div class="titre">' . $titre . '</div></td>' ;
2003-03-25 22:46:18 +01:00
}
2005-08-11 21:13:08 +02:00
if ( $center )
2003-03-25 22:46:18 +01:00
{
2005-08-11 21:13:08 +02:00
print '<td align="left">' . $center . '</td>' ;
2003-03-25 22:46:18 +01:00
}
2005-06-11 13:38:19 +02:00
print '<td align="right">' ;
if ( $sortfield ) $options .= " &sortfield= $sortfield " ;
if ( $sortorder ) $options .= " &sortorder= $sortorder " ;
2003-07-10 15:07:56 +02:00
2005-06-11 13:38:19 +02:00
// Affichage des fleches de navigation
print_fleche_navigation ( $page , $file , $options , $nextpage );
2003-07-10 15:07:56 +02:00
2005-08-11 21:13:08 +02:00
print '</td></tr></table>' ;
2002-05-06 21:10:48 +02:00
}
2003-05-05 13:14:48 +02:00
2004-12-28 16:36:40 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Fonction servant a afficher les fleches de navigation dans les pages de listes
\param page num<EFBFBD> ro de la page
\param file lien
\param options autres parametres d ' url a propager dans les liens ( " " par defaut )
\param nextpage faut - il une page suivante
2004-07-16 00:17:39 +02:00
*/
2005-01-18 22:09:16 +01:00
function print_fleche_navigation ( $page , $file , $options = '' , $nextpage )
2003-05-05 13:14:48 +02:00
{
2004-07-25 20:45:03 +02:00
global $conf , $langs ;
2004-07-16 00:17:39 +02:00
if ( $page > 0 )
2003-05-05 13:14:48 +02:00
{
2005-01-18 22:09:16 +01:00
print '<a href="' . $file . '?page=' . ( $page - 1 ) . $options . '">' . img_previous ( $langs -> trans ( " Previous " )) . '</a>' ;
2003-05-05 13:14:48 +02:00
}
2003-07-10 15:07:56 +02:00
2004-07-16 00:17:39 +02:00
if ( $nextpage > 0 )
2003-07-10 15:07:56 +02:00
{
2005-01-18 22:09:16 +01:00
print '<a href="' . $file . '?page=' . ( $page + 1 ) . $options . '">' . img_next ( $langs -> trans ( " Next " )) . '</a>' ;
2003-07-10 15:07:56 +02:00
}
2003-05-05 13:14:48 +02:00
}
2004-07-16 00:17:39 +02:00
2004-07-17 14:52:41 +02:00
2007-07-07 16:56:38 +02:00
/**
* \brief Fonction qui retourne un taux de tva format<EFBFBD> pour visualisation
* \remarks Fonction utilis<EFBFBD> e dans les pdf et les pages html
* \param rate Taux a formater ( 19.6 19 , 6 19.6 % 19 , 6 %... )
* \return string Chaine avec montant format<EFBFBD> ( 19 , 6 ou 19 , 6 % )
*/
function vatrate ( $rate )
{
$foundpercent = false ;
if ( eregi ( '%' , $rate ))
{
$rate = eregi_replace ( '%' , '' , $rate );
$foundpercent = true ;
}
return price ( $rate , 0 , '' , 0 , 0 ) . ( $foundpercent ? '%' : '' );
}
2004-12-28 16:36:40 +01:00
/**
2007-06-16 15:06:05 +02:00
* \brief Fonction qui retourne un montant mon<EFBFBD> taire format<EFBFBD> pour visualisation
2007-04-02 01:04:24 +02:00
* \remarks Fonction utilis<EFBFBD> e dans les pdf et les pages html
* \param amount Montant a formater
* \param html Formatage html ou pas ( 0 par defaut )
2007-07-07 16:56:38 +02:00
* \param outlangs Objet langs pour formatage text
2007-06-16 15:06:05 +02:00
* \param trunc 1 = Tronque affichage si trop de d<EFBFBD> cimales , 0 = Force le non troncage
2007-07-07 16:56:38 +02:00
* \param nbdecimal Nbre decimals minimum .
2007-04-02 01:04:24 +02:00
* \return string Chaine avec montant format<EFBFBD>
* \seealso price2num Fonction inverse de price
2004-07-16 00:17:39 +02:00
*/
2007-07-07 16:56:38 +02:00
function price ( $amount , $html = 0 , $outlangs = '' , $trunc = 1 , $nbdecimal = 2 )
2002-12-23 15:10:24 +01:00
{
2007-04-02 01:04:24 +02:00
global $langs , $conf ;
2006-12-07 11:19:38 +01:00
2007-04-02 01:04:24 +02:00
// Separateurs par defaut
$dec = '.' ; $thousand = ' ' ;
// Si $outlangs non force, on prend langue utilisateur
if ( ! is_object ( $outlangs )) $outlangs = $langs ;
if ( $outlangs -> trans ( " SeparatorDecimal " ) != " SeparatorDecimal " ) $dec = $outlangs -> trans ( " SeparatorDecimal " );
if ( $outlangs -> trans ( " SeparatorThousand " ) != " SeparatorThousand " ) $thousand = $outlangs -> trans ( " SeparatorThousand " );
2007-07-31 00:34:36 +02:00
//print "amount=".$amount." html=".$html." trunc=".$trunc." nbdecimal=".$nbdecimal." dec=".$dec." thousand=".$thousand;
2007-04-02 01:04:24 +02:00
2007-06-16 15:06:05 +02:00
//print "amount=".$amount."-";
2007-04-02 01:04:24 +02:00
$amount = ereg_replace ( ',' , '.' , $amount );
//print $amount."-";
2007-07-31 00:34:36 +02:00
$datas = split ( '\.' , $amount );
2007-04-02 01:04:24 +02:00
$decpart = $datas [ 1 ];
2007-06-16 15:06:05 +02:00
$decpart = eregi_replace ( '0+$' , '' , $decpart ); // Supprime les 0 de fin de partie d<> cimale
//print "decpart=".$decpart."<br>";
2007-04-02 01:04:24 +02:00
$end = '' ;
2007-07-07 16:56:38 +02:00
2007-04-02 01:04:24 +02:00
// On augmente au besoin si il y a plus de 2 d<> cimales
2007-04-11 03:33:25 +02:00
if ( strlen ( $decpart ) > $nbdecimal ) $nbdecimal = strlen ( $decpart );
2007-04-02 01:04:24 +02:00
// Si on depasse max
2007-04-11 03:33:25 +02:00
if ( $trunc && $nbdecimal > $conf -> global -> MAIN_MAX_DECIMALS_SHOWN )
2007-04-02 01:04:24 +02:00
{
2007-04-11 03:33:25 +02:00
$nbdecimal = $conf -> global -> MAIN_MAX_DECIMALS_SHOWN ;
2007-07-07 16:56:38 +02:00
if ( eregi ( '\.\.\.' , $conf -> global -> MAIN_MAX_DECIMALS_SHOWN ))
{
// Si un affichage est tronqu<71> , on montre des ...
$end = '...' ;
}
2007-04-02 01:04:24 +02:00
}
// Formate nombre
if ( $html )
{
2007-04-11 03:33:25 +02:00
$output = ereg_replace ( ' ' , ' ' , number_format ( $amount , $nbdecimal , $dec , $thousand ));
2007-04-02 01:04:24 +02:00
}
else
{
2007-04-11 03:33:25 +02:00
$output = number_format ( $amount , $nbdecimal , $dec , $thousand );
2007-04-02 01:04:24 +02:00
}
$output .= $end ;
return $output ;
2002-04-30 12:44:42 +02:00
}
2007-04-02 01:04:24 +02:00
2005-10-18 21:56:29 +02:00
/**
2007-06-16 15:06:05 +02:00
\brief Fonction qui retourne un num<EFBFBD> rique conforme PHP et SQL , depuis un montant au
format utilisateur .
\remarks Fonction <EFBFBD> appeler sur montants saisis avant un insert en base
\param amount Montant a formater
\param rounding 'MU' = Round to Max unit price ( MAIN_MAX_DECIMALS_UNIT )
2007-06-19 00:48:05 +02:00
'MT' = Round to Max with Tax ( MAIN_MAX_DECIMALS_TOT )
2007-06-16 15:06:05 +02:00
'MS' = Round to Max Shown ( MAIN_MAX_DECIMALS_SHOWN )
'' = No rounding
\return string Montant au format num<EFBFBD> rique PHP et SQL ( Exemple : '99.99999' )
\seealso price Fonction inverse de price2num
2005-10-18 21:56:29 +02:00
*/
2007-06-16 15:06:05 +02:00
function price2num ( $amount , $rounding = '' )
2005-10-18 21:56:29 +02:00
{
2007-06-16 15:06:05 +02:00
global $conf ;
// Round PHP function does not allow number like '1,234.5'.
// Numbers must be '1234.5'
$amount = ereg_replace ( ',' , '.' , $amount );
$amount = ereg_replace ( ' ' , '' , $amount );
if ( $rounding )
{
if ( $rounding == 'MU' ) $amount = round ( $amount , $conf -> global -> MAIN_MAX_DECIMALS_UNIT );
2007-06-19 00:48:05 +02:00
elseif ( $rounding == 'MT' ) $amount = round ( $amount , $conf -> global -> MAIN_MAX_DECIMALS_TOT );
2007-06-16 15:06:05 +02:00
elseif ( $rounding == 'MS' ) $amount = round ( $amount , $conf -> global -> MAIN_MAX_DECIMALS_SHOWN );
else $amount = 'ErrorBadParameterProvidedToFunction' ;
$amount = ereg_replace ( ',' , '.' , $amount );
$amount = ereg_replace ( ' ' , '' , $amount );
}
return $amount ;
2005-10-18 21:56:29 +02:00
}
2004-12-28 16:36:40 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Fonction qui renvoie la tva d ' une ligne ( en fonction du vendeur , acheteur et taux du produit )
\remarks Si vendeur non assujeti <EFBFBD> TVA , TVA par d<EFBFBD> faut = 0. Fin de r<EFBFBD> gle .
Si le ( pays vendeur = pays acheteur ) alors TVA par d<EFBFBD> faut = TVA du produit vendu . Fin de r<EFBFBD> gle .
Si vendeur et acheteur dans Communaut<EFBFBD> europ<EFBFBD> enne et bien vendu = moyen de transports neuf ( auto , bateau , avion ), TVA par d<EFBFBD> faut = 0 ( La TVA doit <EFBFBD> tre pay<EFBFBD> par acheteur au centre d ' impots de son pays et non au vendeur ) . Fin de r<EFBFBD> gle .
Si vendeur et acheteur dans Communaut<EFBFBD> europ<EFBFBD> enne et acheteur = particulier ou entreprise sans num TVA intra alors TVA par d<EFBFBD> faut = TVA du produit vendu . Fin de r<EFBFBD> gle .
Si vendeur et acheteur dans Communaut<EFBFBD> europ<EFBFBD> enne et acheteur = entreprise avec num TVA intra alors TVA par d<EFBFBD> faut = 0. Fin de r<EFBFBD> gle .
Sinon TVA propos<EFBFBD> e par d<EFBFBD> faut = 0. Fin de r<EFBFBD> gle .
\param societe_vendeuse Objet soci<EFBFBD> t<EFBFBD> vendeuse
\param societe_acheteuse Objet soci<EFBFBD> t<EFBFBD> acheteuse
\param taux_produit Taux par defaut du produit vendu
\return float Taux de tva de la ligne
2005-11-04 00:47:51 +01:00
*/
2006-06-16 02:33:04 +02:00
function get_default_tva ( $societe_vendeuse , $societe_acheteuse , $taux_produit )
2002-12-23 15:10:24 +01:00
{
2006-06-16 02:33:04 +02:00
dolibarr_syslog ( " get_default_tva vendeur_assujeti= $societe_vendeuse->tva_assuj pays_vendeur= $societe_vendeuse->pays_id , pays_acheteur= $societe_acheteuse->pays_id , taux_produit= $taux_produit " );
2006-06-22 17:14:18 +02:00
if ( ! is_object ( $societe_vendeuse )) return 0 ;
2006-11-11 16:52:17 +01:00
2006-06-16 02:33:04 +02:00
// Si vendeur non assujeti <20> TVA (tva_assuj vaut 0/1 ou franchise/reel)
if ( is_numeric ( $societe_vendeuse -> tva_assuj ) && ! $societe_vendeuse -> tva_assuj ) return 0 ;
if ( ! is_numeric ( $societe_vendeuse -> tva_assuj ) && $societe_vendeuse -> tva_assuj == 'franchise' ) return 0 ;
2006-11-11 16:52:17 +01:00
// Si le (pays vendeur = pays acheteur) alors la TVA par d<> faut=TVA du produit vendu. Fin de r<> gle.
2007-05-10 20:34:45 +02:00
//if (is_object($societe_acheteuse) && ($societe_vendeuse->pays_id == $societe_acheteuse->pays_id) && ($societe_acheteuse->tva_assuj == 1 || $societe_acheteuse->tva_assuj == 'reel'))
// Le test ci-dessus ne devrait pas etre necessaire. Me signaler l'exemple du cas juridique concercn<63> si le test suivant n'est pas suffisant.
if ( is_object ( $societe_acheteuse ) && ( $societe_vendeuse -> pays_id == $societe_acheteuse -> pays_id ))
2006-03-16 02:03:55 +01:00
{
return $taux_produit ;
}
2006-11-11 16:52:17 +01:00
2006-03-16 02:03:55 +01:00
// Si vendeur et acheteur dans Communaut<75> europ<6F> enne et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par d<> faut=0 (La TVA doit <20> tre pay<61> par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de r<> gle.
// Non g<> r<EFBFBD>
2006-11-11 16:52:17 +01:00
2006-12-16 14:45:59 +01:00
// Si vendeur et acheteur dans Communaut<75> europ<6F> enne et acheteur = particulier ou entreprise sans num TVA intra alors TVA par d<> faut=TVA du produit vendu. Fin de r<> gle.
if ( is_object ( $societe_acheteuse ) && ( $societe_vendeuse -> isInEEC () && $societe_acheteuse -> isInEEC ()) && ! $societe_acheteuse -> tva_intra )
2006-03-16 02:03:55 +01:00
{
return $taux_produit ;
}
2005-11-04 00:47:51 +01:00
2006-12-16 14:45:59 +01:00
// Si vendeur et acheteur dans Communaut<75> europ<6F> enne et acheteur = entreprise avec num TVA intra alors TVA par d<> faut=0. Fin de r<> gle.
if ( is_object ( $societe_acheteuse ) && ( $societe_vendeuse -> isInEEC () && $societe_acheteuse -> isInEEC ()) && $societe_acheteuse -> tva_intra )
{
return 0 ;
}
2006-03-16 02:03:55 +01:00
// Sinon la TVA propos<6F> e par d<> faut=0. Fin de r<> gle.
return 0 ;
2002-04-30 12:44:42 +02:00
}
2003-03-12 19:05:40 +01:00
2005-11-04 00:47:51 +01:00
2004-12-28 16:36:40 +01:00
/**
2004-08-07 16:41:29 +02:00
\brief Renvoie oui ou non dans la langue choisie
2004-07-31 17:27:37 +02:00
\param yesno variable pour test si oui ou non
\param case Oui / Non ou oui / non
*/
function yn ( $yesno , $case = 1 ) {
global $langs ;
2006-03-23 15:55:04 +01:00
if ( $yesno == 1 || strtolower ( $yesno ) == 'yes' || strtolower ( $yesno ) == 'true' ) // A mettre avant test sur no a cause du == 0
2004-07-31 17:27:37 +02:00
return $case ? $langs -> trans ( " Yes " ) : $langs -> trans ( " yes " );
2006-11-11 16:52:17 +01:00
if ( $yesno == 0 || strtolower ( $yesno ) == 'no' || strtolower ( $yesno ) == 'false' )
2006-03-23 15:55:04 +01:00
return $case ? $langs -> trans ( " No " ) : $langs -> trans ( " no " );
2004-07-31 17:27:37 +02:00
return " unknown " ;
}
2002-04-30 12:44:42 +02:00
2004-12-28 16:36:40 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Fonction pour initialiser un salt pour la fonction crypt
\param $type 2 => renvoi un salt pour cryptage DES
12 => renvoi un salt pour cryptage MD5
non defini => renvoi un salt pour cryptage par defaut
\return string Chaine salt
2004-07-16 00:17:39 +02:00
*/
2006-06-25 19:15:07 +02:00
function makesalt ( $type = CRYPT_SALT_LENGTH )
{
2006-12-22 23:05:44 +01:00
dolibarr_syslog ( " functions.inc::makesalt type= " . $type );
switch ( $type )
{
case 12 : // 8 + 4
$saltlen = 8 ; $saltprefix = '$1$' ; $saltsuffix = '$' ; break ;
case 8 : // 8 + 4 (Pour compatibilite, ne devrait pas etre utilis<69> )
$saltlen = 8 ; $saltprefix = '$1$' ; $saltsuffix = '$' ; break ;
case 2 : // 2
default : // by default, fall back on Standard DES (should work everywhere)
$saltlen = 2 ; $saltprefix = '' ; $saltsuffix = '' ; break ;
}
$salt = '' ;
while ( strlen ( $salt ) < $saltlen ) $salt .= chr ( rand ( 64 , 126 ));
$result = $saltprefix . $salt . $saltsuffix ;
dolibarr_syslog ( " functions.inc::makesalt return= " . $result );
return $result ;
2003-03-07 19:53:17 +01:00
}
2004-12-28 16:36:40 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Fonction pour qui retourne le rowid d ' un departement par son code
\param db handler d ' acc<EFBFBD> s base
\param code Code r<EFBFBD> gion
\param pays_id Id du pays
2004-07-28 10:58:25 +02:00
*/
function departement_rowid ( $db , $code , $pays_id )
2004-07-21 11:05:53 +02:00
{
$sql = " SELECT c.rowid FROM " . MAIN_DB_PREFIX . " c_departements as c, " . MAIN_DB_PREFIX . " c_regions as r " ;
$sql .= " WHERE c.code_departement= " . $code ;
$sql .= " AND c.fk_region = r.code_region " ;
$sql .= " AND r.fk_pays = " . $pays_id ;
2004-07-21 16:44:30 +02:00
2004-07-21 11:05:53 +02:00
if ( $db -> query ( $sql ))
{
$num = $db -> num_rows ();
if ( $num )
{
2004-10-23 19:27:57 +02:00
$obj = $db -> fetch_object ();
2004-07-21 11:05:53 +02:00
return $obj -> rowid ;
}
else
{
return 0 ;
}
$db -> free ();
}
else
{
return 0 ;
}
}
2005-04-02 15:44:44 +02:00
/**
2006-12-22 23:05:44 +01:00
\brief Renvoi un chemin de classement r<EFBFBD> pertoire en fonction d ' un id
\remarks Examples : 1 -> " 0/0/1/ " , 15 -> " 0/1/5/ "
\param $num Id <EFBFBD> d<EFBFBD> composer
\param $level Niveau de decoupage ( 1 , 2 ou 3 niveaux )
2005-04-02 15:44:44 +02:00
*/
2006-09-02 22:53:20 +02:00
function get_exdir ( $num , $level = 3 )
2005-02-18 16:11:11 +01:00
{
2006-12-22 23:05:44 +01:00
$num = substr ( " 000 " . $num , - $level );
if ( $level == 1 ) return substr ( $num , 0 , 1 ) . '/' ;
if ( $level == 2 ) return substr ( $num , 1 , 1 ) . '/' . substr ( $num , 0 , 1 ) . '/' ;
if ( $level == 3 ) return substr ( $num , 2 , 1 ) . '/' . substr ( $num , 1 , 1 ) . '/' . substr ( $num , 0 , 1 ) . '/' ;
return '' ;
2005-02-18 16:11:11 +01:00
}
2004-07-21 11:05:53 +02:00
2005-04-02 15:44:44 +02:00
/**
2006-12-22 23:05:44 +01:00
\brief Cr<EFBFBD> ation de r<EFBFBD> pertoire recursive
\param $dir R<EFBFBD> pertoire <EFBFBD> cr<EFBFBD> er
\return int < 0 si erreur , >= 0 si succ<EFBFBD> s
*/
2005-03-03 17:52:26 +01:00
function create_exdir ( $dir )
{
2006-09-06 23:19:01 +02:00
dolibarr_syslog ( " functions.inc.php::create_exdir: dir= $dir " );
2006-01-05 19:03:28 +01:00
2006-09-06 23:19:01 +02:00
if ( @ is_dir ( $dir )) return 0 ;
2006-11-11 16:52:17 +01:00
2005-04-02 15:44:44 +02:00
$nberr = 0 ;
$nbcreated = 0 ;
2005-03-03 17:52:26 +01:00
2005-04-02 15:44:44 +02:00
$ccdir = '' ;
$cdir = explode ( " / " , $dir );
for ( $i = 0 ; $i < sizeof ( $cdir ) ; $i ++ )
{
if ( $i > 0 ) $ccdir .= '/' . $cdir [ $i ];
else $ccdir = $cdir [ $i ];
2006-05-17 23:12:49 +02:00
if ( eregi ( " ^.: $ " , $ccdir , $regs )) continue ; // Si chemin Windows incomplet, on poursuit par rep suivant
2005-03-03 17:52:26 +01:00
2006-05-17 23:12:49 +02:00
// Attention, le is_dir() peut <20> chouer bien que le rep existe.
// (ex selon config de open_basedir)
if ( $ccdir )
2005-04-02 15:44:44 +02:00
{
2006-09-06 23:19:01 +02:00
if ( ! @ is_dir ( $ccdir ))
2006-05-17 23:12:49 +02:00
{
2007-01-05 10:06:47 +01:00
dolibarr_syslog ( " functions.inc.php::create_exdir: Directory ' " . $ccdir . " ' does not exists or is outside open_basedir PHP setting. " );
umask ( 0 );
if ( ! @ mkdir ( $ccdir , 0755 ))
{
// Si le is_dir a renvoy<6F> une fausse info, alors on passe ici.
dolibarr_syslog ( " functions.inc.php::create_exdir: Fails to create directory ' " . $ccdir . " ' or directory already exists. " );
$nberr ++ ;
}
else
{
dolibarr_syslog ( " functions.inc.php::create_exdir: Directory ' " . $ccdir . " ' created " );
$nberr = 0 ; // On remet <20> z<> ro car si on arrive ici, cela veut dire que les <20> checs pr<70> c<EFBFBD> dents peuvent etre ignor<6F> s
$nbcreated ++ ;
}
}
else
{
$nberr = 0 ; // On remet <20> z<> ro car si on arrive ici, cela veut dire que les <20> checs pr<70> c<EFBFBD> dents peuvent etre ignor<6F> s
}
2005-04-02 15:44:44 +02:00
}
}
return ( $nberr ? - $nberr : $nbcreated );
2005-03-03 17:52:26 +01:00
}
2006-06-24 15:28:39 +02:00
/**
2006-12-22 23:05:44 +01:00
\brief Scan a directory and return a list of files / directories
\param $path Starting path from which to search
\param $types Can be " directories " , " files " , or " all "
\param $recursive Determines whether subdirectories are searched
\param $filter Regex for filter
\param $exludefilter Regex for exclude filter
\param $sortcriteria Sort criteria ( " date " , " size " )
\param $sortorder Sort order ( SORT_ASC , SORT_DESC )
\return array Array of array ( 'name' => xxx , 'date' => yyy , 'size' => zzz )
2006-06-24 15:28:39 +02:00
*/
function dolibarr_dir_list ( $path , $types = " all " , $recursive = 0 , $filter = " " , $excludefilter = " " , $sortcriteria = " " , $sortorder = SORT_ASC )
{
2006-12-22 23:05:44 +01:00
dolibarr_syslog ( " functions.inc.php::dolibarr_dir_list $path " );
if ( ! is_dir ( $path )) return array ();
if ( $dir = opendir ( $path ))
2007-07-14 17:48:42 +02:00
{
$file_list = array ();
while ( false !== ( $file = readdir ( $dir )))
{
$qualified = 1 ;
// Check if file is qualified
if ( eregi ( '^\.' , $file )) $qualified = 0 ;
if ( $excludefilter && eregi ( $excludefilter , $file )) $qualified = 0 ;
if ( $qualified )
2006-12-22 23:05:44 +01:00
{
// Check whether this is a file or directory and whether we're interested in that type
if (( is_dir ( $path . " / " . $file )) && (( $types == " directories " ) || ( $types == " all " )))
2007-07-14 17:48:42 +02:00
{
// Add entry into file_list array
if ( $sortcriteria == 'date' ) $filedate = filemtime ( $path . " / " . $file );
if ( $sortcriteria == 'size' ) $filesize = filesize ( $path . " / " . $file );
if ( ! $filter || eregi ( $filter , $path . '/' . $file ))
{
$file_list [] = array (
2006-12-22 23:05:44 +01:00
" name " => $file ,
" fullname " => $path . '/' . $file ,
" date " => $filedate ,
" size " => $filesize
);
2007-07-14 17:48:42 +02:00
}
// if we're in a directory and we want recursive behavior, call this function again
if ( $recursive )
{
$file_list = array_merge ( $file_list , dolibarr_dir_list ( $path . " / " . $file . " / " , $types , $recursive , $filter , $excludefilter , $sortcriteria , $sortorder ));
}
2006-12-22 23:05:44 +01:00
}
else if (( $types == " files " ) || ( $types == " all " ))
2007-07-14 17:48:42 +02:00
{
// Add file into file_list array
if ( $sortcriteria == 'date' ) $filedate = filemtime ( $path . " / " . $file );
if ( $sortcriteria == 'size' ) $filesize = filesize ( $path . " / " . $file );
if ( ! $filter || eregi ( $filter , $path . '/' . $file ))
{
$file_list [] = array (
2006-12-22 23:05:44 +01:00
" name " => $file ,
" fullname " => $path . '/' . $file ,
" date " => $filedate ,
" size " => $filesize
);
2007-07-14 17:48:42 +02:00
}
2006-12-22 23:05:44 +01:00
}
}
2006-06-24 15:28:39 +02:00
}
2006-12-22 23:05:44 +01:00
closedir ( $dir );
// Obtain a list of columns
$myarray = array ();
foreach ( $file_list as $key => $row )
2006-06-24 15:28:39 +02:00
{
2006-12-22 23:05:44 +01:00
$myarray [ $key ] = $row [ $sortcriteria ];
2006-06-24 15:28:39 +02:00
}
2006-12-22 23:05:44 +01:00
// Sort the data
array_multisort ( $myarray , $sortorder , $file_list );
return $file_list ;
}
else
{
return false ;
}
2006-06-24 15:28:39 +02:00
}
2006-07-12 09:49:39 +02:00
/**
2006-12-22 23:05:44 +01:00
\brief Retourne le num<EFBFBD> ro de la semaine par rapport a une date
\param time Date au format 'timestamp'
\return int Num<EFBFBD> ro de semaine
*/
2006-07-12 09:49:39 +02:00
function numero_semaine ( $time )
{
$stime = strftime ( '%Y-%m-%d' , $time );
2006-11-11 16:52:17 +01:00
2007-06-16 12:13:51 +02:00
if ( eregi ( '^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?' , $stime , $reg ))
2006-07-12 09:49:39 +02:00
{
// Date est au format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS'
$annee = $reg [ 1 ];
$mois = $reg [ 2 ];
$jour = $reg [ 3 ];
}
2006-11-11 16:52:17 +01:00
2006-07-12 09:49:39 +02:00
/*
* Norme ISO - 8601 :
* - La semaine 1 de toute ann<EFBFBD> e est celle qui contient le 4 janvier ou que la semaine 1 de toute ann<EFBFBD> e est celle qui contient le 1 er jeudi de janvier .
* - La majorit<EFBFBD> des ann<EFBFBD> es ont 52 semaines mais les ann<EFBFBD> es qui commence un jeudi et les ann<EFBFBD> es bissextiles commen<EFBFBD> ant un mercredi en poss<EFBFBD> de 53.
* - Le 1 er jour de la semaine est le Lundi
2006-11-11 16:52:17 +01:00
*/
2006-07-12 09:49:39 +02:00
// D<> finition du Jeudi de la semaine
if ( date ( " w " , mktime ( 12 , 0 , 0 , $mois , $jour , $annee )) == 0 ) // Dimanche
$jeudiSemaine = mktime ( 12 , 0 , 0 , $mois , $jour , $annee ) - 3 * 24 * 60 * 60 ;
else if ( date ( " w " , mktime ( 12 , 0 , 0 , $mois , $jour , $annee )) < 4 ) // du Lundi au Mercredi
$jeudiSemaine = mktime ( 12 , 0 , 0 , $mois , $jour , $annee ) + ( 4 - date ( " w " , mktime ( 12 , 0 , 0 , $mois , $jour , $annee ))) * 24 * 60 * 60 ;
else if ( date ( " w " , mktime ( 12 , 0 , 0 , $mois , $jour , $annee )) > 4 ) // du Vendredi au Samedi
$jeudiSemaine = mktime ( 12 , 0 , 0 , $mois , $jour , $annee ) - ( date ( " w " , mktime ( 12 , 0 , 0 , $mois , $jour , $annee )) - 4 ) * 24 * 60 * 60 ;
else // Jeudi
$jeudiSemaine = mktime ( 12 , 0 , 0 , $mois , $jour , $annee );
2006-11-11 16:52:17 +01:00
2006-07-12 09:49:39 +02:00
// D<> finition du premier Jeudi de l'ann<6E> e
if ( date ( " w " , mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine ))) == 0 ) // Dimanche
{
$premierJeudiAnnee = mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine )) + 4 * 24 * 60 * 60 ;
}
else if ( date ( " w " , mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine ))) < 4 ) // du Lundi au Mercredi
{
$premierJeudiAnnee = mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine )) + ( 4 - date ( " w " , mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine )))) * 24 * 60 * 60 ;
}
else if ( date ( " w " , mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine ))) > 4 ) // du Vendredi au Samedi
{
$premierJeudiAnnee = mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine )) + ( 7 - ( date ( " w " , mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine ))) - 4 )) * 24 * 60 * 60 ;
}
else // Jeudi
{
$premierJeudiAnnee = mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine ));
}
2006-11-11 16:52:17 +01:00
2006-07-12 09:49:39 +02:00
// D<> finition du num<75> ro de semaine: nb de jours entre "premier Jeudi de l'ann<6E> e" et "Jeudi de la semaine";
2006-11-11 16:52:17 +01:00
$numeroSemaine = (
(
date ( " z " , mktime ( 12 , 0 , 0 , date ( " m " , $jeudiSemaine ), date ( " d " , $jeudiSemaine ), date ( " Y " , $jeudiSemaine )))
2006-07-12 09:49:39 +02:00
-
2006-11-11 16:52:17 +01:00
date ( " z " , mktime ( 12 , 0 , 0 , date ( " m " , $premierJeudiAnnee ), date ( " d " , $premierJeudiAnnee ), date ( " Y " , $premierJeudiAnnee )))
) / 7
2006-07-12 09:49:39 +02:00
) + 1 ;
2006-11-11 16:52:17 +01:00
2006-07-12 09:49:39 +02:00
// Cas particulier de la semaine 53
if ( $numeroSemaine == 53 )
{
// Les ann<6E> es qui commence un Jeudi et les ann<6E> es bissextiles commen<65> ant un Mercredi en poss<73> de 53
if ( date ( " w " , mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine ))) == 4 || ( date ( " w " , mktime ( 12 , 0 , 0 , 1 , 1 , date ( " Y " , $jeudiSemaine ))) == 3 && date ( " z " , mktime ( 12 , 0 , 0 , 12 , 31 , date ( " Y " , $jeudiSemaine ))) == 365 ))
{
$numeroSemaine = 53 ;
}
else
{
$numeroSemaine = 1 ;
}
}
2006-11-11 16:52:17 +01:00
2006-07-12 09:49:39 +02:00
//echo $jour."-".$mois."-".$annee." (".date("d-m-Y",$premierJeudiAnnee)." - ".date("d-m-Y",$jeudiSemaine).") -> ".$numeroSemaine."<BR>";
2006-11-11 16:52:17 +01:00
2006-07-12 09:49:39 +02:00
return sprintf ( " %02d " , $numeroSemaine );
}
2006-11-19 02:46:32 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Retourne le picto champ obligatoire
\return string Chaine avec picto obligatoire
*/
2006-11-19 02:46:32 +01:00
function picto_required ()
{
return '<b>*</b>' ;
}
2006-12-07 16:20:21 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Convertit une masse d ' une unite vers une autre unite
\param weight float Masse a convertir
\param from_unit int Unite originale en puissance de 10
\param to_unit int Nouvelle unite en puissance de 10
\return float Masse convertie
*/
2006-12-07 16:20:21 +01:00
function weight_convert ( $weight , & $from_unit , $to_unit )
{
/* Pour convertire 320 gr en Kg appeler
* $f = - 3
* weigh_convert ( 320 , $f , 0 ) retournera 0.32
*
*/
while ( $from_unit <> $to_unit )
{
if ( $from_unit > $to_unit )
{
$weight = $weight * 10 ;
$from_unit = $from_unit - 1 ;
$weight = weight_convert ( $weight , $from_unit , $to_unit );
}
if ( $from_unit < $to_unit )
{
$weight = $weight / 10 ;
$from_unit = $from_unit + 1 ;
$weight = weight_convert ( $weight , $from_unit , $to_unit );
}
}
return $weight ;
}
2007-05-11 18:01:11 +02:00
2006-12-07 16:20:21 +01:00
/**
2006-12-22 23:05:44 +01:00
\brief Renvoi le texte d ' une unite
2007-05-11 18:01:11 +02:00
\param int Unit
\param measuring_style Le style de mesure : weight , volume , ...
\return string Unite
2006-12-22 23:05:44 +01:00
\todo gerer les autres unit<EFBFBD> s de mesure comme la livre , le gallon , le litre , ...
*/
2007-05-11 18:01:11 +02:00
function measuring_units_string ( $unit , $measuring_style = '' )
2006-12-07 16:20:21 +01:00
{
/* Note Rodo aux dev : )
* Ne pas ins<EFBFBD> rer dans la base de donn<EFBFBD> es ces valeurs
* cela surchagerait inutilement d ' une requete suppl<EFBFBD> mentaire
* pour quelque chose qui est somme toute peu variable
*/
2007-05-11 18:01:11 +02:00
global $langs ;
if ( $measuring_style == 'weight' )
{
$measuring_units [ 3 ] = $langs -> trans ( " WeightUnitton " );
$measuring_units [ 0 ] = $langs -> trans ( " WeightUnitkg " );
$measuring_units [ - 3 ] = $langs -> trans ( " WeightUnitg " );
$measuring_units [ - 6 ] = $langs -> trans ( " WeightUnitmg " );
}
else if ( $measuring_style == 'volume' )
{
$measuring_units [ 0 ] = $langs -> trans ( " VolumeUnitm3 " );
$measuring_units [ - 3 ] = $langs -> trans ( " VolumeUnitcm3 " );
$measuring_units [ - 6 ] = $langs -> trans ( " VolumeUnitmm3 " );
}
2006-11-19 02:46:32 +01:00
2007-05-11 18:01:11 +02:00
return $measuring_units [ $unit ];
2006-12-07 16:20:21 +01:00
}
2007-03-19 17:28:17 +01:00
/**
2007-03-20 13:12:51 +01:00
\brief Decode le code html
\param string StringHtml
\return string DecodeString
*/
function dol_entity_decode ( $StringHtml )
{
$DecodeString = html_entity_decode ( $StringHtml );
return $DecodeString ;
}
/**
\brief Supprime le code html
2007-03-19 17:28:17 +01:00
\param string StringHtml
\return string CleanString
*/
function clean_html ( $StringHtml )
{
2007-03-19 17:38:32 +01:00
$pattern = " <[^>]+> " ;
2007-03-20 13:12:51 +01:00
$temp = dol_entity_decode ( $StringHtml );
2007-03-19 17:38:32 +01:00
$temp = ereg_replace ( $pattern , " " , $temp );
// Supprime aussi les retours
$temp = str_replace ( " \n " , " " , $temp );
// et les espaces doubles
while ( STRPOS ( $temp , " " ))
{
$temp = STR_REPLACE ( " " , " " , $temp );
}
$CleanString = $temp ;
2007-03-19 17:28:17 +01:00
return $CleanString ;
}
2007-03-23 18:58:06 +01:00
/**
2007-03-23 19:04:36 +01:00
\brief Convertir du binaire en h<EFBFBD> xad<EFBFBD> cimal
2007-03-23 18:58:06 +01:00
\param string bin
\return string x
*/
function binhex ( $bin , $pad = false , $upper = false ){
$last = strlen ( $bin ) - 1 ;
for ( $i = 0 ; $i <= $last ; $i ++ ){ $x += $bin [ $last - $i ] * pow ( 2 , $i ); }
$x = dechex ( $x );
if ( $pad ){ while ( strlen ( $x ) < intval ( strlen ( $bin )) / 4 ){ $x = " 0 $x " ; } }
if ( $upper ){ $x = strtoupper ( $x ); }
return $x ;
}
/**
\brief Convertir de l ' h<EFBFBD> xad<EFBFBD> cimal en binaire
\param string hexa
\return string bin
*/
function hexbin ( $hexa ){
$bin = '' ;
for ( $i = 0 ; $i < strlen ( $hexa ); $i ++ )
{
$bin .= str_pad ( decbin ( hexdec ( $hexa { $i })), 4 , '0' , STR_PAD_LEFT );
}
return $bin ;
}
2007-04-11 12:50:50 +02:00
// Cette fonction est appel<65> e pour coder ou non une chaine en html
// selon qu'on compte l'afficher dans le PDF avec:
// writeHTMLCell -> a besoin d'etre encod<6F> en HTML
// MultiCell -> ne doit pas etre encod<6F> en HTML
function _dol_htmlentities ( $stringtoencode , $isstringalreadyhtml )
{
global $conf ;
if ( $isstringalreadyhtml ) return $stringtoencode ;
if ( $conf -> fckeditor -> enabled ) return htmlentities ( $stringtoencode );
return $stringtoencode ;
}
2007-04-25 13:45:01 +02:00
/**
\brief Encode\decode le mot de passe de la base de donn<EFBFBD> es dans le fichier de conf
\param level niveau d ' encodage : 0 non encod<EFBFBD> , 1 encod<EFBFBD>
*/
function encodedecode_dbpassconf ( $level = 0 )
{
$config = '' ;
if ( $fp = fopen ( DOL_DOCUMENT_ROOT . '/conf/conf.php' , 'r' ))
{
while ( ! feof ( $fp ))
{
$buffer = fgets ( $fp , 4096 );
2007-04-25 16:16:27 +02:00
if ( strstr ( $buffer , " \$ dolibarr_main_db_encrypted_pass " ) && $level == 0 )
2007-04-25 13:45:01 +02:00
{
2007-04-25 16:16:27 +02:00
$passwd = strstr ( $buffer , " $dolibarr_main_db_encrypted_pass = " );
$passwd = substr ( substr ( $passwd , 2 ), 0 , - 3 );
$passwd = dolibarr_decode ( $passwd );
$config .= " \$ dolibarr_main_db_pass= \" $passwd\ " ; \n " ;
2007-04-25 13:45:01 +02:00
}
2007-04-25 16:16:27 +02:00
else if ( strstr ( $buffer , " \$ dolibarr_main_db_pass " ) && $level == 1 )
2007-04-25 13:45:01 +02:00
{
$passwd = strstr ( $buffer , " $dolibarr_main_db_pass = " );
$passwd = substr ( substr ( $passwd , 2 ), 0 , - 3 );
2007-04-25 16:16:27 +02:00
$passwd = dolibarr_encode ( $passwd );
$config .= " \$ dolibarr_main_db_encrypted_pass= \" $passwd\ " ; \n " ;
2007-04-25 13:45:01 +02:00
}
else
{
$config .= $buffer ;
}
}
fclose ( $fp );
2007-04-25 14:16:00 +02:00
if ( $fp = @ fopen ( DOL_DOCUMENT_ROOT . '/conf/conf.php' , 'w' ))
2007-04-25 13:45:01 +02:00
{
fputs ( $fp , $config , strlen ( $config ));
fclose ( $fp );
return 1 ;
}
else
{
return - 1 ;
}
}
else
{
return - 2 ;
}
}
/**
\brief Encode une chaine de caract<EFBFBD> re
\param chain chaine de caract<EFBFBD> res <EFBFBD> encoder
\return string_coded chaine de caract<EFBFBD> res encod<EFBFBD> e
*/
function dolibarr_encode ( $chain )
{
for ( $i = 0 ; $i < strlen ( $chain ); $i ++ )
{
$output_tab [ $i ] = chr ( ord ( substr ( $chain , $i , 1 )) + 17 );
}
$string_coded = base64_encode ( implode ( " " , $output_tab ));
return $string_coded ;
}
/**
\brief Decode une chaine de caract<EFBFBD> re
\param chain chaine de caract<EFBFBD> res <EFBFBD> decoder
\return string_coded chaine de caract<EFBFBD> res decod<EFBFBD> e
*/
function dolibarr_decode ( $chain )
{
$chain = base64_decode ( $chain );
for ( $i = 0 ; $i < strlen ( $chain ); $i ++ )
{
$output_tab [ $i ] = chr ( ord ( substr ( $chain , $i , 1 )) - 17 );
}
$string_decoded = implode ( " " , $output_tab );
return $string_decoded ;
}
2007-05-03 15:23:56 +02:00
/**
\brief Fonction retournant le nombre de jour f<EFBFBD> ri<EFBFBD> s samedis et dimanches entre 2 dates entr<EFBFBD> es en timestamp
\brief SERVANT AU CALCUL DES JOURS OUVRABLES
\param timestampStart Timestamp de d<EFBFBD> but
\param timestampEnd Timestamp de fin
\return nbFerie Nombre de jours f<EFBFBD> ri<EFBFBD> s
\TODO : Pr<EFBFBD> voir les jours f<EFBFBD> ri<EFBFBD> s hors France .
*/
function num_public_holiday ( $timestampStart , $timestampEnd )
{
// Initialisation de la date de d<> but
$jour = date ( " d " , $timestampStart );
$mois = date ( " m " , $timestampStart );
$annee = date ( " Y " , $timestampStart );
$nbFerie = 0 ;
while ( $timestampStart != $timestampEnd )
{
// D<> finition des dates f<> ri<72> es fixes
if ( $jour == 1 && $mois == 1 ) $nbFerie ++ ; // 1er janvier
if ( $jour == 1 && $mois == 5 ) $nbFerie ++ ; // 1er mai
if ( $jour == 8 && $mois == 5 ) $nbFerie ++ ; // 5 mai
if ( $jour == 14 && $mois == 7 ) $nbFerie ++ ; // 14 juillet
if ( $jour == 15 && $mois == 8 ) $nbFerie ++ ; // 15 aout
if ( $jour == 1 && $mois == 11 ) $nbFerie ++ ; // 1 novembre
if ( $jour == 11 && $mois == 11 ) $nbFerie ++ ; // 11 novembre
if ( $jour == 25 && $mois == 12 ) $nbFerie ++ ; // 25 d<> cembre
// Calcul du jour de p<> ques
$date_paques = easter_date ( $annee );
$jour_paques = date ( " d " , $date_paques );
$mois_paques = date ( " m " , $date_paques );
if ( $jour_paques == $jour && $mois_paques == $mois ) $nbFerie ++ ;
// P<> ques
// Calcul du jour de l ascension (38 jours apr<70> s Paques)
$date_ascension = mktime ( date ( " H " , $date_paques ),
date ( " i " , $date_paques ),
date ( " s " , $date_paques ),
date ( " m " , $date_paques ),
date ( " d " , $date_paques ) + 38 ,
date ( " Y " , $date_paques )
);
$jour_ascension = date ( " d " , $date_ascension );
$mois_ascension = date ( " m " , $date_ascension );
if ( $jour_ascension == $jour && $mois_ascension == $mois ) $nbFerie ++ ;
//Ascension
// Calcul de Pentec<65> te (11 jours apr<70> s Paques)
$date_pentecote = mktime ( date ( " H " , $date_ascension ),
date ( " i " , $date_ascension ),
date ( " s " , $date_ascension ),
date ( " m " , $date_ascension ),
date ( " d " , $date_ascension ) + 11 ,
date ( " Y " , $date_ascension )
);
$jour_pentecote = date ( " d " , $date_pentecote );
$mois_pentecote = date ( " m " , $date_pentecote );
if ( $jour_pentecote == $jour && $mois_pentecote == $mois ) $nbFerie ++ ;
//Pentecote
// Calul des samedis et dimanches
$jour_julien = unixtojd ( $timestampStart );
$jour_semaine = jddayofweek ( $jour_julien , 0 );
if ( $jour_semaine == 0 || $jour_semaine == 6 ) $nbFerie ++ ;
//Samedi (6) et dimanche (0)
// Incr<63> mentation du nombre de jour ( on avance dans la boucle)
$jour ++ ;
$timestampStart = mktime ( 0 , 0 , 0 , $mois , $jour , $annee );
}
return $nbFerie ;
}
/**
\brief Fonction retournant le nombre de jour entre deux dates
\param timestampStart Timestamp de d<EFBFBD> but
\param timestampEnd Timestamp de fin
\param lastday On prend en compte le dernier jour , 0 : non , 1 : oui
\return nbjours Nombre de jours
*/
function num_between_day ( $timestampStart , $timestampEnd , $lastday = 0 )
{
2007-05-15 17:53:46 +02:00
if ( $timestampStart < $timestampEnd )
2007-05-03 15:23:56 +02:00
{
2007-05-15 17:53:46 +02:00
if ( $lastday == 1 )
{
$bit = 0 ;
}
else
{
$bit = 1 ;
}
$nbjours = round (( $timestampEnd - $timestampStart ) / ( 60 * 60 * 24 ) - $bit );
2007-05-03 15:23:56 +02:00
}
return $nbjours ;
}
/**
\brief Fonction retournant le nombre de jour entre deux dates sans les jours f<EFBFBD> ri<EFBFBD> s
\param timestampStart Timestamp de d<EFBFBD> but
\param timestampEnd Timestamp de fin
\param inhour 0 : sort le nombre de jour , 1 : sort le nombre d ' heure
\param lastday On prend en compte le dernier jour , 0 : non , 1 : oui
\return nbjours Nombre de jours ou d ' heures
*/
function num_open_day ( $timestampStart , $timestampEnd , $inhour = 0 , $lastday = 0 )
{
2007-05-15 17:53:46 +02:00
if ( $timestampStart < $timestampEnd )
2007-05-03 15:23:56 +02:00
{
2007-05-15 17:53:46 +02:00
if ( $lastday == 1 )
{
$bit = 1 ;
}
else
{
$bit = 0 ;
}
$nbOpenDay = num_between_day ( $timestampStart , $timestampEnd , $bit ) - num_public_holiday ( $timestampStart , $timestampEnd );
if ( $inhour == 1 ) $nbOpenDay = $nbOpenDay * 24 ;
2007-05-03 15:23:56 +02:00
}
return $nbOpenDay ;
}
2007-05-08 13:13:30 +02:00
/**
\brief Fonction retournant le nombre de lignes dans un texte format<EFBFBD>
\param texte Texte
\return nblines Nombre de lignes
*/
function num_lines ( $texte )
{
$repTable = array ( " \t " => " " , " \n " => " <br> " , " \r " => " " , " \0 " => " " , " \x0B " => " " );
$texte = strtr ( $texte , $repTable );
$pattern = '/(<[^>]+>)/Uu' ;
$a = preg_split ( $pattern , $texte , - 1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
$nblines = (( count ( $a ) + 1 ) / 2 );
return $nblines ;
}
2007-06-23 09:03:20 +02:00
function ajax_indicator ( $htmlname , $indicator = 'working' )
2007-05-26 01:24:21 +02:00
{
2007-06-16 12:07:20 +02:00
$script .= '<span id="indicator' . $htmlname . '" style="display: none">' . img_picto ( 'Working...' , $indicator . '.gif' ) . '</span>' ;
2007-05-26 01:24:21 +02:00
return $script ;
}
2007-05-07 13:04:45 +02:00
/**
\brief R<EFBFBD> cup<EFBFBD> re la valeur d ' un champ , effectue un traitement Ajax et affiche le r<EFBFBD> sultat
2007-05-26 01:24:21 +02:00
\param htmlname nom et id du champ
2007-05-07 13:04:45 +02:00
\param keysearch nom et id compl<EFBFBD> mentaire du champ de collecte
2007-05-26 01:24:21 +02:00
\param url chemin du fichier de r<EFBFBD> ponse : / chemin / fichier . php
2007-05-07 13:04:45 +02:00
\param option champ suppl<EFBFBD> mentaire de recherche dans les param<EFBFBD> tres
2007-05-26 01:24:21 +02:00
\param indicator Nom de l 'image gif sans l' extension
2007-05-07 13:04:45 +02:00
\return script script complet
*/
2007-05-09 11:37:28 +02:00
function ajax_updater ( $htmlname , $keysearch , $url , $option = '' , $indicator = 'working' )
2007-05-07 13:04:45 +02:00
{
2007-06-01 21:13:08 +02:00
$script = '<input type="hidden" name="' . $htmlname . '" id="' . $htmlname . '" value="">' ;
2007-06-23 09:03:20 +02:00
if ( $indicator ) $script .= ajax_indicator ( $htmlname , $indicator );
2007-05-26 01:24:21 +02:00
$script .= '<script type="text/javascript">' ;
$script .= 'var myIndicator' . $htmlname . ' = {
2007-05-10 01:16:44 +02:00
onCreate : function (){
2007-05-10 01:30:01 +02:00
if ( $F ( " '. $keysearch . $htmlname .' " )){
2007-05-10 01:16:44 +02:00
Element . show ( \ 'indicator' . $htmlname . ' \ ' );
}
},
onComplete : function () {
if ( Ajax . activeRequestCount == 0 ){
Element . hide ( \ 'indicator' . $htmlname . ' \ ' );
}
}
}; ' ;
2007-05-26 01:24:21 +02:00
$script .= 'Ajax.Responders.register(myIndicator' . $htmlname . ');' ;
$script .= 'new Form.Element.Observer($("' . $keysearch . $htmlname . ' " ), 1,
function (){
var myAjax = new Ajax . Updater ( {
success : \ 'ajdynfield' . $htmlname . ' \ ' },
\ '' . DOL_URL_ROOT . $url . ' \ ' , {
method : \ ' get\ ' ,
parameters : " '. $keysearch .'= " + $F ( " '. $keysearch . $htmlname .' " ) + " &htmlname='. $htmlname . $option .' "
});
}); ' ;
$script .= '</script>' ;
$script .= '<div class="nocellnopadd" id="ajdynfield' . $htmlname . '"></div>' ;
2007-05-07 13:04:45 +02:00
2007-05-26 01:24:21 +02:00
return $script ;
2007-05-07 13:04:45 +02:00
}
/**
\brief R<EFBFBD> cup<EFBFBD> re la valeur d ' un champ , effectue un traitement Ajax et affiche le r<EFBFBD> sultat
\param htmlname nom et id du champ
\param url chemin du fichier de r<EFBFBD> ponse : / chemin / fichier . php
2007-05-09 11:37:28 +02:00
\param indicator nom de l 'image gif sans l' extension
2007-05-07 13:04:45 +02:00
\return script script complet
*/
2007-05-09 11:37:28 +02:00
function ajax_autocompleter ( $selected = '' , $htmlname , $url , $indicator = 'working' )
2007-05-07 13:04:45 +02:00
{
2007-06-23 09:03:20 +02:00
if ( $indicator ) $script .= ajax_indicator ( $htmlname , $indicator );
2007-05-07 13:04:45 +02:00
$script .= '<input type="hidden" name="' . $htmlname . '_id" id="' . $htmlname . '_id" value="' . $selected . '" />' ;
$script .= '</div>' ;
$script .= '<div id="result' . $htmlname . '" class="autocomplete"></div>' ;
$script .= '<script type="text/javascript">' ;
$script .= 'new Ajax.Autocompleter(\'' . $htmlname . '\',\'result' . $htmlname . '\',\'' . DOL_URL_ROOT . $url . ' \ ' ,{
method : \ ' post\ ' ,
paramName : \ '' . $htmlname . ' \ ' ,
indicator : \ 'indicator' . $htmlname . ' \ ' ,
afterUpdateElement : ac_return
}); ' ;
$script .= '</script>' ;
return $script ;
}
2007-05-03 15:23:56 +02:00
2007-05-18 16:49:48 +02:00
/**
* \brief Fonction simple identique <EFBFBD> microtime de PHP 5 mais compatible PHP 4
* \return float Time en millisecondes avec decimal pour microsecondes
*/
function dol_microtime_float ()
{
list ( $usec , $sec ) = explode ( " " , microtime ());
return (( float ) $usec + ( float ) $sec );
}
2007-05-26 17:05:49 +02:00
/*
* \brief Effectue les substitutions des mots cl<EFBFBD> s par les donn<EFBFBD> es en fonction du tableau
* \param chaine Chaine dans laquelle faire les substitutions
* \param substitutionarray Tableau cl<EFBFBD> substitution => valeur a mettre
* \return string Chaine avec les substitutions effectu<EFBFBD> es
*/
function make_substitutions ( $chaine , $substitutionarray )
{
foreach ( $substitutionarray as $key => $value )
{
$chaine = ereg_replace ( $key , $value , $chaine );
}
return $chaine ;
}
2007-06-04 22:03:40 +02:00
/*
* \brief Convertit une variable php en variable javascript
* \param var variable php
* \return result variable javascript
*/
function php2js ( $var )
{
if ( is_array ( $var ))
{
$array = array ();
foreach ( $var as $a_var )
{
$array [] = php2js ( $a_var );
}
$result = " [ " . join ( " , " , $array ) . " ] " ;
return $result ;
}
else if ( is_bool ( $var ))
{
$result = $var ? " true " : " false " ;
return $result ;
}
else if ( is_int ( $var ) || is_integer ( $var ) || is_double ( $var ) || is_float ( $var ))
{
$result = $var ;
return $result ;
}
else if ( is_string ( $var ))
{
$result = " \" " . addslashes ( stripslashes ( $var )) . " \" " ;
return $result ;
}
// autres cas: objets, on ne les g<> re pas
$result = FALSE ;
return $result ;
}
2007-07-26 18:32:30 +02:00
/*
* \brief Formate l ' affichage de date de d<EFBFBD> but et de fin
* \param date_start date de d<EFBFBD> but
* \param date_end date de fin
*/
function print_date_range ( $date_start , $date_end )
{
global $langs ;
if ( $date_start && $date_end )
{
print ' (' . $langs -> trans ( 'DateFromTo' , dolibarr_print_date ( $date_start ), dolibarr_print_date ( $date_end )) . ')' ;
}
if ( $date_start && ! $date_end )
{
print ' (' . $langs -> trans ( 'DateFrom' , dolibarr_print_date ( $date_start )) . ')' ;
}
if ( ! $date_start && $date_end )
{
print ' (' . $langs -> trans ( 'DateUntil' , dolibarr_print_date ( $date_end )) . ')' ;
}
}
2007-07-30 11:01:27 +02:00
/*
* \brief Cr<EFBFBD> ation d 'une vignette <20> partir d' une image ( $file )
* \brief Les extension prise en compte sont jpg et png
* \param file Chemin du fichier image <EFBFBD> redimensionner
* \param maxWidth Largeur maximum que dois faire la miniature ( 160 par d<EFBFBD> faut )
* \param maxHeight Hauteur maximum que dois faire l ' image ( 120 par d<EFBFBD> faut )
2007-08-09 20:22:39 +02:00
* \param extName Extension pour diff<EFBFBD> rencier le nom de la vignette
* \param quality Qualit<EFBFBD> de compression jpeg
2007-07-30 11:01:27 +02:00
* \return imgThumbName Chemin de la vignette
*/
2007-08-09 20:22:39 +02:00
function vignette ( $file , $maxWidth = 160 , $maxHeight = 120 , $extName = '_small' , $quality = 50 ){
2007-07-30 16:22:05 +02:00
2007-07-30 11:01:27 +02:00
// V<> rification des erreurs dans les param<61> tres de la fonction
//============================================================
if ( ! file_exists ( $file )){
// Si le fichier pass<73> en param<61> tre n'existe pas
return 'Le fichier ' . $file . ' n\'a pas <20> t<EFBFBD> trouv<75> sur le serveur.' ;
}
2007-08-09 20:22:39 +02:00
elseif ( ! eregi ( '(\.jpg|\.jpeg|\.png)$' , $file ))
2007-07-30 14:37:06 +02:00
{
// Todo: Ajouter cr<63> ation vignette pour les autres formats d'images
2007-08-10 10:17:57 +02:00
return 'Le fichier ' . $file . ' n\'est pas g<> r<EFBFBD> pour le moment.' ;
2007-07-30 14:37:06 +02:00
}
2007-07-30 11:01:27 +02:00
elseif ( empty ( $file )){
// Si le fichier n'a pas <20> t<EFBFBD> indiqu<71>
return 'Nom du fichier non renseign<67> .' ;
}
elseif ( ! is_numeric ( $maxWidth ) || empty ( $maxWidth ) || $maxWidth < 0 ){
// Si la largeur max est incorrecte (n'est pas num<75> rique, est vide, ou est inf<6E> rieure <20> 0)
return 'Valeur de la largeur incorrecte.' ;
}
elseif ( ! is_numeric ( $maxHeight ) || empty ( $maxHeight ) || $maxHeight < 0 ){
// Si la hauteur max est incorrecte (n'est pas num<75> rique, est vide, ou est inf<6E> rieure <20> 0)
return 'Valeur de la hauteur incorrecte.' ;
}
//============================================================
2007-07-30 16:22:05 +02:00
2007-07-30 11:01:27 +02:00
$fichier = realpath ( $file ); // Chemin canonique absolu de l'image
$dir = dirname ( $file ) . '/' ; // Chemin du dossier contenant l'image
2007-07-30 14:11:09 +02:00
$dirthumb = $dir . 'thumbs/' ; // Chemin du dossier contenant les vignettes
2007-07-30 11:01:27 +02:00
$infoImg = getimagesize ( $fichier ); // R<> cup<75> ration des infos de l'image
$imgWidth = $infoImg [ 0 ]; // Largeur de l'image
$imgHeight = $infoImg [ 1 ]; // Hauteur de l'image
2007-07-30 16:22:05 +02:00
// Si l'image est plus petite que la largeur et le hauteur max, on ne cr<63> e pas de vignette
if ( $infoImg [ 0 ] < $maxWidth && $infoImg [ 1 ] < $maxHeight )
{
return 'Le fichier ' . $file . ' ne n<> cessite pas de cr<63> ation de vignette' ;
}
2007-07-30 13:55:12 +02:00
// On cr<63> e le r<> pertoire contenant les vignettes
if ( ! file_exists ( $dirthumb ))
{
dolibarr_syslog ( " Product Create $dirthumb " );
create_exdir ( $dirthumb );
}
2007-07-30 14:37:06 +02:00
2007-07-30 13:55:12 +02:00
2007-07-30 11:01:27 +02:00
// Initialisation des variables selon l'extension de l'image
switch ( $infoImg [ 2 ]){
case 2 :
$img = imagecreatefromjpeg ( $fichier ); // Cr<43> ation d'une nouvelle image jpeg <20> partir du fichier
$extImg = '.jpg' ; // Extension de l'image
break ;
case 3 :
$img = imagecreatefrompng ( $fichier ); // Cr<43> ation d'une nouvelle image png <20> partir du fichier
$extImg = '.png' ;
}
// Initialisation des dimensions de la vignette si elles sont sup<75> rieures <20> l'original
if ( $maxWidth > $imgWidth ){ $maxWidth = $imgWidth ; }
if ( $maxHeight > $imgHeight ){ $maxHeight = $imgHeight ; }
$whFact = $maxWidth / $maxHeight ; // Facteur largeur/hauteur des dimensions max de la vignette
$imgWhFact = $imgWidth / $imgHeight ; // Facteur largeur/hauteur de l'original
// Fixe les dimensions de la vignette
if ( $whFact < $imgWhFact ){
// Si largeur d<> terminante
$thumbWidth = $maxWidth ;
$thumbHeight = $thumbWidth / $imgWhFact ;
} else {
// Si hauteur d<> terminante
$thumbHeight = $maxHeight ;
$thumbWidth = $thumbHeight * $imgWhFact ;
}
$imgThumb = imagecreatetruecolor ( $thumbWidth , $thumbHeight ); // Cr<43> ation de la vignette
imagecopyresized ( $imgThumb , $img , 0 , 0 , 0 , 0 , $thumbWidth , $thumbHeight , $imgWidth , $imgHeight ); // Ins<6E> re l'image de base redimensionn<6E> e
2007-07-30 13:55:12 +02:00
2007-08-10 10:17:57 +02:00
$fileName = eregi_replace ( '(\.jpeg|\.jpg|\.png)$' , '' , $file ); // On enleve extension quelquesoit la casse
$fileName = basename ( $fileName );
2007-08-09 20:22:39 +02:00
$imgThumbName = $dirthumb . $fileName . $extName . $extImg ; // Chemin complet du fichier de la vignette
2007-07-30 11:01:27 +02:00
//Cr<43> ation du fichier de la vignette
$fp = fopen ( $imgThumbName , " w " );
fclose ( $fp );
// Renvoi la vignette cr<63> <72> e
switch ( $infoImg [ 2 ]){
case 2 :
2007-08-10 10:19:35 +02:00
imagejpeg ( $imgThumb , $imgThumbName , $quality ); // Renvoi d'une image jpeg avec une qualit<69> de 50 par d<> faut
2007-07-30 11:01:27 +02:00
break ;
case 3 :
imagepng ( $imgThumb , $imgThumbName );
}
return $imgThumbName ;
}
2002-04-30 12:44:42 +02:00
?>