'GROUP_USER.USR_UID AS pm_user_id', 'FROM' => 'TASK_USER', 'INNER JOIN' => [ 'GROUP_USER' => [ 'FKEY' => [ 'GROUP_USER' => 'GRP_UID', 'TASK_USER' => 'USR_UID', ['AND' => [ 'TASK_USER.TU_RELATION' => 2, 'TASK_USER.TU_TYPE' => $tu_type ] ] ] ] ], 'WHERE' => [ 'TAS_UID' => $tags['taskGuid'], ] ]); $res2 = new QuerySubQuery([ 'SELECT' => 'TASK_USER.USR_UID AS pm_user_id', 'FROM' => 'TASK_USER', 'WHERE' => [ 'AND' => [ 'TAS_UID' => $tags['taskGuid'], 'TASK_USER.TU_RELATION' => 1, 'TASK_USER.TU_TYPE' => $tu_type ] ] ]); $subqueries = [$res1, $res2]; if ($tags['grpGuid'] != 0) { // then add the user for the selfservice value based assignement $res3 = new QuerySubQuery([ 'SELECT' => 'GROUP_USER.USR_UID AS pm_user_id', 'FROM' => 'GROUP_USER', 'WHERE' => ['GROUP_USER.GRP_UID' => $tags['grpGuid']] ]); $subqueries[] = $res3; } $union = new QueryUnion($subqueries); $res = $PM_DB->request([ 'FROM' => $union ]); $pmUsers = [ ]; foreach ($res as $pmUser) { $pmUsers[ ] = $pmUser[ 'pm_user_id' ]; } $joinprofile = false; switch ($right) { case "id" : $used[] = Session::getLoginUserID(); $query['WHERE']['AND']['glpi_users.id'] = Session::getLoginUserID(); break; case "all" : $query['WHERE']['AND']['glpi_users.id'] = ['>', 0]; break; } if (count($pmUsers) == 0) { // to prevent add of empty array in where clause $pmUsers = 0; } $query['WHERE']['AND']['glpi_plugin_processmaker_users.pm_users_id'] = $pmUsers; $query['WHERE']['AND']['glpi_users.is_deleted'] = 0; $query['WHERE']['AND']['glpi_users.is_active'] = 1; if ((is_numeric($value) && $value) || count($used)) { if (is_numeric($value)) { $used[] = $value; } } if ($count) { $query['FIELDS'] = 'glpi_users.id'; $query['COUNT'] = 'cpt'; $query['DISTINCT'] = true; } else { $query['FIELDS'] = ['glpi_users.id', 'glpi_users.realname', 'glpi_users.firstname', 'glpi_users.name', 'glpi_useremails.email']; $query['DISTINCT'] = true; } $query['FROM'] = 'glpi_plugin_processmaker_users'; $query['INNER JOIN'] = [ 'glpi_users' => [ 'FKEY' => [ 'glpi_users' => 'id', 'glpi_plugin_processmaker_users' => 'id' ] ] ]; $query['LEFT JOIN'] = [ 'glpi_useremails' => [ 'FKEY' => [ 'glpi_users' => 'id', 'glpi_useremails' => 'users_id', [ 'AND' => [ 'glpi_useremails.is_default' => 1 ] ] ] ], 'glpi_profiles_users' => [ 'FKEY' => [ 'glpi_users' => 'id', 'glpi_profiles_users' => 'users_id' ] ] ]; if ($joinprofile) { $query['LEFT JOIN'] = [ 'glpi_profiles' => [ 'FKEY' => [ 'glpi_profiles' => 'id', 'glpi_profiles_user' => 'profiles_id' ] ] ]; } if ($count) { $query['WHERE']['AND']['NOT']['glpi_users.id'] = $used; } else { if (strlen($search)>0 && $search!=$CFG_GLPI["ajax_wildcard"]) { $txt_search = Search::makeTextSearchValue($search); $firstname_field = $DB->quoteName(User::getTableField('firstname')); $realname_field = $DB->quoteName(User::getTableField('realname')); $fields = $_SESSION["glpinames_format"] == User::FIRSTNAME_BEFORE ? [$firstname_field, $realname_field] : [$realname_field, $firstname_field]; $concat = new \QueryExpression( 'CONCAT(' . implode(',' . $DB->quoteValue(' ') . ',', $fields) . ')' . ' LIKE ' . $DB->quoteValue($txt_search) ); $query['WHERE']['AND'] = [ 'glpi_users.name' => ['LIKE', $txt_search], 'OR' => [ 'glpi_users.realname' => ['LIKE', $txt_search], 'glpi_users.firstname' => ['LIKE', $txt_search], 'glpi_users.phone' => ['LIKE', $txt_search], 'glpi_useremails.email' => ['LIKE', $txt_search], $concat ] ]; } $query['WHERE']['AND']['NOT']['glpi_users.id'] = $used; if ($_SESSION["glpinames_format"] == User::FIRSTNAME_BEFORE) { $query['ORDER'] = ['glpi_users.firstname', 'glpi_users.realname', 'glpi_users.name']; } else { $query['ORDER'] = ['glpi_users.realname', 'glpi_users.firstname', 'glpi_users.name']; } if ($search != $CFG_GLPI["ajax_wildcard"]) { $query['LIMIT'] = $limit; $query['START'] = $start; } } return $DB->request($query); } /** * Make a select box with all glpi users where select key = name * * Parameters which could be used in options array : * - name : string / name of the select (default is users_id) * - right : string / limit user who have specific right : * id -> only current user (default case); * interface -> central ; * all -> all users ; * specific right like show_all_ticket, create_ticket.... * - comments : boolean / is the comments displayed near the dropdown (default true) * - entity : integer or array / restrict to a defined entity or array of entities * (default -1 : no restriction) * - entity_sons : boolean / if entity restrict specified auto select its sons * only available if entity is a single value not an array(default false) * - all : Nobody or All display for none selected * all=0 (default) -> Nobody * all=1 -> All * all=-1-> nothing * - rand : integer / already computed rand value * - toupdate : array / Update a specific item on select change on dropdown * (need value_fieldname, to_update, url (see Ajax::updateItemOnSelectEvent for informations) * and may have moreparams) * - used : array / Already used items ID: not to display in dropdown (default empty) * - on_change : string / value to transmit to "onChange" * * @param $options array of possible options * * @return int (print out an HTML select box) **/ static function dropdown($options = []) { global $CFG_GLPI; $options['url'] = $CFG_GLPI["root_doc"].'/plugins/processmaker/ajax/dropdownUsers.php'; return User::dropdown( $options ); } /** * Summary of getGLPIUserId * returns GLPI user ID from a Processmaker user ID * @param string $pmUserId * @return int GLPI user id, or 0 if not found */ public static function getGLPIUserId($pmUserId) { $obj = new self; if ($obj->getFromDBByRequest([ 'WHERE' => [ 'pm_users_id' => $pmUserId ], ])) { return $obj->fields['id']; } return 0; } /** * Summary of getPMUserId * returns processmaker user id for given GLPI user id * @param int $glpi_userId id of user from GLPI database * @return string which is the uid of user in Processmaker database, or false if not found */ public static function getPMUserId($glpiUserId) { if (is_numeric($glpiUserId)) { $obj = new self; if ($obj->getFromDB($glpiUserId)) { return $obj->fields['pm_users_id']; } } return false; } /** * Summary of getGlpiIdFromAny * Returns the GLPI id of the user or false if not found * Accept either PM GUID, GLPI logon, or GLPI ID * @param $any * @return mixed GLPI ID of the user or false if not found */ public static function getGlpiIdFromAny($any) { $ret = self::getGLPIUserId($any); if ($ret) { return $ret; } $ret = self::getPMUserId($any); if ($ret) { return $any; } $usr = new User; if ($usr->getFromDBbyName($any)) { return $usr->getId(); } return false; } ///** // * Summary of getNewPassword // * @param mixed $username // * @return string a new password computed // * from uppercasing first letter of $username // * and encoding // * and adding a ramdon number (4 digits) // * and truncating it to a length of 20 chars // */ //public static function getNewPassword( $username ) { // $newPass = Toolbox::encrypt( ucfirst( stripslashes( $username ) ), GLPIKEY) ; // return substr( rand(1000,9999).$newPass, 0, 19) ; //} }