dolibarr  7.0.0-beta
Functions
functions2.lib.php File Reference

A set of functions for Dolibarr This file contains all rare functions. More...

Go to the source code of this file.

Functions

 jsUnEscape ($source)
 Same function than javascript unescape() function but in PHP. More...
 
 dolGetModulesDirs ($subdir='')
 Return list of modules directories. More...
 
 dol_getDefaultFormat (Translate $outputlangs=null)
 Try to guess default paper format according to language into $langs. More...
 
 dol_print_file ($langs, $filename, $searchalt=0)
 Output content of a file $filename in version of current language (otherwise may use an alternate language) More...
 
 dol_print_object_info ($object, $usetable=0)
 Show informations on an object TODO Move this into html.formother. More...
 
 dolAddEmailTrackId ($email, $trackingid)
 Return an email formatted to include a tracking id For example myema.nosp@m.il@e.nosp@m.xampl.nosp@m.e.co.nosp@m.m becom myema.nosp@m.il+t.nosp@m.racki.nosp@m.ngid.nosp@m.@exam.nosp@m.ple..nosp@m.com. More...
 
 isValidMailDomain ($mail)
 Return true if email has a domain name that can't be resolved. More...
 
 isValidUrl ($url, $http=0, $pass=0, $port=0, $path=0, $query=0, $anchor=0)
 Url string validation <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor]. More...
 
 clean_url ($url, $http=1)
 Clean an url string. More...
 
 dolObfuscateEmail ($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdisplaydomain=3, $displaytld=true)
 Returns an email value with obfuscated parts. More...
 
 array2tr ($data, $troptions='', $tdoptions='')
 Return lines of an html table from an array Used by array2table function only. More...
 
 array2table ($data, $tableMarkup=1, $tableoptions='', $troptions='', $tdoptions='')
 Return an html table from an array. More...
 
 get_next_value ($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null)
 Return last or next value for a mask (according to area we should not reset) More...
 
 check_value ($mask, $value)
 Check value. More...
 
 binhex ($bin, $pad=false, $upper=false)
 Convert a binary data to string that represent hexadecimal value. More...
 
 hexbin ($hexa)
 Convert an hexadecimal string into a binary string. More...
 
 numero_semaine ($time)
 Retourne le numero de la semaine par rapport a une date. More...
 
 weight_convert ($weight, &$from_unit, $to_unit)
 Convertit une masse d'une unite vers une autre unite. More...
 
 dol_set_user_param ($db, $conf, &$user, $tab)
 Save personnal parameter. More...
 
 dol_print_reduction ($reduction, $langs)
 Returns formated reduction. More...
 
 version_os ()
 Return OS version. More...
 
 version_php ()
 Return PHP version. More...
 
 version_dolibarr ()
 Return Dolibarr version. More...
 
 version_webserver ()
 Return web server version. More...
 
 getListOfModels ($db, $type, $maxfilenamelength=0)
 Return list of activated modules usable for document generation. More...
 
 is_ip ($ip)
 This function evaluates a string that should be a valid IPv4 Note: For ip 169.254.0.0, it returns 0 with some PHP (5.6.24) and 2 with some minor patchs of PHP (5.6.25). More...
 
 dol_buildlogin ($lastname, $firstname)
 Build a login from lastname, firstname. More...
 
 getSoapParams ()
 Return array to use for SoapClient constructor. More...
 
 dolGetElementUrl ($objectid, $objecttype, $withpicto=0, $option='')
 List urls of element. More...
 
 cleanCorruptedTree ($db, $tabletocleantree, $fieldfkparent)
 Clean corrupted tree (orphelins linked to a not existing parent), record linked to themself and child-parent loop. More...
 
 getElementProperties ($element_type)
 Get an array with properties of an element. More...
 
 fetchObjectByElement ($element_id, $element_type, $element_ref='')
 Fetch an object from its id and element_type Inclusion of classes is automatic. More...
 
 colorArrayToHex ($arraycolor, $colorifnotfound='888888')
 Convert an array with RGB value into hex RGB value. More...
 
 colorStringToArray ($stringcolor, $colorifnotfound=array(88, 88, 88))
 Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,255). More...
 
 cartesianArray (array $input)
 Applies the Cartesian product algorithm to an array Source: http://stackoverflow.com/a/15973172. More...
 
 getModuleDirForApiClass ($module)
 Get name of directory where the api_...class.php file is stored. More...
 

Detailed Description

A set of functions for Dolibarr This file contains all rare functions.

Definition in file functions2.lib.php.

Function Documentation

array2table (   $data,
  $tableMarkup = 1,
  $tableoptions = '',
  $troptions = '',
  $tdoptions = '' 
)

Return an html table from an array.

