/** * used by user/myfriends.php and user/find.php to get the data (including pieforms etc) for display * @param $userlist the ids separated by commas * @return array containing the users in the order from $userlist */ function get_users_data($userlist, $getviews = true) { global $USER; // $userlist is only used by build_userlist_html() in this file and is sanitised there $sql = 'SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted, u.profileicon, u.email, 0 AS pending, ap.value AS hidenamepref, COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages, COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'friendscontrol\'), \'auth\') AS friendscontrol, (SELECT 1 FROM {usr_friend} WHERE ((usr1 = ? AND usr2 = u.id) OR (usr2 = ? AND usr1 = u.id))) AS friend, (SELECT 1 FROM {usr_friend_request} fr WHERE fr.requester = ? AND fr.owner = u.id) AS requestedfriendship, (SELECT title FROM {artefact} WHERE artefacttype = \'introduction\' AND owner = u.id) AS introduction, NULL AS message FROM {usr} u LEFT JOIN {usr_account_preference} ap ON (u.id = ap.usr AND ap.field = \'hiderealname\') WHERE u.id IN (' . $userlist . ') UNION SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted, u.profileicon, u.email, 1 AS pending, ap.value AS hidenamepref, COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages, NULL AS friendscontrol, NULL AS friend, NULL AS requestedfriendship, (SELECT title FROM {artefact} WHERE artefacttype = \'introduction\' AND owner = u.id) AS introduction, message FROM {usr} u LEFT JOIN {usr_account_preference} ap ON (u.id = ap.usr AND ap.field = \'hiderealname\') JOIN {usr_friend_request} fr ON fr.requester = u.id WHERE fr.owner = ? AND u.id IN (' . $userlist . ')'; $userid = $USER->get('id'); $data = get_records_sql_assoc($sql, array($userid, $userid, $userid, $userid)); $allowhidename = get_config('userscanhiderealnames'); $showusername = get_config('searchusernames'); foreach ($data as &$record) { $record->messages = $record->messages == 'allow' || $record->friend && $record->messages == 'friends' || $USER->get('admin') ? 1 : 0; $record->institutions = get_institution_string_for_user($record->id); $record->display_name = display_name($record, null, false, !$allowhidename || !$record->hidenamepref, $showusername); } if (!$data || !$getviews || !($views = get_views(array_keys($data), null, null))) { $views = array(); } if ($getviews) { $viewcount = array_map('count', $views); // since php is so special and inconsistent, we can't use array_map for this because it breaks the top level indexes. $cleanviews = array(); foreach ($views as $userindex => $viewarray) { $cleanviews[$userindex] = array_slice($viewarray, 0, 5); // Don't reveal any more about the view than necessary foreach ($cleanviews as $userviews) { foreach ($userviews as &$view) { foreach (array_keys(get_object_vars($view)) as $key) { if ($key != 'id' && $key != 'title') { unset($view->{$key}); } } } } } } foreach ($data as $friend) { if ($getviews && isset($cleanviews[$friend->id])) { $friend->views = $cleanviews[$friend->id]; } if ($friend->pending) { $friend->accept = pieform(array('name' => 'acceptfriend' . $friend->id, 'successcallback' => 'acceptfriend_submit', 'renderer' => 'div', 'autofocus' => 'false', 'elements' => array('submit' => array('type' => 'submit', 'value' => get_string('approverequest', 'group')), 'id' => array('type' => 'hidden', 'value' => $friend->id)))); } if (!$friend->friend && !$friend->pending && !$friend->requestedfriendship && $friend->friendscontrol == 'auto') { $friend->makefriend = pieform(array('name' => 'addfriend' . $friend->id, 'successcallback' => 'addfriend_submit', 'renderer' => 'div', 'autofocus' => 'false', 'elements' => array('submit' => array('type' => 'submit', 'value' => get_string('addtofriendslist', 'group')), 'id' => array('type' => 'hidden', 'value' => $friend->id), 'query' => array('type' => 'hidden', 'value' => param_variable('query', '')), 'offset' => array('type' => 'hidden', 'value' => param_integer('offset', 0))))); } } $order = explode(',', $userlist); $ordereddata = array(); foreach ($order as $id) { if (isset($data[$id])) { $ordereddata[] = $data[$id]; } } return $ordereddata; }
} if ($remoteuseracceptform) { $smarty->assign('acceptform', acceptfriend_form($userid)); } if ($remoteusernewfriendform) { $smarty->assign('newfriendform', addfriend_form($userid)); } if ($remoteuserfriendscontrol) { $smarty->assign('friendscontrol', $friendscontrol); } if ($remoteuserrelationship) { $smarty->assign('relationship', $relationship); } $smarty->assign('loginas', $loginas); $smarty->assign('INLINEJAVASCRIPT', $inlinejs); $smarty->assign('institutions', get_institution_string_for_user($userid)); $smarty->assign('canmessage', $loggedinid != $userid && can_send_message($loggedinid, $userid)); $smarty->assign('USERID', $userid); $smarty->assign('viewtitle', get_string('usersprofile', 'mahara', display_name($user, null, true))); $smarty->assign('viewtype', 'profile'); $smarty->assign('user', $user); if ($loggedinid && $loggedinid == $userid) { $smarty->assign('ownprofile', true); } $smarty->assign('pageheadinghtml', $view->display_title(false)); if ($skin) { if ($skindata['header_logo_image'] == 'light' || $skindata['header_logo_image'] == 'dark') { // override the default $smarty->assign('sitelogo') that happens // in the initial call to smarty() $smarty->assign('sitelogo', $THEME->header_logo($skindata['header_logo_image'])); }