require dirname(dirname(dirname(__FILE__))) . '/init.php'; require_once dirname(__FILE__) . '/lib/multirecipientnotification.php'; require_once get_config('docroot') . '/lib/searchlib.php'; global $USER; $request = param_variable('q'); $page = param_integer('page'); if ($page < 1) { $page = 1; } $usersperpage = 10; $more = true; $tmpuser = array(); while ($more && count($tmpuser) < $usersperpage) { $users = search_user($request, $usersperpage, $usersperpage * ($page - 1)); $more = $users['count'] > $usersperpage * $page; if (!$users['data']) { $users['data'] = array(); } foreach ($users['data'] as $user) { if (count($tmpuser) >= $usersperpage) { $more = true; continue; } if (!can_send_message($USER->id, $user['id']) || $USER->id == $user['id']) { continue; } $tmpuser[] = (object) array('id' => $user['id'], 'text' => '<img class="select2-user-icon" src="' . get_config('wwwroot') . 'thumb.php?type=profileicon&maxwidth=40&maxheight=40&id=' . $user['id'] . '" />' . '<span>' . display_name($user['id']) . '</span>', 'name' => display_name($user['id'])); } $page++; } echo json_encode(array('more' => $more, 'results' => $tmpuser));
/** * * sends a message with text $message and subject $subject to all users referenced * in $userids. The message is connected to $parentid and $fromid will be related * as the id of the sending user. If $fromid=null is not provided, logged in user * is assumed. * * @param array $usrids the ids of the users, may contain the recipient as well * @param string $subject the subject of the message * @param string $message the text of the message * @param int $parentid the id of the message, this one replies to * @param int $fromid the id of the sending user * @return int the message id */ function send_user_message_mr(array $userids, $subject, $message, $parentid = null, $fromid = null) { global $USER; $fromuser = $USER; if (null === $fromid) { $fromid = $USER->get('id'); } else { $fromuser = new User(); $fromuser->find_by_id($fromid); } if (!in_array($fromuser->id, $userids)) { $userids[] = $fromuser->id; } if (empty($userids)) { return true; } // Check permissions for all recipients foreach ($userids as $userid) { if (!can_send_message($USER, $userid) && $userid !== $USER->get('id')) { throw new AccessDeniedException(get_string('cantmessageuser', 'group')); } } $data = new stdClass(); $data->usrids = $userids; $data->subject = $subject; $data->message = $message; $data->parent = $parentid; $data->userfrom = $fromid; $activity = new ActivityTypeMultirecipientmessage($data); return $activity->notify_users($userids); }
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'])); } }
function translate_ids_to_names(array $ids) { global $USER; // for an empty list, the element '' is transmitted $ids = array_diff($ids, array('')); $results = array(); foreach ($ids as $id) { $deleted = get_field('usr', 'deleted', 'id', $id); if ($deleted === '0' && is_numeric($id) && can_send_message($USER->to_stdclass(), $id)) { $results[] = (object) array('id' => $id, 'text' => display_name($id)); } } return $results; }
// addressed to us and originated from user we are replying to. $message = get_record('notification_internal_activity', 'id', $replytoid, 'usr', $USER->get('id'), 'from', $id); if (!$message) { throw new AccessDeniedException(get_string('cantviewmessage', 'group')); } // OK, now it safe to fetch the whole thread. $messages = get_message_thread($replytoid); } $user = get_record('usr', 'id', $id); if (!$user) { throw new UserNotFoundException(get_string('cantmessageuser', 'group')); } else { if ($user->deleted != 0) { throw new AccessDeniedException(get_string('cantmessageuserdeleted', 'group')); } else { if (!can_send_message($USER->to_stdclass(), $id)) { throw new AccessDeniedException(get_string('cantmessageuser', 'group')); } } } define('TITLE', get_string('sendmessageto', 'group', display_name($user))); $returnto = param_alpha('returnto', 'myfriends'); switch ($returnto) { case 'find': $goto = 'user/find.php'; break; case 'view': $goto = profile_url($user, false); break; case 'inbox': $goto = 'account/activity';