Parameters
array$dataArray of data
int$tableMarkupTable markup
string$tableoptionsOptions for table
string$troptionsOptions for tr
string$tdoptionsOptions for td
Returns
string

Definition at line 680 of file functions2.lib.php.

References array2tr().

array2tr (   $data,
  $troptions = '',
  $tdoptions = '' 
)

Return lines of an html table from an array Used by array2table function only.

Parameters
array$dataArray of data
string$troptionsOptions for tr
string$tdoptionsOptions for td
Returns
string

Definition at line 660 of file functions2.lib.php.

Referenced by array2table().

binhex (   $bin,
  $pad = false,
  $upper = false 
)

Convert a binary data to string that represent hexadecimal value.

Parameters
string$binValue to convert
boolean$padAdd 0
boolean$upperConvert to tupper
Returns
string x

Definition at line 1277 of file functions2.lib.php.

References dol_strlen().

cartesianArray ( array  $input)

Applies the Cartesian product algorithm to an array Source: http://stackoverflow.com/a/15973172.

Parameters
array$inputArray of products
Returns
array Array of combinations

Definition at line 2165 of file functions2.lib.php.

check_value (   $mask,
  $value 
)

Check value.

Parameters
string$maskMask to use
string$valueValue
Returns
int|string <0 or error string if KO, 0 if OK

Definition at line 1168 of file functions2.lib.php.

References dol_string_nospecial(), dol_strlen(), and dol_syslog().

Referenced by mod_codeproduct_elephant\verif(), mod_codeclient_elephant\verif(), and mod_barcode_product_standard\verif_syntax().

clean_url (   $url,
  $http = 1 
)

Clean an url string.

Parameters
string$urlUrl
integer$http1 = keep both http:// and https://, 0: remove http:// but not https://
Returns
string Cleaned url

Definition at line 573 of file functions2.lib.php.

Referenced by Link\update(), and Societe\update().

cleanCorruptedTree (   $db,
  $tabletocleantree,
  $fieldfkparent 
)

Clean corrupted tree (orphelins linked to a not existing parent), record linked to themself and child-parent loop.

Parameters
DoliDB$dbDatabase handler
string$tabletocleantreeTable to clean
string$fieldfkparentField name that contains id of parent
Returns
int Nb of records fixed/deleted

Definition at line 1861 of file functions2.lib.php.

References $resql, dol_print_error(), and print.

colorArrayToHex (   $arraycolor,
  $colorifnotfound = '888888' 
)

Convert an array with RGB value into hex RGB value.

This is the opposite function of colorStringToArray

Parameters
array$arraycolorArray
string$colorifnotfoundColor code to return if entry not defined or not a RGB format
Returns
string RGB hex value (without # before). For example: 'FF00FF', '01FF02'
See also
colorStringToArray

Definition at line 2128 of file functions2.lib.php.

Referenced by show_theme(), and FormOther\showColor().

colorStringToArray (   $stringcolor,
  $colorifnotfound = array(88,88,88) 
)

Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,255).

This is the opposite function of colorArrayToHex. If entry is already an array, return it.

