diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index cbc5c5840e5..a80b6ac313e 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -79,10 +79,10 @@ if (GETPOST('cancel', 'alpha')) { if ($action == 'add' /* && $user->hasRight('accounting', 'chartofaccount') // already checked */) { if (!$cancel) { - if (!$account_number) { + if ((string) $account_number === '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountNumber")), null, 'errors'); $action = 'create'; - } elseif (!$label) { + } elseif ((string) $label === '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); $action = 'create'; } else { @@ -134,10 +134,10 @@ if ($action == 'add' /* && $user->hasRight('accounting', 'chartofaccount') // al } } elseif ($action == 'edit' /* && $user->hasRight('accounting', 'chartofaccount') // already checked */) { if (!$cancel) { - if (!$account_number) { + if ((string) $account_number === '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountNumber")), null, 'errors'); $action = 'update'; - } elseif (!$label) { + } elseif ((string) $label === '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); $action = 'update'; } else { diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index d396f734ff4..8f4c5df7991 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -360,11 +360,22 @@ if (empty($reshook)) { $nbcreated = 0; $now = dol_now(); $amount = price2num(GETPOST('amount', 'alpha')); + // Honour MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH and + // MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR the same way as the + // single subscription form (adherents/subscription.php), otherwise + // the mass action falls back to a one-year duration in + // Adherent::subscription() and ignores the global setting. + $datesubend = 0; + if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) { + $datesubend = dol_get_last_day((int) dol_print_date($now, "%Y"), (int) dol_print_date($now, "%m")); + } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) { + $datesubend = dol_get_last_day((int) dol_print_date($now, "%Y")); + } $db->begin(); foreach ($toselect as $id) { $res = $tmpmember->fetch($id); if ($res > 0) { - $result = $tmpmember->subscription($now, (float) $amount); + $result = $tmpmember->subscription($now, (float) $amount, 0, '', '', '', '', '', $datesubend); if ($result < 0) { $error++; } else { diff --git a/htdocs/api/index.php b/htdocs/api/index.php index b76ef49b65e..3be224d492e 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -29,6 +29,15 @@ use Luracast\Restler\Format\UploadFormat; +// API endpoints return JSON (or XML). A stray PHP warning or notice in the +// response body corrupts the parser on the caller side. Silence the display +// of PHP messages here while keeping them in the server log so that the +// problem is still observable to the operator (filefunc.inc.php only does +// this when dolibarr_main_prod is set, which leaves development setups +// emitting HTML into every API answer). +@ini_set('display_errors', '0'); +@ini_set('log_errors', '1'); + if (!defined('NOCSRFCHECK')) { define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test } diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 07235512864..aa47e9dac63 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -803,6 +803,10 @@ if (isModEnabled('project')) { $formproject = new FormProjets($db); } +// Same check as the email templates editor in admin/mails_templates.php so the +// local media browser is shown consistently in both places. +$acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0); + $help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing'; llxHeader( '', @@ -959,7 +963,7 @@ if ($action == 'create') { // aaa print '
'; // wysiwyg editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, -1, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%'); + $doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'restricthtmlallowunvalid'), '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%'); $doleditor->Create(); print '
'; @@ -1432,7 +1436,7 @@ if ($action == 'create') { // aaa $readonly = 1; // wysiwyg editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, -1, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%', $readonly); + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%', $readonly); $doleditor->Create(); } else { print dol_htmlentitiesbr($object->body); @@ -1712,19 +1716,19 @@ if ($action == 'create') { // aaa $object->body = '
'.$object->body.'
'; } } - $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, -1, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%'); + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, getDolGlobalInt('FCKEDITOR_ENABLE_MAILING'), 20, '100%'); $doleditor->Create(); } if ($action == 'edittxt') { // wysiwyg editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, -1, 0, 20, '100%'); + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, 0, 20, '100%'); $doleditor->Create(); } if ($action == 'edithtml') { // HTML source editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, -1, 'ace', 20, '100%'); + $doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, $acceptlocallinktomedia, 'ace', 20, '100%'); $doleditor->Create(0, '', false, 'HTML Source', 'php'); } diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 9ba8f4624fe..392d3b44788 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -373,6 +373,10 @@ if (empty($reshook)) { $result = $object->closeProposal($user, $object::STATUS_SIGNED); } if ($result >= 0) { + $ret = $object->fetch($id); // Reload to get new records + if ($ret > 0) { + $object->fetch_thirdparty(); + } if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { $outputlangs = $langs; $newlang = ''; @@ -387,10 +391,6 @@ if (empty($reshook)) { $outputlangs->setDefaultLang($newlang); } $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - if ($ret > 0) { - $object->fetch_thirdparty(); - } $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 4eb6638c144..da9c44ea56c 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2743,10 +2743,16 @@ class Propal extends CommonObject $this->db->commit(); return 1; } else { - $this->statut = $this->oldcopy->status; // deprecated - $this->status = $this->oldcopy->status; - $this->date_signature = $this->oldcopy->date_signature; - $this->note_private = $this->oldcopy->note_private; + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + if (!empty($this->oldcopy)) { + $this->statut = $this->oldcopy->status; // deprecated + $this->status = $this->oldcopy->status; + $this->date_signature = $this->oldcopy->date_signature; + $this->note_private = $this->oldcopy->note_private; + } $this->db->rollback(); return -1; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 91e4f621e21..70ee28e1f08 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -20,6 +20,7 @@ * Copyright (C) 2024-2025 MDW * Copyright (C) 2024-2025 Alexandre Spangaro * Copyright (C) 2025 Lenin Rivas + * Copyright (C) 2026 Joachim Küter * * 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 @@ -250,7 +251,7 @@ if (empty($reshook)) { $objectutil->date = dol_mktime(12, 0, 0, GETPOSTINT('newdatemonth'), GETPOSTINT('newdateday'), GETPOSTINT('newdateyear')); $objectutil->socid = $socid; - $result = $objectutil->createFromClone($user, $id); + $result = $objectutil->createFromClone($user, $id, (GETPOSTISSET('entity') ? GETPOSTINT('entity') : null)); if ($result > 0) { $warningMsgLineList = array(); // check all product lines are to sell otherwise add a warning message for each product line is not to sell @@ -5492,15 +5493,23 @@ if ($action == 'create') { print ''; if (getDolGlobalString('INVOICE_POINTOFTAX_DATE')) { - // Date invoice point of tax + // Date invoice point of tax (Leistungsdatum / service date for tax). + // Only editable while the invoice is a draft — once validated, the + // invoice is a legally issued document and date_pointoftax is the + // basis for the VAT-return period assignment under accrual taxation + // (Soll-Versteuerung). To correct, set the invoice back to draft or + // issue a credit note. + $editable = ($usercancreate && $object->status < Facture::STATUS_VALIDATED); print ''; print ''; - print ''; + if ($editable) { + print ''; + } print '
'; print $langs->trans('DatePointOfTax'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print ''; - if ($action == 'editdate_pointoftax') { + if ($action == 'editdate_pointoftax' && $editable) { $form->form_date($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->date_pointoftax, 'date_pointoftax'); } else { print ''.dol_print_date($object->date_pointoftax, 'day').''; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index e1573a76668..985bf604ded 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1269,9 +1269,10 @@ class Facture extends CommonInvoice * * @param User $user User that clone * @param int $fromid Id of object to clone + * @param int $forceentity Entity id to force (used by multicompany to clone into another entity) * @return int New id of clone */ - public function createFromClone(User $user, $fromid = 0) + public function createFromClone(User $user, $fromid = 0, $forceentity = null) { global $conf, $hookmanager; @@ -1301,6 +1302,8 @@ class Facture extends CommonInvoice // TODO Change product price if multi-prices } + $object->entity = (!empty($forceentity) ? $forceentity : $object->entity); + $object->id = 0; $object->statut = self::STATUS_DRAFT; $object->status = self::STATUS_DRAFT; @@ -1800,6 +1803,10 @@ class Facture extends CommonInvoice $amountdeposit = array(); $descriptions = array(); + // Bucket lines by tva_tx + vat_src_code so addline below receives the rate in + // the "tva (CODE)" format that Facture::addline knows how to parse. Bucketing + // on tva_tx alone wipes out the dictionary Code on the generated deposit line + // and on every downstream document derived from it (see issue #38035). if (getDolGlobalString('MAIN_DEPOSIT_MULTI_TVA')) { $amount = $origin->total_ttc * ($origin->deposit_percent / 100); @@ -1808,7 +1815,7 @@ class Facture extends CommonInvoice if (!empty($line->special_code)) { continue; } - $key = $line->tva_tx; + $key = $line->tva_tx . ($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''); if (!array_key_exists($key, $TTotalByTva)) { $TTotalByTva[$key] = 0; $descriptions[$key] = ''; @@ -1821,10 +1828,11 @@ class Facture extends CommonInvoice } foreach ($TTotalByTva as $tva => &$total) { + $tva_rate_only = preg_replace('/\s*\(.*\)/', '', (string) $tva); $coef = $total / $origin->total_ttc; // Calc coef $am = $amount * $coef; $amount_ttc_diff += $am; - $amountdeposit[$tva] += $am / (1 + $tva / 100); // Convert into HT for the addline + $amountdeposit[$tva] += $am / (1 + ((float) $tva_rate_only) / 100); // Convert into HT for the addline } } else { $totalamount = 0; @@ -1839,19 +1847,23 @@ class Facture extends CommonInvoice } $totalamount += $lines[$i]->total_ht; // Fixme : is it not for the customer ? Shouldn't we take total_ttc ? - $tva_tx = $lines[$i]->tva_tx; - $amountdeposit[$tva_tx] += ((float) $lines[$i]->total_ht * (float) $origin->deposit_percent) / 100; - $descriptions[$tva_tx] .= '
  • ' . (!empty($lines[$i]->product_ref) ? $lines[$i]->product_ref . ' - ' : ''); - $descriptions[$tva_tx] .= (!empty($lines[$i]->product_label) ? $lines[$i]->product_label . ' - ' : ''); - $descriptions[$tva_tx] .= $langs->trans('Qty') . ' : ' . $lines[$i]->qty; - $descriptions[$tva_tx] .= ' - ' . $langs->trans('TotalHT') . ' : ' . price($lines[$i]->total_ht) . '
  • '; + $tva_key = $lines[$i]->tva_tx . ($lines[$i]->vat_src_code ? ' ('.$lines[$i]->vat_src_code.')' : ''); + if (!isset($amountdeposit[$tva_key])) { + $amountdeposit[$tva_key] = 0; + $descriptions[$tva_key] = ''; + } + $amountdeposit[$tva_key] += ((float) $lines[$i]->total_ht * (float) $origin->deposit_percent) / 100; + $descriptions[$tva_key] .= '
  • ' . (!empty($lines[$i]->product_ref) ? $lines[$i]->product_ref . ' - ' : ''); + $descriptions[$tva_key] .= (!empty($lines[$i]->product_label) ? $lines[$i]->product_label . ' - ' : ''); + $descriptions[$tva_key] .= $langs->trans('Qty') . ' : ' . $lines[$i]->qty; + $descriptions[$tva_key] .= ' - ' . $langs->trans('TotalHT') . ' : ' . price($lines[$i]->total_ht) . '
  • '; } if ($totalamount == 0) { $amountdeposit[0] = 0; } - $amount_ttc_diff = $amountdeposit[0]; + $amount_ttc_diff = $amountdeposit[0] ?? 0; } foreach ($amountdeposit as $tva => $amount) { @@ -1907,6 +1919,9 @@ class Facture extends CommonInvoice $deposit->fetch_lines(); $subprice_diff = $deposit->lines[0]->subprice - $diff / (1 + $deposit->lines[0]->tva_tx / 100); + // Pass tva_tx in the "rate (CODE)" form so updateline preserves the vat_src_code + // it received from addline; passing the bare rate would wipe the code. + $tva_tx_with_code = $deposit->lines[0]->tva_tx . ($deposit->lines[0]->vat_src_code ? ' ('.$deposit->lines[0]->vat_src_code.')' : ''); $updatelineResult = $deposit->updateline( $deposit->lines[0]->id, $deposit->lines[0]->desc, @@ -1915,7 +1930,7 @@ class Facture extends CommonInvoice $deposit->lines[0]->remise_percent, $deposit->lines[0]->date_start, $deposit->lines[0]->date_end, - $deposit->lines[0]->tva_tx, + $tva_tx_with_code, 0, 0, 'HT', diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index f07e0ae0a68..5405ed230e9 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -173,6 +173,9 @@ if ($action == 'add' && !empty($permissiontoadd)) { if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') { $value = ''; // This is an explicit foreign key field } + if (preg_match('/^sellist:/i', $object->fields[$key]['type']) && $value == '0') { + $value = ''; // sellist blank option posts "0"; normalize to '' so notnull check works on PHP 8.0+ (see github.com/Dolibarr/dolibarr/issues/38199) + } //var_dump($key.' '.$value.' '.$object->fields[$key]['type'].' '.$object->fields[$key]['notnull']); @@ -335,6 +338,9 @@ if ($action == 'update' && !empty($permissiontoadd)) { if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') { $value = ''; // This is an explicit foreign key field } + if (preg_match('/^sellist:/i', $object->fields[$key]['type']) && $value == '0') { + $value = ''; // sellist blank option posts "0"; normalize to '' so notnull check works on PHP 8.0+ (see github.com/Dolibarr/dolibarr/issues/38199) + } $object->$key = $value; diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php index 27575769201..8ed2ed630c3 100644 --- a/htdocs/core/class/cunits.class.php +++ b/htdocs/core/class/cunits.class.php @@ -208,7 +208,13 @@ class CUnits extends CommonDict $this->code = $obj->code; $this->label = $obj->label; $this->short_label = $obj->short_label; - $this->scale = $obj->scale ? (int) $obj->scale : null; + // Preserve scale=0 (e.g. the kg row). A truthy test on $obj->scale would + // collapse the legitimate scale of "0" into null and, downstream, the + // "weight unit" dropdown comparison in selectMeasuringUnits would no + // longer match the stored value under PHP 8 strict numeric-string + // rules, silently switching saved products to the first option (see + // issue #38497). + $this->scale = isset($obj->scale) ? (int) $obj->scale : null; $this->unit_type = $obj->unit_type; $this->active = (int) $obj->active; } @@ -302,7 +308,8 @@ class CUnits extends CommonDict $record->label = $obj->label; $record->short_label = $obj->short_label; $record->unit_type = $obj->unit_type; - $record->scale = $obj->scale ? (int) $obj->scale : null; + // Same scale-preservation as in fetch(): see issue #38497. + $record->scale = isset($obj->scale) ? (int) $obj->scale : null; $record->active = (int) $obj->active; $this->records[$record->id] = $record; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 711a257d565..a6cad6c0e9f 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -488,7 +488,10 @@ class Form } $extralanguages->fetch_name_extralanguages('societe'); - if (!is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) { + // ExtraLanguages::fetch_name_extralanguages() leaves $this->attributes empty + // when MAIN_USE_ALTERNATE_TRANSLATION_FOR is not configured, so PHP 8 raises + // 'Undefined array key' on the read below if we do not guard it (issue #34596). + if (empty($extralanguages->attributes[$object->element]) || !is_array($extralanguages->attributes[$object->element]) || empty($extralanguages->attributes[$object->element][$fieldname])) { return ''; // No extralang field to show } @@ -10998,7 +11001,9 @@ class Form } $extralanguages->fetch_name_extralanguages('societe'); - if (!empty($extralanguages->attributes['societe']['name'])) { + // Guard against PHP 8 'Undefined array key' when MAIN_USE_ALTERNATE_TRANSLATION_FOR + // is not configured and fetch_name_extralanguages() leaves attributes empty (issue #34596). + if (!empty($extralanguages->attributes['societe']) && !empty($extralanguages->attributes['societe']['name'])) { $object->fetchValuesForExtraLanguages(); $htmltext = ''; diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index e79f3b9ed81..f54bc137be8 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1042,7 +1042,7 @@ class FormMail extends Form $defaultlines = $arraydefaultmessage->content_lines; if (isset($defaultlines)) { foreach ($this->substit_lines as $lineid => $substit_line) { - $lines .= make_substitutions($defaultlines, $substit_line)."\n"; + $lines .= make_substitutions($defaultlines, $substit_line, $outputlangs)."\n"; } } $this->substit['__LINES__'] = $lines; @@ -1087,7 +1087,10 @@ class FormMail extends Form if (GETPOSTISSET("message") && !GETPOST('modelselected')) { $defaultmessage = GETPOST("message", "restricthtml"); } else { - $defaultmessage = make_substitutions($defaultmessage, $this->substit); + // Pass $outputlangs so __(TranslationKey)__ in the template body is resolved + // in the language of the selected email template, not the operator's language + // (see issue #34540). + $defaultmessage = make_substitutions($defaultmessage, $this->substit, $outputlangs); // Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty) $defaultmessage = preg_replace("/^(
    )+/", "", $defaultmessage); $defaultmessage = preg_replace("/^\n+/", "", $defaultmessage); @@ -1468,7 +1471,7 @@ class FormMail extends Form */ public function getHtmlForTopic($arraydefaultmessage, $helpforsubstitution) { - global $langs, $form; + global $conf, $langs, $form; $defaulttopic = GETPOST('subject', 'restricthtml'); @@ -1480,7 +1483,17 @@ class FormMail extends Form } } - $defaulttopic = make_substitutions($defaulttopic, $this->substit); + // Resolve __(TranslationKey)__ in the language of the selected template + // (see issue #34540). Falls back to the caller's language when the template + // has no explicit language pinned. + $outputlangs = $langs; + if (is_object($arraydefaultmessage) && !empty($arraydefaultmessage->lang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($arraydefaultmessage->lang); + $outputlangs->load('other'); + } + + $defaulttopic = make_substitutions($defaulttopic, $this->substit, $outputlangs); $out = ''; $out .= ''; diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index a342693db32..7bb1ce43f5f 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -825,26 +825,26 @@ class Notify case 'FICHINTER_ADD_CONTACT': $link = ''.$newref.''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link); break; case 'FICHINTER_VALIDATE': $link = ''.$newref.''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated", $link); break; case 'FICHINTER_MODIFY': $link = ''.$newref.''; $context_info = array_key_exists('signature', $object->context) ? $object->getLibSignedStatus() : ''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionModified", $link, $context_info); break; case 'FICHINTER_CLOSE': $link = ''.$newref.''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionClosed", $link); break; case 'ORDER_SUPPLIER_VALIDATE': @@ -1150,26 +1150,26 @@ class Notify case 'FICHINTER_ADD_CONTACT': $link = ''.$newref.''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link); break; case 'FICHINTER_VALIDATE': $link = ''.$newref.''; $dir_output = $conf->facture->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $link); break; case 'FICHINTER_MODIFY': $link = ''.$newref.''; $context_info = array_key_exists('signature', $object->context) ? $object->getLibSignedStatus() : ''; $dir_output = $conf->ficheinter->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionModified", $link, $context_info); break; case 'FICHINTER_CLOSE': $link = ''.$newref.''; $dir_output = $conf->facture->dir_output; - $object_type = 'ficheinter'; + $object_type = 'fichinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionClosed", $link); break; case 'ORDER_SUPPLIER_CANCEL': diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 2e89de5a733..84c28e54826 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -1009,6 +1009,9 @@ function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tabl if ($feature == 'member') { $feature = 'adherent'; } + if ($feature == 'category') { + $feature = 'categorie'; + } if ($feature == 'project') { $feature = 'projet'; } diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index e6756d7b3bc..fa4a1a2c8f8 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -989,6 +989,16 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) { $('#tva_tx').val(tva_tx); } + // Sync the measuring unit dropdown with the product's default fk_unit + // (issue #34610). Without this, the dropdown keeps the static initial + // value (the first c_units row, typically "Kg") regardless of what + // the selected product is configured with. + if (typeof data.fk_unit != 'undefined' && data.fk_unit != null && $("#units").length) { + $("#units").val(data.fk_unit).trigger('change'); + } else if (typeof data.default_unit != 'undefined' && data.default_unit != null && $("#units").length) { + $("#units").val(data.default_unit).trigger('change'); + } + diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 8aff7c2c49b..6c14f8e8009 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -773,6 +773,7 @@ if (empty($reshook)) { if ($action == 'settracking_url') { // Test on permission not required $object->tracking_url = trim(GETPOST('tracking_url', 'restricthtml')); } + if ($action == 'settrueWeight') { // Test on permission not required $object->trueWeight = GETPOSTFLOAT('trueWeight'); $object->weight_units = GETPOSTINT('weight_units'); @@ -1756,8 +1757,9 @@ if ($action == 'create' && $usercancreate) { print $langs->trans("Weight"); print ''; print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"'); - print ' '; // Do not use GETPOSTINT here, we must accept '' also. - $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units'), 0, 2); + + print ' '; // Do not use GETPOSTINT here, we must accept '' also. + $text = $formproduct->selectMeasuringUnits("weight_units", "weight", (string) GETPOST('weight_units'), 0, 2); $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); print $form->textwithpicto($text, $htmltext); print ''; @@ -2068,8 +2070,8 @@ if ($action == 'create' && $usercancreate) { // Quantity to send print ''; if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || ($line->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES'))) { - if (GETPOSTINT('qtyl' . $indiceAsked)) { - $deliverableQty = GETPOSTINT('qtyl' . $indiceAsked); + if (GETPOSTISSET('qtyl'.$indiceAsked) && GETPOST('qtyl'.$indiceAsked) !== '') { + $deliverableQty = GETPOSTFLOAT('qtyl'.$indiceAsked, 'MS'); } print ''; $qtylValue = $deliverableQty; diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 79d67b2804f..9ac31383c42 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -754,8 +754,10 @@ if (empty($reshook)) { $result = $objectline->update($user); if ($result < 0) { - dol_print_error($db); - exit; + // Surface validation errors (e.g. mandatory extrafield left empty) as an + // event message on the same page instead of breaking with a full Dolibarr + // error screen that loses the user's edit context. + setEventMessages($objectline->error, $objectline->errors, 'errors'); } // Define output language diff --git a/htdocs/fourn/facture/card-rec.php b/htdocs/fourn/facture/card-rec.php index 059b2bd7fce..6897ff900e3 100644 --- a/htdocs/fourn/facture/card-rec.php +++ b/htdocs/fourn/facture/card-rec.php @@ -1011,7 +1011,7 @@ if ($action == 'create') { $projectid = GETPOST('projectid') ? GETPOST('projectid') : $object->fk_project; $langs->load('projects'); print '' . $langs->trans('Project') . ''; - $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, ''); + $numprojet = $formproject->select_projects((!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->thirdparty->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, ''); print '   thirdparty->id . (!empty($id) ? '&id=' . $id : '')) . '">' . $langs->trans("AddProject") . ''; print ''; } @@ -1039,7 +1039,7 @@ if ($action == 'create') { print "" . $langs->trans('Model') . ""; include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php'; $list = ModelePDFSuppliersInvoices::liste_modeles($db); - print $form->selectarray('modelpdf', $list, $conf->global->INVOICE_SUPPLIER_ADDON_PDF); + print $form->selectarray('modelpdf', $list, getDolGlobalString('INVOICE_SUPPLIER_ADDON_PDF')); print ""; // Public note @@ -1202,7 +1202,7 @@ if ($action == 'create') { $morehtmlref .= '
    '; $morehtmlref .= ''; $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects($object->socid, (string) $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= $formproject->select_projects((!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), (string) $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= ''; $morehtmlref .= '
    '; } else { diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 1cd6a7835ce..40eb5da3c03 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -216,7 +216,11 @@ if (!defined('DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > } // Clean parameters - $dolibarr_main_data_root = isset($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.'/../documents'; + // isset() is true on an empty string, which would let DOL_DATA_ROOT + // resolve to '' and the lock file to /install.lock (rejected by a + // restrictive open_basedir). Use !empty() so an empty value falls + // back to the default relative documents path. + $dolibarr_main_data_root = !empty($dolibarr_main_data_root) ? trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.'/../documents'; $dolibarr_main_url_root = isset($dolibarr_main_url_root) ? trim($dolibarr_main_url_root) : ''; $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ? trim($dolibarr_main_url_root_alt) : ''; $dolibarr_main_document_root = isset($dolibarr_main_document_root) ? trim($dolibarr_main_document_root) : ''; @@ -268,7 +272,7 @@ if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) { define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : '')); define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir -define('DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.'/../documents')); +define('DOL_DATA_ROOT', (!empty($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.'/../documents')); define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http* $suburi = strstr($uri, '/'); // $suburi contains url without domain diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index c308c61a7eb..a5a94d9079a 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -295,9 +295,10 @@ if ($action == 'fetch' && !empty($id)) { 'qty' => $outqty, 'discount' => $outdiscount, 'mandatory_period' => $mandatory_period, + 'array_options' => $object->array_options, - 'default_unit'=>$default_unit + 'default_unit' => $default_unit ); } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 60157c83fa4..b5ae2109fed 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1053,6 +1053,19 @@ class Product extends CommonObject $this->accountancy_code_sell_intra = trim((string) $this->accountancy_code_sell_intra); $this->accountancy_code_sell_export = trim((string) $this->accountancy_code_sell_export); + // Normalize the accountancy codes the way the admin dropdown does it, so an API client that + // sends '606111000' ends up with the same '606111' value the GUI stores (see issue #32343). + // When ACCOUNTING_MANAGE_ZERO is on, trailing zeros are part of the code and must be kept. + if (!getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + $this->accountancy_code_buy = clean_account($this->accountancy_code_buy); + $this->accountancy_code_buy_intra = clean_account($this->accountancy_code_buy_intra); + $this->accountancy_code_buy_export = clean_account($this->accountancy_code_buy_export); + $this->accountancy_code_sell = clean_account($this->accountancy_code_sell); + $this->accountancy_code_sell_intra = clean_account($this->accountancy_code_sell_intra); + $this->accountancy_code_sell_export = clean_account($this->accountancy_code_sell_export); + } + // Barcode value $this->barcode = trim($this->barcode); $this->mandatory_period = empty($this->mandatory_period) ? 0 : $this->mandatory_period; @@ -1488,6 +1501,19 @@ class Product extends CommonObject $this->accountancy_code_sell_intra = trim($this->accountancy_code_sell_intra); $this->accountancy_code_sell_export = trim($this->accountancy_code_sell_export); + // Normalize the accountancy codes the way the admin dropdown does it, so an API client that + // sends '606111000' ends up with the same '606111' value the GUI stores (see issue #32343). + // When ACCOUNTING_MANAGE_ZERO is on, trailing zeros are part of the code and must be kept. + if (!getDolGlobalString('ACCOUNTING_MANAGE_ZERO')) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + $this->accountancy_code_buy = clean_account($this->accountancy_code_buy); + $this->accountancy_code_buy_intra = clean_account($this->accountancy_code_buy_intra); + $this->accountancy_code_buy_export = clean_account($this->accountancy_code_buy_export); + $this->accountancy_code_sell = clean_account($this->accountancy_code_sell); + $this->accountancy_code_sell_intra = clean_account($this->accountancy_code_sell_intra); + $this->accountancy_code_sell_export = clean_account($this->accountancy_code_sell_export); + } + $this->db->begin(); $result = 0; diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 514e33be040..083d58e0e70 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -126,7 +126,14 @@ $type = GETPOST("type", 'alpha'); // Show/hide child product variants $show_childproducts = 0; if (isModEnabled('variants')) { - $show_childproducts = GETPOST('search_show_childproducts'); + // An HTML checkbox does not submit anything when unchecked, so a hidden + // "search_show_childproducts=0" companion field is emitted next to the + // checkbox (see below). GETPOSTISSET() then let's us distinguish a + // resubmission with the checkbox off from a request that does not carry + // the filter at all, and the value is read as a strict 0/1 flag. + if (GETPOSTISSET('search_show_childproducts')) { + $show_childproducts = GETPOSTINT('search_show_childproducts'); + } } $diroutputmassaction = $conf->product->dir_output.'/temp/massgeneration/'.$user->id; @@ -400,7 +407,7 @@ if (empty($reshook)) { $search_finished = ''; //$search_type=''; // There is 2 types of list: a list of product and a list of services. No list with both. So when we clear search criteria, we must keep the filter on type. - $show_childproducts = ''; + $show_childproducts = 0; $search_import_key = ''; $search_stockable_product = ''; $search_accountancy_code_sell = ''; @@ -827,7 +834,7 @@ if ($fourn_id > 0) { $param .= "&fourn_id=".urlencode((string) ($fourn_id)); } if ($show_childproducts) { - $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : ""); + $param .= "&search_show_childproducts=".urlencode((string) $show_childproducts); } if ($type != '') { $param .= '&type='.urlencode((string) ($type)); @@ -984,7 +991,11 @@ if (isModEnabled('category') && $user->hasRight('categorie', 'read')) { // Show/hide child variant products if (isModEnabled('variants')) { $moreforfilter .= '
    '; - $moreforfilter .= ''; + // Companion hidden field ensures search_show_childproducts is always + // posted, even when the checkbox below is unchecked, so the unchecked + // state survives the filter/pagination submit and is parsed as 0/1. + $moreforfilter .= ''; + $moreforfilter .= ''; $moreforfilter .= ' '; $moreforfilter .= '
    '; } diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 5dc6a840ab2..1170bd877bd 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1684,6 +1684,16 @@ class Task extends CommonObjectLine $ret = -1; } + // Propagate trigger handler messages from $this->errors (plural array) + // to $this->error (singular string) so callers like the REST API can + // surface a useful message instead of an empty error tail. + if ($ret <= 0 && empty($this->error) && !empty($this->errors)) { + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + } + if ($ret > 0) { // Recalculate amount of time spent for task and update denormalized field $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; @@ -2146,6 +2156,16 @@ class Task extends CommonObjectLine $ret = -1; } + // Propagate trigger handler messages from $this->errors (plural array) + // to $this->error (singular string) so callers like the REST API can + // surface a useful message instead of an empty error tail. + if ($ret < 0 && empty($this->error) && !empty($this->errors)) { + foreach ($this->errors as $errmsg) { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + } + if ($ret == 1 && (($this->timespent_old_duration != $this->timespent_duration) || getDolGlobalString('TIMESPENT_ALWAYS_UPDATE_THM'))) { if ($this->timespent_old_duration != $this->timespent_duration) { // Recalculate amount of time spent for task and update denormalized field diff --git a/htdocs/recruitment/class/api_recruitments.class.php b/htdocs/recruitment/class/api_recruitments.class.php index 87fb02e4b57..d2e240e2cef 100644 --- a/htdocs/recruitment/class/api_recruitments.class.php +++ b/htdocs/recruitment/class/api_recruitments.class.php @@ -375,7 +375,7 @@ class Recruitments extends DolibarrApi } // Check mandatory fields - $result = $this->_validate($request_data); + $result = $this->_validate($request_data, $this->jobposition); foreach ($request_data as $field => $value) { if ($field === 'caller') { @@ -414,8 +414,10 @@ class Recruitments extends DolibarrApi throw new RestException(403); } - // Check mandatory fields - $result = $this->_validate($request_data); + // Check mandatory fields. Validate against the candidature model so the API + // rejects with the actual missing candidature fields (e.g. email) instead of + // the unrelated job position fields (see issue #38429). + $result = $this->_validate($request_data, $this->candidature); foreach ($request_data as $field => $value) { if ($field === 'caller') { @@ -686,25 +688,26 @@ class Recruitments extends DolibarrApi * Validate fields before create or update object * * @param ?array $data Array of data to validate + * @param CommonObject $object Object to validate against * @return array * * @throws RestException */ - private function _validate($data) + private function _validate($data, $object) { if ($data === null) { $data = array(); } - $jobposition = array(); - foreach ($this->jobposition->fields as $field => $propfield) { + $result = array(); + foreach ($object->fields as $field => $propfield) { if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || empty($propfield['notnull']) || $propfield['notnull'] != 1) { continue; // Not a mandatory field } if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); } - $jobposition[$field] = $data[$field]; + $result[$field] = $data[$field]; } - return $jobposition; + return $result; } } diff --git a/htdocs/takepos/receipt.php b/htdocs/takepos/receipt.php index de468d5e5a5..1969d97b1f1 100644 --- a/htdocs/takepos/receipt.php +++ b/htdocs/takepos/receipt.php @@ -406,14 +406,19 @@ if (getDolGlobalString('TAKEPOS_TICKET_VAT_GROUPPED')) { // Now show local taxes if company uses them -if (price2num($object->total_localtax1, 'MU') || $mysoc->useLocalTax(1)) { ?> +// $mysoc->useLocalTax(N) is a country-wide flag (true as soon as the country has a +// matching c_tva row with a localtaxN_type), so on its own it always prints the line +// for Spanish companies even when the company is "No sujeto a RE / IRPF". Mirror the +// pattern used by compta/facture/card.php, card-rec.php and prelevement.php and gate +// the country check on $mysoc->localtaxN_assuj == "1". +if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || price2num($object->total_localtax1, 'MU')) { ?> trans("TotalLT1").''.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency)."\n"; } ?> -total_localtax2, 'MU') || $mysoc->useLocalTax(2)) { ?> +localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || price2num($object->total_localtax2, 'MU')) { ?> trans("TotalLT2").''.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency)."\n"; diff --git a/htdocs/user/card.php b/htdocs/user/card.php index d7ac0cd50c9..4c778accc2c 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -472,7 +472,7 @@ if (empty($reshook)) { $object->pass = GETPOST("password", 'password'); } if ($permissiontoeditpasswordandsee || $user->hasRight("api", "apikey", "generate")) { - $object->api_key = (GETPOST("api_key", 'alphanohtml')) ? GETPOST("api_key", 'alphanohtml') : $object->api_key; + $object->api_key = (GETPOSTISSET("api_key", 'alphanohtml')) ? GETPOST("api_key", 'alphanohtml') : $object->api_key; } if (!empty($user->admin) && $user->id != $id) { // admin flag can only be set/unset by an admin user and not four ourself @@ -561,6 +561,9 @@ if (empty($reshook)) { $isimage = image_format_supported($_FILES['photo']['name']); if ($isimage > 0) { $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); + if ($object->id == $user->id) { + $user->photo = $object->photo; + } } else { $error++; $langs->load("errors");