function privatemsg_contacts_form in Privatemsg 5
Same name and namespace in other branches
- 5.3 privatemsg.module \privatemsg_contacts_form()
Display a user's contacts list and let them write a PM to multiple contacts.
1 string reference to 'privatemsg_contacts_form'
- privatemsg_menu in ./
privatemsg.module - Implementation of hook_menu().
File
- ./
privatemsg.module, line 1685
Code
function privatemsg_contacts_form() {
$contacts = array();
global $user;
// Add people who have messaged the user to the contact list.
$result = db_query("SELECT DISTINCT u.name, u.uid FROM {privatemsg} AS p " . "LEFT JOIN {users} AS u ON p.author = u.uid WHERE " . "p.recipient = %d AND p.author != %d AND p.timestamp > " . "(UNIX_TIMESTAMP(NOW()) - (3600 * 24 * 30)) ORDER BY " . "u.name", $user->uid, $user->uid);
while ($author = db_fetch_object($result)) {
$contacts[check_plain($author->name)] = $author->uid;
}
// Add people the user has messaged to the contact list.
$result = db_query("SELECT DISTINCT u.name, u.uid FROM {privatemsg} AS p " . "LEFT JOIN {users} AS u ON p.recipient = u.uid WHERE " . "p.author = %d AND p.timestamp > " . "(UNIX_TIMESTAMP(NOW()) - (3600 * 24 * 30)) ORDER BY " . "u.name", $user->uid, $user->uid);
while ($author = db_fetch_object($result)) {
$contacts[check_plain($author->name)] = $author->uid;
}
if (module_exists('buddylist')) {
$result = db_query("SELECT u.name, u.uid FROM {buddylist} AS b LEFT JOIN " . "{users} AS u ON b.buddy = u.uid WHERE b.uid = %d", $user->uid);
while ($buddy = db_fetch_object($result)) {
$contacts[check_plain($buddy->name)] = $buddy->uid;
}
}
ksort($contacts);
$form['contacts'] = array(
'#theme' => 'privatemsg_contacts_table',
'#tree' => TRUE,
);
foreach ($contacts as $name => $uid) {
$form['contacts'][$uid]['selected'] = array(
'#type' => 'checkbox',
);
$form['contacts'][$uid]['name'] = array(
'#type' => 'value',
'#value' => $name,
);
$form['contacts'][$uid]['contact'] = array(
'#type' => 'value',
'#value' => theme('privatemsg_username', (object) array(
'uid' => $uid,
'name' => $name,
)),
);
$form['contacts'][$uid]['operations'] = array(
'#type' => 'value',
'#value' => l(t('Write private message'), 'privatemsg/new/' . $uid),
);
}
if (count($contacts) > 0) {
$form['selected'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
);
$form['selected']['label'] = array(
'#value' => '<div><strong>' . t('With selected:') . '</strong> </div>',
);
$form['selected']['write_message'] = array(
'#type' => 'submit',
'#value' => t('Write private message'),
);
}
return $form;
}