From ae2ddb1f1e30fd3aa14f47fe1c39352ce6fa8ad4 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Nov 2019 16:36:07 +0100 Subject: [PATCH 01/28] Fix adherent type v11 --- .../adherents/class/adherent_type.class.php | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 5d992b168d4..56410c6439a 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -507,6 +507,7 @@ class AdherentType extends CommonObject $this->label = $obj->label; $this->morphy = $obj->morphy; $this->statut = $obj->statut; + $this->status = $obj->statut; $this->duration = $obj->duration; $this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration)-1); $this->duration_unit = substr($obj->duration, -1); @@ -668,14 +669,42 @@ class AdherentType extends CommonObject return $result; } - /** - * getLibStatut - * - * @return string Return status of a type of member - */ - public function getLibStatut() - { - return ''; + /** + * Return label of status (activity, closed) + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status + */ + public function getLibStatut($mode = 0) + { + return $this->LibStatut($this->status, $mode); + } + + /** + * Return the label of a given status + * + * @param int $status Status id + * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Status label + */ + public function LibStatut($status, $mode = 0) + { + // phpcs:enable + global $langs; + $langs->load('companies'); + + $statusType = 'status4'; + if ($status == 0) $statusType = 'status5'; + + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { + $this->labelStatus[0] = $langs->trans("ActivityCeased"); + $this->labelStatus[1] = $langs->trans("InActivity"); + $this->labelStatusShort[0] = $langs->trans("ActivityCeased"); + $this->labelStatusShort[1] = $langs->trans("InActivity"); + } + + return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps From 280c0a56b6e0912cb6a712dc8fbb3b3610a99d11 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 14 Nov 2019 15:37:54 +0000 Subject: [PATCH 02/28] Fixing style errors. --- htdocs/adherents/class/adherent_type.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 56410c6439a..77fa991d07f 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -679,7 +679,7 @@ class AdherentType extends CommonObject { return $this->LibStatut($this->status, $mode); } - + /** * Return the label of a given status * From fee8e33e2b6f8d41a422a73975ae30d53bee4d78 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Nov 2019 16:58:17 +0100 Subject: [PATCH 03/28] Update type.php --- htdocs/adherents/type.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index d98dcd9f693..f49dd73874a 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -226,7 +226,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') { //dol_fiche_head(''); - $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.vote, d.statut, d.morphy"; + $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.vote, d.statut as status, d.morphy"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; $sql .= " WHERE d.entity IN (".getEntity('member_type').")"; @@ -280,7 +280,8 @@ if (!$rowid && $action != 'create' && $action != 'edit') $membertype->id = $objp->rowid; $membertype->ref = $objp->rowid; $membertype->label = $objp->rowid; - + $membertype->status = $objp->status; + print ''; print ''; print $membertype->getNomUrl(1); @@ -294,13 +295,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') print ''; print ''.yn($objp->subscription).''; print ''.yn($objp->vote).''; - print ''; - if (!empty($objp->statut)) { - print img_picto($langs->trans("InActivity"), 'statut4'); - } else { - print img_picto($langs->trans("ActivityCeased"), 'statut5'); - } - print ''; + print ''.$membertype->getLibStatut(5).''; if ($user->rights->adherent->configurer) print 'rowid.'">'.img_edit().''; else @@ -432,15 +427,7 @@ if ($rowid > 0) print ''; - print ''; - - // Morphy + // Morphy print ''; print ''; From 07880dd835521f4d856b476de60b498b90c2e4a5 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 14 Nov 2019 16:00:08 +0000 Subject: [PATCH 04/28] Fixing style errors. --- htdocs/adherents/type.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index f49dd73874a..b1b18e3ed31 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -280,8 +280,8 @@ if (!$rowid && $action != 'create' && $action != 'edit') $membertype->id = $objp->rowid; $membertype->ref = $objp->rowid; $membertype->label = $objp->rowid; - $membertype->status = $objp->status; - + $membertype->status = $objp->status; + print ''; print '
'.$langs->trans("Status").''; - if (!empty($object->statut)) { - print img_picto($langs->trans('TypeStatusActive'), 'statut4').' '.$langs->trans("InActivity"); - } else { - print img_picto($langs->trans('TypeStatusInactive'), 'statut5').' '.$langs->trans("ActivityCeased"); - } - print '
'.$langs->trans("MemberNature").''.$object->getmorphylib($object->morphy).'
'; print $membertype->getNomUrl(1); @@ -427,7 +427,7 @@ if ($rowid > 0) print ''; - // Morphy + // Morphy print ''; print ''; From 4ea3fe7609c3302b42b965fb354816320876f609 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Thu, 14 Nov 2019 17:57:29 +0100 Subject: [PATCH 05/28] NEW get user connected informations in REST API --- htdocs/user/class/api_users.class.php | 83 +++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index 778823d3d7d..a7d98ca0b2d 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -108,6 +108,7 @@ class Users extends DolibarrApi if ($result) { + $i = 0; $num = $db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); while ($i < $min) @@ -159,6 +160,41 @@ class Users extends DolibarrApi return $this->_cleanObjectDatas($this->useraccount); } + /** + * Get properties of user connected + * + * @url GET /info + * + * @return array|mixed Data without useless information + * + * @throws 401 RestException Insufficient rights + * @throws 404 RestException User not found + * @throws 404 RestException User group not found + */ + public function getInfo() + { + $apiUser = DolibarrApiAccess::$user; + + $result = $this->useraccount->fetch($apiUser->id); + if (!$result) { + throw new RestException(404, 'User not found'); + } + + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + + $usergroup = new UserGroup($this->db); + $userGroupList = $usergroup->listGroupsForUser($apiUser->id, false); + if (!is_array($userGroupList)) { + throw new RestException(404, 'User group not found'); + } + + $this->useraccount = $this->_cleanObjectDatas($this->useraccount); + $this->useraccount->user_group_list = $this->_cleanUserGroupListDatas($userGroupList); + + return $this->useraccount; + } /** * Create user account @@ -414,6 +450,53 @@ class Users extends DolibarrApi return $object; } + /** + * Clean sensible user group list datas + * + * @param array $objectList Array of object to clean + * @return array Array of cleaned object properties + */ + private function _cleanUserGroupListDatas($objectList) + { + $cleanObjectList = array(); + + foreach ($objectList as $object) { + $cleanObject = parent::_cleanObjectDatas($object); + + unset($cleanObject->default_values); + unset($cleanObject->lastsearch_values); + unset($cleanObject->lastsearch_values_tmp); + + unset($cleanObject->total_ht); + unset($cleanObject->total_tva); + unset($cleanObject->total_localtax1); + unset($cleanObject->total_localtax2); + unset($cleanObject->total_ttc); + + unset($cleanObject->libelle_incoterms); + unset($cleanObject->location_incoterms); + + unset($cleanObject->fk_delivery_address); + unset($cleanObject->fk_incoterms); + unset($cleanObject->all_permissions_are_loaded); + unset($cleanObject->shipping_method_id); + unset($cleanObject->nb_rights); + unset($cleanObject->search_sid); + unset($cleanObject->ldap_sid); + unset($cleanObject->clicktodial_loaded); + + unset($cleanObject->datec); + unset($cleanObject->datem); + unset($cleanObject->members); + unset($cleanObject->note); + unset($cleanObject->note_private); + + $cleanObjectList[] = $cleanObject; + } + + return $cleanObjectList; + } + /** * Validate fields before create or update object * From fc55123af0b9b37b9afca4ade68a49919cdf6723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 14 Nov 2019 18:31:09 +0100 Subject: [PATCH 06/28] Update api_thirdparties.class.php --- htdocs/societe/class/api_thirdparties.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index b8fbb099fb3..8a29d653912 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -112,7 +112,7 @@ class Thirdparties extends DolibarrApi */ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $sqlfilters = '') { - global $db, $conf; + global $db; $obj_ret = array(); @@ -137,7 +137,7 @@ class Thirdparties extends DolibarrApi $sql .= ' AND t.entity IN ('.getEntity('societe').')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; - if ($socid) $sql .= " AND t.rowid IN (".$socids.")"; + if ($socids) $sql .= " AND t.rowid IN (".$socids.")"; if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale // Insert sale filter if ($search_sale > 0) @@ -172,6 +172,7 @@ class Thirdparties extends DolibarrApi { $num = $db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); + $i = 0; while ($i < $min) { $obj = $db->fetch_object($result); @@ -1722,7 +1723,7 @@ class Thirdparties extends DolibarrApi * * Return an array with thirdparty informations * - * @param int $rowid Id of third party to load + * @param int $rowid Id of third party to load * @param string $ref Reference of third party, name (Warning, this can return several records) * @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) * @param string $ref_int Internal reference of third party (not used by dolibarr) @@ -1740,6 +1741,7 @@ class Thirdparties extends DolibarrApi */ private function _fetch($rowid, $ref = '', $ref_ext = '', $ref_int = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '') { + global $conf; if(! DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } From 1936b11db81173b6a4d3fb6b28df9b8eb8df1eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 14 Nov 2019 18:40:30 +0100 Subject: [PATCH 07/28] doxygen --- htdocs/user/class/user.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a2083f35bec..c5a3add278d 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2083,9 +2083,9 @@ class User extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Read clicktodial information for user + * Read clicktodial information for user * - * @return <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK */ public function fetch_clicktodial() { @@ -2123,7 +2123,7 @@ class User extends CommonObject /** * Update clicktodial info * - * @return integer + * @return int <0 if KO, >0 if OK */ public function update_clicktodial() { From 91eb6eb7d7af9c5879355d0411647729873c1cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 14 Nov 2019 18:44:18 +0100 Subject: [PATCH 08/28] Update user.class.php --- htdocs/user/class/user.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index c5a3add278d..4144a27685b 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2886,7 +2886,7 @@ class User extends CommonObject /** * Return and array with all instanciated first level children users of current user * - * @return void + * @return User[]|int * @see getAllChildIds() */ public function get_children() From e73202c2af6565ed82799cf944694a4a673a9f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 14 Nov 2019 18:47:16 +0100 Subject: [PATCH 09/28] Update user.class.php --- htdocs/user/class/user.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 4144a27685b..104ff767299 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2895,7 +2895,7 @@ class User extends CommonObject $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."user"; $sql .= " WHERE fk_user = ".$this->id; - dol_syslog(get_class($this)."::get_children result=".$result, LOG_DEBUG); + dol_syslog(get_class($this)."::get_children sql=".$sql, LOG_DEBUG); $res = $this->db->query($sql); if ($res) { From 67d05cae1baf2d6859e46c01384f9856cf22ecce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 14 Nov 2019 19:06:14 +0100 Subject: [PATCH 10/28] doxygen --- htdocs/projet/class/project.class.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index f969679a9f6..0ec6652f20b 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -88,6 +88,15 @@ class Project extends CommonObject public $thirdparty_name; // To store name of thirdparty (defined only in some cases) public $user_author_id; //!< Id of project creator. Not defined if shared project. + + /** + * @var int user close id + */ + public $fk_user_close; + + /** + * @var int user close id + */ public $user_close_id; public $public; //!< Tell if this is a public or private project public $budget_amount; From 892b61f1c2872d4218ba44a839356021564d5fdb Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Nov 2019 20:02:44 +0100 Subject: [PATCH 11/28] Update adherent_type.class.php --- htdocs/adherents/class/adherent_type.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 77fa991d07f..304f54b4c30 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -627,7 +627,8 @@ class AdherentType extends CommonObject return -1; } } - + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return translated label by the nature of a adherent (physical or moral) * @@ -642,7 +643,8 @@ class AdherentType extends CommonObject else return $langs->trans("MorPhy"); //return $morphy; } - + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return clicable name (with picto eventually) * From f369fa06a61aca17ab8b3ecb7bc44341c3798d1f Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 14 Nov 2019 19:04:18 +0000 Subject: [PATCH 12/28] Fixing style errors. --- htdocs/adherents/class/adherent_type.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 304f54b4c30..cb1f80bb081 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -627,7 +627,7 @@ class AdherentType extends CommonObject return -1; } } - + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return translated label by the nature of a adherent (physical or moral) @@ -643,7 +643,7 @@ class AdherentType extends CommonObject else return $langs->trans("MorPhy"); //return $morphy; } - + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return clicable name (with picto eventually) From fc2e0d4f9544b2df718c3c2ba112da9088bddc1e Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Nov 2019 20:09:36 +0100 Subject: [PATCH 13/28] Update adherent_type.class.php --- htdocs/adherents/class/adherent_type.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index cb1f80bb081..a658cff86b8 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -671,6 +671,7 @@ class AdherentType extends CommonObject return $result; } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return label of status (activity, closed) * From 332c91aa11ccdd91d118e248b8689871cb80c94c Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Thu, 14 Nov 2019 20:10:14 +0100 Subject: [PATCH 14/28] Update adherent_type.class.php --- htdocs/adherents/class/adherent_type.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index a658cff86b8..14a0c0186a5 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -628,7 +628,6 @@ class AdherentType extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return translated label by the nature of a adherent (physical or moral) * @@ -644,7 +643,6 @@ class AdherentType extends CommonObject //return $morphy; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return clicable name (with picto eventually) * From 71003281168583e6d0d8edd01be81223b5971a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 14 Nov 2019 21:25:12 +0100 Subject: [PATCH 15/28] doxygen menubase class --- htdocs/core/class/menubase.class.php | 95 +++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index d47146abc64..3af8d3924a8 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2009-2012 Regis Houssin - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2019 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,17 +45,32 @@ class Menubase public $errors = array(); /** - * @var int ID - */ - public $id; + * @var int ID + */ + public $id; + /** + * @var string Menu handler + */ public $menu_handler; + + /** + * @var string Module name if record is added by a module + */ public $module; + + /** + * @var string Menu top or left + */ public $type; + + /** + * @var string Name family/module for top menu (home, companies, ...) + */ public $mainmenu; /** - * @var int ID + * @var int 0 or Id of mother menu line, or -1 if we use fk_mainmenu and fk_leftmenu */ public $fk_menu; @@ -70,23 +85,71 @@ class Menubase public $fk_leftmenu; /** - * @var int position + * @var int Sort order of entry */ public $position; + + /** + * @var string Relative (or absolute) url to go + */ public $url; + + /** + * @var string Target of Url link + */ public $target; + + /** + * @var string Key for menu translation + * @deprecated + * @see title + */ public $titre; + + /** + * @var string Key for menu translation + */ + public $title; + + /** + * @var string Lang file to load for translation + */ public $langs; + + /** + * @var string Not used + * @deprecated + */ public $level; - public $leftmenu; //langs=trim($this->langs); $this->perms=trim($this->perms); $this->enabled=trim($this->enabled); - $this->user=trim($this->user); + $this->user = (int) $this->user; if (empty($this->position)) $this->position=0; if (! $this->level) $this->level=0; @@ -246,7 +309,7 @@ class Menubase */ public function update($user = null, $notrigger = 0) { - global $conf, $langs; + //global $conf, $langs; // Clean parameters $this->rowid=trim($this->rowid); @@ -265,7 +328,7 @@ class Menubase $this->langs=trim($this->langs); $this->perms=trim($this->perms); $this->enabled=trim($this->enabled); - $this->user=trim($this->user); + $this->user = (int) $this->user; // Check parameters // Put here code to add control on parameters values @@ -311,7 +374,7 @@ class Menubase */ public function fetch($id, $user = null) { - global $langs; + //global $langs; $sql = "SELECT"; $sql.= " t.rowid,"; @@ -385,7 +448,7 @@ class Menubase */ public function delete($user) { - global $conf, $langs; + //global $conf, $langs; $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; $sql.= " WHERE rowid=".$this->id; From 837c7276aba8ab2df1cda27fb2a4b61b18c702f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 14 Nov 2019 21:57:21 +0100 Subject: [PATCH 16/28] API New get categories linked to an object --- .../categories/class/api_categories.class.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 0f2a425fe87..5b8f0cdbe39 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -264,6 +264,41 @@ class Categories extends DolibarrApi ) ); } + + /** + * List categories of an object + * + * Get the list of categories linked to an object + * + * @param int $id Object ID + * @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact') + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @return array Array of category objects + * + * @throws RestException + * + * @url GET /object/{type}/{id} + */ + public function getListForObject($id, $type = 'customer', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + { + // TODO add other types + if (!in_array($type, ['product'/*, 'member', 'customer', 'supplier', 'contact'*/])) { + throw new RestException(401); + } + + if($type == 'product' && ! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + throw new RestException(401); + } + + $categories = $this->category->getListForItem($id, $type, $sortfield, $sortorder, $limit, $page); + + if( ! count($categories)) { + throw new RestException(404, 'No category found for this object'); + } + return $categories; + } /** * Link an object to a category by id From b2d18a8e0c011f5011c42450eb4cacdd3fb4335b Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 14 Nov 2019 20:56:31 +0000 Subject: [PATCH 17/28] Fixing style errors. --- htdocs/categories/class/api_categories.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 5b8f0cdbe39..92ce17642ab 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -264,7 +264,7 @@ class Categories extends DolibarrApi ) ); } - + /** * List categories of an object * @@ -278,7 +278,7 @@ class Categories extends DolibarrApi * @return array Array of category objects * * @throws RestException - * + * * @url GET /object/{type}/{id} */ public function getListForObject($id, $type = 'customer', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) @@ -287,13 +287,13 @@ class Categories extends DolibarrApi if (!in_array($type, ['product'/*, 'member', 'customer', 'supplier', 'contact'*/])) { throw new RestException(401); } - + if($type == 'product' && ! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } - + $categories = $this->category->getListForItem($id, $type, $sortfield, $sortorder, $limit, $page); - + if( ! count($categories)) { throw new RestException(404, 'No category found for this object'); } From 88692fe95d62628a7d4fd89fd0fd4aa2c86e71ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 14 Nov 2019 22:00:46 +0100 Subject: [PATCH 18/28] Doc for $page --- htdocs/categories/class/api_categories.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 92ce17642ab..a202ee97df9 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -275,6 +275,7 @@ class Categories extends DolibarrApi * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list + * @param int $page Page number * @return array Array of category objects * * @throws RestException From 100827ae0be85e0891f2879cde9050beaac00caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 14 Nov 2019 22:16:08 +0100 Subject: [PATCH 19/28] Fix error process --- htdocs/categories/class/api_categories.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index a202ee97df9..d532c481c24 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -295,8 +295,11 @@ class Categories extends DolibarrApi $categories = $this->category->getListForItem($id, $type, $sortfield, $sortorder, $limit, $page); - if( ! count($categories)) { - throw new RestException(404, 'No category found for this object'); + if( ! is_array($categories)) { + if ($categories == 0) { + throw new RestException(404, 'No category found for this object'); + } + throw new RestException(500, 'Error when fetching object categories', array_merge(array($this->category->error), $this->category->errors)); } return $categories; } From 0f907fbc297143dcdec0d58a79c97f6d4817e680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 14 Nov 2019 22:26:15 +0100 Subject: [PATCH 20/28] $type is mandatory --- htdocs/categories/class/api_categories.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index d532c481c24..5cb733789ee 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -282,7 +282,7 @@ class Categories extends DolibarrApi * * @url GET /object/{type}/{id} */ - public function getListForObject($id, $type = 'customer', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + public function getListForObject($id, $type, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { // TODO add other types if (!in_array($type, ['product'/*, 'member', 'customer', 'supplier', 'contact'*/])) { From 0c9b4fe16b3a72445722107f465443242de89007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Thu, 14 Nov 2019 22:36:16 +0100 Subject: [PATCH 21/28] Add all types --- htdocs/categories/class/api_categories.class.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 5cb733789ee..aa908ec7965 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -284,14 +284,21 @@ class Categories extends DolibarrApi */ public function getListForObject($id, $type, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { - // TODO add other types - if (!in_array($type, ['product'/*, 'member', 'customer', 'supplier', 'contact'*/])) { + if (!in_array($type, ['product', 'member', 'customer', 'supplier', 'contact'])) { throw new RestException(401); } - if($type == 'product' && ! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { + if($type == Categorie::TYPE_PRODUCT && ! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); - } + } elseif ($type == Categorie::TYPE_CONTACT && ! DolibarrApiAccess::$user->rights->contact->lire) { + throw new RestException(401); + } elseif ($type == Categorie::TYPE_CUSTOMER && ! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } elseif ($type == Categorie::TYPE_SUPPLIER && ! DolibarrApiAccess::$user->rights->fournisseur->lire) { + throw new RestException(401); + } elseif ($type == Categorie::TYPE_MEMBER && ! DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } $categories = $this->category->getListForItem($id, $type, $sortfield, $sortorder, $limit, $page); From bb8a4e9efcbb1ca93353322963821576c6742339 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 15 Nov 2019 09:02:21 +0100 Subject: [PATCH 22/28] FIX better look compatibility with Multicompany --- htdocs/user/card.php | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index e522f542621..1430ccc8483 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -2005,15 +2005,6 @@ else } } - if ($caneditgroup) - { - print '
'."\n"; - print ''; - print ''; - } - - print '
'.$langs->trans("MemberNature").''.$object->getmorphylib($object->morphy).'
'."\n"; - // Other form for add user to group $parameters = array('caneditgroup' => $caneditgroup, 'groupslist' => $groupslist, 'exclude' => $exclude); $reshook = $hookmanager->executeHooks('formAddUserToGroup', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -2021,6 +2012,14 @@ else if (empty($reshook)) { + if ($caneditgroup) + { + print ''."\n"; + print ''; + print ''; + } + + print '
'."\n"; print ''."\n"; print ''; } - } - print "
'.$langs->trans("Groups").''; if ($caneditgroup) @@ -2068,15 +2067,15 @@ else { print '
'.$langs->trans("None").'
"; + print "
"; - if ($caneditgroup) - { - print ''; + if ($caneditgroup) + { + print ''; + } + print "
"; } - print "
"; } } } From fa3c63ea28f4872b24f73f5f3eb579a94b53c7e4 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 14:47:08 +0100 Subject: [PATCH 23/28] API New can include childs when get a category --- htdocs/categories/class/api_categories.class.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index aa908ec7965..ffbfff4d90f 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -71,11 +71,12 @@ class Categories extends DolibarrApi * Return an array with category informations * * @param int $id ID of category + * @param bool $include_childs Include child categories list (true or false) * @return array|mixed data without useless information * * @throws RestException */ - public function get($id) + public function get($id, $include_childs = false) { if (! DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); @@ -89,6 +90,17 @@ class Categories extends DolibarrApi if ( ! DolibarrApi::_checkAccessToResource('categorie', $this->category->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } + + if ($include_childs) { + $cats = $this->category->get_filles(); + if (!is_array($cats)) { + throw new RestException(500, 'Error when fetching child categories', array_merge(array($this->category->error), $this->category->errors)); + } + $this->category->childs = []; + foreach ($cats as $cat) { + $this->category->childs[] = $this->_cleanObjectDatas($cat); + } + } return $this->_cleanObjectDatas($this->category); } From cc6d8f159bf102f8b8a81541680d15b2b0d1896d Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 15 Nov 2019 13:47:40 +0000 Subject: [PATCH 24/28] Fixing style errors. --- htdocs/categories/class/api_categories.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index ffbfff4d90f..3dff8066070 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -90,7 +90,7 @@ class Categories extends DolibarrApi if ( ! DolibarrApi::_checkAccessToResource('categorie', $this->category->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if ($include_childs) { $cats = $this->category->get_filles(); if (!is_array($cats)) { From 71a683658887123fc896330705acf53dc5e0f5dc 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 16:12:35 +0100 Subject: [PATCH 25/28] Implement categorie field ref_ext --- htdocs/categories/class/categorie.class.php | 25 ++++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 033f3f38100..6bbc0afcb1c 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -240,25 +240,30 @@ class Categorie extends CommonObject /** * Load category into memory from database * - * @param int $id Id of category - * @param string $label Label of category - * @param string $type Type of category ('product', '...') or (0, 1, ...) + * @param int $id Id of category + * @param string $label Label of category + * @param string $type Type of category ('product', '...') or (0, 1, ...) + * @param string $ref_ext External reference of object * @return int <0 if KO, >0 if OK */ - public function fetch($id, $label = '', $type = null) + public function fetch($id, $label = '', $type = null, $ref_ext = '') { global $conf; // Check parameters - if (empty($id) && empty($label)) return -1; + if (empty($id) && empty($label) && empty($ref_ext)) return -1; if (!is_numeric($type)) $type = $this->MAP_ID[$type]; - $sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type"; + $sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type, ref_ext"; $sql .= " FROM ".MAIN_DB_PREFIX."categorie"; if ($id > 0) { $sql .= " WHERE rowid = ".$id; } + elseif (!empty($ref_ext)) + { + $sql .= " WHERE ref_ext LIKE '".$this->db->escape($ref_ext)."'"; + } else { $sql .= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")"; @@ -282,6 +287,7 @@ class Categorie extends CommonObject $this->socid = $res['fk_soc']; $this->visible = $res['visible']; $this->type = $res['type']; + $this->ref_ext = $res['ref_ext']; $this->entity = $res['entity']; // Retreive all extrafield @@ -334,6 +340,7 @@ class Categorie extends CommonObject $this->description = trim($this->description); $this->color = trim($this->color); $this->import_key = trim($this->import_key); + $this->ref_ext = trim($this->ref_ext); if (empty($this->visible)) $this->visible = 0; $this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0); @@ -359,6 +366,7 @@ class Categorie extends CommonObject $sql .= " visible,"; $sql .= " type,"; $sql .= " import_key,"; + $sql .= " ref_ext,"; $sql .= " entity"; $sql .= ") VALUES ("; $sql .= $this->db->escape($this->fk_parent).","; @@ -372,6 +380,7 @@ class Categorie extends CommonObject $sql .= "'".$this->db->escape($this->visible)."',"; $sql .= $this->db->escape($type).","; $sql .= (!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : 'null').","; + $sql .= (!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : 'null').","; $sql .= $this->db->escape($conf->entity); $sql .= ")"; @@ -446,6 +455,7 @@ class Categorie extends CommonObject // Clean parameters $this->label = trim($this->label); $this->description = trim($this->description); + $this->ref_ext = trim($this->ref_ext); $this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0); $this->visible = ($this->visible != "" ? intval($this->visible) : 0); @@ -461,6 +471,7 @@ class Categorie extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."categorie"; $sql .= " SET label = '".$this->db->escape($this->label)."',"; $sql .= " description = '".$this->db->escape($this->description)."',"; + $sql .= " ref_ext = '".$this->db->escape($this->ref_ext)."',"; $sql .= " color = '".$this->db->escape($this->color)."'"; if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) { @@ -918,6 +929,7 @@ class Categorie extends CommonObject $categories[$i]['description'] = $category_static->description; $categories[$i]['color'] = $category_static->color; $categories[$i]['socid'] = $category_static->socid; + $categories[$i]['ref_ext'] = $category_static->ref_ext; $categories[$i]['visible'] = $category_static->visible; $categories[$i]['type'] = $category_static->type; $categories[$i]['entity'] = $category_static->entity; @@ -1082,6 +1094,7 @@ class Categorie extends CommonObject $this->cats[$obj->rowid]['description'] = !empty($obj->description_trans) ? $obj->description_trans : $obj->description; $this->cats[$obj->rowid]['color'] = $obj->color; $this->cats[$obj->rowid]['visible'] = $obj->visible; + $this->cats[$obj->rowid]['ref_ext'] = $obj->ref_ext; $i++; } } From 4332834ff7cd0b28ecab32837f889c97c22569dd 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 23:08:25 +0100 Subject: [PATCH 26/28] Add all types everywhere --- .../categories/class/api_categories.class.php | 118 +++++++++++++++--- 1 file changed, 100 insertions(+), 18 deletions(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 3dff8066070..d1b2973041e 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -296,21 +296,27 @@ class Categories extends DolibarrApi */ public function getListForObject($id, $type, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { - if (!in_array($type, ['product', 'member', 'customer', 'supplier', 'contact'])) { + if (!in_array($type, [ + Categorie::TYPE_PRODUCT, + Categorie::TYPE_CONTACT, + Categorie::TYPE_CUSTOMER, + Categorie::TYPE_SUPPLIER, + Categorie::TYPE_MEMBER + ])) { throw new RestException(401); } - + if($type == Categorie::TYPE_PRODUCT && ! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } elseif ($type == Categorie::TYPE_CONTACT && ! DolibarrApiAccess::$user->rights->contact->lire) { throw new RestException(401); - } elseif ($type == Categorie::TYPE_CUSTOMER && ! DolibarrApiAccess::$user->rights->societe->lire) { + } elseif ($type == Categorie::TYPE_CUSTOMER && ! DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); - } elseif ($type == Categorie::TYPE_SUPPLIER && ! DolibarrApiAccess::$user->rights->fournisseur->lire) { + } elseif ($type == Categorie::TYPE_SUPPLIER && ! DolibarrApiAccess::$user->rights->fournisseur->lire) { throw new RestException(401); - } elseif ($type == Categorie::TYPE_MEMBER && ! DolibarrApiAccess::$user->rights->adherent->lire) { + } elseif ($type == Categorie::TYPE_MEMBER && ! DolibarrApiAccess::$user->rights->adherent->lire) { throw new RestException(401); - } + } $categories = $this->category->getListForItem($id, $type, $sortfield, $sortorder, $limit, $page); @@ -349,13 +355,32 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - - // TODO Add all types - if ($type === "product") { + + if ($type === Categorie::TYPE_PRODUCT) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); } $object = new Product($this->db); + } elseif ($type === Categorie::TYPE_CUSTOMER) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $object = new Societe($this->db); + } elseif ($type === Categorie::TYPE_SUPPLIER) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $object = new Societe($this->db); + } elseif ($type === Categorie::TYPE_CONTACT) { + if(! DolibarrApiAccess::$user->rights->societe->contact->creer) { + throw new RestException(401); + } + $object = new Contact($this->db); + } elseif ($type === Categorie::TYPE_MEMBER) { + if(! DolibarrApiAccess::$user->rights->adherent->creer) { + throw new RestException(401); + } + $object = new Adherent($this->db); } else { throw new RestException(401, "this type is not recognized yet."); } @@ -410,13 +435,32 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - - // TODO Add all types - if ($type === "product") { + + if ($type === Categorie::TYPE_PRODUCT) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); } $object = new Product($this->db); + } elseif ($type === Categorie::TYPE_CUSTOMER) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $object = new Societe($this->db); + } elseif ($type === Categorie::TYPE_SUPPLIER) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $object = new Societe($this->db); + } elseif ($type === Categorie::TYPE_CONTACT) { + if(! DolibarrApiAccess::$user->rights->societe->contact->creer) { + throw new RestException(401); + } + $object = new Contact($this->db); + } elseif ($type === Categorie::TYPE_MEMBER) { + if(! DolibarrApiAccess::$user->rights->adherent->creer) { + throw new RestException(401); + } + $object = new Adherent($this->db); } else { throw new RestException(401, "this type is not recognized yet."); } @@ -471,13 +515,32 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - - // TODO Add all types - if ($type === "product") { + + if ($type === Categorie::TYPE_PRODUCT) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); } $object = new Product($this->db); + } elseif ($type === Categorie::TYPE_CUSTOMER) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $object = new Societe($this->db); + } elseif ($type === Categorie::TYPE_SUPPLIER) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $object = new Societe($this->db); + } elseif ($type === Categorie::TYPE_CONTACT) { + if(! DolibarrApiAccess::$user->rights->societe->contact->creer) { + throw new RestException(401); + } + $object = new Contact($this->db); + } elseif ($type === Categorie::TYPE_MEMBER) { + if(! DolibarrApiAccess::$user->rights->adherent->creer) { + throw new RestException(401); + } + $object = new Adherent($this->db); } else { throw new RestException(401, "this type is not recognized yet."); } @@ -530,13 +593,32 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - - // TODO Add all types - if ($type === "product") { + + if ($type === Categorie::TYPE_PRODUCT) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); } $object = new Product($this->db); + } elseif ($type === Categorie::TYPE_CUSTOMER) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $object = new Societe($this->db); + } elseif ($type === Categorie::TYPE_SUPPLIER) { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + $object = new Societe($this->db); + } elseif ($type === Categorie::TYPE_CONTACT) { + if(! DolibarrApiAccess::$user->rights->societe->contact->creer) { + throw new RestException(401); + } + $object = new Contact($this->db); + } elseif ($type === Categorie::TYPE_MEMBER) { + if(! DolibarrApiAccess::$user->rights->adherent->creer) { + throw new RestException(401); + } + $object = new Adherent($this->db); } else { throw new RestException(401, "this type is not recognized yet."); } From 17667d6a1be453e7b6195f122811320ddf2396bd Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 15 Nov 2019 22:08:56 +0000 Subject: [PATCH 27/28] Fixing style errors. --- htdocs/categories/class/api_categories.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index d1b2973041e..e916255f7b5 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -305,7 +305,7 @@ class Categories extends DolibarrApi ])) { throw new RestException(401); } - + if($type == Categorie::TYPE_PRODUCT && ! (DolibarrApiAccess::$user->rights->produit->lire || DolibarrApiAccess::$user->rights->service->lire)) { throw new RestException(401); } elseif ($type == Categorie::TYPE_CONTACT && ! DolibarrApiAccess::$user->rights->contact->lire) { @@ -355,7 +355,7 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - + if ($type === Categorie::TYPE_PRODUCT) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); @@ -435,7 +435,7 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - + if ($type === Categorie::TYPE_PRODUCT) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); @@ -515,7 +515,7 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - + if ($type === Categorie::TYPE_PRODUCT) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); @@ -593,7 +593,7 @@ class Categories extends DolibarrApi if( ! $result ) { throw new RestException(404, 'category not found'); } - + if ($type === Categorie::TYPE_PRODUCT) { if(! (DolibarrApiAccess::$user->rights->produit->creer || DolibarrApiAccess::$user->rights->service->creer)) { throw new RestException(401); From d2aa4ba54e3d2b3dc2492c8ce24d8116c370f55c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 16 Nov 2019 00:41:55 +0100 Subject: [PATCH 28/28] Update adherent_type.class.php --- htdocs/adherents/class/adherent_type.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 14a0c0186a5..5006becb053 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -489,7 +489,7 @@ class AdherentType extends CommonObject { global $langs, $conf; - $sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut, d.duration, d.subscription, d.mail_valid, d.note, d.vote"; + $sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.mail_valid, d.note, d.vote"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d"; $sql .= " WHERE d.rowid = ".(int) $rowid; @@ -506,8 +506,8 @@ class AdherentType extends CommonObject $this->ref = $obj->rowid; $this->label = $obj->label; $this->morphy = $obj->morphy; - $this->statut = $obj->statut; - $this->status = $obj->statut; + $this->statut = $obj->status; // deprecated + $this->status = $obj->status; $this->duration = $obj->duration; $this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration)-1); $this->duration_unit = substr($obj->duration, -1);