diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index cd78a874ec4..c32881491c8 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -97,6 +97,23 @@ class Documents extends DolibarrApi throw new RestException(403); } + if (DolibarrApiAccess::$user->socid > 0) { + if ($sqlprotectagainstexternals) { + $resql = $this->db->query($sqlprotectagainstexternals); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + if (DolibarrApiAccess::$user->socid != $obj->fk_soc) { + throw new RestException(403, 'Not allowed to download documents with such a ref'); + } + $i++; + } + } + } + } + $filename = basename($original_file); $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset @@ -174,6 +191,23 @@ class Documents extends DolibarrApi throw new RestException(403); } + if (DolibarrApiAccess::$user->socid > 0) { + if ($sqlprotectagainstexternals) { + $resql = $this->db->query($sqlprotectagainstexternals); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + if (DolibarrApiAccess::$user->socid != $obj->fk_soc) { + throw new RestException(403, 'Not allowed to download documents with such a ref'); + } + $i++; + } + } + } + } + // --- Generates the document $hidedetails = !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 0 : 1; $hidedesc = !getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 0 : 1; @@ -1010,6 +1044,23 @@ class Documents extends DolibarrApi throw new RestException(403); } + if (DolibarrApiAccess::$user->socid > 0) { + if ($sqlprotectagainstexternals) { + $resql = $this->db->query($sqlprotectagainstexternals); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + if (DolibarrApiAccess::$user->socid != $obj->fk_soc) { + throw new RestException(403, 'Not allowed to download documents with such a ref'); + } + $i++; + } + } + } + } + $filename = basename($original_file); $original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 9d94c28aac1..5207099ea9e 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -111,7 +111,6 @@ if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_e $value = ($type == 'ckeditor' ? GETPOST('value', '', 2) : GETPOST('value', 'alpha', 2)); $loadmethod = GETPOST('loadmethod', 'alpha', 2); $savemethod = GETPOST('savemethod', 'alpha', 2); - $savemethodname = (!empty($savemethod) ? $savemethod : 'setValueFrom'); $newelement = $element; $subelement = null; @@ -236,11 +235,7 @@ if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_e } } - if (!$error) { - if ((isset($object) && !is_object($object)) || empty($savemethod)) { - $object = new GenericObject($db); - } - + if (!$error && isset($object) && is_object($object)) { // Specific for add_object_linked() // TODO add a function for variable treatment $object->ext_fk_element = $newvalue; @@ -248,7 +243,7 @@ if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_e $object->fk_element = $fk_element; $object->element = $element; - $ret = $object->$savemethodname($field, $newvalue, $table_element, $fk_element, $format); + $ret = $object->setValueFrom($field, $newvalue, $object->table_element, $fk_element, $format); if ($ret > 0) { if ($type == 'numeric') { $value = price($newvalue); diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index fd87c07cc12..0a7022c6ae5 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -1738,8 +1738,11 @@ abstract class CommonDocGenerator } $disableOnEmpty = 0; - if ($enabled && !empty($extrafields->attributes[$object->table_element]['printable'][$key])) { - $printable = intval($extrafields->attributes[$object->table_element]['printable'][$key]); + $printable = 0; + if (isset($extrafields->attributes[$object->table_element]['printable'][$key])) { + $printable = (int) $extrafields->attributes[$object->table_element]['printable'][$key]; + } + if ($enabled && !empty($printable)) { if (in_array($printable, $params['printableEnable']) || in_array($printable, $params['printableEnableNotEmpty'])) { $enabled = 1; } @@ -1749,7 +1752,7 @@ abstract class CommonDocGenerator } } - if (empty($enabled)) { + if (empty($enabled) || empty($printable)) { continue; } diff --git a/htdocs/document.php b/htdocs/document.php index a758ab79b8e..aa6251cab17 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -242,7 +242,7 @@ if (empty($modulepart)) { } // Check security and set return info with full path of file -$check_access = dol_check_secure_access_document($modulepart, $original_file, $entity, $user, ''); +$check_access = dol_check_secure_access_document($modulepart, $original_file, (int) $entity, $user, '', 'read'); $accessallowed = $check_access['accessallowed']; $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals']; $fullpath_original_file = $check_access['original_file']; // $fullpath_original_file is now a full path name diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 030582bda91..aa61182fa25 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -359,6 +359,13 @@ if (!empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6) ! // Include the conf.php and functions.lib.php and security.lib.php. This defined the constants like DOL_DOCUMENT_ROOT, DOL_DATA_ROOT, DOL_URL_ROOT... require_once 'filefunc.inc.php'; +/** + * @var ?string $php_session_save_handler + * @var ?string $dolibarr_main_force_https + * @var ?string $dolibarr_main_restrict_ip + * @var ?string $dolibarr_nocsrfcheck + * @var ?string $dolibarr_main_demo + */ /** * @var Conf $conf @@ -725,31 +732,33 @@ if ((!defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && getDolGlobalInt( // Note: There is another CSRF protection into the filefunc.inc.php } -// Disable modules (this must be after session_start and after conf has been loaded) -if (GETPOSTISSET('disablemodules')) { - $_SESSION["disablemodules"] = GETPOST('disablemodules', 'alpha'); -} -if (!empty($_SESSION["disablemodules"])) { - $modulepartkeys = array('css', 'js', 'tabs', 'triggers', 'login', 'substitutions', 'menus', 'theme', 'sms', 'tpl', 'barcode', 'models', 'societe', 'hooks', 'dir', 'syslog', 'tpllinkable', 'contactelement', 'moduleforexternal', 'websitetemplates'); +if (!empty($dolibarr_main_demo)) { + // Disable modules (this must be after session_start and after conf has been loaded) + if (GETPOSTISSET('disablemodules')) { + $_SESSION["disablemodules"] = GETPOST('disablemodules', 'alpha'); + } + if (!empty($_SESSION["disablemodules"])) { + $modulepartkeys = array('css', 'js', 'tabs', 'triggers', 'login', 'substitutions', 'menus', 'theme', 'sms', 'tpl', 'barcode', 'models', 'societe', 'hooks', 'dir', 'syslog', 'tpllinkable', 'contactelement', 'moduleforexternal', 'websitetemplates'); - $disabled_modules = explode(',', $_SESSION["disablemodules"]); - foreach ($disabled_modules as $module) { - if ($module) { - if (empty($conf->$module)) { - $conf->$module = new stdClass(); // To avoid warnings - } + $disabled_modules = explode(',', $_SESSION["disablemodules"]); + foreach ($disabled_modules as $module) { + if ($module) { + if (empty($conf->$module)) { + $conf->$module = new stdClass(); // To avoid warnings + } - $conf->$module->enabled = false; // Old usage - unset($conf->modules[$module]); + $conf->$module->enabled = false; // Old usage + unset($conf->modules[$module]); - foreach ($modulepartkeys as $modulepartkey) { - unset($conf->modules_parts[$modulepartkey][$module]); - } - if ($module == 'fournisseur') { // Special case - $conf->supplier_order->enabled = 0; // Old usage - $conf->supplier_invoice->enabled = 0; // Old usage - unset($conf->modules['supplier_order']); - unset($conf->modules['supplier_invoice']); + foreach ($modulepartkeys as $modulepartkey) { + unset($conf->modules_parts[$modulepartkey][$module]); + } + if ($module == 'fournisseur') { // Special case + $conf->supplier_order->enabled = 0; // Old usage + $conf->supplier_invoice->enabled = 0; // Old usage + unset($conf->modules['supplier_order']); + unset($conf->modules['supplier_invoice']); + } } } } diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index a8203654913..deea4e588f8 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -720,6 +720,11 @@ if ($action == 'create' || $action == 'presend') { print load_fiche_titre($langs->trans('NewTicket'), '', 'ticket'); $formticket->trackid = ''; // TODO Use a unique key 'tic' to avoid conflict in upload file feature + + if (GETPOST("mode", "aZ09") == 'init' && empty($_POST)) { + $formticket->clear_attached_files(); + } + $formticket->withfromsocid = $socid ? $socid : $user->socid; $formticket->withfromcontactid = $contactid ? $contactid : ''; $formticket->withtitletopic = 1; diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php index 8b25544f0e0..c9cd63ad078 100644 --- a/htdocs/ticket/list.php +++ b/htdocs/ticket/list.php @@ -778,7 +778,7 @@ if ($projectid) { print ''; } -$url = DOL_URL_ROOT.'/ticket/card.php?action=create'.($socid ? '&socid='.$socid : '').($projectid ? '&origin=projet_project&originid='.$projectid : ''); +$url = DOL_URL_ROOT.'/ticket/card.php?action=create&mode=init'.($socid ? '&socid='.$socid : '').($projectid ? '&origin=projet_project&originid='.$projectid : ''); if (!empty($socid)) { $url .= '&socid='.$socid; }