--- /tmp/dsg/dolibarr/htdocs/user/class/github_api_users.class.php +++ /tmp/dsg/dolibarr/htdocs/user/class/client_api_users.class.php @@ -1,6 +1,6 @@ -/* Copyright (C) 2020 Thibault FOUCART +/* Copyright (C) 2030 Thibault FOUCART * * 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,8 +45,8 @@ /** * Constructor */ - public function __construct() - { + public function __construct() + { global $db, $conf; $this->db = $db; $this->useraccount = new User($this->db); @@ -63,106 +63,109 @@ * @param int $limit Limit for list * @param int $page Page number * @param string $user_ids User ids filter field. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i} - * @param int $category Use this param to filter list by category - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + * @param int $category Use this param to filter list by category + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" * @return array Array of User objects */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $category = 0, $sqlfilters = '') - { - global $db, $conf; - - $obj_ret = array(); + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $category = 0, $sqlfilters = '') + { + global $db, $conf; + + $obj_ret = array(); if (!DolibarrApiAccess::$user->rights->user->user->lire) { - throw new RestException(401, "You are not allowed to read list of users"); - } - - // case of external user, $societe param is ignored and replaced by user's socid - //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe; - - $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."user as t"; - if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_user as c"; - } - $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; - if ($user_ids) { - $sql .= " AND t.rowid IN (".$user_ids.")"; - } - - // Select products of given category - if ($category > 0) { - $sql .= " AND c.fk_categorie = ".$this->db->escape($category); + throw new RestException(401, "You are not allowed to read list of users"); + } + + // case of external user, $societe param is ignored and replaced by user's socid + //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe; + + $sql = "SELECT t.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."user as t"; + if ($category > 0) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_user as c"; + } + $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; + if ($user_ids) $sql .= " AND t.rowid IN (".$user_ids.")"; + + // Select products of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$db->escape($category); $sql .= " AND c.fk_user = t.rowid "; - } - - // Add sql filters - if ($sqlfilters) { - if (!DolibarrApi::_checkFilters($sqlfilters)) { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); - } - $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - $result = $this->db->query($sql); - - if ($result) { - $i = 0; - $num = $this->db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) { - $obj = $this->db->fetch_object($result); - $user_static = new User($this->db); - if ($user_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_cleanObjectDatas($user_static); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve User list : '.$this->db->lasterror()); - } - if (!count($obj_ret)) { - throw new RestException(404, 'No User found'); - } - return $obj_ret; + } + + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); + + if ($result) + { + $i = 0; + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) + { + $obj = $db->fetch_object($result); + $user_static = new User($db); + if ($user_static->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($user_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve User list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No User found'); + } + return $obj_ret; } /** * Get properties of an user object + * Return an array with user informations * * @param int $id ID of user - * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) - * @return array|mixed data without useless information - * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 User or group not found - */ - public function get($id, $includepermissions = 0) - { + * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) + * @return array|mixed data without useless information + * + * @throws RestException + */ + public function get($id, $includepermissions = 0) + { //if (!DolibarrApiAccess::$user->rights->user->user->lire) { //throw new RestException(401); //} - if ($id == 0) { - $result = $this->useraccount->initAsSpecimen(); - } else { - $result = $this->useraccount->fetch($id); - } - if (!$result) { + + $result = $this->useraccount->fetch($id); + if (!$result) + { throw new RestException(404, 'User not found'); } - if ($id > 0 && !DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) { + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -173,112 +176,39 @@ return $this->_cleanObjectDatas($this->useraccount); } - /** - * Get properties of an user object by login - * - * @param string $login Login of user - * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) - * @return array|mixed Data without useless information - * - * @url GET login/{login} - * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 User or group not found - */ - public function getByLogin($login, $includepermissions = 0) - { - //if (!DolibarrApiAccess::$user->rights->user->user->lire) { - //throw new RestException(401); - //} - - $result = $this->useraccount->fetch('', $login); - 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); - } - - if ($includepermissions) { - $this->useraccount->getRights(); - } - - return $this->_cleanObjectDatas($this->useraccount); - } - - /** - * Get properties of an user object by Email - * - * @param string $email Email of user - * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) - * @return array|mixed Data without useless information - * - * @url GET email/{email} - * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 User or group not found - */ - public function getByEmail($email, $includepermissions = 0) - { - //if (!DolibarrApiAccess::$user->rights->user->user->lire) { - //throw new RestException(401); - //} - - $result = $this->useraccount->fetch('', '', '', 0, -1, $email); - 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); - } - - if ($includepermissions) { - $this->useraccount->getRights(); - } - - return $this->_cleanObjectDatas($this->useraccount); - } - - /** - * Get properties of user connected - * - * @url GET /info - * - * @param int $includepermissions Set this to 1 to have the array of permissions loaded (not done by default for performance purpose) - * @return array|mixed Data without useless information - * - * @throws RestException 401 Insufficient rights - * @throws RestException 404 User or group not found - */ - public function getInfo($includepermissions = 0) - { - $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); - } - - if ($includepermissions) { - $this->useraccount->getRights(); - } - - $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->user_group_list = $this->_cleanUserGroupListDatas($userGroupList); - - return $this->_cleanObjectDatas($this->useraccount); - } + /** + * Get properties of user connected + * + * @url GET /info + * + * @return array|mixed Data without useless information + * + * @throws RestException 401 Insufficient rights + * @throws RestException 404 User or 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->user_group_list = $this->_cleanUserGroupListDatas($userGroupList); + + return $this->_cleanObjectDatas($this->useraccount); + } /** * Create user account @@ -286,81 +216,84 @@ * @param array $request_data New user data * @return int */ - public function post($request_data = null) - { - // check user authorization - //if(! DolibarrApiAccess::$user->rights->user->creer) { - // throw new RestException(401, "User creation not allowed"); - //} - // check mandatory fields - /*if (!isset($request_data["login"])) - throw new RestException(400, "login field missing"); - if (!isset($request_data["password"])) - throw new RestException(400, "password field missing"); - if (!isset($request_data["lastname"])) - throw new RestException(400, "lastname field missing");*/ - //assign field values - foreach ($request_data as $field => $value) { - $this->useraccount->$field = $value; - } - - if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, 'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors)); - } - return $this->useraccount->id; - } + public function post($request_data = null) + { + // check user authorization + //if(! DolibarrApiAccess::$user->rights->user->creer) { + // throw new RestException(401, "User creation not allowed"); + //} + // check mandatory fields + /*if (!isset($request_data["login"])) + throw new RestException(400, "login field missing"); + if (!isset($request_data["password"])) + throw new RestException(400, "password field missing"); + if (!isset($request_data["lastname"])) + throw new RestException(400, "lastname field missing");*/ + //assign field values + foreach ($request_data as $field => $value) + { + $this->useraccount->$field = $value; + } + + if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, 'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors)); + } + return $this->useraccount->id; + } /** * Update account * - * @param int $id Id of account to update - * @param array $request_data Datas - * @return array|mixed Record after update - * - * @throws RestException 401 Not allowed - * @throws RestException 404 Not found - * @throws RestException 500 System error - */ - public function put($id, $request_data = null) - { + * @param int $id Id of account to update + * @param array $request_data Datas + * @return array + * + * @throws RestException + */ + public function put($id, $request_data = null) + { //if (!DolibarrApiAccess::$user->rights->user->user->creer) { //throw new RestException(401); //} $result = $this->useraccount->fetch($id); - if (!$result) { + if (!$result) + { throw new RestException(404, 'Account not found'); } - if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) { + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - foreach ($request_data as $field => $value) { - if ($field == 'id') { - continue; - } + foreach ($request_data as $field => $value) + { + if ($field == 'id') continue; // The status must be updated using setstatus() because it // is not handled by the update() method. if ($field == 'statut') { $result = $this->useraccount->setstatus($value); if ($result < 0) { - throw new RestException(500, 'Error when updating status of user: '.$this->useraccount->error); + throw new RestException(500, 'Error when updating status of user: '.$this->useraccount->error); } } else { - $this->useraccount->$field = $value; + $this->useraccount->$field = $value; } } // If there is no error, update() returns the number of affected // rows so if the update is a no op, the return value is zezo. - if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0) { + if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0) + { return $this->get($id); - } else { + } + else + { throw new RestException(500, $this->useraccount->error); } - } + } /** @@ -370,7 +303,7 @@ * @return array Array of group objects * * @throws RestException 403 Not allowed - * @throws RestException 404 Not found + * @throws RestException 404 Not found * * @url GET {id}/groups */ @@ -398,18 +331,18 @@ } - /** + /** * Add a user into a group * * @param int $id User ID * @param int $group Group ID * @param int $entity Entity ID (valid only for superadmin in multicompany transverse mode) * @return int 1 if success - * + * * @url GET {id}/setGroup/{group} */ - public function setGroup($id, $group, $entity = 1) - { + public function setGroup($id, $group, $entity = 1) + { global $conf; @@ -417,24 +350,30 @@ //throw new RestException(401); //} $result = $this->useraccount->fetch($id); - if (!$result) { + if (!$result) + { throw new RestException(404, 'User not found'); } - if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) { + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity)) { + if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity)) + { $entity = (!empty($entity) ? $entity : $conf->entity); - } else { + } + else + { // When using API, action is done on entity of logged user because a user of entity X with permission to create user should not be able to // hack the security by giving himself permissions on another entity. $entity = (DolibarrApiAccess::$user->entity > 0 ? DolibarrApiAccess::$user->entity : $conf->entity); } $result = $this->useraccount->SetInGroup($group, $entity); - if (!($result > 0)) { + if (!($result > 0)) + { throw new RestException(500, $this->useraccount->error); } @@ -456,65 +395,69 @@ * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" * @return array Array of User objects */ - public function listGroups($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $group_ids = 0, $sqlfilters = '') - { - global $db, $conf; - - $obj_ret = array(); + public function listGroups($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $group_ids = 0, $sqlfilters = '') + { + global $db, $conf; + + $obj_ret = array(); if (!DolibarrApiAccess::$user->rights->user->group_advance->read) { - throw new RestException(401, "You are not allowed to read list of groups"); - } - - // case of external user, $societe param is ignored and replaced by user's socid - //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe; - - $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as t"; - $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; - if ($group_ids) { - $sql .= " AND t.rowid IN (".$group_ids.")"; - } - // Add sql filters - if ($sqlfilters) { - if (!DolibarrApi::_checkFilters($sqlfilters)) { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); - } - $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - $result = $this->db->query($sql); - - if ($result) { - $i = 0; - $num = $this->db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) { - $obj = $this->db->fetch_object($result); - $group_static = new UserGroup($this->db); - if ($group_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_cleanObjectDatas($group_static); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve Group list : '.$this->db->lasterror()); - } - if (!count($obj_ret)) { - throw new RestException(404, 'No Group found'); - } - return $obj_ret; + throw new RestException(401, "You are not allowed to read list of groups"); + } + + // case of external user, $societe param is ignored and replaced by user's socid + //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe; + + $sql = "SELECT t.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as t"; + $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; + if ($group_ids) $sql .= " AND t.rowid IN (".$group_ids.")"; + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); + + if ($result) + { + $i = 0; + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) + { + $obj = $db->fetch_object($result); + $group_static = new UserGroup($this->db); + if ($group_static->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($group_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve Group list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No Group found'); + } + return $obj_ret; } /** @@ -528,22 +471,23 @@ * @param int $load_members Load members list or not {@min 0} {@max 1} * @return array Array of User objects */ - public function infoGroups($group, $load_members = 0) - { - global $db, $conf; + public function infoGroups($group, $load_members = 0) + { + global $db, $conf; if (!DolibarrApiAccess::$user->rights->user->group_advance->read) { - throw new RestException(401, "You are not allowed to read groups"); - } - - $group_static = new UserGroup($this->db); - $result = $group_static->fetch($group, '', $load_members); - - if (!$result) { + throw new RestException(401, "You are not allowed to read groups"); + } + + $group_static = new UserGroup($this->db); + $result = $group_static->fetch($group, '', $load_members); + + if (!$result) + { throw new RestException(404, 'Group not found'); } - return $this->_cleanObjectDatas($group_static); + return $this->_cleanObjectDatas($group_static); } /** @@ -552,151 +496,153 @@ * @param int $id Account ID * @return array */ - public function delete($id) - { + public function delete($id) + { //if (!DolibarrApiAccess::$user->rights->user->user->supprimer) { //throw new RestException(401); //} $result = $this->useraccount->fetch($id); - if (!$result) { + if (!$result) + { throw new RestException(404, 'User not found'); } - if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) { + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $this->useraccount->oldcopy = clone $this->useraccount; + $this->useraccount->oldcopy = clone $this->useraccount; return $this->useraccount->delete(DolibarrApiAccess::$user); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Clean sensible object datas * - * @param Object $object Object to clean - * @return Object Object with cleaned properties + * @param object $object Object to clean + * @return array Array of cleaned object properties */ protected function _cleanObjectDatas($object) { - // phpcs:enable + // phpcs:enable global $conf; - $object = parent::_cleanObjectDatas($object); - - unset($object->default_values); - unset($object->lastsearch_values); - unset($object->lastsearch_values_tmp); - - unset($object->total_ht); - unset($object->total_tva); - unset($object->total_localtax1); - unset($object->total_localtax2); - unset($object->total_ttc); - - unset($object->label_incoterms); - unset($object->location_incoterms); - - unset($object->fk_delivery_address); - unset($object->fk_incoterms); - unset($object->all_permissions_are_loaded); - unset($object->shipping_method_id); - unset($object->nb_rights); - unset($object->search_sid); - unset($object->ldap_sid); - unset($object->clicktodial_loaded); - - // List of properties never returned by API, whatever are permissions - unset($object->pass); - unset($object->pass_indatabase); - unset($object->pass_indatabase_crypted); - unset($object->pass_temp); - unset($object->api_key); - unset($object->clicktodial_password); - unset($object->openid); - - unset($object->lines); - unset($object->model_pdf); - unset($object->skype); - unset($object->twitter); - unset($object->facebook); - unset($object->linkedin); - - $canreadsalary = ((!empty($conf->salaries->enabled) && !empty(DolibarrApiAccess::$user->rights->salaries->read)) - || (!empty($conf->hrm->enabled) && !empty(DolibarrApiAccess::$user->rights->hrm->employee->read))); - - if (!$canreadsalary) { + $object = parent::_cleanObjectDatas($object); + + unset($object->default_values); + unset($object->lastsearch_values); + unset($object->lastsearch_values_tmp); + + unset($object->total_ht); + unset($object->total_tva); + unset($object->total_localtax1); + unset($object->total_localtax2); + unset($object->total_ttc); + + unset($object->label_incoterms); + unset($object->location_incoterms); + + unset($object->fk_delivery_address); + unset($object->fk_incoterms); + unset($object->all_permissions_are_loaded); + unset($object->shipping_method_id); + unset($object->nb_rights); + unset($object->search_sid); + unset($object->ldap_sid); + unset($object->clicktodial_loaded); + + // List of properties never returned by API, whatever are permissions + unset($object->pass); + unset($object->pass_indatabase); + unset($object->pass_indatabase_crypted); + unset($object->pass_temp); + unset($object->api_key); + unset($object->clicktodial_password); + unset($object->openid); + + unset($object->lines); + unset($object->modelpdf); + unset($object->skype); + unset($object->twitter); + unset($object->facebook); + unset($object->linkedin); + + $canreadsalary = ((!empty($conf->salaries->enabled) && !empty(DolibarrApiAccess::$user->rights->salaries->read)) + || (!empty($conf->hrm->enabled) && !empty(DolibarrApiAccess::$user->rights->hrm->employee->read))); + + if (!$canreadsalary) + { unset($object->salary); unset($object->salaryextra); unset($object->thm); unset($object->tjm); } - 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; - } + 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 - * + * * @param array|null $data Data to validate * @return array * @throws RestException - */ - private function _validate($data) - { - $account = array(); - foreach (Users::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, "$field field missing"); - } - $account[$field] = $data[$field]; - } - return $account; - } + */ + private function _validate($data) + { + $account = array(); + foreach (Users::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $account[$field] = $data[$field]; + } + return $account; + } } --- /tmp/dsg/dolibarr/htdocs/user/class/github_user.class.php +++ /tmp/dsg/dolibarr/htdocs/user/class/client_user.class.php @@ -12,7 +12,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2018 charlene Benke * Copyright (C) 2018 Nicolas ZABOURI - * Copyright (C) 2019-2020 Frédéric France + * Copyright (C) 2019 Frédéric France * Copyright (C) 2019 Abbes Bahfir * * This program is free software; you can redistribute it and/or modify @@ -54,7 +54,7 @@ public $table_element = 'user'; /** - * @var string Field with ID of parent key if this field has a parent + * @var int Field with ID of parent key if this field has a parent */ public $fk_element = 'fk_user'; @@ -64,9 +64,6 @@ */ public $ismultientitymanaged = 1; - /** - * @var string picto - */ public $picto = 'user'; public $id = 0; @@ -74,61 +71,18 @@ public $ldap_sid; public $search_sid; public $employee; - public $civility_code; - - /** - * @var string gender - */ public $gender; public $birth; - - /** - * @var string email - */ public $email; - - /** - * @var string personal email - */ public $personal_email; - /** - * @var array array of socialnetworks - */ - public $socialnetworks; - - /** - * @var string skype account - * @deprecated - */ - public $skype; - - /** - * @var string twitter account - * @deprecated - */ - public $twitter; - - /** - * @var string facebook account - * @deprecated - */ - public $facebook; - - /** - * @var string linkedin account - * @deprecated - */ - public $linkedin; - - /** - * @var string job position - */ - public $job; - - /** - * @var string user signature - */ + + /** + * @var array array of socialnetworks + */ + public $socialnetworks; + + public $job; // job position public $signature; /** @@ -136,52 +90,17 @@ */ public $address; - /** - * @var string zip code - */ public $zip; - - /** - * @var string town - */ public $town; public $state_id; // The state/department public $state_code; public $state; - - /** - * @var string office phone - */ public $office_phone; - - /** - * @var string office fax - */ public $office_fax; - - /** - * @var string phone mobile - */ public $user_mobile; - - /** - * @var string personal phone mobile - */ - public $personal_mobile; - - /** - * @var int 1 if admin 0 if standard user - */ + public $personal_mobile; public $admin; - - /** - * @var string user login - */ public $login; - - /** - * @var string user apikey - */ public $api_key; /** @@ -189,132 +108,76 @@ */ public $entity; - /** - * @var string Clear password in memory - */ + //! Clear password in memory public $pass; - - /** - * @var string Clear password in database (defined if DATABASE_PWD_ENCRYPTED=0) - */ + //! Clear password in database (defined if DATABASE_PWD_ENCRYPTED=0) public $pass_indatabase; - - /** - * @var string Encrypted password in database (always defined) - */ + //! Encrypted password in database (always defined) public $pass_indatabase_crypted; /** - * @var string Temporary password - */ - public $pass_temp; - - /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; - - /** - * Date modification record (tms) - * - * @var integer - */ - public $datem; - - /** - * @var int If this is defined, it is an external user - */ + * Date creation record (datec) + * + * @var integer + */ + public $datec; + + /** + * Date modification record (tms) + * + * @var integer + */ + public $datem; + + //! If this is defined, it is an external user + /** + * @deprecated + * @see $socid + */ + public $societe_id; + /** + * @deprecated + * @see $contactid + */ + public $contact_id; public $socid; - - /** - * @var int If this is defined, it is a user created from a contact - */ - public $contact_id; - - /** - * @var int ID - */ + public $contactid; + + /** + * @var int ID + */ public $fk_member; /** - * @var int User ID of supervisor + * @var int User ID */ public $fk_user; - - /** - * @var int User ID of expense validator - */ public $fk_user_expense_validator; - - /** - * @var int User ID of holidays validator - */ - public $fk_user_holiday_validator; - - /** - * @string clicktodial url - */ + public $fk_user_holiday_validator; + public $clicktodial_url; - - /** - * @var string clicktodial login - */ public $clicktodial_login; - - /** - * @var string clicktodial password - */ public $clicktodial_password; - - /** - * @var string clicktodial poste - */ public $clicktodial_poste; public $datelastlogin; public $datepreviouslogin; - public $datestartvalidity; - public $dateendvalidity; - - /** - * @var string photo filename - */ public $photo; public $lang; - /** - * @var stdClass Class of permissions user->rights->permx - */ - public $rights; - - /** - * @var int All permissions are loaded - */ - public $all_permissions_are_loaded; - - /** - * @var int Number of rights granted to the user - */ - public $nb_rights; - - /** - * @var array Cache array of already loaded permissions - */ - private $_tab_loaded = array(); - - /** - * @var stdClass To store personal config - */ - public $conf; + public $rights; // Array of permissions user->rights->permx + public $all_permissions_are_loaded; // All permission are loaded + public $nb_rights; // Number of rights granted to the user + private $_tab_loaded = array(); // Cache array of already loaded permissions + + public $conf; // To store personal config public $default_values; // To store default values for user public $lastsearch_values_tmp; // To store current search criterias for user public $lastsearch_values; // To store last saved search criterias for user public $users = array(); // To store all tree of users hierarchy public $parentof; // To store an array of all parents for all ids. - private $cache_childids; // Cache array of already loaded childs + private $cache_childids; public $accountancy_code; // Accountancy code in prevision of the complete accountancy module @@ -325,10 +188,7 @@ public $salaryextra; // Monthly salary extra - Denormalized value from llx_user_employment public $weeklyhours; // Weekly hours - Denormalized value from llx_user_employment - /** - * @var string Define background color for user in agenda - */ - public $color; + public $color; // Define background color for user in agenda public $dateemployment; // Define date of employment by company public $dateemploymentend; // Define date of employment end by company @@ -336,16 +196,13 @@ public $default_c_exp_tax_cat; public $default_range; - /** - *@var int id of warehouse - */ public $fk_warehouse; public $fields = array( - 'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), - 'lastname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20, 'searchall'=>1), - 'firstname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1), - ); + 'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), + 'lastname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20, 'searchall'=>1, 'comment'=>'Reference of object'), + 'firstname'=>array('type'=>'varchar(50)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), + ); const STATUS_DISABLED = 0; @@ -401,7 +258,7 @@ $login = trim($login); // Get user - $sql = "SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.email, u.personal_email, u.job,"; + $sql = "SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.birth, u.email, u.personal_email, u.job,"; $sql .= " u.socialnetworks,"; $sql .= " u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,"; $sql .= " u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,"; @@ -413,9 +270,6 @@ $sql .= " u.tms as datem,"; $sql .= " u.datelastlogin as datel,"; $sql .= " u.datepreviouslogin as datep,"; - $sql .= " u.datelastpassvalidation,"; - $sql .= " u.datestartvalidity,"; - $sql .= " u.dateendvalidity,"; $sql .= " u.photo as photo,"; $sql .= " u.openid as openid,"; $sql .= " u.accountancy_code,"; @@ -435,47 +289,59 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON u.fk_country = c.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON u.fk_state = d.rowid"; - if ($entity < 0) { - if ((empty($conf->multicompany->enabled) || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) { + if ($entity < 0) + { + if ((empty($conf->multicompany->enabled) || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) + { $sql .= " WHERE u.entity IN (0,".$conf->entity.")"; - } else { + } + else + { $sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database } - } else { - // The fetch was forced on an entity - if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + } + else // The fetch was forced on an entity + { + if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database - } else { + else $sql .= " WHERE u.entity IN (0, ".(($entity != '' && $entity >= 0) ? $entity : $conf->entity).")"; // search in entity provided in parameter - } - } - - if ($sid) { // permet une recherche du user par son SID ActiveDirectory ou Samba + } + + if ($sid) // permet une recherche du user par son SID ActiveDirectory ou Samba + { $sql .= " AND (u.ldap_sid = '".$this->db->escape($sid)."' OR u.login = '".$this->db->escape($login)."') LIMIT 1"; - } elseif ($login) { + } + elseif ($login) + { $sql .= " AND u.login = '".$this->db->escape($login)."'"; - } elseif ($email) { + } + elseif ($email) + { $sql .= " AND u.email = '".$this->db->escape($email)."'"; - } else { + } + else + { $sql .= " AND u.rowid = ".$id; } $sql .= " ORDER BY u.entity ASC"; // Avoid random result when there is 2 login in 2 different entities $result = $this->db->query($sql); - if ($result) { + if ($result) + { $obj = $this->db->fetch_object($result); - if ($obj) { + if ($obj) + { $this->id = $obj->rowid; $this->ref = $obj->rowid; - $this->ref_ext = $obj->ref_ext; - - $this->ldap_sid = $obj->ldap_sid; - $this->civility_code = $obj->civility_code; - $this->lastname = $obj->lastname; + $this->ref_ext = $obj->ref_ext; + + $this->ldap_sid = $obj->ldap_sid; + $this->lastname = $obj->lastname; $this->firstname = $obj->firstname; - $this->employee = $obj->employee; + $this->employee = $obj->employee; $this->login = $obj->login; $this->gender = $obj->gender; @@ -501,7 +367,7 @@ $this->office_phone = $obj->office_phone; $this->office_fax = $obj->office_fax; $this->user_mobile = $obj->user_mobile; - $this->personal_mobile = $obj->personal_mobile; + $this->personal_mobile = $obj->personal_mobile; $this->email = $obj->email; $this->personal_email = $obj->personal_email; $this->socialnetworks = (array) json_decode($obj->socialnetworks, true); @@ -530,15 +396,15 @@ $this->datem = $this->db->jdate($obj->datem); $this->datelastlogin = $this->db->jdate($obj->datel); $this->datepreviouslogin = $this->db->jdate($obj->datep); - $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity); - $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity); - + + $this->societe_id = $obj->fk_soc; // deprecated + $this->contact_id = $obj->fk_socpeople; // deprecated $this->socid = $obj->fk_soc; - $this->contact_id = $obj->fk_socpeople; + $this->contactid = $obj->fk_socpeople; $this->fk_member = $obj->fk_member; $this->fk_user = $obj->fk_user; - $this->fk_user_expense_validator = $obj->fk_user_expense_validator; - $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator; + $this->fk_user_expense_validator = $obj->fk_user_expense_validator; + $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator; $this->default_range = $obj->default_range; $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat; @@ -546,55 +412,61 @@ // Protection when module multicompany was set, admin was set to first entity and then, the module was disabled, // in such case, this admin user must be admin for ALL entities. - if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) { - $this->entity = 0; - } - - // Retrieve all extrafield + if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) $this->entity = 0; + + // Retreive all extrafield // fetch optionals attributes and labels $this->fetch_optionals(); $this->db->free($result); - } else { + } + else + { $this->error = "USERNOTFOUND"; dol_syslog(get_class($this)."::fetch user not found", LOG_DEBUG); $this->db->free($result); return 0; } - } else { + } + else + { $this->error = $this->db->lasterror(); return -1; } // To get back the global configuration unique to the user - if ($loadpersonalconf) { + if ($loadpersonalconf) + { // Load user->conf for user $sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param"; $sql .= " WHERE fk_user = ".$this->id; $sql .= " AND entity = ".$conf->entity; //dol_syslog(get_class($this).'::fetch load personalized conf', LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) { + while ($i < $num) + { $obj = $this->db->fetch_object($resql); $p = (!empty($obj->param) ? $obj->param : ''); - if (!empty($p)) { - $this->conf->$p = $obj->value; - } + if (!empty($p)) $this->conf->$p = $obj->value; $i++; } $this->db->free($resql); - } else { + } + else + { $this->error = $this->db->lasterror(); return -2; } $result = $this->loadDefaultValues(); - if ($result < 0) { + if ($result < 0) + { $this->error = $this->db->lasterror(); return -3; } @@ -618,16 +490,20 @@ $sql .= " WHERE entity IN (".($this->entity > 0 ? $this->entity.", " : "").$conf->entity.")"; // Entity of user (if defined) + current entity $sql .= " AND user_id IN (0".($this->id > 0 ? ", ".$this->id : "").")"; // User 0 (all) + me (if defined) $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - if (!empty($obj->page) && !empty($obj->type) && !empty($obj->param)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { + if (!empty($obj->page) && !empty($obj->type) && !empty($obj->param)) + { // $obj->page is relative URL with or without params // $obj->type can be 'filters', 'sortorder', 'createform', ... // $obj->param is key or param $pagewithoutquerystring = $obj->page; $pagequeries = ''; $reg = array(); - if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) { // There is query param + if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) // There is query param + { $pagewithoutquerystring = $reg[1]; $pagequeries = $reg[2]; } @@ -637,8 +513,10 @@ } // Sort by key, so _noquery_ is last if (!empty($this->default_values)) { - foreach ($this->default_values as $a => $b) { - foreach ($b as $c => $d) { + foreach ($this->default_values as $a => $b) + { + foreach ($b as $c => $d) + { krsort($this->default_values[$a][$c]); } } @@ -646,7 +524,9 @@ $this->db->free($resql); return 1; - } else { + } + else + { dol_print_error($this->db); return -1; } @@ -675,56 +555,54 @@ $this->db->begin(); - if (!empty($rid)) { - $module = $perms = $subperms = ''; - + if (!empty($rid)) + { // Si on a demande ajout d'un droit en particulier, on recupere // les caracteristiques (module, perms et subperms) de ce droit. $sql = "SELECT module, perms, subperms"; $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; - $sql .= " WHERE id = ".((int) $rid); - $sql .= " AND entity = ".((int) $entity); + $sql .= " WHERE id = '".$this->db->escape($rid)."'"; + $sql .= " AND entity = ".$entity; $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - - if ($obj) { - $module = $obj->module; - $perms = $obj->perms; - $subperms = $obj->subperms; - } - } else { + $module = $obj->module; + $perms = $obj->perms; + $subperms = $obj->subperms; + } + else { $error++; dol_print_error($this->db); } // Where pour la liste des droits a ajouter - $whereforadd = "id=".((int) $rid); + $whereforadd = "id=".$this->db->escape($rid); // Ajout des droits induits - if (!empty($subperms)) { - $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))"; - } elseif (!empty($perms)) { - $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)"; - } - } else { + if (!empty($subperms)) $whereforadd .= " OR (module='$module' AND perms='$perms' AND (subperms='lire' OR subperms='read'))"; + elseif (!empty($perms)) $whereforadd .= " OR (module='$module' AND (perms='lire' OR perms='read') AND subperms IS NULL)"; + } + else { // On a pas demande un droit en particulier mais une liste de droits // sur la base d'un nom de module de de perms // Where pour la liste des droits a ajouter - if (!empty($allmodule)) { - if ($allmodule == 'allmodules') { + if (!empty($allmodule)) + { + if ($allmodule == 'allmodules') + { $whereforadd = 'allmodules'; - } else { + } + else + { $whereforadd = "module='".$this->db->escape($allmodule)."'"; - if (!empty($allperms)) { - $whereforadd .= " AND perms='".$this->db->escape($allperms)."'"; - } + if (!empty($allperms)) $whereforadd .= " AND perms='".$this->db->escape($allperms)."'"; } } } // Ajout des droits trouves grace au critere whereforadd - if (!empty($whereforadd)) { + if (!empty($whereforadd)) + { //print "$module-$perms-$subperms"; $sql = "SELECT id"; $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; @@ -734,46 +612,46 @@ } $result = $this->db->query($sql); - if ($result) { + if ($result) + { $num = $this->db->num_rows($result); $i = 0; - while ($i < $num) { + while ($i < $num) + { $obj = $this->db->fetch_object($result); $nid = $obj->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = ".$this->id." AND fk_id=".$nid." AND entity = ".$entity; - if (!$this->db->query($sql)) { - $error++; - } + if (!$this->db->query($sql)) $error++; $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (entity, fk_user, fk_id) VALUES (".$entity.", ".$this->id.", ".$nid.")"; - if (!$this->db->query($sql)) { - $error++; - } + if (!$this->db->query($sql)) $error++; $i++; } - } else { + } + else + { $error++; dol_print_error($this->db); } } - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { $langs->load("other"); $this->context = array('audit'=>$langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : '')); // Call trigger $result = $this->call_trigger('USER_MODIFY', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } // End call triggers } if ($error) { $this->db->rollback(); return -$error; - } else { + } + else { $this->db->commit(); return 1; } @@ -802,8 +680,6 @@ $this->db->begin(); if (!empty($rid)) { - $module = $perms = $subperms = ''; - // Si on a demande supression d'un droit en particulier, on recupere // les caracteristiques module, perms et subperms de ce droit. $sql = "SELECT module, perms, subperms"; @@ -814,43 +690,40 @@ $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - - if ($obj) { - $module = $obj->module; - $perms = $obj->perms; - $subperms = $obj->subperms; - } - } else { + $module = $obj->module; + $perms = $obj->perms; + $subperms = $obj->subperms; + } + else { $error++; dol_print_error($this->db); } // Where pour la liste des droits a supprimer - $wherefordel = "id=".((int) $rid); + $wherefordel = "id=".$this->db->escape($rid); // Suppression des droits induits - if ($subperms == 'lire' || $subperms == 'read') { - $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)"; - } - if ($perms == 'lire' || $perms == 'read') { - $wherefordel .= " OR (module='".$this->db->escape($module)."')"; - } + if ($subperms == 'lire' || $subperms == 'read') $wherefordel .= " OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)"; + if ($perms == 'lire' || $perms == 'read') $wherefordel .= " OR (module='$module')"; } else { // On a demande suppression d'un droit sur la base d'un nom de module ou perms // Where pour la liste des droits a supprimer - if (!empty($allmodule)) { - if ($allmodule == 'allmodules') { + if (!empty($allmodule)) + { + if ($allmodule == 'allmodules') + { $wherefordel = 'allmodules'; - } else { + } + else + { $wherefordel = "module='".$this->db->escape($allmodule)."'"; - if (!empty($allperms)) { - $wherefordel .= " AND perms='".$this->db->escape($allperms)."'"; - } + if (!empty($allperms)) $whereforadd .= " AND perms='".$this->db->escape($allperms)."'"; } } } // Suppression des droits selon critere defini dans wherefordel - if (!empty($wherefordel)) { + if (!empty($wherefordel)) + { //print "$module-$perms-$subperms"; $sql = "SELECT id"; $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; @@ -859,53 +732,47 @@ $sql .= " AND ".$wherefordel; } - // avoid admin can remove his own important rights - if ($this->admin == 1) { - $sql .= " AND id NOT IN (251, 252, 253, 254, 255, 256)"; // other users rights - $sql .= " AND id NOT IN (341, 342, 343, 344)"; // own rights - $sql .= " AND id NOT IN (351, 352, 353, 354)"; // groups rights - $sql .= " AND id NOT IN (358)"; // user export - } - $result = $this->db->query($sql); - if ($result) { + if ($result) + { $num = $this->db->num_rows($result); $i = 0; - while ($i < $num) { + while ($i < $num) + { $obj = $this->db->fetch_object($result); $nid = $obj->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights"; $sql .= " WHERE fk_user = ".$this->id." AND fk_id=".$nid; $sql .= " AND entity = ".$entity; - if (!$this->db->query($sql)) { - $error++; - } + if (!$this->db->query($sql)) $error++; $i++; } - } else { + } + else + { $error++; dol_print_error($this->db); } } - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { $langs->load("other"); $this->context = array('audit'=>$langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : '')); // Call trigger $result = $this->call_trigger('USER_MODIFY', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } // End call triggers } if ($error) { $this->db->rollback(); return -$error; - } else { + } + else { $this->db->commit(); return 1; } @@ -921,7 +788,7 @@ public function clearrights() { dol_syslog(get_class($this)."::clearrights reset user->rights"); - $this->rights = null; + $this->rights = ''; $this->nb_rights = 0; $this->all_permissions_are_loaded = 0; $this->_tab_loaded = array(); @@ -940,13 +807,16 @@ { global $conf; - if (empty($forcereload)) { - if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) { + if (empty($forcereload)) + { + if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) + { // Rights for this module are already loaded, so we leave return; } - if (!empty($this->all_permissions_are_loaded)) { + if (!empty($this->all_permissions_are_loaded)) + { // We already loaded all rights for this user, so we leave return; } @@ -959,52 +829,47 @@ $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur"; $sql .= ", ".MAIN_DB_PREFIX."rights_def as r"; $sql .= " WHERE r.id = ur.fk_id"; - if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) { + if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) + { $sql .= " AND r.entity IN (0,".(!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? "1," : "").$conf->entity.")"; - } else { + } + else + { $sql .= " AND ur.entity = ".$conf->entity; } $sql .= " AND ur.fk_user= ".$this->id; $sql .= " AND r.perms IS NOT NULL"; - if ($moduletag) { - $sql .= " AND r.module = '".$this->db->escape($moduletag)."'"; - } + if ($moduletag) $sql .= " AND r.module = '".$this->db->escape($moduletag)."'"; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); $i = 0; - - while ($i < $num) { + while ($i < $num) + { $obj = $this->db->fetch_object($resql); - if ($obj) { - $module = $obj->module; - $perms = $obj->perms; - $subperms = $obj->subperms; - - if (!empty($perms)) { - if (!isset($this->rights) || !is_object($this->rights)) { - $this->rights = new stdClass(); // For avoid error + $module = $obj->module; + $perms = $obj->perms; + $subperms = $obj->subperms; + + if ($perms) + { + if (!isset($this->rights) || !is_object($this->rights)) $this->rights = new stdClass(); // For avoid error + if ($module) + { + if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass(); + if ($subperms) + { + if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass(); + if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++; + $this->rights->$module->$perms->$subperms = 1; } - if (!empty($module)) { - if (!isset($this->rights->$module) || !is_object($this->rights->$module)) { - $this->rights->$module = new stdClass(); - } - if (!empty($subperms)) { - if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) { - $this->rights->$module->$perms = new stdClass(); - } - if (empty($this->rights->$module->$perms->$subperms)) { - $this->nb_rights++; - } - $this->rights->$module->$perms->$subperms = 1; - } else { - if (empty($this->rights->$module->$perms)) { - $this->nb_rights++; - } - $this->rights->$module->$perms = 1; - } + else + { + if (empty($this->rights->$module->$perms)) $this->nb_rights++; + $this->rights->$module->$perms = 1; } } } @@ -1019,13 +884,16 @@ $sql .= " ".MAIN_DB_PREFIX."usergroup_user as gu,"; $sql .= " ".MAIN_DB_PREFIX."rights_def as r"; $sql .= " WHERE r.id = gr.fk_id"; - if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) { + if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) + { if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { $sql .= " AND gu.entity IN (0,".$conf->entity.")"; } else { $sql .= " AND r.entity = ".$conf->entity; } - } else { + } + else + { $sql .= " AND gr.entity = ".$conf->entity; $sql .= " AND gu.entity = ".$conf->entity; $sql .= " AND r.entity = ".$conf->entity; @@ -1033,48 +901,36 @@ $sql .= " AND gr.fk_usergroup = gu.fk_usergroup"; $sql .= " AND gu.fk_user = ".$this->id; $sql .= " AND r.perms IS NOT NULL"; - if ($moduletag) { - $sql .= " AND r.module = '".$this->db->escape($moduletag)."'"; - } + if ($moduletag) $sql .= " AND r.module = '".$this->db->escape($moduletag)."'"; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) { + while ($i < $num) + { $obj = $this->db->fetch_object($resql); - if ($obj) { - $module = $obj->module; - $perms = $obj->perms; - $subperms = $obj->subperms; - - if (!empty($perms)) { - if (!isset($this->rights) || !is_object($this->rights)) { - $this->rights = new stdClass(); // For avoid error - } - if (!empty($module)) { - if (!isset($this->rights->$module) || !is_object($this->rights->$module)) { - $this->rights->$module = new stdClass(); - } - if (!empty($subperms)) { - if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) { - $this->rights->$module->$perms = new stdClass(); - } - if (empty($this->rights->$module->$perms->$subperms)) { - $this->nb_rights++; - } - $this->rights->$module->$perms->$subperms = 1; - } else { - if (empty($this->rights->$module->$perms)) { - $this->nb_rights++; - } - // if we have already define a subperm like this $this->rights->$module->level1->level2 with llx_user_rights, we don't want override level1 because the level2 can be not define on user group - if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) { - $this->rights->$module->$perms = 1; - } - } - } + $module = $obj->module; + $perms = $obj->perms; + $subperms = $obj->subperms; + + if ($perms) + { + if (!isset($this->rights) || !is_object($this->rights)) $this->rights = new stdClass(); // For avoid error + if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass(); + if ($subperms) + { + if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass(); + if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++; + $this->rights->$module->$perms->$subperms = 1; + } + else + { + if (empty($this->rights->$module->$perms)) $this->nb_rights++; + // if we have already define a subperm like this $this->rights->$module->level1->level2 with llx_user_rights, we don't want override level1 because the level2 can be not define on user group + if (!is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = 1; } } $i++; @@ -1083,18 +939,17 @@ } // For backward compatibility - if (isset($this->rights->propale) && !isset($this->rights->propal)) { - $this->rights->propal = $this->rights->propale; - } - if (isset($this->rights->propal) && !isset($this->rights->propale)) { - $this->rights->propale = $this->rights->propal; - } - - if (!$moduletag) { + if (isset($this->rights->propale) && !isset($this->rights->propal)) $this->rights->propal = $this->rights->propale; + if (isset($this->rights->propal) && !isset($this->rights->propale)) $this->rights->propale = $this->rights->propal; + + if (!$moduletag) + { // Si module etait non defini, alors on a tout charge, on peut donc considerer // que les droits sont en cache (car tous charges) pour cet instance de user $this->all_permissions_are_loaded = 1; - } else { + } + else + { // If module defined, we flag it as loaded into cache $this->_tab_loaded[$moduletag] = 1; } @@ -1113,11 +968,8 @@ $error = 0; // Check parameters - if ($this->statut == $status) { - return 0; - } else { - $this->statut = $status; - } + if ($this->statut == $status) return 0; + else $this->statut = $status; $this->db->begin(); @@ -1128,19 +980,21 @@ $result = $this->db->query($sql); dol_syslog(get_class($this)."::setstatus", LOG_DEBUG); - if ($result) { + if ($result) + { // Call trigger $result = $this->call_trigger('USER_ENABLEDISABLE', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } // End call triggers } - if ($error) { + if ($error) + { $this->db->rollback(); return -$error; - } else { + } + else + { $this->db->commit(); return 1; } @@ -1154,7 +1008,7 @@ * Existing categories are left untouch. * * @param int[]|int $categories Category or categories IDs - * @return void + * @return void */ public function setCategories($categories) { @@ -1216,57 +1070,60 @@ // Remove rights $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = ".$this->id; - if (!$error && !$this->db->query($sql)) { + if (!$error && !$this->db->query($sql)) + { $error++; $this->error = $this->db->lasterror(); } // Remove group $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user WHERE fk_user = ".$this->id; - if (!$error && !$this->db->query($sql)) { + if (!$error && !$this->db->query($sql)) + { $error++; $this->error = $this->db->lasterror(); } - // Remove params - $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param WHERE fk_user = ".$this->id; - if (!$error && !$this->db->query($sql)) { - $error++; - $this->error = $this->db->lasterror(); - } - // If contact, remove link - if ($this->contact_id > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE rowid = ".$this->contact_id; - if (!$error && !$this->db->query($sql)) { + if ($this->contactid > 0 || $this->contact_id > 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE rowid = ".(($this->contactid > 0) ? $this->contactid : $this->contact_id); + if (!$error && !$this->db->query($sql)) + { $error++; $this->error = $this->db->lasterror(); } } // Remove extrafields - if (!$error) { - $result = $this->deleteExtraFields(); - if ($result < 0) { - $error++; - dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); - } + if (!$error) + { + $result = $this->deleteExtraFields(); + if ($result < 0) + { + $error++; + dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); + } } // Remove user - if (!$error) { + if (!$error) + { $sql = "DELETE FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - if (!$this->db->query($sql)) { - $error++; - $this->error = $this->db->lasterror(); - } - } - - if (!$error) { + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + if (!$this->db->query($sql)) + { + $error++; + $this->error = $this->db->lasterror(); + } + } + + if (!$error) + { // Call trigger $result = $this->call_trigger('USER_DELETE', $user); - if ($result < 0) { + if ($result < 0) + { $error++; $this->db->rollback(); return -1; @@ -1275,7 +1132,9 @@ $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } @@ -1294,23 +1153,25 @@ global $mysoc; // Clean parameters - $this->setUpperOrLowerCase(); - - $this->civility_code = trim($this->civility_code); + + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); + $this->login = trim($this->login); - if (!isset($this->entity)) { - $this->entity = $conf->entity; // If not defined, we use default value - } + if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value dol_syslog(get_class($this)."::create login=".$this->login.", user=".(is_object($user) ? $user->id : ''), LOG_DEBUG); // Check parameters - if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) { + if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) + { $langs->load("errors"); $this->error = $langs->trans("ErrorBadEMail", $this->email); return -1; } - if (empty($this->login)) { + if (empty($this->login)) + { $langs->load("errors"); $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")); return -1; @@ -1327,32 +1188,47 @@ dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); $this->db->free($resql); - if ($num) { + if ($num) + { $this->error = 'ErrorLoginAlreadyExists'; dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); $this->db->rollback(); return -6; - } else { + } + else + { $sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,ldap_sid,entity)"; $sql .= " VALUES('".$this->db->idate($this->datec)."','".$this->db->escape($this->login)."','".$this->db->escape($this->ldap_sid)."',".$this->db->escape($this->entity).")"; $result = $this->db->query($sql); dol_syslog(get_class($this)."::create", LOG_DEBUG); - if ($result) { + if ($result) + { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user"); // Set default rights - if ($this->set_default_rights() < 0) { + if ($this->set_default_rights() < 0) + { $this->error = 'ErrorFailedToSetDefaultRightOfUser'; $this->db->rollback(); return -5; } - if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) { + // Update minor fields + $result = $this->update($user, 1, 1); + if ($result < 0) + { + $this->db->rollback(); + return -4; + } + + if (!empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) + { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $langs->load("stocks"); $entrepot = new Entrepot($this->db); @@ -1361,43 +1237,40 @@ $entrepot->description = $langs->trans("ThisWarehouseIsPersonalStock", $this->getFullName($langs)); $entrepot->statut = 1; $entrepot->country_id = $mysoc->country_id; - $warehouseid = $entrepot->create($user); - - $this->fk_warehouse = $warehouseid; + $entrepot->create($user); } - // Update minor fields - $result = $this->update($user, 1, 1); - if ($result < 0) { - $this->db->rollback(); - return -4; - } - - if (!$notrigger) { + if (!$notrigger) + { // Call trigger $result = $this->call_trigger('USER_CREATE', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } // End call triggers } - if (!$error) { + if (!$error) + { $this->db->commit(); return $this->id; - } else { + } + else + { //$this->error=$interface->error; dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); $this->db->rollback(); return -3; } - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); return -2; } } - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; @@ -1405,7 +1278,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a user from a contact object. User will be internal but if contact is linked to a third party, user will be external * @@ -1416,14 +1289,13 @@ */ public function create_from_contact($contact, $login = '', $password = '') { - // phpcs:enable + // phpcs:enable global $conf, $user, $langs; $error = 0; // Define parameters $this->admin = 0; - $this->civility_code = $contact->civility_code; $this->lastname = $contact->lastname; $this->firstname = $contact->firstname; $this->gender = $contact->gender; @@ -1439,46 +1311,44 @@ $this->country_id = $contact->country_id; $this->employee = 0; - if (empty($login)) { - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $login = dol_buildlogin($contact->lastname, $contact->firstname); - } + if (empty($login)) $login = strtolower(substr($contact->firstname, 0, 4)).strtolower(substr($contact->lastname, 0, 4)); $this->login = $login; $this->db->begin(); // Create user and set $this->id. Trigger is disabled because executed later. $result = $this->create($user, 1); - if ($result > 0) { + if ($result > 0) + { $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql .= " SET fk_socpeople=".$contact->id; - $sql .= ", civility='".$this->db->escape($contact->civility_code)."'"; - if ($contact->socid > 0) { - $sql .= ", fk_soc=".$contact->socid; - } - $sql .= " WHERE rowid=".((int) $this->id); + if ($contact->socid) $sql .= ", fk_soc=".$contact->socid; + $sql .= " WHERE rowid=".$this->id; $resql = $this->db->query($sql); dol_syslog(get_class($this)."::create_from_contact", LOG_DEBUG); - if ($resql) { + if ($resql) + { $this->context['createfromcontact'] = 'createfromcontact'; // Call trigger $result = $this->call_trigger('USER_CREATE', $user); - if ($result < 0) { - $error++; $this->db->rollback(); return -1; - } + if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers $this->db->commit(); return $this->id; - } else { + } + else + { $this->error = $this->db->error(); $this->db->rollback(); return -1; } - } else { + } + else + { // $this->error deja positionne dol_syslog(get_class($this)."::create_from_contact - 0"); @@ -1487,23 +1357,21 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Create a user into database from a member object. - * If $member->fk_soc is set, it will be an external user. - * - * @param Adherent $member Object member source - * @param string $login Login to force - * @return int <0 if KO, if OK, return id of created account + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Create a user into database from a member object + * + * @param Adherent $member Object member source + * @param string $login Login to force + * @return int <0 if KO, if OK, return id of created account */ public function create_from_member($member, $login = '') { - // phpcs:enable + // phpcs:enable global $conf, $user, $langs; // Set properties on new user $this->admin = 0; - $this->civility_code = $member->civility_id; $this->lastname = $member->lastname; $this->firstname = $member->firstname; $this->gender = $member->gender; @@ -1519,44 +1387,45 @@ $this->pass = $member->pass; $this->pass_crypted = $member->pass_indatabase_crypted; - if (empty($login)) { - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $login = dol_buildlogin($member->lastname, $member->firstname); - } + if (empty($login)) $login = strtolower(substr($member->firstname, 0, 4)).strtolower(substr($member->lastname, 0, 4)); $this->login = $login; $this->db->begin(); // Create and set $this->id $result = $this->create($user); - if ($result > 0) { + if ($result > 0) + { if (!empty($this->pass)) { // If a clear password was received (this situation should not happen anymore now), we use it to save it into database $newpass = $this->setPassword($user, $this->pass); - if (is_numeric($newpass) && $newpass < 0) { - $result = -2; - } + if (is_numeric($newpass) && $newpass < 0) $result = -2; } elseif (!empty($this->pass_crypted)) { // If a crypted password is already known, we save it directly into database because the previous create did not save it. $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql .= " SET pass_crypted = '".$this->db->escape($this->pass_crypted)."'"; $sql .= " WHERE rowid=".$this->id; $resql = $this->db->query($sql); - if (!$resql) { + if (!$resql) + { $result = -1; } } - if ($result > 0 && $member->fk_soc) { // If member is linked to a thirdparty + if ($result > 0 && $member->fk_soc) // If member is linked to a thirdparty + { $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql .= " SET fk_soc=".$member->fk_soc; $sql .= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $this->db->commit(); return $this->id; - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); @@ -1565,17 +1434,20 @@ } } - if ($result > 0) { + if ($result > 0) + { $this->db->commit(); return $this->id; - } else { + } + else + { // $this->error deja positionne $this->db->rollback(); return -2; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Assign rights by default * @@ -1583,20 +1455,21 @@ */ public function set_default_rights() { - // phpcs:enable + // phpcs:enable global $conf; - $rd = array(); - $num = 0; $sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def"; $sql .= " WHERE bydefault = 1"; $sql .= " AND entity = ".$conf->entity; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) { + $rd = array(); + while ($i < $num) + { $row = $this->db->fetch_row($resql); $rd[$i] = $row[0]; $i++; @@ -1604,15 +1477,14 @@ $this->db->free($resql); } $i = 0; - while ($i < $num) { + while ($i < $num) + { $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]"; $result = $this->db->query($sql); $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])"; $result = $this->db->query($sql); - if (!$result) { - return -1; - } + if (!$result) return -1; $i++; } @@ -1639,26 +1511,30 @@ dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember.", nosyncmemberpass=".$nosyncmemberpass); // Clean parameters - $this->civility_code = trim($this->civility_code); + + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); + $this->lastname = trim($this->lastname); $this->firstname = trim($this->firstname); $this->employee = $this->employee ? $this->employee : 0; $this->login = trim($this->login); $this->gender = trim($this->gender); + $this->birth = trim($this->birth); $this->pass = trim($this->pass); $this->api_key = trim($this->api_key); - $this->address = $this->address ? trim($this->address) : trim($this->address); - $this->zip = $this->zip ? trim($this->zip) : trim($this->zip); - $this->town = $this->town ? trim($this->town) : trim($this->town); - $this->setUpperOrLowerCase(); + $this->address = $this->address ?trim($this->address) : trim($this->address); + $this->zip = $this->zip ?trim($this->zip) : trim($this->zip); + $this->town = $this->town ?trim($this->town) : trim($this->town); $this->state_id = trim($this->state_id); $this->country_id = ($this->country_id > 0) ? $this->country_id : 0; $this->office_phone = trim($this->office_phone); $this->office_fax = trim($this->office_fax); $this->user_mobile = trim($this->user_mobile); - $this->personal_mobile = trim($this->personal_mobile); + $this->personal_mobile = trim($this->personal_mobile); $this->email = trim($this->email); - $this->personal_email = trim($this->personal_email); + $this->personal_email = trim($this->personal_email); $this->job = trim($this->job); $this->signature = trim($this->signature); @@ -1673,20 +1549,19 @@ $this->color = empty($this->color) ? '' : $this->color; $this->dateemployment = empty($this->dateemployment) ? '' : $this->dateemployment; $this->dateemploymentend = empty($this->dateemploymentend) ? '' : $this->dateemploymentend; - $this->datestartvalidity = empty($this->datestartvalidity) ? '' : $this->datestartvalidity; - $this->dateendvalidity = empty($this->dateendvalidity) ? '' : $this->dateendvalidity; - $this->birth = trim($this->birth); - $this->fk_warehouse = (int) $this->fk_warehouse; + $this->fk_warehouse = trim(empty($this->fk_warehouse) ? '' : $this->fk_warehouse); // Check parameters - if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) { + if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) + { $langs->load("errors"); $this->error = $langs->trans("ErrorBadEMail", $this->email); return -1; } - if (empty($this->login)) { + if (empty($this->login)) + { $langs->load("errors"); - $this->error = $langs->trans("ErrorFieldRequired", 'Login'); + $this->error = $langs->trans("ErrorFieldRequired", $this->login); return -1; } @@ -1694,17 +1569,14 @@ // Update datas $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; - $sql .= " civility = '".$this->db->escape($this->civility_code)."'"; - $sql .= ", lastname = '".$this->db->escape($this->lastname)."'"; + $sql .= " lastname = '".$this->db->escape($this->lastname)."'"; $sql .= ", firstname = '".$this->db->escape($this->firstname)."'"; $sql .= ", employee = ".(int) $this->employee; $sql .= ", login = '".$this->db->escape($this->login)."'"; $sql .= ", api_key = ".($this->api_key ? "'".$this->db->escape($this->api_key)."'" : "null"); $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman' $sql .= ", birth=".(strval($this->birth) != '' ? "'".$this->db->idate($this->birth)."'" : 'null'); - if (!empty($user->admin)) { - $sql .= ", admin = ".(int) $this->admin; // admin flag can be set/unset only by an admin user - } + if (!empty($user->admin)) $sql .= ", admin = ".(int) $this->admin; // admin flag can be set/unset only by an admin user $sql .= ", address = '".$this->db->escape($this->address)."'"; $sql .= ", zip = '".$this->db->escape($this->zip)."'"; $sql .= ", town = '".$this->db->escape($this->town)."'"; @@ -1713,80 +1585,70 @@ $sql .= ", office_phone = '".$this->db->escape($this->office_phone)."'"; $sql .= ", office_fax = '".$this->db->escape($this->office_fax)."'"; $sql .= ", user_mobile = '".$this->db->escape($this->user_mobile)."'"; - $sql .= ", personal_mobile = '".$this->db->escape($this->personal_mobile)."'"; + $sql .= ", personal_mobile = '".$this->db->escape($this->personal_mobile)."'"; $sql .= ", email = '".$this->db->escape($this->email)."'"; - $sql .= ", personal_email = '".$this->db->escape($this->personal_email)."'"; - $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; + $sql .= ", personal_email = '".$this->db->escape($this->personal_email)."'"; + $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; $sql .= ", job = '".$this->db->escape($this->job)."'"; $sql .= ", signature = '".$this->db->escape($this->signature)."'"; $sql .= ", accountancy_code = '".$this->db->escape($this->accountancy_code)."'"; $sql .= ", color = '".$this->db->escape($this->color)."'"; $sql .= ", dateemployment=".(strval($this->dateemployment) != '' ? "'".$this->db->idate($this->dateemployment)."'" : 'null'); $sql .= ", dateemploymentend=".(strval($this->dateemploymentend) != '' ? "'".$this->db->idate($this->dateemploymentend)."'" : 'null'); - $sql .= ", datestartvalidity=".(strval($this->datestartvalidity) != '' ? "'".$this->db->idate($this->datestartvalidity)."'" : 'null'); - $sql .= ", dateendvalidity=".(strval($this->dateendvalidity) != '' ? "'".$this->db->idate($this->dateendvalidity)."'" : 'null'); $sql .= ", note = '".$this->db->escape($this->note_private)."'"; $sql .= ", note_public = '".$this->db->escape($this->note_public)."'"; $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null"); $sql .= ", openid = ".($this->openid ? "'".$this->db->escape($this->openid)."'" : "null"); $sql .= ", fk_user = ".($this->fk_user > 0 ? "'".$this->db->escape($this->fk_user)."'" : "null"); - $sql .= ", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? "'".$this->db->escape($this->fk_user_expense_validator)."'" : "null"); - $sql .= ", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? "'".$this->db->escape($this->fk_user_holiday_validator)."'" : "null"); - if (isset($this->thm) || $this->thm != '') { - $sql .= ", thm= ".($this->thm != '' ? "'".$this->db->escape($this->thm)."'" : "null"); - } - if (isset($this->tjm) || $this->tjm != '') { - $sql .= ", tjm= ".($this->tjm != '' ? "'".$this->db->escape($this->tjm)."'" : "null"); - } - if (isset($this->salary) || $this->salary != '') { - $sql .= ", salary= ".($this->salary != '' ? "'".$this->db->escape($this->salary)."'" : "null"); - } - if (isset($this->salaryextra) || $this->salaryextra != '') { - $sql .= ", salaryextra= ".($this->salaryextra != '' ? "'".$this->db->escape($this->salaryextra)."'" : "null"); - } + $sql .= ", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? "'".$this->db->escape($this->fk_user_expense_validator)."'" : "null"); + $sql .= ", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? "'".$this->db->escape($this->fk_user_holiday_validator)."'" : "null"); + if (isset($this->thm) || $this->thm != '') $sql .= ", thm= ".($this->thm != '' ? "'".$this->db->escape($this->thm)."'" : "null"); + if (isset($this->tjm) || $this->tjm != '') $sql .= ", tjm= ".($this->tjm != '' ? "'".$this->db->escape($this->tjm)."'" : "null"); + if (isset($this->salary) || $this->salary != '') $sql .= ", salary= ".($this->salary != '' ? "'".$this->db->escape($this->salary)."'" : "null"); + if (isset($this->salaryextra) || $this->salaryextra != '') $sql .= ", salaryextra= ".($this->salaryextra != '' ? "'".$this->db->escape($this->salaryextra)."'" : "null"); $sql .= ", weeklyhours= ".($this->weeklyhours != '' ? "'".$this->db->escape($this->weeklyhours)."'" : "null"); $sql .= ", entity = '".$this->db->escape($this->entity)."'"; $sql .= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null'); $sql .= ", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null'); - $sql .= ", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse : "null"); - $sql .= ", lang = ".($this->lang ? "'".$this->db->escape($this->lang)."'" : "null"); + $sql .= ", fk_warehouse = ".($this->fk_warehouse ? "'".$this->db->escape($this->fk_warehouse)."'" : "null"); + $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $nbrowsaffected += $this->db->affected_rows($resql); // Update password - if (!empty($this->pass)) { - if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) { + if (!empty($this->pass)) + { + if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) + { // Si mot de passe saisi et different de celui en base $result = $this->setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass); - if (!$nbrowsaffected) { - $nbrowsaffected++; - } + if (!$nbrowsaffected) $nbrowsaffected++; } } // If user is linked to a member, remove old link to this member - if ($this->fk_member > 0) { + if ($this->fk_member > 0) + { dol_syslog(get_class($this)."::update remove link with member. We will recreate it later", LOG_DEBUG); $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->fk_member; $resql = $this->db->query($sql); - if (!$resql) { - $this->error = $this->db->error(); $this->db->rollback(); return -5; - } + if (!$resql) { $this->error = $this->db->error(); $this->db->rollback(); return -5; } } // Set link to user dol_syslog(get_class($this)."::update set link with member", LOG_DEBUG); $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member =".($this->fk_member > 0 ? $this->fk_member : 'null')." where rowid = ".$this->id; $resql = $this->db->query($sql); - if (!$resql) { - $this->error = $this->db->error(); $this->db->rollback(); return -5; - } - - if ($nbrowsaffected) { // If something has changed in data - if ($this->fk_member > 0 && !$nosyncmember) { + if (!$resql) { $this->error = $this->db->error(); $this->db->rollback(); return -5; } + + if ($nbrowsaffected) // If something has changed in data + { + if ($this->fk_member > 0 && !$nosyncmember) + { dol_syslog(get_class($this)."::update user is linked with a member. We try to update member too.", LOG_DEBUG); require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; @@ -1796,8 +1658,8 @@ $adh = new Adherent($this->db); $result = $adh->fetch($this->fk_member); - if ($result > 0) { - $adh->civility_code = $this->civility_code; + if ($result > 0) + { $adh->firstname = $this->firstname; $adh->lastname = $this->lastname; $adh->login = $this->login; @@ -1806,7 +1668,7 @@ $adh->pass = $this->pass; - //$adh->societe = (empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe); + $adh->societe = (empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe); $adh->address = $this->address; $adh->town = $this->town; @@ -1825,30 +1687,35 @@ $adh->user_login = $this->login; $result = $adh->update($user, 0, 1, 0); - if ($result < 0) { + if ($result < 0) + { $this->error = $adh->error; $this->errors = $adh->errors; dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR); $error++; } - } elseif ($result < 0) { + } + elseif ($result < 0) + { $this->error = $adh->error; $this->errors = $adh->errors; $error++; } } - if ($this->contact_id > 0 && !$nosynccontact) { + if ($this->contact_id > 0 && !$nosynccontact) + { dol_syslog(get_class($this)."::update user is linked with a contact. We try to update contact too.", LOG_DEBUG); require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; - // This user is linked with a contact, so we also update contact information if this is an update. + // This user is linked with a contact, so we also update contact information + // if this is an update. $tmpobj = new Contact($this->db); $result = $tmpobj->fetch($this->contact_id); - if ($result >= 0) { - $tmpobj->civility_code = $this->civility_code; + if ($result >= 0) + { $tmpobj->firstname = $this->firstname; $tmpobj->lastname = $this->lastname; $tmpobj->login = $this->login; @@ -1877,13 +1744,16 @@ $tmpobj->user_login = $this->login; $result = $tmpobj->update($tmpobj->id, $user, 0, 'update', 1); - if ($result < 0) { + if ($result < 0) + { $this->error = $tmpobj->error; $this->errors = $tmpobj->errors; dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR); $error++; } - } else { + } + else + { $this->error = $tmpobj->error; $this->errors = $tmpobj->errors; $error++; @@ -1894,38 +1764,44 @@ $action = 'update'; // Actions on extra fields - if (!$error) { + if (!$error) + { $result = $this->insertExtraFields(); - if ($result < 0) { + if ($result < 0) + { $error++; } } - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { // Call trigger $result = $this->call_trigger('USER_MODIFY', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } // End call triggers } - if (!$error) { + if (!$error) + { $this->db->commit(); return $nbrowsaffected; - } else { + } + else + { dol_syslog(get_class($this)."::update error=".$this->error, LOG_ERR); $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); return -2; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Mise a jour en base de la date de derniere connexion d'un utilisateur * Fonction appelee lors d'une nouvelle connexion @@ -1934,7 +1810,7 @@ */ public function update_last_login_date() { - // phpcs:enable + // phpcs:enable $now = dol_now(); $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; @@ -1945,11 +1821,14 @@ dol_syslog(get_class($this)."::update_last_login_date user->id=".$this->id." ".$sql, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $this->datepreviouslogin = $this->datelastlogin; $this->datelastlogin = $now; return 1; - } else { + } + else + { $this->error = $this->db->lasterror().' sql='.$sql; return -1; } @@ -1976,7 +1855,8 @@ dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." changelater=".$changelater." notrigger=".$notrigger." nosyncmember=".$nosyncmember, LOG_DEBUG); // If new password not provided, we generate one - if (!$password) { + if (!$password) + { $password = getRandomPassword(false); } @@ -1984,32 +1864,37 @@ $password_crypted = dol_hash($password); // Mise a jour - if (!$changelater) { - if (!is_object($this->oldcopy)) { - $this->oldcopy = clone $this; - } + if (!$changelater) + { + if (!is_object($this->oldcopy)) $this->oldcopy = clone $this; $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."',"; $sql .= " pass_temp = null"; - if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) { + if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) + { $sql .= ", pass = null"; - } else { + } + else + { $sql .= ", pass = '".$this->db->escape($password)."'"; } $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::setPassword", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) { - if ($this->db->affected_rows($result)) { + if ($result) + { + if ($this->db->affected_rows($result)) + { $this->pass = $password; $this->pass_indatabase = $password; $this->pass_indatabase_crypted = $password_crypted; - if ($this->fk_member && !$nosyncmember) { + if ($this->fk_member && !$nosyncmember) + { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; // This user is linked with a member, so we also update members informations @@ -2017,14 +1902,18 @@ $adh = new Adherent($this->db); $result = $adh->fetch($this->fk_member); - if ($result >= 0) { + if ($result >= 0) + { $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1); // Cryptage non gere dans module adherent - if ($result < 0) { + if ($result < 0) + { $this->error = $adh->error; dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR); $error++; } - } else { + } + else + { $this->error = $adh->error; $error++; } @@ -2032,27 +1921,32 @@ dol_syslog(get_class($this)."::setPassword notrigger=".$notrigger." error=".$error, LOG_DEBUG); - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { // Call trigger $result = $this->call_trigger('USER_NEW_PASSWORD', $user); - if ($result < 0) { - $error++; $this->db->rollback(); return -1; - } + if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } $this->db->commit(); return $this->pass; - } else { + } + else + { $this->db->rollback(); return 0; } - } else { + } + else + { $this->db->rollback(); dol_print_error($this->db); return -1; } - } else { + } + else + { // We store clear password in password temporary field. // After receiving confirmation link, we will crypt it and store it in pass_crypted $sql = "UPDATE ".MAIN_DB_PREFIX."user"; @@ -2061,9 +1955,12 @@ dol_syslog(get_class($this)."::setPassword", LOG_DEBUG); // No log $result = $this->db->query($sql); - if ($result) { + if ($result) + { return $password; - } else { + } + else + { dol_print_error($this->db); return -3; } @@ -2071,7 +1968,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Send new password by email * @@ -2082,7 +1979,7 @@ */ public function send_password($user, $password = '', $changelater = 0) { - // phpcs:enable + // phpcs:enable global $conf, $langs; global $dolibarr_main_url_root; @@ -2096,23 +1993,24 @@ $outputlangs = new Translate("", $conf); if (isset($this->conf->MAIN_LANG_DEFAULT) - && $this->conf->MAIN_LANG_DEFAULT != 'auto') { // If user has defined its own language (rare because in most cases, auto is used) + && $this->conf->MAIN_LANG_DEFAULT != 'auto') + { // If user has defined its own language (rare because in most cases, auto is used) $outputlangs->getDefaultLang($this->conf->MAIN_LANG_DEFAULT); } if ($this->conf->MAIN_LANG_DEFAULT) { - $outputlangs->setDefaultLang($this->conf->MAIN_LANG_DEFAULT); - } else { // If user has not defined its own language, we used current language + $outputlangs->setDefaultLang($this->conf->MAIN_LANG_DEFAULT); + } + else + { // If user has not defined its own language, we used current language $outputlangs = $langs; } - // Load translation files required by the page + // Load translation files required by the page $outputlangs->loadLangs(array("main", "errors", "users", "other")); $appli = constant('DOL_APPLICATION_TITLE'); - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { - $appli = $conf->global->MAIN_APPLICATION_TITLE; - } + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli = $conf->global->MAIN_APPLICATION_TITLE; $subject = $outputlangs->transnoentitiesnoconv("SubjectNewPassword", $appli); @@ -2120,7 +2018,8 @@ $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file - if (!$changelater) { + if (!$changelater) + { $url = $urlwithroot.'/'; $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived").".\n"; $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyIs")." :\n\n"; @@ -2133,7 +2032,9 @@ $mesg .= $user->getFullName($outputlangs); // Username that send the email (not the user for who we want to reset password) dol_syslog(get_class($this)."::send_password changelater is off, url=".$url); - } else { + } + else + { $url = $urlwithroot.'/user/passwordforgotten.php?action=validatenewpassword&username='.urlencode($this->login)."&passwordhash=".dol_hash($password); $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived")."\n"; @@ -2150,8 +2051,8 @@ $trackid = 'use'.$this->id; - $mailfile = new CMailFile( - $subject, + $mailfile = new CMailFile( + $subject, $this->email, $conf->global->MAIN_MAIL_EMAIL_FROM, $mesg, @@ -2161,15 +2062,18 @@ '', '', 0, - $msgishtml, - '', - '', - $trackid - ); - - if ($mailfile->sendfile()) { + $msgishtml, + '', + '', + $trackid + ); + + if ($mailfile->sendfile()) + { return 1; - } else { + } + else + { $langs->trans("errors"); $this->error = $langs->trans("ErrorFailedToSendPassword").' '.$mailfile->error; return -1; @@ -2187,7 +2091,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Read clicktodial information for user * @@ -2195,14 +2099,16 @@ */ public function fetch_clicktodial() { - // phpcs:enable + // phpcs:enable $sql = "SELECT url, login, pass, poste "; $sql .= " FROM ".MAIN_DB_PREFIX."user_clicktodial as u"; $sql .= " WHERE u.fk_user = ".$this->id; $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { $obj = $this->db->fetch_object($resql); $this->clicktodial_url = $obj->url; @@ -2215,21 +2121,23 @@ $this->db->free($resql); return 1; - } else { + } + else + { $this->error = $this->db->error(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update clicktodial info * * @return int <0 if KO, >0 if OK - */ - public function update_clicktodial() - { - // phpcs:enable + */ + public function update_clicktodial() + { + // phpcs:enable $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_clicktodial"; @@ -2248,18 +2156,21 @@ dol_syslog(get_class($this).'::update_clicktodial', LOG_DEBUG); $result = $this->db->query($sql); - if ($result) { + if ($result) + { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); $this->error = $this->db->lasterror(); return -1; } - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Add user into a group * @@ -2270,7 +2181,7 @@ */ public function SetInGroup($group, $entity, $notrigger = 0) { - // phpcs:enable + // phpcs:enable global $conf, $langs, $user; $error = 0; @@ -2288,35 +2199,40 @@ $sql .= " VALUES (".$entity.",".$this->id.",".$group.")"; $result = $this->db->query($sql); - if ($result) { - if (!$error && !$notrigger) { + if ($result) + { + if (!$error && !$notrigger) + { $this->newgroupid = $group; // deprecated. Remove this. $this->context = array('audit'=>$langs->trans("UserSetInGroup"), 'newgroupid'=>$group); // Call trigger $result = $this->call_trigger('USER_MODIFY', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } // End call triggers } - if (!$error) { + if (!$error) + { $this->db->commit(); return 1; - } else { + } + else + { dol_syslog(get_class($this)."::SetInGroup ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Remove a user from a group * @@ -2327,7 +2243,7 @@ */ public function RemoveFromGroup($group, $entity, $notrigger = 0) { - // phpcs:enable + // phpcs:enable global $conf, $langs, $user; $error = 0; @@ -2340,28 +2256,33 @@ $sql .= " AND entity = ".$entity; $result = $this->db->query($sql); - if ($result) { - if (!$error && !$notrigger) { + if ($result) + { + if (!$error && !$notrigger) + { $this->oldgroupid = $group; // deprecated. Remove this. $this->context = array('audit'=>$langs->trans("UserRemovedFromGroup"), 'oldgroupid'=>$group); // Call trigger $result = $this->call_trigger('USER_MODIFY', $user); - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } // End call triggers } - if (!$error) { + if (!$error) + { $this->db->commit(); return 1; - } else { + } + else + { dol_syslog(get_class($this)."::RemoveFromGroup ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; @@ -2409,18 +2330,14 @@ global $dolibarr_main_authentication, $dolibarr_main_demo; global $menumanager; - if (!$user->rights->user->user->lire && $user->id != $this->id) { - $option = 'nolink'; - } - - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) { - $withpictoimg = 0; - } + if (!$user->rights->user->user->lire && $user->id != $this->id) $option = 'nolink'; + + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg = 0; $result = ''; $label = ''; - $companylink = ''; - - if (!empty($this->photo)) { + + if (!empty($this->photo)) + { $label .= '
'; $label .= Form::showphoto('userphoto', $this, 0, 60, 0, 'photowithmargin photologintooltip', 'small', 0, 1); // Force height to 60 so we total height of tooltip can be calculated and collision can be managed $label .= '
'; @@ -2428,82 +2345,63 @@ // Info Login $label .= '
'; - $label .= img_picto('', $this->picto).' '.$langs->trans("User").''; - $label .= ' '.$this->getLibStatut(4); - $label .= '
'.$langs->trans('Name').': '.dol_string_nohtmltag($this->getFullName($langs, '')); - if (!empty($this->login)) { - $label .= '
'.$langs->trans('Login').': '.dol_string_nohtmltag($this->login); - } - if (!empty($this->job)) { - $label .= '
'.$langs->trans("Job").': '.dol_string_nohtmltag($this->job); - } - $label .= '
'.$langs->trans("Email").': '.dol_string_nohtmltag($this->email); - if (!empty($this->phone)) { - $label .= '
'.$langs->trans("Phone").': '.dol_string_nohtmltag($this->phone); - } - if (!empty($this->admin)) { + $label .= ''.$langs->trans("User").'
'; + $label .= ''.$langs->trans('Name').': '.$this->getFullName($langs, ''); + if (!empty($this->login)) $label .= '
'.$langs->trans('Login').': '.$this->login; + if (!empty($this->job)) $label .= '
'.$langs->trans("Job").': '.$this->job; + $label .= '
'.$langs->trans("Email").': '.$this->email; + if (!empty($this->phone)) $label .= '
'.$langs->trans("Phone").': '.$this->phone; + if (!empty($this->admin)) $label .= '
'.$langs->trans("Administrator").': '.yn($this->admin); - } - $company = ''; - if (!empty($this->socid)) { // Add thirdparty for external users + if (!empty($this->socid)) // Add thirdparty for external users + { $thirdpartystatic = new Societe($db); $thirdpartystatic->fetch($this->socid); - if (empty($hidethirdpartylogo)) { - $companylink = ' '.$thirdpartystatic->getNomUrl(2, (($option == 'nolink') ? 'nolink' : '')); // picto only of company - } - $company = ' ('.$langs->trans("Company").': '.dol_string_nohtmltag($thirdpartystatic->name).')'; + if (empty($hidethirdpartylogo)) $companylink = ' '.$thirdpartystatic->getNomUrl(2, (($option == 'nolink') ? 'nolink' : '')); // picto only of company + $company = ' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; } $type = ($this->socid ? $langs->trans("External").$company : $langs->trans("Internal")); - $label .= '
'.$langs->trans("Type").': '.dol_string_nohtmltag($type); + $label .= '
'.$langs->trans("Type").': '.$type; + $label .= '
'.$langs->trans("Status").': '.$this->getLibStatut(4); $label .= '
'; - if ($infologin > 0) { + if ($infologin > 0) + { $label .= '
'; $label .= '
'.$langs->trans("Session").''; - $label .= '
'.$langs->trans("IPAddress").': '.dol_string_nohtmltag(getUserRemoteIP()); - if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) { - $label .= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (User entity '.$this->entity.')'; - } - $label .= '
'.$langs->trans("AuthenticationMode").': '.dol_string_nohtmltag($_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)')); + $label .= '
'.$langs->trans("IPAddress").': '.$_SERVER["REMOTE_ADDR"]; + if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $label .= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$this->entity.')'; + $label .= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)'); $label .= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($this->datelastlogin, "dayhour", 'tzuser'); $label .= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($this->datepreviouslogin, "dayhour", 'tzuser'); - $label .= '
'.$langs->trans("CurrentTheme").': '.dol_string_nohtmltag($conf->theme); - $label .= '
'.$langs->trans("CurrentMenuManager").': '.dol_string_nohtmltag($menumanager->name); + $label .= '
'.$langs->trans("CurrentTheme").': '.$conf->theme; + $label .= '
'.$langs->trans("CurrentMenuManager").': '.$menumanager->name; $s = picto_from_langcode($langs->getDefaultLang()); - $label .= '
'.$langs->trans("CurrentUserLanguage").': '.dol_string_nohtmltag(($s ? $s.' ' : '').$langs->getDefaultLang()); - $label .= '
'.$langs->trans("Browser").': '.dol_string_nohtmltag($conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' ('.$_SERVER['HTTP_USER_AGENT'].')'); - $label .= '
'.$langs->trans("Layout").': '.dol_string_nohtmltag($conf->browser->layout); - $label .= '
'.$langs->trans("Screen").': '.dol_string_nohtmltag($_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']); - if ($conf->browser->layout == 'phone') { - $label .= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); - } - if (!empty($_SESSION["disablemodules"])) { - $label .= '
'.$langs->trans("DisabledModules").':
'.dol_string_nohtmltag(join(', ', explode(',', $_SESSION["disablemodules"]))); - } - } - if ($infologin < 0) { - $label = ''; - } + $label .= '
'.$langs->trans("CurrentUserLanguage").': '.($s ? $s.' ' : '').$langs->getDefaultLang(); + $label .= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' ('.$_SERVER['HTTP_USER_AGENT'].')'; + $label .= '
'.$langs->trans("Layout").': '.$conf->browser->layout; + $label .= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; + if ($conf->browser->layout == 'phone') $label .= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); + if (!empty($_SESSION["disablemodules"])) $label .= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); + } + if ($infologin < 0) $label = ''; $url = DOL_URL_ROOT.'/user/card.php?id='.$this->id; - if ($option == 'leave') { - $url = DOL_URL_ROOT.'/holiday/list.php?id='.$this->id; - } - - if ($option != 'nolink') { + if ($option == 'leave') $url = DOL_URL_ROOT.'/holiday/list.php?id='.$this->id; + + if ($option != 'nolink') + { // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; } $linkstart = 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) { + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { $langs->load("users"); $label = $langs->trans("ShowUser"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; @@ -2524,33 +2422,22 @@ //if ($withpictoimg == -1) $result.='
'; $result .= (($option == 'nolink') ? '' : $linkstart); - if ($withpictoimg) { - $paddafterimage = ''; - if (abs($withpictoimg) == 1) { - $paddafterimage = 'style="margin-'.($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right').': 3px;"'; - } + if ($withpictoimg) + { + $paddafterimage = ''; + if (abs($withpictoimg) == 1) $paddafterimage = 'style="margin-'.($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right').': 3px;"'; // Only picto - if ($withpictoimg > 0) { - $picto = ''.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).''; - } + if ($withpictoimg > 0) $picto = ''.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).''; // Picto must be a photo - else { - $picto = ''.Form::showphoto('userphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1).''; - } + else $picto = ''.Form::showphoto('userphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1).''; $result .= $picto; } - if ($withpictoimg > -2 && $withpictoimg != 2) { - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $result .= ''; - } - if ($mode == 'login') { - $result .= dol_string_nohtmltag(dol_trunc($this->login, $maxlen)); - } else { - $result .= dol_string_nohtmltag($this->getFullName($langs, '', ($mode == 'firstelselast' ? 3 : ($mode == 'firstname' ? 2 : -1)), $maxlen)); - } - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $result .= ''; - } + if ($withpictoimg > -2 && $withpictoimg != 2) + { + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .= ''; + if ($mode == 'login') $result .= dol_trunc($this->login, $maxlen); + else $result .= $this->getFullName($langs, '', ($mode == 'firstelselast' ? 3 : ($mode == 'firstname' ? 2 : -1)), $maxlen); + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .= ''; } $result .= (($option == 'nolink') ? '' : $linkend); //if ($withpictoimg == -1) $result.='
'; @@ -2561,11 +2448,8 @@ $hookmanager->initHooks(array('userdao')); $parameters = array('id'=>$this->id, 'getnomurl'=>$result); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + if ($reshook > 0) $result = $hookmanager->resPrint; + else $result .= $hookmanager->resPrint; return $result; } @@ -2587,33 +2471,31 @@ $linkend = '
'; //Check user's rights to see an other user - if ((!$user->rights->user->user->lire && $this->id != $user->id)) { - $option = 'nolink'; - } - - if ($option == 'xxx') { + if ((!$user->rights->user->user->lire && $this->id != $user->id)) $option = 'nolink'; + + if ($option == 'xxx') + { $linkstart = ''; $linkend = ''; } - if ($option == 'nolink') { + if ($option == 'nolink') + { $linkstart = ''; $linkend = ''; } $result .= $linkstart; - if ($withpicto) { - $result .= img_object($langs->trans("ShowUser"), 'user', 'class="paddingright"'); - } + if ($withpicto) $result .= img_object($langs->trans("ShowUser"), 'user', 'class="paddingright"'); $result .= $this->login; $result .= $linkend; return $result; } /** - * Return the label of the status of user (active, inactive) - * - * @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 label of status of user (active, inactive) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * @return string Label of status */ public function getLibStatut($mode = 0) @@ -2621,20 +2503,21 @@ return $this->LibStatut($this->statut, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return the label of a status of user (active, inactive) - * - * @param int $status Id status + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return label of a status of user (active, inactive) + * + * @param int $status Id status * @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 LibStatut($status, $mode = 0) - { - // phpcs:enable + * @return string Label of status + */ + public function LibStatut($status, $mode = 0) + { + // phpcs:enable global $langs; - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { global $langs; //$langs->load("mymodule"); $this->labelStatus[self::STATUS_ENABLED] = $langs->trans('Enabled'); @@ -2644,9 +2527,7 @@ } $statusType = 'status5'; - if ($status == self::STATUS_ENABLED) { - $statusType = 'status4'; - } + if ($status == self::STATUS_ENABLED) $statusType = 'status4'; return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); } @@ -2665,16 +2546,12 @@ */ public function _load_ldap_dn($info, $mode = 0) { - // phpcs:enable + // phpcs:enable global $conf; $dn = ''; - if ($mode == 0) { - $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN; - } elseif ($mode == 1) { - $dn = $conf->global->LDAP_USER_DN; - } elseif ($mode == 2) { - $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS]; - } + if ($mode == 0) $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".$conf->global->LDAP_USER_DN; + elseif ($mode == 1) $dn = $conf->global->LDAP_USER_DN; + elseif ($mode == 2) $dn = $conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS]; return $dn; } @@ -2687,13 +2564,10 @@ */ public function _load_ldap_info() { - // phpcs:enable + // phpcs:enable global $conf, $langs; $info = array(); - - $socialnetworks = getArrayOfSocialNetworks(); - $keymodified = false; // Object classes @@ -2713,85 +2587,70 @@ 'LDAP_FIELD_FAX' => 'office_fax', 'LDAP_FIELD_MAIL' => 'email', 'LDAP_FIELD_SID' => 'ldap_sid', + 'LDAP_FIELD_SKYPE' => 'skype', + 'LDAP_FIELD_TWITTER' => 'twitter', + 'LDAP_FIELD_FACEBOOK' => 'facebook', + 'LDAP_FIELD_LINKEDIN' => 'linkedin' ); // Champs - foreach ($ldapkey as $constname => $varname) { - if (!empty($this->$varname) && !empty($conf->global->$constname)) { + foreach ($ldapkey as $constname => $varname) + { + if (!empty($this->$varname) && !empty($conf->global->$constname)) + { $info[$conf->global->$constname] = $this->$varname; // Check if it is the LDAP key and if its value has been changed - if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) { - if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) { - $keymodified = true; // For check if LDAP key has been modified - } + if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) + { + if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) $keymodified = true; // For check if LDAP key has been modified } } } - foreach ($socialnetworks as $key => $value) { - if ($this->socialnetworks[$value['label']] && !empty($conf->global->{'LDAP_FIELD_'.strtoupper($value['label'])})) { - $info[$conf->global->{'LDAP_FIELD_'.strtoupper($value['label'])}] = $this->socialnetworks[$value['label']]; - } - } - if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) { - $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address; - } - if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) { - $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip; - } - if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) { - $info[$conf->global->LDAP_FIELD_TOWN] = $this->town; - } - if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) { - $info[$conf->global->LDAP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_public, 2); - } - if ($this->socid > 0) { + if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address; + if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip; + if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) $info[$conf->global->LDAP_FIELD_TOWN] = $this->town; + if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_public, 2); + if ($this->socid > 0) + { $soc = new Societe($this->db); $soc->fetch($this->socid); $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name; - if ($soc->client == 1) { - $info["businessCategory"] = "Customers"; - } - if ($soc->client == 2) { - $info["businessCategory"] = "Prospects"; - } - if ($soc->fournisseur == 1) { - $info["businessCategory"] = "Suppliers"; - } + if ($soc->client == 1) $info["businessCategory"] = "Customers"; + if ($soc->client == 2) $info["businessCategory"] = "Prospects"; + if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers"; } // When password is modified - if (!empty($this->pass)) { - if (!empty($conf->global->LDAP_FIELD_PASSWORD)) { - $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte - } - if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) { - $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption) - } + if (!empty($this->pass)) + { + if (!empty($conf->global->LDAP_FIELD_PASSWORD)) $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte + if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption) } // Set LDAP password if possible - elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') { // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password - if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) { + elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password + { + if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) + { // Just for the default MD5 ! - if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) { + if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) + { if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) { $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase_crypted, 5); // Create OpenLDAP MD5 password from Dolibarr MD5 password } } } // Use $this->pass_indatabase value if exists - elseif (!empty($this->pass_indatabase)) { - if (!empty($conf->global->LDAP_FIELD_PASSWORD)) { - $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte - } - if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) { - $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 4); // md5 for OpenLdap TODO add type of encryption - } - } - } - - if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') { + elseif (!empty($this->pass_indatabase)) + { + if (!empty($conf->global->LDAP_FIELD_PASSWORD)) $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte + if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 4); // md5 for OpenLdap TODO add type of encryption + } + } + + if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') + { $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware $info['uidnumber'] = $this->id; @@ -2804,40 +2663,33 @@ $info["phpgwContactCatId"] = 0; $info["phpgwContactAccess"] = "public"; - if (dol_strlen($this->egroupware_id) == 0) { + if (dol_strlen($this->egroupware_id) == 0) + { $this->egroupware_id = 1; } $info["phpgwContactOwner"] = $this->egroupware_id; - if ($this->email) { - $info["rfc822Mailbox"] = $this->email; - } - if ($this->phone_mobile) { - $info["phpgwCellTelephoneNumber"] = $this->phone_mobile; - } - } - - if (!empty($conf->global->LDAP_FIELD_USERID)) { - $info[$conf->global->LDAP_FIELD_USERID] = $this->id; - } - if (!empty($info[$conf->global->LDAP_FIELD_GROUPID])) { - $usergroup = new UserGroup($this->db); - $groupslist = $usergroup->listGroupsForUser($this->id); - $info[$conf->global->LDAP_FIELD_GROUPID] = '1'; - if (!empty($groupslist)) { - foreach ($groupslist as $groupforuser) { - $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id; //Select first group in list - break; - } - } - } - if (!empty($this->firstname) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) { - $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] = "{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->firstname"; - } - - return $info; - } + if ($this->email) $info["rfc822Mailbox"] = $this->email; + if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile; + } + + if (!empty($conf->global->LDAP_FIELD_USERID))$info[$conf->global->LDAP_FIELD_USERID] = $this->id; + if (!empty($info[$conf->global->LDAP_FIELD_GROUPID])) { + $usergroup = new UserGroup($this->db); + $groupslist = $usergroup->listGroupsForUser($this->id); + $info[$conf->global->LDAP_FIELD_GROUPID] = '1'; + if (!empty($groupslist)) { + foreach ($groupslist as $groupforuser) { + $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id; //Select first group in list + break; + } + } + } + if (!empty($this->firstname) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] = "{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->firstname"; + + return $info; + } /** @@ -2845,7 +2697,7 @@ * Used to build previews or test instances. * id must be 0 if object instance is a specimen. * - * @return int + * @return void */ public function initAsSpecimen() { @@ -2864,7 +2716,7 @@ $this->note_public = 'This is a note public'; $this->note_private = 'This is a note private'; $this->email = 'email@specimen.com'; - $this->personal_email = 'personalemail@specimen.com'; + $this->personal_email = 'personalemail@specimen.com'; $this->socialnetworks = array( 'skype' => 'skypepseudo', 'twitter' => 'twitterpseudo', @@ -2874,7 +2726,7 @@ $this->office_phone = '0999999999'; $this->office_fax = '0999999998'; $this->user_mobile = '0999999997'; - $this->personal_mobile = '0999999996'; + $this->personal_mobile = '0999999996'; $this->admin = 0; $this->login = 'dolibspec'; $this->pass = 'dolibspec'; @@ -2887,8 +2739,9 @@ $this->datepreviouslogin = $now; $this->statut = 1; + //$this->societe_id = 1; For external users + //$this->contact_id = 1; For external users $this->entity = 1; - return 1; } /** @@ -2905,8 +2758,10 @@ $sql .= " WHERE u.rowid = ".$id; $result = $this->db->query($sql); - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; @@ -2918,7 +2773,9 @@ } $this->db->free($result); - } else { + } + else + { dol_print_error($this->db); } } @@ -2937,13 +2794,16 @@ $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $obj = $this->db->fetch_object($resql); $nb = $obj->nb; $this->db->free($resql); return $nb; - } else { + } + else + { $this->error = $this->db->error(); return -1; } @@ -2963,32 +2823,35 @@ $sql = "SELECT count(rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."user"; - if ($option == 'superadmin') { + if ($option == 'superadmin') + { $sql .= " WHERE entity = 0"; - } else { + if ($admin >= 0) $sql .= " AND admin = ".$admin; + } + else + { $sql .= " WHERE entity IN (".getEntity('user', 0).")"; - if ($limitTo == 'active') { - $sql .= " AND statut = 1"; - } - } - if ($admin >= 0) { - $sql .= " AND admin = ".(int) $admin; + if ($limitTo == 'active') $sql .= " AND statut = 1"; + if ($admin >= 0) $sql .= " AND admin = ".$admin; } $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $obj = $this->db->fetch_object($resql); - $nb = (int) $obj->nb; + $nb = $obj->nb; $this->db->free($resql); return $nb; - } else { + } + else + { $this->error = $this->db->lasterror(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update user using data from the LDAP * @@ -2997,11 +2860,9 @@ */ public function update_ldap2dolibarr(&$ldapuser) { - // phpcs:enable + // phpcs:enable // TODO: Voir pourquoi le update met à jour avec toutes les valeurs vide (global $user écrase ?) global $user, $conf; - - $socialnetworks = getArrayOfSocialNetworks(); $this->firstname = $ldapuser->{$conf->global->LDAP_FIELD_FIRSTNAME}; $this->lastname = $ldapuser->{$conf->global->LDAP_FIELD_NAME}; @@ -3013,14 +2874,14 @@ $this->user_mobile = $ldapuser->{$conf->global->LDAP_FIELD_MOBILE}; $this->office_fax = $ldapuser->{$conf->global->LDAP_FIELD_FAX}; $this->email = $ldapuser->{$conf->global->LDAP_FIELD_MAIL}; - foreach ($socialnetworks as $key => $value) { - $tmpkey = 'LDAP_FIELD_'.strtoupper($value['label']); - $this->socialnetworks[$value['label']] = $ldapuser->{$conf->global->$tmpkey}; - } + $this->skype = $ldapuser->{$conf->global->LDAP_FIELD_SKYPE}; + $this->twitter = $ldapuser->{$conf->global->LDAP_FIELD_TWITTER}; + $this->facebook = $ldapuser->{$conf->global->LDAP_FIELD_FACEBOOK}; + $this->linkedin = $ldapuser->{$conf->global->LDAP_FIELD_LINKEDIN}; $this->ldap_sid = $ldapuser->{$conf->global->LDAP_FIELD_SID}; $this->job = $ldapuser->{$conf->global->LDAP_FIELD_TITLE}; - $this->note_public = $ldapuser->{$conf->global->LDAP_FIELD_DESCRIPTION}; + $this->note = $ldapuser->{$conf->global->LDAP_FIELD_DESCRIPTION}; $result = $this->update($user); @@ -3030,7 +2891,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return and array with all instanciated first level children users of current user * @@ -3039,21 +2900,25 @@ */ public function get_children() { - // phpcs:enable + // phpcs:enable $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."user"; $sql .= " WHERE fk_user = ".$this->id; dol_syslog(get_class($this)."::get_children sql=".$sql, LOG_DEBUG); $res = $this->db->query($sql); - if ($res) { + if ($res) + { $users = array(); - while ($rec = $this->db->fetch_array($res)) { + while ($rec = $this->db->fetch_array($res)) + { $user = new User($this->db); $user->fetch($rec['rowid']); $users[] = $user; } return $users; - } else { + } + else + { dol_print_error($this->db); return -1; } @@ -3079,18 +2944,22 @@ dol_syslog(get_class($this)."::loadParentOf", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { $this->parentof[$obj->id_son] = $obj->id_parent; } return 1; - } else { + } + else + { dol_print_error($this->db); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Build the hierarchy/tree of users into an array. * Set and return this->users that is an array sorted according to tree with arrays of: @@ -3104,9 +2973,9 @@ * @param string $filter SQL filter on users * @return array Array of users $this->users. Note: $this->parentof is also set. */ - public function get_full_tree($deleteafterid = 0, $filter = '') - { - // phpcs:enable + public function get_full_tree($deleteafterid = 0, $filter = '') + { + // phpcs:enable global $conf, $user; global $hookmanager; @@ -3129,15 +2998,15 @@ } else { $sql .= " WHERE u.entity IN (".getEntity('user').")"; } - if ($filter) { - $sql .= " AND ".$filter; - } + if ($filter) $sql .= " AND ".$filter; dol_syslog(get_class($this)."::get_full_tree get user list", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $i = 0; - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { $this->users[$obj->rowid]['rowid'] = $obj->rowid; $this->users[$obj->rowid]['id'] = $obj->rowid; $this->users[$obj->rowid]['fk_user'] = $obj->fk_user; @@ -3153,31 +3022,38 @@ $this->users[$obj->rowid]['photo'] = $obj->photo; $i++; } - } else { + } + else + { dol_print_error($this->db); return -1; } // We add the fullpath property to each elements of first level (no parent exists) dol_syslog(get_class($this)."::get_full_tree call to build_path_from_id_user", LOG_DEBUG); - foreach ($this->users as $key => $val) { + foreach ($this->users as $key => $val) + { $result = $this->build_path_from_id_user($key, 0); // Process a branch from the root user key (this user has no parent) - if ($result < 0) { + if ($result < 0) + { $this->error = 'ErrorLoopInHierarchy'; return -1; } } // Exclude leaf including $deleteafterid from tree - if ($deleteafterid) { + if ($deleteafterid) + { //print "Look to discard user ".$deleteafterid."\n"; $keyfilter1 = '^'.$deleteafterid.'$'; $keyfilter2 = '_'.$deleteafterid.'$'; $keyfilter3 = '^'.$deleteafterid.'_'; $keyfilter4 = '_'.$deleteafterid.'_'; - foreach ($this->users as $key => $val) { + foreach ($this->users as $key => $val) + { if (preg_match('/'.$keyfilter1.'/', $val['fullpath']) || preg_match('/'.$keyfilter2.'/', $val['fullpath']) - || preg_match('/'.$keyfilter3.'/', $val['fullpath']) || preg_match('/'.$keyfilter4.'/', $val['fullpath'])) { + || preg_match('/'.$keyfilter3.'/', $val['fullpath']) || preg_match('/'.$keyfilter4.'/', $val['fullpath'])) + { unset($this->users[$key]); } } @@ -3199,36 +3075,36 @@ * @return array Array of user id lower than user (all levels under user). This overwrite this->users. * @see get_children() */ - public function getAllChildIds($addcurrentuser = 0) - { + public function getAllChildIds($addcurrentuser = 0) + { $childids = array(); - if (isset($this->cache_childids[$this->id])) { + if (isset($this->cache_childids[$this->id])) + { $childids = $this->cache_childids[$this->id]; - } else { + } + else + { // Init this->users $this->get_full_tree(); $idtoscan = $this->id; dol_syslog("Build childid for id = ".$idtoscan); - foreach ($this->users as $id => $val) { + foreach ($this->users as $id => $val) + { //var_dump($val['fullpath']); - if (preg_match('/_'.$idtoscan.'_/', $val['fullpath'])) { - $childids[$val['id']] = $val['id']; - } + if (preg_match('/_'.$idtoscan.'_/', $val['fullpath'])) $childids[$val['id']] = $val['id']; } } $this->cache_childids[$this->id] = $childids; - if ($addcurrentuser) { - $childids[$this->id] = $this->id; - } + if ($addcurrentuser) $childids[$this->id] = $this->id; return $childids; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * For user id_user and its childs available in this->users, define property fullpath and fullname. * Function called by get_full_tree(). @@ -3237,12 +3113,13 @@ * @param int $protection Deep counter to avoid infinite loop (no more required, a protection is added with array useridfound) * @return int < 0 if KO (infinit loop), >= 0 if OK */ - public function build_path_from_id_user($id_user, $protection = 0) - { - // phpcs:enable - //dol_syslog(get_class($this)."::build_path_from_id_user id_user=".$id_user." protection=".$protection, LOG_DEBUG); - - if (!empty($this->users[$id_user]['fullpath'])) { + public function build_path_from_id_user($id_user, $protection = 0) + { + // phpcs:enable + dol_syslog(get_class($this)."::build_path_from_id_user id_user=".$id_user." protection=".$protection, LOG_DEBUG); + + if (!empty($this->users[$id_user]['fullpath'])) + { // Already defined dol_syslog(get_class($this)."::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING); return 0; @@ -3254,8 +3131,10 @@ $i = 0; $cursor_user = $id_user; $useridfound = array($id_user); - while (!empty($this->parentof[$cursor_user])) { - if (in_array($this->parentof[$cursor_user], $useridfound)) { + while (!empty($this->parentof[$cursor_user])) + { + if (in_array($this->parentof[$cursor_user], $useridfound)) + { dol_syslog("The hierarchy of user has a recursive loop", LOG_WARNING); return -1; // Should not happen. Protection against looping hierarchy } @@ -3289,7 +3168,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load metrics this->nb for dashboard * @@ -3297,7 +3176,7 @@ */ public function load_state_board() { - // phpcs:enable + // phpcs:enable $this->nb = array(); @@ -3308,13 +3187,17 @@ $sql .= " AND u.entity IN (".getEntity('user').")"; $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { $this->nb["users"] = $obj->nb; } $this->db->free($resql); return 1; - } else { + } + else + { dol_print_error($this->db); $this->error = $this->db->error(); return -1; @@ -3329,7 +3212,7 @@ * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) @@ -3339,10 +3222,14 @@ $langs->load("user"); // Positionne le modele sur le nom du modele a utiliser - if (!dol_strlen($modele)) { - if (!empty($conf->global->USER_ADDON_PDF)) { + if (!dol_strlen($modele)) + { + if (!empty($conf->global->USER_ADDON_PDF)) + { $modele = $conf->global->USER_ADDON_PDF; - } else { + } + else + { $modele = 'bluesky'; } } @@ -3352,7 +3239,7 @@ return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return property of user from its id * @@ -3362,32 +3249,31 @@ */ public function user_get_property($rowid, $mode) { - // phpcs:enable + // phpcs:enable $user_property = ''; - if (empty($rowid)) { - return ''; - } + if (empty($rowid)) return ''; $sql = "SELECT rowid, email, user_mobile, civility, lastname, firstname"; $sql .= " FROM ".MAIN_DB_PREFIX."user"; - $sql .= " WHERE rowid = ".((int) $rowid); + $sql .= " WHERE rowid = '".$rowid."'"; $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $nump = $this->db->num_rows($resql); - if ($nump) { + if ($nump) + { $obj = $this->db->fetch_object($resql); - if ($mode == 'email') { - $user_property = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">"; - } elseif ($mode == 'mobile') { - $user_property = $obj->user_mobile; - } + if ($mode == 'email') $user_property = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">"; + elseif ($mode == 'mobile') $user_property = $obj->user_mobile; } return $user_property; - } else { + } + else + { dol_print_error($this->db); } } @@ -3405,14 +3291,16 @@ * @return int <0 if KO, >0 if OK */ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = array(), $filtermode = 'AND', $entityfilter = false) - { - global $conf, $user; + { + global $conf, $user; $sql = "SELECT t.rowid"; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t '; - if ($entityfilter) { - if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { + if ($entityfilter) + { + if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) + { if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { $sql .= " WHERE t.entity IS NOT NULL"; // Show all users } else { @@ -3421,10 +3309,14 @@ $sql .= " AND ug.entity IN (".getEntity('user')."))"; $sql .= " OR t.entity = 0)"; // Show always superadmin } - } else { + } + else + { $sql .= " WHERE t.entity IN (".getEntity('user').")"; } - } else { + } + else + { $sql .= " WHERE 1"; } @@ -3434,11 +3326,14 @@ foreach ($filter as $key => $value) { if ($key == 't.rowid') { $sqlwhere[] = $key.'='.$value; - } elseif (strpos($key, 'date') !== false) { + } + elseif (strpos($key, 'date') !== false) { $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; - } elseif ($key == 'customsql') { + } + elseif ($key == 'customsql') { $sqlwhere[] = $value; - } else { + } + else { $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; } } @@ -3447,18 +3342,19 @@ $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')'; } $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - $sql .= $this->db->plimit($limit + 1, $offset); - } + if ($limit) $sql .= $this->db->plimit($limit + 1, $offset); dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { + if ($resql) + { $this->users = array(); $num = $this->db->num_rows($resql); - if ($num) { - while ($obj = $this->db->fetch_object($resql)) { + if ($num) + { + while ($obj = $this->db->fetch_object($resql)) + { $line = new self($this->db); $result = $line->fetch($obj->rowid); if ($result > 0 && !empty($line->id)) { @@ -3468,64 +3364,11 @@ $this->db->free($resql); } return $num; - } else { - $this->errors[] = $this->db->lasterror(); - return -1; - } - } - - /** - * Cache the SQL results of the function "findUserIdByEmail($email)" - * - * NOTE: findUserIdByEmailCache[...] === -1 means not found in database - * - * @var array - */ - private $findUserIdByEmailCache; - - /** - * Find a user by the given e-mail and return it's user id when found - * - * NOTE: - * Use AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR - * to disable exact e-mail search - * - * @param string $email The full e-mail (or a part of a e-mail) - * @return int <0 = user was not found, >0 = The id of the user - */ - public function findUserIdByEmail($email) - { - if ($this->findUserIdByEmailCache[$email]) { - return $this->findUserIdByEmailCache[$email]; - } - - $this->findUserIdByEmailCache[$email] = -1; - - global $conf; - - $sql = 'SELECT rowid'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'user'; - - if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) { - $sql .= ' WHERE email LIKE "%'.$email.'%"'; - } else { - $sql .= ' WHERE email = "'.$email.'"'; - } - - $sql .= ' LIMIT 1'; - - $resql = $this->db->query($sql); - if (!$resql) { - return -1; - } - - $obj = $this->db->fetch_object($resql); - if (!$obj) { - return -1; - } - - $this->findUserIdByEmailCache[$email] = (int) $obj->rowid; - - return $this->findUserIdByEmailCache[$email]; - } + } + else + { + $this->errors[] = $this->db->lasterror(); + return -1; + } + } } --- /tmp/dsg/dolibarr/htdocs/user/class/github_userbankaccount.class.php +++ /tmp/dsg/dolibarr/htdocs/user/class/client_userbankaccount.class.php @@ -45,183 +45,190 @@ public $table_element = 'user_rib'; - /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; - - /** - * Date modification record (tms) - * - * @var integer - */ - public $datem; - - /** - * User id of bank account - * - * @var integer - */ - public $userid; - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct(DoliDB $db) - { - $this->db = $db; - - $this->userid = 0; - $this->solde = 0; - $this->error_number = 0; - } - - - /** - * Create bank information record - * - * @param User $user User - * @param int $notrigger 1=Disable triggers - * @return int <0 if KO, >= 0 if OK - */ - public function create(User $user = null, $notrigger = 0) - { - $now = dol_now(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rib (fk_user, datec)"; - $sql .= " VALUES (".$this->userid.", '".$this->db->idate($now)."')"; - $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->affected_rows($resql)) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user_rib"); - - return $this->update($user); - } - } else { - print $this->db->error(); - return 0; - } - } - - /** - * Update bank account - * - * @param User $user Object user - * @param int $notrigger 1=Disable triggers - * @return int <=0 if KO, >0 if OK - */ - public function update(User $user = null, $notrigger = 0) - { - global $conf; - - if (!$this->id) - { - $this->create(); - } - - $sql = "UPDATE ".MAIN_DB_PREFIX."user_rib SET"; - $sql .= " bank = '".$this->db->escape($this->bank)."'"; - $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'"; - $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'"; - $sql .= ",number='".$this->db->escape($this->number)."'"; - $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'"; - $sql .= ",bic='".$this->db->escape($this->bic)."'"; - $sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'"; - $sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'"; - $sql .= ",proprio = '".$this->db->escape($this->proprio)."'"; - $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'"; - - if (trim($this->label) != '') - $sql .= ",label = '".$this->db->escape($this->label)."'"; - else $sql .= ",label = NULL"; - $sql .= " WHERE rowid = ".$this->id; - - $result = $this->db->query($sql); - if ($result) - { - return 1; - } else { - dol_print_error($this->db); - return 0; - } - } - - /** - * Load record from database - * - * @param int $id Id of record - * @param string $ref Ref of record - * @param int $userid User id - * @return int <0 if KO, >0 if OK - */ - public function fetch($id, $ref = '', $userid = 0) - { - if (empty($id) && empty($ref) && empty($userid)) return -1; - - $sql = "SELECT rowid, fk_user, entity, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; - $sql .= " owner_address, label, datec, tms as datem"; - $sql .= " FROM ".MAIN_DB_PREFIX."user_rib"; - if ($id) $sql .= " WHERE rowid = ".$id; - if ($ref) $sql .= " WHERE label = '".$this->db->escape($ref)."'"; - if ($userid) $sql .= " WHERE fk_user = ".((int) $userid); - - $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->userid = $obj->fk_soc; - $this->bank = $obj->bank; - $this->code_banque = $obj->code_banque; - $this->code_guichet = $obj->code_guichet; - $this->number = $obj->number; - $this->cle_rib = $obj->cle_rib; - $this->bic = $obj->bic; - $this->iban = $obj->iban; - $this->domiciliation = $obj->domiciliation; - $this->proprio = $obj->proprio; - $this->owner_address = $obj->owner_address; - $this->label = $obj->label; - $this->datec = $this->db->jdate($obj->datec); - $this->datem = $this->db->jdate($obj->datem); - } - $this->db->free($resql); - - return 1; - } else { - dol_print_error($this->db); - return -1; - } - } - - /** - * Return RIB - * - * @param boolean $displayriblabel Prepend or Hide Label - * @return string RIB - */ - public function getRibLabel($displayriblabel = true) - { - $rib = ''; - - if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) { - if ($this->label && $displayriblabel) { - $rib = $this->label." : "; - } - - $rib .= (string) $this; - } - - return $rib; - } + /** + * Date creation record (datec) + * + * @var integer + */ + public $datec; + + /** + * Date modification record (tms) + * + * @var integer + */ + public $datem; + + /** + * User id of bank account + * + * @var integer + */ + public $userid; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct(DoliDB $db) + { + $this->db = $db; + + $this->userid = 0; + $this->solde = 0; + $this->error_number = 0; + } + + + /** + * Create bank information record + * + * @param User $user User + * @param int $notrigger 1=Disable triggers + * @return int <0 if KO, >= 0 if OK + */ + public function create(User $user = null, $notrigger = 0) + { + $now = dol_now(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rib (fk_user, datec)"; + $sql .= " VALUES (".$this->userid.", '".$this->db->idate($now)."')"; + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->affected_rows($resql)) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user_rib"); + + return $this->update($user); + } + } + else + { + print $this->db->error(); + return 0; + } + } + + /** + * Update bank account + * + * @param User $user Object user + * @param int $notrigger 1=Disable triggers + * @return int <=0 if KO, >0 if OK + */ + public function update(User $user = null, $notrigger = 0) + { + global $conf; + + if (!$this->id) + { + $this->create(); + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."user_rib SET"; + $sql .= " bank = '".$this->db->escape($this->bank)."'"; + $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'"; + $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'"; + $sql .= ",number='".$this->db->escape($this->number)."'"; + $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'"; + $sql .= ",bic='".$this->db->escape($this->bic)."'"; + $sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'"; + $sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'"; + $sql .= ",proprio = '".$this->db->escape($this->proprio)."'"; + $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'"; + + if (trim($this->label) != '') + $sql .= ",label = '".$this->db->escape($this->label)."'"; + else + $sql .= ",label = NULL"; + $sql .= " WHERE rowid = ".$this->id; + + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + dol_print_error($this->db); + return 0; + } + } + + /** + * Load record from database + * + * @param int $id Id of record + * @param string $ref Ref of record + * @param int $userid User id + * @return int <0 if KO, >0 if OK + */ + public function fetch($id, $ref = '', $userid = 0) + { + if (empty($id) && empty($ref) && empty($userid)) return -1; + + $sql = "SELECT rowid, fk_user, entity, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; + $sql .= " owner_address, label, datec, tms as datem"; + $sql .= " FROM ".MAIN_DB_PREFIX."user_rib"; + if ($id) $sql .= " WHERE rowid = ".$id; + if ($ref) $sql .= " WHERE label = '".$this->db->escape($ref)."'"; + if ($userid) $sql .= " WHERE fk_user = '".$userid."'"; + + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->userid = $obj->fk_soc; + $this->bank = $obj->bank; + $this->code_banque = $obj->code_banque; + $this->code_guichet = $obj->code_guichet; + $this->number = $obj->number; + $this->cle_rib = $obj->cle_rib; + $this->bic = $obj->bic; + $this->iban = $obj->iban; + $this->domiciliation = $obj->domiciliation; + $this->proprio = $obj->proprio; + $this->owner_address = $obj->owner_address; + $this->label = $obj->label; + $this->datec = $this->db->jdate($obj->datec); + $this->datem = $this->db->jdate($obj->datem); + } + $this->db->free($resql); + + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + /** + * Return RIB + * + * @param boolean $displayriblabel Prepend or Hide Label + * @return string RIB + */ + public function getRibLabel($displayriblabel = true) + { + $rib = ''; + + if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) { + if ($this->label && $displayriblabel) { + $rib = $this->label." : "; + } + + $rib .= (string) $this; + } + + return $rib; + } } --- /tmp/dsg/dolibarr/htdocs/user/class/github_usergroup.class.php +++ /tmp/dsg/dolibarr/htdocs/user/class/client_usergroup.class.php @@ -77,23 +77,20 @@ public $globalgroup; // Global group /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; - - /** - * Date modification record (tms) - * - * @var integer - */ - public $datem; - - /** - * @var string Description - */ - public $note; + * Date creation record (datec) + * + * @var integer + */ + public $datec; + + /** + * Date modification record (tms) + * + * @var integer + */ + public $datem; + + public $note; // Description public $members = array(); // Array of users @@ -114,7 +111,7 @@ ); /** - * @var string Field with ID of parent key if this field has a parent + * @var int Field with ID of parent key if this field has a parent */ public $fk_element = 'fk_usergroup'; @@ -130,15 +127,15 @@ /** - * Constructor de la classe - * - * @param DoliDb $db Database handler - */ - public function __construct($db) - { - $this->db = $db; - $this->nb_rights = 0; - } + * Constructor de la classe + * + * @param DoliDb $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + $this->nb_rights = 0; + } /** @@ -157,11 +154,13 @@ if (!empty($groupname)) { $result = $this->fetchCommon(0, '', ' AND nom = \''.$this->db->escape($groupname).'\''); - } else { + } + else + { $result = $this->fetchCommon($id); } - $this->name = $this->nom; // For compatibility with field name + $this->name = $this->nom; // For compatibility with field name if ($result) { @@ -171,7 +170,9 @@ } return 1; - } else { + } + else + { $this->error = $this->db->lasterror(); return -1; } @@ -199,7 +200,9 @@ if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { $sql .= " AND g.entity IS NOT NULL"; - } else { + } + else + { $sql .= " AND g.entity IN (0,".$conf->entity.")"; } $sql .= " ORDER BY g.nom"; @@ -223,7 +226,9 @@ $this->db->free($result); return $ret; - } else { + } + else + { $this->error = $this->db->lasterror(); return -1; } @@ -252,7 +257,9 @@ if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { $sql .= " AND u.entity IS NOT NULL"; - } else { + } + else + { $sql .= " AND u.entity IN (0,".$conf->entity.")"; } if (!empty($excludefilter)) $sql .= ' AND ('.$excludefilter.')'; @@ -270,7 +277,8 @@ $newuser = new User($this->db); $newuser->fetch($obj->rowid); $ret[$obj->rowid] = $newuser; - } else $ret[$obj->rowid] = $obj->rowid; + } + else $ret[$obj->rowid] = $obj->rowid; } if ($mode != 1 && !empty($obj->usergroup_entity)) { @@ -281,7 +289,9 @@ $this->db->free($resql); return $ret; - } else { + } + else + { $this->error = $this->db->lasterror(); return -1; } @@ -310,48 +320,52 @@ if (!empty($rid)) { - $module = $perms = $subperms = ''; - // Si on a demande ajout d'un droit en particulier, on recupere // les caracteristiques (module, perms et subperms) de ce droit. $sql = "SELECT module, perms, subperms"; $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; - $sql .= " WHERE id = ".((int) $rid); - $sql .= " AND entity = ".((int) $entity); + $sql .= " WHERE id = '".$this->db->escape($rid)."'"; + $sql .= " AND entity = ".$entity; $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - if ($obj) { - $module = $obj->module; - $perms = $obj->perms; - $subperms = $obj->subperms; - } - } else { + $module = $obj->module; + $perms = $obj->perms; + $subperms = $obj->subperms; + } + else { $error++; dol_print_error($this->db); } // Where pour la liste des droits a ajouter - $whereforadd = "id=".((int) $rid); - // Find also rights that are herited to add them too - if ($subperms) $whereforadd .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND (subperms='lire' OR subperms='read'))"; - elseif ($perms) $whereforadd .= " OR (module='".$this->db->escape($module)."' AND (perms='lire' OR perms='read') AND subperms IS NULL)"; - } else { + $whereforadd = "id=".$this->db->escape($rid); + // Ajout des droits induits + if ($subperms) $whereforadd .= " OR (module='$module' AND perms='$perms' AND (subperms='lire' OR subperms='read'))"; + elseif ($perms) $whereforadd .= " OR (module='$module' AND (perms='lire' OR perms='read') AND subperms IS NULL)"; + + // Pour compatibilite, si lowid = 0, on est en mode ajout de tout + // TODO A virer quand sera gere par l'appelant + //if (substr($rid,-1,1) == 0) $whereforadd="module='$module'"; + } + else { // Where pour la liste des droits a ajouter if (!empty($allmodule)) { if ($allmodule == 'allmodules') { $whereforadd = 'allmodules'; - } else { + } + else + { $whereforadd = "module='".$this->db->escape($allmodule)."'"; if (!empty($allperms)) $whereforadd .= " AND perms='".$this->db->escape($allperms)."'"; } } } - // Add permission of the list $whereforadd + // Ajout des droits de la liste whereforadd if (!empty($whereforadd)) { //print "$module-$perms-$subperms"; @@ -379,7 +393,9 @@ $i++; } - } else { + } + else + { $error++; dol_print_error($this->db); } @@ -389,17 +405,18 @@ $langs->load("other"); $this->context = array('audit'=>$langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : '')); - // Call trigger - $result = $this->call_trigger('USERGROUP_MODIFY', $user); - if ($result < 0) { $error++; } - // End call triggers + // Call trigger + $result = $this->call_trigger('USERGROUP_MODIFY', $user); + if ($result < 0) { $error++; } + // End call triggers } } if ($error) { $this->db->rollback(); return -$error; - } else { + } + else { $this->db->commit(); return 1; } @@ -428,8 +445,6 @@ if (!empty($rid)) { - $module = $perms = $subperms = ''; - // Si on a demande supression d'un droit en particulier, on recupere // les caracteristiques module, perms et subperms de ce droit. $sql = "SELECT module, perms, subperms"; @@ -440,12 +455,11 @@ $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - if ($obj) { - $module = $obj->module; - $perms = $obj->perms; - $subperms = $obj->subperms; - } - } else { + $module = $obj->module; + $perms = $obj->perms; + $subperms = $obj->subperms; + } + else { $error++; dol_print_error($this->db); } @@ -453,22 +467,24 @@ // Where pour la liste des droits a supprimer $wherefordel = "id=".$this->db->escape($rid); // Suppression des droits induits - if ($subperms == 'lire' || $subperms == 'read') $wherefordel .= " OR (module='".$this->db->escape($module)."' AND perms='".$this->db->escape($perms)."' AND subperms IS NOT NULL)"; - if ($perms == 'lire' || $perms == 'read') $wherefordel .= " OR (module='".$this->db->escape($module)."')"; + if ($subperms == 'lire' || $subperms == 'read') $wherefordel .= " OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)"; + if ($perms == 'lire' || $perms == 'read') $wherefordel .= " OR (module='$module')"; // Pour compatibilite, si lowid = 0, on est en mode suppression de tout // TODO A virer quand sera gere par l'appelant //if (substr($rid,-1,1) == 0) $wherefordel="module='$module'"; } else { - // Add permission of the list $wherefordel + // Where pour la liste des droits a supprimer if (!empty($allmodule)) { if ($allmodule == 'allmodules') { $wherefordel = 'allmodules'; - } else { + } + else + { $wherefordel = "module='".$this->db->escape($allmodule)."'"; - if (!empty($allperms)) $wherefordel .= " AND perms='".$this->db->escape($allperms)."'"; + if (!empty($allperms)) $whereforadd .= " AND perms='".$this->db->escape($allperms)."'"; } } } @@ -491,12 +507,8 @@ $i = 0; while ($i < $num) { - $nid = 0; - $obj = $this->db->fetch_object($result); - if ($obj) { - $nid = $obj->id; - } + $nid = $obj->id; $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights"; $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".$nid; @@ -505,7 +517,9 @@ $i++; } - } else { + } + else + { $error++; dol_print_error($this->db); } @@ -515,17 +529,18 @@ $langs->load("other"); $this->context = array('audit'=>$langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : '')); - // Call trigger - $result = $this->call_trigger('USERGROUP_MODIFY', $user); - if ($result < 0) { $error++; } - // End call triggers + // Call trigger + $result = $this->call_trigger('USERGROUP_MODIFY', $user); + if ($result < 0) { $error++; } + // End call triggers } } if ($error) { $this->db->rollback(); return -$error; - } else { + } + else { $this->db->commit(); return 1; } @@ -576,24 +591,24 @@ { $obj = $this->db->fetch_object($resql); - if ($obj) { - $module = $obj->module; - $perms = $obj->perms; - $subperms = $obj->subperms; - - if ($perms) + $module = $obj->module; + $perms = $obj->perms; + $subperms = $obj->subperms; + + if ($perms) + { + if (!isset($this->rights)) $this->rights = new stdClass(); // For avoid error + if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass(); + if ($subperms) { - if (!isset($this->rights)) $this->rights = new stdClass(); // For avoid error - if (!isset($this->rights->$module) || !is_object($this->rights->$module)) $this->rights->$module = new stdClass(); - if ($subperms) - { - if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass(); - if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++; - $this->rights->$module->$perms->$subperms = 1; - } else { - if (empty($this->rights->$module->$perms)) $this->nb_rights++; - $this->rights->$module->$perms = 1; - } + if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) $this->rights->$module->$perms = new stdClass(); + if (empty($this->rights->$module->$perms->$subperms)) $this->nb_rights++; + $this->rights->$module->$perms->$subperms = 1; + } + else + { + if (empty($this->rights->$module->$perms)) $this->nb_rights++; + $this->rights->$module->$perms = 1; } } @@ -607,12 +622,14 @@ // Si module etait non defini, alors on a tout charge, on peut donc considerer // que les droits sont en cache (car tous charges) pour cet instance de group $this->all_permissions_are_loaded = 1; - } else { + } + else + { // If module defined, we flag it as loaded into cache - $this->_tab_loaded[$moduletag] = 1; - } - - return 1; + $this->_tab_loaded[$moduletag] = 1; + } + + return 1; } /** @@ -637,11 +654,13 @@ global $user, $conf; $this->datec = dol_now(); - if (!empty($this->name)) { - $this->nom = $this->name; // Field for 'name' is called 'nom' in database + if (empty($this->nom) && !empty($this->name)) { + $this->nom = $this->name; } if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value + $entity = $this->entity; + if (!empty($conf->multicompany->enabled) && $conf->entity == 1) $entity = $this->entity; return $this->createCommon($user, $notrigger); } @@ -656,8 +675,10 @@ { global $user, $conf; - if (!empty($this->name)) { - $this->nom = $this->name; // Field for 'name' is called 'nom' in database + $entity = $conf->entity; + if (!empty($conf->multicompany->enabled) && $conf->entity == 1) + { + $entity = $this->entity; } return $this->updateCommon($user, $notrigger); @@ -672,10 +693,10 @@ */ public function getLibStatut($mode = 0) { - return $this->LibStatut(0, $mode); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + return $this->LibStatut(0, $mode); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Renvoi le libelle d'un statut donne * @@ -685,10 +706,10 @@ */ public function LibStatut($status, $mode = 0) { - // phpcs:enable - global $langs; - $langs->load('users'); - return ''; + // phpcs:enable + global $langs; + $langs->load('users'); + return ''; } /** @@ -778,9 +799,9 @@ * 2=Return key only (uid=qqq) * @return string DN */ - public function _load_ldap_dn($info, $mode = 0) - { - // phpcs:enable + public function _load_ldap_dn($info, $mode = 0) + { + // phpcs:enable global $conf; $dn = ''; if ($mode == 0) $dn = $conf->global->LDAP_KEY_GROUPS."=".$info[$conf->global->LDAP_KEY_GROUPS].",".$conf->global->LDAP_GROUP_DN; @@ -797,9 +818,9 @@ * * @return array Tableau info des attributs */ - public function _load_ldap_info() - { - // phpcs:enable + public function _load_ldap_info() + { + // phpcs:enable global $conf; $info = array(); @@ -822,22 +843,22 @@ $valueofldapfield[] = $muser->_load_ldap_dn($info2); } $info[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield : ''); - } - if (!empty($info[$conf->global->LDAP_GROUP_FIELD_GROUPID])) { - $info[$conf->global->LDAP_GROUP_FIELD_GROUPID] = $this->id; - } + } + if (!empty($info[$conf->global->LDAP_GROUP_FIELD_GROUPID])) { + $info[$conf->global->LDAP_GROUP_FIELD_GROUPID] = $this->id; + } return $info; } /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - public function initAsSpecimen() + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + public function initAsSpecimen() { global $conf, $user, $langs; @@ -851,11 +872,11 @@ $this->datec = time(); $this->datem = time(); - // Members of this group is just me - $this->members = array( - $user->id => $user - ); - } + // Members of this group is just me + $this->members = array( + $user->id => $user + ); + } /** * Create a document onto disk according to template module. @@ -865,7 +886,7 @@ * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) @@ -880,7 +901,9 @@ if (!empty($conf->global->USERGROUP_ADDON_PDF)) { $modele = $conf->global->USERGROUP_ADDON_PDF; - } else { + } + else + { $modele = 'grass'; } }