Parameters
string$stringcolorString with hex (FFFFFF) or comma RGB ('255,255,255')
array$colorifnotfoundColor code array to return if entry not defined
Returns
string RGB hex value (without # before). For example: FF00FF
See also
colorArrayToHex

Definition at line 2145 of file functions2.lib.php.

Referenced by show_theme(), and FormOther\showColor().

dol_buildlogin (   $lastname,
  $firstname 
)

Build a login from lastname, firstname.

Parameters
string$lastnameLastname
string$firstnameFirstname
Returns
string Login

Definition at line 1689 of file functions2.lib.php.

References dol_string_nospecial(), and dol_string_unaccent().

Referenced by ActionsContactCardCommon\assign_values(), and ActionsAdherentCardCommon\assign_values().

dol_getDefaultFormat ( Translate  $outputlangs = null)

Try to guess default paper format according to language into $langs.

Parameters
Translate$outputlangsOutput lang to use to autodetect output format if setup not done
Returns
string Default paper format code

Definition at line 123 of file functions2.lib.php.

Referenced by pdf_getFormat().

dol_print_file (   $langs,
  $filename,
  $searchalt = 0 
)

Output content of a file $filename in version of current language (otherwise may use an alternate language)

Parameters
Translate$langsObject language to use for output
string$filenameRelative filename to output
int$searchalt1=Search also in alternative languages
Returns
boolean true if OK, false if KO

Definition at line 145 of file functions2.lib.php.

References dol_syslog(), print, and utf8_check().

dol_print_object_info (   $object,
  $usetable = 0 
)

Show informations on an object TODO Move this into html.formother.

Parameters
object$objectObjet to show
int$usetableOutput into a table
Returns
void

Definition at line 195 of file functions2.lib.php.

References dol_print_date(), getServerTimeZoneInt(), and print.

dol_print_reduction (   $reduction,
  $langs 
)

Returns formated reduction.

Parameters
int$reductionReduction percentage
Translate$langsOutput language
Returns
string Formated reduction

Definition at line 1497 of file functions2.lib.php.

References price().

Referenced by pdf_getlineremisepercent().

dol_set_user_param (   $db,
  $conf,
$user,
  $tab 
)

Save personnal parameter.

Parameters
DoliDB$dbHandler database
Conf$confObject conf
User$userObject user
array$tabArray (key=>value) with all parameters to save
Returns
int <0 if KO, >0 if OK
See also
dolibarr_get_const, dolibarr_set_const, dolibarr_del_const

Definition at line 1430 of file functions2.lib.php.

References $resql, dol_print_error(), and dol_syslog().

Referenced by InfoBox\saveboxorder().

dolAddEmailTrackId (   $email,
  $trackingid 
)

Return an email formatted to include a tracking id For example myema.nosp@m.il@e.nosp@m.xampl.nosp@m.e.co.nosp@m.m becom myema.nosp@m.il+t.nosp@m.racki.nosp@m.ngid.nosp@m.@exam.nosp@m.ple..nosp@m.com.

Parameters
string$emailEmail address (Ex: "toto@example.com", "John Do <johndo@example.com>")
string$trackingidTracking id (Ex: thi123 for thirdparty with id 123)
Returns
string Return email tracker string

Definition at line 492 of file functions2.lib.php.

dolGetElementUrl (   $objectid,
  $objecttype,
  $withpicto = 0,
  $option = '' 
)

List urls of element.

Parameters
int$objectidId of record
string$objecttypeType of object ('invoice', 'order', 'expedition_bon', ...)
int$withpictoPicto to show
string$optionMore options
Returns
string URL of link to object id/type

Definition at line 1753 of file functions2.lib.php.

References dol_include_once().

dolGetModulesDirs (   $subdir = '')

Return list of modules directories.

We detect directories that contains a subdirectory /core/modules We discard directory modules that contains 'disabled' into their name.

Parameters
string$subdirSub directory (Example: '/mailings')
Returns
array Array of directories that can contains module descriptors

Definition at line 81 of file functions2.lib.php.

Referenced by activateModule(), activateModulesRequiredByCountry(), complete_dictionary_with_modules(), complete_elementList_with_modules(), Import\load_arrays(), Export\load_arrays(), and unActivateModule().

dolObfuscateEmail (   $mail,
  $replace = "*",
  $nbreplace = 8,
  $nbdisplaymail = 4,
  $nbdisplaydomain = 3,
  $displaytld = true 
)

Returns an email value with obfuscated parts.

Parameters
string$mailEmail
string$replaceReplacement character (defaul: *)
int$nbreplaceNumber of replacement character (default: 8)
int$nbdisplaymailNumber of character unchanged (default: 4)
int$nbdisplaydomainNumber of character unchanged of domain (default: 3)
bool$displaytldDisplay tld (default: true)
Returns
string Return email with hidden parts or '';

Definition at line 619 of file functions2.lib.php.

References isValidEmail().

fetchObjectByElement (   $element_id,
  $element_type,
  $element_ref = '' 
)

Fetch an object from its id and element_type Inclusion of classes is automatic.

Parameters
int$element_idElement id
string$element_typeElement type
ref$element_refElement ref (Use this if element_id but not both)
Returns
int|object object || 0 || -1 if error

Definition at line 2098 of file functions2.lib.php.

References getElementProperties().

Referenced by Dolresource\fetch_all_resources(), Dolresource\fetch_all_used(), and Dolresource\fetch_element_resource().

get_next_value (   $db,
  $mask,
  $table,
  $field,
  $where = '',
  $objsoc = '',
  $date = '',
  $mode = 'next',
  $bentityon = true,
  $objuser = null 
)

Return last or next value for a mask (according to area we should not reset)

Parameters
DoliDB$dbDatabase handler
string$maskMask to use
string$tableTable containing field with counter
string$fieldField containing already used values of counter
string$whereTo add a filter on selection (for exemple to filter on invoice types)
Societe$objsocThe company that own the object we need a counter for
string$dateDate to use for the {y},{m},{d} tags.
string$mode'next' for next value or 'last' for last value
bool$bentityonActivate the entity filter. Default is true (for modules not compatible with multicompany)
User$objuserObject user we need data from.
Returns
string New value (numeric) or error message

Definition at line 713 of file functions2.lib.php.

References $resql, dol_mktime(), dol_now(), dol_print_error(), dol_string_nospecial(), dol_strlen(), and dol_syslog().

Referenced by mod_contract_magre\getNextValue(), mod_expedition_ribera\getNextValue(), mod_supplier_payment_brodator\getNextValue(), mod_chequereceipt_thyme\getNextValue(), mod_payment_ant\getNextValue(), mod_expensereport_sand\getNextValue(), mod_arctic\getNextValue(), mod_livraison_saphir\getNextValue(), mod_project_universal\getNextValue(), mod_task_universal\getNextValue(), mod_commande_fournisseur_orchidee\getNextValue(), mod_supplier_proposal_saphir\getNextValue(), mod_commande_saphir\getNextValue(), mod_propale_saphir\getNextValue(), mod_facture_mercure\getNextValue(), mod_barcode_product_standard\getNextValue(), mod_facture_fournisseur_tulip\getNextValue(), mod_codeproduct_elephant\getNextValue(), and mod_codeclient_elephant\getNextValue().

getElementProperties (   $element_type)

Get an array with properties of an element.

Parameters
string$element_typeElement type: 'action', 'facture', 'project_task' or 'object'...
Returns
array (module, classpath, element, subelement, classfile, classname)

Definition at line 1978 of file functions2.lib.php.

Referenced by fetchObjectByElement().

getListOfModels (   $db,
  $type,
  $maxfilenamelength = 0 
)
getModuleDirForApiClass (   $module)

Get name of directory where the api_...class.php file is stored.

Parameters
string$moduleModule name
Returns
string Directory name

Definition at line 2194 of file functions2.lib.php.

getSoapParams ( )

Return array to use for SoapClient constructor.

Returns
array

Definition at line 1703 of file functions2.lib.php.

hexbin (   $hexa)

Convert an hexadecimal string into a binary string.

Parameters
string$hexaHexadecimal string to convert (example: 'FF')
Returns
string bin

Definition at line 1293 of file functions2.lib.php.

References dol_strlen().

is_ip (   $ip)

This function evaluates a string that should be a valid IPv4 Note: For ip 169.254.0.0, it returns 0 with some PHP (5.6.24) and 2 with some minor patchs of PHP (5.6.25).

See https://github.com/php/php-src/pull/1954.

Parameters
string$ipIP Address
Returns
int 0 if not valid or reserved range, 1 if valid and public IP, 2 if valid and private range IP

Definition at line 1665 of file functions2.lib.php.

Referenced by SMTPs\_server_connect().

isValidMailDomain (   $mail)

Return true if email has a domain name that can't be resolved.

Parameters
string$mailEmail address (Ex: "toto@example.com", "John Do <johndo@example.com>")
Returns
boolean True if domain email is OK, False if KO

Definition at line 504 of file functions2.lib.php.

isValidUrl (   $url,
  $http = 0,
  $pass = 0,
  $port = 0,
  $path = 0,
  $query = 0,
  $anchor = 0 
)

Url string validation <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor].

