function privatemsg_list in Privatemsg 5.3
Same name and namespace in other branches
- 5 privatemsg.module \privatemsg_list()
- 6.2 privatemsg.pages.inc \privatemsg_list()
- 6 privatemsg.module \privatemsg_list()
- 7.2 privatemsg.pages.inc \privatemsg_list()
- 7 privatemsg.pages.inc \privatemsg_list()
1 string reference to 'privatemsg_list'
- privatemsg_menu in ./
privatemsg.module - Implementation of hook_menu().
File
- ./
privatemsg.module, line 671
Code
function privatemsg_list($uid = NULL) {
global $user;
if (!empty($uid) && is_numeric($uid) && user_access('administer private messages')) {
$account = user_load(array(
'uid' => $uid,
));
}
else {
$account = $user;
}
// Notification emails link here, but the user may not be logged in yet.
if ($account && !$account->uid) {
drupal_goto('user/login', 'destination=privatemsg');
}
// wha? Disallow users who have set their pref to "don't contact me" from
// seeing their inbox? Surely not: privatemsg_allow only determines whether a
// user receives direct private messages, there are still other types of
// messages that arrive in a user's inbox.
if (!user_access('access private messages')) {
// || !$account->privatemsg_allow) {
return drupal_access_denied();
}
$args = array(
$account->uid,
);
if (isset($_SESSION['privatemsg_type'])) {
$type = " AND type = '%s'";
$args[] = $_SESSION['privatemsg_type'];
}
else {
$type = '';
}
$current_folder = intval(arg(2));
$folder_name = _privatemsg_folder_map($current_folder, $account->uid);
$count_query = NULL;
if ($current_folder == PRIVATEMSG_FOLDER_SENT) {
$where_field = 'author';
$join_field = 'recipient';
}
else {
$where_field = 'recipient';
$join_field = 'author';
}
$sql1 = "SELECT id, subject, p.timestamp, u.uid, u.name, newmsg, type FROM {privatemsg} p INNER JOIN {users} u ON ";
$sql = $sql1 . "p.{$join_field} = u.uid WHERE p.{$where_field} = %d {$type} AND p.{$where_field}_del = %d";
if ($current_folder == PRIVATEMSG_FOLDER_RECYCLE_BIN) {
$args[] = 1;
$sql .= " UNION {$sql1} p.recipient = u.uid WHERE p.author = %d {$type} AND p.author_del = %d";
$args = array_merge($args, $args);
$count_query = "SELECT (SELECT COUNT(*) FROM {privatemsg} p INNER JOIN {users} u ON p.author = u.uid WHERE p.recipient = %d AND p.recipient_del = %d) + (SELECT COUNT(*) FROM {privatemsg} p INNER JOIN {users} u ON p.recipient = u.uid WHERE p.author = %d AND p.author_del = %d)";
}
else {
$args[] = 0;
if ($current_folder != PRIVATEMSG_FOLDER_SENT) {
$args[] = $current_folder;
$sql .= " AND folder = %d";
}
}
$header = _privatemsg_list_header($current_folder);
$ts = tablesort_init($header);
$_SESSION['privatemsg_list_sql'] = array(
'sql' => $sql,
'args' => $args,
'field' => db_escape_string($ts['sql']),
'sort' => drupal_strtoupper(db_escape_string($ts['sort'])),
);
$result = pager_query($sql . tablesort_sql($header), variable_get('privatemsg_per_page', 10), 0, $count_query, $args);
$messages = array();
while ($message = db_fetch_object($result)) {
if ($current_folder == PRIVATEMSG_FOLDER_SENT) {
$message->newmsg = 0;
}
$messages[] = $message;
}
$folders = privatemsg_load_folders($account->uid);
$output = drupal_get_form('privatemsg_cur_folder_form', $folders, $current_folder);
$output .= drupal_get_form('privatemsg_list_form', $messages, $folders, $current_folder, $account);
return $output;
}