From f620b165d3b87d4c7f25c495375cd2e613ce11cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Fri, 15 Nov 2019 22:17:53 +0100 Subject: [PATCH 01/44] API New get / add / remove product childs --- htdocs/product/class/api_products.class.php | 136 ++++++++++++++++++-- 1 file changed, 127 insertions(+), 9 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index f9a4a12b0df..c2f61604cd9 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -66,15 +66,16 @@ class Products extends DolibarrApi * * @param int $id ID of product * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesousproduits Load information about virtual product components * @return array|mixed Data without useless information * * @throws 401 * @throws 403 * @throws 404 */ - public function get($id, $includestockdata = 0) + public function get($id, $includestockdata = 0, $includesousproduits = false) { - return $this->_fetch($id, '', '', '', $includestockdata); + return $this->_fetch($id, '', '', '', $includestockdata, $includesousproduits); } /** @@ -84,6 +85,7 @@ class Products extends DolibarrApi * * @param string $ref Ref of element * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesousproduits Load information about virtual product components * * @return array|mixed Data without useless information * @@ -93,9 +95,9 @@ class Products extends DolibarrApi * @throws 403 * @throws 404 */ - public function getByRef($ref, $includestockdata = 0) + public function getByRef($ref, $includestockdata = 0, $includesousproduits = false) { - return $this->_fetch('', $ref, '', '', $includestockdata); + return $this->_fetch('', $ref, '', '', $includestockdata, $includesousproduits); } /** @@ -105,6 +107,7 @@ class Products extends DolibarrApi * * @param string $ref_ext Ref_ext of element * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesousproduits Load information about virtual product components * * @return array|mixed Data without useless information * @@ -114,9 +117,9 @@ class Products extends DolibarrApi * @throws 403 * @throws 404 */ - public function getByRefExt($ref_ext, $includestockdata = 0) + public function getByRefExt($ref_ext, $includestockdata = 0, $includesousproduits = false) { - return $this->_fetch('', '', $ref_ext, '', $includestockdata); + return $this->_fetch('', '', $ref_ext, '', $includestockdata, $includesousproduits); } /** @@ -126,6 +129,7 @@ class Products extends DolibarrApi * * @param string $barcode Barcode of element * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesousproduits Load information about virtual product components * * @return array|mixed Data without useless information * @@ -135,9 +139,9 @@ class Products extends DolibarrApi * @throws 403 * @throws 404 */ - public function getByBarcode($barcode, $includestockdata = 0) + public function getByBarcode($barcode, $includestockdata = 0, $includesousproduits = false) { - return $this->_fetch('', '', '', $barcode, $includestockdata); + return $this->_fetch('', '', '', $barcode, $includestockdata, $includesousproduits); } /** @@ -369,6 +373,105 @@ class Products extends DolibarrApi return $this->product->delete(DolibarrApiAccess::$user); } + + /** + * Get the list of children of the product. + * + * @param int $id Id of parent product/service + * @return array + * + * @throws RestException + * @throws 401 + * @throws 404 + * + * @url GET {id}/childs + */ + public function getChilds($id) + { + if(! DolibarrApiAccess::$user->rights->produit->lire) { + throw new RestException(401); + } + + if(! DolibarrApi::_checkAccessToResource('product', $id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $childsArbo = $this->product->getChildsArbo($id, 1); + + $keys = ['rowid', 'qty', 'fk_product_type', 'label', 'incdec']; + $childs = []; + foreach ($childsArbo as $values) { + $childs[] = array_combine($keys, $values); + } + + return $childs; + } + + /** + * Add product child. + * + * Link a product/service to a parent product/service + * + * @param int $id Id of parent product/service + * @param int $id_fils Id of child product/service + * @param int $qty Quantity + * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease + * @return int + * + * @throws RestException + * @throws 401 + * @throws 404 + * + * @url POST {id}/childs/add + */ + public function addChild($id, $child_id, $qty, $incdec = 1) + { + if(! DolibarrApiAccess::$user->rights->produit->creer) { + throw new RestException(401); + } + + if(! DolibarrApi::_checkAccessToResource('product', $id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->product->add_sousproduit($id, $child_id, $qty, $incdec); + if ($result <= 0) { + throw new RestException(500, "Error adding product child"); + } + return $result; + } + + /** + * Remove product child. + * + * Unlink a product/service from a parent product/service + * + * @param int $id Id of parent product/service + * @param int $child_id Id of child product/service + * @return int + * + * @throws RestException + * @throws 401 + * @throws 404 + * + * @url DELETE {id}/childs/remove + */ + public function delChild($id, $child_id) + { + if(! DolibarrApiAccess::$user->rights->produit->creer) { + throw new RestException(401); + } + + if(! DolibarrApi::_checkAccessToResource('product', $id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->product->del_sousproduit($id, $child_id); + if ($result <= 0) { + throw new RestException(500, "Error while removing product child"); + } + return $result; + } /** @@ -753,13 +856,14 @@ class Products extends DolibarrApi * @param string $ref_ext Ref ext of element * @param string $barcode Barcode of element * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesousproduits Load information about virtual product components * @return array|mixed Data without useless information * * @throws 401 * @throws 403 * @throws 404 */ - private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0) + private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesousproduits = false) { if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) { throw new RestException(400, 'bad value for parameter id, ref, ref_ext or barcode'); @@ -783,6 +887,20 @@ class Products extends DolibarrApi if ($includestockdata) { $this->product->load_stock(); } + + + + if ($includesousproduits) { + $childsArbo = $this->product->getChildsArbo($id, 1); + + $keys = ['rowid', 'qty', 'fk_product_type', 'label', 'incdec']; + $childs = []; + foreach ($childsArbo as $values) { + $childs[] = array_combine($keys, $values); + } + + $this->product->sousprods = $childs; + } return $this->_cleanObjectDatas($this->product); } From aa7353d3cf25020b627fc7434a2defe5e9e6a67c Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 15 Nov 2019 21:18:40 +0000 Subject: [PATCH 02/44] Fixing style errors. --- htdocs/product/class/api_products.class.php | 36 ++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index c2f61604cd9..1ec1479f24c 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -373,7 +373,7 @@ class Products extends DolibarrApi return $this->product->delete(DolibarrApiAccess::$user); } - + /** * Get the list of children of the product. * @@ -391,22 +391,22 @@ class Products extends DolibarrApi if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } - + if(! DolibarrApi::_checkAccessToResource('product', $id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + $childsArbo = $this->product->getChildsArbo($id, 1); - + $keys = ['rowid', 'qty', 'fk_product_type', 'label', 'incdec']; $childs = []; foreach ($childsArbo as $values) { $childs[] = array_combine($keys, $values); } - + return $childs; } - + /** * Add product child. * @@ -421,26 +421,26 @@ class Products extends DolibarrApi * @throws RestException * @throws 401 * @throws 404 - * + * * @url POST {id}/childs/add */ public function addChild($id, $child_id, $qty, $incdec = 1) - { + { if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } - + if(! DolibarrApi::_checkAccessToResource('product', $id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + $result = $this->product->add_sousproduit($id, $child_id, $qty, $incdec); if ($result <= 0) { throw new RestException(500, "Error adding product child"); } return $result; } - + /** * Remove product child. * @@ -461,11 +461,11 @@ class Products extends DolibarrApi if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } - + if(! DolibarrApi::_checkAccessToResource('product', $id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + $result = $this->product->del_sousproduit($id, $child_id); if ($result <= 0) { throw new RestException(500, "Error while removing product child"); @@ -887,18 +887,18 @@ class Products extends DolibarrApi if ($includestockdata) { $this->product->load_stock(); } - - - + + + if ($includesousproduits) { $childsArbo = $this->product->getChildsArbo($id, 1); - + $keys = ['rowid', 'qty', 'fk_product_type', 'label', 'incdec']; $childs = []; foreach ($childsArbo as $values) { $childs[] = array_combine($keys, $values); } - + $this->product->sousprods = $childs; } From 04f58f5d32e7b9b4e82c7db4949478b2a4021731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 16 Nov 2019 11:17:56 +0100 Subject: [PATCH 03/44] $includesubproducts and path consistency --- htdocs/product/class/api_products.class.php | 64 ++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 1ec1479f24c..ccfe8f1acf9 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -64,18 +64,18 @@ class Products extends DolibarrApi * * Return an array with product information. * - * @param int $id ID of product - * @param int $includestockdata Load also information about stock (slower) - * @param bool $includesousproduits Load information about virtual product components + * @param int $id ID of product + * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesubproducts Load information about subproducts * @return array|mixed Data without useless information * * @throws 401 * @throws 403 * @throws 404 */ - public function get($id, $includestockdata = 0, $includesousproduits = false) + public function get($id, $includestockdata = 0, $includesubproducts = false) { - return $this->_fetch($id, '', '', '', $includestockdata, $includesousproduits); + return $this->_fetch($id, '', '', '', $includestockdata, $includesubproducts); } /** @@ -83,21 +83,21 @@ class Products extends DolibarrApi * * Return an array with product information. * - * @param string $ref Ref of element - * @param int $includestockdata Load also information about stock (slower) - * @param bool $includesousproduits Load information about virtual product components + * @param string $ref Ref of element + * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesubproducts Load information about subproducts * * @return array|mixed Data without useless information * - * @url GET byRef/{ref} + * @url GET ref/{ref} * * @throws 401 * @throws 403 * @throws 404 */ - public function getByRef($ref, $includestockdata = 0, $includesousproduits = false) + public function getByRef($ref, $includestockdata = 0, $includesubproducts = false) { - return $this->_fetch('', $ref, '', '', $includestockdata, $includesousproduits); + return $this->_fetch('', $ref, '', '', $includestockdata, $includesubproducts); } /** @@ -105,21 +105,21 @@ class Products extends DolibarrApi * * Return an array with product information. * - * @param string $ref_ext Ref_ext of element - * @param int $includestockdata Load also information about stock (slower) - * @param bool $includesousproduits Load information about virtual product components + * @param string $ref_ext Ref_ext of element + * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesubproducts Load information about subproducts * * @return array|mixed Data without useless information * - * @url GET byRefExt/{ref_ext} + * @url GET ref_ext/{ref_ext} * * @throws 401 * @throws 403 * @throws 404 */ - public function getByRefExt($ref_ext, $includestockdata = 0, $includesousproduits = false) + public function getByRefExt($ref_ext, $includestockdata = 0, $includesubproducts = false) { - return $this->_fetch('', '', $ref_ext, '', $includestockdata, $includesousproduits); + return $this->_fetch('', '', $ref_ext, '', $includestockdata, $includesubproducts); } /** @@ -127,21 +127,21 @@ class Products extends DolibarrApi * * Return an array with product information. * - * @param string $barcode Barcode of element - * @param int $includestockdata Load also information about stock (slower) - * @param bool $includesousproduits Load information about virtual product components + * @param string $barcode Barcode of element + * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesubproducts Load information about subproducts * * @return array|mixed Data without useless information * - * @url GET byBarcode/{barcode} + * @url GET barcode/{barcode} * * @throws 401 * @throws 403 * @throws 404 */ - public function getByBarcode($barcode, $includestockdata = 0, $includesousproduits = false) + public function getByBarcode($barcode, $includestockdata = 0, $includesubproducts = false) { - return $this->_fetch('', '', '', $barcode, $includestockdata, $includesousproduits); + return $this->_fetch('', '', '', $barcode, $includestockdata, $includesubproducts); } /** @@ -851,19 +851,19 @@ class Products extends DolibarrApi * * Return an array with product information. * - * @param int $id ID of product - * @param string $ref Ref of element - * @param string $ref_ext Ref ext of element - * @param string $barcode Barcode of element - * @param int $includestockdata Load also information about stock (slower) - * @param bool $includesousproduits Load information about virtual product components - * @return array|mixed Data without useless information + * @param int $id ID of product + * @param string $ref Ref of element + * @param string $ref_ext Ref ext of element + * @param string $barcode Barcode of element + * @param int $includestockdata Load also information about stock (slower) + * @param bool $includesubproducts Load information about subproducts + * @return array|mixed Data without useless information * * @throws 401 * @throws 403 * @throws 404 */ - private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesousproduits = false) + private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesubproducts = false) { if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) { throw new RestException(400, 'bad value for parameter id, ref, ref_ext or barcode'); @@ -890,7 +890,7 @@ class Products extends DolibarrApi - if ($includesousproduits) { + if ($includesubproducts) { $childsArbo = $this->product->getChildsArbo($id, 1); $keys = ['rowid', 'qty', 'fk_product_type', 'label', 'incdec']; From 33d4c4b73cd09a064612438f9b3a1c07dad4379c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 16 Nov 2019 11:23:50 +0100 Subject: [PATCH 04/44] Doc for $child_id --- htdocs/product/class/api_products.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index ccfe8f1acf9..06cf17ea66b 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -412,10 +412,10 @@ class Products extends DolibarrApi * * Link a product/service to a parent product/service * - * @param int $id Id of parent product/service - * @param int $id_fils Id of child product/service - * @param int $qty Quantity - * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease + * @param int $id Id of parent product/service + * @param int $child_id Id of child product/service + * @param int $qty Quantity + * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease * @return int * * @throws RestException From 256e256f62c00a8b0cdaff829a045f704833a960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 16 Nov 2019 12:30:47 +0100 Subject: [PATCH 05/44] Paths and vars: subproducts instead of childs --- htdocs/product/class/api_products.class.php | 34 ++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 06cf17ea66b..58d53583645 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -375,7 +375,7 @@ class Products extends DolibarrApi } /** - * Get the list of children of the product. + * Get the list of subproducts of the product. * * @param int $id Id of parent product/service * @return array @@ -384,9 +384,9 @@ class Products extends DolibarrApi * @throws 401 * @throws 404 * - * @url GET {id}/childs + * @url GET {id}/subproducts */ - public function getChilds($id) + public function getSubproducts($id) { if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); @@ -408,23 +408,23 @@ class Products extends DolibarrApi } /** - * Add product child. + * Add subproduct. * * Link a product/service to a parent product/service * - * @param int $id Id of parent product/service - * @param int $child_id Id of child product/service - * @param int $qty Quantity - * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease + * @param int $id Id of parent product/service + * @param int $subproduct_id Id of child product/service + * @param int $qty Quantity + * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease * @return int * * @throws RestException * @throws 401 * @throws 404 * - * @url POST {id}/childs/add + * @url POST {id}/subproducts/add */ - public function addChild($id, $child_id, $qty, $incdec = 1) + public function addSubproducts($id, $subproduct_id, $qty, $incdec = 1) { if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); @@ -434,7 +434,7 @@ class Products extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->product->add_sousproduit($id, $child_id, $qty, $incdec); + $result = $this->product->add_sousproduit($id, $subproduct_id, $qty, $incdec); if ($result <= 0) { throw new RestException(500, "Error adding product child"); } @@ -442,21 +442,21 @@ class Products extends DolibarrApi } /** - * Remove product child. + * Remove subproduct. * * Unlink a product/service from a parent product/service * - * @param int $id Id of parent product/service - * @param int $child_id Id of child product/service + * @param int $id Id of parent product/service + * @param int $subproduct_id Id of child product/service * @return int * * @throws RestException * @throws 401 * @throws 404 * - * @url DELETE {id}/childs/remove + * @url DELETE {id}/subproducts/remove */ - public function delChild($id, $child_id) + public function delSubproducts($id, $subproduct_id) { if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); @@ -466,7 +466,7 @@ class Products extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->product->del_sousproduit($id, $child_id); + $result = $this->product->del_sousproduit($id, $subproduct_id); if ($result <= 0) { throw new RestException(500, "Error while removing product child"); } From 8c057f1975d07aaa1b1c14dd506196bd07932361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sun, 17 Nov 2019 01:20:15 +0100 Subject: [PATCH 06/44] API New Product variants --- htdocs/product/class/api_products.class.php | 546 ++++++++++++++++++++ 1 file changed, 546 insertions(+) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 58d53583645..e3fb4d6079c 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -21,6 +21,10 @@ use Luracast\Restler\RestException; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; +require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php'; +require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php'; +require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php'; /** * API class for products @@ -798,6 +802,548 @@ class Products extends DolibarrApi return $this->_cleanObjectDatas($this->productsupplier); } + + /** + * Get attributes. + * + * @return array + * + * @throws RestException + * + * @url GET attributes + */ + public function getAttributes() + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $prodattr = new ProductAttribute($this->db); + return $prodattr->fetchAll(); + } + + /** + * Get attribute by ID. + * + * @param int $id ID of Attribute + * @return array + * + * @throws RestException + * @throws 401 + * @throws 404 + * + * @url GET attributes/{id} + */ + public function getAttributeById($id) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $prodattr = new ProductAttribute($this->db); + $result = $prodattr->fetch((int) $id); + + if($result < 0) { + throw new RestException(404, "Attribute not found"); + } + + return $prodattr; + } + + /** + * Add attributes. + * + * @param string $ref Reference of Attribute + * @param string $label Label of Attribute + * @return int + * + * @throws RestException + * @throws 401 + * + * @url POST attributes + */ + public function addAttributes($ref, $label) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $prodattr = new ProductAttribute($this->db); + $prodattr->label = $label; + $prodattr->ref = $ref; + + $resid = $prodattr->create(DolibarrApiAccess::$user); + if ($resid <= 0) { + throw new RestException(500, "Error creating new attribute"); + } + return $resid; + } + + /** + * Update attributes by id. + * + * @param int $id ID of Attribute + * @param string $ref Reference of Attribute + * @param string $label Label of Attribute + * @return int + * + * @throws RestException + * @throws 401 + * @throws 404 + * + * @url PUT attributes/{id} + */ + public function putAttributes($id, $ref, $label) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $prodattr = new ProductAttribute($this->db); + + $result = $prodattr->fetch((int) $id); + if ($result == 0) { + throw new RestException(404, 'Attribute not found'); + } elseif ($result < 0) { + throw new RestException(500, "Error fetching attribute"); + } + + + $prodattr->label = $label; + $prodattr->ref = $ref; + + if ($prodattr->update(DolibarrApiAccess::$user) > 0) { + return 1; + } + throw new RestException(500, "Error updating attribute"); + } + + /** + * Delete attributes by id. + * + * @param int $id ID of Attribute + * @return int + * + * @throws RestException + * @throws 401 + * + * @url DELETE attributes/{id} + */ + public function deleteAttributes($id) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $prodattr = new ProductAttribute($this->db); + $prodattr->id = (int) $id; + $result = $prodattr->delete(); + + if ($result > 0) { + return 1; + } + throw new RestException(500, "Error deleting attribute"); + } + + /** + * Delete attributes by ref. + * + * @param string $ref Reference of Attribute + * @return int + * + * @throws RestException + * @throws 401 + * + * @url DELETE attributes/ref/{ref} + */ + public function deleteAttributesByRef($ref) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". trim($ref) ."'"; + + if ($this->db->query($sql)) { + return 1; + } + throw new RestException(500, "Error deleting attribute"); + } + + /** + * Get all values for an attribute id. + * + * @param int $id ID of an Attribute + * @return array + * + * @throws RestException + * @throws 401 + * + * @url GET attributes/{id}/values + */ + public function getAttributeValues($id) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $objectval = new ProductAttributeValue($this->db); + return $objectval->fetchAllByProductAttribute((int) $id); + } + + /** + * Get all values for an attribute ref. + * + * @param string $ref Ref of an Attribute + * @return array + * + * @throws RestException + * @throws 401 + * + * @url GET attributes/ref/{ref}/values + */ + public function getAttributeValuesByRef($ref) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $return = array(); + + $sql = 'SELECT '; + $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value v '; + $sql .= "WHERE v.fk_product_attribute = ( SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". strtoupper(trim($ref)) ."' LIMIT 1)"; + + $query = $this->db->query($sql); + + while ($result = $this->db->fetch_object($query)) { + $tmp = new ProductAttributeValue($this->db); + $tmp->fk_product_attribute = $result->fk_product_attribute; + $tmp->id = $result->rowid; + $tmp->ref = $result->ref; + $tmp->value = $result->value; + + $return[] = $tmp; + } + + return $return; + } + + /** + * Add attribute value. + * + * @param int $id ID of Attribute + * @param string $ref Reference of Attribute value + * @param string $value Value of Attribute value + * @return int + * + * @throws RestException + * @throws 401 + * + * @url POST attributes/{id}/values + */ + public function addAttributeValue($id, $ref, $value) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + if (empty($ref) || empty($value)) { + throw new RestException(401); + } + + $objectval = new ProductAttributeValue($this->db); + $objectval->fk_product_attribute = $id; + $objectval->ref = $ref; + $objectval->value = $value; + + if ($objectval->create(DolibarrApiAccess::$user) > 0) { + return $objectval->id; + } + throw new RestException(500, "Error creating new attribute value"); + } + + /** + * Delete attribute value by id. + * + * @param int $id ID of Attribute value + * @return int + * + * @throws RestException + * @throws 401 + * + * @url DELETE attributes/values/{id} + */ + public function deleteAttributeValueById($id) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $objectval = new ProductAttributeValue($this->db); + $objectval->id = (int) $id; + + if ($objectval->delete() > 0) { + return 1; + } + throw new RestException(500, "Error deleting attribute value"); + } + + /** + * Delete attribute value by ref. + * + * @param string $ref Ref of Attribute value + * @return int + * + * @throws RestException + * @throws 401 + * + * @url DELETE attributes/values/ref/{ref} + */ + public function deleteAttributeValueByRef($ref) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE ref LIKE '". trim($ref) ."'"; + + if ($this->db->query($sql)) { + return 1; + } + + throw new RestException(500, "Error deleting attribute value"); + } + + /** + * Get product variants. + * + * @param int $id ID of Product + * @return array + * + * @throws RestException + * @throws 401 + * + * @url GET {id}/variants + */ + public function getVariants($id) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $prodcomb = new ProductCombination($this->db); + return $prodcomb->fetchAllByFkProductParent((int) $id); + } + + /** + * Get product variants by Product ref. + * + * @param string $ref Ref of Product + * @return array + * + * @throws RestException + * @throws 401 + * + * @url GET ref/{ref}/variants + */ + public function getVariantsByProdRef($ref) + { + if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $result = $this->product->fetch('', $ref); + if(! $result ) { + throw new RestException(404, 'Product not found'); + } + + $prodcomb = new ProductCombination($this->db); + return $prodcomb->fetchAllByFkProductParent((int) $this->product->id); + } + + /** + * Add variant. + * + * "features" is a list of attributes pairs id_attribute=>id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...) + * + * @param int $id ID of Product + * @param float $weight_impact Weight impact of variant + * @param float $price_impact Price impact of variant + * @param bool $price_impact_is_percent Price impact in percent (true or false) + * @param array $features List of attributes pairs id_attribute->id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...) + * @return int + * + * @throws RestException + * @throws 401 + * @throws 404 + * + * @url POST {id}/variants + */ + public function addVariant($id, $weight_impact, $price_impact, $price_impact_is_percent, $features) + { + if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { + throw new RestException(401); + } + + if (empty($id) || empty($weight_impact) || empty($price_impact) || empty($features) || !is_array($features)) { + throw new RestException(401); + } + + $prodattr = new ProductAttribute($this->db); + $prodattr_val = new ProductAttributeValue($this->db); + foreach ($features as $id_attr => $id_value) { + if ($prodattr->fetch((int) $id_attr) < 0) { + throw new RestException(401); + } + if ($prodattr_val->fetch((int) $id_value) < 0) { + throw new RestException(401); + } + } + + $result = $this->product->fetch((int) $id); + if(! $result ) { + throw new RestException(404, 'Product not found'); + } + + $prodcomb = new ProductCombination($this->db); + if (! $prodcomb->fetchByProductCombination2ValuePairs($id, $features)) + { + $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact); + if ($result > 0) + { + return $result; + } else { + throw new RestException(500, "Error creating new product variant"); + } + } else { + return $prodcomb->id; + } + } + + /** + * Add variant by product ref. + * + * "features" is a list of attributes pairs id_attribute=>id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...) + * + * @param string $ref Ref of Product + * @param float $weight_impact Weight impact of variant + * @param float $price_impact Price impact of variant + * @param bool $price_impact_is_percent Price impact in percent (true or false) + * @param array $features List of attributes pairs id_attribute->id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...) + * @return int + * + * @throws RestException + * @throws 401 + * @throws 404 + * + * @url POST ref/{ref}/variants + */ + public function addVariantByProductRef($ref, $weight_impact, $price_impact, $price_impact_is_percent, $features) + { + if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { + throw new RestException(401); + } + + if (empty($ref) || empty($weight_impact) || empty($price_impact) || empty($features) || !is_array($features)) { + throw new RestException(401); + } + + $prodattr = new ProductAttribute($this->db); + $prodattr_val = new ProductAttributeValue($this->db); + foreach ($features as $id_attr => $id_value) { + if ($prodattr->fetch((int) $id_attr) < 0) { + throw new RestException(404); + } + if ($prodattr_val->fetch((int) $id_value) < 0) { + throw new RestException(404); + } + } + + $result = $this->product->fetch('', trim($ref)); + if(! $result ) { + throw new RestException(404, 'Product not found'); + } + + $prodcomb = new ProductCombination($this->db); + if (! $prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features)) + { + $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact); + if ($result > 0) + { + return $result; + } else { + throw new RestException(500, "Error creating new product variant"); + } + } else { + return $prodcomb->id; + } + } + + /** + * Put product variants. + * + * @param int $id ID of Variant + * @param array $request_data Datas + * @return int + * + * @throws RestException + * @throws 401 + * + * @url PUT variants/{id} + */ + public function putVariant($id, $request_data = null) + { + if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { + throw new RestException(401); + } + + $prodcomb = new ProductCombination($this->db); + $prodcomb->fetch((int) $id); + + $old_prodcomb = dol_clone($prodcomb, 0); + + foreach($request_data as $field => $value) { + if ($field == 'rowid') { continue; + } + $prodcomb->$field = $value; + } + + $result = $prodcomb->update(DolibarrApiAccess::$user); + if ($result > 0) + { + return 1; + } + throw new RestException(500, "Error editing variant"); + } + + /** + * Delete product variants. + * + * @param int $id ID of Variant + * @return int + * + * @throws RestException + * @throws 401 + * + * @url DELETE variants/{id} + */ + public function deleteVariant($id) + { + if(! (DolibarrApiAccess::$user->rights->produit->supprimer || DolibarrApiAccess::$user->rights->service->supprimer)) { + throw new RestException(401); + } + + $prodcomb = new ProductCombination($this->db); + $prodcomb->id = (int) $id; + $result = $prodcomb->delete(DolibarrApiAccess::$user); + return $result; + if ($result > 0) + { + return 1; + } + throw new RestException(500, "Error deleting variant"); + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** From a17e183da906fddfc0f1a663f8365bcf2482e892 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 17 Nov 2019 00:18:43 +0000 Subject: [PATCH 07/44] Fixing style errors. --- htdocs/product/class/api_products.class.php | 132 ++++++++++---------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index e3fb4d6079c..fd564b17278 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -802,7 +802,7 @@ class Products extends DolibarrApi return $this->_cleanObjectDatas($this->productsupplier); } - + /** * Get attributes. * @@ -813,15 +813,15 @@ class Products extends DolibarrApi * @url GET attributes */ public function getAttributes() - { + { if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); return $prodattr->fetchAll(); } - + /** * Get attribute by ID. * @@ -839,17 +839,17 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); $result = $prodattr->fetch((int) $id); - + if($result < 0) { throw new RestException(404, "Attribute not found"); } - + return $prodattr; } - + /** * Add attributes. * @@ -867,18 +867,18 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); $prodattr->label = $label; $prodattr->ref = $ref; - + $resid = $prodattr->create(DolibarrApiAccess::$user); if ($resid <= 0) { throw new RestException(500, "Error creating new attribute"); } return $resid; } - + /** * Update attributes by id. * @@ -898,26 +898,26 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); - + $result = $prodattr->fetch((int) $id); if ($result == 0) { throw new RestException(404, 'Attribute not found'); } elseif ($result < 0) { throw new RestException(500, "Error fetching attribute"); } - - + + $prodattr->label = $label; $prodattr->ref = $ref; - + if ($prodattr->update(DolibarrApiAccess::$user) > 0) { return 1; } throw new RestException(500, "Error updating attribute"); } - + /** * Delete attributes by id. * @@ -934,17 +934,17 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); $prodattr->id = (int) $id; $result = $prodattr->delete(); - + if ($result > 0) { return 1; } throw new RestException(500, "Error deleting attribute"); } - + /** * Delete attributes by ref. * @@ -961,15 +961,15 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". trim($ref) ."'"; - + if ($this->db->query($sql)) { return 1; } throw new RestException(500, "Error deleting attribute"); } - + /** * Get all values for an attribute id. * @@ -986,11 +986,11 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $objectval = new ProductAttributeValue($this->db); return $objectval->fetchAllByProductAttribute((int) $id); } - + /** * Get all values for an attribute ref. * @@ -1007,28 +1007,28 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $return = array(); - + $sql = 'SELECT '; $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value v '; $sql .= "WHERE v.fk_product_attribute = ( SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". strtoupper(trim($ref)) ."' LIMIT 1)"; $query = $this->db->query($sql); - + while ($result = $this->db->fetch_object($query)) { $tmp = new ProductAttributeValue($this->db); $tmp->fk_product_attribute = $result->fk_product_attribute; $tmp->id = $result->rowid; $tmp->ref = $result->ref; $tmp->value = $result->value; - + $return[] = $tmp; } - + return $return; } - + /** * Add attribute value. * @@ -1047,22 +1047,22 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + if (empty($ref) || empty($value)) { throw new RestException(401); } - + $objectval = new ProductAttributeValue($this->db); $objectval->fk_product_attribute = $id; $objectval->ref = $ref; $objectval->value = $value; - + if ($objectval->create(DolibarrApiAccess::$user) > 0) { return $objectval->id; } throw new RestException(500, "Error creating new attribute value"); } - + /** * Delete attribute value by id. * @@ -1079,16 +1079,16 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $objectval = new ProductAttributeValue($this->db); $objectval->id = (int) $id; - + if ($objectval->delete() > 0) { return 1; } throw new RestException(500, "Error deleting attribute value"); } - + /** * Delete attribute value by ref. * @@ -1105,16 +1105,16 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE ref LIKE '". trim($ref) ."'"; - + if ($this->db->query($sql)) { return 1; } - + throw new RestException(500, "Error deleting attribute value"); } - + /** * Get product variants. * @@ -1131,11 +1131,11 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $prodcomb = new ProductCombination($this->db); return $prodcomb->fetchAllByFkProductParent((int) $id); } - + /** * Get product variants by Product ref. * @@ -1152,19 +1152,19 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $result = $this->product->fetch('', $ref); if(! $result ) { throw new RestException(404, 'Product not found'); } - + $prodcomb = new ProductCombination($this->db); return $prodcomb->fetchAllByFkProductParent((int) $this->product->id); } - + /** * Add variant. - * + * * "features" is a list of attributes pairs id_attribute=>id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...) * * @param int $id ID of Product @@ -1185,11 +1185,11 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); } - + if (empty($id) || empty($weight_impact) || empty($price_impact) || empty($features) || !is_array($features)) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); $prodattr_val = new ProductAttributeValue($this->db); foreach ($features as $id_attr => $id_value) { @@ -1200,12 +1200,12 @@ class Products extends DolibarrApi throw new RestException(401); } } - + $result = $this->product->fetch((int) $id); if(! $result ) { throw new RestException(404, 'Product not found'); } - + $prodcomb = new ProductCombination($this->db); if (! $prodcomb->fetchByProductCombination2ValuePairs($id, $features)) { @@ -1220,10 +1220,10 @@ class Products extends DolibarrApi return $prodcomb->id; } } - + /** * Add variant by product ref. - * + * * "features" is a list of attributes pairs id_attribute=>id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...) * * @param string $ref Ref of Product @@ -1244,11 +1244,11 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); } - + if (empty($ref) || empty($weight_impact) || empty($price_impact) || empty($features) || !is_array($features)) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); $prodattr_val = new ProductAttributeValue($this->db); foreach ($features as $id_attr => $id_value) { @@ -1259,16 +1259,16 @@ class Products extends DolibarrApi throw new RestException(404); } } - + $result = $this->product->fetch('', trim($ref)); if(! $result ) { throw new RestException(404, 'Product not found'); } - + $prodcomb = new ProductCombination($this->db); if (! $prodcomb->fetchByProductCombination2ValuePairs($this->product->id, $features)) { - $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact); + $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact); if ($result > 0) { return $result; @@ -1279,7 +1279,7 @@ class Products extends DolibarrApi return $prodcomb->id; } } - + /** * Put product variants. * @@ -1297,18 +1297,18 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); } - + $prodcomb = new ProductCombination($this->db); $prodcomb->fetch((int) $id); - + $old_prodcomb = dol_clone($prodcomb, 0); - + foreach($request_data as $field => $value) { if ($field == 'rowid') { continue; } $prodcomb->$field = $value; } - + $result = $prodcomb->update(DolibarrApiAccess::$user); if ($result > 0) { @@ -1316,7 +1316,7 @@ class Products extends DolibarrApi } throw new RestException(500, "Error editing variant"); } - + /** * Delete product variants. * @@ -1333,7 +1333,7 @@ class Products extends DolibarrApi if(! (DolibarrApiAccess::$user->rights->produit->supprimer || DolibarrApiAccess::$user->rights->service->supprimer)) { throw new RestException(401); } - + $prodcomb = new ProductCombination($this->db); $prodcomb->id = (int) $id; $result = $prodcomb->delete(DolibarrApiAccess::$user); From 40e4af234de3fc0568bd9c9abd6b615f1b9b1d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sun, 17 Nov 2019 01:24:07 +0100 Subject: [PATCH 08/44] Inject $user instead of global var --- htdocs/variants/class/ProductCombination.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php index 4dfd40a8f53..1c09aae62df 100644 --- a/htdocs/variants/class/ProductCombination.class.php +++ b/htdocs/variants/class/ProductCombination.class.php @@ -495,6 +495,7 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1"; * [...] * ) * + * @param User $user Object user * @param Product $product Parent product * @param array $combinations Attribute and value combinations. * @param array $variations Price and weight variations @@ -503,9 +504,9 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1"; * @param bool|float $forced_weightvar If the weight variation is forced * @return int <0 KO, >0 OK */ - public function createProductCombination(Product $product, array $combinations, array $variations, $price_var_percent = false, $forced_pricevar = false, $forced_weightvar = false) + public function createProductCombination(User $user, Product $product, array $combinations, array $variations, $price_var_percent = false, $forced_pricevar = false, $forced_weightvar = false) { - global $db, $user, $conf; + global $db, $conf; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php'; require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttributeValue.class.php'; @@ -660,11 +661,12 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1"; /** * Copies all product combinations from the origin product to the destination product * + * @param User $user Object user * @param int $origProductId Origin product id * @param Product $destProduct Destination product * @return int >0 OK <0 KO */ - public function copyAll($origProductId, Product $destProduct) + public function copyAll(User $user, $origProductId, Product $destProduct) { require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination2ValuePair.class.php'; @@ -686,6 +688,7 @@ WHERE c.fk_product_parent = ".(int) $productid." AND p.tosell = 1"; } if ($this->createProductCombination( + $user, $destProduct, $variations, array(), From a7f42b3fdfeba4783575e303d370877d665e949f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sun, 17 Nov 2019 01:25:44 +0100 Subject: [PATCH 09/44] Inject $user for createProductCombination --- htdocs/variants/combinations.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index 714ee07ed3f..f8a8b9cc9e5 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -141,7 +141,7 @@ if ($_POST) { if (!$prodcomb->fetchByProductCombination2ValuePairs($id, $sanit_features)) { - $result = $prodcomb->createProductCombination($object, $sanit_features, array(), $price_impact_percent, $price_impact, $weight_impact); + $result = $prodcomb->createProductCombination($user, $object, $sanit_features, array(), $price_impact_percent, $price_impact, $weight_impact); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); @@ -268,7 +268,7 @@ if ($action === 'confirm_deletecombination') { if ($prodstatic->fetch('', $dest_product) > 0) { //To prevent from copying to the same product if ($prodstatic->ref != $object->ref) { - if ($prodcomb->copyAll($object->id, $prodstatic) > 0) { + if ($prodcomb->copyAll($user, $object->id, $prodstatic) > 0) { header('Location: '.dol_buildpath('/variants/combinations.php?id='.$prodstatic->id, 2)); exit(); } else { From 398f0e00f75bca7958db73ece512da9b28e7f381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sun, 17 Nov 2019 01:27:23 +0100 Subject: [PATCH 10/44] inject $user for createProductCombination --- htdocs/variants/generator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/variants/generator.php b/htdocs/variants/generator.php index 27f811fdafe..137186bd5b8 100644 --- a/htdocs/variants/generator.php +++ b/htdocs/variants/generator.php @@ -110,7 +110,7 @@ if ($_POST) $cartesianarray = cartesianArray($adapted_values); foreach ($cartesianarray as $currcomb) { - $res = $combination->createProductCombination($product, $currcomb, $sanitized_values, $price_var_percent); + $res = $combination->createProductCombination($user, $product, $currcomb, $sanitized_values, $price_var_percent); if ($res < 0) { $error++; setEventMessages($combination->error, $combination->errors, 'errors'); From 8fbf853b9421d0788469d72f9de18caeecfc0ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Tue, 19 Nov 2019 14:40:50 +0100 Subject: [PATCH 11/44] Display attributes infos when get product variants --- htdocs/product/class/api_products.class.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index fd564b17278..1d71246cab7 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1133,7 +1133,14 @@ class Products extends DolibarrApi } $prodcomb = new ProductCombination($this->db); - return $prodcomb->fetchAllByFkProductParent((int) $id); + $combinations = $prodcomb->fetchAllByFkProductParent((int) $id); + + foreach ($combinations as $key => $combination) { + $prodc2vp = new ProductCombination2ValuePair($this->db); + $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); + } + + return $combinations; } /** @@ -1159,7 +1166,14 @@ class Products extends DolibarrApi } $prodcomb = new ProductCombination($this->db); - return $prodcomb->fetchAllByFkProductParent((int) $this->product->id); + $combinations = $prodcomb->fetchAllByFkProductParent((int) $this->product->id); + + foreach ($combinations as $key => $combination) { + $prodc2vp = new ProductCombination2ValuePair($this->db); + $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); + } + + return $combinations; } /** From c33506b4cc567d8e1134746227c161868769905c Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 19 Nov 2019 13:41:30 +0000 Subject: [PATCH 12/44] Fixing style errors. --- htdocs/product/class/api_products.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 1d71246cab7..c9e95cb5fe0 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1134,12 +1134,12 @@ class Products extends DolibarrApi $prodcomb = new ProductCombination($this->db); $combinations = $prodcomb->fetchAllByFkProductParent((int) $id); - + foreach ($combinations as $key => $combination) { $prodc2vp = new ProductCombination2ValuePair($this->db); $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); } - + return $combinations; } @@ -1167,12 +1167,12 @@ class Products extends DolibarrApi $prodcomb = new ProductCombination($this->db); $combinations = $prodcomb->fetchAllByFkProductParent((int) $this->product->id); - + foreach ($combinations as $key => $combination) { $prodc2vp = new ProductCombination2ValuePair($this->db); $combinations[$key]->attributes = $prodc2vp->fetchByFkCombination((int) $combination->id); } - + return $combinations; } From 8f5c8c63dfb7fbce04356d7c73c688d5f66e585a Mon Sep 17 00:00:00 2001 From: John Botella Date: Tue, 19 Nov 2019 16:35:31 +0100 Subject: [PATCH 13/44] Fix dom and showOptionals call --- htdocs/expedition/card.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index be5ed4c757a..a33055d4b10 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -2443,10 +2443,10 @@ elseif ($id || $ref) // Display lines extrafields if (is_array($extralabelslines) && count($extralabelslines)>0) { $colspan= empty($conf->productbatch->enabled) ? 5 : 6; - $line = new ExpeditionLigne($db); - $line->fetch_optionals($lines[$i]->id); - print ''; - if ($action == 'editline' && $lines[$i]->id == $line_id) + $line = $lines[$i]; + $line->fetch_optionals($line->id); + + if ($action == 'editline' && $line->id == $line_id) { print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan), $indiceAsked); } @@ -2454,7 +2454,6 @@ elseif ($id || $ref) { print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan), $indiceAsked); } - print ''; } } } From db0d352af3d485187f7b5a9ee20f03106b88f1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Hahn?= Date: Wed, 20 Nov 2019 12:53:23 +0100 Subject: [PATCH 14/44] Use virtual stock when this has been configured When "Use virtual stock by default, instead of physical stock, for replenishment feature" has been set in configuration, this should really be used. Otherwise only physically missing items will be shown in replenishment. --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 0de9fa76786..99a4b4c286e 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -89,7 +89,7 @@ if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) { $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. } -$usevirtualstock=0; +$usevirtualstock = !empty($conf->global->STOCK_USE_VIRTUAL_STOCK); if ($mode == 'virtual') $usevirtualstock=1; $parameters=array(); From f73bd0e0a6fba4087e50e1f1548870b0068805ea Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 20 Nov 2019 13:07:26 +0100 Subject: [PATCH 15/44] FIX display job of contact list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit can see différent contact with same name but different job --- htdocs/comm/action/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 4e5abac75d3..c057dc2dee3 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1290,7 +1290,7 @@ if ($id > 0) // related contact print ''.$langs->trans("ActionOnContact").''; print '
'; - print $form->selectcontacts($object->socid, array_keys($object->socpeopleassigned), 'socpeopleassigned[]', 1, '', '', 0, 'quatrevingtpercent', false, 0, 0, array(), 'multiple', 'contactid'); + print $form->selectcontacts($object->socid, array_keys($object->socpeopleassigned), 'socpeopleassigned[]', 1, '', '', 1, 'quatrevingtpercent', false, 0, 0, array(), 'multiple', 'contactid'); print '
'; print ''; print ''; From 2f064567efbc2d505efa4801acd66ae06ca9645d Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 21 Nov 2019 07:50:44 +0100 Subject: [PATCH 16/44] NEW Add shipment widget --- htdocs/core/boxes/box_shipments.php | 191 ++++++++++++++++++++ htdocs/core/modules/modExpedition.class.php | 4 +- htdocs/langs/en_US/boxes.lang | 3 + 3 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 htdocs/core/boxes/box_shipments.php diff --git a/htdocs/core/boxes/box_shipments.php b/htdocs/core/boxes/box_shipments.php new file mode 100644 index 00000000000..4852934af74 --- /dev/null +++ b/htdocs/core/boxes/box_shipments.php @@ -0,0 +1,191 @@ + + * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2019 Alexandre Spangaro + * + * 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/core/boxes/box_shipments.php + * \ingroup shipment + * \brief Module for generating the display of the shipment box + */ + +include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php'; + + +/** + * Class to manage the box to show last shipments + */ +class box_shipments extends ModeleBoxes +{ + public $boxcode="lastcustomershipments"; + public $boximg="sending"; + public $boxlabel="BoxLastCustomerShipments"; + public $depends = array("expedition"); + + /** + * @var DoliDB Database handler. + */ + public $db; + + public $param; + + public $info_box_head = array(); + public $info_box_contents = array(); + + + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + public function __construct($db, $param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->expedition->lire); + } + + /** + * Load data for box to show them later + * + * @param int $max Maximum number of records to load + * @return void + */ + public function loadBox($max = 5) + { + global $user, $langs, $conf; + $langs->loadLangs(array('orders', 'sendings')); + + $this->max = $max; + + include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; + include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + + $shipmentstatic = new Expedition($this->db); + $orderstatic = new Commande($this->db); + $societestatic = new Societe($this->db); + + $this->info_box_head = array('text' => $langs->trans("BoxTitleLastCustomerShipments", $max)); + + if ($user->rights->expedition->lire) + { + $sql = "SELECT s.nom as name"; + $sql.= ", s.rowid as socid"; + $sql.= ", s.code_client"; + $sql.= ", s.logo, s.email"; + $sql.= ", e.ref, e.tms"; + $sql.= ", e.rowid"; + $sql.= ", e.ref_customer"; + $sql.= ", e.fk_statut"; + $sql.= ", e.fk_user_valid"; + $sql.= ", c.ref as commande_ref"; + $sql.= ", c.rowid as commande_id"; + $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc"; + $sql.= " WHERE e.entity = ".$conf->entity; + if (! empty($conf->global->ORDER_BOX_LAST_SHIPMENTS_VALIDATED_ONLY)) $sql.=" AND e.fk_statut = 1"; + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND sc.fk_user = " .$user->id; + else $sql.= " ORDER BY e.date_delivery, e.ref DESC "; + $sql.= $this->db->plimit($max, 0); + + $result = $this->db->query($sql); + if ($result) { + $num = $this->db->num_rows($result); + + $line = 0; + + while ($line < $num) { + $objp = $this->db->fetch_object($result); + + $shipmentstatic->id = $objp->rowid; + $shipmentstatic->ref = $objp->ref; + $shipmentstatic->ref_customer = $objp->ref_customer; + + $orderstatic->id= $objp->commande_id; + $orderstatic->ref=$objp->commande_ref; + print $orderstatic->getNomUrl(1); + + $societestatic->id = $objp->socid; + $societestatic->name = $objp->name; + $societestatic->email = $objp->email; + $societestatic->code_client = $objp->code_client; + $societestatic->logo = $objp->logo; + + $this->info_box_contents[$line][] = array( + 'td' => '', + 'text' => $shipmentstatic->getNomUrl(1), + 'asis' => 1, + ); + + $this->info_box_contents[$line][] = array( + 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"', + 'text' => $societestatic->getNomUrl(1), + 'asis' => 1, + ); + + $this->info_box_contents[$line][] = array( + 'td' => '', + 'text' => $orderstatic->getNomUrl(1), + 'asis' => 1, + ); + + $this->info_box_contents[$line][] = array( + 'td' => 'class="right" width="18"', + 'text' => $shipmentstatic->LibStatut($objp->fk_statut, 3), + ); + + $line++; + } + + if ($num==0) $this->info_box_contents[$line][0] = array('td' => 'class="center"','text'=>$langs->trans("NoRecordedShipments")); + + $this->db->free($result); + } else { + $this->info_box_contents[0][0] = array( + 'td' => '', + 'maxlength'=>500, + 'text' => ($this->db->error().' sql='.$sql), + ); + } + } else { + $this->info_box_contents[0][0] = array( + 'td' => 'class="nohover opacitymedium left"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); + } + } + + /** + * Method to show box + * + * @param array $head Array with properties of box title + * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string + * @return string + */ + public function showBox($head = null, $contents = null, $nooutput = 0) + { + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + } +} diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index 68f4a3d5fba..d8225a1b2a5 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -133,7 +133,9 @@ class modExpedition extends DolibarrModules $r++; // Boxes - $this->boxes = array(); + $this->boxes = array( + 0=>array('file'=>'box_shipments.php','enabledbydefaulton'=>'Home'), + ); // Permissions $this->rights = array(); diff --git a/htdocs/langs/en_US/boxes.lang b/htdocs/langs/en_US/boxes.lang index a55a0194632..8fe1f84b149 100644 --- a/htdocs/langs/en_US/boxes.lang +++ b/htdocs/langs/en_US/boxes.lang @@ -97,3 +97,6 @@ BoxSuspenseAccount=Count accountancy operation with suspense account BoxTitleSuspenseAccount=Number of unallocated lines NumberOfLinesInSuspenseAccount=Number of line in suspense account SuspenseAccountNotDefined=Suspense account isn't defined +BoxLastCustomerShipments=Last customer shipments +BoxTitleLastCustomerShipments=Latest %s customer shipments +NoRecordedShipments=No recorded customer shipment From f6c5605fd5fdf05c38a6c4b86bae7f48c2be0895 Mon Sep 17 00:00:00 2001 From: Tobias Sekan Date: Thu, 21 Nov 2019 08:29:47 +0100 Subject: [PATCH 17/44] Fix number of tasks on dashboard always zero --- htdocs/projet/class/task.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index bc122367312..60657b08061 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1985,7 +1985,7 @@ class Task extends CommonObject $sql .= " WHERE p.entity IN (".getEntity('project', 0).')'; $sql .= " AND p.fk_statut = 1"; $sql .= " AND t.fk_projet = p.rowid"; - $sql .= " AND t.progress < 100"; // tasks to do + $sql .= " AND (t.progress IS NULL OR t.progress < 100)"; // tasks to do if (!$user->rights->projet->all->lire) $sql .= " AND p.rowid IN (".$projectsListId.")"; // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser //if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; From 3daeb24da1ff2adf2d0c312156c41bb46254441f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Nov 2019 13:05:13 +0100 Subject: [PATCH 18/44] Fix confusion with field name in sql --- htdocs/comm/remx.php | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index eabb217fb99..7a8b03cde4e 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -739,8 +739,8 @@ if ($socid > 0) $sql.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,"; $sql.= " rc.fk_facture_source,"; $sql.= " u.login, u.rowid as user_id,"; - $sql.= " f.rowid, f.ref,"; - $sql.= " fa.ref as ref, fa.type as type"; + $sql.= " f.rowid as invoiceid, f.ref,"; + $sql.= " fa.ref as invoice_source_ref, fa.type as type"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " , ".MAIN_DB_PREFIX."user as u"; $sql.= " , ".MAIN_DB_PREFIX."facturedet as fc"; @@ -758,8 +758,8 @@ if ($socid > 0) $sql2.= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,"; $sql2.= " rc.fk_facture_source,"; $sql2.= " u.login, u.rowid as user_id,"; - $sql2.= " f.rowid, f.ref,"; - $sql2.= " fa.ref as ref, fa.type as type"; + $sql2.= " f.rowid as invoiceid, f.ref,"; + $sql2.= " fa.ref as invoice_source_ref, fa.type as type"; $sql2.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql2.= " , ".MAIN_DB_PREFIX."user as u"; $sql2.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc"; @@ -833,7 +833,7 @@ if ($socid > 0) { print ''; $facturestatic->id=$obj->fk_facture_source; - $facturestatic->ref=$obj->ref; + $facturestatic->ref=$obj->invoice_source_ref; $facturestatic->type=$obj->type; print preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $obj->description).' '.$facturestatic->getNomURl(1); print ''; @@ -842,7 +842,7 @@ if ($socid > 0) { print ''; $facturestatic->id=$obj->fk_facture_source; - $facturestatic->ref=$obj->ref; + $facturestatic->ref=$obj->invoice_source_ref; $facturestatic->type=$obj->type; print preg_replace('/\(DEPOSIT\)/', $langs->trans("InvoiceDeposit"), $obj->description).' '.$facturestatic->getNomURl(1); print ''; @@ -851,7 +851,7 @@ if ($socid > 0) { print ''; $facturestatic->id=$obj->fk_facture_source; - $facturestatic->ref=$obj->ref; + $facturestatic->ref=$obj->invoice_source_ref; $facturestatic->type=$obj->type; print preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("Invoice"), $obj->description).' '.$facturestatic->getNomURl(1); print ''; @@ -862,7 +862,12 @@ if ($socid > 0) print $obj->description; print ''; } - print ''.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.''; + print ''; + if ($obj->invoiceid) + { + print ''.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.''; + } + print ''; print ''.price($obj->amount_ht).''; if (! empty($conf->multicurrency->enabled)) { @@ -909,8 +914,8 @@ if ($socid > 0) $sql.= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,"; $sql.= " rc.fk_invoice_supplier_source,"; $sql.= " u.login, u.rowid as user_id,"; - $sql.= " f.rowid, f.ref as ref,"; - $sql.= " fa.ref, fa.type as type"; + $sql.= " f.rowid as invoiceid, f.ref as ref,"; + $sql.= " fa.ref as invoice_source_ref, fa.type as type"; $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; $sql.= " , ".MAIN_DB_PREFIX."user as u"; $sql.= " , ".MAIN_DB_PREFIX."facture_fourn_det as fc"; @@ -928,8 +933,8 @@ if ($socid > 0) $sql2.= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,"; $sql2.= " rc.fk_invoice_supplier_source,"; $sql2.= " u.login, u.rowid as user_id,"; - $sql2.= " f.rowid, f.ref as ref,"; - $sql2.= " fa.ref, fa.type as type"; + $sql2.= " f.rowid as invoiceid, f.ref as ref,"; + $sql2.= " fa.ref as invoice_source_ref, fa.type as type"; $sql2.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; $sql2.= " , ".MAIN_DB_PREFIX."user as u"; $sql2.= " , ".MAIN_DB_PREFIX."societe_remise_except as rc"; @@ -1003,7 +1008,7 @@ if ($socid > 0) { print ''; $facturefournstatic->id=$obj->fk_invoice_supplier_source; - $facturefournstatic->ref=$obj->ref; + $facturefournstatic->ref=$obj->invoice_source_ref; $facturefournstatic->type=$obj->type; print preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $obj->description).' '.$facturefournstatic->getNomURl(1); print ''; @@ -1012,7 +1017,7 @@ if ($socid > 0) { print ''; $facturefournstatic->id=$obj->fk_invoice_supplier_source; - $facturefournstatic->ref=$obj->ref; + $facturefournstatic->ref=$obj->invoice_source_ref; $facturefournstatic->type=$obj->type; print preg_replace('/\(DEPOSIT\)/', $langs->trans("InvoiceDeposit"), $obj->description).' '.$facturefournstatic->getNomURl(1); print ''; @@ -1021,7 +1026,7 @@ if ($socid > 0) { print ''; $facturefournstatic->id=$obj->fk_invoice_supplier_source; - $facturefournstatic->ref=$obj->ref; + $facturefournstatic->ref=$obj->invoice_source_ref; $facturefournstatic->type=$obj->type; print preg_replace('/\(EXCESS PAID\)/', $langs->trans("Invoice"), $obj->description).' '.$facturefournstatic->getNomURl(1); print ''; @@ -1032,7 +1037,11 @@ if ($socid > 0) print $obj->description; print ''; } - print ''.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.''; + print ''; + if ($obj->invoiceid) { + print ''.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.''; + } + print ''; print ''.price($obj->amount_ht).''; if (! empty($conf->multicurrency->enabled)) { From a8d02615a843a5b9debf34d80a64a1245fe937ef Mon Sep 17 00:00:00 2001 From: gauthier Date: Thu, 21 Nov 2019 14:58:20 +0100 Subject: [PATCH 19/44] FIX : we need to be able to recalculate tva only if invoice not ventil --- htdocs/fourn/facture/card.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index a294cf3c6ad..f82a2aeac0b 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2642,11 +2642,14 @@ else else $calculationrule=(empty($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)?'totalofround':'roundoftotal'); if ($calculationrule == 'totalofround') $calculationrulenum=1; else $calculationrulenum=2; - $s=$langs->trans("ReCalculate").' '; - $s.=''.$langs->trans("Mode1").''; - $s.=' / '; - $s.=''.$langs->trans("Mode2").''; - print $form->textwithtooltip($s, $langs->trans("CalculationRuleDesc",$calculationrulenum).'
'.$langs->trans("CalculationRuleDescSupplier"), 2, 1, img_picto('','help')); + + if(empty($object->getVentilExportCompta())) { + $s=$langs->trans("ReCalculate").' '; + $s.=''.$langs->trans("Mode1").''; + $s.=' / '; + $s.=''.$langs->trans("Mode2").''; + print $form->textwithtooltip($s, $langs->trans("CalculationRuleDesc",$calculationrulenum).'
'.$langs->trans("CalculationRuleDescSupplier"), 2, 1, img_picto('','help')); + } print ''; // Amount Local Taxes From d6ba06e271f7b98a410243416438f163a8678de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 21 Nov 2019 15:50:06 +0100 Subject: [PATCH 20/44] API New get attribute by ref + security update --- htdocs/product/class/api_products.class.php | 70 ++++++++++++++++----- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index c9e95cb5fe0..6010f6dbcdf 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -814,7 +814,7 @@ class Products extends DolibarrApi */ public function getAttributes() { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } @@ -836,7 +836,7 @@ class Products extends DolibarrApi */ public function getAttributeById($id) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } @@ -849,6 +849,42 @@ class Products extends DolibarrApi return $prodattr; } + + /** + * Get attributes by ref. + * + * @param string $ref Reference of Attribute + * @return array + * + * @throws RestException + * @throws 401 + * + * @url GET attributes/ref/{ref} + */ + public function getAttributesByRef($ref) + { + if(! DolibarrApiAccess::$user->rights->produit->lire) { + throw new RestException(401); + } + + $sql = "SELECT rowid, ref, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". trim($ref) ."' AND entity IN (".getEntity('product').")"; + + $query = $this->db->query($sql); + + if (!$this->db->num_rows($query)) { + throw new RestException(404); + } + + $result = $this->db->fetch_object($query); + + $attr = []; + $attr['id'] = $result->rowid; + $attr['ref'] = $result->ref; + $attr['label'] = $result->label; + $attr['rang'] = $result->rang; + + return $attr; + } /** * Add attributes. @@ -864,7 +900,7 @@ class Products extends DolibarrApi */ public function addAttributes($ref, $label) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } @@ -895,7 +931,7 @@ class Products extends DolibarrApi */ public function putAttributes($id, $ref, $label) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } @@ -931,7 +967,7 @@ class Products extends DolibarrApi */ public function deleteAttributes($id) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->supprimer) { throw new RestException(401); } @@ -958,7 +994,7 @@ class Products extends DolibarrApi */ public function deleteAttributesByRef($ref) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->supprimer) { throw new RestException(401); } @@ -983,7 +1019,7 @@ class Products extends DolibarrApi */ public function getAttributeValues($id) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } @@ -1004,7 +1040,7 @@ class Products extends DolibarrApi */ public function getAttributeValuesByRef($ref) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } @@ -1044,7 +1080,7 @@ class Products extends DolibarrApi */ public function addAttributeValue($id, $ref, $value) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } @@ -1076,7 +1112,7 @@ class Products extends DolibarrApi */ public function deleteAttributeValueById($id) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->supprimer) { throw new RestException(401); } @@ -1102,7 +1138,7 @@ class Products extends DolibarrApi */ public function deleteAttributeValueByRef($ref) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->supprimer) { throw new RestException(401); } @@ -1128,7 +1164,7 @@ class Products extends DolibarrApi */ public function getVariants($id) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } @@ -1156,7 +1192,7 @@ class Products extends DolibarrApi */ public function getVariantsByProdRef($ref) { - if(! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } @@ -1196,7 +1232,7 @@ class Products extends DolibarrApi */ public function addVariant($id, $weight_impact, $price_impact, $price_impact_is_percent, $features) { - if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { + if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } @@ -1255,7 +1291,7 @@ class Products extends DolibarrApi */ public function addVariantByProductRef($ref, $weight_impact, $price_impact, $price_impact_is_percent, $features) { - if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { + if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } @@ -1308,7 +1344,7 @@ class Products extends DolibarrApi */ public function putVariant($id, $request_data = null) { - if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { + if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } @@ -1344,7 +1380,7 @@ class Products extends DolibarrApi */ public function deleteVariant($id) { - if(! (DolibarrApiAccess::$user->rights->produit->supprimer || DolibarrApiAccess::$user->rights->service->supprimer)) { + if(! DolibarrApiAccess::$user->rights->produit->supprimer) { throw new RestException(401); } From 4f747e2eb8e5054a8836eb99e0e4ef7fd1f623e2 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 21 Nov 2019 14:50:47 +0000 Subject: [PATCH 21/44] Fixing style errors. --- htdocs/product/class/api_products.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 6010f6dbcdf..faf312e77ff 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -849,7 +849,7 @@ class Products extends DolibarrApi return $prodattr; } - + /** * Get attributes by ref. * @@ -866,23 +866,23 @@ class Products extends DolibarrApi if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } - + $sql = "SELECT rowid, ref, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". trim($ref) ."' AND entity IN (".getEntity('product').")"; - + $query = $this->db->query($sql); - + if (!$this->db->num_rows($query)) { throw new RestException(404); } - + $result = $this->db->fetch_object($query); - + $attr = []; $attr['id'] = $result->rowid; $attr['ref'] = $result->ref; $attr['label'] = $result->label; $attr['rang'] = $result->rang; - + return $attr; } From 1068d9a62388606adceabcac241c681155ebc2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:23:46 +0100 Subject: [PATCH 22/44] FIX deleteAttributeValueByRef / ADD getAttributeValueById, getAttributeValueByRef --- htdocs/product/class/api_products.class.php | 102 ++++++++++++++++++-- 1 file changed, 93 insertions(+), 9 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index faf312e77ff..5be52795437 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -980,30 +980,114 @@ class Products extends DolibarrApi } throw new RestException(500, "Error deleting attribute"); } - + /** - * Delete attributes by ref. + * Get attribute value by id. * - * @param string $ref Reference of Attribute + * @param int $id ID of Attribute value + * @param string $ref Ref of Attribute value + * @return array + * + * @throws RestException + * @throws 401 + * + * @url GET attributes/values/{id} + */ + public function getAttributeValueById($id) + { + if(! DolibarrApiAccess::$user->rights->produit->lire) { + throw new RestException(401); + } + + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")"; + + $query = $this->db->query($sql); + + if (!$query) { + throw new RestException(401); + } + + if (!$this->db->num_rows($query)) { + throw new RestException(404, 'Attribute value not found'); + } + + $result = $this->db->fetch_object($query); + + $attrval = []; + $attrval['id'] = $result->rowid; + $attrval['fk_product_attribute'] = $result->fk_product_attribute; + $attrval['ref'] = $result->ref; + $attrval['value'] = $result->value; + + return $attrval; + } + + /** + * Get attribute value by ref. + * + * @param int $id ID of Attribute value + * @param string $ref Ref of Attribute value + * @return array + * + * @throws RestException + * @throws 401 + * + * @url GET attributes/{id}/values/ref/{ref} + */ + public function getAttributeValueByRef($id, $ref) + { + if(! DolibarrApiAccess::$user->rights->produit->lire) { + throw new RestException(401); + } + + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE ref LIKE '". trim($ref) ."' AND fk_product_attribute = ". (int) $id ." AND entity IN (".getEntity('product').")"; + + $query = $this->db->query($sql); + + if (!$query) { + throw new RestException(401); + } + + if (!$this->db->num_rows($query)) { + throw new RestException(404, 'Attribute value not found'); + } + + $result = $this->db->fetch_object($query); + + $attrval = []; + $attrval['id'] = $result->rowid; + $attrval['fk_product_attribute'] = $result->fk_product_attribute; + $attrval['ref'] = $result->ref; + $attrval['value'] = $result->value; + + return $attrval; + } + + /** + * Delete attribute value by ref. + * + * @param int $id ID of Attribute + * @param string $ref Ref of Attribute value * @return int * * @throws RestException * @throws 401 * - * @url DELETE attributes/ref/{ref} + * @url DELETE attributes/{id}/values/ref/{ref} */ - public function deleteAttributesByRef($ref) + public function deleteAttributeValueByRef($id, $ref) { if(! DolibarrApiAccess::$user->rights->produit->supprimer) { throw new RestException(401); } - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '". trim($ref) ."'"; - + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE ref LIKE '". trim($ref) ."' AND fk_product_attribute = ". (int) $id; + if ($this->db->query($sql)) { return 1; } - throw new RestException(500, "Error deleting attribute"); + + throw new RestException(500, "Error deleting attribute value"); } /** From 0074589b6fa689ca1c355a78e153690292c3bb6f Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 21 Nov 2019 16:24:25 +0000 Subject: [PATCH 23/44] Fixing style errors. --- htdocs/product/class/api_products.class.php | 40 ++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 5be52795437..c614b013f83 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -980,7 +980,7 @@ class Products extends DolibarrApi } throw new RestException(500, "Error deleting attribute"); } - + /** * Get attribute value by id. * @@ -998,30 +998,30 @@ class Products extends DolibarrApi if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } - + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")"; - + $query = $this->db->query($sql); - + if (!$query) { throw new RestException(401); } - + if (!$this->db->num_rows($query)) { throw new RestException(404, 'Attribute value not found'); } - + $result = $this->db->fetch_object($query); - + $attrval = []; $attrval['id'] = $result->rowid; $attrval['fk_product_attribute'] = $result->fk_product_attribute; $attrval['ref'] = $result->ref; $attrval['value'] = $result->value; - + return $attrval; } - + /** * Get attribute value by ref. * @@ -1039,30 +1039,30 @@ class Products extends DolibarrApi if(! DolibarrApiAccess::$user->rights->produit->lire) { throw new RestException(401); } - + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE ref LIKE '". trim($ref) ."' AND fk_product_attribute = ". (int) $id ." AND entity IN (".getEntity('product').")"; - + $query = $this->db->query($sql); - + if (!$query) { throw new RestException(401); } - + if (!$this->db->num_rows($query)) { throw new RestException(404, 'Attribute value not found'); } - + $result = $this->db->fetch_object($query); - + $attrval = []; $attrval['id'] = $result->rowid; $attrval['fk_product_attribute'] = $result->fk_product_attribute; $attrval['ref'] = $result->ref; $attrval['value'] = $result->value; - + return $attrval; } - + /** * Delete attribute value by ref. * @@ -1080,13 +1080,13 @@ class Products extends DolibarrApi if(! DolibarrApiAccess::$user->rights->produit->supprimer) { throw new RestException(401); } - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE ref LIKE '". trim($ref) ."' AND fk_product_attribute = ". (int) $id; - + if ($this->db->query($sql)) { return 1; } - + throw new RestException(500, "Error deleting attribute value"); } From 416a2f7f1c0056c3cdebe6eb4505c8526bf10655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:41:09 +0100 Subject: [PATCH 24/44] FIX putAttributes, ADD putAttributeValue --- htdocs/product/class/api_products.class.php | 80 +++++++++++++++++---- 1 file changed, 67 insertions(+), 13 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index c614b013f83..2f3f7463b8d 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -914,14 +914,13 @@ class Products extends DolibarrApi } return $resid; } - + /** * Update attributes by id. * * @param int $id ID of Attribute - * @param string $ref Reference of Attribute - * @param string $label Label of Attribute - * @return int + * @param array $request_data Datas + * @return array * * @throws RestException * @throws 401 @@ -929,27 +928,36 @@ class Products extends DolibarrApi * * @url PUT attributes/{id} */ - public function putAttributes($id, $ref, $label) + public function putAttributes($id, $request_data = null) { if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); - + $result = $prodattr->fetch((int) $id); if ($result == 0) { throw new RestException(404, 'Attribute not found'); } elseif ($result < 0) { throw new RestException(500, "Error fetching attribute"); } - - - $prodattr->label = $label; - $prodattr->ref = $ref; - + + foreach($request_data as $field => $value) { + if ($field == 'rowid') { continue; + } + $prodattr->$field = $value; + } + if ($prodattr->update(DolibarrApiAccess::$user) > 0) { - return 1; + $result = $prodattr->fetch((int) $id); + if ($result == 0) { + throw new RestException(404, 'Attribute not found'); + } elseif ($result < 0) { + throw new RestException(500, "Error fetching attribute"); + } else { + return $prodattr; + } } throw new RestException(500, "Error updating attribute"); } @@ -1182,6 +1190,52 @@ class Products extends DolibarrApi } throw new RestException(500, "Error creating new attribute value"); } + + /** + * Update attribute value. + * + * @param int $id ID of Attribute + * @param array $request_data Datas + * @return array + * + * @throws RestException + * @throws 401 + * + * @url PUT attributes/values/{id} + */ + public function putAttributeValue($id, $request_data) + { + if(! DolibarrApiAccess::$user->rights->produit->creer) { + throw new RestException(401); + } + + $objectval = new ProductAttributeValue($this->db); + $result = $objectval->fetch((int) $id); + + if ($result == 0) { + throw new RestException(404, 'Attribute value not found'); + } elseif ($result < 0) { + throw new RestException(500, "Error fetching attribute value"); + } + + foreach($request_data as $field => $value) { + if ($field == 'rowid') { continue; + } + $objectval->$field = $value; + } + + if ($objectval->update(DolibarrApiAccess::$user) > 0) { + $result = $objectval->fetch((int) $id); + if ($result == 0) { + throw new RestException(404, 'Attribute not found'); + } elseif ($result < 0) { + throw new RestException(500, "Error fetching attribute"); + } else { + return $objectval; + } + } + throw new RestException(500, "Error updating attribute"); + } /** * Delete attribute value by id. From cfa0860d244896fe64ca5e2e29b01b210e915a0a Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 21 Nov 2019 16:41:45 +0000 Subject: [PATCH 25/44] Fixing style errors. --- htdocs/product/class/api_products.class.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 2f3f7463b8d..04d9979cefe 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -914,7 +914,7 @@ class Products extends DolibarrApi } return $resid; } - + /** * Update attributes by id. * @@ -933,22 +933,22 @@ class Products extends DolibarrApi if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } - + $prodattr = new ProductAttribute($this->db); - + $result = $prodattr->fetch((int) $id); if ($result == 0) { throw new RestException(404, 'Attribute not found'); } elseif ($result < 0) { throw new RestException(500, "Error fetching attribute"); } - + foreach($request_data as $field => $value) { if ($field == 'rowid') { continue; } $prodattr->$field = $value; } - + if ($prodattr->update(DolibarrApiAccess::$user) > 0) { $result = $prodattr->fetch((int) $id); if ($result == 0) { @@ -1190,7 +1190,7 @@ class Products extends DolibarrApi } throw new RestException(500, "Error creating new attribute value"); } - + /** * Update attribute value. * @@ -1208,22 +1208,22 @@ class Products extends DolibarrApi if(! DolibarrApiAccess::$user->rights->produit->creer) { throw new RestException(401); } - + $objectval = new ProductAttributeValue($this->db); $result = $objectval->fetch((int) $id); - + if ($result == 0) { throw new RestException(404, 'Attribute value not found'); } elseif ($result < 0) { throw new RestException(500, "Error fetching attribute value"); } - + foreach($request_data as $field => $value) { if ($field == 'rowid') { continue; } $objectval->$field = $value; } - + if ($objectval->update(DolibarrApiAccess::$user) > 0) { $result = $objectval->fetch((int) $id); if ($result == 0) { From 351ba58bbe65f9ddf6e1f85d852ea39d620c613f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:43:40 +0100 Subject: [PATCH 26/44] Fix Superfluous parameter comment --- htdocs/product/class/api_products.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 04d9979cefe..32423c015fc 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -993,7 +993,6 @@ class Products extends DolibarrApi * Get attribute value by id. * * @param int $id ID of Attribute value - * @param string $ref Ref of Attribute value * @return array * * @throws RestException From 5a3f78088e2c42fd763d6493a4143783164c42fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 21 Nov 2019 18:18:11 +0100 Subject: [PATCH 27/44] Fix double deleteAttributeValueByRef --- htdocs/product/class/api_products.class.php | 26 --------------------- 1 file changed, 26 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 32423c015fc..2fa4f600b11 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1262,32 +1262,6 @@ class Products extends DolibarrApi throw new RestException(500, "Error deleting attribute value"); } - /** - * Delete attribute value by ref. - * - * @param string $ref Ref of Attribute value - * @return int - * - * @throws RestException - * @throws 401 - * - * @url DELETE attributes/values/ref/{ref} - */ - public function deleteAttributeValueByRef($ref) - { - if(! DolibarrApiAccess::$user->rights->produit->supprimer) { - throw new RestException(401); - } - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE ref LIKE '". trim($ref) ."'"; - - if ($this->db->query($sql)) { - return 1; - } - - throw new RestException(500, "Error deleting attribute value"); - } - /** * Get product variants. * From 5fdd6f698d3b550c7537d37deab1e54b69a50033 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 21 Nov 2019 20:45:19 +0100 Subject: [PATCH 28/44] More complete error message Conflicts: htdocs/core/class/CMailFile.class.php --- htdocs/core/class/CMailFile.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index bf9b617693f..9b1a5a69525 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -752,9 +752,9 @@ class CMailFile } else { - if (empty($this->error)) $this->error=$result; - dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); - $res=false; + if (empty($this->error)) $this->error = $result; + dol_syslog("CMailFile::sendfile: mail end error with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."
".$this->error, LOG_ERR); + $res = false; } } } From 1bc8c57d6d2486d5f3919bf12dc5ff5204968f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 21 Nov 2019 22:54:13 +0100 Subject: [PATCH 29/44] Fix $weight_impact $price_impact --- htdocs/product/class/api_products.class.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 2fa4f600b11..bb83630bb72 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1347,9 +1347,12 @@ class Products extends DolibarrApi throw new RestException(401); } - if (empty($id) || empty($weight_impact) || empty($price_impact) || empty($features) || !is_array($features)) { + if (empty($id) || empty($features) || !is_array($features)) { throw new RestException(401); } + + $weight_impact = price2num($weight_impact); + $price_impact = price2num($price_impact); $prodattr = new ProductAttribute($this->db); $prodattr_val = new ProductAttributeValue($this->db); @@ -1406,9 +1409,12 @@ class Products extends DolibarrApi throw new RestException(401); } - if (empty($ref) || empty($weight_impact) || empty($price_impact) || empty($features) || !is_array($features)) { + if (empty($ref) || empty($features) || !is_array($features)) { throw new RestException(401); } + + $weight_impact = price2num($weight_impact); + $price_impact = price2num($price_impact); $prodattr = new ProductAttribute($this->db); $prodattr_val = new ProductAttributeValue($this->db); From 821ca724a5031f0825efec5a94334596505d8292 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 21 Nov 2019 21:54:51 +0000 Subject: [PATCH 30/44] Fixing style errors. --- htdocs/product/class/api_products.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index bb83630bb72..c5ca4271f75 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1350,7 +1350,7 @@ class Products extends DolibarrApi if (empty($id) || empty($features) || !is_array($features)) { throw new RestException(401); } - + $weight_impact = price2num($weight_impact); $price_impact = price2num($price_impact); @@ -1412,7 +1412,7 @@ class Products extends DolibarrApi if (empty($ref) || empty($features) || !is_array($features)) { throw new RestException(401); } - + $weight_impact = price2num($weight_impact); $price_impact = price2num($price_impact); From e76a112099ec5eff39d77a3f4f87ba049e78146e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 21 Nov 2019 23:09:18 +0100 Subject: [PATCH 31/44] Remove unecessary dol_clone in ::putVariant --- htdocs/product/class/api_products.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index c5ca4271f75..37c950e9956 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -1468,8 +1468,6 @@ class Products extends DolibarrApi $prodcomb = new ProductCombination($this->db); $prodcomb->fetch((int) $id); - $old_prodcomb = dol_clone($prodcomb, 0); - foreach($request_data as $field => $value) { if ($field == 'rowid') { continue; } From f4e1361d068b62902b96ae787fba5d7c37005137 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 22 Nov 2019 06:53:05 +0100 Subject: [PATCH 32/44] NEW small fix --- htdocs/core/boxes/box_shipments.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/boxes/box_shipments.php b/htdocs/core/boxes/box_shipments.php index 4852934af74..957c738ad22 100644 --- a/htdocs/core/boxes/box_shipments.php +++ b/htdocs/core/boxes/box_shipments.php @@ -124,7 +124,6 @@ class box_shipments extends ModeleBoxes $orderstatic->id= $objp->commande_id; $orderstatic->ref=$objp->commande_ref; - print $orderstatic->getNomUrl(1); $societestatic->id = $objp->socid; $societestatic->name = $objp->name; From 61913078654c3846cecfbcb3227ca15f450f875a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 22 Nov 2019 12:22:27 +0100 Subject: [PATCH 33/44] Debug v11 --- htdocs/admin/mails_senderprofile_list.php | 14 +++++-- .../core/class/emailsenderprofile.class.php | 37 ++++++++++++------- .../install/mysql/migration/10.0.0-11.0.0.sql | 1 + htdocs/theme/md/style.css.php | 3 ++ 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/htdocs/admin/mails_senderprofile_list.php b/htdocs/admin/mails_senderprofile_list.php index c5201adedeb..a22c9d79ac5 100644 --- a/htdocs/admin/mails_senderprofile_list.php +++ b/htdocs/admin/mails_senderprofile_list.php @@ -135,6 +135,10 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { + // Actions cancel, add, update, delete or clone + $backurlforlist = $_SERVER["PHP_SELF"].'?action=list'; + include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; + // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; @@ -344,7 +348,7 @@ print '
'; print ''; print ''; -print ''; +print ''; print ''; print ''; print ''; @@ -365,10 +369,14 @@ if ($action != 'create') { print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; print '
'.$langs->trans("Label").'
'.$langs->trans("Email").'
'.$langs->trans("Signature").'
'.$langs->trans("Signature").''; + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor = new DolEditor('signature', GETPOST('signature'), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%'); + print $doleditor->Create(1); + print '
'.$langs->trans("Position").'
'.$langs->trans("Status").''; - print ''; + print $form->selectyesno('active', GETPOST('active', 'int'), 1); print '
'; print '
'; diff --git a/htdocs/core/class/emailsenderprofile.class.php b/htdocs/core/class/emailsenderprofile.class.php index b65d72332e0..41a0d485ce0 100644 --- a/htdocs/core/class/emailsenderprofile.class.php +++ b/htdocs/core/class/emailsenderprofile.class.php @@ -56,19 +56,28 @@ class EmailSenderProfile extends CommonObject public $picto = 'emailsenderprofile@monmodule'; + const STATUS_DISABLED = 0; + const STATUS_ENABLED = 1; + + /** - * 'type' if the field format. - * 'label' the translation key. - * 'enabled' is a condition when the filed must be managed. - * 'visible' says if field is visible in list (-1 means not shown by default but can be added into list to be viewed). - * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). - * 'index' if we want an index in database. - * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). - * 'position' is the sort order of field. - * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. - * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). - * 'help' is a string visible as a tooltip on field - * 'comment' is not used. You can store here any text of your choice. + * 'type' if the field format ('integer', 'integer:Class:pathtoclass', 'varchar(x)', 'double(24,8)', 'text', 'html', 'datetime', 'timestamp', 'float') + * 'label' the translation key. + * 'enabled' is a condition when the field must be managed. + * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). Using a negative value means field is not shown by default on list but can be selected for viewing) + * 'noteditable' says if field is not editable (1 or 0) + * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). + * 'default' is a default value for creation (can still be replaced by the global setup of default values) + * 'index' if we want an index in database. + * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). + * 'position' is the sort order of field. + * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. + * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). + * 'css' is the CSS style to use on field. For example: 'maxwidth200' + * 'help' is a string visible as a tooltip on field + * 'comment' is not used. You can store here any text of your choice. It is not used by application. + * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record + * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") */ // BEGIN MODULEBUILDER PROPERTIES @@ -78,7 +87,7 @@ class EmailSenderProfile extends CommonObject public $fields=array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',), 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>-1, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,), - 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>-1), + 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>30, 'notnull'=>1), 'email' => array('type'=>'varchar(255)', 'label'=>'Email', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1), //'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), //'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,), @@ -86,7 +95,7 @@ class EmailSenderProfile extends CommonObject 'position' => array('type'=>'integer', 'label'=>'Position', 'visible'=>1, 'enabled'=>1, 'position'=>405, 'notnull'=>-1, 'index'=>1,), 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), - 'active' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1), + 'active' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'default'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1), ); /** diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index 90e3b03319c..96ac938883c 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -59,6 +59,7 @@ ALTER TABLE llx_emailcollector_emailcollectoraction ADD COLUMN position integer -- For v11 +ALTER TABLE llx_c_email_senderprofile MODIFY COLUMN active tinyint DEFAULT 1 NOT NULL; insert into llx_c_type_container (code,label,module,active) values ('menu', 'Menu', 'system', 1); diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index d704ce13cbf..d25c106bf39 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -972,6 +972,9 @@ select.flat.selectlimit { -ms-overflow-style: -ms-autohiding-scrollbar; }*/ /* Style used for most tables */ +div.fiche>div.tabBar>form>div.div-table-responsive { + min-height: 392px; +} .div-table-responsive, .div-table-responsive-no-min { overflow-x: auto; min-height: 0.01%; From 1ed2eacbef482604cd2f120b21a84a854c366a2a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 22 Nov 2019 12:40:17 +0100 Subject: [PATCH 34/44] Debug add email profile --- htdocs/admin/mails_senderprofile_list.php | 7 ++++--- htdocs/core/actions_addupdatedelete.inc.php | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/mails_senderprofile_list.php b/htdocs/admin/mails_senderprofile_list.php index a22c9d79ac5..e287db9c7c9 100644 --- a/htdocs/admin/mails_senderprofile_list.php +++ b/htdocs/admin/mails_senderprofile_list.php @@ -358,7 +358,7 @@ $newcardbutton = ''; if ($action != 'create') { $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create', '', $permissiontoadd); } else { - print ''; + /*print ''; if ($optioncss != '') print ''; print ''; print ''; @@ -366,6 +366,7 @@ if ($action != 'create') { print ''; print ''; print ''; + */ print ''; print ''; print ''; @@ -374,7 +375,7 @@ if ($action != 'create') { $doleditor = new DolEditor('signature', GETPOST('signature'), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%'); print $doleditor->Create(1); print ''; - print ''; + print ''; print ''; @@ -385,7 +386,7 @@ if ($action != 'create') { print '   '; print ''; print ''; - print ''; + //print ''; } print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit); diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index ee4208cd65e..0d718c2abc2 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -75,6 +75,7 @@ if ($action == 'add' && !empty($permissiontoadd)) if (preg_match('/^integer:/i', $object->fields[$key]['type']) && $value == '-1') $value = ''; // This is an implicit foreign key field if (!empty($object->fields[$key]['foreignkey']) && $value == '-1') $value = ''; // This is an explicit foreign key field + //var_dump($key.' '.$value.' '.$object->fields[$key]['type']); $object->$key = $value; if ($val['notnull'] > 0 && $object->$key == '' && !is_null($val['default']) && $val['default'] == '(PROV)') { From 00ad95c01e671abc6e87d1c088c2fa4e89342df0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 22 Nov 2019 14:06:43 +0100 Subject: [PATCH 35/44] Figth against useless dependencies: Remove library the core never use. --- htdocs/core/class/html.form.class.php | 1 + .../multiselect/jquery.multi-select.js | 360 ------------------ .../multiselect/jquery.multi-select.min.js | 9 - htdocs/main.inc.php | 4 - 4 files changed, 1 insertion(+), 373 deletions(-) delete mode 100644 htdocs/includes/jquery/plugins/multiselect/jquery.multi-select.js delete mode 100644 htdocs/includes/jquery/plugins/multiselect/jquery.multi-select.min.js diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index cac859c53b5..d70993be51d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6521,6 +6521,7 @@ class Form elseif ($addjscombo == 2) { // Add other js lib + // TODO external lib multiselect/jquery.multi-select.js must have been loaded to use this multiselect plugin // ... $out .= '$(document).ready(function () { $(\'#'.$htmlname.'\').multiSelect({ diff --git a/htdocs/includes/jquery/plugins/multiselect/jquery.multi-select.js b/htdocs/includes/jquery/plugins/multiselect/jquery.multi-select.js deleted file mode 100644 index ee62d1f588d..00000000000 --- a/htdocs/includes/jquery/plugins/multiselect/jquery.multi-select.js +++ /dev/null @@ -1,360 +0,0 @@ -// jquery.multi-select.js -// by mySociety -// https://github.com/mysociety/jquery-multi-select - -;(function($) { - - "use strict"; - - var pluginName = "multiSelect", - defaults = { - 'containerHTML': '
', - 'menuHTML': '
', - 'buttonHTML': '', - 'menuItemsHTML': '
', - 'menuItemHTML': '
'; print ''. ''. ''. ''. ''; // Company - $href = DOL_URL_ROOT . '/fourn/card.php?socid=' . $obj->socid; + $href = DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid; print ''; + ''. + img_object($langs->trans('ShowCompany'), 'company').' '. + $obj->name.''; // Author $userstatic->id = $obj->fk_user_author; @@ -288,7 +288,7 @@ if ($resql) if ($userstatic->id) { $txt = $userstatic->getLoginUrl(1); } else { - $txt = ' '; + $txt = ' '; } print ''; // Amount @@ -296,9 +296,9 @@ if ($resql) // Date if ($obj->dc) { - $date = dol_print_date($db->jdate($obj->dc), 'dayhour'); + $date = dol_print_date($db->jdate($obj->dc), 'dayhour'); } else { - $date = '-'; + $date = '-'; } print ''; // Statut diff --git a/htdocs/product/stock/valo.php b/htdocs/product/stock/valo.php index e814bdfaac0..816d97351b4 100644 --- a/htdocs/product/stock/valo.php +++ b/htdocs/product/stock/valo.php @@ -30,19 +30,19 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $langs->load("stocks"); // Security check -$result=restrictedArea($user, 'stock'); +$result = restrictedArea($user, 'stock'); -$sref=GETPOST("sref", 'alpha'); -$snom=GETPOST("snom", 'alpha'); -$sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml')); +$sref = GETPOST("sref", 'alpha'); +$snom = GETPOST("snom", 'alpha'); +$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); -if (! $sortfield) $sortfield="e.ref"; -if (! $sortorder) $sortorder="ASC"; +if (!$sortfield) $sortfield = "e.ref"; +if (!$sortorder) $sortorder = "ASC"; $page = $_GET["page"]; if ($page < 0) $page = 0; -$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; $year = strftime("%Y", time()); @@ -53,23 +53,23 @@ $year = strftime("%Y", time()); */ $sql = "SELECT e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays,"; -$sql.= " SUM(ps.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue"; -$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON e.rowid = ps.fk_entrepot"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid"; -$sql.= " WHERE e.entity IN (".getEntity('stock').")"; -if ($sref) $sql.= natural_search("e.ref", $sref); +$sql .= " SUM(ps.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue"; +$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON e.rowid = ps.fk_entrepot"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid"; +$sql .= " WHERE e.entity IN (".getEntity('stock').")"; +if ($sref) $sql .= natural_search("e.ref", $sref); if ($sall) { - $sql.= " AND (e.ref LIKE '%".$db->escape($sall)."%'"; - $sql.= " OR e.description LIKE '%".$db->escape($sall)."%'"; - $sql.= " OR e.lieu LIKE '%".$db->escape($sall)."%'"; - $sql.= " OR e.address LIKE '%".$db->escape($sall)."%'"; - $sql.= " OR e.town LIKE '%".$db->escape($sall)."%')"; + $sql .= " AND (e.ref LIKE '%".$db->escape($sall)."%'"; + $sql .= " OR e.description LIKE '%".$db->escape($sall)."%'"; + $sql .= " OR e.lieu LIKE '%".$db->escape($sall)."%'"; + $sql .= " OR e.address LIKE '%".$db->escape($sall)."%'"; + $sql .= " OR e.town LIKE '%".$db->escape($sall)."%')"; } -$sql.= " GROUP BY e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays"; -$sql.= $db->order($sortfield, $sortorder); -$sql.= $db->plimit($limit + 1, $offset); +$sql .= " GROUP BY e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays"; +$sql .= $db->order($sortfield, $sortorder); +$sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); if ($result) @@ -78,7 +78,7 @@ if ($result) $i = 0; - $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; + $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("", $langs->trans("EnhancedValueOfWarehouses"), $help_url); print_barre_liste($langs->trans("EnhancedValueOfWarehouses"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num); @@ -94,9 +94,9 @@ if ($result) if ($num) { - $entrepot=new Entrepot($db); + $entrepot = new Entrepot($db); $total = $totalsell = 0; - $var=false; + $var = false; while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); @@ -136,17 +136,17 @@ if ($result) print '
'; - $file='entrepot-'.$year.'.png'; + $file = 'entrepot-'.$year.'.png'; if (file_exists($conf->stock->dir_temp.'/'.$file)) { - $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file='.$file; + $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file='.$file; print ''; } - $file='entrepot-'.($year-1).'.png'; + $file = 'entrepot-'.($year - 1).'.png'; if (file_exists($conf->stock->dir_temp.'/'.$file)) { - $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file='.$file; + $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file='.$file; print '
'; } } diff --git a/htdocs/projet/info.php b/htdocs/projet/info.php index c28460e1045..ddb7673dece 100644 --- a/htdocs/projet/info.php +++ b/htdocs/projet/info.php @@ -36,34 +36,34 @@ $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); $action = GETPOST('action', 'aZ09'); -$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", "alpha"); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOST("page", 'int'); $page = is_numeric($page) ? $page : 0; $page = $page == -1 ? 0 : $page; -if (! $sortfield) $sortfield="a.datep,a.id"; -if (! $sortorder) $sortorder="DESC"; -$offset = $limit * $page ; +if (!$sortfield) $sortfield = "a.datep,a.id"; +if (!$sortorder) $sortorder = "DESC"; +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (GETPOST('actioncode', 'array')) { - $actioncode=GETPOST('actioncode', 'array', 3); - if (! count($actioncode)) $actioncode='0'; + $actioncode = GETPOST('actioncode', 'array', 3); + if (!count($actioncode)) $actioncode = '0'; } else { - $actioncode=GETPOST("actioncode", "alpha", 3)?GETPOST("actioncode", "alpha", 3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); + $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); } -$search_agenda_label=GETPOST('search_agenda_label'); +$search_agenda_label = GETPOST('search_agenda_label'); // Security check $id = GETPOST("id", 'int'); -$socid=0; +$socid = 0; //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement. -$result=restrictedArea($user, 'projet', $id, ''); +$result = restrictedArea($user, 'projet', $id, ''); if (!$user->rights->projet->lire) accessforbidden(); @@ -149,20 +149,20 @@ dol_fiche_end(); // Actions buttons -$out=''; -$permok=$user->rights->agenda->myactions->create; +$out = ''; +$permok = $user->rights->agenda->myactions->create; if ($permok) { - $out.='&projectid='.$object->id; + $out .= '&projectid='.$object->id; } //print '
'; -$morehtmlcenter=''; -if (! empty($conf->agenda->enabled)) +$morehtmlcenter = ''; +if (!empty($conf->agenda->enabled)) { - $addActionBtnRight = ! empty($user->rights->agenda->myactions->create) || ! empty($user->rights->agenda->allactions->create); - $morehtmlcenter.= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $addActionBtnRight); + $addActionBtnRight = !empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create); + $morehtmlcenter .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', $addActionBtnRight); } //print '
'; diff --git a/htdocs/resource/list.php b/htdocs/resource/list.php index e1bf458b6e4..d0f85eb9fe2 100644 --- a/htdocs/resource/list.php +++ b/htdocs/resource/list.php @@ -50,56 +50,56 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); -$search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); -if (! is_array($search_array_options)) $search_array_options = array(); -$search_ref=GETPOST("search_ref"); -$search_type=GETPOST("search_type"); +$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); +if (!is_array($search_array_options)) $search_array_options = array(); +$search_ref = GETPOST("search_ref"); +$search_type = GETPOST("search_type"); -$filter=array(); +$filter = array(); -if ($search_ref != ''){ - $param.='&search_ref='.$search_ref; - $filter['t.ref']=$search_ref; +if ($search_ref != '') { + $param .= '&search_ref='.$search_ref; + $filter['t.ref'] = $search_ref; } -if ($search_type != ''){ - $param.='&search_type='.$search_type; - $filter['ty.label']=$search_type; +if ($search_type != '') { + $param .= '&search_type='.$search_type; + $filter['ty.label'] = $search_type; } -if ($search_label != '') $param.='&search_label='.$search_label; +if ($search_label != '') $param .= '&search_label='.$search_label; // Add $param from extra fields foreach ($search_array_options as $key => $val) { - $crit=$val; - $tmpkey=preg_replace('/search_options_/', '', $key); - $typ=$extrafields->attributes[$object->table_element]['type'][$tmpkey]; + $crit = $val; + $tmpkey = preg_replace('/search_options_/', '', $key); + $typ = $extrafields->attributes[$object->table_element]['type'][$tmpkey]; if ($val != '') { - $param.='&search_options_'.$tmpkey.'='.urlencode($val); + $param .= '&search_options_'.$tmpkey.'='.urlencode($val); } - $mode_search=0; - if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric - if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int - if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1')) + $mode_search = 0; + if (in_array($typ, array('int', 'double', 'real'))) $mode_search = 1; // Search on a numeric + if (in_array($typ, array('sellist', 'link')) && $crit != '0' && $crit != '-1') $mode_search = 2; // Search on a foreign key int + if ($crit != '' && (!in_array($typ, array('select', 'sellist')) || $crit != '0') && (!in_array($typ, array('link')) || $crit != '-1')) { $filter['ef.'.$tmpkey] = natural_search('ef.'.$tmpkey, $crit, $mode_search); } } -if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; $hookmanager->initHooks(array('resourcelist')); -if (empty($sortorder)) $sortorder="ASC"; -if (empty($sortfield)) $sortfield="t.ref"; +if (empty($sortorder)) $sortorder = "ASC"; +if (empty($sortfield)) $sortfield = "t.ref"; if (empty($arch)) $arch = 0; -$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $page = GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 -$offset = $limit * $page ; +$offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if( ! $user->rights->resource->read) { +if (!$user->rights->resource->read) { accessforbidden(); } $arrayfields = array( @@ -115,10 +115,10 @@ $arrayfields = array( // Extra fields if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) { - foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val) + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { - if (! empty($extrafields->attributes[$object->table_element]['list'][$key])) - $arrayfields["ef.".$key]=array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key]<0)?0:1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key])!=3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])); } } $object->fields = dol_sort_array($object->fields, 'position'); From e36ee63ab60337c162fbb0570e2ba20c204df16c Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Fri, 22 Nov 2019 13:16:38 +0000 Subject: [PATCH 39/44] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- htdocs/commande/tpl/linkedobjectblock.tpl.php | 16 +- htdocs/compta/facture/card.php | 2 +- .../expedition/tpl/linkedobjectblock.tpl.php | 16 +- htdocs/main.inc.php | 848 +++++++++--------- htdocs/theme/eldy/style.css.php | 212 ++--- htdocs/theme/md/theme_vars.inc.php | 96 +- htdocs/ticket/tpl/linkedobjectblock.tpl.php | 18 +- htdocs/user/document.php | 66 +- 8 files changed, 637 insertions(+), 637 deletions(-) diff --git a/htdocs/commande/tpl/linkedobjectblock.tpl.php b/htdocs/commande/tpl/linkedobjectblock.tpl.php index 1b69e035fba..a593e10adf4 100644 --- a/htdocs/commande/tpl/linkedobjectblock.tpl.php +++ b/htdocs/commande/tpl/linkedobjectblock.tpl.php @@ -18,7 +18,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || ! is_object($conf)) { +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } @@ -36,14 +36,14 @@ $langs->load("orders"); $linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1); -$total=0; -$ilink=0; -foreach($linkedObjectBlock as $key => $objectlink) +$total = 0; +$ilink = 0; +foreach ($linkedObjectBlock as $key => $objectlink) { $ilink++; - $trclass='oddeven'; - if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total'; + $trclass = 'oddeven'; + if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total'; echo ''; echo ''; echo ''; echo "\n"; } if (count($linkedObjectBlock) > 1) { - echo ''; + echo ''; echo ''; echo ''; echo ''; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 0d39cda6513..f0854eabde2 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1216,7 +1216,7 @@ if (empty($reshook)) // Si facture standard $object->socid = GETPOST('socid', 'int'); $object->type = GETPOST('type'); - $object->ref = $_POST['ref']; + $object->ref = $_POST['ref']; $object->date = $dateinvoice; $object->date_pointoftax = $date_pointoftax; $object->note_public = trim(GETPOST('note_public', 'none')); diff --git a/htdocs/expedition/tpl/linkedobjectblock.tpl.php b/htdocs/expedition/tpl/linkedobjectblock.tpl.php index 1cc0e30934d..fbc1763beb3 100644 --- a/htdocs/expedition/tpl/linkedobjectblock.tpl.php +++ b/htdocs/expedition/tpl/linkedobjectblock.tpl.php @@ -17,7 +17,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || ! is_object($conf)) +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; @@ -35,14 +35,14 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; // Load translation files required by the page $langs->load("sendings"); -$total=0; -$ilink=0; -foreach($linkedObjectBlock as $key => $objectlink) +$total = 0; +$ilink = 0; +foreach ($linkedObjectBlock as $key => $objectlink) { $ilink++; - $trclass='oddeven'; - if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass.=' liste_sub_total'; + $trclass = 'oddeven'; + if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total'; ?> @@ -58,7 +58,7 @@ foreach($linkedObjectBlock as $key => $objectlink) $objectlink) } if (count($linkedObjectBlock) > 1) { ?> - + diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 2fe3dbc140a..6b17bb6f947 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -89,28 +89,28 @@ function testSqlAndScriptInject($val, $type) $inj += preg_match('/'."\n"; + print ''."\n"; } } // Global js function print ''."\n"; - print ''."\n"; + print ''."\n"; // JS forced by modules (relative url starting with /) - if (! empty($conf->modules_parts['js'])) // $conf->modules_parts['js'] is array('module'=>array('file1','file2')) + if (!empty($conf->modules_parts['js'])) // $conf->modules_parts['js'] is array('module'=>array('file1','file2')) { - $arrayjs=(array) $conf->modules_parts['js']; - foreach($arrayjs as $modjs => $filesjs) + $arrayjs = (array) $conf->modules_parts['js']; + foreach ($arrayjs as $modjs => $filesjs) { - $filesjs=(array) $filesjs; // To be sure filejs is an array - foreach($filesjs as $jsfile) + $filesjs = (array) $filesjs; // To be sure filejs is an array + foreach ($filesjs as $jsfile) { // jsfile is a relative path - print ''."\n".''."\n"; + print ''."\n".''."\n"; } } } @@ -1613,15 +1613,15 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead // Add login user link - $toprightmenu.=''."\n"; - $toprightmenu.=''; print $toprightmenu; - print "\n"; // end div class="login_block" + print "\n"; // end div class="login_block" print ''; @@ -1752,94 +1752,94 @@ function top_menu_user() global $menumanager; $userImage = $userDropDownImage = ''; - if (! empty($user->photo)) + if (!empty($user->photo)) { $userImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'photouserphoto userphoto', 'small', 0, 1); $userDropDownImage = Form::showphoto('userphoto', $user, 0, 0, 0, 'dropdown-user-image', 'small', 0, 1); } else { - $nophoto='/public/theme/common/user_anonymous.png'; - if ($user->gender == 'man') $nophoto='/public/theme/common/user_man.png'; - if ($user->gender == 'woman') $nophoto='/public/theme/common/user_woman.png'; + $nophoto = '/public/theme/common/user_anonymous.png'; + if ($user->gender == 'man') $nophoto = '/public/theme/common/user_man.png'; + if ($user->gender == 'woman') $nophoto = '/public/theme/common/user_woman.png'; $userImage = 'No photo'; $userDropDownImage = 'No photo'; } $dropdownBody = ''; - $dropdownBody.= ' '.$langs->trans("ShowMoreInfos").''; - $dropdownBody.= '
'; + $dropdownBody .= ' '.$langs->trans("ShowMoreInfos").''; + $dropdownBody .= '
'; // login infos - if (! empty($user->admin)) { - $dropdownBody.= '
' . $langs->trans("Administrator").': '.yn($user->admin); + if (!empty($user->admin)) { + $dropdownBody .= '
'.$langs->trans("Administrator").': '.yn($user->admin); } - if (! empty($user->socid)) // Add thirdparty for external users + if (!empty($user->socid)) // Add thirdparty for external users { $thirdpartystatic = new Societe($db); $thirdpartystatic->fetch($user->socid); - $companylink = ' '.$thirdpartystatic->getNomUrl(2); // picto only of company - $company=' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; + $companylink = ' '.$thirdpartystatic->getNomUrl(2); // picto only of company + $company = ' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; } - $type=($user->socid?$langs->trans("External").$company:$langs->trans("Internal")); - $dropdownBody.= '
' . $langs->trans("Type") . ': ' . $type; - $dropdownBody.= '
' . $langs->trans("Status").': '.$user->getLibStatut(0); - $dropdownBody.= '
'; + $type = ($user->socid ? $langs->trans("External").$company : $langs->trans("Internal")); + $dropdownBody .= '
'.$langs->trans("Type").': '.$type; + $dropdownBody .= '
'.$langs->trans("Status").': '.$user->getLibStatut(0); + $dropdownBody .= '
'; - $dropdownBody.= '
'.$langs->trans("Session").''; - $dropdownBody.= '
'.$langs->trans("IPAddress").': '.dol_escape_htmltag($_SERVER["REMOTE_ADDR"]); - if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $dropdownBody.= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$user->entity.')'; - $dropdownBody.= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo)?'':' (demo)'); - $dropdownBody.= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser'); - $dropdownBody.= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser'); - $dropdownBody.= '
'.$langs->trans("CurrentTheme").': '.$conf->theme; - $dropdownBody.= '
'.$langs->trans("CurrentMenuManager").': '.$menumanager->name; - $langFlag=picto_from_langcode($langs->getDefaultLang()); - $dropdownBody.= '
'.$langs->trans("CurrentUserLanguage").': '.($langFlag?$langFlag.' ':'').$langs->getDefaultLang(); - $dropdownBody.= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version?' '.$conf->browser->version:'').' ('.dol_escape_htmltag($_SERVER['HTTP_USER_AGENT']).')'; - $dropdownBody.= '
'.$langs->trans("Layout").': '.$conf->browser->layout; - $dropdownBody.= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; - if ($conf->browser->layout == 'phone') $dropdownBody.= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); - if (! empty($_SESSION["disablemodules"])) $dropdownBody.= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); - $dropdownBody.= '
'; + $dropdownBody .= '
'.$langs->trans("Session").''; + $dropdownBody .= '
'.$langs->trans("IPAddress").': '.dol_escape_htmltag($_SERVER["REMOTE_ADDR"]); + if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $dropdownBody .= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$user->entity.')'; + $dropdownBody .= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)'); + $dropdownBody .= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($user->datelastlogin, "dayhour", 'tzuser'); + $dropdownBody .= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($user->datepreviouslogin, "dayhour", 'tzuser'); + $dropdownBody .= '
'.$langs->trans("CurrentTheme").': '.$conf->theme; + $dropdownBody .= '
'.$langs->trans("CurrentMenuManager").': '.$menumanager->name; + $langFlag = picto_from_langcode($langs->getDefaultLang()); + $dropdownBody .= '
'.$langs->trans("CurrentUserLanguage").': '.($langFlag ? $langFlag.' ' : '').$langs->getDefaultLang(); + $dropdownBody .= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' ('.dol_escape_htmltag($_SERVER['HTTP_USER_AGENT']).')'; + $dropdownBody .= '
'.$langs->trans("Layout").': '.$conf->browser->layout; + $dropdownBody .= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; + if ($conf->browser->layout == 'phone') $dropdownBody .= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); + if (!empty($_SESSION["disablemodules"])) $dropdownBody .= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); + $dropdownBody .= '
'; // Execute hook - $parameters=array('user'=>$user, 'langs' => $langs); - $result=$hookmanager->executeHooks('printTopRightMenuLoginDropdownBody', $parameters); // Note that $action and $object may have been modified by some hooks + $parameters = array('user'=>$user, 'langs' => $langs); + $result = $hookmanager->executeHooks('printTopRightMenuLoginDropdownBody', $parameters); // Note that $action and $object may have been modified by some hooks if (is_numeric($result)) { - if ($result == 0){ - $dropdownBody.= $hookmanager->resPrint; // add + if ($result == 0) { + $dropdownBody .= $hookmanager->resPrint; // add } - else{ - $dropdownBody = $hookmanager->resPrint; // replace + else { + $dropdownBody = $hookmanager->resPrint; // replace } } - $logoutLink =' '.$langs->trans("Logout").''; - $profilLink =' '.$langs->trans("Card").''; + $logoutLink = ' '.$langs->trans("Logout").''; + $profilLink = ' '.$langs->trans("Card").''; $profilName = $user->getFullName($langs).' ('.$user->login.')'; - if (! empty($user->admin)) { + if (!empty($user->admin)) { $profilName = ' '.$profilName; } // Define version to show - $appli=constant('DOL_APPLICATION_TITLE'); - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) + $appli = constant('DOL_APPLICATION_TITLE'); + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { - $appli=$conf->global->MAIN_APPLICATION_TITLE; + $appli = $conf->global->MAIN_APPLICATION_TITLE; if (preg_match('/\d\.\d/', $appli)) { - if (! preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli.=" (".DOL_VERSION.")"; // If new title contains a version that is different than core + if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core } - else $appli.=" ".DOL_VERSION; + else $appli .= " ".DOL_VERSION; } - else $appli.=" ".DOL_VERSION; + else $appli .= " ".DOL_VERSION; $btnUser = ''; - if (! defined('JS_JQUERY_DISABLE_DROPDOWN')) // This may be set by some pages that use different jquery version to avoid errors + if (!defined('JS_JQUERY_DISABLE_DROPDOWN')) // This may be set by some pages that use different jquery version to avoid errors { $btnUser .= ' @@ -1919,12 +1919,12 @@ function top_menu_bookmark() $html = ''; // Define $bookmarks - if (! empty($conf->bookmark->enabled) && $user->rights->bookmark->lire) + if (!empty($conf->bookmark->enabled) && $user->rights->bookmark->lire) { include_once DOL_DOCUMENT_ROOT.'/bookmarks/bookmarks.lib.php'; $langs->load("bookmarks"); - $html.= ' + $html .= '
'.$langs->trans("Label").'
'.$langs->trans("Email").'
'.$langs->trans("Position").'
'.$langs->trans("Position").'
'.$langs->trans("Status").''; print $form->selectyesno('active', GETPOST('active', 'int'), 1); print '
'. - ''. + ''. ''. - ''. + ''. ''. - ''. + ''. ''. - ''. + ''. ''. $form->selectDate($search_date, 'search_date', 0, 0, 1, '', 1, 0, 0, ''). @@ -260,7 +260,7 @@ if ($resql) $userstatic = new User($db); - while ($i < min($num, $sproduct?$num:$conf->liste_limit)) + while ($i < min($num, $sproduct ? $num : $conf->liste_limit)) { $obj = $db->fetch_object($resql); @@ -276,11 +276,11 @@ if ($resql) print ''. - ''. - img_object($langs->trans('ShowCompany'), 'company'). ' '. - $obj->name . ''.$txt.''.$date.'
'.$langs->trans("CustomerOrder"); if (!empty($showImportButton) && $conf->global->MAIN_ENABLE_IMPORT_LINKED_OBJECT_LINES) { @@ -62,14 +62,14 @@ foreach($linkedObjectBlock as $key => $objectlink) echo ''.$objectlink->getLibStatut(3).''; // For now, shipments must stay linked to order, so link is not deletable - if($object->element != 'shipping') { + if ($object->element != 'shipping') { echo ''.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').''; } echo '
'.$langs->trans("Total").'
trans("Shipment"); ?> element != 'commande') { + if ($object->element != 'commande') { ?> ">transnoentitiesnoconv("RemoveLink"), 'unlink'); ?>
trans("Total"); ?>