From 77c335c5f36a45fb6343c9b38d2cacb4ca3e6e23 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 23 Dec 2020 09:19:56 +0100 Subject: [PATCH 01/23] fix colspan balance accountanty --- htdocs/accountancy/bookkeeping/balance.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 29e56cd4233..94a927d676c 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -302,7 +302,7 @@ if ($action != 'export_csv') { // Display a sub-total per account if ($displayed_account != "") { - print ''.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_credit - $sous_total_debit)).''; + print ''.$langs->trans("SubTotal").':'.price($sous_total_opening_balance).''.price($sous_total_debit).''.price($sous_total_credit).''.price(price2num($sous_total_credit - $sous_total_debit)).''; print " \n"; print ''; } From 7d1d58822589fde6947531260c1e850c08c08e3f Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 23 Dec 2020 23:48:45 +0100 Subject: [PATCH 02/23] fix service right problem for mass action --- htdocs/product/list.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index d2f212df8da..50001d25026 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -240,6 +240,9 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +$rightskey = 'produit'; +if ($type == Product::TYPE_SERVICE) $rightskey = 'service'; + if (empty($reshook)) { // Selection of new fields @@ -275,8 +278,8 @@ if (empty($reshook)) if ((string) $search_type == '1') { $objectlabel = 'Services'; } if ((string) $search_type == '0') { $objectlabel = 'Products'; } - $permissiontoread = $user->rights->produit->lire; - $permissiontodelete = $user->rights->produit->supprimer; + $permissiontoread = $user->rights->{$rightskey}->lire; + $permissiontodelete = $user->rights->{$rightskey}->supprimer; $uploaddir = $conf->product->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -507,8 +510,6 @@ if ($resql) //'builddoc'=>$langs->trans("PDFMerge"), //'presend'=>$langs->trans("SendByMail"), ); - $rightskey = 'produit'; - if ($type == Product::TYPE_SERVICE) $rightskey = 'service'; if ($user->rights->{$rightskey}->supprimer) $arrayofmassactions['predelete'] = "".$langs->trans("Delete"); if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); From 60d8fb47199261c92c3ab416674bd70fdcc2157d Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 24 Dec 2020 00:48:48 +0100 Subject: [PATCH 03/23] fic porject mass action right --- htdocs/projet/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index 5c36044dcd1..9bb383e9803 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -436,7 +436,7 @@ $arrayofmassactions = array( ); //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer"); if ($user->rights->projet->creer) $arrayofmassactions['close'] = $langs->trans("Close"); -if ($user->rights->societe->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); +if ($user->rights->projet->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); From 11146a0b66a1d4986b18c0765aa8314a75ffa7c8 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 25 Dec 2020 11:01:19 +0100 Subject: [PATCH 04/23] Add contact tab in default generated php files --- htdocs/langs/en_US/modulebuilder.lang | 3 +- htdocs/modulebuilder/index.php | 11 + .../template/myobject_contact.php | 203 ++++++++++++++++++ 3 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 htdocs/modulebuilder/template/myobject_contact.php diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 6f8fdcad996..f2090de11c0 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -40,6 +40,7 @@ PageForCreateEditView=PHP page to create/edit/view a record PageForAgendaTab=PHP page for event tab PageForDocumentTab=PHP page for document tab PageForNoteTab=PHP page for note tab +PageForContactTab=PHP page for contact tab PathToModulePackage=Path to zip of module/application package PathToModuleDocumentation=Path to file of module/application documentation (%s) SpaceOrSpecialCharAreNotAllowed=Spaces or special characters are not allowed. @@ -138,4 +139,4 @@ ForeignKey=Foreign key TypeOfFieldsHelp=Type of fields:
varchar(99), double(24,8), real, text, html, datetime, timestamp, integer, integer:ClassName:relativepath/to/classfile.class.php[:1[:filter]] ('1' means we add a + button after the combo to create the record, 'filter' can be 'status=1 AND fk_user = __USER_ID AND entity IN (__SHARED_ENTITIES__)' for example) AsciiToHtmlConverter=Ascii to HTML converter AsciiToPdfConverter=Ascii to PDF converter -TableNotEmptyDropCanceled=Table not empty. Drop has been canceled. \ No newline at end of file +TableNotEmptyDropCanceled=Table not empty. Drop has been canceled. diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index fba9b0d4855..2b7453c904a 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -902,6 +902,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) $filetogenerate = array( 'myobject_card.php'=>strtolower($objectname).'_card.php', 'myobject_note.php'=>strtolower($objectname).'_note.php', + 'myobject_contact.php'=>strtolower($objectname).'_contact.php', 'myobject_document.php'=>strtolower($objectname).'_document.php', 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php', 'myobject_list.php'=>strtolower($objectname).'_list.php', @@ -2336,6 +2337,7 @@ if ($module == 'initmodule') $pathtodocument = strtolower($module).'/'.strtolower($tabobj).'_document.php'; $pathtolist = strtolower($module).'/'.strtolower($tabobj).'_list.php'; $pathtonote = strtolower($module).'/'.strtolower($tabobj).'_note.php'; + $pathtocontact = strtolower($module).'/'.strtolower($tabobj).'_contact.php'; $pathtophpunit = strtolower($module).'/test/phpunit/'.strtolower($tabobj).'Test.php'; $pathtosql = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'.sql'; $pathtosqlextra = strtolower($module).'/sql/llx_'.strtolower($module).'_'.strtolower($tabobj).'_extrafields.sql'; @@ -2354,6 +2356,7 @@ if ($module == 'initmodule') $realpathtodocument = $dirread.'/'.$pathtodocument; $realpathtolist = $dirread.'/'.$pathtolist; $realpathtonote = $dirread.'/'.$pathtonote; + $realpathtocontact = $dirread.'/'.$pathtocontact; $realpathtophpunit = $dirread.'/'.$pathtophpunit; $realpathtosql = $dirread.'/'.$pathtosql; $realpathtosqlextra = $dirread.'/'.$pathtosqlextra; @@ -2487,6 +2490,14 @@ if ($module == 'initmodule') print ''.img_picto($langs->trans("Delete"), 'delete').''; } print '
'; + print ' '.$langs->trans("PageForContactTab").' : '.($realpathtocontact ? '' : '').$pathtocontact.($realpathtocontact ? '' : '').''; + print ' '.img_picto($langs->trans("Edit"), 'edit').''; + if ($realpathtocontact) + { + print ' '; + print ''.img_picto($langs->trans("Delete"), 'delete').''; + } + print '
'; /* This is already on Tab CLI print '
'; diff --git a/htdocs/modulebuilder/template/myobject_contact.php b/htdocs/modulebuilder/template/myobject_contact.php new file mode 100644 index 00000000000..c48a997aba4 --- /dev/null +++ b/htdocs/modulebuilder/template/myobject_contact.php @@ -0,0 +1,203 @@ + + * Copyright (C) ---Put here your own copyright and developer email--- + * + * 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 htdocs/modulebuilder/template/myobject_contact.php + * \ingroup mymodule + * \brief Tab for contacts linked to MyObject + */ + +// 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_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +dol_include_once('/mymodule/class/myobject.class.php'); +dol_include_once('/mymodule/lib/mymodule_myobject.lib.php'); + +// Load translation files required by the page +$langs->loadLangs(array("mymodule@mymodule", "companies", "other", "mails")); + +$id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility +$ref = GETPOST('ref', 'alpha'); +$lineid = GETPOST('lineid', 'int'); +$socid = GETPOST('socid', 'int'); +$action = GETPOST('action', 'aZ09'); + +// Initialize technical objects +$object = new MyObject($db); +$extrafields = new ExtraFields($db); +$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id; +$hookmanager->initHooks(array('myobjectcontact', 'globalcard')); // Note that conf->hooks_modules contains array +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); + +// Load object +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals + +// Security check - Protection if external user +//if ($user->socid > 0) accessforbidden(); +//if ($user->socid > 0) $socid = $user->socid; +//$result = restrictedArea($user, 'mymodule', $object->id); + +$permission = $user->rights->mymodule->myobject->write; + +/* + * Add a new contact + */ + +if ($action == 'addcontact' && $permission) +{ + $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); + $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); + $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } +} // Toggle the status of a contact +elseif ($action == 'swapstatut' && $permission) +{ + $result = $object->swapContactStatus(GETPOST('ligne')); +} // Deletes a contact +elseif ($action == 'deletecontact' && $permission) +{ + $result = $object->delete_contact($lineid); + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + dol_print_error($db); + } +} + + +/* + * View + */ + +$title = $langs->trans('MyObject')." - ".$langs->trans('ContactsAddresses'); +$help_url = ''; +//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; +llxHeader('', $title, $help_url); + +$form = new Form($db); +$formcompany = new FormCompany($db); +$contactstatic = new Contact($db); +$userstatic = new User($db); + + +/* *************************************************************************** */ +/* */ +/* View and edit mode */ +/* */ +/* *************************************************************************** */ + +if ($object->id) +{ + /* + * Show tabs + */ + $head = myobjectPrepareHead($object); + + print dol_get_fiche_head($head, 'contact', $langs->trans("MyObject"), -1, $object->picto); + + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref = '
'; + /* + // Ref customer + $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); + $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : ''); + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($permissiontoadd) + { + if ($action != 'classify') + //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + $morehtmlref.=' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.='
'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= ': '.$proj->getNomUrl(); + } else { + $morehtmlref .= ''; + } + } + }*/ + $morehtmlref .= '
'; + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); + + print dol_get_fiche_end(); + + print '
'; + + // Contacts lines (modules that overwrite templates must declare this into descriptor) + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); + foreach ($dirtpls as $reldir) + { + $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); + if ($res) break; + } +} + +// End of page +llxFooter(); +$db->close(); From 214167b55270f3269a2fa085c20e001db64de3b9 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 25 Dec 2020 11:13:53 +0100 Subject: [PATCH 05/23] Add generation of admin/xxx_extrafields page --- htdocs/modulebuilder/index.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 2b7453c904a..5c8739977d6 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -906,6 +906,7 @@ if ($dirins && $action == 'initobject' && $module && $objectname) 'myobject_document.php'=>strtolower($objectname).'_document.php', 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php', 'myobject_list.php'=>strtolower($objectname).'_list.php', + 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php', 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php', //'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php', 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql', @@ -1336,6 +1337,7 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) 'myobject_document.php'=>strtolower($objectname).'_document.php', 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php', 'myobject_list.php'=>strtolower($objectname).'_list.php', + 'admin/myobject_extrafields.php'=>'admin/'.strtolower($objectname).'_extrafields.php', 'lib/mymodule_myobject.lib.php'=>'lib/'.strtolower($module).'_'.strtolower($objectname).'.lib.php', 'test/phpunit/MyObjectTest.php'=>'test/phpunit/'.strtolower($objectname).'Test.php', 'sql/llx_mymodule_myobject.sql'=>'sql/llx_'.strtolower($module).'_'.strtolower($objectname).'.sql', From 4cee1e8d792ffa1388da01b03c4f64c94a605aa1 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 25 Dec 2020 11:18:01 +0100 Subject: [PATCH 06/23] Fix admin/myobject_extrafields page --- .../template/admin/myobject_extrafields.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/htdocs/modulebuilder/template/admin/myobject_extrafields.php b/htdocs/modulebuilder/template/admin/myobject_extrafields.php index c844f80e4cc..0e42b75da0b 100644 --- a/htdocs/modulebuilder/template/admin/myobject_extrafields.php +++ b/htdocs/modulebuilder/template/admin/myobject_extrafields.php @@ -26,9 +26,22 @@ * \brief Page to setup extra fields of myobject */ -require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/bom.lib.php'; +// 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_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once '../lib/mymodule.lib.php'; // Load translation files required by the page $langs->loadLangs(array('mymodule@mymodule', 'admin')); From 22e036057521fb17575f2c281323acf899401639 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 25 Dec 2020 11:46:29 +0100 Subject: [PATCH 07/23] Fix missing delete files in module builder --- htdocs/modulebuilder/index.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 5c8739977d6..294ad4563b5 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -226,12 +226,15 @@ if ($dirins && $action == 'initmodule' && $modulename) // Delete dir and files that can be generated in sub tabs later if we need them (we want a minimal module first) dol_delete_dir_recursive($destdir.'/build/doxygen'); dol_delete_dir_recursive($destdir.'/core/modules/mailings'); + dol_delete_dir_recursive($destdir.'/core/modules/'.strtolower($modulename).''); dol_delete_dir_recursive($destdir.'/core/tpl'); dol_delete_dir_recursive($destdir.'/core/triggers'); dol_delete_dir_recursive($destdir.'/doc'); dol_delete_dir_recursive($destdir.'/.tx'); dol_delete_dir_recursive($destdir.'/core/boxes'); + dol_delete_file($destdir.'/admin/myobject_extrafields'); + dol_delete_file($destdir.'/sql/data.sql'); dol_delete_file($destdir.'/sql/update_x.x.x-y.y.y.sql'); @@ -1334,6 +1337,7 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) $filetodelete = array( 'myobject_card.php'=>strtolower($objectname).'_card.php', 'myobject_note.php'=>strtolower($objectname).'_note.php', + 'myobject_contact.php'=>strtolower($objectname).'_contact.php', 'myobject_document.php'=>strtolower($objectname).'_document.php', 'myobject_agenda.php'=>strtolower($objectname).'_agenda.php', 'myobject_list.php'=>strtolower($objectname).'_list.php', From f20f4cc5990b65caf28c2577a653602003fd9281 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 26 Dec 2020 19:23:25 +0100 Subject: [PATCH 08/23] Fix warnings --- .../webservices/server_productorservice.php | 38 +++++++++---------- test/phpunit/WebservicesProductsTest.php | 5 ++- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index f285d245030..2b3a76f5f7f 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -493,42 +493,42 @@ function createProductOrService($authentication, $product) $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); // Check parameters - if ($product['price_net'] > 0) $product['price_base_type'] = 'HT'; - if ($product['price'] > 0) $product['price_base_type'] = 'TTC'; + if (empty($product['price_base_type'])) { + if (isset($product['price_net']) && $product['price_net'] > 0) $product['price_base_type'] = 'HT'; + if (isset($product['price']) && $product['price'] > 0) $product['price_base_type'] = 'TTC'; + } - if ($product['price_net'] > 0 && $product['price'] > 0) + if (isset($product['price_net']) && $product['price_net'] > 0 && isset($product['price']) && $product['price'] > 0) { $error++; $errorcode = 'KO'; $errorlabel = "You must choose between price or price_net to provide price."; } - if ($product['barcode'] && !$product['barcode_type']) + if (!empty($product['barcode']) && empty($product['barcode_type'])) { $error++; $errorcode = 'KO'; $errorlabel = "You must set a barcode type when setting a barcode."; } - - if (!$error) { include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $newobject = new Product($db); $newobject->ref = $product['ref']; - $newobject->ref_ext = $product['ref_ext']; - $newobject->type = $product['type']; - $newobject->label = $product['label']; - $newobject->description = $product['description']; - $newobject->note_public = $product['note_public']; - $newobject->note_private = $product['note_private']; - $newobject->status = $product['status_tosell']; - $newobject->status_buy = $product['status_tobuy']; - $newobject->price = $product['price_net']; - $newobject->price_ttc = $product['price']; - $newobject->tva_tx = $product['vat_rate']; + $newobject->ref_ext = empty($product['ref_ext']) ? '' : $product['ref_ext']; + $newobject->type = empty($product['type']) ? 0 : $product['type']; + $newobject->label = empty($product['label']) ? '' : $product['label']; + $newobject->description = empty($product['description']) ? '' : $product['description']; + $newobject->note_public = empty($product['note_public']) ? '' : $product['note_public']; + $newobject->note_private = empty($product['note_private']) ? '' :$product['note_private']; + $newobject->status = empty($product['status_tosell']) ? 0 : $product['status_tosell']; + $newobject->status_buy = empty($product['status_tobuy']) ? 0 : $product['status_tobuy']; + $newobject->price = isset($product['price_net']) ? $product['price_net'] : 0; + $newobject->price_ttc = isset($product['price']) ? $product['price'] : 0; + $newobject->tva_tx = empty($product['vat_rate']) ? 0 : $product['vat_rate']; $newobject->price_base_type = $product['price_base_type']; $newobject->date_creation = $now; - if ($product['barcode']) + if (!empty($product['barcode'])) { $newobject->barcode = $product['barcode']; $newobject->barcode_type = $product['barcode_type']; @@ -539,7 +539,7 @@ function createProductOrService($authentication, $product) $newobject->seuil_stock_alert = $product['stock_alert']; $newobject->country_id = $product['country_id']; - if ($product['country_code']) $newobject->country_id = getCountry($product['country_code'], 3); + if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3); $newobject->customcode = $product['customcode']; $newobject->canvas = $product['canvas']; diff --git a/test/phpunit/WebservicesProductsTest.php b/test/phpunit/WebservicesProductsTest.php index 7b90fcbbd88..479fe5854de 100644 --- a/test/phpunit/WebservicesProductsTest.php +++ b/test/phpunit/WebservicesProductsTest.php @@ -182,7 +182,10 @@ class WebservicesProductsTest extends PHPUnit\Framework\TestCase 'type'=>1, 'description'=>'This is a new product created from WS PHPUnit test case', 'barcode'=>'123456789012', - 'barcode_type'=>2 + 'barcode_type'=>2, + 'price_net'=>10, + 'status_tosell'=>1, + 'status_tobuy'=>1 ) ); print __METHOD__." call method ".$WS_METHOD."\n"; From 28642238deb62e25277ad8f78c21ba01b0e251c7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 15:09:27 +0100 Subject: [PATCH 09/23] Fix error message --- htdocs/langs/en_US/modulebuilder.lang | 3 ++- htdocs/modulebuilder/index.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 6f8fdcad996..4a91bf60c6c 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -138,4 +138,5 @@ ForeignKey=Foreign key TypeOfFieldsHelp=Type of fields:
varchar(99), double(24,8), real, text, html, datetime, timestamp, integer, integer:ClassName:relativepath/to/classfile.class.php[:1[:filter]] ('1' means we add a + button after the combo to create the record, 'filter' can be 'status=1 AND fk_user = __USER_ID AND entity IN (__SHARED_ENTITIES__)' for example) AsciiToHtmlConverter=Ascii to HTML converter AsciiToPdfConverter=Ascii to PDF converter -TableNotEmptyDropCanceled=Table not empty. Drop has been canceled. \ No newline at end of file +TableNotEmptyDropCanceled=Table not empty. Drop has been canceled. +ModuleBuilderNotAllowed=The module builder is enabled but not allowed to your user. \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index fba9b0d4855..0631725a22c 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -57,8 +57,8 @@ $modulename = dol_sanitizeFileName(GETPOST('modulename', 'alpha')); $objectname = dol_sanitizeFileName(GETPOST('objectname', 'alpha')); // Security check -if (empty($conf->modulebuilder->enabled)) accessforbidden('ModuleBuilderNotAllowed'); -if (!$user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessforbidden('ModuleBuilderNotAllowed'); +if (empty($conf->modulebuilder->enabled)) accessforbidden(); +if (!$user->admin && empty($conf->global->MODULEBUILDER_FOREVERYONE)) accessforbidden($langs->trans('ModuleBuilderNotAllowed')); // Dir for custom dirs From 5fc3a9ce7dc8d431278e9503372261882b11f25f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 15:39:10 +0100 Subject: [PATCH 10/23] Debug v13 --- htdocs/langs/en_US/modulebuilder.lang | 2 +- htdocs/modulebuilder/index.php | 4 ++-- .../core/modules/modMyModule.class.php | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index 4a91bf60c6c..8e406d34c0f 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -105,7 +105,7 @@ TryToUseTheModuleBuilder=If you have knowledge of SQL and PHP, you may use the n SeeTopRightMenu=See on the top right menu AddLanguageFile=Add language file YouCanUseTranslationKey=You can use here a key that is the translation key found into language file (see tab "Languages") -DropTableIfEmpty=(Delete table if empty) +DropTableIfEmpty=(Destroy table if empty) TableDoesNotExists=The table %s does not exists TableDropped=Table %s deleted InitStructureFromExistingTable=Build the structure array string of an existing table diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 0631725a22c..ce5cadf9c35 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -2385,7 +2385,7 @@ if ($module == 'initmodule') print '   '; if (empty($conf->global->$const_name)) // If module is not activated { - print ''.$langs->trans("GoToApiExplorer").''; + print ''.$langs->trans("GoToApiExplorer").''; } else { print ''.$langs->trans("GoToApiExplorer").''; } @@ -3412,7 +3412,7 @@ if ($module == 'initmodule') if ($action != 'editfile' || empty($file)) { - print ''.$langs->trans("CronJobDefDesc", ''.$langs->transnoentities('CronList').'').'
'; + print ''.str_replace('{s1}', ''.$langs->transnoentities('CronList').'', $langs->trans("CronJobDefDesc", '{s1}')).'
'; print '
'; print ' '.$langs->trans("DescriptorFile").' : '.$pathtofile.''; diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 4917074dad0..2a5853a1e60 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -46,23 +46,31 @@ class modMyModule extends DolibarrModules // Id for module (must be unique). // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). $this->numero = 500000; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve an id number for your module + // Key text used to identify module (for permissions, menus, etc...) $this->rights_class = 'mymodule'; + // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...' // It is used to group modules by family in module setup page $this->family = "other"; + // Module position in the family on 2 digits ('01', '10', '20', ...) $this->module_position = '90'; + // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); // Module label (no space allowed), used if translation string 'ModuleMyModuleName' not found (MyModule is name of module). $this->name = preg_replace('/^mod/i', '', get_class($this)); + // Module description, used if translation string 'ModuleMyModuleDesc' not found (MyModule is name of module). $this->description = "MyModuleDescription"; // Used only if file README.md and README-LL.md not found. $this->descriptionlong = "MyModule description (Long)"; + + // Author $this->editor_name = 'Editor name'; $this->editor_url = 'https://www.example.com'; + // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' $this->version = '1.0'; // Url to the file with your last numberversion of this module @@ -70,10 +78,13 @@ class modMyModule extends DolibarrModules // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase) $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); + // Name of image file used for this module. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' + // To use a supported fa-xxx css style of font awesome, use this->picto='xxx' $this->picto = 'generic'; + // Define some features supported by module (triggers, login, substitutions, menus, css, etc...) $this->module_parts = array( // Set this to 1 if module has its own trigger directory (core/triggers) @@ -113,11 +124,14 @@ class modMyModule extends DolibarrModules // Set this to 1 if features of module are opened to external users 'moduleforexternal' => 0, ); + // Data directories to create when module is enabled. // Example: this->dirs = array("/mymodule/temp","/mymodule/subdir"); $this->dirs = array("/mymodule/temp"); + // Config pages. Put here list of php page, stored into mymodule/admin directory, to use to setup module. $this->config_page_url = array("setup.php@mymodule"); + // Dependencies // A condition to hide module $this->hidden = false; @@ -125,9 +139,15 @@ class modMyModule extends DolibarrModules $this->depends = array(); $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...) $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...) + + // The language file dedicated to your module $this->langfiles = array("mymodule@mymodule"); + + // Prerequisites $this->phpmin = array(5, 5); // Minimum version of PHP required by module $this->need_dolibarr_version = array(11, -3); // Minimum version of Dolibarr required by module + + // Messages at activation $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) //$this->automatic_activation = array('FR'=>'MyModuleWasAutomaticallyActivatedBecauseOfYourCountryChoice'); From 00c847b743cfef058a61a10789cfe51d6faf255a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 16:56:44 +0100 Subject: [PATCH 11/23] Fix warning --- htdocs/webservices/server_productorservice.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index 2b3a76f5f7f..bb068167b74 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -534,15 +534,15 @@ function createProductOrService($authentication, $product) $newobject->barcode_type = $product['barcode_type']; } - $newobject->stock_reel = $product['stock_real']; - $newobject->pmp = $product['pmp']; - $newobject->seuil_stock_alert = $product['stock_alert']; + $newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null; + $newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null; + $newobject->seuil_stock_alert = isset($product['stock_alert']) ? $product['stock_alert'] : null; - $newobject->country_id = $product['country_id']; + $newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0; if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3); - $newobject->customcode = $product['customcode']; + $newobject->customcode = isset($product['customcode']) ? $product['customcode'] : ''; - $newobject->canvas = $product['canvas']; + $newobject->canvas = isset($product['canvas']) ? $product['canvas'] : ''; /*foreach($product['lines'] as $line) { $newline=new FactureLigne($db); @@ -565,7 +565,7 @@ function createProductOrService($authentication, $product) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $product[$key]; From 5ff53691a5028927b25829728d90d8734f5a89a2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 19:13:09 +0100 Subject: [PATCH 12/23] Fix migration --- htdocs/install/upgrade2.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index ba24cf3a496..3a2b8889d96 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -4332,6 +4332,14 @@ function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $fo $mod->remove('noboxes'); $mod->init($reloadmode); } + } elseif ($moduletoreload == 'MAIN_MODULE_EXTERNALSITE') { + dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate ExternalSite module"); + $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/modExternalSite.class.php'; + if ($res) { + $mod = new modExternalSite($db); + $mod->remove('noboxes'); + $mod->init($reloadmode); + } } elseif ($moduletoreload == 'MAIN_MODULE_SOCIETE') { dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate Societe module"); $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/modSociete.class.php'; From 4ec78d029b24655c2e9d3eab4fb484f83a1e9df6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 19:21:37 +0100 Subject: [PATCH 13/23] Fix warning --- htdocs/core/modules/modCommande.class.php | 1 + htdocs/core/modules/modExpedition.class.php | 2 +- htdocs/core/modules/modFacture.class.php | 4 ++-- htdocs/core/modules/modPropale.class.php | 2 +- htdocs/core/modules/modReception.class.php | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/modCommande.class.php b/htdocs/core/modules/modCommande.class.php index 84a46c49d63..ac4d26725bc 100644 --- a/htdocs/core/modules/modCommande.class.php +++ b/htdocs/core/modules/modCommande.class.php @@ -263,6 +263,7 @@ class modCommande extends DolibarrModules $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande'; $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('commande').')'; if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); + // Imports //-------- $r = 0; diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index 54fecd1a5af..c42cbeb0f8c 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -306,7 +306,7 @@ class modExpedition extends DolibarrModules } $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_origin_line = cd.rowid'; $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('expedition').')'; - if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; + if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); } diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 8f4172112b5..9212fa1f7ce 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -291,7 +291,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')'; - if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; + if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); $r++; @@ -371,7 +371,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid'; $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')'; - if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; + if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); $r++; } diff --git a/htdocs/core/modules/modPropale.class.php b/htdocs/core/modules/modPropale.class.php index f1de32bd1a9..c0ffa6f0811 100644 --- a/htdocs/core/modules/modPropale.class.php +++ b/htdocs/core/modules/modPropale.class.php @@ -254,7 +254,7 @@ class modPropale extends DolibarrModules $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal'; $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('propal').')'; - if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; + if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); // Imports //-------- diff --git a/htdocs/core/modules/modReception.class.php b/htdocs/core/modules/modReception.class.php index f784d88a3da..8bebf949b6f 100644 --- a/htdocs/core/modules/modReception.class.php +++ b/htdocs/core/modules/modReception.class.php @@ -231,7 +231,7 @@ class modReception extends DolibarrModules } $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_reception AND ed.fk_commandefourndet = cd.rowid'; $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('reception').')'; - if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; + if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id); } From 5aae018a0bfd302f87c59d3f077b9c16a6b7b3d6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 19:33:07 +0100 Subject: [PATCH 14/23] Fix for php8 --- dev/dolibarr_changes.txt | 7 +++++++ htdocs/includes/nusoap/lib/nusoap.php | 6 ++++-- test/phpunit/WebservicesProductsTest.php | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dev/dolibarr_changes.txt b/dev/dolibarr_changes.txt index 5648381ff49..f3374c43234 100644 --- a/dev/dolibarr_changes.txt +++ b/dev/dolibarr_changes.txt @@ -50,6 +50,13 @@ Replace call to serialize_val with no bugged value * In all files, replace constructor names into __construct. Replace also parent::constructor_name with parent::__construct +* Line 4222 of file nusoap.php + + $rev = array(); + preg_match('/\$Revision: ([^ ]+)/', $this->revision, $rev); + $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (".(isset($rev[1]) ? $rev[1] : '').")"; + + TCPDF: diff --git a/htdocs/includes/nusoap/lib/nusoap.php b/htdocs/includes/nusoap/lib/nusoap.php index a1fbd00051d..459f4aeb7b6 100644 --- a/htdocs/includes/nusoap/lib/nusoap.php +++ b/htdocs/includes/nusoap/lib/nusoap.php @@ -4219,8 +4219,10 @@ class nusoap_server extends nusoap_base { $payload .= $this->getDebugAsXMLComment(); } $this->outgoing_headers[] = "Server: $this->title Server v$this->version"; - preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev); - $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (".$rev[1].")"; + // @CHANGE Fix for php8 + $rev = array(); + preg_match('/\$Revision: ([^ ]+)/', $this->revision, $rev); + $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (".(isset($rev[1]) ? $rev[1] : '').")"; // Let the Web server decide about this //$this->outgoing_headers[] = "Connection: Close\r\n"; $payload = $this->getHTTPBody($payload); diff --git a/test/phpunit/WebservicesProductsTest.php b/test/phpunit/WebservicesProductsTest.php index 479fe5854de..b78650cc480 100644 --- a/test/phpunit/WebservicesProductsTest.php +++ b/test/phpunit/WebservicesProductsTest.php @@ -204,7 +204,7 @@ class WebservicesProductsTest extends PHPUnit\Framework\TestCase print $soapclient->response; print "\n"; } - + print var_export($result, true); print __METHOD__." count(result)=".(is_array($result) ? count($result) : '')."\n"; $this->assertEquals('OK', $result['result']['result_code']); From e89a410e59b8378bc6b0f76fe2fc00886e1e8e41 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 20:33:07 +0100 Subject: [PATCH 15/23] Fix warning --- htdocs/product/class/product.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index c40ffd4e0a9..1c2eb2327d2 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2651,14 +2651,14 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql .= ", ".MAIN_DB_PREFIX."commande as c"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'commande').")"; $sql .= " AND cd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { From d1d4914684dfc4fbd1c2677ceaca17d1ba2aed97 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 20:49:54 +0100 Subject: [PATCH 16/23] Sanitize data --- htdocs/ecm/file_card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/ecm/file_card.php b/htdocs/ecm/file_card.php index 496afbf8568..abd6209ac7a 100644 --- a/htdocs/ecm/file_card.php +++ b/htdocs/ecm/file_card.php @@ -65,7 +65,7 @@ if (!$section) dol_print_error('', 'Error, section parameter missing'); exit; } -$urlfile = GETPOST("urlfile"); +$urlfile = (string) dol_sanitizePathName(GETPOST("urlfile")); if (!$urlfile) { dol_print_error('', "ErrorParamNotDefined"); From 6421f757dc592a3747482ae8781275b8cfd39cb5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 21:21:13 +0100 Subject: [PATCH 17/23] FIX Can delete a directory created manually that can not be indexed --- htdocs/ecm/class/ecmdirectory.class.php | 2 +- htdocs/ecm/dir_card.php | 86 ++++++++++++------------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index ca2b9fec473..4c4a3fc3412 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -345,7 +345,7 @@ class EcmDirectory extends CommonObject $sql .= " t.date_c as date_c,"; $sql .= " t.tms as date_m"; $sql .= " FROM ".MAIN_DB_PREFIX."ecm_directories as t"; - $sql .= " WHERE t.rowid = ".$id; + $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/ecm/dir_card.php b/htdocs/ecm/dir_card.php index 9dc6977f1e4..8b86f99d2c7 100644 --- a/htdocs/ecm/dir_card.php +++ b/htdocs/ecm/dir_card.php @@ -54,7 +54,7 @@ $pagenext = $page + 1; if (!$sortorder) $sortorder = "ASC"; if (!$sortfield) $sortfield = "name"; -$section = GETPOST("section", 'alpha') ?GETPOST("section", 'alpha') : GETPOST("relativedir", 'alpha'); +$section = GETPOST("section", 'alpha') ? GETPOST("section", 'alpha') : GETPOST("relativedir", 'alpha'); if (!$section) { dol_print_error('', "ErrorSectionParamNotDefined"); @@ -66,15 +66,15 @@ $ecmdir = new EcmDirectory($db); if ($module == 'ecm') { + // $section should be an int except if it is dir not yet created into EcmDirectory $result = $ecmdir->fetch($section); - if (!$result > 0) - { - dol_print_error($db, $ecmdir->error); - exit; + if ($result > 0) { + $relativepath = $ecmdir->getRelativePath(); + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; + } else { + $relativepath = $section; + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; } - - $relativepath = $ecmdir->getRelativePath(); - $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; } else // For example $module == 'medias' { $relativepath = $section; @@ -143,28 +143,23 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') } // Remove dir -if ($action == 'confirm_deletedir' && $confirm == 'yes') -{ +if ($action == 'confirm_deletedir' && $confirm == 'yes') { $backtourl = DOL_URL_ROOT."/ecm/index.php"; - if ($module == 'medias') - { + if ($module == 'medias') { $backtourl = DOL_URL_ROOT."/website/index.php?file_manager=1"; } $deletedirrecursive = (GETPOST('deletedirrecursive', 'alpha') == 'on' ? 1 : 0); - if ($module == 'ecm') - { + if ($module == 'ecm' && $ecmdir->id > 0) { // If manual ECM and directory is indexed into database // Fetch was already done $result = $ecmdir->delete($user, 'all', $deletedirrecursive); - if ($result <= 0) - { + if ($result <= 0) { $langs->load('errors'); setEventMessages($langs->trans($ecmdir->error, $ecmdir->label), null, 'errors'); } } else { - if ($deletedirrecursive) - { + if ($deletedirrecursive) { $resbool = dol_delete_dir_recursive($upload_dir, 0, 1); } else { $resbool = dol_delete_dir($upload_dir, 1); @@ -176,8 +171,7 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes') $result = 0; } } - if ($result > 0) - { + if ($result > 0) { header("Location: ".$backtourl); exit; } @@ -269,10 +263,9 @@ if ($action == 'update' && !GETPOST('cancel', 'alpha')) } - -/******************************************************************* -* View -********************************************************************/ +/* + * View + */ $form = new Form($db); @@ -281,9 +274,7 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); - -if ($module == 'ecm') -{ +if ($module == 'ecm' && $ecmdir->id > 0) { $object->fetch($ecmdir->id); } @@ -323,24 +314,27 @@ if ($module == 'ecm') $result = 1; $i = 0; $tmpecmdir = new EcmDirectory($db); // Need to create a new one - $tmpecmdir->fetch($ecmdir->id); - while ($tmpecmdir && $result > 0) - { - $tmpecmdir->ref = $tmpecmdir->label; - if ($i == 0 && $action == 'edit') + if ($ecmdir->id > 0) { + $tmpecmdir->fetch($ecmdir->id); + while ($tmpecmdir && $result > 0) { - $s = ''; - } else $s = $tmpecmdir->getNomUrl(1).$s; - if ($tmpecmdir->fk_parent) - { - $s = ' -> '.$s; - $result = $tmpecmdir->fetch($tmpecmdir->fk_parent); - } else { - $tmpecmdir = 0; + $tmpecmdir->ref = $tmpecmdir->label; + if ($i == 0 && $action == 'edit') + { + $s = ''; + } else $s = $tmpecmdir->getNomUrl(1).$s; + if ($tmpecmdir->fk_parent) + { + $s = ' -> '.$s; + $result = $tmpecmdir->fetch($tmpecmdir->fk_parent); + } else { + $tmpecmdir = 0; + } + $i++; } - $i++; + } else { + $s .= join(' -> ', explode('/', $section)); } - $morehtmlref = ''.$langs->trans("ECMRoot").' -> '.$s; } if ($module == 'medias') @@ -393,9 +387,11 @@ if ($module == 'ecm') print ''; print ''.$langs->trans("ECMCreationUser").''; - $userecm = new User($db); - $userecm->fetch($ecmdir->fk_user_c); - print $userecm->getNomUrl(1); + if ($ecmdir->fk_user_c > 0) { + $userecm = new User($db); + $userecm->fetch($ecmdir->fk_user_c); + print $userecm->getNomUrl(1); + } print ''; } print ''.$langs->trans("ECMCreationDate").''; From eac711f96c83ff2f505abfedbb3eb3ae1ca91d87 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 27 Dec 2020 21:41:39 +0100 Subject: [PATCH 18/23] Debug v13 --- htdocs/product/class/product.class.php | 119 +++++++++++++------------ 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 1c2eb2327d2..63e0fea2b36 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2395,7 +2395,7 @@ class Product extends CommonObject public function load_stats_mo($socid = 0) { // phpcs:enable - global $user, $hookmanager; + global $user, $hookmanager, $action; $error = 0; @@ -2408,7 +2408,7 @@ class Product extends CommonObject $sql .= " SUM(mp.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."mrp_production as mp ON mp.fk_mo=c.rowid"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= "INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".$user->id; } $sql .= " WHERE "; @@ -2527,14 +2527,14 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd"; $sql .= ", ".MAIN_DB_PREFIX."propal as p"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = pd.fk_propal"; $sql .= " AND p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('propal').")"; $sql .= " AND pd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND pr.fk_statut != 0"; @@ -2593,23 +2593,26 @@ class Product extends CommonObject public function load_stats_proposal_supplier($socid = 0) { // phpcs:enable - global $conf, $user, $hookmanager; + global $conf, $user, $hookmanager, $action; $sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_suppliers, COUNT(DISTINCT p.rowid) as nb,"; $sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as pd"; $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = pd.fk_supplier_proposal"; $sql .= " AND p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")"; $sql .= " AND pd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND pr.fk_statut != 0"; - if ($socid > 0) { $sql .= " AND p.fk_soc = ".$socid; + if ($socid > 0) { + $sql .= " AND p.fk_soc = ".$socid; } $result = $this->db->query($sql); @@ -2665,7 +2668,7 @@ class Product extends CommonObject $sql .= " AND c.fk_soc = ".$socid; } if ($filtrestatut <> '') { - $sql .= " AND c.fk_statut in (".$filtrestatut.")"; + $sql .= " AND c.fk_statut in (".$this->db->sanitize($filtrestatut).")"; } $result = $this->db->query($sql); @@ -2744,28 +2747,28 @@ class Product extends CommonObject public function load_stats_commande_fournisseur($socid = 0, $filtrestatut = '', $forVirtualStock = 0) { // phpcs:enable - global $conf, $user, $hookmanager; + global $conf, $user, $hookmanager, $action; $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")"; $sql .= " AND cd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { $sql .= " AND c.fk_soc = ".$socid; } if ($filtrestatut != '') { - $sql .= " AND c.fk_statut in (".$filtrestatut.")"; // Peut valoir 0 + $sql .= " AND c.fk_statut in (".$this->db->sanitize($filtrestatut).")"; // Peut valoir 0 } $result = $this->db->query($sql); @@ -2809,7 +2812,7 @@ class Product extends CommonObject $sql .= ", ".MAIN_DB_PREFIX."commande as c"; $sql .= ", ".MAIN_DB_PREFIX."expedition as e"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE e.rowid = ed.fk_expedition"; @@ -2818,16 +2821,16 @@ class Product extends CommonObject $sql .= " AND e.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'expedition').")"; $sql .= " AND ed.fk_origin_line = cd.rowid"; $sql .= " AND cd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { $sql .= " AND e.fk_soc = ".$socid; } if ($filtrestatut <> '') { - $sql .= " AND c.fk_statut in (".$filtrestatut.")"; + $sql .= " AND c.fk_statut IN (".$this->db->sanitize($filtrestatut).")"; } - if (!empty($filterShipmentStatus)) $sql .= " AND e.fk_statut IN (".$filterShipmentStatus.")"; + if (!empty($filterShipmentStatus)) $sql .= " AND e.fk_statut IN (".$this->db->sanitize($filterShipmentStatus).")"; $result = $this->db->query($sql); if ($result) { @@ -2881,24 +2884,28 @@ class Product extends CommonObject public function load_stats_reception($socid = 0, $filtrestatut = '', $forVirtualStock = 0) { // phpcs:enable - global $conf, $user, $hookmanager; + global $conf, $user, $hookmanager, $action; $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd"; $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE cf.rowid = fd.fk_commande"; $sql .= " AND cf.fk_soc = s.rowid"; $sql .= " AND cf.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")"; $sql .= " AND fd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { + $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } - if ($socid > 0) { $sql .= " AND cf.fk_soc = ".$socid; + if ($socid > 0) { + $sql .= " AND cf.fk_soc = ".$socid; } - if ($filtrestatut <> '') { $sql .= " AND cf.fk_statut in (".$filtrestatut.")"; + if ($filtrestatut <> '') { + $sql .= " AND cf.fk_statut IN (".$this->db->sanitize($filtrestatut).")"; } $result = $this->db->query($sql); @@ -2939,20 +2946,20 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."mrp_production as mp"; $sql .= ", ".MAIN_DB_PREFIX."mrp_mo as m"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = m.fk_soc"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE m.rowid = mp.fk_mo"; $sql .= " AND m.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mrp').")"; $sql .= " AND mp.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= " AND m.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { $sql .= " AND m.fk_soc = ".$socid; } if ($filtrestatut <> '') { - $sql .= " AND m.status in (".$filtrestatut.")"; + $sql .= " AND m.status IN (".$this->db->sanitize($filtrestatut).")"; } $sql .= " GROUP BY role"; @@ -3026,14 +3033,14 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; $sql .= ", ".MAIN_DB_PREFIX."contrat as c"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_contrat"; $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('contract').")"; $sql .= " AND cd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND c.statut != 0"; @@ -3098,14 +3105,14 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd"; $sql .= ", ".MAIN_DB_PREFIX."facture as f"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = fd.fk_facture"; $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; $sql .= " AND fd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND f.fk_statut != 0"; @@ -3163,21 +3170,21 @@ class Product extends CommonObject public function load_stats_facture_fournisseur($socid = 0) { // phpcs:enable - global $conf, $user, $hookmanager; + global $conf, $user, $hookmanager, $action; $sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as fd"; $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = fd.fk_facture_fourn"; $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture_fourn').")"; $sql .= " AND fd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND f.fk_statut != 0"; @@ -3302,7 +3309,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = d.fk_facture"; @@ -3312,11 +3319,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3355,7 +3362,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = d.fk_facture_fourn"; @@ -3365,11 +3372,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture_fourn').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3406,7 +3413,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as prod"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = d.fk_propal"; @@ -3416,11 +3423,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND prod.rowid = d.fk_product AND prod.fk_product_type =".$filteronproducttype; + $sql .= " AND prod.rowid = d.fk_product AND prod.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('propal').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3458,7 +3465,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as prod"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = d.fk_supplier_proposal"; @@ -3468,11 +3475,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND prod.rowid = d.fk_product AND prod.fk_product_type =".$filteronproducttype; + $sql .= " AND prod.rowid = d.fk_product AND prod.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3509,7 +3516,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = d.fk_commande"; @@ -3519,11 +3526,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('commande').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3560,7 +3567,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = d.fk_commande"; @@ -3570,11 +3577,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('supplier_order').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3611,7 +3618,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -3624,11 +3631,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND c.fk_soc = s.rowid"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3665,7 +3672,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -3678,10 +3685,10 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND d.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { From cec96b33aeb4bc21e2118048aac3ee2fa804166b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 28 Dec 2020 12:30:59 +0100 Subject: [PATCH 19/23] Fix warning --- htdocs/core/lib/ws.lib.php | 2 +- htdocs/webservices/server_invoice.php | 24 ++++++++----------- htdocs/webservices/server_order.php | 14 +++++------ htdocs/webservices/server_other.php | 9 +++---- htdocs/webservices/server_payment.php | 5 ++-- .../webservices/server_productorservice.php | 16 ++++++------- htdocs/webservices/server_project.php | 8 +++---- .../webservices/server_supplier_invoice.php | 5 ++-- htdocs/webservices/server_thirdparty.php | 22 ++++++++--------- htdocs/webservices/server_user.php | 21 +++++++--------- test/phpunit/WebservicesInvoicesTest.php | 2 ++ 11 files changed, 59 insertions(+), 69 deletions(-) diff --git a/htdocs/core/lib/ws.lib.php b/htdocs/core/lib/ws.lib.php index faf1b5bc871..2545c8e5973 100644 --- a/htdocs/core/lib/ws.lib.php +++ b/htdocs/core/lib/ws.lib.php @@ -29,7 +29,7 @@ * @param array $authentication Array with authentication informations ('login'=>,'password'=>,'entity'=>,'dolibarrkey'=>) * @param int $error Number of errors * @param string $errorcode Error string code - * @param string $errorlabel Error string label + * @param string $errorlabel Error string label * @return User Return user object identified by login/pass/entity into authentication array */ function check_authentication($authentication, &$error, &$errorcode, &$errorlabel) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 5a8e6fb241c..e1f08cbb1ca 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -288,7 +288,7 @@ $server->register( */ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -363,7 +363,7 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '') 'note_private' => $invoice->note_private ? $invoice->note_private : '', 'note_public' => $invoice->note_public ? $invoice->note_public : '', 'status' => $invoice->statut, - 'project_id' => $invoic->fk_project, + 'project_id' => $invoice->fk_project, 'close_code' => $invoice->close_code ? $invoice->close_code : '', 'close_note' => $invoice->close_note ? $invoice->close_note : '', 'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id : '', @@ -399,7 +399,7 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '') */ function getInvoicesForThirdParty($authentication, $idthirdparty) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getInvoicesForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty); @@ -482,7 +482,7 @@ function getInvoicesForThirdParty($authentication, $idthirdparty) 'fk_user_valid' => $invoice->user_valid ? $invoice->user_valid : '', 'date' => $invoice->date ?dol_print_date($invoice->date, 'dayrfc') : '', 'date_due' => $invoice->date_lim_reglement ?dol_print_date($invoice->date_lim_reglement, 'dayrfc') : '', - 'date_creation' => $invoice->date_creation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '', + 'date_creation' => $invoice->date_creation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '', 'date_validation' => $invoice->date_validation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '', 'date_modification' => $invoice->datem ?dol_print_date($invoice->datem, 'dayhourrfc') : '', 'type' => $invoice->type, @@ -492,7 +492,7 @@ function getInvoicesForThirdParty($authentication, $idthirdparty) 'note_private' => $invoice->note_private ? $invoice->note_private : '', 'note_public' => $invoice->note_public ? $invoice->note_public : '', 'status'=> $invoice->statut, - 'project_id' => $invoic->fk_project, + 'project_id' => $invoice->fk_project, 'close_code' => $invoice->close_code ? $invoice->close_code : '', 'close_note' => $invoice->close_note ? $invoice->close_note : '', 'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id : '', @@ -528,17 +528,16 @@ function getInvoicesForThirdParty($authentication, $idthirdparty) * Create an invoice * * @param array $authentication Array of authentication information - * @param Facture $invoice Invoice + * @param array $invoice Invoice * @return array Array result */ function createInvoice($authentication, $invoice) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); - dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice->id. - ", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext); + dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice['id'].", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -580,7 +579,7 @@ function createInvoice($authentication, $invoice) if (isset($invoice['lines']['line'][0])) $arrayoflines = $invoice['lines']['line']; else $arrayoflines = $invoice['lines']; - foreach ($arrayoflines as $key => $line) + foreach ($arrayoflines as $line) { // $key can be 'line' or '0','1',... $newline = new FactureLigne($db); @@ -654,10 +653,7 @@ function createInvoiceFromOrder($authentication, $id_order = '', $ref_order = '' { global $db, $conf; - $now = dol_now(); - - dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order. - ", ref=".$ref_order.", ref_ext=".$ref_ext_order); + dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order.", ref=".$ref_order.", ref_ext=".$ref_ext_order); if ($authentication['entity']) $conf->entity = $authentication['entity']; diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 30c105d7192..361b2a08f4a 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -354,7 +354,7 @@ $server->register( */ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getOrder login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -504,7 +504,7 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') */ function getOrdersForThirdParty($authentication, $idthirdparty) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getOrdersForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty); @@ -707,7 +707,7 @@ function createOrder($authentication, $order) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $order[$key]; @@ -813,7 +813,7 @@ function validOrder($authentication, $id = '', $id_warehouse = 0) { global $db, $conf, $langs; - dol_syslog("Function: validOrder login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + dol_syslog("Function: validOrder login=".$authentication['login']." id=".$id." id_warehouse=".$id_warehouse); // Init and check authentication $objectresp = array(); @@ -830,7 +830,7 @@ function validOrder($authentication, $id = '', $id_warehouse = 0) if ($fuser->rights->commande->lire) { $order = new Commande($db); - $result = $order->fetch($id, $ref, $ref_ext); + $result = $order->fetch($id); $order->fetch_thirdparty(); $db->begin(); @@ -889,8 +889,6 @@ function updateOrder($authentication, $order) { global $db, $conf, $langs; - $now = dol_now(); - dol_syslog("Function: updateOrder login=".$authentication['login']); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -950,7 +948,7 @@ function updateOrder($authentication, $order) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; if (isset($order[$key])) diff --git a/htdocs/webservices/server_other.php b/htdocs/webservices/server_other.php index 71ee78d3c4d..61f53f7e275 100644 --- a/htdocs/webservices/server_other.php +++ b/htdocs/webservices/server_other.php @@ -145,7 +145,7 @@ $server->register( */ function getVersions($authentication) { - global $db, $conf, $langs; + global $conf; dol_syslog("Function: getVersions login=".$authentication['login']); @@ -188,7 +188,7 @@ function getVersions($authentication) */ function getDocument($authentication, $modulepart, $file, $refname = '') { - global $db, $conf, $langs, $mysoc; + global $db, $conf; dol_syslog("Function: getDocument login=".$authentication['login'].' - modulepart='.$modulepart.' - file='.$file); @@ -283,10 +283,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '') { if (file_exists($original_file)) { - dol_syslog("Function: getDocument $original_file $filename content-type=$type"); - - $file = $fileparams['fullname']; - $filename = basename($file); + dol_syslog("Function: getDocument $original_file content-type=$type"); $f = fopen($original_file, 'r'); $content_file = fread($f, filesize($original_file)); diff --git a/htdocs/webservices/server_payment.php b/htdocs/webservices/server_payment.php index 8a9b19d76d6..3fd3868a36a 100644 --- a/htdocs/webservices/server_payment.php +++ b/htdocs/webservices/server_payment.php @@ -45,6 +45,7 @@ $langs->load("main"); if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) { $langs->load("admin"); + dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled"); print $langs->trans("WarningModuleNotActive", 'WebServices').'.

'; print $langs->trans("ToActivateModule"); @@ -139,7 +140,7 @@ $server->register( */ function createPayment($authentication, $payment) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); @@ -165,7 +166,7 @@ function createPayment($authentication, $payment) if (!$error) { $soc = new Societe($db); - $res = $soc->fetch($payment['thirdparty_id']); + $soc->fetch($payment['thirdparty_id']); $new_payment = new Paiement($db); $new_payment->amount = doubleval($payment['amount']); diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index bb068167b74..473a720f46a 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -438,7 +438,7 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $productorservice_result_fields = array_merge($productorservice_result_fields, array('options_'.$key => $product->array_options['options_'.$key])); } @@ -479,7 +479,7 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' */ function createProductOrService($authentication, $product) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); @@ -650,7 +650,7 @@ function createProductOrService($authentication, $product) */ function updateProductOrService($authentication, $product) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); @@ -721,7 +721,7 @@ function updateProductOrService($authentication, $product) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $product[$key]; @@ -824,7 +824,7 @@ function updateProductOrService($authentication, $product) */ function deleteProductOrService($authentication, $listofidstring) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: deleteProductOrService login=".$authentication['login']); @@ -855,7 +855,7 @@ function deleteProductOrService($authentication, $listofidstring) $db->begin(); - foreach ($listofid as $key => $id) + foreach ($listofid as $id) { $newobject = new Product($db); $result = $newobject->fetch($id); @@ -917,7 +917,7 @@ function deleteProductOrService($authentication, $listofidstring) */ function getListOfProductsOrServices($authentication, $filterproduct) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getListOfProductsOrServices login=".$authentication['login']); @@ -1092,7 +1092,7 @@ function getProductsForCategory($authentication, $id, $lang = '') if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $products[$iProduct] = array_merge($products[$iProduct], array('options_'.$key => $tmpproduct->array_options['options_'.$key])); } diff --git a/htdocs/webservices/server_project.php b/htdocs/webservices/server_project.php index 0817332c09f..8d76786df71 100644 --- a/htdocs/webservices/server_project.php +++ b/htdocs/webservices/server_project.php @@ -131,7 +131,7 @@ $server->wsdl->addComplexType( ); $project_elements = array(); -foreach ($listofreferent as $key => $_) +foreach ($listofreferent as $key => $label) { $project_elements[$key] = array('name'=>$key, 'type'=>'tns:elementsArray'); } @@ -279,7 +279,7 @@ function createProject($authentication, $project) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $project[$key]; @@ -338,7 +338,7 @@ function createProject($authentication, $project) */ function getProject($authentication, $id = '', $ref = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getProject login=".$authentication['login']." id=".$id." ref=".$ref); @@ -389,7 +389,7 @@ function getProject($authentication, $id = '', $ref = '') if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { $project->fetch_optionals(); - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $project_result_fields = array_merge($project_result_fields, array('options_'.$key => $project->array_options['options_'.$key])); } diff --git a/htdocs/webservices/server_supplier_invoice.php b/htdocs/webservices/server_supplier_invoice.php index be90b60c36f..507095ac78b 100644 --- a/htdocs/webservices/server_supplier_invoice.php +++ b/htdocs/webservices/server_supplier_invoice.php @@ -225,7 +225,7 @@ $server->register( */ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getSupplierInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -333,7 +333,7 @@ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '') */ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getSupplierInvoicesForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty); @@ -344,6 +344,7 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty) $errorcode = ''; $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); + // Check parameters if (!$error && empty($idthirdparty)) { diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 5bde94cc0d5..12b2d3315c8 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -132,7 +132,7 @@ if (is_array($extrafields) && count($extrafields) > 0) { } if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { //$value=$object->array_options["options_".$key]; $type = $extrafields->attributes[$elementtype]['type'][$key]; @@ -290,7 +290,7 @@ $server->register( */ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -367,7 +367,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $thirdparty_result_fields = array_merge($thirdparty_result_fields, array('options_'.$key => $thirdparty->array_options['options_'.$key])); } @@ -408,7 +408,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') */ function createThirdParty($authentication, $thirdparty) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); @@ -483,7 +483,7 @@ function createThirdParty($authentication, $thirdparty) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $thirdparty[$key]; @@ -538,7 +538,7 @@ function createThirdParty($authentication, $thirdparty) */ function updateThirdParty($authentication, $thirdparty) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); @@ -617,7 +617,7 @@ function updateThirdParty($authentication, $thirdparty) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $object->array_options[$key] = $thirdparty[$key]; @@ -672,9 +672,7 @@ function updateThirdParty($authentication, $thirdparty) */ function getListOfThirdParties($authentication, $filterthirdparty) { - global $db, $conf, $langs; - - $now = dol_now(); + global $db, $conf; dol_syslog("Function: getListOfThirdParties login=".$authentication['login']); @@ -725,7 +723,7 @@ function getListOfThirdParties($authentication, $filterthirdparty) if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $extrafieldsOptions['options_'.$key] = $obj->{$key}; } @@ -782,7 +780,7 @@ function getListOfThirdParties($authentication, $filterthirdparty) */ function deleteThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: deleteThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 25cb2324412..8619a952ea1 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -195,7 +195,7 @@ if (is_array($extrafields) && count($extrafields) > 0) { } if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $type = $extrafields->attributes[$elementtype]['type'][$key]; if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; } @@ -308,7 +308,7 @@ $server->register( */ function getUser($authentication, $id, $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getUser login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -399,9 +399,7 @@ function getUser($authentication, $id, $ref = '', $ref_ext = '') */ function getListOfGroups($authentication) { - global $db, $conf, $langs; - - $now = dol_now(); + global $db, $conf; dol_syslog("Function: getListOfGroups login=".$authentication['login']); @@ -477,7 +475,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) { global $db, $conf, $langs; - dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -601,7 +599,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'contact_options_'.$key; $key = substr($key, 8); // Remove 'contact_' prefix @@ -644,7 +642,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) } } else { $error++; - $errors = ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors); + $errorcode = join(', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors)); } } } else { @@ -662,7 +660,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) { $db->rollback(); $objectresp = array( - 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel) + 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel) ); } @@ -680,9 +678,9 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) function setUserPassword($authentication, $shortuser) { - global $db, $conf, $langs; + global $db, $conf; - dol_syslog("Function: setUserPassword login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + dol_syslog("Function: setUserPassword login=".$authentication['login']); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -715,7 +713,6 @@ function setUserPassword($authentication, $shortuser) { $objectresp = array( 'result'=>array('result_code' => 'OK', 'result_label' => ''), - 'groups'=>$arraygroups ); } else { diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 650e391587b..beb3e844809 100644 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -102,6 +102,8 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase { global $conf,$user,$langs,$db; + $now = dol_now(); + // create a third_party, needed to create an invoice // // The third party is created in setUpBeforeClass() and not in the From 4b3cd947f2432d7893d1f6527d47fa9dc8b4d8e2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 28 Dec 2020 12:33:00 +0100 Subject: [PATCH 20/23] Fix name of function --- htdocs/admin/agenda_reminder.php | 4 ++-- htdocs/core/lib/functions.lib.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/agenda_reminder.php b/htdocs/admin/agenda_reminder.php index 27c6bbeed73..36f0c572de4 100644 --- a/htdocs/admin/agenda_reminder.php +++ b/htdocs/admin/agenda_reminder.php @@ -187,14 +187,14 @@ print ' '."\n"; print ''."\n"; if (empty($conf->global->AGENDA_REMINDER_BROWSER)) { - if (! getIsHTTPS()) { + if (!isHTTPS()) { $langs->load("errors"); print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' '; } print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; print ''."\n"; } else { - if (! getIsHTTPS()) { + if (!isHTTPS()) { $langs->load("errors"); print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' '; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 884d8eac496..33a09f541c6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2909,7 +2909,7 @@ function getUserRemoteIP() * * @return boolean True if user is using HTTPS */ -function getIsHTTPS() +function isHTTPS() { $isSecure = false; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { From 7c3688c66f67e46802ad47adaf5da4b91c73c431 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 28 Dec 2020 12:36:36 +0100 Subject: [PATCH 21/23] Fix var not defined --- htdocs/comm/mailing/cibles.php | 2 +- htdocs/comm/mailing/class/mailing.class.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 81f64ef6016..6d9587961c6 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -499,7 +499,7 @@ if ($object->fetch($id) >= 0) // Fix/update nbemail on emailing record if it differs (may happen if user edit lines from database directly) if (empty($asearchcriteriahasbeenset)) { - if ($nbtotalofrecords != $object->email) { + if ($nbtotalofrecords != $object->nbemail) { dol_syslog("We found a difference in nb of record in target table and the property ->nbemail, we fix ->nbemail"); //print "nbemail=".$object->nbemail." nbtotalofrecords=".$nbtotalofrecords; $resultrefresh = $object->refreshNbOfTargets(); diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index 17b5a779617..873dae1464a 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -603,12 +603,15 @@ class Mailing extends CommonObject if (! $resqlupdate) { $this->error = $this->db->lasterror(); return -1; + } else { + $this->nbemail = (int) $nbforupdate; } } } else { $this->error = $this->db->lasterror(); return -1; } + return 1; } From 8b696ced3bf5474c7f927e33054a9543e790b78b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 28 Dec 2020 12:38:33 +0100 Subject: [PATCH 22/23] Clean code --- htdocs/core/class/notify.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index f9f1c3b99ef..7cd38233eb3 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -129,7 +129,7 @@ class Notify if (is_array($listofnotiftodo)) { $i = 0; - foreach ($listofnotiftodo as $key => $val) { + foreach ($listofnotiftodo as $val) { if ($i) { $texte .= ', '; } else { From b7cd27e76a5d03be44fece88d7f91ba99660d328 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 28 Dec 2020 12:42:55 +0100 Subject: [PATCH 23/23] Fix warning --- htdocs/webservices/server_invoice.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index e1f08cbb1ca..15db912ff47 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -585,16 +585,16 @@ function createInvoice($authentication, $invoice) $newline = new FactureLigne($db); $newline->product_type = $line['type']; $newline->desc = $line['desc']; - $newline->fk_product = $line['fk_product']; - $newline->tva_tx = $line['vat_rate']; + $newline->fk_product = $line['product_id']; + $newline->tva_tx = isset($line['vat_rate']) ? $line['vat_rate'] : 0; $newline->qty = $line['qty']; - $newline->subprice = $line['unitprice']; + $newline->subprice = isset($line['unitprice']) ? $line['unitprice'] : null; $newline->total_ht = $line['total_net']; $newline->total_tva = $line['total_vat']; $newline->total_ttc = $line['total']; $newline->date_start = dol_stringtotime($line['date_start']); $newline->date_end = dol_stringtotime($line['date_end']); - $newline->fk_product = $line['product_id']; + $new_invoice->lines[] = $newline; } //var_dump($newobject->date_lim_reglement); exit;