From d0b646659591145afdf68f85898d4f0e45a468f4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 00:51:44 +0100 Subject: [PATCH 01/35] Prepare v13 packaging --- build/rpm/dolibarr_generic.spec | 1 + build/rpm/dolibarr_mandriva.spec | 1 + build/rpm/dolibarr_opensuse.spec | 1 + 3 files changed, 3 insertions(+) diff --git a/build/rpm/dolibarr_generic.spec b/build/rpm/dolibarr_generic.spec index f3c86419f8e..4541868a04f 100755 --- a/build/rpm/dolibarr_generic.spec +++ b/build/rpm/dolibarr_generic.spec @@ -292,6 +292,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/product %_datadir/dolibarr/htdocs/projet %_datadir/dolibarr/htdocs/public +%_datadir/dolibarr/htdocs/recruitment %_datadir/dolibarr/htdocs/reception %_datadir/dolibarr/htdocs/resource %_datadir/dolibarr/htdocs/salaries diff --git a/build/rpm/dolibarr_mandriva.spec b/build/rpm/dolibarr_mandriva.spec index 3c2b8adeb5b..d618b5729d5 100755 --- a/build/rpm/dolibarr_mandriva.spec +++ b/build/rpm/dolibarr_mandriva.spec @@ -209,6 +209,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/product %_datadir/dolibarr/htdocs/projet %_datadir/dolibarr/htdocs/public +%_datadir/dolibarr/htdocs/recruitment %_datadir/dolibarr/htdocs/reception %_datadir/dolibarr/htdocs/resource %_datadir/dolibarr/htdocs/salaries diff --git a/build/rpm/dolibarr_opensuse.spec b/build/rpm/dolibarr_opensuse.spec index 71db3f43445..230a8946e99 100755 --- a/build/rpm/dolibarr_opensuse.spec +++ b/build/rpm/dolibarr_opensuse.spec @@ -220,6 +220,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/product %_datadir/dolibarr/htdocs/projet %_datadir/dolibarr/htdocs/public +%_datadir/dolibarr/htdocs/recruitment %_datadir/dolibarr/htdocs/reception %_datadir/dolibarr/htdocs/resource %_datadir/dolibarr/htdocs/salaries From 88e441412c23e1efeb8208220d4f4c10ae9104b2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 01:35:59 +0100 Subject: [PATCH 02/35] CSS --- htdocs/compta/bank/various_payment/list.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/bank/various_payment/list.php b/htdocs/compta/bank/various_payment/list.php index 48da6483152..9c936c1d943 100644 --- a/htdocs/compta/bank/various_payment/list.php +++ b/htdocs/compta/bank/various_payment/list.php @@ -466,14 +466,18 @@ if ($result) // Project if ($arrayfields['project']['checked']) { - $proj->fetch($obj->fk_project); - print ''.$proj->getNomUrl(1).''; + print ''; + if ($obj->fk_project > 0) { + $proj->fetch($obj->fk_project); + print $proj->getNomUrl(1); + } + print ''; if (!$i) $totalarray['nbfield']++; } // Bank account if ($arrayfields['bank']['checked']) { - print ''; + print ''; if ($obj->bid > 0) { $accountstatic->id = $obj->bid; From e590fb36adeb3338b8a3f50d7e85d07edb846b43 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 01:53:36 +0100 Subject: [PATCH 03/35] Log for debug --- test/phpunit/RestAPIUserTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index 2bce51e2a05..979daa521b9 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -164,11 +164,11 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase print __METHOD__." Request GET url=".$url."\n"; $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); - //print __METHOD__." Result for unexisting user: ".var_export($result, true)."\n"; + print __METHOD__." result for get on unexisting user: ".var_export($result, true)."\n"; print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; $this->assertEquals($result['curl_error_no'], ''); $object=json_decode($result['content'], true); - $this->assertNotNull($object, "Parsing of json result must no be null"); + $this->assertNotNull($object, "Parsing of json result must not be null"); $this->assertEquals(404, $object['error']['code']); $url = $this->api_url.'/users/1?api_key='.$this->api_key; @@ -179,7 +179,7 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; $this->assertEquals($result['curl_error_no'], ''); $object=json_decode($result['content'], true); - $this->assertNotNull($object, "Parsing of json result must no be null"); + $this->assertNotNull($object, "Parsing of json result must not be null"); $this->assertEquals(1, $object['statut']); } @@ -222,7 +222,7 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase $body = json_encode($bodyobj); print __METHOD__." Request POST url=".$url."\n"; $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); - print __METHOD__." Result code for creating user ".var_export($result, true)."\n"; + print __METHOD__." rclsesult code for creating user ".var_export($result, true)."\n"; print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; $this->assertEquals($result['curl_error_no'], ''); $resid=json_decode($result['content'], true); From 11b15557ebcf0625e9645b61ad97176949fd3840 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 02:09:11 +0100 Subject: [PATCH 04/35] Clean code --- htdocs/user/class/api_users.class.php | 10 ++++++---- test/phpunit/RestAPIUserTest.php | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index e68ecb8bc1d..eb377b7685e 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -314,11 +314,13 @@ class Users extends DolibarrApi /** * Update account * - * @param int $id Id of account to update - * @param array $request_data Datas - * @return array + * @param int $id Id of account to update + * @param array $request_data Datas + * @return array|mixed Record after update * - * @throws RestException + * @throws RestException 401 Not allowed + * @throws RestException 404 Not found + * @throws RestException 500 System error */ public function put($id, $request_data = null) { diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index 979daa521b9..d74ecb5534f 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -169,7 +169,7 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase $this->assertEquals($result['curl_error_no'], ''); $object=json_decode($result['content'], true); $this->assertNotNull($object, "Parsing of json result must not be null"); - $this->assertEquals(404, $object['error']['code']); + $this->assertEquals(404, $object['error']['code'], 'Error code is not 404'); $url = $this->api_url.'/users/1?api_key='.$this->api_key; From 65dc7667651a41c5b50d0481e95022b19c4a7d2c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 02:12:13 +0100 Subject: [PATCH 05/35] Code comment --- htdocs/api/class/api_login.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/api/class/api_login.class.php b/htdocs/api/class/api_login.class.php index 25765e7f7e5..17d8916b9aa 100644 --- a/htdocs/api/class/api_login.class.php +++ b/htdocs/api/class/api_login.class.php @@ -48,8 +48,8 @@ class Login * @param int $reset Reset token (0=get current token, 1=ask a new token and canceled old token. This means access using current existing API token of user will fails: new token will be required for new access) * @return array Response status and user token * - * @throws RestException 403 - * @throws RestException 500 + * @throws RestException 403 Access denied + * @throws RestException 500 System error * * @url GET / * @url POST / From e9129154e448392e115b3540d5d4485802016aa4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 02:16:22 +0100 Subject: [PATCH 06/35] Log --- test/phpunit/RestAPIUserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index d74ecb5534f..d2dd8660922 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -164,7 +164,7 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase print __METHOD__." Request GET url=".$url."\n"; $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); - print __METHOD__." result for get on unexisting user: ".var_export($result, true)."\n"; + //print __METHOD__." result for get on unexisting user: ".var_export($result, true)."\n"; print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; $this->assertEquals($result['curl_error_no'], ''); $object=json_decode($result['content'], true); @@ -175,7 +175,7 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase print __METHOD__." Request GET url=".$url."\n"; $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); - //print __METHOD__." Result for existing user user: ".var_export($result, true)."\n"; + print __METHOD__." result for get on an existing user: ".var_export($result, true)."\n"; print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; $this->assertEquals($result['curl_error_no'], ''); $object=json_decode($result['content'], true); From 11a122176d2587faeab5eeb86819a789ba11e3b3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 02:33:11 +0100 Subject: [PATCH 07/35] Clean code --- htdocs/api/class/api.class.php | 2 +- htdocs/user/class/api_users.class.php | 20 ++++++++++---------- test/phpunit/RestAPIUserTest.php | 1 - 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index e101fb89602..89d170feb60 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -173,7 +173,7 @@ class DolibarrApi unset($object->name_bis); unset($object->newref); - if ($object->table_element != 'ticket') { + if (!isset($object->table_element) || $object->table_element != 'ticket') { unset($object->comments); } diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index eb377b7685e..d50fec76353 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -142,11 +142,11 @@ class Users extends DolibarrApi * Get properties of an user object * * @param int $id ID of user - * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) - * @return array|mixed data without useless information + * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) + * @return array|mixed data without useless information * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 User or group not found + * @throws RestException 401 Insufficient rights + * @throws RestException 404 User or group not found */ public function get($id, $includepermissions = 0) { @@ -177,13 +177,13 @@ class Users extends DolibarrApi * Get properties of an user object by login * * @param string $login Login of user - * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) - * @return array|mixed data without useless information + * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) + * @return array|mixed Data without useless information * * @url GET login/{login} * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 User or group not found + * @throws RestException 401 Insufficient rights + * @throws RestException 404 User or group not found */ public function getByLogin($login, $includepermissions = 0) { @@ -211,8 +211,8 @@ class Users extends DolibarrApi * Get properties of an user object by Email * * @param string $email Email of user - * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) - * @return array|mixed data without useless information + * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) + * @return array|mixed Data without useless information * * @url GET email/{email} * diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index d2dd8660922..6222f7fcaf7 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -190,7 +190,6 @@ class RestAPIUserTest extends PHPUnit\Framework\TestCase */ public function testRestCreateUser() { - // attemp to create without mandatory fields : $url = $this->api_url.'/users?api_key='.$this->api_key; $addheaders=array('Content-Type: application/json'); From ea0ae758a35cabf4715bb1f1c781cc3a8334678d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 02:48:32 +0100 Subject: [PATCH 08/35] Fix warnings --- htdocs/webservices/server_actioncomm.php | 8 ++++---- htdocs/webservices/server_contact.php | 8 ++++---- htdocs/webservices/server_order.php | 10 +++++----- htdocs/webservices/server_productorservice.php | 10 +++++----- htdocs/webservices/server_project.php | 6 +++--- htdocs/webservices/server_thirdparty.php | 10 +++++----- htdocs/webservices/server_user.php | 4 ++-- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/htdocs/webservices/server_actioncomm.php b/htdocs/webservices/server_actioncomm.php index 7864c93243f..140351e7d21 100644 --- a/htdocs/webservices/server_actioncomm.php +++ b/htdocs/webservices/server_actioncomm.php @@ -122,7 +122,7 @@ $extrafield_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) +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) { @@ -315,7 +315,7 @@ function getActionComm($authentication, $id) //Get extrafield values $actioncomm->fetch_optionals(); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -454,7 +454,7 @@ function createActionComm($authentication, $actioncomm) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -551,7 +551,7 @@ function updateActionComm($authentication, $actioncomm) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index 9abc7b6088f..6fc521a43c7 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -127,7 +127,7 @@ $extrafield_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) +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) { @@ -319,7 +319,7 @@ function getContact($authentication, $id, $ref_ext) //Get extrafield values $contact->fetch_optionals(); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -424,7 +424,7 @@ function createContact($authentication, $contact) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -671,7 +671,7 @@ function updateContact($authentication, $contact) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 62e8dc99d72..30c105d7192 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -120,7 +120,7 @@ $extrafield_line_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_line_array = array(); } -if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) +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) { @@ -224,7 +224,7 @@ $extrafield_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) +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) { @@ -705,7 +705,7 @@ function createOrder($authentication, $order) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -743,7 +743,7 @@ function createOrder($authentication, $order) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -948,7 +948,7 @@ function updateOrder($authentication, $order) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index f723dcfd054..f285d245030 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -142,7 +142,7 @@ $extrafield_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) +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) { @@ -436,7 +436,7 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' //Get extrafield values $product->fetch_optionals(); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -563,7 +563,7 @@ function createProductOrService($authentication, $product) $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -719,7 +719,7 @@ function updateProductOrService($authentication, $product) $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -1090,7 +1090,7 @@ function getProductsForCategory($authentication, $id, $lang = '') //Get extrafield values $tmpproduct->fetch_optionals(); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { diff --git a/htdocs/webservices/server_project.php b/htdocs/webservices/server_project.php index 9d4c93c9ce9..0817332c09f 100644 --- a/htdocs/webservices/server_project.php +++ b/htdocs/webservices/server_project.php @@ -169,7 +169,7 @@ $extrafield_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) +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) { @@ -277,7 +277,7 @@ function createProject($authentication, $project) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -386,7 +386,7 @@ function getProject($authentication, $id = '', $ref = '') $extrafields->fetch_name_optionals_label($elementtype, true); //Get extrafield values - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 3a1e911f510..5bde94cc0d5 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -130,7 +130,7 @@ $extrafield_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) +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) { @@ -365,7 +365,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') //Get extrafield values $thirdparty->fetch_optionals(); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -481,7 +481,7 @@ function createThirdParty($authentication, $thirdparty) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -615,7 +615,7 @@ function updateThirdParty($authentication, $thirdparty) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { @@ -723,7 +723,7 @@ function getListOfThirdParties($authentication, $filterthirdparty) $extrafieldsOptions = array(); $obj = $db->fetch_object($resql); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 6f7ed5c10aa..25cb2324412 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -193,7 +193,7 @@ $extrafield_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) +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) { @@ -599,7 +599,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) + 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) { From 3586da75a2c38d5ed74a551b6d02994d3019d786 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 02:52:49 +0100 Subject: [PATCH 09/35] Fix warning --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index dd80c660e71..884d8eac496 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4461,7 +4461,7 @@ function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '', $savlimit = $limit; $savtotalnboflines = $totalnboflines; - $totalnboflines = abs($totalnboflines); + $totalnboflines = abs((int) $totalnboflines); if ($picto == 'setup') $picto = 'title_setup.png'; if (($conf->browser->name == 'ie') && $picto == 'generic') $picto = 'title.gif'; From 6c2a17b29ad629bc7922c1ee1891d8cda44026aa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 02:59:00 +0100 Subject: [PATCH 10/35] Fix warning --- htdocs/contrat/list.php | 6 +++--- htdocs/core/class/notify.class.php | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index d273dd7cdf7..72a8ec2974d 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -614,14 +614,14 @@ while ($i < min($num, $limit)) $socstatic->logo = $obj->logo; $socstatic->country_id = $obj->country_id; $socstatic->country_code = ''; - $socstatic->country_label = '';*/ + $socstatic->country = '';*/ if ($obj->country_id > 0) { if (!isset($cacheCountryIDCode[$obj->country_id]['code'])) { $tmparray = getCountry($obj->country_id, 'all'); $cacheCountryIDCode[$obj->country_id] = array('code'=> empty($tmparray['code']) ? '' : $tmparray['code'], 'label' => empty($tmparray['label']) ? '' : $tmparray['label']); } $socstatic->country_code = $cacheCountryIDCode[$obj->country_id]['code']; - $socstatic->country_label = $cacheCountryIDCode[$obj->country_id]['label']; + $socstatic->country = $cacheCountryIDCode[$obj->country_id]['label']; } @@ -695,7 +695,7 @@ while ($i < min($num, $limit)) if (!empty($arrayfields['country.code_iso']['checked'])) { print ''; - print $socstatic->country_label; + print $socstatic->country; print ''; if (!$i) $totalarray['nbfield']++; } diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 6f60f6cdca6..f9f1c3b99ef 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -112,6 +112,7 @@ class Notify $listofnotiftodo = $this->getNotificationsArray($action, $socid, $object, 0); + $texte = ''; $nb = -1; if (is_array($listofnotiftodo)) { $nb = count($listofnotiftodo); @@ -170,6 +171,8 @@ class Notify if (is_object($object)) { $valueforthreshold = $object->total_ht; } + + $sqlnotifcode = ''; if ($notifcode) { if (is_numeric($notifcode)) { $sqlnotifcode = " AND n.fk_action = ".$notifcode; // Old usage From 5ef3ffbdc63e7fdeaab4e203f110c535c5cd99e0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 03:03:38 +0100 Subject: [PATCH 11/35] Fix warning --- htdocs/core/class/utils.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index 93eaeb6d4f2..07b67e30062 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -168,7 +168,7 @@ class Utils $this->output = $langs->trans("PurgeNDirectoriesDeleted", $countdeleted); if ($count > $countdeleted) $this->output .= '
'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted)); } else { - $this->output = $langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)' : ''); + $this->output = $langs->trans("PurgeNothingToDelete").(in_array('tempfilesold', $choicesarray) ? ' (older than 24h for temp files)' : ''); } // Recreate temp dir that are not automatically recreated by core code for performance purpose, we need them From a0440fbe8841a8a6b2582f2e10cab928bb85ba8a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 03:06:52 +0100 Subject: [PATCH 12/35] Removed warnings --- htdocs/core/boxes/box_funnel_of_prospection.php | 4 ++-- htdocs/core/boxes/modules_boxes.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index 6ffce6d781b..5b6130d8eb2 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -61,9 +61,9 @@ class box_funnel_of_prospection extends ModeleBoxes $this->db = $db; - $this->enabled = ($conf->global->MAIN_FEATURES_LEVEL >= 1); // Not enabled by default, still need some work + $this->enabled = ($conf->global->MAIN_FEATURES_LEVEL >= 1 ? 1 : 0); // Not enabled by default, still need some work - $this->hidden = !($user->rights->projet->lire); + $this->hidden = empty($user->rights->projet->lire); } /** diff --git a/htdocs/core/boxes/modules_boxes.php b/htdocs/core/boxes/modules_boxes.php index 1e32a28f25c..9faf45932e2 100644 --- a/htdocs/core/boxes/modules_boxes.php +++ b/htdocs/core/boxes/modules_boxes.php @@ -56,7 +56,7 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" box /** * @var boolean Condition to have widget visible (in most cases, permissions) */ - public $hidden = 0; + public $hidden = false; /** * @var int Box definition database ID From 360a85cbbc76b26634578081254f68ea02150e0b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 12:32:34 +0100 Subject: [PATCH 13/35] FIX add autofix of count of email target when data is corrupted --- htdocs/comm/mailing/cibles.php | 38 ++++++++++++++++++--- htdocs/comm/mailing/class/mailing.class.php | 34 ++++++++++++++++++ 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index d8d9873b88b..8bfa82260b9 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -481,11 +481,27 @@ if ($object->fetch($id) >= 0) $sql .= " mc.source_url, mc.source_id, mc.source_type, mc.error_text"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; $sql .= " WHERE mc.fk_mailing=".$object->id; - if ($search_lastname) $sql .= natural_search("mc.lastname", $search_lastname); - if ($search_firstname) $sql .= natural_search("mc.firstname", $search_firstname); - if ($search_email) $sql .= natural_search("mc.email", $search_email); - if ($search_other) $sql .= natural_search("mc.other", $search_other); - if ($search_dest_status != '' && $search_dest_status >= -1) $sql .= " AND mc.statut=".$db->escape($search_dest_status)." "; + $asearchcriteriahasbeenset = 0; + if ($search_lastname) { + $sql .= natural_search("mc.lastname", $search_lastname); + $asearchcriteriahasbeenset++; + } + if ($search_firstname) { + $sql .= natural_search("mc.firstname", $search_firstname); + $asearchcriteriahasbeenset++; + } + if ($search_email) { + $sql .= natural_search("mc.email", $search_email); + $asearchcriteriahasbeenset++; + } + if ($search_other) { + $sql .= natural_search("mc.other", $search_other); + $asearchcriteriahasbeenset++; + } + if ($search_dest_status != '' && $search_dest_status >= -1) { + $sql .= " AND mc.statut=".$db->escape($search_dest_status)." "; + $asearchcriteriahasbeenset++; + } $sql .= $db->order($sortfield, $sortorder); // Count total nb of records @@ -499,6 +515,18 @@ if ($object->fetch($id) >= 0) $page = 0; $offset = 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) { + 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(); + if ($resultrefresh < 0) { + dol_print_error($db, $object->error, $object->errors); + } + } + } } //$nbtotalofrecords=$object->nbemail; // nbemail is a denormalized field storing nb of targets diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index 56a115a2fea..75efe1f07b2 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -461,6 +461,8 @@ class Mailing extends CommonObject $resql = $this->db->query($sql); if ($resql) { + $this->refreshNbOfTargets(); + return 1; } else @@ -532,6 +534,38 @@ class Mailing extends CommonObject return 0; } + /** + * Refresh denormalized value ->nbemail into emailing record + * Note: There is also the method update_nb into modules_mailings that is used for this. + * + * @return int <0 if KO, >0 if OK + */ + public function refreshNbOfTargets() + { + $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles"; + $sql .= " WHERE fk_mailing = ".$this->id; + + $resql = $this->db->query($sql); + if ($resql) { + $obj = $this->db->fetch_object($resql); + if ($obj) { + $nbforupdate = $obj->nb; + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'mailing SET nbemail = '.((int) $nbforupdate); + $sql .= ' WHERE rowid = '.$this->id; + + $resqlupdate = $this->db->query($sql); + if (! $resqlupdate) { + $this->error = $this->db->lasterror(); + return -1; + } + } + } else { + $this->error = $this->db->lasterror(); + return -1; + } + return 1; + } /** * Return a link to the object card (with optionally the picto) From 739695c442e40960dc5435c7033853419d7de3f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 12:49:17 +0100 Subject: [PATCH 14/35] Fix delay to wait between email for emailing refused float. --- htdocs/admin/mailing.php | 2 +- htdocs/comm/mailing/card.php | 2 +- scripts/emailings/mailing-send.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/mailing.php b/htdocs/admin/mailing.php index 921a4a6338c..6e3341dcd8f 100644 --- a/htdocs/admin/mailing.php +++ b/htdocs/admin/mailing.php @@ -125,7 +125,7 @@ print ''; print ''; print $langs->trans("MailingDelay").''; -print ''; +print ''; print ''; diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index e3cb5a9ad97..80692c1384d 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -346,7 +346,7 @@ if (empty($reshook)) if (!empty($conf->global->MAILING_DELAY)) { dol_syslog("Wait a delay of MAILING_DELAY=".$conf->global->MAILING_DELAY); - sleep($conf->global->MAILING_DELAY); + usleep((float) $conf->global->MAILING_DELAY * 1000000); } //test if CHECK READ change statut prospect contact diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index bc7efec7dba..0118697e5ec 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -318,7 +318,7 @@ if ($resql) { } if (!empty($conf->global->MAILING_DELAY)) { - sleep($conf->global->MAILING_DELAY); + usleep((float) $conf->global->MAILING_DELAY * 1000000); } } } else { From 3abceadb86445c021bac43139d5295f8f74adaf6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 24 Dec 2020 13:02:45 +0100 Subject: [PATCH 15/35] Add info --- scripts/emailings/mailing-send.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 0118697e5ec..5f93600f1be 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -60,6 +60,10 @@ $error = 0; @set_time_limit(0); print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; +if (!empty($conf->global->MAILING_DELAY)) { + print 'A delay of '.((float) $conf->global->MAILING_DELAY * 1000000).' millisecond has been set between each email'."\n"; +} + if ($conf->global->MAILING_LIMIT_SENDBYCLI == '-1') {} $user = new User($db); From 11146a0b66a1d4986b18c0765aa8314a75ffa7c8 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 25 Dec 2020 11:01:19 +0100 Subject: [PATCH 16/35] 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 17/35] 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 18/35] 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 19/35] 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 20/35] 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 21/35] 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 22/35] 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 23/35] 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 24/35] 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 25/35] 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 26/35] 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 27/35] 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 28/35] 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 29/35] 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 30/35] 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 31/35] 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 32/35] 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 33/35] 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 34/35] 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 35/35] 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;