Merge branch '18.0' into 18.0-ticket_code_review

This commit is contained in:
Eric Seigne 2024-03-08 00:12:22 +01:00
commit 57e5599d82
18 changed files with 106 additions and 28 deletions

View file

@ -538,7 +538,7 @@ if ($action != 'export_csv') {
// Show first line of a break
print '<tr class="trforbreak">';
print '<td colspan="'.($colspan+1).'" style="font-weight:bold; border-bottom: 1pt solid black;">'.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').'</td>';
print '<td colspan="'.($colspan+1).'" class="tdforbreak">'.$root_account_number.($root_account_description ? ' - '.$root_account_description : '').'</td>';
print '</tr>';
$displayed_account = $root_account_number;

View file

@ -3102,6 +3102,7 @@ class Adherent extends CommonObject
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
$sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
$sql .= " AND statut = 1";
$sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
//$sql .= " LIMIT 10000";

View file

@ -358,7 +358,7 @@ if ($rowid && $action != 'edit') {
print '<div class="tabsAction">';
if ($user->hasRight('adherent', 'cotisation', 'creer')) {
if (!empty($bankline->rappro) || empty($bankline)) {
if (empty($bankline->rappro) || empty($bankline)) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated").'" href="#">'.$langs->trans("Modify")."</a></div>";

View file

@ -1821,6 +1821,9 @@ if ($resql) {
$totalarray['val']['f.total_tva'] = 0;
$totalarray['val']['f.total_ht'] = 0;
$totalarray['val']['f.total_ttc'] = 0;
$totalarray['val']['totalam'] = 0;
$totalarray['val']['rtp'] = 0;
$with_margin_info = false;
if (isModEnabled('margin') && (

View file

@ -102,7 +102,7 @@ $arrayfields = array(
'cs.fk_type' =>array('label'=>"Type", 'checked'=>1, 'position'=>30),
'cs.date_ech' =>array('label'=>"Date", 'checked'=>1, 'position'=>40),
'cs.periode' =>array('label'=>"PeriodEndDate", 'checked'=>1, 'position'=>50),
'p.ref' =>array('label'=>"ProjectRef", 'checked'=>1, 'position'=>60, 'enable'=>(isModEnabled('project'))),
'p.ref' =>array('label'=>"ProjectRef", 'checked'=>1, 'position'=>60, 'enabled'=>(isModEnabled('project'))),
'cs.fk_user' =>array('label'=>"Employee", 'checked'=>1, 'position'=>70),
'cs.fk_mode_reglement' =>array('checked'=>-1, 'position'=>80, 'label'=>"DefaultPaymentMode"),
'cs.amount' =>array('label'=>"Amount", 'checked'=>1, 'position'=>100),

View file

@ -619,6 +619,19 @@ abstract class CommonObject
public $user_modification_id;
/**
* @var int ID
* @deprecated Use $user_creation_id
*/
public $fk_user_creat;
/**
* @var int ID
* @deprecated Use $user_modification_id
*/
public $fk_user_modif;
public $next_prev_filter;
/**
@ -9058,9 +9071,9 @@ abstract class CommonObject
/**
* Function to prepare a part of the query for insert by returning an array with all properties of object.
* Function to return the array of data key-value from the ->fields and all the ->properties of an object.
*
* Note $this->${field} are set by the page that make the createCommon() or the updateCommon().
* Note: $this->${field} are set by the page that make the createCommon() or the updateCommon().
* $this->${field} should be a clean and string value (so date are formated for SQL insert).
*
* @return array Array with all values of each properties to update
@ -9263,6 +9276,11 @@ abstract class CommonObject
}
if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) {
$fieldvalues['fk_user_creat'] = $user->id;
$this->fk_user_creat = $user->id;
}
if (array_key_exists('user_modification_id', $fieldvalues) && !($fieldvalues['user_modification_id'] > 0)) {
$fieldvalues['user_modification_id'] = $user->id;
$this->user_modification_id = $user->id;
}
unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert.
if (array_key_exists('ref', $fieldvalues)) {

View file

@ -6348,7 +6348,7 @@ class Form
if (!empty($user) && $user->admin && preg_match('/\'(..)\'/', $country_code, $reg)) {
$langs->load("errors");
$new_country_code = $reg[1];
$country_id = dol_getIdFromCode($this->db, $new_country_code, 'c_pays', 'code', 'rowid');
$country_id = dol_getIdFromCode($this->db, $new_country_code, 'c_country', 'code', 'rowid');
$this->error .= '<br>'.$langs->trans("ErrorFixThisHere", DOL_URL_ROOT.'/admin/dict.php?id=10'.($country_id > 0 ? '&countryidforinsert='.$country_id : ''));
}
$this->error .= '</span>';

View file

@ -81,7 +81,7 @@ function expensereport_prepare_head($object)
$head[$h][2] = 'info';
$h++;
complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'add', 'external');
complete_head_from_modules($conf, $langs, $object, $head, $h, 'expensereport', 'add', 'external');
complete_head_from_modules($conf, $langs, $object, $head, $h, 'expensereport', 'remove');

View file

@ -9289,22 +9289,28 @@ function dol_eval($s, $returnvalue = 0, $hideerrors = 1, $onlysimplestring = '1'
// We block use of php exec or php file functions
$forbiddenphpstrings = array('$$');
$forbiddenphpstrings = array_merge($forbiddenphpstrings, array('_ENV', '_SESSION', '_COOKIE', '_GET', '_POST', '_REQUEST'));
$forbiddenphpstrings = array_merge($forbiddenphpstrings, array('_ENV', '_SESSION', '_COOKIE', '_GET', '_POST', '_REQUEST', 'ReflectionFunction'));
$forbiddenphpfunctions = array("exec", "passthru", "shell_exec", "system", "proc_open", "popen");
$forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array("dol_eval", "executeCLI", "verifCond")); // native dolibarr functions
$forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array("base64_decode", "rawurldecode", "urldecode")); // decode string functions
$forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array("base64_decode", "rawurldecode", "urldecode", "str_rot13", "hex2bin")); // decode string functions used to obfuscated function name
$forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array("fopen", "file_put_contents", "fputs", "fputscsv", "fwrite", "fpassthru", "require", "include", "mkdir", "rmdir", "symlink", "touch", "unlink", "umask"));
$forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array("get_defined_functions", "get_defined_vars", "get_defined_constants", "get_declared_classes"));
$forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array("function", "call_user_func"));
$forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array("require", "include", "require_once", "include_once"));
$forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array("eval", "create_function", "assert", "mb_ereg_replace")); // function with eval capabilities
$forbiddenphpmethods = array('invoke', 'invokeArgs'); // Method of ReflectionFunction to execute a function
$forbiddenphpregex = 'global\s+\$|\b('.implode('|', $forbiddenphpfunctions).')\b';
$forbiddenphpmethodsregex = '->('.implode('|', $forbiddenphpmethods).')';
do {
$oldstringtoclean = $s;
$s = str_ireplace($forbiddenphpstrings, '__forbiddenstring__', $s);
$s = preg_replace('/'.$forbiddenphpregex.'/i', '__forbiddenstring__', $s);
$s = preg_replace('/'.$forbiddenphpmethodsregex.'/i', '__forbiddenstring__', $s);
//$s = preg_replace('/\$[a-zA-Z0-9_\->\$]+\(/i', '', $s); // Remove $function( call and $mycall->mymethod(
} while ($oldstringtoclean != $s);

View file

@ -884,7 +884,10 @@ function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tabl
$feature = 'agenda';
$dbtablename = 'actioncomm';
}
if ($feature == 'payment_sc') {
if ($feature == 'payment_sc' && empty($parenttableforentity)) {
// If we check perm on payment page but $parenttableforentity not defined, we force value on parent table
$parenttableforentity = '';
$dbtablename = "chargesociales";
$feature = "chargesociales";
$objectid = $object->fk_charge;
}
@ -892,7 +895,7 @@ function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tabl
$checkonentitydone = 0;
// Array to define rules of checks to do
$check = array('adherent', 'banque', 'bom', 'don', 'mrp', 'user', 'usergroup', 'payment', 'payment_supplier', 'product', 'produit', 'service', 'produit|service', 'categorie', 'resource', 'expensereport', 'holiday', 'salaries', 'website', 'recruitment', 'chargesociales'); // Test on entity only (Objects with no link to company)
$check = array('adherent', 'banque', 'bom', 'don', 'mrp', 'user', 'usergroup', 'payment', 'payment_supplier', 'payment_sc', 'product', 'produit', 'service', 'produit|service', 'categorie', 'resource', 'expensereport', 'holiday', 'salaries', 'website', 'recruitment', 'chargesociales'); // Test on entity only (Objects with no link to company)
$checksoc = array('societe'); // Test for object Societe
$checkparentsoc = array('agenda', 'contact', 'contrat'); // Test on entity + link to third party on field $dbt_keyfield. Allowed if link is empty (Ex: contacts...).
$checkproject = array('projet', 'project'); // Test for project object

View file

@ -2,7 +2,7 @@
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2023 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
@ -1501,6 +1501,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it
$frequency = isset($this->cronjobs[$key]['frequency']) ? $this->cronjobs[$key]['frequency'] : '';
$unitfrequency = isset($this->cronjobs[$key]['unitfrequency']) ? $this->cronjobs[$key]['unitfrequency'] : '';
$priority = isset($this->cronjobs[$key]['priority']) ? $this->cronjobs[$key]['priority'] : '';
$datenextrun = isset($this->cronjobs[$key]['datenextrun']) ? $this->cronjobs[$key]['datenextrun'] : '';
$datestart = isset($this->cronjobs[$key]['datestart']) ? $this->cronjobs[$key]['datestart'] : '';
$dateend = isset($this->cronjobs[$key]['dateend']) ? $this->cronjobs[$key]['dateend'] : '';
$status = isset($this->cronjobs[$key]['status']) ? $this->cronjobs[$key]['status'] : '';
@ -1536,7 +1537,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it
$this->db->begin();
if (!$err) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, datestart, dateend, label, jobtype, classesname, objectname, methodename, command, params, note,";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, datenextrun, datestart, dateend, label, jobtype, classesname, objectname, methodename, command, params, note,";
if (is_int($frequency)) {
$sql .= ' frequency,';
}
@ -1553,6 +1554,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it
$sql .= " VALUES (";
$sql .= "'".$this->db->escape(empty($this->rights_class) ?strtolower($this->name) : $this->rights_class)."', ";
$sql .= "'".$this->db->idate($now)."', ";
$sql .= ($datenextrun ? "'".$this->db->idate($datenextrun)."'" : "'".$this->db->idate($now)."'").", ";
$sql .= ($datestart ? "'".$this->db->idate($datestart)."'" : "'".$this->db->idate($now)."'").", ";
$sql .= ($dateend ? "'".$this->db->idate($dateend)."'" : "NULL").", ";
$sql .= "'".$this->db->escape($label)."', ";

View file

@ -246,13 +246,15 @@ class InterfaceTicketEmail extends DolibarrTriggers
$linked_contacts = array_merge($linked_contacts, $object->listeContact(-1, 'internal'));
if (empty($linked_contacts) && !empty($conf->global->TICKET_NOTIFY_AT_CLOSING) && !empty($object->fk_soc)) {
$object->fetch_thirdparty();
$linked_contacts[] = $object->thirdparty->email;
$linked_contacts[]['email'] = $object->thirdparty->email;
}
$contactid = GETPOST('contactid', 'int');
$res = 0;
if ($contactid > 0) {
// TODO This security test has no sens. We must check that $contactid is inside $linked_contacts[]['id'] when $linked_contacts[]['source'] = 'external' or 'thirdparty'
// Refuse email if not
$contact = new Contact($this->db);
$res = $contact->fetch($contactid);
if (! in_array($contact, $linked_contacts)) {

View file

@ -34,7 +34,7 @@ if (!defined('DOL_APPLICATION_TITLE')) {
define('DOL_APPLICATION_TITLE', 'Dolibarr');
}
if (!defined('DOL_VERSION')) {
define('DOL_VERSION', '18.0.5'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c
define('DOL_VERSION', '18.0.6'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c
}
if (!defined('EURO')) {

View file

@ -1350,8 +1350,6 @@ if (empty($reshook)) {
$tva_tx = get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id);
}
$object->special_code = $lines[$i]->special_code;
$result = $object->addline(
$desc,
$lines[$i]->subprice,
@ -1374,7 +1372,9 @@ if (empty($reshook)) {
$lines[$i]->fk_unit,
0,
$element,
!empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->rowid
!empty($lines[$i]->id) ? $lines[$i]->id : $lines[$i]->rowid,
-1,
$lines[$i]->special_code
);
if ($result < 0) {

View file

@ -114,16 +114,16 @@ if ($action == 'add_payment') {
if (!$error) {
$paymentid = 0;
$pay_amount_capital = price2num(GETPOST('amount_capital'));
$pay_amount_insurance = price2num(GETPOST('amount_insurance'));
$pay_amount_capital = (float) price2num(GETPOST('amount_capital'));
$pay_amount_insurance = (float) price2num(GETPOST('amount_insurance'));
// User can't set interest him self if schedule is set (else value in schedule can be incoherent)
if (!empty($line)) {
$pay_amount_interest = $line->amount_interest;
} else {
$pay_amount_interest = price2num(GETPOST('amount_interest'));
$pay_amount_interest = (float) price2num(GETPOST('amount_interest'));
}
$remaindertopay = price2num(GETPOST('remaindertopay'));
$amount = $pay_amount_capital + $pay_amount_insurance + $pay_amount_interest;
$remaindertopay = (float) price2num(GETPOST('remaindertopay'));
$amount = (float) price2num($pay_amount_capital + $pay_amount_insurance + $pay_amount_interest, 'MT');
// This term is allready paid
if (!empty($line) && !empty($line->fk_bank)) {

View file

@ -1045,8 +1045,9 @@ if ($resql) {
// Expected quantity = Quantity in stock when we start inventory
print '<td class="right expectedqty" id="id_'.$obj->rowid.'" title="Stock viewed at last update: '.$obj->qty_stock.'">';
$valuetoshow = $obj->qty_stock;
// For inventory not yet close, we overwrite with the real value in stock now
if ($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) {
if (($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) && !getDolGlobalString('DISABLE_QTY_OVERWRITE')) {
if (isModEnabled('productbatch') && $product_static->hasbatch()) {
$valuetoshow = $product_static->stock_warehouse[$obj->fk_warehouse]->detail_batch[$obj->batch]->qty;
} else {

View file

@ -248,6 +248,7 @@ if ($resql) {
}
}
}
?>
<script>
@ -509,20 +510,51 @@ if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) {
?>
</script>
<?php
$showothercurrency = 0;
if (isModEnabled('multicurrency') && $_SESSION["takeposcustomercurrency"] != "" && $conf->currency != $_SESSION["takeposcustomercurrency"]) {
//Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
$showothercurrency = 1;
include_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php';
$multicurrency = new MultiCurrency($db);
$multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]);
}
?>
<div style="position:relative; padding-top: 20px; left:5%; height:140px; width:90%;">
<div class="paymentbordline paymentbordlinetotal center">
<span class="takepospay colorwhite"><?php echo $langs->trans('TotalTTC'); ?>: <span id="totaldisplay" class="colorwhite"><?php echo price($invoice->total_ttc, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?></span></span>
<span class="takepospay colorwhite"><?php echo $langs->trans('TotalTTC'); ?>: <span id="totaldisplay" class="colorwhite"><?php
echo price($invoice->total_ttc, 1, '', 1, -1, -1, $conf->currency);
if ($showothercurrency) {
print ' &nbsp; <span id="linecolht-span-total opacitymedium" style="font-size:0.9em; font-style:italic;">(' . price($invoice->total_ht * $multicurrency->rate->rate) . ' ' . $_SESSION["takeposcustomercurrency"] . ')</span>';
}
?></span></span>
</div>
<?php if ($remaintopay != $invoice->total_ttc) { ?>
<div class="paymentbordline paymentbordlineremain center">
<span class="takepospay colorwhite"><?php echo $langs->trans('RemainToPay'); ?>: <span id="remaintopaydisplay" class="colorwhite"><?php echo price($remaintopay, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?></span></span>
<span class="takepospay colorwhite"><?php echo $langs->trans('RemainToPay'); ?>: <span id="remaintopaydisplay" class="colorwhite"><?php
echo price($remaintopay, 1, '', 1, -1, -1, $invoice->multicurrency_code);
if ($showothercurrency) {
print ' &nbsp; <span id="linecolht-span-total opacitymedium" style="font-size:0.9em; font-style:italic;">(' . price($remaintopay * $multicurrency->rate->rate) . ' ' . $_SESSION["takeposcustomercurrency"] . ')</span>';
}
?></span></span>
</div>
<?php } ?>
<div class="paymentbordline paymentbordlinereceived center">
<span class="takepospay colorwhite"><?php echo $langs->trans("Received"); ?>: <span class="change1 colorred"><?php echo price(0, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?></span><input type="hidden" id="change1" class="change1" value="0"></span>
<span class="takepospay colorwhite"><?php echo $langs->trans("Received"); ?>: <span class="change1 colorred"><?php
echo price(0, 1, '', 1, -1, -1, $invoice->multicurrency_code);
if ($showothercurrency) {
print ' &nbsp; <span id="linecolht-span-total opacitymedium" style="font-size:0.9em; font-style:italic;">(' . price(0 * $multicurrency->rate->rate) . ' ' . $_SESSION["takeposcustomercurrency"] . ')</span>';
}
?></span><input type="hidden" id="change1" class="change1" value="0"></span>
</div>
<div class="paymentbordline paymentbordlinechange center">
<span class="takepospay colorwhite"><?php echo $langs->trans("Change"); ?>: <span class="change2 colorwhite"><?php echo price(0, 1, '', 1, -1, -1, $invoice->multicurrency_code); ?></span><input type="hidden" id="change2" class="change2" value="0"></span>
<span class="takepospay colorwhite"><?php echo $langs->trans("Change"); ?>: <span class="change2 colorwhite"><?php
echo price(0, 1, '', 1, -1, -1, $invoice->multicurrency_code);
if ($showothercurrency) {
print ' &nbsp; <span id="linecolht-span-total opacitymedium" style="font-size:0.9em; font-style:italic;">(' . price(0 * $multicurrency->rate->rate) . ' ' . $_SESSION["takeposcustomercurrency"] . ')</span>';
}
?></span><input type="hidden" id="change2" class="change2" value="0"></span>
</div>
<?php
if (!empty($conf->global->TAKEPOS_CAN_FORCE_BANK_ACCOUNT_DURING_PAYMENT)) {

View file

@ -960,6 +960,16 @@ class SecurityTest extends PHPUnit\Framework\TestCase
print "result = ".$result."\n";
$this->assertEquals('Parent project not found', $result);
$s = 'new abc->invoke(\'whoami\')';
$result=dol_eval($s, 1, 1, '2');
print "result = ".$result."\n";
$this->assertEquals('Bad string syntax to evaluate: new abc__forbiddenstring__(\'whoami\')', $result);
$s = 'new ReflectionFunction(\'abc\')';
$result=dol_eval($s, 1, 1, '2');
print "result = ".$result."\n";
$this->assertEquals('Bad string syntax to evaluate: new __forbiddenstring__(\'abc\')', $result);
$result=dol_eval('$a=function() { }; $a;', 1, 1, '');
print "result = ".$result."\n";
$this->assertContains('Bad string syntax to evaluate', $result);