2015-05-01 14:12:30 +00:00
< ? php
2025-01-06 17:20:18 +00:00
/* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
* Copyright ( C ) 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2025-09-24 08:37:26 +00:00
/* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
* Copyright ( C ) 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2025-01-06 17:20:18 +00:00
* Copyright ( C ) 2020 - 2025 Frédéric France < frederic . france @ free . fr >
2025-03-03 13:23:57 +00:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . com >
2026-06-13 23:13:22 +00:00
* Copyright ( C ) 2025 - 2026 William Mead < william @ m34d . com >
2015-05-01 14:12:30 +00:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2015-05-01 14:12:30 +00:00
*/
use Luracast\Restler\Restler ;
2015-11-22 16:39:13 +00:00
use Luracast\Restler\Defaults ;
2026-05-29 09:52:46 +00:00
use Luracast\Restler\RestException ;
2015-05-02 16:14:51 +00:00
2015-05-02 21:54:35 +00:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2015-05-01 14:12:30 +00:00
2026-05-29 09:52:46 +00:00
2015-05-01 14:12:30 +00:00
/**
2016-11-09 21:54:51 +00:00
* Class for API REST v1
2015-05-01 14:12:30 +00:00
*/
2015-05-05 22:55:42 +00:00
class DolibarrApi
{
2020-10-31 14:59:33 +00:00
/**
2025-03-03 13:23:57 +00:00
* @ var DoliDB Database object
2020-10-31 14:59:33 +00:00
*/
protected $db ;
/**
2025-03-03 13:23:57 +00:00
* @ var Restler Restler object
2020-10-31 14:59:33 +00:00
*/
public $r ;
/**
* Constructor
*
2024-01-13 14:50:02 +00:00
* @ param DoliDB $db Database handler
2020-10-31 14:59:33 +00:00
* @ param string $cachedir Cache dir
* @ param boolean $refreshCache Update cache
*/
public function __construct ( $db , $cachedir = '' , $refreshCache = false )
{
global $conf , $dolibarr_main_url_root ;
2021-02-23 16:44:43 +00:00
if ( empty ( $cachedir )) {
$cachedir = $conf -> api -> dir_temp ;
}
2020-10-31 14:59:33 +00:00
Defaults :: $cacheDirectory = $cachedir ;
$this -> db = $db ;
2025-12-15 14:56:34 +00:00
2024-08-13 20:50:31 +00:00
$production_mode = getDolGlobalBool ( 'API_PRODUCTION_MODE' );
2025-10-31 15:22:53 +00:00
2025-10-31 15:44:29 +00:00
if ( $production_mode ) {
2025-11-13 13:01:34 +00:00
// Create the directory Defaults::$cacheDirectory if it does not exist. If dir does not exist, using production_mode generates an error 500.
2025-10-31 15:55:48 +00:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2025-10-31 15:44:29 +00:00
if ( ! dol_is_dir ( Defaults :: $cacheDirectory )) {
dol_mkdir ( Defaults :: $cacheDirectory , DOL_DATA_ROOT );
}
if ( getDolGlobalString ( 'MAIN_API_DEBUG' )) {
dol_syslog ( " Debug API construct::cacheDirectory= " . Defaults :: $cacheDirectory , LOG_DEBUG , 0 , '_api' );
}
2025-10-31 15:22:53 +00:00
}
2020-10-31 14:59:33 +00:00
$this -> r = new Restler ( $production_mode , $refreshCache );
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
$urlwithouturlrootautodetect = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( DOL_MAIN_URL_ROOT ));
$urlwithrootautodetect = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use local domain autodetected by dolibarr from url
$this -> r -> setBaseUrls ( $urlwithouturlroot , $urlwithouturlrootautodetect );
$this -> r -> setAPIVersion ( 1 );
//$this->r->setSupportedFormats('json');
//$this->r->setSupportedFormats('jsonFormat');
}
2021-04-28 13:25:06 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2020-10-31 14:59:33 +00:00
/**
2021-04-26 23:05:14 +00:00
* Check and convert a string depending on its type / name .
2020-10-31 14:59:33 +00:00
*
2024-02-25 09:05:26 +00:00
* @ param string $field Field name
2024-09-18 01:27:25 +00:00
* @ param string | string [] $value Value to check / clean
2024-02-25 09:05:26 +00:00
* @ param Object $object Object
2024-09-18 01:27:25 +00:00
* @ return string | array < string , mixed > Value cleaned
2026-05-29 09:52:46 +00:00
* @ throws RestException 400 Bad parameters
2020-10-31 14:59:33 +00:00
*/
2021-04-28 13:25:06 +00:00
protected function _checkValForAPI ( $field , $value , $object )
2020-10-31 14:59:33 +00:00
{
2021-04-28 13:25:06 +00:00
// phpcs:enable
2023-12-15 11:15:33 +00:00
if ( ! is_array ( $value )) {
2026-05-29 09:56:44 +00:00
// Make protected values for forbidden properties
/* Disabled . A protection exists to check that -> entity is same than the HTTP header DOLAPIENTITY
2026-05-29 09:52:46 +00:00
if ( in_array ( $field , array ( 'entity' ))) {
throw new RestException ( 400 , 'Parameter ' . $field . ' is not allowed in request. To work on a different entity, you must set the entity into the HTTP header "DOLAPIENTITY: idOfEntity"' );
2026-05-29 09:56:44 +00:00
} */
2026-05-29 09:52:46 +00:00
if ( in_array ( $field , array (
'db' , 'table_element' , 'table_rowid' , 'table_ref_field' , 'table_element_line' , 'element' , 'fk_element' , 'element_for_permission' , 'class_element_line' ,
'fields' , 'TRIGGER_PREFIX' , 'picto' ,
'restrictiononfksoc' , 'ismultientitymanaged' , 'isextrafieldmanaged' ,
'module' , 'error' , 'errorhidden' , 'errors' , 'warning' , 'warnings' , 'validateFieldsErrors' ,
'oldcopy' , 'oldref' , 'newref' , 'context' ,
2026-05-29 10:36:54 +00:00
'actionmsg' , 'actionmsg2' , 'thirdparty' , 'user' ,
'tpl' , 'extraparams' ,
2026-05-29 09:52:46 +00:00
'childtables' , 'childtablesoncascade'
))) {
throw new RestException ( 400 , 'Parameter ' . $field . ' is not allowed in request' );
}
2026-05-29 10:36:54 +00:00
if ( in_array ( $field , array ( 'specimen' ))) {
// Allowed but not used
2026-06-09 17:42:58 +00:00
dol_syslog ( 'Debug API _checkValForAPI, found use of field specimen' , LOG_DEBUG , 0 , '_api' );
2026-05-29 10:36:54 +00:00
}
2026-05-29 09:52:46 +00:00
2024-04-02 09:57:30 +00:00
// Sanitize the value using its type declared into ->fields of $object
if ( ! empty ( $object -> fields ) && ! empty ( $object -> fields [ $field ]) && ! empty ( $object -> fields [ $field ][ 'type' ])) {
2026-08-13 01:44:04 +00:00
if ( strpos ( $object -> fields [ $field ][ 'type' ], 'int' ) === 0 || strpos ( $object -> fields [ $field ][ 'type' ], 'double' ) === 0 || in_array ( $object -> fields [ $field ][ 'type' ], array ( 'real' , 'price' , 'stock' ))) {
2024-04-02 09:57:30 +00:00
return sanitizeVal ( $value , 'int' );
}
if ( $object -> fields [ $field ][ 'type' ] == 'html' ) {
return sanitizeVal ( $value , 'restricthtml' );
}
if ( $object -> fields [ $field ][ 'type' ] == 'select' ) {
// Check values are in the list of possible 'options'
2026-05-08 23:16:35 +00:00
return sanitizeVal ( $value , 'alphanohtml' );
2024-04-02 09:57:30 +00:00
}
if ( $object -> fields [ $field ][ 'type' ] == 'sellist' || $object -> fields [ $field ][ 'type' ] == 'checkbox' ) {
2026-05-08 23:16:35 +00:00
return sanitizeVal ( $value , 'alphanohtml' );
2024-04-02 09:57:30 +00:00
}
if ( $object -> fields [ $field ][ 'type' ] == 'boolean' || $object -> fields [ $field ][ 'type' ] == 'radio' ) {
2026-05-08 23:16:35 +00:00
return sanitizeVal ( $value , 'alphanohtml' );
2024-04-02 09:57:30 +00:00
}
if ( $object -> fields [ $field ][ 'type' ] == 'email' ) {
return sanitizeVal ( $value , 'email' );
}
if ( $object -> fields [ $field ][ 'type' ] == 'password' ) {
2026-05-08 23:16:35 +00:00
return sanitizeVal ( $value , 'password' );
2024-04-02 09:57:30 +00:00
}
// Others will use 'alphanohtml'
}
2024-04-02 10:28:55 +00:00
2026-05-08 23:16:35 +00:00
// In case of a field with unknown type (legacy code), we use other tricks to guess a more accurate type
// We try to use its name to have a chance to sanitize it
2026-04-08 19:39:41 +00:00
if ( preg_match ( '/^fk_/i' , $field )) {
// We accept only integer
return sanitizeVal ( $value , 'int' );
}
2023-12-15 11:15:33 +00:00
if ( in_array ( $field , array ( 'note' , 'note_private' , 'note_public' , 'desc' , 'description' ))) {
return sanitizeVal ( $value , 'restricthtml' );
}
2026-05-08 23:16:35 +00:00
return sanitizeVal ( $value , 'alphanohtml' );
2024-04-02 10:28:55 +00:00
} else { // Example when $field = 'extrafields' and $value = content of $object->array_options
2024-04-02 09:57:30 +00:00
$newarrayvalue = array ();
foreach ( $value as $tmpkey => $tmpvalue ) {
$newarrayvalue [ $tmpkey ] = $this -> _checkValForAPI ( $tmpkey , $tmpvalue , $object );
}
2023-12-15 13:18:30 +00:00
2024-04-02 09:57:30 +00:00
return $newarrayvalue ;
2021-04-26 23:05:14 +00:00
}
}
2020-10-31 14:59:33 +00:00
2026-05-08 23:16:35 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Check and convert a string depending on its type / name .
*
* @ param string $field Field name
* @ param string | string [] $value Value to check / clean
* @ param Object $object Object
* @ return string | array < string , mixed > Value cleaned
*/
protected function _checkValExtrafieldsForAPI ( $field , $value , $object )
{
global $extrafields ;
// phpcs:enable
if ( ! is_array ( $value )) {
// Sanitize the value using its type declared into ->fields of $object
$typeOfExtraField = '' ;
if ( ! empty ( $extrafields -> attributes ) && ! empty ( $extrafields -> attributes [ $object -> table_element ])
&& ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'type' ])
&& ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $field ])) {
$typeOfExtraField = $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $field ];
}
if ( $typeOfExtraField ) {
2026-08-13 01:44:04 +00:00
if ( strpos ( $typeOfExtraField , 'int' ) === 0 || strpos ( $typeOfExtraField , 'double' ) === 0 || in_array ( $typeOfExtraField , array ( 'real' , 'price' , 'stock' ))) {
2026-05-08 23:16:35 +00:00
return sanitizeVal ( $value , 'int' );
}
2026-06-13 23:13:22 +00:00
if ( $typeOfExtraField == 'html' ) {
2026-05-08 23:16:35 +00:00
return sanitizeVal ( $value , 'restricthtml' );
}
2026-06-13 23:13:22 +00:00
if ( $typeOfExtraField == 'select' ) {
2026-05-08 23:16:35 +00:00
// TODO Check values are in the list of possible 'options'
return sanitizeVal ( $value , 'alphanohtml' );
}
if ( $typeOfExtraField == 'sellist' || $typeOfExtraField == 'checkbox' ) {
return sanitizeVal ( $value , 'alphanohtml' );
}
if ( $typeOfExtraField == 'boolean' || $typeOfExtraField == 'radio' ) {
return sanitizeVal ( $value , 'alphanohtml' );
}
if ( $typeOfExtraField == 'email' ) {
return sanitizeVal ( $value , 'email' );
}
if ( $typeOfExtraField == 'password' ) {
return sanitizeVal ( $value , 'password' );
}
// Others will use 'alphanohtml'
}
return sanitizeVal ( $value , 'alphanohtml' );
} else { // Example when $field = 'extrafields' and $value = content of $object->array_options
$newarrayvalue = array ();
foreach ( $value as $tmpkey => $tmpvalue ) {
$newarrayvalue [ $tmpkey ] = $this -> _checkValExtrafieldsForAPI ( $tmpkey , $tmpvalue , $object );
}
return $newarrayvalue ;
}
}
2023-09-26 16:04:48 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
* Filter properties that will be returned on object
*
2025-11-12 08:44:39 +00:00
* @ phpstan - template T
2025-03-03 13:23:57 +00:00
*
2023-09-26 16:04:48 +00:00
* @ param Object $object Object to clean
2025-03-03 13:23:57 +00:00
* @ param string $properties Comma separated list of properties names
2023-09-26 16:04:48 +00:00
* @ return Object Object with cleaned properties
2025-03-03 13:23:57 +00:00
* @ phpstan - param T $object
* @ phpstan - return T
2023-09-26 16:04:48 +00:00
*/
protected function _filterObjectProperties ( $object , $properties )
{
2024-03-31 14:06:04 +00:00
// phpcs:enable
2023-09-26 16:04:48 +00:00
// If properties is empty, we return all properties
if ( empty ( $properties )) {
return $object ;
}
2024-03-31 14:06:04 +00:00
// Copy of exploded array for efficiency
$arr_properties = explode ( ',' , $properties );
$magic_properties = array ();
$real_properties = get_object_vars ( $object );
// Unsetting real properties may unset magic properties.
// We keep a copy of the requested magic properties
foreach ( $arr_properties as $key ) {
if ( ! array_key_exists ( $key , $real_properties )) {
// Not a real property,
// check if $key is a magic property (we want to keep '$obj->$key')
if ( property_exists ( $object , $key ) && isset ( $object -> $key )) {
$magic_properties [ $key ] = $object -> $key ;
}
}
}
// Filter real properties (may indirectly unset magic properties)
2023-09-26 16:04:48 +00:00
foreach ( get_object_vars ( $object ) as $key => $value ) {
2024-03-31 14:06:04 +00:00
if ( ! in_array ( $key , $arr_properties )) {
2023-09-26 16:04:48 +00:00
unset ( $object -> $key );
}
}
2024-03-31 14:06:04 +00:00
// Restore the magic properties
foreach ( $magic_properties as $key => $value ) {
$object -> $key = $value ;
}
2023-09-26 16:04:48 +00:00
return $object ;
}
2020-10-31 14:59:33 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
2024-08-18 16:16:08 +00:00
* Clean sensitive object data
2025-11-12 08:44:39 +00:00
* @ phpstan - template T
2020-10-31 14:59:33 +00:00
*
2023-06-18 22:52:43 +00:00
* @ param Object $object Object to clean
* @ return Object Object with cleaned properties
2024-08-18 16:16:08 +00:00
*
* @ phpstan - param T $object
* @ phpstan - return T
2020-10-31 14:59:33 +00:00
*/
protected function _cleanObjectDatas ( $object )
{
// phpcs:enable
// Remove $db object property for object
unset ( $object -> db );
unset ( $object -> isextrafieldmanaged );
2017-11-06 10:06:31 +00:00
unset ( $object -> ismultientitymanaged );
2017-12-21 15:50:18 +00:00
unset ( $object -> restrictiononfksoc );
2019-11-02 14:05:14 +00:00
unset ( $object -> table_rowid );
2021-12-19 16:05:57 +00:00
unset ( $object -> pass );
unset ( $object -> pass_indatabase );
2026-08-09 17:48:21 +00:00
unset ( $object -> pass_indatabase_crypted );
2016-12-12 14:19:47 +00:00
2022-10-21 22:08:10 +00:00
// Remove linkedObjects. We should already have and keep only linkedObjectsIds that avoid huge responses
2020-10-31 14:59:33 +00:00
unset ( $object -> linkedObjects );
2022-08-27 17:02:05 +00:00
//unset($object->lines[$i]->linked_objects); // This is the array to create linked object during create
2020-10-31 14:59:33 +00:00
unset ( $object -> fields );
unset ( $object -> oldline );
unset ( $object -> error );
unset ( $object -> errors );
2020-12-04 23:02:40 +00:00
unset ( $object -> errorhidden );
2026-05-29 10:36:54 +00:00
unset ( $object -> warning );
2025-12-21 12:32:32 +00:00
unset ( $object -> warnings );
2025-10-29 17:58:06 +00:00
unset ( $object -> TRIGGER_PREFIX );
2020-10-31 14:59:33 +00:00
unset ( $object -> ref_previous );
unset ( $object -> ref_next );
2021-05-12 09:04:22 +00:00
unset ( $object -> imgWidth );
unset ( $object -> imgHeight );
unset ( $object -> barcode_type_code );
unset ( $object -> barcode_type_label );
unset ( $object -> mode_reglement ); // We use mode_reglement_id now
unset ( $object -> cond_reglement ); // We use cond_reglement_id now
unset ( $object -> note ); // We use note_public or note_private now
unset ( $object -> contact ); // We use contact_id now
unset ( $object -> thirdparty ); // We use thirdparty_id or fk_soc or socid now
2020-10-31 14:59:33 +00:00
unset ( $object -> project ); // Should be fk_project
2022-08-27 17:02:05 +00:00
unset ( $object -> fk_projet ); // Should be fk_project
2020-10-31 14:59:33 +00:00
unset ( $object -> author ); // Should be fk_user_author
unset ( $object -> timespent_old_duration );
unset ( $object -> timespent_id );
unset ( $object -> timespent_duration );
unset ( $object -> timespent_date );
unset ( $object -> timespent_datehour );
unset ( $object -> timespent_withhour );
unset ( $object -> timespent_fk_user );
unset ( $object -> timespent_note );
unset ( $object -> fk_delivery_address );
2026-05-29 10:36:54 +00:00
unset ( $object -> fk_multicurrency );
2025-10-28 09:23:06 +00:00
//unset($object->model_pdf);
2021-05-12 09:04:22 +00:00
unset ( $object -> sendtoid );
unset ( $object -> name_bis );
unset ( $object -> newref );
2024-04-29 09:04:19 +00:00
unset ( $object -> oldref );
2021-05-12 09:04:22 +00:00
unset ( $object -> alreadypaid );
unset ( $object -> openid );
2024-04-29 09:04:19 +00:00
unset ( $object -> fk_bank );
unset ( $object -> showphoto_on_popup );
unset ( $object -> nb );
unset ( $object -> nbphoto );
unset ( $object -> output );
unset ( $object -> tpl );
//unset($object->libelle);
2020-10-31 14:59:33 +00:00
unset ( $object -> stats_propale );
2021-02-23 16:44:43 +00:00
unset ( $object -> stats_commande );
2020-10-31 14:59:33 +00:00
unset ( $object -> stats_contrat );
unset ( $object -> stats_facture );
unset ( $object -> stats_commande_fournisseur );
unset ( $object -> stats_reception );
unset ( $object -> stats_mrptoconsume );
unset ( $object -> stats_mrptoproduce );
unset ( $object -> fieldsforcombobox );
2022-09-20 23:13:53 +00:00
unset ( $object -> regeximgext );
2020-10-31 14:59:33 +00:00
unset ( $object -> skip_update_total );
unset ( $object -> context );
unset ( $object -> next_prev_filter );
unset ( $object -> region );
unset ( $object -> region_code );
2021-05-12 09:04:22 +00:00
unset ( $object -> country );
unset ( $object -> state );
unset ( $object -> state_code );
unset ( $object -> departement );
unset ( $object -> departement_code );
2020-10-31 14:59:33 +00:00
unset ( $object -> libelle_statut );
unset ( $object -> libelle_paiement );
2024-04-29 09:04:19 +00:00
unset ( $object -> labelStatus );
unset ( $object -> labelStatusShort );
unset ( $object -> actionmsg );
unset ( $object -> actionmsg2 );
2020-10-31 14:59:33 +00:00
2020-12-19 21:24:58 +00:00
unset ( $object -> prefix_comm );
2024-09-01 13:10:08 +00:00
if ( ! isset ( $object -> table_element ) || ! in_array ( $object -> table_element , array ( 'expensereport_det' , 'ticket' ))) {
2020-10-31 14:59:33 +00:00
unset ( $object -> comments );
}
2026-05-29 10:36:54 +00:00
unset ( $object -> module );
2024-09-01 13:10:08 +00:00
unset ( $object -> origin_object );
unset ( $object -> origin );
unset ( $object -> element );
unset ( $object -> element_for_permission );
unset ( $object -> fk_element );
unset ( $object -> table_element );
unset ( $object -> table_element_line );
unset ( $object -> class_element_line );
unset ( $object -> picto );
unset ( $object -> linked_objects );
2020-10-31 14:59:33 +00:00
// Remove the $oldcopy property because it is not supported by the JSON
// encoder. The following error is generated when trying to serialize
// it: "Error encoding/decoding JSON: Type is not supported"
// Note: Event if this property was correctly handled by the JSON
// encoder, it should be ignored because keeping it would let the API
// have a very strange behavior: calling PUT and then GET on the same
// resource would give different results:
// PUT /objects/{id} -> returns object with oldcopy = previous version of the object
// GET /objects/{id} -> returns object with oldcopy empty
unset ( $object -> oldcopy );
// If object has lines, remove $db property
if ( isset ( $object -> lines ) && is_array ( $object -> lines ) && count ( $object -> lines ) > 0 ) {
$nboflines = count ( $object -> lines );
2021-02-23 16:44:43 +00:00
for ( $i = 0 ; $i < $nboflines ; $i ++ ) {
2020-10-31 13:32:18 +00:00
$this -> _cleanObjectDatas ( $object -> lines [ $i ]);
unset ( $object -> lines [ $i ] -> contact );
unset ( $object -> lines [ $i ] -> contact_id );
unset ( $object -> lines [ $i ] -> country );
unset ( $object -> lines [ $i ] -> country_id );
unset ( $object -> lines [ $i ] -> country_code );
2026-05-29 10:36:54 +00:00
unset ( $object -> lines [ $i ] -> deposit_percent );
2020-10-31 13:32:18 +00:00
unset ( $object -> lines [ $i ] -> mode_reglement_id );
unset ( $object -> lines [ $i ] -> mode_reglement_code );
unset ( $object -> lines [ $i ] -> mode_reglement );
unset ( $object -> lines [ $i ] -> cond_reglement_id );
2026-05-29 10:36:54 +00:00
unset ( $object -> lines [ $i ] -> cond_reglement_supplier_id );
2020-10-31 13:32:18 +00:00
unset ( $object -> lines [ $i ] -> cond_reglement_code );
unset ( $object -> lines [ $i ] -> cond_reglement );
unset ( $object -> lines [ $i ] -> fk_delivery_address );
unset ( $object -> lines [ $i ] -> fk_projet );
unset ( $object -> lines [ $i ] -> fk_project );
2026-05-29 10:36:54 +00:00
2020-10-31 13:32:18 +00:00
unset ( $object -> lines [ $i ] -> thirdparty );
unset ( $object -> lines [ $i ] -> user );
2026-05-29 10:36:54 +00:00
unset ( $object -> lines [ $i ] -> product );
2020-10-31 13:32:18 +00:00
unset ( $object -> lines [ $i ] -> model_pdf );
unset ( $object -> lines [ $i ] -> note_public );
unset ( $object -> lines [ $i ] -> note_private );
unset ( $object -> lines [ $i ] -> fk_incoterms );
unset ( $object -> lines [ $i ] -> label_incoterms );
unset ( $object -> lines [ $i ] -> location_incoterms );
unset ( $object -> lines [ $i ] -> name );
unset ( $object -> lines [ $i ] -> lastname );
unset ( $object -> lines [ $i ] -> firstname );
unset ( $object -> lines [ $i ] -> civility_id );
unset ( $object -> lines [ $i ] -> fk_multicurrency );
unset ( $object -> lines [ $i ] -> multicurrency_code );
unset ( $object -> lines [ $i ] -> shipping_method_id );
}
}
2020-10-31 15:22:13 +00:00
if ( ! empty ( $object -> thirdparty ) && is_object ( $object -> thirdparty )) {
2020-10-31 14:59:33 +00:00
$this -> _cleanObjectDatas ( $object -> thirdparty );
}
2022-09-20 23:13:53 +00:00
if ( ! empty ( $object -> product ) && is_object ( $object -> product )) {
$this -> _cleanObjectDatas ( $object -> product );
}
2015-05-02 23:54:04 +00:00
return $object ;
2020-10-31 14:59:33 +00:00
}
2015-06-05 16:26:12 +00:00
2020-10-31 14:59:33 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2015-05-03 12:44:37 +00:00
/**
* Check access by user to a given resource
2015-06-05 16:26:12 +00:00
*
2026-03-26 15:46:59 +00:00
* @ param string $resource element to check
* @ param int | string | Object $resource_id Full object or object ID or list of object id . For example if we want to check a particular record ( optional ) is linked to a owned thirdparty ( optional ) .
* @ param string $dbtablename 'TableName&SharedElement' with Tablename is table where object is stored . SharedElement is an optional key to define where to check entity . Not used if objectid is null ( optional )
* @ param string $feature2 Feature to check , second level of permission ( optional ) . Can be or check with 'level1|level2' .
* @ param string $dbt_keyfield Field name for socid foreign key if not fk_soc . Not used if objectid is null ( optional )
* @ param string $dbt_select Field name for select if not rowid . Not used if objectid is null ( optional )
* @ return bool
2015-05-03 12:44:37 +00:00
*/
2020-10-31 14:59:33 +00:00
protected static function _checkAccessToResource ( $resource , $resource_id = 0 , $dbtablename = '' , $feature2 = '' , $dbt_keyfield = 'fk_soc' , $dbt_select = 'rowid' )
{
// phpcs:enable
2015-05-03 12:44:37 +00:00
// Features/modules to check
$featuresarray = array ( $resource );
2015-06-05 16:26:12 +00:00
if ( preg_match ( '/&/' , $resource )) {
$featuresarray = explode ( " & " , $resource );
2020-05-21 13:05:19 +00:00
} elseif ( preg_match ( '/\|/' , $resource )) {
2015-06-05 16:26:12 +00:00
$featuresarray = explode ( " | " , $resource );
2015-05-03 12:44:37 +00:00
}
// More subfeatures to check
2020-04-10 08:59:32 +00:00
if ( ! empty ( $feature2 )) {
2015-05-03 12:44:37 +00:00
$feature2 = explode ( " | " , $feature2 );
}
2017-02-03 10:42:49 +00:00
return checkUserAccessToObject ( DolibarrApiAccess :: $user , $featuresarray , $resource_id , $dbtablename , $feature2 , $dbt_keyfield , $dbt_select );
2020-10-31 14:59:33 +00:00
}
2016-12-12 14:19:47 +00:00
2020-10-31 14:59:33 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2016-10-25 16:33:45 +00:00
/**
* Return if a $sqlfilters parameter is valid
2023-02-25 18:48:33 +00:00
* Function no more used . Kept for backward compatibility with old APIs of modules
2016-12-12 14:19:47 +00:00
*
2021-12-20 19:49:32 +00:00
* @ param string $sqlfilters sqlfilter string
* @ param string $error Error message
* @ return boolean | string True if valid , False if not valid
2016-10-25 16:33:45 +00:00
*/
2021-12-20 19:49:32 +00:00
protected function _checkFilters ( $sqlfilters , & $error = '' )
2016-10-25 16:33:45 +00:00
{
2020-10-31 14:59:33 +00:00
// phpcs:enable
2024-02-16 00:19:53 +00:00
$firstandlastparenthesis = 0 ;
return dolCheckFilters ( $sqlfilters , $error , $firstandlastparenthesis );
2016-10-25 16:33:45 +00:00
}
2016-12-12 14:19:47 +00:00
2020-10-31 14:59:33 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2016-10-25 16:33:45 +00:00
/**
2023-02-25 18:48:33 +00:00
* Function to forge a SQL criteria from a Generic filter string .
* Function no more used . Kept for backward compatibility with old APIs of modules
2016-12-12 14:19:47 +00:00
*
2024-09-18 01:27:25 +00:00
* @ param string [] $matches Array of found string by regex search .
2021-08-30 14:54:45 +00:00
* Each entry is 1 and only 1 criteria .
2026-05-29 10:16:42 +00:00
* Example : " t.ref:like:'SO-%' " , " t.date_creation:>:'20160101' " , " t.date_creation:<:'2016-01-01 12:30:00' " , " t.nature:is:NULL " , " t.field2:isnot:NULL "
2021-05-03 12:58:29 +00:00
* @ return string Forged criteria . Example : " t.field like 'abc%' "
2016-10-25 16:33:45 +00:00
*/
2019-02-26 20:13:07 +00:00
protected static function _forge_criteria_callback ( $matches )
2016-10-25 16:33:45 +00:00
{
2024-11-24 13:58:40 +00:00
return dolForgeSQLCriteriaCallback ( $matches );
2016-12-12 14:19:47 +00:00
}
2015-05-01 14:12:30 +00:00
}