function privatemsg_list_form_submit in Privatemsg 5
Same name and namespace in other branches
- 5.3 privatemsg.module \privatemsg_list_form_submit()
File
- ./
privatemsg.module, line 1026
Code
function privatemsg_list_form_submit($form_id, $form_values) {
global $user;
$selected = $placeholders = array();
foreach ($form_values['messages'] as $mid => $message) {
if ($message['selected']) {
$selected[$mid] = $message;
$placeholders[] = '%d';
}
}
if (empty($selected) && $form_values['op'] != t('Empty recycle bin')) {
drupal_set_message(t('No messages selected.'), 'error');
return;
}
else {
$args = array_keys($selected);
$args[] = $form_values['account']->uid;
$where1 = 'WHERE id IN (' . implode(', ', $placeholders) . ') AND ';
$where = $where1 . 'recipient = %d';
$new = 0;
}
switch ($form_values['op']) {
case t('Delete'):
if ($_POST['js_bypass'] == 1) {
foreach ($selected as $mid => $message) {
_privatemsg_delete($mid);
}
drupal_set_message(t('The selected messages have been deleted.'));
}
else {
$_SESSION['privatemsg'] = $form_values['messages'];
$_SESSION['fromfolder'] = intval(arg(2));
drupal_goto('privatemsg/delete/multiple');
}
break;
case t('Mark as unread'):
$new = 1;
// deliberate no break;
case t('Mark as read'):
array_unshift($args, $new);
db_query('UPDATE {privatemsg} SET newmsg = %d ' . $where, $args);
drupal_set_message(t('The selected messages have been updated.'));
break;
case t('Move to folder'):
$fid = $form_values['folder'];
if ($fid == 'new') {
$_SESSION['privatemsg'] = $form_values['messages'];
$_SESSION['fromfolder'] = intval(arg(2));
drupal_goto('privatemsg/folders/movetonew');
}
_privatemsg_move_folder($where, $args, $fid, $form_values['extra_folders']);
break;
case t('Delete permanently'):
foreach (array_keys($selected) as $mid) {
_privatemsg_delete($mid, 2);
}
drupal_set_message(t('The selected messages have been deleted permanently.'));
break;
case t('Restore'):
db_query('UPDATE {privatemsg} SET recipient_del = 0 ' . $where, $args);
$where = $where1 . 'author = %d';
db_query('UPDATE {privatemsg} SET author_del = 0 ' . $where, $args);
drupal_set_message(t('The selected messages have been restored.'));
break;
case t('Empty recycle bin'):
$result = db_query('SELECT id FROM {privatemsg} p WHERE p.recipient = %d AND p.recipient_del = 1 UNION SELECT id FROM {privatemsg} p WHERE p.author = %d AND p.author_del = 1', $user->uid, $user->uid);
while ($message = db_fetch_object($result)) {
_privatemsg_delete($message->id, 2);
}
drupal_set_message('Recycle bin emptied.');
break;
}
}