@@ -171,7 +162,7 @@ $documentation->showSidebar(); ?>
'});',
'',
);
- echo $documentation->showCode($lines, 'php');
+ $documentation->showCode($lines, 'php');
print implode("\n", $lines);
?>
diff --git a/htdocs/core/class/fileupload.class.php b/htdocs/core/class/fileupload.class.php
index 1354894cf41..47e4ab90c02 100644
--- a/htdocs/core/class/fileupload.class.php
+++ b/htdocs/core/class/fileupload.class.php
@@ -100,11 +100,13 @@ class FileUpload
dol_include_once('/'.$parentElement.'/class/'.$parentObject.'.class.php');
$parent = new $parentClass($db);
- $parent->fetch($object->$parentForeignKey);
- if (!empty($parent->socid)) {
- $parent->fetch_thirdparty();
+ if ($object->$parentForeignKey !== null) {
+ $parent->fetch((int) $object->$parentForeignKey);
+ if (!empty($parent->socid)) {
+ $parent->fetch_thirdparty();
+ }
+ $object->$parentObject = clone $parent;
}
- $object->$parentObject = clone $parent;
$object_ref = dol_sanitizeFileName($object->project->ref).'/'.$object_ref;
}
@@ -396,6 +398,7 @@ class FileUpload
// Remove path information and dots around the filename, to prevent uploading
// into different directories or replacing hidden system files.
$file_name = basename(dol_sanitizeFileName($name));
+ $file_name = preg_replace('/ {2,}/', ' ', $file_name); // replaces multiple spaces into one space like the upload flow via input field
// Add missing file extension for known image types:
$matches = array();
if (strpos($file_name, '.') === false && preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php
index 3a4e100a982..e094ec390a3 100644
--- a/htdocs/fourn/facture/list.php
+++ b/htdocs/fourn/facture/list.php
@@ -420,9 +420,39 @@ if (empty($reshook)) {
$numprlv = $db->num_rows($result_sql);
}
- if ($numprlv > 0) {
+ // Calculate pending amount to check if more requests can be made
+ $pending = 0;
+ // Get pending requests open with no transfer receipt yet
+ $sqlPending1 = "SELECT SUM(pfd.amount) as amount";
+ $sqlPending1 .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
+ $sqlPending1 .= " WHERE pfd.fk_facture_fourn = ".((int) $objecttmp->id);
+ $sqlPending1 .= " AND pfd.traite = 0";
+ $resPending1 = $db->query($sqlPending1);
+ if ($resPending1) {
+ $objPending1 = $db->fetch_object($resPending1);
+ if ($objPending1) {
+ $pending += (float) $objPending1->amount;
+ }
+ }
+ $db->free($resPending1);
+ // Get pending request with a transfer receipt generated but not yet processed
+ $sqlPending2 = "SELECT SUM(pl.amount) as amount";
+ $sqlPending2 .= " FROM ".$db->prefix()."prelevement_lignes as pl";
+ $sqlPending2 .= " INNER JOIN ".$db->prefix()."prelevement as p ON p.fk_prelevement_lignes = pl.rowid";
+ $sqlPending2 .= " WHERE p.fk_facture_fourn = ".((int) $objecttmp->id);
+ $sqlPending2 .= " AND (pl.statut IS NULL OR pl.statut = 0)";
+ $resPending2 = $db->query($sqlPending2);
+ if ($resPending2) {
+ if ($objPending2 = $db->fetch_object($resPending2)) {
+ $pending += (float) $objPending2->amount;
+ }
+ }
+ $db->free($resPending2);
+ $remaintopaylesspendingdebit = $objecttmp->resteapayer - $pending;
+ // Check remaining amount (allows multiple partial requests as long as total doesn't exceed invoice amount)
+ if ($remaintopaylesspendingdebit <= 0) {
$error++;
- setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
+ setEventMessages($objecttmp->ref.' '.$langs->trans("AmountRequestedAlreadyReachesTotal"), $objecttmp->errors, 'warnings');
} elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'VIR') {
$langs->load("errors");
$error++;
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index 352802d3b02..cf36e105bfd 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -721,3 +721,4 @@ InvoiceSentFromTemplate=Invoice %s sent from recurring invoice template %s
InvoiceSentFromTemplateError=Failed to send invoice %s from recurring invoice template %s : %s
BillStatusValidatedWithSendind=Validated (needs to be paid) and sending
sendAutoEmailInvoiceKO=Failed to send email from %s to %s
+AmountRequestedAlreadyReachesTotal=The amount requested already reaches the total of the invoice
diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index e6b74e2d5bd..14ac4a79e3f 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -467,3 +467,4 @@ SomeShipmentExists=Error, there is some shipment linked to the order. Deletion r
WarningEvaluationEmptyValidate=Can't validate evaluation, levels on skills not defined
ErrorBadParametersForDirectDebitFileCreate=Can't create bank transfer file: expected format parameter is not provided.
ErrorBadParametersForDirectDebitFileCreateDids=Can't create bank transfer file: IDs of existing payment requests are not provided.
+UserDoesNotHaveRightsToChangeHisPassword=That user doesn't have the rights to change his own password
diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang
index a2f91b13861..6973f03e94e 100644
--- a/htdocs/langs/fr_FR/bills.lang
+++ b/htdocs/langs/fr_FR/bills.lang
@@ -715,6 +715,7 @@ DisputeWon=Victoire en litige
DisputeClosed=Litige clos
Dispute=Différend
Sales=Ventes
+AmountRequestedAlreadyReachesTotal=Le montant demandé atteint déjà le total de la facture
AutoSendEmail=Envoi automatique d'e-mails
EmailTemplateForAutoSend=Modèle d'e-mail pour l'envoi automatique
InvoiceSentFromTemplate=facture %s envoyé depuis le modèle récurrent facture %s
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index 3189c8246ea..8a57776ff94 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -45,7 +45,7 @@
// For optional tuning. Enabled if environment variable MAIN_SHOW_TUNING_INFO is defined.
$micro_start_time = 0; // Used as global var into printCommonFooter()
if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO'])) {
- list($usec, $sec) = explode(" ", microtime());
+ [$usec, $sec] = explode(" ", microtime());
$micro_start_time = ((float) $usec + (float) $sec);
// Add Xdebug code coverage
//define('XDEBUGCOVERAGE',1);
@@ -1814,6 +1814,42 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr
$themeparam .= '&THEME_SATURATE_RATIO='.GETPOSTINT('THEME_SATURATE_RATIO');
}
+
+ /**
+ * ====================================
+ * DEFINE DOLIBARR JS CONTEXT AND TOOLS
+ * ====================================
+ * see Documentation at admin/tools/ui/dolibarr-context/index.php
+ */
+ $jsContextVars = [
+ 'DOL_VERSION' => DOL_VERSION,
+ 'DOL_URL_ROOT' => DOL_URL_ROOT,
+ ];
+
+ $jsContextPathUrl = DOL_URL_ROOT . '/public/includes/dolibarr-js-context';
+ $jsContextFiles = [
+ 'dolibarr-context.umd.js', // The js Dolibarr context definition
+ 'dolibarr-tool.seteventmessage.js' // The first tools to help dev for easy event in js
+ ];
+
+ if (! defined('NOREQUIRETRAN')) {
+ // Langs tool see Documentation at admin/tools/ui/dolibarr-context/index.php
+ $jsContextFiles[] = 'dolibarr-tool.langs.js';
+ $jsContextVars['MAIN_LANG_DEFAULT'] = $langs->getDefaultLang();// For langs tool
+ $jsContextVars['DOL_LANG_INTERFACE_URL'] = dol_buildpath('public/langs/langs-tool-interface.php', 1);// For langs tool
+ }
+
+ // Load context and all js tools
+ foreach ($jsContextFiles as $jsContextFile) {
+ print ''."\n";
+ }
+
+ // DEFINE FIRST NEEDED JS CONTEXT VARS
+ print ''."\n";
+
+ // -- END OF DEFINITION OF DOLIBARR JS CONTEXT AND TOOLS
+
+
if (getDolGlobalString('MAIN_ENABLE_FONT_ROBOTO')) {
print ''."\n";
print ''."\n";
diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php
index b55ebbc9770..ec19295a425 100644
--- a/htdocs/projet/class/api_projects.class.php
+++ b/htdocs/projet/class/api_projects.class.php
@@ -28,6 +28,7 @@ require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php';
/**
* API class for projects
*
+ * @since 5.0.0 Initial implementation
* @access protected
* @class DolibarrApiAccess {@requires user,external}
*/
@@ -68,6 +69,7 @@ class Projects extends DolibarrApi
*
* Return an array with project information
*
+ * @since 5.0.0 Initial implementation
* @param int $id ID of project
* @return Object Object with cleaned properties
*
@@ -97,6 +99,7 @@ class Projects extends DolibarrApi
*
* Return an array with project information
*
+ * @since 20.0.0 Initial implementation
* @param string $ref Ref of project
* @return Object Object with cleaned properties
*
@@ -128,6 +131,7 @@ class Projects extends DolibarrApi
*
* Return an array with project information
*
+ * @since 20.0.0 Initial implementation
* @param string $ref_ext Ref_Ext of project
* @return Object Object with cleaned properties
*
@@ -159,6 +163,7 @@ class Projects extends DolibarrApi
*
* Return an array with project information
*
+ * @since 20.0.0 Initial implementation
* @param string $email_msgid Email msgid of project
* @return Object Object with cleaned properties
*
@@ -190,6 +195,7 @@ class Projects extends DolibarrApi
*
* Get a list of projects
*
+ * @since 5.0.0 Initial implementation
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
@@ -307,6 +313,7 @@ class Projects extends DolibarrApi
/**
* Create project object
*
+ * @since 5.0.0 Initial implementation
* @param array $request_data Request data
* @phan-param array $request_data
* @phpstan-param array $request_data
@@ -390,6 +397,7 @@ class Projects extends DolibarrApi
/**
* Adds a contact to an project
*
+ * @since 23.0.0 Initial implementation
* @param int $id project ID
* @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if source = 'internal') to link
* @param string $type_contact Type of contact (code). Must a code found into table llx_c_type_contact. For example: BILLING
@@ -431,6 +439,7 @@ class Projects extends DolibarrApi
/**
* Delete a contact type of given project
*
+ * @since 23.0.0 Initial implementation
* @param int $id Id of project to update
* @param int $contactid Row key of the contact in the array contact_ids.
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER).
@@ -475,6 +484,7 @@ class Projects extends DolibarrApi
* Get tasks of a project.
* See also API /tasks
*
+ * @since 5.0.0 Initial implementation
* @param int $id Id of project
* @param int $includetimespent 0=Return only list of tasks. 1=Include a summary of time spent, 2=Include details of time spent lines
* @return array
@@ -515,6 +525,7 @@ class Projects extends DolibarrApi
/**
* Get roles a user is assigned to a project with
*
+ * @since 5.0.0 Initial implementation
* @param int $id Id of project
* @param int $userid Id of user (0 = connected user)
* @return array
@@ -693,6 +704,7 @@ class Projects extends DolibarrApi
/**
* Update project general fields (won't touch lines of project)
*
+ * @since 5.0.0 Initial implementation
* @param int $id Id of project to update
* @param array $request_data Datas
* @phan-param ?array $request_data
@@ -744,6 +756,7 @@ class Projects extends DolibarrApi
/**
* Delete project
*
+ * @since 5.0.0 Initial implementation
* @param int $id Project ID
*
* @return array
@@ -781,6 +794,7 @@ class Projects extends DolibarrApi
* You can test this API with the following input message
* { "notrigger": 0 }
*
+ * @since 5.0.0 Initial implementation
* @param int $id Project ID
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @phan-param int<0,1> $notrigger
@@ -831,6 +845,7 @@ class Projects extends DolibarrApi
/**
* Get all timespent
*
+ * @since 23.0.0 Initial implementation
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
@@ -1027,6 +1042,7 @@ class Projects extends DolibarrApi
*
* Return an array with contact information
*
+ * @since 23.0.0 Initial implementation
* @param int $id ID of project
* @param string $type Type of the contact
* @return array Array with cleaned properties
@@ -1061,6 +1077,7 @@ class Projects extends DolibarrApi
/**
* Adds a contact to a project
*
+ * @since 23.0.0 Initial implementation
* @param int $id Project ID
* @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if source = 'internal') to link
* @param string $type_contact Type of contact (code). Must a code found into table llx_c_type_contact. For example: BILLING
@@ -1121,6 +1138,7 @@ class Projects extends DolibarrApi
/**
* Delete a contact type of given project
*
+ * @since 23.0.0 Initial implementation
* @param int $id Id of project to update
* @param int $contactid Row key of the contact in the array contact_ids.
* @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER).
@@ -1167,6 +1185,7 @@ class Projects extends DolibarrApi
/**
* Get timespent of a project (from all its tasks)
*
+ * @since 23.0.0 Initial implementation
* @param int $id ID of project
* @return array Array of timespent objects
*
diff --git a/htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-context.mock.js b/htdocs/public/includes/dolibarr-js-context/dolibarr-context.mock.js
similarity index 100%
rename from htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-context.mock.js
rename to htdocs/public/includes/dolibarr-js-context/dolibarr-context.mock.js
diff --git a/htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-context.umd.js b/htdocs/public/includes/dolibarr-js-context/dolibarr-context.umd.js
similarity index 100%
rename from htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-context.umd.js
rename to htdocs/public/includes/dolibarr-js-context/dolibarr-context.umd.js
diff --git a/htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-tool.langs.js b/htdocs/public/includes/dolibarr-js-context/dolibarr-tool.langs.js
similarity index 89%
rename from htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-tool.langs.js
rename to htdocs/public/includes/dolibarr-js-context/dolibarr-tool.langs.js
index adeefc27ddb..becfdff5f32 100644
--- a/htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-tool.langs.js
+++ b/htdocs/public/includes/dolibarr-js-context/dolibarr-tool.langs.js
@@ -24,8 +24,14 @@ document.addEventListener('Dolibarr:Init', function(e) {
* @returns {Promise}
*/
async function openDB() {
+
+ // Generate a unique name per instance
+ const path = Dolibarr.getContextVar('DOL_URL_ROOT'); // or a unique Dolibarr identifier if available
+ const hashedPath = await hashString(path);
+ const dbName = `DolibarrLangs_${hashedPath}`;
+
return new Promise((resolve, reject) => {
- const request = indexedDB.open('DolibarrLangs', 1);
+ const request = indexedDB.open(dbName, 1);
request.onupgradeneeded = e => {
const db = e.target.result;
if (!db.objectStoreNames.contains('langs')) db.createObjectStore('langs');
@@ -35,6 +41,22 @@ document.addEventListener('Dolibarr:Init', function(e) {
});
}
+ // Create a secure DB name
+ async function getSafeDbName() {
+ const path = window.location.pathname;
+ const hashedPath = await hashString(path);
+ return `DolibarrLangs_${hashedPath}`;
+ }
+
+ // Simple function to generate a hash from a string
+ async function hashString(str) {
+ const encoder = new TextEncoder();
+ const data = encoder.encode(str);
+ const hashBuffer = await crypto.subtle.digest('SHA-1', data);
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
+ return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
+ }
+
/**
* Get cached translation for a domain + locale
* @param {string} domain
diff --git a/htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-tool.seteventmessage.js b/htdocs/public/includes/dolibarr-js-context/dolibarr-tool.seteventmessage.js
similarity index 100%
rename from htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/assets/dolibarr-tool.seteventmessage.js
rename to htdocs/public/includes/dolibarr-js-context/dolibarr-tool.seteventmessage.js
diff --git a/htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/langs-tool-interface.php b/htdocs/public/langs/langs-tool-interface.php
similarity index 89%
rename from htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/langs-tool-interface.php
rename to htdocs/public/langs/langs-tool-interface.php
index 2404220fc31..179c9f04fc2 100644
--- a/htdocs/admin/tools/ui/experimental/experiments/dolibarr-context/langs-tool-interface.php
+++ b/htdocs/public/langs/langs-tool-interface.php
@@ -17,17 +17,17 @@
*/
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
-//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
+if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
-//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
+if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
-//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
+if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too.
//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value
//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
@@ -36,7 +36,7 @@ if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // I
// Load Dolibarr environment
-require '../../../../../../main.inc.php';
+require '../../main.inc.php';
/**
diff --git a/htdocs/takepos/send.php b/htdocs/takepos/send.php
index 6d40cb76bbd..044700c89ef 100644
--- a/htdocs/takepos/send.php
+++ b/htdocs/takepos/send.php
@@ -144,7 +144,6 @@ if ($action == "send" && $user->hasRight('takepos', 'run')) {
$object->context['email_msgid'] = $mail->msgid;
// Same code as in actions_sendmail.inc.php
- // if ($triggersendname === 'BILL_SENTBYMAIL' && $object instanceof Facture) { // Always true ($triggersendname is set above, and $object = $invoice = Facture object
// If sending email for invoice, we increase the counter of invoices sent by email
$sql = "UPDATE ".MAIN_DB_PREFIX."facture SET email_sent_counter = email_sent_counter + 1";
$sql .= " WHERE rowid = ".((int) $object->id);
diff --git a/htdocs/user/card.php b/htdocs/user/card.php
index 56cbebb1175..4078819a665 100644
--- a/htdocs/user/card.php
+++ b/htdocs/user/card.php
@@ -1222,7 +1222,12 @@ if ($action == 'create' || $action == 'adduserldap') {
if ($_SESSION["dol_authmode"] == 'dolibarr') {
print '