Parameters
string$urlUrl
int$http1: verify http is provided, 0: not verify http
int$pass1: verify user and pass is provided, 0: not verify user and pass
int$port1: verify port is provided, 0: not verify port
int$path1: verify a path is provided "/" or "/..." or "/.../", 0: not verify path
int$query1: verify query is provided, 0: not verify query
int$anchor1: verify anchor is provided, 0: not verify anchor
Returns
int 1=Check is OK, 0=Check is KO

Definition at line 530 of file functions2.lib.php.

Referenced by ActionsCardCommon\doActions().

jsUnEscape (   $source)

Same function than javascript unescape() function but in PHP.

Parameters
string$sourceString to decode
Returns
string Unescaped string

Definition at line 40 of file functions2.lib.php.

References dol_html_entity_decode().

numero_semaine (   $time)

Retourne le numero de la semaine par rapport a une date.

Parameters
string$timeDate au format 'timestamp'
Returns
string Number of week

Definition at line 1310 of file functions2.lib.php.

version_dolibarr ( )

Return Dolibarr version.

Returns
string Dolibarr version
See also
versiondolibarrarray

Definition at line 1541 of file functions2.lib.php.

version_os ( )

Return OS version.

Note that PHP_OS returns only OS (not version) and OS PHP was built on, not necessarly OS PHP runs on.

Returns
string OS version

Definition at line 1518 of file functions2.lib.php.

version_php ( )

Return PHP version.

Returns
string PHP version
See also
versionphparray

Definition at line 1530 of file functions2.lib.php.

version_webserver ( )

Return web server version.

Returns
string Web server version

Definition at line 1551 of file functions2.lib.php.

weight_convert (   $weight,
$from_unit,
  $to_unit 
)

Convertit une masse d'une unite vers une autre unite.

Parameters
float$weightMasse a convertir
int$from_unitUnite originale en puissance de 10
int$to_unitNouvelle unite en puissance de 10
Returns
float Masse convertie

Definition at line 1393 of file functions2.lib.php.