diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 5d992b168d4..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,7 +506,8 @@ class AdherentType extends CommonObject $this->ref = $obj->rowid; $this->label = $obj->label; $this->morphy = $obj->morphy; - $this->statut = $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); @@ -668,14 +669,43 @@ class AdherentType extends CommonObject return $result; } - /** - * getLibStatut - * - * @return string Return status of a type of member - */ - public function getLibStatut() - { - return ''; + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * 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 diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index d98dcd9f693..b1b18e3ed31 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,6 +280,7 @@ if (!$rowid && $action != 'create' && $action != 'edit') $membertype->id = $objp->rowid; $membertype->ref = $objp->rowid; $membertype->label = $objp->rowid; + $membertype->status = $objp->status; print ''; print ''; @@ -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 ''; diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 0f2a425fe87..e916255f7b5 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); @@ -90,6 +91,17 @@ class Categories extends DolibarrApi 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); } @@ -265,6 +277,58 @@ 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 + * @param int $page Page number + * @return array Array of category objects + * + * @throws RestException + * + * @url GET /object/{type}/{id} + */ + public function getListForObject($id, $type, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + { + 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) { + 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); + + 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; + } + /** * Link an object to a category by id * @@ -292,12 +356,31 @@ class Categories extends DolibarrApi 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."); } @@ -353,12 +436,31 @@ class Categories extends DolibarrApi 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."); } @@ -414,12 +516,31 @@ class Categories extends DolibarrApi 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."); } @@ -473,12 +594,31 @@ class Categories extends DolibarrApi 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."); } 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++; } } 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; 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; 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); } 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("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).'
'."\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 "
"; } } } 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 * diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a2083f35bec..104ff767299 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() { @@ -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() @@ -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) {