diff --git a/SECURITY.md b/SECURITY.md index f004cea7c86..a10c1eb15b7 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -48,12 +48,16 @@ Reports are processed around once a month. ONLY vulnerabilities discovered, when the following setup on test platform is used, are "valid": -* The version to analyze must be the last version available in the "develop" branch or in the last stable "vX.Y" released version. Reports on vulnerabilities already fixed (so already reported) in the develop branch will not be validated. +* The version to analyze must be the last version available in the "develop" branch. Reports on vulnerabilities already fixed (so already reported) in the develop branch will not be validated. * $dolibarr_main_prod must be set to 1 in conf.php * $dolibarr_nocsrfcheck must be kept to the value 0 in conf.php (this is the default value) * $dolibarr_main_force_https must be set to something else than 0. -* The constant MAIN_SECURITY_CSRF_WITH_TOKEN must be set to 3 in the backoffice menu Home - Setup - Other (this protection should be set to 3 soon by default). CSRF attacks are accepted but - double check that you have set MAIN_SECURITY_CSRF_WITH_TOKEN to value 3. +* Some constant must be set in the backoffice menu Home - Setup - Other + - MAIN_SECURITY_CSRF_WITH_TOKEN must be set to 3 + - MAIN_RESTRICTHTML_ONLY_VALID_HTML = 1 + - MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY = 1 + - MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES = 1 + CSRF attacks and HTML injections are accepted but double check this setup that is experimental setup that already fix a lot of case and soon enabled by default. * ONLY security reports on modules provided by default and with the "stable" status are valid (troubles in "experimental", "development" or external modules are not valid vulnerabilities). * The root of web server must link to htdocs and the documents directory must be outside of the web server root (this is the default when using the default installer but may differs with external installer). * The web server setup must be done so that only the documents directory is in write mode. The root directory called htdocs must be read-only. @@ -87,12 +91,10 @@ Scope is the web application (backoffice) and the APIs. * Logout and other instances of low-severity Cross-Site Request Forgery * Reports from automated web vulnerability scanners (Acunetix, Vega, etc.) that have not been validated * Reports on features on modules flagged as "deprecated", "experimental" or "development" if the module needs to be enabled for that (this is not the case on production). -* Software or libraries versions or private IP disclosure when logged-in user is admin -* Stack traces or path disclosure when logged-in user is admin +* Software or libraries versions, private IP disclosure, Stack traces or path disclosure when logged-in user is admin. * Any vulnerabilities due to a configuration different than the one defined in chapter "Scope for qualified vulnerabilities". * Vulnerabilities affecting outdated browsers or platforms, or vulnerabilities inside browsers themself. * Brute force attacks on login page, password forgotten page or any public pages (/public/*) are not qualified if the recommended fail2ban rules were not installed. * SSL/TLS best practices -* Denial of Service attacks * Invalid or missing SPF (Sender Policy Framework) records (Incomplete or missing SPF/DKIM/DMARC) * Physical or social engineering attempts or issues that require physical access to a victim’s computer/device diff --git a/dev/tools/codespell/addCodespellIgnores.sh b/dev/tools/codespell/addCodespellIgnores.sh index 476c5ba287e..0b73c4c16b2 100755 --- a/dev/tools/codespell/addCodespellIgnores.sh +++ b/dev/tools/codespell/addCodespellIgnores.sh @@ -11,10 +11,22 @@ # ```shell # echo > dev/tools/codespell/codespell-lines-ignore.txt # ``` -# and then execute this script +# and then execute this script. # # author: https://github.com/mdeweerd +# +# :warning: +# +# This script only works properly if codespell is install for your CLI. +# As the configuration is in pyproject.toml, you also need tomli. +# +# ```shell +# python -m pip install codespell tomli +# # or +# pip install codespell tomli +# ``` + codespell_ignore_file=dev/tools/codespell/codespell-lines-ignore.txt if [ -z "${0##*.sh}" ] ; then # Suppose running from inside script diff --git a/htdocs/accountancy/admin/fiscalyear_card.php b/htdocs/accountancy/admin/fiscalyear_card.php index ee587a31f96..477fac08eee 100644 --- a/htdocs/accountancy/admin/fiscalyear_card.php +++ b/htdocs/accountancy/admin/fiscalyear_card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2024 Frédéric France * * 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 @@ -109,7 +109,7 @@ if ($action == 'confirm_delete' && $confirm == "yes") { $object->date_start = $date_start; $object->date_end = $date_end; $object->label = GETPOST('label', 'alpha'); - $object->status = GETPOST('status', 'int'); + $object->status = GETPOSTINT('status'); $object->datec = dol_now(); if (empty($object->date_start) && empty($object->date_end)) { @@ -152,7 +152,7 @@ if ($action == 'confirm_delete' && $confirm == "yes") { $object->date_start = GETPOST("fiscalyear") ? $date_start : ''; $object->date_end = GETPOST("fiscalyearend") ? $date_end : ''; $object->label = GETPOST('label', 'alpha'); - $object->status = GETPOST('status', 'int'); + $object->status = GETPOSTINT('status'); $result = $object->update($user); diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 7d42cb64a00..0e4abdaebd4 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -663,7 +663,7 @@ if ($action == 'create') { if (!empty($object->linesmvt[0])) { $tmpline = $object->linesmvt[0]; if (!empty($tmpline->numero_compte)) { - $line = new BookKeepingLine(); + $line = new BookKeepingLine($db); $object->linesmvt[] = $line; } } diff --git a/htdocs/accountancy/bookkeeping/export.php b/htdocs/accountancy/bookkeeping/export.php index 498a8ee2ed3..f92c3aee5f0 100644 --- a/htdocs/accountancy/bookkeeping/export.php +++ b/htdocs/accountancy/bookkeeping/export.php @@ -1087,7 +1087,7 @@ if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print "\n"; -$line = new BookKeepingLine(); +$line = new BookKeepingLine($db); // Loop on record // -------------------------------------------------------------------- diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index ed00a185230..be1c5a34fcd 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -1037,7 +1037,7 @@ if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) { print "\n"; -$line = new BookKeepingLine(); +$line = new BookKeepingLine($db); // Loop on record // -------------------------------------------------------------------- diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index a479ce52bc2..554f4390510 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -26,6 +26,7 @@ // Class require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/fiscalyear.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; @@ -986,7 +987,7 @@ class BookKeeping extends CommonObject $i = 0; while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) { - $line = new BookKeepingLine(); + $line = new BookKeepingLine($this->db); $line->id = $obj->rowid; @@ -1140,7 +1141,7 @@ class BookKeeping extends CommonObject $i = 0; while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) { - $line = new BookKeepingLine(); + $line = new BookKeepingLine($this->db); $line->id = $obj->rowid; @@ -1275,7 +1276,7 @@ class BookKeeping extends CommonObject $i = 0; while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) { - $line = new BookKeepingLine(); + $line = new BookKeepingLine($this->db); $line->numero_compte = $obj->numero_compte; //$line->label_compte = $obj->label_compte; @@ -1881,7 +1882,7 @@ class BookKeeping extends CommonObject $result = $this->db->query($sql); if ($result) { while ($obj = $this->db->fetch_object($result)) { - $line = new BookKeepingLine(); + $line = new BookKeepingLine($this->db); $line->id = $obj->rowid; @@ -1951,7 +1952,7 @@ class BookKeeping extends CommonObject $num = $this->db->num_rows($resql); while ($obj = $this->db->fetch_object($resql)) { - $line = new BookKeepingLine(); + $line = new BookKeepingLine($this->db); $line->id = $obj->rowid; @@ -2976,7 +2977,7 @@ class BookKeeping extends CommonObject /** * Class BookKeepingLine */ -class BookKeepingLine +class BookKeepingLine extends CommonObjectLine { /** * @var int ID diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 224c25c23b6..2b9d86c3bbd 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -323,7 +323,7 @@ if (empty($reshook)) { } $object->birth = $birthdate; $object->default_lang = GETPOST('default_lang', 'alpha'); - $object->typeid = GETPOST("typeid", 'int'); + $object->typeid = GETPOSTINT("typeid"); //$object->note = trim(GETPOST("comment", "restricthtml")); $object->morphy = GETPOST("morphy", 'alpha'); @@ -1118,7 +1118,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // Birth Date print "".$langs->trans("DateOfBirth")."\n"; - print $form->selectDate(($object->birth ? $object->birth : -1), 'birth', '', '', 1, 'formsoc'); + print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', '', '', 1, 'formsoc'); print "\n"; // Public profil @@ -1364,13 +1364,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // Birth Date print "".$langs->trans("DateOfBirth")."\n"; - print $form->selectDate(($object->birth ? $object->birth : -1), 'birth', '', '', 1, 'formsoc'); + print img_picto('', 'object_calendar', 'class="pictofixedwidth"').$form->selectDate(($object->birth ? $object->birth : -1), 'birth', '', '', 1, 'formsoc'); print "\n"; // Default language if (getDolGlobalInt('MAIN_MULTILANGS')) { print ''.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).''."\n"; - print img_picto('', 'language').$formadmin->select_language($object->default_lang, 'default_lang', 0, 0, 1); + print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, 0, 1); print ''; print ''; } diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 2155f8e0872..2b5dd23b7d8 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -80,6 +80,10 @@ $socid = GETPOST('socid', 'int'); $search_filter = GETPOST("search_filter", 'alpha'); $search_status = GETPOST("search_status", 'intcomma'); // statut +$search_datec_start = dol_mktime(0, 0, 0, GETPOST('search_datec_start_month', 'int'), GETPOST('search_datec_start_day', 'int'), GETPOST('search_datec_start_year', 'int')); +$search_datec_end = dol_mktime(23, 59, 59, GETPOST('search_datec_end_month', 'int'), GETPOST('search_datec_end_day', 'int'), GETPOST('search_datec_end_year', 'int')); +$search_datem_start = dol_mktime(0, 0, 0, GETPOST('search_datem_start_month', 'int'), GETPOST('search_datem_start_day', 'int'), GETPOST('search_datem_start_year', 'int')); +$search_datem_end = dol_mktime(23, 59, 59, GETPOST('search_datem_end_month', 'int'), GETPOST('search_datem_end_day', 'int'), GETPOST('search_datem_end_year', 'int')); $filter = GETPOST("filter", 'alpha'); if ($filter) { @@ -258,6 +262,10 @@ if (empty($reshook)) { $catid = ""; $search_all = ""; $toselect = array(); + $search_datec_start = ''; + $search_datec_end = ''; + $search_datem_start = ''; + $search_datem_end = ''; $search_array_options = array(); } @@ -513,6 +521,18 @@ if ($search_country) { if ($search_import_key) { $sql .= natural_search("d.import_key", $search_import_key); } +if ($search_datec_start) { + $sql .= " AND d.datec >= '".$db->idate($search_datec_start)."'"; +} +if ($search_datec_end) { + $sql .= " AND d.datec <= '".$db->idate($search_datec_end)."'"; +} +if ($search_datem_start) { + $sql .= " AND d.tms >= '".$db->idate($search_datem_start)."'"; +} +if ($search_datem_end) { + $sql .= " AND d.tms <= '".$db->idate($search_datem_end)."'"; +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -659,6 +679,12 @@ if ($search_import_key != '') { if ($search_type > 0) { $param .= "&search_type=".urlencode($search_type); } +if ($search_datec_start) { + $param .= '&search_datec_start_day='.dol_print_date($search_datec_start, '%d').'&search_datec_start_month='.dol_print_date($search_datec_start, '%m').'&search_datec_start_year='.dol_print_date($search_datec_start, '%Y'); +} +if ($search_datem_end) { + $param .= '&search_datem_end_day='.dol_print_date($search_datem_end, '%d').'&search_datem_end_month='.dol_print_date($search_datem_end, '%m').'&search_datem_end_year='.dol_print_date($search_datem_end, '%Y'); +} // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -914,6 +940,12 @@ print $hookmanager->resPrint; // Date creation if (!empty($arrayfields['d.datec']['checked'])) { print ''; + print '
'; + print $form->selectDate($search_datec_start ? $search_datec_start : -1, 'search_datec_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); + print '
'; + print '
'; + print $form->selectDate($search_datec_end ? $search_datec_end : -1, 'search_datec_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); + print '
'; print ''; } @@ -926,6 +958,12 @@ if (!empty($arrayfields['d.birth']['checked'])) { // Date modification if (!empty($arrayfields['d.tms']['checked'])) { print ''; + print '
'; + print $form->selectDate($search_datem_start ? $search_datem_start : -1, 'search_datem_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); + print '
'; + print '
'; + print $form->selectDate($search_datem_end ? $search_datem_end : -1, 'search_datem_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); + print '
'; print ''; } diff --git a/htdocs/ai/README.md b/htdocs/ai/README.md new file mode 100644 index 00000000000..e0f33ef5f69 --- /dev/null +++ b/htdocs/ai/README.md @@ -0,0 +1,14 @@ +# AI FOR [DOLIBARR ERP CRM](https://www.dolibarr.org) + +## Features + +Provides an api key for chatchpt for use it in other modules + + +### Main code + +GPLv3 or (at your option) any later version. See file COPYING for more information. + +### Documentation + +All texts and readmes are licensed under GFDL. diff --git a/htdocs/ai/admin/setup.php b/htdocs/ai/admin/setup.php new file mode 100644 index 00000000000..6a6e15db8ed --- /dev/null +++ b/htdocs/ai/admin/setup.php @@ -0,0 +1,239 @@ + + * Copyright (C) 2022 Alice Adminson + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file ai/admin/setup.php + * \ingroup ai + * \brief Ai setup page. + */ + +// Load Dolibarr environment +require '../../main.inc.php'; + +global $langs, $user; + +// Libraries +require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; +require_once '../lib/ai.lib.php'; + +// Access control +if (!$user->admin) { + accessforbidden(); +} + +// Parameters +$action = GETPOST('action', 'aZ09'); +$backtopage = GETPOST('backtopage', 'alpha'); +$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php + +$value = GETPOST('value', 'alpha'); +$label = GETPOST('label', 'alpha'); +$scandir = GETPOST('scan_dir', 'alpha'); +$type = 'myobject'; + + +$error = 0; +$setupnotempty = 0; + +// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only +$useFormSetup = 1; + +if (!class_exists('FormSetup')) { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; +} + +$formSetup = new FormSetup($db); + +// Setup conf AI_PUBLIC_INTERFACE_TOPIC +$item = $formSetup->newItem('AI_KEY_API_CHATGPT'); +$item->defaultFieldValue = ''; + + +// Save API Key +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $apiKey = GETPOST('api_key', 'alpha'); + // Validate and clean $apiKey here + dolibarr_set_const($db, 'MAIN_AI_CHATGPT_API_KEY', $apiKey, 'chaine', 0, '', $conf->entity); +} + +// Retrieve existing API Key +$apiKey = dolibarr_get_const($db, 'MAIN_AI_CHATGPT_API_KEY'); + +$setupnotempty =+ count($formSetup->items); + + +$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + + +/* + * Actions + */ + +// For retrocompatibility Dolibarr < 15.0 +if (versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) { + $formSetup->saveConfFromPost(); +} + +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + +if ($action == 'updateMask') { + $maskconst = GETPOST('maskconst', 'aZ09'); + $maskvalue = GETPOST('maskvalue', 'alpha'); + + if ($maskconst && preg_match('/_MASK$/', $maskconst)) { + $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity); + if (!($res > 0)) { + $error++; + } + } + + if (!$error) { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } else { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} elseif ($action == 'specimen') { + $modele = GETPOST('module', 'alpha'); + $tmpobjectkey = GETPOST('object'); + + $tmpobject = new $tmpobjectkey($db); + $tmpobject->initAsSpecimen(); + + // Search template files + $file = ''; + $classname = ''; + $filefound = 0; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) { + $file = dol_buildpath($reldir."core/modules/ai/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); + if (file_exists($file)) { + $filefound = 1; + $classname = "pdf_".$modele."_".strtolower($tmpobjectkey); + break; + } + } + + if ($filefound) { + require_once $file; + + $module = new $classname($db); + + if ($module->write_file($tmpobject, $langs) > 0) { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bookcal-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); + return; + } else { + setEventMessages($module->error, null, 'errors'); + dol_syslog($module->error, LOG_ERR); + } + } else { + setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); + } +} elseif ($action == 'setmod') { + // TODO Check if numbering module chosen can be activated by calling method canBeActivated + $tmpobjectkey = GETPOST('object'); + if (!empty($tmpobjectkey)) { + $constforval = 'Ai_'.strtoupper($tmpobjectkey)."_ADDON"; + dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity); + } +} elseif ($action == 'set') { + // Activate a model + $ret = addDocumentModel($value, $type, $label, $scandir); +} elseif ($action == 'del') { + $ret = delDocumentModel($value, $type); + if ($ret > 0) { + $tmpobjectkey = GETPOST('object'); + if (!empty($tmpobjectkey)) { + $constforval = 'Ai_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + if (getDolGlobalString($constforval) == "$value") { + dolibarr_del_const($db, $constforval, $conf->entity); + } + } + } +} elseif ($action == 'setdoc') { + // Set or unset default model + $tmpobjectkey = GETPOST('object'); + if (!empty($tmpobjectkey)) { + $constforval = 'Ai_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) { + // The constant that was read before the new set + // We therefore requires a variable to have a coherent view + $conf->global->$constforval = $value; + } + + // We disable/enable the document template (into llx_document_model table) + $ret = delDocumentModel($value, $type); + if ($ret > 0) { + $ret = addDocumentModel($value, $type, $label, $scandir); + } + } +} elseif ($action == 'unsetdoc') { + $tmpobjectkey = GETPOST('object'); + if (!empty($tmpobjectkey)) { + $constforval = 'Ai_'.strtoupper($tmpobjectkey).'_ADDON_PDF'; + dolibarr_del_const($db, $constforval, $conf->entity); + } +} + + +/* + * View + */ + + $form = new Form($db); + + $help_url = ''; + $page_name = "AiSetup"; + + llxHeader('', $langs->trans($page_name), $help_url); + + // Subheader + $linkback = ''.$langs->trans("BackToModuleList").''; + + print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup'); + + // Configuration header + $head = aiAdminPrepareHead(); + print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "fa-microchip"); + + // Setup page goes here + //echo ''.$langs->trans("AiSetupPage").'

'; + + +if ($action == 'edit') { + print $formSetup->generateOutput(true); + print '
'; +} elseif (!empty($formSetup->items)) { + print $formSetup->generateOutput(); + print '
'; + print ''.$langs->trans("Modify").''; + print '
'; +} else { + print '
'.$langs->trans("NothingToSetup"); +} + + +if (empty($setupnotempty)) { + print '
'.$langs->trans("NothingToSetup"); +} + + // Page end + print dol_get_fiche_end(); + + llxFooter(); + $db->close(); diff --git a/htdocs/ai/class/ai.class.php b/htdocs/ai/class/ai.class.php new file mode 100644 index 00000000000..8349d6f3aa5 --- /dev/null +++ b/htdocs/ai/class/ai.class.php @@ -0,0 +1,90 @@ + + * Copyright (C) 2005-2016 Regis Houssin + * Copyright (C) 2012 J. Fernando Lagrange + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2023 Eric Seigne + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see https://www.gnu.org/ + */ + +/** + * Class for AI + */ +class Ai +{ + + /** + * @var DoliDB $db Database object + */ + protected $db; + /** + * @var string $apiEndpoint + */ + private $apiEndpoint; + + /** + * @var string $apiKey + */ + private $apiKey; + + /** + * Constructor + * + * @param string $apiEndpoint Endpoint of api + * @param boolean $apiKey key of api + */ + public function __construct($apiEndpoint, $apiKey) + { + $this->apiEndpoint = $apiEndpoint; + $this->apiKey = $apiKey; + } + + /** + * Generate response of instructions + * @param string $instructions instruction for generate content + * @return mixed $response + */ + public function generateContent($instructions) + { + try { + $ch = curl_init($this->apiEndpoint); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['prompt' => $instructions])); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Authorization: Bearer ' . $this->apiKey, + 'Content-Type: application/json' + ]); + + $response = curl_exec($ch); + + if (curl_errno($ch)) { + throw new Exception('cURL error: ' . curl_error($ch)); + } + + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ($statusCode != 200) { + throw new Exception('API request failed with status code ' . $statusCode); + } + + return $response; + } catch (Exception $e) { + error_log($e->getMessage()); + return null; + } finally { + curl_close($ch); + } + } +} diff --git a/htdocs/ai/lib/ai.lib.php b/htdocs/ai/lib/ai.lib.php new file mode 100644 index 00000000000..ad597757308 --- /dev/null +++ b/htdocs/ai/lib/ai.lib.php @@ -0,0 +1,63 @@ + + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file ai/lib/ai.lib.php + * \ingroup ai + * \brief Library files with common functions for Ai + */ + +/** + * Prepare admin pages header + * + * @return array + */ +function aiAdminPrepareHead() +{ + global $langs, $conf; + + $langs->load("agenda"); + + $h = 0; + $head = array(); + + $head[$h][0] = dol_buildpath("/ai/admin/setup.php", 1); + $head[$h][1] = $langs->trans("Settings"); + $head[$h][2] = 'settings'; + $h++; + + /* + $head[$h][0] = dol_buildpath("/ai/admin/myobject_extrafields.php", 1); + $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][2] = 'myobject_extrafields'; + $h++; + */ + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + //$this->tabs = array( + // 'entity:+tabname:Title:@ai:/ai/mypage.php?id=__ID__' + //); // to add new tab + //$this->tabs = array( + // 'entity:-tabname:Title:@ai:/ai/mypage.php?id=__ID__' + //); // to remove a tab + complete_head_from_modules($conf, $langs, null, $head, $h, 'ai@ai'); + + complete_head_from_modules($conf, $langs, null, $head, $h, 'ai@ai', 'remove'); + + return $head; +} diff --git a/htdocs/ai/lib/generate_content.lib.php b/htdocs/ai/lib/generate_content.lib.php new file mode 100644 index 00000000000..efe8a019c86 --- /dev/null +++ b/htdocs/ai/lib/generate_content.lib.php @@ -0,0 +1,70 @@ + + * Copyright (C) 2005-2016 Regis Houssin + * Copyright (C) 2012 J. Fernando Lagrange + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2023 Eric Seigne + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see https://www.gnu.org/ + */ + +/** + * \file htdocs/ai/lib/generate_content.lib.php + * \brief Library of ai script + */ + +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); // Disables token renewal +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} + +require_once '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/ai/class/ai.class.php'; + + +//get data from AJAX +$rawData = file_get_contents('php://input'); +$jsonData = json_decode($rawData, true); + +if (is_null($jsonData)) { + dol_print_error('data with format JSON valide.'); +} +$token = GETPOST('token'); +if ($token !== currentToken()) { // Remplacez 'newToken' par le nom de votre variable de session contenant le token + dol_print_error('CSRF token validation failed.'); + exit; +} +$chatGPT = new Ai('API_ENDPOINT', 'API_KEY'); + +$instructions = dol_string_nohtmltag($jsonData['instructions'], 1, 'UTF-8'); + +$generatedContent = $chatGPT->generateContent($instructions); + +if ($generatedContent) { + print $generatedContent; +} else { + dol_print_error('error!!'); +} diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index fe9e885dcc8..3bb8c08e892 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -63,7 +63,9 @@ class Setup extends DolibarrApi * * @return array [List of ordering methods] * - * @throws RestException 400 + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 401 Access denied + * @throws RestException 503 Error retrieving list of ordering methods */ public function getOrderingMethods($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -81,7 +83,7 @@ class Setup extends DolibarrApi $errormessage = ''; $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); if ($errormessage) { - throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage); + throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); } } @@ -106,7 +108,7 @@ class Setup extends DolibarrApi $list[] = $this->db->fetch_object($result); } } else { - throw new RestException(400, $this->db->lasterror()); + throw new RestException(503, $this->db->lasterror()); } return $list; @@ -125,7 +127,9 @@ class Setup extends DolibarrApi * * @url GET dictionary/ordering_origins * - * @throws RestException 400 + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 401 Access denied + * @throws RestException 503 Error retrieving list of ordering origins */ public function getOrderingOrigins($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -168,7 +172,7 @@ class Setup extends DolibarrApi $list[] = $this->db->fetch_object($result); } } else { - throw new RestException(400, $this->db->lasterror()); + throw new RestException(503, $this->db->lasterror()); } return $list; @@ -188,7 +192,9 @@ class Setup extends DolibarrApi * * @return array [List of payment types] * - * @throws RestException 400 + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 401 Access denied + * @throws RestException 503 Error retrieving list of payment types */ public function getPaymentTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -232,7 +238,7 @@ class Setup extends DolibarrApi $list[] = $this->db->fetch_object($result); } } else { - throw new RestException(400, $this->db->lasterror()); + throw new RestException(503, $this->db->lasterror()); } return $list; @@ -253,7 +259,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/regions * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error retrieving list of regions */ public function getListOfRegions($sortfield = "code_region", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $filter = '', $sqlfilters = '') { @@ -316,7 +323,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/regions/{id} * - * @throws RestException + * @throws RestException 404 Region not found + * @throws RestException 503 Error retrieving region */ public function getRegionByID($id) { @@ -331,7 +339,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/regions/byCode/{code} * - * @throws RestException + * @throws RestException 404 Region not found + * @throws RestException 503 Error when retrieving region */ public function getRegionByCode($code) { @@ -357,7 +366,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/states * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error retrieving list of states */ public function getListOfStates($sortfield = "code_departement", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $filter = '', $sqlfilters = '') { @@ -422,7 +432,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/states/{id} * - * @throws RestException + * @throws RestException 404 State not found + * @throws RestException 503 Error retrieving state */ public function getStateByID($id) { @@ -437,7 +448,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/states/byCode/{code} * - * @throws RestException + * @throws RestException 404 State not found + * @throws RestException 503 Error retrieving state */ public function getStateByCode($code) { @@ -463,7 +475,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/countries * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error retrieving list of countries */ public function getListOfCountries($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $lang = '', $sqlfilters = '') { @@ -527,7 +540,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/countries/{id} * - * @throws RestException + * @throws RestException 404 Country not found + * @throws RestException 503 Error retrieving country */ public function getCountryByID($id, $lang = '') { @@ -543,7 +557,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/countries/byCode/{code} * - * @throws RestException + * @throws RestException 404 Country not found + * @throws RestException 503 Error retrieving country */ public function getCountryByCode($code, $lang = '') { @@ -559,7 +574,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/countries/byISO/{iso} * - * @throws RestException + * @throws RestException 404 Country not found + * @throws RestException 503 Error retrieving country */ public function getCountryByISO($iso, $lang = '') { @@ -654,7 +670,9 @@ class Setup extends DolibarrApi * * @return array [List of availability] * - * @throws RestException 400 + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 401 Access denied + * @throws RestException 503 Error when retrieving list of availabilities */ public function getAvailability($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -697,7 +715,7 @@ class Setup extends DolibarrApi $list[] = $this->db->fetch_object($result); } } else { - throw new RestException(400, $this->db->lasterror()); + throw new RestException(503, $this->db->lasterror()); } return $list; @@ -766,7 +784,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/event_types * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of events types */ public function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $sqlfilters = '') { @@ -832,7 +851,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/expensereport_types * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of expense report types */ public function getListOfExpenseReportsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $sqlfilters = '') { @@ -897,7 +917,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/contact_types * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of contacts types */ public function getListOfContactTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $lang = '', $sqlfilters = '') { @@ -965,7 +986,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/civilities * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of civilities */ public function getListOfCivilities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $lang = '', $sqlfilters = '') { @@ -1029,7 +1051,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/currencies * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of currencies */ public function getListOfCurrencies($multicurrency = 0, $sortfield = "code_iso", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -1098,7 +1121,8 @@ class Setup extends DolibarrApi * * @url GET extrafields * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of extra fields */ public function getListOfExtrafields($sortfield = "t.pos", $sortorder = 'ASC', $type = '', $sqlfilters = '') { @@ -1175,7 +1199,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/towns * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of towns */ public function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $active = 1, $sqlfilters = '') { @@ -1240,7 +1265,8 @@ class Setup extends DolibarrApi * * @return array List of payment terms * - * @throws RestException 400 + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of payments terms */ public function getPaymentTerms($sortfield = "sortorder", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -1284,7 +1310,7 @@ class Setup extends DolibarrApi $list[] = $this->db->fetch_object($result); } } else { - throw new RestException(400, $this->db->lasterror()); + throw new RestException(503, $this->db->lasterror()); } return $list; @@ -1303,7 +1329,8 @@ class Setup extends DolibarrApi * * @return array List of shipping methods * - * @throws RestException 400 + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of shipping modes */ public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '') { @@ -1345,7 +1372,7 @@ class Setup extends DolibarrApi $list[] = $method; } } else { - throw new RestException(400, $this->db->lasterror()); + throw new RestException(503, $this->db->lasterror()); } return $list; @@ -1364,7 +1391,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/units * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of measuring units */ public function getListOfMeasuringUnits($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -1423,7 +1451,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/legal_form * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of legal form */ public function getListOfLegalForm($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters = '') { @@ -1484,7 +1513,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/staff * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of staff */ public function getListOfStaff($sortfield = "id", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -1542,7 +1572,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/socialnetworks * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of social networks */ public function getListOfsocialNetworks($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { @@ -1608,7 +1639,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/ticket_categories * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of tickets categories */ public function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '') { @@ -1670,7 +1702,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/ticket_severities * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of tickets severities */ public function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '') { @@ -1732,7 +1765,8 @@ class Setup extends DolibarrApi * * @url GET dictionary/ticket_types * - * @throws RestException + * @throws RestException 400 Bad value for sqlfilters + * @throws RestException 503 Error when retrieving list of tickets types */ public function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '') { @@ -1795,7 +1829,7 @@ class Setup extends DolibarrApi * * @url GET dictionary/incoterms * - * @throws RestException + * @throws RestException 503 Error when retrieving list of incoterms types */ public function getListOfIncoterms($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '') { @@ -1905,7 +1939,7 @@ class Setup extends DolibarrApi * * @url GET /establishments * - * @throws RestException + * @throws RestException 503 Error when retrieving list of establishments */ public function getEstablishments() { @@ -1943,7 +1977,8 @@ class Setup extends DolibarrApi * * @url GET establishments/{id} * - * @throws RestException + * @throws RestException 404 Establishment not found + * @throws RestException 503 Error when retrieving establishment */ public function getEtablishmentByID($id) { @@ -1969,8 +2004,8 @@ class Setup extends DolibarrApi * * @url GET conf/{constantname} * + * @throws RestException 400 Error Bad or unknown value for constantname * @throws RestException 403 Forbidden - * @throws RestException 404 Error Bad or unknown value for constantname */ public function getConf($constantname) { @@ -1982,7 +2017,7 @@ class Setup extends DolibarrApi } if (!preg_match('/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) { - throw new RestException(404, 'Error Bad or unknown value for constantname'); + throw new RestException(400, 'Error Bad or unknown value for constantname'); } if (isASecretKey($constantname)) { throw new RestException(403, 'Forbidden. This parameter can not be read with APIs'); @@ -2002,7 +2037,6 @@ class Setup extends DolibarrApi * @throws RestException 403 Forbidden * @throws RestException 404 Signature file not found * @throws RestException 500 Technical error - * @throws RestException 503 Forbidden */ public function getCheckIntegrity($target) { diff --git a/htdocs/api/index.php b/htdocs/api/index.php index a2c7328aa21..2f6bac8452d 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -411,19 +411,19 @@ Luracast\Restler\Defaults::$returnResponse = $usecompression; // Call API (we suppose we found it). // The handle will use the file api/temp/routes.php to get data to run the API. If the file exists and the entry for API is not found, it will return 404. -$result = $api->r->handle(); +$responsedata = $api->r->handle(); if (Luracast\Restler\Defaults::$returnResponse) { // We try to compress the data received data if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br') !== false && function_exists('brotli_compress') && defined('BROTLI_TEXT')) { header('Content-Encoding: br'); - $result = brotli_compress($result, 11, constant('BROTLI_TEXT')); + $result = brotli_compress($responsedata, 11, constant('BROTLI_TEXT')); } elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'bz') !== false && function_exists('bzcompress')) { header('Content-Encoding: bz'); - $result = bzcompress($result, 9); + $result = bzcompress($responsedata, 9); } elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && function_exists('gzencode')) { header('Content-Encoding: gzip'); - $result = gzencode($result, 9); + $result = gzencode($responsedata, 9); } else { header('Content-Encoding: text/html'); print "No compression method found. Try to disable compression by adding API_DISABLE_COMPRESSION=1"; @@ -434,4 +434,20 @@ if (Luracast\Restler\Defaults::$returnResponse) { echo $result; } +// Call API termination method +$apiMethodInfo = &$api->r->apiMethodInfo; +$terminateCall = '_terminate_' . $apiMethodInfo->methodName . '_' . $api->r->responseFormat->getExtension(); +if (method_exists($apiMethodInfo->className, $terminateCall)) { + // Now flush output buffers so that response data is sent to the client even if we still have action to do in a termination method. + ob_end_flush(); + + // If you're using PHP-FPM, this function will allow you to send the response and then continue processing + if (function_exists('fastcgi_finish_request')) { + fastcgi_finish_request(); + } + + // Call a termination method. Warning: This method can do I/O, sync but must not make ouput. + call_user_func(array(Luracast\Restler\Scope::get($apiMethodInfo->className), $terminateCall), $responsedata); +} + //session_destroy(); diff --git a/htdocs/bom/class/api_boms.class.php b/htdocs/bom/class/api_boms.class.php index d84b25d7225..2f68b565394 100644 --- a/htdocs/bom/class/api_boms.class.php +++ b/htdocs/bom/class/api_boms.class.php @@ -61,7 +61,9 @@ class Boms extends DolibarrApi * @return Object Object with cleaned properties * * @url GET {id} - * @throws RestException + * + * @throws RestException 401 Access denied + * @throws RestException 404 BOM not found */ public function get($id) { @@ -95,7 +97,9 @@ class Boms extends DolibarrApi * @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names * @return array Array of order objects * - * @throws RestException + * @throws RestException 400 Bad sqlfilters + * @throws RestException 401 Access denied + * @throws RestException 503 Error retrieving list of boms */ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '') { @@ -176,6 +180,9 @@ class Boms extends DolibarrApi * * @param array $request_data Request datas * @return int ID of bom + * + * @throws RestException 401 Access denied + * @throws RestException 500 Error retrieving list of boms */ public function post($request_data = null) { @@ -210,6 +217,10 @@ class Boms extends DolibarrApi * @param array $request_data Datas * * @return int + * + * @throws RestException 401 Access denied + * @throws RestException 404 BOM not found + * @throws RestException 500 Error updating bom */ public function put($id, $request_data = null) { @@ -253,6 +264,10 @@ class Boms extends DolibarrApi * * @param int $id BOM ID * @return array + * + * @throws RestException 401 Access denied + * @throws RestException 404 BOM not found + * @throws RestException 500 Error deleting bom */ public function delete($id) { @@ -288,6 +303,9 @@ class Boms extends DolibarrApi * @url GET {id}/lines * * @return array + * + * @throws RestException 401 Access denied + * @throws RestException 404 BOM not found */ public function getLines($id) { @@ -320,6 +338,10 @@ class Boms extends DolibarrApi * @url POST {id}/lines * * @return int + * + * @throws RestException 401 Access denied + * @throws RestException 404 BOM not found + * @throws RestException 500 Error adding bom line */ public function postLine($id, $request_data = null) { @@ -353,7 +375,7 @@ class Boms extends DolibarrApi if ($updateRes > 0) { return $updateRes; } else { - throw new RestException(400, $this->bom->error); + throw new RestException(500, $this->bom->error); } } @@ -367,6 +389,9 @@ class Boms extends DolibarrApi * @url PUT {id}/lines/{lineid} * * @return object|bool + * + * @throws RestException 401 Access denied + * @throws RestException 404 BOM not found */ public function putLine($id, $lineid, $request_data = null) { @@ -415,9 +440,9 @@ class Boms extends DolibarrApi * * @return int * - * @throws RestException 401 - * @throws RestException 404 - * @throws RestException 500 + * @throws RestException 401 Access denied + * @throws RestException 404 BOM not found + * @throws RestException 500 Error deleting bom line */ public function deleteLine($id, $lineid) { @@ -450,7 +475,7 @@ class Boms extends DolibarrApi if ($updateRes > 0) { return $this->get($id); } else { - throw new RestException(405, $this->bom->error); + throw new RestException(500, $this->bom->error); } } diff --git a/htdocs/bookcal/calendar_agenda.php b/htdocs/bookcal/calendar_agenda.php index a9792756553..e882d054f45 100644 --- a/htdocs/bookcal/calendar_agenda.php +++ b/htdocs/bookcal/calendar_agenda.php @@ -22,62 +22,14 @@ * \brief Tab of events on Calendar */ -//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db -//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user -//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc -//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs -//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters -//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters -//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on) -//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data -//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu -//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library -//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too. -//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip -//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value -//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler -//if (! defined("MAIN_SECURITY_FORCECSP")) define('MAIN_SECURITY_FORCECSP', 'none'); // Disable all Content Security Policies -//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET -//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification - // Load Dolibarr environment -$res = 0; -// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) -if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { - $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; -} -// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME -$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; -while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { - $i--; - $j--; -} -if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) { - $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; -} -if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) { - $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; -} -// Try main.inc.php using relative path -if (!$res && file_exists("../main.inc.php")) { - $res = @include "../main.inc.php"; -} -if (!$res && file_exists("../../main.inc.php")) { - $res = @include "../../main.inc.php"; -} -if (!$res && file_exists("../../../main.inc.php")) { - $res = @include "../../../main.inc.php"; -} -if (!$res) { - die("Include of main fails"); -} +require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -dol_include_once('/bookcal/class/calendar.class.php'); -dol_include_once('/bookcal/lib/bookcal_calendar.lib.php'); +require_once DOL_DOCUMENT_ROOT.'/bookcal/class/calendar.class.php'; +require_once DOL_DOCUMENT_ROOT.'/bookcal/lib/bookcal_calendar.lib.php'; // Load translation files required by the page $langs->loadLangs(array("bookcal@bookcal", "other")); diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 11d31aaa031..139ed636366 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -220,6 +220,11 @@ class Categorie extends CommonObject */ public $color; + /** + * @var int Position + */ + public $position; + /** * @var int Visible */ @@ -352,7 +357,7 @@ class Categorie extends CommonObject $type = $this->MAP_ID[$type]; } - $sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type, ref_ext"; + $sql = "SELECT rowid, fk_parent, entity, label, description, color, position, fk_soc, visible, type, ref_ext"; $sql .= ", date_creation, tms, fk_user_creat, fk_user_modif"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie"; if ($id) { @@ -378,6 +383,7 @@ class Categorie extends CommonObject $this->label = $res['label']; $this->description = $res['description']; $this->color = $res['color']; + $this->position = $res['position']; $this->socid = (int) $res['fk_soc']; $this->visible = (int) $res['visible']; $this->type = (int) $res['type']; @@ -440,6 +446,7 @@ class Categorie extends CommonObject $this->label = trim($this->label); $this->description = trim($this->description); $this->color = trim($this->color); + $this->position = trim($this->position); $this->import_key = trim($this->import_key); $this->ref_ext = trim($this->ref_ext); if (empty($this->visible)) { @@ -461,6 +468,7 @@ class Categorie extends CommonObject $sql .= " label,"; $sql .= " description,"; $sql .= " color,"; + $sql .= " position,"; if (getDolGlobalString('CATEGORY_ASSIGNED_TO_A_CUSTOMER')) { $sql .= "fk_soc,"; } @@ -476,6 +484,7 @@ class Categorie extends CommonObject $sql .= "'".$this->db->escape($this->label)."', "; $sql .= "'".$this->db->escape($this->description)."', "; $sql .= "'".$this->db->escape($this->color)."', "; + $sql .= (int) $this->position.","; if (getDolGlobalString('CATEGORY_ASSIGNED_TO_A_CUSTOMER')) { $sql .= ($this->socid > 0 ? $this->socid : 'null').", "; } @@ -566,6 +575,7 @@ class Categorie extends CommonObject $sql .= " description = '".$this->db->escape($this->description)."',"; $sql .= " ref_ext = '".$this->db->escape($this->ref_ext)."',"; $sql .= " color = '".$this->db->escape($this->color)."'"; + $sql .= ", position = ".(int) $this->position; if (getDolGlobalString('CATEGORY_ASSIGNED_TO_A_CUSTOMER')) { $sql .= ", fk_soc = ".($this->socid > 0 ? $this->socid : 'null'); } @@ -1028,6 +1038,7 @@ class Categorie extends CommonObject $categories[$i]['label'] = $category_static->label; $categories[$i]['description'] = $category_static->description; $categories[$i]['color'] = $category_static->color; + $categories[$i]['position'] = $category_static->position; $categories[$i]['socid'] = $category_static->socid; $categories[$i]['ref_ext'] = $category_static->ref_ext; $categories[$i]['visible'] = $category_static->visible; @@ -1163,7 +1174,7 @@ class Categorie extends CommonObject $current_lang = $langs->getDefaultLang(); // Init $this->cats array - $sql = "SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.fk_parent, c.visible"; // Distinct reduce pb with old tables with duplicates + $sql = "SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.position, c.fk_parent, c.visible"; // Distinct reduce pb with old tables with duplicates if (getDolGlobalInt('MAIN_MULTILANGS')) { $sql .= ", t.label as label_trans, t.description as description_trans"; } @@ -1185,6 +1196,7 @@ class Categorie extends CommonObject $this->cats[$obj->rowid]['label'] = !empty($obj->label_trans) ? $obj->label_trans : $obj->label; $this->cats[$obj->rowid]['description'] = !empty($obj->description_trans) ? $obj->description_trans : $obj->description; $this->cats[$obj->rowid]['color'] = $obj->color; + $this->cats[$obj->rowid]['position'] = $obj->position; $this->cats[$obj->rowid]['visible'] = $obj->visible; $this->cats[$obj->rowid]['ref_ext'] = $obj->ref_ext; $this->cats[$obj->rowid]['picto'] = 'category'; diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 43510b10241..fd82b212feb 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -45,6 +45,7 @@ $socid = (int) GETPOST('socid', 'int'); $label = (string) GETPOST('label', 'alphanohtml'); $description = (string) GETPOST('description', 'restricthtml'); $color = preg_replace('/[^0-9a-f#]/i', '', (string) GETPOST('color', 'alphanohtml')); +$position = (int) GETPOST('position', 'int'); $visible = (int) GETPOST('visible', 'int'); $parent = (int) GETPOST('parent', 'int'); @@ -80,7 +81,7 @@ $error = 0; /* * Actions */ -$parameters = array('id' => $id, 'ref' => $ref, 'cancel'=> $cancel, 'backtopage' => $backtopage, 'socid' => $socid, 'label' => $label, 'description' => $description, 'color' => $color, 'visible' => $visible, 'parent' => $parent); +$parameters = array('id' => $id, 'ref' => $ref, 'cancel'=> $cancel, 'backtopage' => $backtopage, 'socid' => $socid, 'label' => $label, 'description' => $description, 'color' => $color, 'position' => $position, 'visible' => $visible, 'parent' => $parent); // Note that $action and $object may be modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); if ($reshook < 0) { @@ -105,6 +106,7 @@ if (empty($reshook)) { $object->label = $label; $object->description = dol_htmlcleanlastbr($description); $object->color = $color; + $object->position = $position; $object->socid = ($socid > 0 ? $socid : 0); $object->visible = $visible; $object->fk_parent = $parent != -1 ? $parent : 0; @@ -186,6 +188,12 @@ print ''; print $formother->selectColor($object->color, 'color'); print ''; +// Position +print ''; +print $langs->trans("Position").''; +print ''; +print ''; + // Parent category print ''.$langs->trans("In").''; print img_picto('', 'category', 'class="pictofixedwidth"'); diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 5d1d44738fe..19459aa6806 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -301,6 +301,12 @@ print $langs->trans("Color").''; print $formother->showColor($object->color); print ''; +// Position +print ''; +print $langs->trans("Position").''; +print $object->position; +print ''; + // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index bfeebc0abbb..62b86621a6a 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -215,12 +215,12 @@ if (isModEnabled('accounting')) { $calcmode .= ''; $calcmode .= '
'; } -$calcmode .= '