/** * Parse object data * @return * @param object $a_ids */ public function parseObjectIds($a_ids) { foreach ($a_ids as $object_id) { $row = array(); $type = ilObject::_lookupType($object_id); $row['title'] = ilObject::_lookupTitle($object_id); $row['desc'] = ilObject::_lookupDescription($object_id); $row['id'] = $object_id; switch ($type) { case 'crs': case 'grp': include_once './Services/Membership/classes/class.ilParticipants.php'; if (ilParticipants::hasParticipantListAccess($object_id)) { $row['member'] = count(ilParticipants::getInstanceByObjId($object_id)->getParticipants()); } else { $row['member'] = 0; } break; case 'role': global $rbacreview; include_once './Services/User/classes/class.ilUserFilter.php'; $row['member'] = count(ilUserFilter::getInstance()->filter($rbacreview->assignedUsers($object_id))); break; } $data[] = $row; } $this->setData($data ? $data : array()); }
/** * List users of course/group/roles * @return */ protected function listUsers() { // get parameter is used e.g. in exercises to provide // "add members of course" link if ($_GET["list_obj"] != "" && !is_array($_POST['obj'])) { $_POST['obj'][0] = $_GET["list_obj"]; } if (!is_array($_POST['obj']) or !$_POST['obj']) { ilUtil::sendFailure($this->lng->txt('select_one')); $this->showSearchResults(); return false; } $_SESSION['rep_search']['objs'] = $_POST['obj']; // Get all members $members = array(); foreach ($_POST['obj'] as $obj_id) { $type = ilObject::_lookupType($obj_id); switch ($type) { case 'crs': case 'grp': include_once './Services/Membership/classes/class.ilParticipants.php'; if (ilParticipants::hasParticipantListAccess($obj_id)) { $members = array_merge((array) $members, ilParticipants::getInstanceByObjId($obj_id)->getParticipants()); } break; case 'role': global $rbacreview; include_once './Services/User/classes/class.ilUserFilter.php'; $members = array_merge($members, ilUserFilter::getInstance()->filter($rbacreview->assignedUsers($obj_id))); break; } } $members = array_unique((array) $members); $this->__appendToStoredResults($members); $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.rep_search_result.html', 'Services/Search'); $this->addNewSearchButton(); $this->showSearchUserTable($_SESSION['rep_search']['usr'], 'storedUserList'); return true; }
public function showResults() { global $lng, $ilUser, $rbacreview, $ilObjDataCache; $form = $this->initSearchForm(); $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_search.html", "Services/Contact"); $this->tpl->setVariable("ACTION", $this->ctrl->getFormAction($this)); $this->tpl->setTitle($this->lng->txt("mail")); $this->tpl->setVariable('SEARCHFORM', $form->getHtml()); // #14109 if (strlen($_SESSION['mail_search_search']) < 3) { if ($_GET["ref"] != "wsp") { $this->tpl->show(); } return; } $abook = new ilAddressbook($ilUser->getId()); $entries = $abook->searchUsers(addslashes(urldecode($_SESSION['mail_search_search']))); // remove all contacts who are not registered users for personal workspace if ($_GET["ref"] == "wsp") { foreach ($entries as $idx => $entry) { if (!$entry["login"]) { unset($entries[$idx]); } } } if (count($entries)) { $tbl_addr = new ilTable2GUI($this); $tbl_addr->setTitle($lng->txt('mail_addressbook')); $tbl_addr->setRowTemplate('tpl.mail_search_addr_row.html', 'Services/Contact'); $result = array(); $counter = 0; foreach ($entries as $entry) { if ($_GET["ref"] != "wsp") { $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_addr[]', $entry['login'] ? $entry['login'] : $entry['email']) . ilUtil::formCheckbox(0, 'search_name_cc[]', $entry['login'] ? $entry['login'] : $entry['email']) . ilUtil::formCheckbox(0, 'search_name_bcc[]', $entry['login'] ? $entry['login'] : $entry['email']); } else { $user_id = ilObjUser::_loginExists($entry["login"]); $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_addr[]', $user_id); } $result[$counter]['login'] = $entry['login']; $result[$counter]['firstname'] = $entry['firstname']; $result[$counter]['lastname'] = $entry['lastname']; $id = ilObjUser::_lookupId($entry['login']); if (ilObjUser::_lookupPref($id, 'public_email') == 'y' || !$entry['login']) { $has_mail_addr = true; $result[$counter]['email'] = $entry['email']; } ++$counter; } if ($_GET["ref"] != "wsp") { $tbl_addr->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%'); } else { $tbl_addr->addColumn("", "", "1%"); } $tbl_addr->addColumn($this->lng->txt('login'), 'login', "15%"); $tbl_addr->addColumn($this->lng->txt('firstname'), 'firstname', "15%"); $tbl_addr->addColumn($this->lng->txt('lastname'), 'lastname', "15%"); if ($has_mail_addr) { foreach ($result as $key => $val) { if ($val['email'] == '') { $result[$key]['email'] = ' '; } } $tbl_addr->addColumn($this->lng->txt('email'), 'email', "15%"); } $tbl_addr->setData($result); $tbl_addr->setDefaultOrderField('login'); $tbl_addr->setPrefix('addr_'); $tbl_addr->enable('select_all'); $tbl_addr->setSelectAllCheckbox('search_name_to_addr'); $tbl_addr->setFormName('recipients'); $this->tpl->setVariable('TABLE_ADDR', $tbl_addr->getHTML()); } include_once 'Services/Search/classes/class.ilQueryParser.php'; include_once 'Services/Search/classes/class.ilObjectSearchFactory.php'; include_once 'Services/Search/classes/class.ilSearchResult.php'; $all_results = new ilSearchResult(); $query_parser = new ilQueryParser(addcslashes($_SESSION['mail_search_search'], '%_')); $query_parser->setCombination(QP_COMBINATION_AND); $query_parser->setMinWordLength(3); $query_parser->parse(); $user_search =& ilObjectSearchFactory::_getUserSearchInstance($query_parser); $user_search->enableActiveCheck(true); $user_search->setFields(array('login')); $result_obj = $user_search->performSearch(); $all_results->mergeEntries($result_obj); $user_search->setFields(array('firstname')); $result_obj = $user_search->performSearch(); $all_results->mergeEntries($result_obj); $user_search->setFields(array('lastname')); $result_obj = $user_search->performSearch(); $all_results->mergeEntries($result_obj); $all_results->setMaxHits(100000); $all_results->preventOverwritingMaxhits(true); $all_results->filter(ROOT_FOLDER_ID, true); // Filter users (depends on setting in user accounts) include_once 'Services/User/classes/class.ilUserFilter.php'; $users = ilUserFilter::getInstance()->filter($all_results->getResultIds()); if (count($users)) { $tbl_users = new ilTable2GUI($this); $tbl_users->setTitle($lng->txt('system') . ': ' . $lng->txt('persons')); $tbl_users->setRowTemplate('tpl.mail_search_users_row.html', 'Services/Contact'); $result = array(); $counter = 0; foreach ($users as $user) { $login = ilObjUser::_lookupLogin($user); if ($_GET["ref"] != "wsp") { $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_usr[]', $login) . ilUtil::formCheckbox(0, 'search_name_cc[]', $login) . ilUtil::formCheckbox(0, 'search_name_bcc[]', $login); } else { $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_usr[]', $user); } $result[$counter]['login'] = $login; if (in_array(ilObjUser::_lookupPref($user, 'public_profile'), array('y', "g"))) { $name = ilObjUser::_lookupName($user); $result[$counter]['firstname'] = $name['firstname']; $result[$counter]['lastname'] = $name['lastname']; } else { $result[$counter]['firstname'] = ''; $result[$counter]['lastname'] = ''; } if (ilObjUser::_lookupPref($user, 'public_email') == 'y') { $has_mail_usr = true; $result[$counter]['email'] = ilObjUser::_lookupEmail($user); } ++$counter; } if ($_GET["ref"] != "wsp") { $tbl_users->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%'); } else { $tbl_users->addColumn("", "", "1%"); } $tbl_users->addColumn($this->lng->txt('login'), 'login', '15%'); $tbl_users->addColumn($this->lng->txt('firstname'), 'firstname', '15%'); $tbl_users->addColumn($this->lng->txt('lastname'), 'lastname', '15%'); if ($has_mail_usr == true) { foreach ($result as $key => $val) { if ($val['email'] == '') { $result[$key]['email'] = ' '; } } $tbl_users->addColumn($this->lng->txt('email'), 'email', '15%'); } $tbl_users->setData($result); $tbl_users->setDefaultOrderField('login'); $tbl_users->setPrefix('usr_'); $tbl_users->enable('select_all'); $tbl_users->setSelectAllCheckbox('search_name_to_usr'); $tbl_users->setFormName('recipients'); $this->tpl->setVariable('TABLE_USERS', $tbl_users->getHTML()); } include_once 'Services/Search/classes/class.ilQueryParser.php'; include_once 'Services/Search/classes/class.ilObjectSearchFactory.php'; include_once 'Services/Search/classes/class.ilSearchResult.php'; include_once 'Services/Membership/classes/class.ilParticipants.php'; $group_results = new ilSearchResult(); $query_parser = new ilQueryParser(addcslashes($_SESSION['mail_search_search'], '%_')); $query_parser->setCombination(QP_COMBINATION_AND); $query_parser->setMinWordLength(3); $query_parser->parse(); $search = ilObjectSearchFactory::_getObjectSearchInstance($query_parser); $search->setFilter(array('grp')); $result = $search->performSearch(); $group_results->mergeEntries($result); $group_results->setMaxHits(PHP_INT_MAX); $group_results->preventOverwritingMaxhits(true); $group_results->setRequiredPermission('read'); $group_results->filter(ROOT_FOLDER_ID, true); $visible_groups = array(); if ($group_results->getResults()) { $tbl_grp = new ilTable2GUI($this); $tbl_grp->setTitle($lng->txt('system') . ': ' . $lng->txt('groups')); $tbl_grp->setRowTemplate('tpl.mail_search_groups_row.html', 'Services/Contact'); $result = array(); $counter = 0; $ilObjDataCache->preloadReferenceCache(array_keys($group_results->getResults())); $groups = $group_results->getResults(); foreach ($groups as $grp) { if (!ilParticipants::hasParticipantListAccess($grp['obj_id'])) { continue; } if ($_GET["ref"] != "wsp") { $members = array(); $roles = $rbacreview->getAssignableChildRoles($grp['ref_id']); foreach ($roles as $role) { if (substr($role['title'], 0, 14) == 'il_grp_member_' || substr($role['title'], 0, 13) == 'il_grp_admin_') { // does not work if Pear is enabled and Mailbox Address contain special chars!! //array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id'])); // FIX for Mantis: 7523 array_push($members, '#' . $role['title']); } } $str_members = implode(',', $members); $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_grp[]', $str_members) . ilUtil::formCheckbox(0, 'search_name_cc[]', $str_members) . ilUtil::formCheckbox(0, 'search_name_bcc[]', $str_members); } else { $result[$counter]['check'] = ilUtil::formCheckbox(0, 'search_name_to_grp[]', $grp['obj_id']); } $result[$counter]['title'] = $ilObjDataCache->lookupTitle($grp['obj_id']); $result[$counter]['description'] = $ilObjDataCache->lookupDescription($grp['obj_id']); ++$counter; $visible_groups[] = $grp; } if ($visible_groups) { $tbl_grp->setData($result); if ($_GET["ref"] != "wsp") { $tbl_grp->addColumn($this->lng->txt('mail_to') . '/' . $this->lng->txt('cc') . '/' . $this->lng->txt('bc'), 'check', '10%'); } else { $tbl_grp->addColumn("", "", "1%"); } $tbl_grp->addColumn($this->lng->txt('title'), 'title', '15%'); $tbl_grp->addColumn($this->lng->txt('description'), 'description', '15%'); $tbl_grp->setDefaultOrderField('title'); $tbl_grp->setPrefix('grp_'); $tbl_grp->enable('select_all'); $tbl_grp->setSelectAllCheckbox('search_name_to_grp'); $tbl_grp->setFormName('recipients'); $this->tpl->setVariable('TABLE_GRP', $tbl_grp->getHTML()); } } if (count($users) || count($visible_groups) || count($entries)) { $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg")); $this->tpl->setVariable("ALT_ARROW", ''); if ($_GET["ref"] != "wsp") { $this->tpl->setVariable('BUTTON_ADOPT', $this->lng->txt('adopt')); } else { $this->tpl->setVariable('BUTTON_ADOPT', $this->lng->txt('wsp_share_with_users')); } } else { $this->lng->loadLanguageModule('search'); ilUtil::sendInfo($this->lng->txt('search_no_match')); } if ($_GET["ref"] != "wsp") { $this->tpl->show(); } }
/** * reads all active sessions from db and returns users that are online * OR returns only one active user if a user_id is given * * @param integer user_id (optional) * @return array */ public static function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false) { /** * @var $ilDB ilDB */ global $ilDB; $pd_set = new ilSetting('pd'); $atime = $pd_set->get('user_activity_time') * 60; $ctime = time(); $where = array(); if ($a_user_id == 0) { $where[] = 'user_id > 0'; $where[] = '(agree_date IS NOT NULL OR user_id = ' . $ilDB->quote(SYSTEM_USER_ID, 'integer') . ')'; } else { $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer'); } if ($a_no_anonymous) { $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer'); } include_once 'Services/User/classes/class.ilUserAccountSettings.php'; if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) { include_once 'Services/User/classes/class.ilUserFilter.php'; $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer'); } $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer'); $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')'; $where = 'WHERE ' . implode(' AND ', $where); $r = $ilDB->queryF("\n\t\t\tSELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime\n\t\t\tFROM usr_session\n\t\t\tLEFT JOIN usr_data u\n\t\t\t\tON user_id = u.usr_id\n\t\t\tLEFT JOIN usr_pref p\n\t\t\t\tON (p.usr_id = u.usr_id AND p.keyword = %s)\n\t\t\t{$where}\n\t\t\tGROUP BY user_id, firstname, lastname, title, login, last_login\n\t\t\tORDER BY lastname, firstname\n\t\t\t", array('text'), array('hide_own_online_status')); $users = array(); while ($user = $ilDB->fetchAssoc($r)) { if ($atime <= 0 || $user['ctime'] + $atime > $ctime) { $users[$user['user_id']] = $user; } } return $users; }
/** * @param string * @return string */ protected function getWherePart($search_query) { /** * @var $ilDB ilDB * @var $ilSetting ilSetting */ global $ilDB, $ilSetting; $outer_conditions = array(); // In 'anonymous' context with respected user privacy, only users with globally published profiles should be found. if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode() && $this->getUser() instanceof ilObjUser && $this->getUser()->isAnonymous()) { if (!$ilSetting->get('enable_global_profiles', 0)) { // If 'Enable User Content Publishing' is not set in the administration, no user should be found for 'anonymous' context. return '1 = 2'; } else { // Otherwise respect the profile activation setting of every user (as a global (outer) condition in the where clause). $outer_conditions[] = 'profpref.value = ' . $ilDB->quote('g', 'text'); } } $outer_conditions[] = 'ud.usr_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer'); $field_conditions = array(); foreach ($this->getFields() as $field) { $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query); if ('email' == $field && self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode()) { // If privacy should be respected, the profile setting of every user concerning the email address has to be // respected (in every user context, no matter if the user is 'logged in' or 'anonymous'). $email_query = array(); $email_query[] = $field_condition; $email_query[] = 'pubemail.value = ' . $ilDB->quote('y', 'text'); $field_conditions[] = '(' . implode(' AND ', $email_query) . ')'; } else { $field_conditions[] = $field_condition; } } // If the current user context ist 'logged in' and privacy should be respected, all fields >>>except the login<<< // should only be searchable if the users' profile is published (y oder g) // In 'anonymous' context we do not need this additional conditions, // because we checked the privacy setting in the condition above: profile = 'g' if (self::PRIVACY_MODE_RESPECT_USER_SETTING == $this->getPrivacyMode() && $this->getUser() instanceof ilObjUser && !$this->getUser()->isAnonymous() && $field_conditions) { $fields = implode(' OR ', $field_conditions); $field_conditions[] = '(' . implode(' AND ', array($fields, $ilDB->in('profpref.value', array('y', 'g'), false, 'text'))) . ')'; } // The login field must be searchable regardless (for 'logged in' users) of any privacy settings. // We handled the general condition for 'anonymous' context above: profile = 'g' $field_conditions[] = $this->getQueryConditionByFieldAndValue('login', $search_query); include_once 'Services/User/classes/class.ilUserAccountSettings.php'; if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) { include_once './Services/User/classes/class.ilUserFilter.php'; $outer_conditions[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer'); } if ($field_conditions) { $outer_conditions[] = '(' . implode(' OR ', $field_conditions) . ')'; } return implode(' AND ', $outer_conditions); }
/** * reads all active sessions from db and returns users that are online * OR returns only one active user if a user_id is given * * @param integer user_id (optional) * @return array */ function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false) { global $ilDB; $pd_set = new ilSetting("pd"); $atime = $pd_set->get("user_activity_time") * 60; $ctime = time(); if ($a_user_id == 0) { $where = "WHERE user_id != 0 AND NOT agree_date IS NULL "; $type_array = array("integer"); $val_array = array(time()); } else { $where = "WHERE user_id = %s "; $type_array = array("integer", "integer"); $val_array = array($a_user_id, time()); } $no_anonym = $a_no_anonymous ? "AND user_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") . " " : ""; include_once './Services/User/classes/class.ilUserAccountSettings.php'; if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) { include_once './Services/User/classes/class.ilUserFilter.php'; $user_filter = 'AND ' . $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer') . ' '; } else { $user_filter = ' '; } $r = $ilDB->queryF($q = "SELECT count(user_id) as num,user_id,firstname,lastname,title,login,last_login,max(ctime) AS ctime " . "FROM usr_session " . "LEFT JOIN usr_data u ON user_id = u.usr_id " . "LEFT JOIN usr_pref p ON (p.usr_id = u.usr_id AND p.keyword = " . $ilDB->quote("hide_own_online_status", "text") . ") " . $where . "AND expires > %s " . "AND (p.value IS NULL OR NOT p.value = " . $ilDB->quote("y", "text") . ") " . $no_anonym . $user_filter . "GROUP BY user_id,firstname,lastname,title,login,last_login " . "ORDER BY lastname, firstname", $type_array, $val_array); while ($user = $ilDB->fetchAssoc($r)) { if ($atime <= 0 || $user["ctime"] + $atime > $ctime) { $users[$user["user_id"]] = $user; } } return $users ? $users : array(); }