From f103278bb4bd6680a2a500d32dc75d783cb27af4 Mon Sep 17 00:00:00 2001 From: William Mead Date: Mon, 4 Mar 2024 18:08:07 +0100 Subject: [PATCH 1/3] Qual phpstan cron card (#28626) * Fixed unitfrequency type. Fixed localization. * Cleaned code & comments. Added contributor details. --- htdocs/cron/card.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index 17fce5f159d..68dbac1b3e7 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -3,6 +3,7 @@ * Copyright (C) 2013 Florian Henry * Copyright (C) 2013-2016 Laurent Destailleur * Copyright (C) 2018-2023 Frédéric France + * Copyright (C) 2024 William Mead * * 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 @@ -29,7 +30,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; -// librairie jobs +// Cron job libraries require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php"; require_once DOL_DOCUMENT_ROOT."/core/class/html.formcron.class.php"; require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php'; @@ -73,11 +74,10 @@ if (!empty($cancel)) { } else { if ($backtopage) { header("Location: ".$backtopage); - exit; } else { header("Location: ".DOL_URL_ROOT.'/cron/list.php'); - exit; } + exit; } } @@ -98,7 +98,6 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontodelete) { if ($action == 'confirm_execute' && $confirm == "yes" && $permissiontoexecute) { if (getDolGlobalString('CRON_KEY') && $conf->global->CRON_KEY != $securitykey) { setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors'); - $action = ''; } else { $now = dol_now(); // Date we start @@ -106,7 +105,6 @@ if ($action == 'confirm_execute' && $confirm == "yes" && $permissiontoexecute) { if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; } else { $res = $object->reprogram_jobs($user->login, $now); if ($res > 0) { @@ -115,13 +113,12 @@ if ($action == 'confirm_execute' && $confirm == "yes" && $permissiontoexecute) { } else { setEventMessages($langs->trans("JobFinished"), null, 'mesgs'); } - $action = ''; } else { setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; } } } + $action = ''; } @@ -140,7 +137,7 @@ if ($action == 'add' && $permissiontoadd) { $object->dateend = dol_mktime(GETPOSTINT('dateendhour'), GETPOSTINT('dateendmin'), 0, GETPOSTINT('dateendmonth'), GETPOSTINT('dateendday'), GETPOSTINT('dateendyear')); $object->priority = GETPOSTINT('priority'); $object->datenextrun = dol_mktime(GETPOSTINT('datenextrunhour'), GETPOSTINT('datenextrunmin'), 0, GETPOSTINT('datenextrunmonth'), GETPOSTINT('datenextrunday'), GETPOSTINT('datenextrunyear')); - $object->unitfrequency = GETPOSTINT('unitfrequency'); + $object->unitfrequency = GETPOST('unitfrequency', 'alpha'); $object->frequency = GETPOSTINT('nbfrequency'); $object->maxrun = GETPOSTINT('maxrun'); $object->email_alert = GETPOST('email_alert'); @@ -150,7 +147,7 @@ if ($action == 'add' && $permissiontoadd) { // Add cron task $result = $object->create($user); - // test du Resultat de la requete + // Test request result if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'create'; @@ -177,7 +174,7 @@ if ($action == 'update' && $permissiontoadd) { $object->dateend = dol_mktime(GETPOSTINT('dateendhour'), GETPOSTINT('dateendmin'), 0, GETPOSTINT('dateendmonth'), GETPOSTINT('dateendday'), GETPOSTINT('dateendyear')); $object->priority = GETPOSTINT('priority'); $object->datenextrun = dol_mktime(GETPOSTINT('datenextrunhour'), GETPOSTINT('datenextrunmin'), 0, GETPOSTINT('datenextrunmonth'), GETPOSTINT('datenextrunday'), GETPOSTINT('datenextrunyear')); - $object->unitfrequency = GETPOSTINT('unitfrequency'); + $object->unitfrequency = GETPOST('unitfrequency', 'alpha'); $object->frequency = GETPOSTINT('nbfrequency'); $object->maxrun = GETPOSTINT('maxrun'); $object->email_alert = GETPOST('email_alert'); @@ -185,7 +182,7 @@ if ($action == 'update' && $permissiontoadd) { // Add cron task $result = $object->update($user); - // test du Resultat de la requete + // Test request result if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; @@ -201,7 +198,7 @@ if ($action == 'activate' && $permissiontoadd) { // Add cron task $result = $object->update($user); - // test du Resultat de la requete + // Test request result if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; @@ -218,7 +215,7 @@ if ($action == 'inactive' && $permissiontoadd) { // Add cron task $result = $object->update($user); - // test du Resultat de la requete + // Test request result if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'edit'; @@ -679,7 +676,7 @@ if (($action == "create") || ($action == "edit")) { print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Weeks'); } if ($object->unitfrequency == "2678400") { - print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Month'); + print $langs->trans('CronEach')." ".($object->frequency)." ".$langs->trans('Months'); } print ""; From cf7f40b739e8b5da4e31243456744c09d66735b8 Mon Sep 17 00:00:00 2001 From: thomas-Ngr Date: Mon, 4 Mar 2024 18:11:50 +0100 Subject: [PATCH 2/3] new fetch() for classes Fournisseur and Client (#28621) * New : introduce Fournisseur::fetch() and Client::fetch(). Add new parameters and to Societe::fetch() * societe::fetch: both is_client and is_fournisseur false by default * Simplify code --- htdocs/fourn/class/fournisseur.class.php | 23 +++++++++++++++++++++ htdocs/societe/class/client.class.php | 26 ++++++++++++++++++++++++ htdocs/societe/class/societe.class.php | 13 +++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.class.php b/htdocs/fourn/class/fournisseur.class.php index cf3263ec3df..4ee18163e16 100644 --- a/htdocs/fourn/class/fournisseur.class.php +++ b/htdocs/fourn/class/fournisseur.class.php @@ -49,6 +49,29 @@ class Fournisseur extends Societe $this->fournisseur = 1; } + /** + * Load a third party from database into memory + * + * @param int $rowid Id of third party to load + * @param string $ref Reference of third party, name (Warning, this can return several records) + * @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) + * @param string $barcode Barcode of third party to load + * @param string $idprof1 Prof id 1 of third party (Warning, this can return several records) + * @param string $idprof2 Prof id 2 of third party (Warning, this can return several records) + * @param string $idprof3 Prof id 3 of third party (Warning, this can return several records) + * @param string $idprof4 Prof id 4 of third party (Warning, this can return several records) + * @param string $idprof5 Prof id 5 of third party (Warning, this can return several records) + * @param string $idprof6 Prof id 6 of third party (Warning, this can return several records) + * @param string $email Email of third party (Warning, this can return several records) + * @param string $ref_alias Name_alias of third party (Warning, this can return several records) + * @param bool $is_client Is the thirdparty a client ? + * @param bool $is_supplier Is the thirdparty a supplier ? + * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found. + */ + public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = false, $is_supplier = true) + { + return parent::fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier); + } /** * Return nb of orders diff --git a/htdocs/societe/class/client.class.php b/htdocs/societe/class/client.class.php index 67b3bef8ee8..b1fad2a4be8 100644 --- a/htdocs/societe/class/client.class.php +++ b/htdocs/societe/class/client.class.php @@ -48,6 +48,32 @@ class Client extends Societe $this->fournisseur = 0; } + + /** + * Load a third party from database into memory + * + * @param int $rowid Id of third party to load + * @param string $ref Reference of third party, name (Warning, this can return several records) + * @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) + * @param string $barcode Barcode of third party to load + * @param string $idprof1 Prof id 1 of third party (Warning, this can return several records) + * @param string $idprof2 Prof id 2 of third party (Warning, this can return several records) + * @param string $idprof3 Prof id 3 of third party (Warning, this can return several records) + * @param string $idprof4 Prof id 4 of third party (Warning, this can return several records) + * @param string $idprof5 Prof id 5 of third party (Warning, this can return several records) + * @param string $idprof6 Prof id 6 of third party (Warning, this can return several records) + * @param string $email Email of third party (Warning, this can return several records) + * @param string $ref_alias Name_alias of third party (Warning, this can return several records) + * @param bool $is_client Is the thirdparty a client ? + * @param bool $is_supplier Is the thirdparty a supplier ? + * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found. + */ + public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = true, $is_supplier = false) + { + return parent::fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load indicators into this->nb for board * diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 73b871bc7f0..9dd643d37ed 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1797,9 +1797,11 @@ class Societe extends CommonObject * @param string $idprof6 Prof id 6 of third party (Warning, this can return several records) * @param string $email Email of third party (Warning, this can return several records) * @param string $ref_alias Name_alias of third party (Warning, this can return several records) + * @param bool $is_client Is the thirdparty a client ? + * @param bool $is_supplier Is the thirdparty a supplier ? * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found. */ - public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '') + public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = false, $is_supplier = false) { global $langs; global $conf; @@ -1869,6 +1871,15 @@ class Societe extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_remise_supplier as sr2 ON sr2.rowid = (SELECT MAX(rowid) FROM '.MAIN_DB_PREFIX.'societe_remise_supplier WHERE fk_soc = s.rowid AND entity IN ('.getEntity('discount').'))'; } $sql .= ' WHERE s.entity IN ('.getEntity($this->element).')'; + + // Filter on client or supplier, for Client::fetch() and Fournisseur::fetch() + if ($is_client) { + $sql .= ' AND s.client > 0'; + } + if ($is_supplier) { + $sql .= ' AND s.fournisseur > 0'; + } // if both false, no test (the thirdparty can be client and/or supplier) + if ($rowid) { $sql .= ' AND s.rowid = '.((int) $rowid); } From 47dfcf9bfcd5c38b7e4c9cb33c222a9e9b31df95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 4 Mar 2024 18:13:32 +0100 Subject: [PATCH 3/3] clean code (#28616) --- htdocs/bookcal/admin/calendar_extrafields.php | 33 ++--------- htdocs/bookcal/booking_list.php | 6 +- htdocs/bookcal/calendar_agenda.php | 3 +- htdocs/bookcal/calendar_card.php | 58 ++----------------- htdocs/bookcal/calendar_contact.php | 34 +---------- htdocs/bookcal/calendar_document.php | 57 ++---------------- htdocs/bookcal/calendar_list.php | 3 +- htdocs/bookcal/calendar_note.php | 57 ++---------------- 8 files changed, 29 insertions(+), 222 deletions(-) diff --git a/htdocs/bookcal/admin/calendar_extrafields.php b/htdocs/bookcal/admin/calendar_extrafields.php index 72c84e50e35..46a7a39ebb4 100644 --- a/htdocs/bookcal/admin/calendar_extrafields.php +++ b/htdocs/bookcal/admin/calendar_extrafields.php @@ -5,6 +5,7 @@ * Copyright (C) 2012 Regis Houssin * Copyright (C) 2014 Florian Henry * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 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 @@ -27,39 +28,13 @@ */ // 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) { - die("Include of main fails"); -} +require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once '../lib/bookcal.lib.php'; // Load translation files required by the page -$langs->loadLangs(array('bookcal@bookcal', 'admin')); +$langs->loadLangs(array('agenda', 'admin')); $extrafields = new ExtraFields($db); $form = new Form($db); @@ -106,7 +81,7 @@ print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup'); $head = bookcalAdminPrepareHead(); -print dol_get_fiche_head($head, 'calendar_extrafields', $langs->trans($page_name), -1, 'bookcal@bookcal'); +print dol_get_fiche_head($head, 'calendar_extrafields', $langs->trans($page_name), -1, 'agenda'); require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; diff --git a/htdocs/bookcal/booking_list.php b/htdocs/bookcal/booking_list.php index 2503e170947..b4ac4cabe1b 100644 --- a/htdocs/bookcal/booking_list.php +++ b/htdocs/bookcal/booking_list.php @@ -5,7 +5,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2017 Ferran Marcet - * Copyright (C) 2018-2023 Frédéric France + * Copyright (C) 2023-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 @@ -34,13 +34,13 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -dol_include_once('/bookcal/lib/bookcal_calendar.lib.php'); +require_once DOL_DOCUMENT_ROOT.'/bookcal/lib/bookcal_calendar.lib.php'; // load module libraries require_once __DIR__.'/class/calendar.class.php'; // Load translation files required by the page -$langs->loadLangs(array("bookcal@bookcal", "other")); +$langs->loadLangs(array("agenda", "other")); $id = (GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility $ref = GETPOST('ref', 'alpha'); diff --git a/htdocs/bookcal/calendar_agenda.php b/htdocs/bookcal/calendar_agenda.php index b3b131a8a7e..391c65e81ed 100644 --- a/htdocs/bookcal/calendar_agenda.php +++ b/htdocs/bookcal/calendar_agenda.php @@ -1,6 +1,7 @@ * Copyright (C) 2023 Alice Adminson + * Copyright (C) 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 @@ -32,7 +33,7 @@ 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")); +$langs->loadLangs(array("agenda", "other")); // Get parameters $id = GETPOSTINT('id'); diff --git a/htdocs/bookcal/calendar_card.php b/htdocs/bookcal/calendar_card.php index 6d8038b8d4a..2b86d58e41d 100644 --- a/htdocs/bookcal/calendar_card.php +++ b/htdocs/bookcal/calendar_card.php @@ -1,6 +1,7 @@ * Copyright (C) 2023 Alice Adminson + * Copyright (C) 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 @@ -22,66 +23,17 @@ * \brief Page to create/edit/view 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 -//if (! defined('NOSESSION')) define('NOSESSION', '1'); // Disable session - // 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.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.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")); +$langs->loadLangs(array("agenda", "other")); // Get parameters $id = GETPOSTINT('id'); diff --git a/htdocs/bookcal/calendar_contact.php b/htdocs/bookcal/calendar_contact.php index 71821a0a8c3..4eb679a97f3 100644 --- a/htdocs/bookcal/calendar_contact.php +++ b/htdocs/bookcal/calendar_contact.php @@ -1,6 +1,7 @@ * Copyright (C) 2023 Alice Adminson + * Copyright (C) 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 @@ -23,36 +24,7 @@ */ // 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/class/html.formcompany.class.php'; @@ -60,7 +32,7 @@ dol_include_once('/bookcal/class/calendar.class.php'); dol_include_once('/bookcal/lib/bookcal_calendar.lib.php'); // Load translation files required by the page -$langs->loadLangs(array("bookcal@bookcal", "companies", "other", "mails")); +$langs->loadLangs(array("agenda", "companies", "other", "mails")); $id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility $ref = GETPOST('ref', 'alpha'); diff --git a/htdocs/bookcal/calendar_document.php b/htdocs/bookcal/calendar_document.php index c11253b4503..32aaf416f35 100644 --- a/htdocs/bookcal/calendar_document.php +++ b/htdocs/bookcal/calendar_document.php @@ -1,6 +1,7 @@ * Copyright (C) 2023 Alice Adminson + * Copyright (C) 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 @@ -22,66 +23,18 @@ * \brief Tab for documents linked to 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.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.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", "companies", "other", "mails")); +$langs->loadLangs(array("agenda", "companies", "other", "mails")); $action = GETPOST('action', 'aZ09'); diff --git a/htdocs/bookcal/calendar_list.php b/htdocs/bookcal/calendar_list.php index fd187d7c757..a513aab7d31 100644 --- a/htdocs/bookcal/calendar_list.php +++ b/htdocs/bookcal/calendar_list.php @@ -1,6 +1,7 @@ * Copyright (C) 2023 Alice Adminson + * Copyright (C) 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 @@ -32,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once __DIR__.'/class/calendar.class.php'; // Load translation files required by the page -$langs->loadLangs(array("bookcal@bookcal", "other")); +$langs->loadLangs(array("agenda", "other")); $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ... $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) diff --git a/htdocs/bookcal/calendar_note.php b/htdocs/bookcal/calendar_note.php index 5f13b1129e6..7eb44b892e2 100644 --- a/htdocs/bookcal/calendar_note.php +++ b/htdocs/bookcal/calendar_note.php @@ -1,6 +1,7 @@ * Copyright (C) 2023 Alice Adminson + * Copyright (C) 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 @@ -22,62 +23,14 @@ * \brief Tab for notes 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'; -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", "companies")); +$langs->loadLangs(array("agenda", "companies")); // Get parameters $id = GETPOSTINT('id');