Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentjdc committed Aug 31, 2023
1 parent 815d815 commit 0d23eae
Show file tree
Hide file tree
Showing 26 changed files with 4,181 additions and 511 deletions.
18 changes: 16 additions & 2 deletions htdocs/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
require_once DOL_DOCUMENT_ROOT.'/api/class/api.class.php';
require_once DOL_DOCUMENT_ROOT.'/api/class/api_access.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ip.lib.php';


$url = $_SERVER['PHP_SELF'];
Expand Down Expand Up @@ -190,9 +191,22 @@

// Restrict API to some IPs
if (!empty($conf->global->API_RESTRICT_ON_IP)) {
$allowedip = explode(' ', $conf->global->API_RESTRICT_ON_IP);
$allowedips = explode(' ', $conf->global->API_RESTRICT_ON_IP);
$ipremote = getUserRemoteIP();
if (!in_array($ipremote, $allowedip)) {
$ip_is_allowed = false;
if (in_array($ipremote, $allowedips)) {
$ip_is_allowed = true;
} else {
// check for ip range
foreach($allowedips as $allowedip) {
if (ipInRange($ipremote, $allowedip)) {
$ip_is_allowed = true;
break;
}
}
}

if (!$ip_is_allowed) {
dol_syslog('Remote ip is '.$ipremote.', not into list '.$conf->global->API_RESTRICT_ON_IP);
print 'APIs are not allowed from the IP '.$ipremote;
header('HTTP/1.1 503 API not allowed from your IP '.$ipremote);
Expand Down
3 changes: 2 additions & 1 deletion htdocs/commande/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
// Link to a project
$object->setProject(GETPOST('projectid', 'int'));
} elseif ($action == 'add' && $usercancreate) {

// Add order
$datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
$date_delivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
Expand Down Expand Up @@ -1715,7 +1716,7 @@
$langs->load("projects");
print '<tr>';
print '<td>'.$langs->trans("Project").'</td><td>';
print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
print '</td>';
print '</tr>';
Expand Down
1 change: 1 addition & 0 deletions htdocs/core/class/commoninvoice.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ public function is_erasable()
$this->fetch_thirdparty(); // We need to have this->thirdparty defined, in case of numbering rule use tags that depend on thirdparty (like {t} tag).
}
$maxref = $this->getNextNumRef($this->thirdparty, 'last');
echo '==>'.$maxref;

// If there is no invoice into the reset range and not already dispatched, we can delete
// If invoice to delete is last one and not already dispatched, we can delete
Expand Down
87 changes: 31 additions & 56 deletions htdocs/core/class/commonobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Copyright (C) 2012-2015 Marcos García <[email protected]>
* Copyright (C) 2012-2015 Raphaël Doursenaud <[email protected]>
* Copyright (C) 2012 Cedric Salvador <[email protected]>
* Copyright (C) 2015-2022 Alexandre Spangaro <[email protected]>
* Copyright (C) 2015-2021 Alexandre Spangaro <[email protected]>
* Copyright (C) 2016 Bahfir abbes <[email protected]>
* Copyright (C) 2017 ATM Consulting <[email protected]>
* Copyright (C) 2017-2019 Nicolas ZABOURI <[email protected]>
Expand Down Expand Up @@ -83,11 +83,6 @@ abstract class CommonObject
*/
public $element;

/**
* @var string Name to use for 'features' parameter to check module permissions with restrictedArea(). Undefined means same value than $element.
*/
public $element_for_permission;

/**
* @var string Name of table without prefix where object is stored
*/
Expand Down Expand Up @@ -2931,20 +2926,15 @@ public function line_order($renum = false, $rowidorder = 'ASC', $fk_parent_line
return -1;
}

$fieldposition = 'rang'; // @todo Rename 'rang' into 'position'
if (in_array($this->table_element_line, array('bom_bomline', 'ecm_files', 'emailcollector_emailcollectoraction', 'product_attribute_value'))) {
$fieldposition = 'position';
}

// Count number of lines to reorder (according to choice $renum)
$nl = 0;
$sql = "SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
if (!$renum) {
$sql .= " AND " . $fieldposition . " = 0";
$sql .= ' AND rang = 0';
}
if ($renum) {
$sql .= " AND " . $fieldposition . " <> 0";
$sql .= ' AND rang <> 0';
}

dol_syslog(get_class($this)."::line_order", LOG_DEBUG);
Expand All @@ -2965,7 +2955,7 @@ public function line_order($renum = false, $rowidorder = 'ASC', $fk_parent_line
if ($fk_parent_line) {
$sql .= ' AND fk_parent_line IS NULL';
}
$sql .= " ORDER BY " . $fieldposition . " ASC, rowid " . $rowidorder;
$sql .= " ORDER BY rang ASC, rowid ".$rowidorder;

dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG);
$resql = $this->db->query($sql);
Expand Down Expand Up @@ -3006,17 +2996,12 @@ public function line_order($renum = false, $rowidorder = 'ASC', $fk_parent_line
*/
public function getChildrenOfLine($id, $includealltree = 0)
{
$fieldposition = 'rang'; // @todo Rename 'rang' into 'position'
if (in_array($this->table_element_line, array('bom_bomline', 'ecm_files', 'emailcollector_emailcollectoraction', 'product_attribute_value'))) {
$fieldposition = 'position';
}

$rows = array();

$sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
$sql .= ' AND fk_parent_line = '.((int) $id);
$sql .= " ORDER BY " . $fieldposition . " ASC";
$sql .= ' ORDER BY rang ASC';

dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id, LOG_DEBUG);
$resql = $this->db->query($sql);
Expand Down Expand Up @@ -3087,7 +3072,7 @@ public function updateRangOfLine($rowid, $rang)
{
global $hookmanager;
$fieldposition = 'rang'; // @todo Rename 'rang' into 'position'
if (in_array($this->table_element_line, array('bom_bomline', 'ecm_files', 'emailcollector_emailcollectoraction', 'product_attribute_value'))) {
if (in_array($this->table_element_line, array('bom_bomline', 'ecm_files', 'emailcollector_emailcollectoraction'))) {
$fieldposition = 'position';
}

Expand Down Expand Up @@ -3133,13 +3118,13 @@ public function updateLineUp($rowid, $rang)
{
if ($rang > 1) {
$fieldposition = 'rang';
if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction', 'product_attribute_value'))) {
if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
$fieldposition = 'position';
}

$sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang);
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
$sql .= " AND " . $fieldposition . " = " . ((int) ($rang - 1));
$sql .= ' AND rang = '.((int) ($rang - 1));
if ($this->db->query($sql)) {
$sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang - 1));
$sql .= ' WHERE rowid = '.((int) $rowid);
Expand All @@ -3164,13 +3149,13 @@ public function updateLineDown($rowid, $rang, $max)
{
if ($rang < $max) {
$fieldposition = 'rang';
if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction', 'product_attribute_value'))) {
if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
$fieldposition = 'position';
}

$sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang);
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
$sql .= " AND " . $fieldposition . " = " . ((int) ($rang + 1));
$sql .= ' AND rang = '.((int) ($rang + 1));
if ($this->db->query($sql)) {
$sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang + 1));
$sql .= ' WHERE rowid = '.((int) $rowid);
Expand All @@ -3191,12 +3176,7 @@ public function updateLineDown($rowid, $rang, $max)
*/
public function getRangOfLine($rowid)
{
$fieldposition = 'rang';
if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction', 'product_attribute_value'))) {
$fieldposition = 'position';
}

$sql = "SELECT " . $fieldposition . " FROM ".$this->db->prefix().$this->table_element_line;
$sql = "SELECT rang FROM ".$this->db->prefix().$this->table_element_line;
$sql .= " WHERE rowid = ".((int) $rowid);

dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG);
Expand All @@ -3215,14 +3195,9 @@ public function getRangOfLine($rowid)
*/
public function getIdOfLine($rang)
{
$fieldposition = 'rang';
if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction', 'product_attribute_value'))) {
$fieldposition = 'position';
}

$sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
$sql .= " WHERE ".$this->fk_element." = ".((int) $this->id);
$sql .= " AND " . $fieldposition . " = ".((int) $rang);
$sql .= " AND rang = ".((int) $rang);
$resql = $this->db->query($sql);
if ($resql) {
$row = $this->db->fetch_row($resql);
Expand All @@ -3241,7 +3216,7 @@ public function line_max($fk_parent_line = 0)
{
// phpcs:enable
$positionfield = 'rang';
if (in_array($this->table_element, array('bom_bom', 'product_attribute'))) {
if ($this->table_element == 'bom_bom') {
$positionfield = 'position';
}

Expand Down Expand Up @@ -3695,7 +3670,7 @@ public function add_object_linked($origin = null, $origin_id = null, $f_user = n

// Elements of the core modules which have `$module` property but may to which we don't want to prefix module part to the element name for finding the linked object in llx_element_element.
// It's because an entry for this element may be exist in llx_element_element before this modification (version <=14.2) and ave named only with their element name in fk_source or fk_target.
$coremodule = array('knowledgemanagement', 'partnership', 'workstation', 'ticket', 'recruitment', 'eventorganization', 'asset');
$coremodule = array('knowledgemanagement', 'partnership', 'workstation', 'ticket', 'recruitment', 'eventorganization');
// Add module part to target type if object has $module property and isn't in core modules.
$targettype = ((!empty($this->module) && ! in_array($this->module, $coremodule)) ? $this->module.'_' : '').$this->element;

Expand Down Expand Up @@ -5330,7 +5305,8 @@ protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $h
$sav_charset_output = $outputlangs->charset_output;

if (in_array(get_class($this), array('Adherent'))) {
$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, 'tmp_cards', $moreparams);
$arrayofrecords = array(); // The write_file of templates of adherent class need this var
$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams);
} else {
$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
}
Expand Down Expand Up @@ -5713,12 +5689,12 @@ public function setValuesForExtraLanguages($onlykey = '')

$enabled = 1;
if (isset($this->fields[$key]['enabled'])) {
$enabled = dol_eval($this->fields[$key]['enabled'], 1, 1, '1');
$enabled = dol_eval($this->fields[$key]['enabled'], 1);
}
/*$perms = 1;
if (isset($this->fields[$key]['perms']))
{
$perms = dol_eval($this->fields[$key]['perms'], 1, 1, '1');
$perms = dol_eval($this->fields[$key]['perms'], 1);
}*/
if (empty($enabled)) {
continue;
Expand All @@ -5728,11 +5704,11 @@ public function setValuesForExtraLanguages($onlykey = '')
if (in_array($key_type, array('date'))) {
// Clean parameters
// TODO GMT date in memory must be GMT so we should add gm=true in parameters
$value_key = dol_mktime(0, 0, 0, GETPOST($postfieldkey."month", 'int'), GETPOST($postfieldkey."day", 'int'), GETPOST($postfieldkey."year", 'int'));
$value_key = dol_mktime(0, 0, 0, $_POST[$postfieldkey."month"], $_POST[$postfieldkey."day"], $_POST[$postfieldkey."year"]);
} elseif (in_array($key_type, array('datetime'))) {
// Clean parameters
// TODO GMT date in memory must be GMT so we should add gm=true in parameters
$value_key = dol_mktime(GETPOST($postfieldkey."hour", 'int'), GETPOST($postfieldkey."min", 'int'), 0, GETPOST($postfieldkey."month", 'int'), GETPOST($postfieldkey."day", 'int'), GETPOST($postfieldkey."year", 'int'));
$value_key = dol_mktime($_POST[$postfieldkey."hour"], $_POST[$postfieldkey."min"], 0, $_POST[$postfieldkey."month"], $_POST[$postfieldkey."day"], $_POST[$postfieldkey."year"]);
} elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) {
$value_arr = GETPOST($postfieldkey, 'array'); // check if an array
if (!empty($value_arr)) {
Expand Down Expand Up @@ -5874,7 +5850,7 @@ public function fetch_optionals($rowid = null, $optionsArray = null)
if (!empty($extrafields) && !empty($extrafields->attributes[$this->table_element]['computed'][$key])) {
//var_dump($conf->disable_compute);
if (empty($conf->disable_compute)) {
$this->array_options["options_".$key] = dol_eval($extrafields->attributes[$this->table_element]['computed'][$key], 1, 0, '');
$this->array_options["options_".$key] = dol_eval($extrafields->attributes[$this->table_element]['computed'][$key], 1, 0);
}
}
}
Expand Down Expand Up @@ -5955,6 +5931,7 @@ public function insertExtraFields($trigger = '', $userused = null)

$error = 0;


if (!empty($this->array_options)) {
// Check parameters
$langs->load('admin');
Expand Down Expand Up @@ -6005,7 +5982,7 @@ public function insertExtraFields($trigger = '', $userused = null)

if (!empty($attrfieldcomputed)) {
if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) {
$value = dol_eval($attrfieldcomputed, 1, 0, '');
$value = dol_eval($attrfieldcomputed, 1, 0);
dol_syslog($langs->trans("Extrafieldcomputed")." sur ".$attributeLabel."(".$value.")", LOG_DEBUG);
$new_array_options[$key] = $value;
} else {
Expand Down Expand Up @@ -6372,7 +6349,7 @@ public function updateExtraField($key, $trigger = null, $userused = null)

if (!empty($attrfieldcomputed)) {
if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) {
$value = dol_eval($attrfieldcomputed, 1, 0, '');
$value = dol_eval($attrfieldcomputed, 1, 0);
dol_syslog($langs->trans("Extrafieldcomputed")." sur ".$attributeLabel."(".$value.")", LOG_DEBUG);
$this->array_options["options_".$key] = $value;
} else {
Expand Down Expand Up @@ -6668,7 +6645,7 @@ public function showInputField($val, $key, $value, $moreparam = '', $keysuffix =

// Add validation state class
if (!empty($validationClass)) {
$morecss.= $validationClass;
$morecss.= ' '.$validationClass;
}

if (in_array($type, array('date'))) {
Expand Down Expand Up @@ -7087,8 +7064,6 @@ public function showInputField($val, $key, $value, $moreparam = '', $keysuffix =
$paramforthenewlink = '';
$paramforthenewlink .= (GETPOSTISSET('action') ? '&action='.GETPOST('action', 'aZ09') : '');
$paramforthenewlink .= (GETPOSTISSET('id') ? '&id='.GETPOST('id', 'int') : '');
$paramforthenewlink .= (GETPOSTISSET('origin') ? '&origin='.GETPOST('origin', 'aZ09') : '');
$paramforthenewlink .= (GETPOSTISSET('originid') ? '&originid='.GETPOST('originid', 'int') : '');
$paramforthenewlink .= '&fk_'.strtolower($class).'=--IDFORBACKTOPAGE--';
// TODO Add Javascript code to add input fields already filled into $paramforthenewlink so we won't loose them when going back to main page
$out .= '<a class="butActionNew" title="'.$langs->trans("New").'" href="'.$url_path.'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF'].($paramforthenewlink ? '?'.$paramforthenewlink : '')).'"><span class="fa fa-plus-circle valignmiddle"></span></a>';
Expand Down Expand Up @@ -7173,7 +7148,7 @@ public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix
$objectid = $this->id; // Not used ???
$label = empty($val['label']) ? '' : $val['label'];
$type = empty($val['type']) ? '' : $val['type'];
$type = empty($val['type']) ? '' : $val['ty²pe'];
$size = empty($val['css']) ? '' : $val['css'];
$reg = array();

Expand Down Expand Up @@ -7228,7 +7203,7 @@ public function showOutputField($val, $key, $value, $moreparam = '', $keysuffix
if ($computed) {
// Make the eval of compute string
//var_dump($computed);
$value = dol_eval($computed, 1, 0, '');
$value = dol_eval($computed, 1, 0);
}

if (empty($morecss)) {
Expand Down Expand Up @@ -7739,7 +7714,7 @@ public function showOptionals($extrafields, $mode = 'view', $params = null, $key
if (empty($reshook)) {
if (key_exists('label', $extrafields->attributes[$this->table_element]) && is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) {
$out .= "\n";
$out .= '<!-- commonobject:showOptionals --> ';
$out .= '<!-- showOptionals --> ';
$out .= "\n";

$extrafields_collapse_num = '';
Expand All @@ -7753,20 +7728,20 @@ public function showOptionals($extrafields, $mode = 'view', $params = null, $key
// Test on 'enabled' ('enabled' is different than 'list' = 'visibility')
$enabled = 1;
if ($enabled && isset($extrafields->attributes[$this->table_element]['enabled'][$key])) {
$enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1, 1, '1');
$enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1);
}
if (empty($enabled)) {
continue;
}

$visibility = 1;
if ($visibility && isset($extrafields->attributes[$this->table_element]['list'][$key])) {
$visibility = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1, 1, '1');
$visibility = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1);
}

$perms = 1;
if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) {
$perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1, 1, '1');
$perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1);
}

if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) {
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -8355,7 +8355,7 @@ function verifCond($strToEvaluate)
//$str = 'if(!('.$strToEvaluate.')) $rights = false;';
//dol_eval($str, 0, 1, '2'); // The dol_eval must contains all the global $xxx used into a condition
//var_dump($strToEvaluate);
$rep = dol_eval($strToEvaluate, 1, 1, '1'); // The dol_eval must contains all the global $xxx for all variables $xxx found into the string condition
$rep = dol_eval($strToEvaluate, 1, 1, '0'); // The dol_eval must contains all the global $xxx for all variables $xxx found into the string condition
$rights = (($rep && strpos($rep, 'Bad string syntax to evaluate') === false) ? true : false);
//var_dump($rights);
}
Expand Down
14 changes: 14 additions & 0 deletions htdocs/core/lib/ip.lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

function ipInRange($ip, $range) {
if (strpos($range, '/') == false) {
$range .= '/32';
}
// $range is in IP/CIDR format eg
list($range, $netmask) = explode('/', $range, 2);
$range_decimal = ip2long($range);
$ip_decimal = ip2long($ip);
$wildcard_decimal = pow(2, (32 - $netmask)) - 1;
$netmask_decimal = ~ $wildcard_decimal;
return (($ip_decimal & $netmask_decimal) == ($range_decimal & $netmask_decimal));
}
2 changes: 2 additions & 0 deletions htdocs/core/lib/pdf.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ function pdf_build_address($outputlangs, $sourcecompany, $targetcompany = '', $t
$withCountry = 1;
}



$stringaddress .= ($stringaddress ? "\n" : '').$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n";

if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS)) {
Expand Down
Loading

0 comments on commit 0d23eae

Please sign in to comment.