dolibarr 23.0.3
admin.lib.php File Reference

Library of admin functions. More...

Go to the source code of this file.

Functions

 versiontostring ($versionarray)
 Renvoi une version en chaine depuis une version en tableau.
 
 versioncompare ($versionarray1, $versionarray2)
 Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,y,z) To check using a string version do a preg_split('/[.
 
 versionphparray ()
 Return version PHP.
 
 versiondolibarrarray ()
 Return version Dolibarr.
 
 run_sql ($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
 Launch a sql file.
 
 dolibarr_del_const ($db, $name, $entity=1)
 Delete a constant.
 
 dolibarr_get_const ($db, $name, $entity=1)
 Get the value of a setup constant from database.
 
 dolibarr_set_const ($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
 Insert a parameter (key,value) into database (delete old key then insert it again).
 
 modules_prepare_head ($nbofactivatedmodules, $nboftotalmodules, $nbmodulesnotautoenabled)
 Prepare array with list of tabs.
 
 ihm_prepare_head ()
 Prepare array with list of tabs.
 
 security_prepare_head ()
 Prepare array with list of tabs.
 
 modulehelp_prepare_head ($object)
 Prepare array with list of tabs.
 
 translation_prepare_head ()
 Prepare array with list of tabs.
 
 defaultvalues_prepare_head ()
 Prepare array with list of tabs.
 
 listOfSessions ()
 Return list of session.
 
 purgeSessions ($mysessionid)
 Purge existing sessions.
 
 form_constantes ($tableau, $strictw3c=2, $helptext='', $text='')
 Show array with constants to edit.
 
 showModulesExludedForExternal ($modules)
 Show array with constants to edit.
 
 addDocumentModel ($name, $type, $label='', $description='')
 Add document model used by doc generator.
 
 delDocumentModel ($name, $type)
 Delete document model used by doc generator.
 
 phpinfo_array ()
 Return the php_info into an array.
 
 company_admin_prepare_head ()
 Return array head with list of tabs to view object information.
 
 email_admin_prepare_head ()
 Return array head with list of tabs to view object information.
 
 GetContentPolicyDirectives ()
 Prepare array of directives for HTTP headers.
 
 GetContentPolicySources ()
 Prepare array of sources for HTTP headers.
 
 GetContentPolicyToArray ($forceCSP)
 Transform a Content Security Policy to an array.
 

Detailed Description

Library of admin functions.

Definition in file admin.lib.php.

Function Documentation

◆ addDocumentModel()

addDocumentModel ( $name,
$type,
$label = '',
$description = '' )

Add document model used by doc generator.

Parameters
string$nameModel name
string$typeModel type
string$labelModel label
string$descriptionModel description
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 1993 of file admin.lib.php.

References dol_print_error(), and dol_syslog().

◆ company_admin_prepare_head()

company_admin_prepare_head ( )

Return array head with list of tabs to view object information.

Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 2082 of file admin.lib.php.

References complete_head_from_modules().

◆ defaultvalues_prepare_head()

defaultvalues_prepare_head ( )

Prepare array with list of tabs.

Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 1026 of file admin.lib.php.

References complete_head_from_modules().

◆ delDocumentModel()

delDocumentModel ( $name,
$type )

Delete document model used by doc generator.

Parameters
string$nameModel name
string$typeModel type
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 2024 of file admin.lib.php.

References dol_print_error(), and dol_syslog().

◆ dolibarr_del_const()

dolibarr_del_const ( $db,
$name,
$entity = 1 )

Delete a constant.

Parameters
DoliDB$dbDatabase handler
int | string$nameName of constant or rowid of line
int$entityMulti company id, -1 for all entities
Returns
int Return integer <0 if KO, >0 if OK
See also
dolibarr_get_const(), dolibarr_set_const(), dol_set_user_param()

Definition at line 585 of file admin.lib.php.

References dol_print_error(), and dol_syslog().

◆ dolibarr_get_const()

dolibarr_get_const ( $db,
$name,
$entity = 1 )

Get the value of a setup constant from database.

Parameters
DoliDB$dbDatabase handler
string$nameName of constant
int$entityMulti company id
Returns
string Value of constant
See also
dolibarr_del_const(), dolibarr_set_const(), dol_set_user_param()

Definition at line 639 of file admin.lib.php.

References dol_syslog(), and dolDecrypt().

◆ dolibarr_set_const()

dolibarr_set_const ( $db,
$name,
$value,
$type = 'chaine',
$visible = 0,
$note = '',
$entity = 1 )

Insert a parameter (key,value) into database (delete old key then insert it again).

Parameters
DoliDB$dbDatabase handler
string$nameName of constant
int | string$valueValue of constant
string$typeType of constant. Deprecated, only strings are allowed for $value. Caller must json encode/decode to store other type of data.
int$visibleIs constant visible in Setup->Other page (0 by default)
string$noteNote on parameter
int$entityMulti company id (0 means all entities)
Returns
int -1 if KO, 1 if OK
See also
dolibarr_del_const(), dolibarr_get_const(), dol_set_user_param()

Definition at line 675 of file admin.lib.php.

References dol_print_error(), dol_syslog(), and dolEncrypt().

Referenced by modGeneratePassPerso\__construct(), DolibarrApiAccess\__isAllowed(), BlockedLog\getOrInitFirstSignature(), mod_codeclient_elephant\info(), modBlockedLog\init(), modEventOrganization\init(), modProductBatch\init(), modTakePos\init(), migrate_accountingbookkeeping(), migrate_blockedlog_add_hmac_key(), migrate_invoice_export_models(), FormSetupItem\saveConfValue(), and top_htmlhead().

◆ email_admin_prepare_head()

email_admin_prepare_head ( )

Return array head with list of tabs to view object information.

Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 2121 of file admin.lib.php.

References complete_head_from_modules(), getDolGlobalString(), and isModEnabled().

◆ form_constantes()

form_constantes ( $tableau,
$strictw3c = 2,
$helptext = '',
$text = '' )

Show array with constants to edit.

Parameters
array<string,array{type:string,label:string,tooltip?:string}>|array<int,string>$tableau Array of constants array('key'=>array('type'=>type, 'label'=>label, 'tooltip'=>tooltip) where type can be 'string', 'text', 'textarea', 'html', 'yesno', 'emailtemplate:xxx', ...
int<2,3>$strictw3c 0=Include form into table (deprecated), 1=Form is outside table to respect W3C (deprecated), 2=No form nor button at all, 3=No form nor button at all and each field has a unique name (form is output by caller, recommended) (typed as int<2,3> to highlight the deprecated values)
string$helptextTooltip help to use for the column name of values
string$textText to use for the column name of values
Returns
void

Definition at line 1768 of file admin.lib.php.

References dol_escape_htmltag(), dol_syslog(), dolBuildUrl(), img_down(), img_picto(), and isModEnabled().

◆ GetContentPolicyDirectives()

GetContentPolicyDirectives ( )

Prepare array of directives for HTTP headers.

Returns
array<string,array<string,string>> Array of directives

Definition at line 2184 of file admin.lib.php.

◆ GetContentPolicySources()

GetContentPolicySources ( )

Prepare array of sources for HTTP headers.

Returns
array<string,array<string,array<string,string>>> Array of sources

Definition at line 2226 of file admin.lib.php.

Referenced by GetContentPolicyToArray().

◆ GetContentPolicyToArray()

GetContentPolicyToArray ( $forceCSP)

Transform a Content Security Policy to an array.

Parameters
string$forceCSPContent security policy string
Returns
array<string,array<string|int,array<string|int,string>|string>> Array of sources

Definition at line 2281 of file admin.lib.php.

References GetContentPolicySources().

◆ ihm_prepare_head()

ihm_prepare_head ( )

Prepare array with list of tabs.

Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 813 of file admin.lib.php.

References complete_head_from_modules(), and dolBuildUrl().

◆ listOfSessions()

listOfSessions ( )

Return list of session.

Returns
array<string,array{login:string,age:int,creation:null|int|false,modification:int|false,raw:string,remote_ip:?string,user_agent:?string}> Array list of sessions

Definition at line 1078 of file admin.lib.php.

References dol_osencode(), dol_syslog(), dolListSessions(), and getDolGlobalString().

◆ modulehelp_prepare_head()

modulehelp_prepare_head ( $object)

Prepare array with list of tabs.

Parameters
DolibarrModules$objectDescriptor class
Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 958 of file admin.lib.php.

References $object, complete_head_from_modules(), and dolBuildUrl().

◆ modules_prepare_head()

modules_prepare_head ( $nbofactivatedmodules,
$nboftotalmodules,
$nbmodulesnotautoenabled )

Prepare array with list of tabs.

Parameters
int$nbofactivatedmodulesNumber if activated modules
int$nboftotalmodulesNb of total modules
int$nbmodulesnotautoenabledNb of modules not auto enabled that are activated
Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 767 of file admin.lib.php.

References dolBuildUrl(), getDolGlobalInt(), getDolGlobalString(), and img_picto().

◆ phpinfo_array()

phpinfo_array ( )

Return the php_info into an array.

Returns
array<string,array<string,string|array{local:string,master:string}>> Array with PHP info

Definition at line 2053 of file admin.lib.php.

◆ purgeSessions()

purgeSessions ( $mysessionid)

Purge existing sessions.

Parameters
string$mysessionidTo avoid to try to delete my own session
Returns
int >0 if OK, <0 if KO

Definition at line 1142 of file admin.lib.php.

References dol_osencode(), dol_syslog(), and getDolGlobalString().

◆ run_sql()

run_sql ( $sqlfile,
$silent = 1,
$entity = 0,
$usesavepoint = 1,
$handler = '',
$okerror = 'default',
$linelengthlimit = 32768,
$nocommentremoval = 0,
$offsetforchartofaccount = 0,
$colspan = 0,
$onlysqltoimportwebsite = 0,
$database = '' )

Launch a sql file.

Function is used by:

  • Migrate process (dolibarr-xyz-abc.sql)
  • Loading sql menus (auguria)
  • Running specific Sql by a module init
  • Loading sql file of website import package Install process however does not use it. Note that SQL files must have all comments at start of line. Also this function take ';' as the char to detect end of sql request
Parameters
string$sqlfileFull path to sql file
int$silent1=Do not output anything, 0=Output line for update page
int$entityEntity targeted for multicompany module
int$usesavepoint1=Run a savepoint before each request and a rollback to savepoint if error (this allow to have some request with errors inside global transactions).
string$handlerHandler targeted for menu (replace HANDLER with this value between quotes)
string$okerrorFamily of errors we accept ('default', 'none')
int$linelengthlimitLimit for length of each line (Use 0 if unknown, may be faster if defined)
int$nocommentremovalDo no try to remove comments (in such a case, we consider that each line is a request, so use also $linelengthlimit=0)
int$offsetforchartofaccountOffset to use to load chart of account table to update sql on the fly to add offset to rowid and account_parent value
int$colspan2=Add a colspan=2 on td
int$onlysqltoimportwebsiteOnly sql requests used to import a website template are allowed. This is a security feature to disallow SQL injection when loading a template.
string$databaseDatabase (replace DATABASE with this value)
Returns
int Return integer <=0 if KO, >0 if OK

Definition at line 173 of file admin.lib.php.

References checkPHPCode(), dol_htmlentities(), dol_syslog(), dolKeepOnlyPhpCode(), and versioncompare().

Referenced by DolibarrModules\_load_tables(), and migrate_reload_menu().

◆ security_prepare_head()

security_prepare_head ( )

Prepare array with list of tabs.

Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 865 of file admin.lib.php.

References dol_print_error(), dolBuildUrl(), and getDolGlobalString().

◆ showModulesExludedForExternal()

showModulesExludedForExternal ( $modules)

Show array with constants to edit.

Parameters
DolibarrModules[]$modulesArray of all modules
Returns
string HTML string with warning

Definition at line 1943 of file admin.lib.php.

References dol_sort_array(), and getDolGlobalString().

◆ translation_prepare_head()

translation_prepare_head ( )

Prepare array with list of tabs.

Returns
array<array{0:string,1:string,2:string}> Array of tabs to show

Definition at line 996 of file admin.lib.php.

References complete_head_from_modules(), and dolBuildUrl().

◆ versioncompare()

versioncompare ( $versionarray1,
$versionarray2 )

Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,y,z) To check using a string version do a preg_split('/[.

-]/', strinversion) to convert the string into an array. To check with Dolibarr version use versiondolibarrarray() to get the array of Dolibarr current version

For example: if (versioncompare(versiondolibarrarray(),array(4,0,-5)) >= 0) is true if version is 4.0 alpha or higher. For example: if (versioncompare(versiondolibarrarray(),array(4,0,0)) >= 0) is true if version is 4.0 final or higher. For example: if (versioncompare(versiondolibarrarray(),array(4,0,1)) >= 0) is true if version is 4.0.1 or higher. Alternative way to compare: if ((float) DOL_VERSION >= 4.0) is true if version is 4.0 alpha or higher (works only to compare first and second level)

Parameters
array<int|string>$versionarray1 Array of version (vermajor,verminor,patch)
array<int|string>$versionarray2 Array of version (vermajor,verminor,patch)
Returns
int<-4,4> -4,-3,-2,-1 if versionarray1<versionarray2 (value depends on level of difference) 0 if same 1,2,3,4 if versionarray1>versionarray2 (value depends on level of difference)
See also
versiontostring()

Definition at line 71 of file admin.lib.php.

Referenced by ImportCsv\__construct(), ImportXlsx\__construct(), migrate_invoice_export_models(), migrate_restore_missing_links(), and run_sql().

◆ versiondolibarrarray()

versiondolibarrarray ( )

Return version Dolibarr.

Returns
array<int<0,2>,string> Array of version (vermajor,verminor,vermaintenance,other)
See also
versioncompare()

Definition at line 144 of file admin.lib.php.

◆ versionphparray()

versionphparray ( )

Return version PHP.

Returns
array<int<0,2>,string> Tableau de version (vermajeur,vermineur,autre)
See also
versioncompare()

Definition at line 133 of file admin.lib.php.

Referenced by ImportCsv\__construct(), and ImportXlsx\__construct().

◆ versiontostring()

versiontostring ( $versionarray)

Renvoi une version en chaine depuis une version en tableau.

Parameters
array<int<0,2>,int|string>$versionarray Tableau de version (vermajeur,vermineur,autre)
Returns
string Chaine version
See also
versioncompare()

Definition at line 39 of file admin.lib.php.