You are here

function privatemsg_manage_folders in Privatemsg 5.3

Same name and namespace in other branches
  1. 5 privatemsg.module \privatemsg_manage_folders()

Display the console that lets users manage their private message folders.

1 string reference to 'privatemsg_manage_folders'
privatemsg_menu in ./privatemsg.module
Implementation of hook_menu().

File

./privatemsg.module, line 1106

Code

function privatemsg_manage_folders() {
  global $user;
  $header = array(
    t('Name'),
    t('Messages'),
    t('Operations'),
  );
  $folders = privatemsg_load_folders($user->uid);
  foreach ($folders as $folder) {
    $fid = $folder['fid'];
    $operations = array();
    switch ($fid) {
      case PRIVATEMSG_FOLDER_RECYCLE_BIN:

        // Deleted messages are not necessarily stored in a folder with folder
        // ID -1. Instead, they retain the folder ID of their original folders.
        $msg_count = db_result(db_query("SELECT COUNT(*) FROM {privatemsg} WHERE recipient = %d AND recipient_del = 1", $user->uid));
        break;
      case PRIVATEMSG_FOLDER_SENT:
        $msg_count = db_result(db_query("SELECT COUNT(*) FROM {privatemsg} WHERE author = %d AND author_del = 0", $user->uid, $fid));
        break;
      case PRIVATEMSG_FOLDER_INBOX:
        $msg_count = db_result(db_query("SELECT COUNT(*) FROM {privatemsg} WHERE recipient = %d AND folder = %d AND recipient_del = 0", $user->uid, $fid));
        break;
      default:

        // Custom folders.
        $msg_count = db_result(db_query("SELECT COUNT(*) FROM {privatemsg} WHERE recipient = %d AND folder = %d AND recipient_del = 0", $user->uid, $fid));
        $operations[] = l(t('Rename'), 'privatemsg/folders/' . $fid . '/rename');
        $operations[] = l(t('Empty'), 'privatemsg/folders/' . $fid . '/empty');
        $operations[] = l(t('Delete'), 'privatemsg/folders/' . $fid . '/delete');
        break;
    }
    $row = array(
      l($folder['name'], $fid != 0 ? 'privatemsg/list/' . $fid : 'privatemsg'),
      $msg_count,
    );
    $row = array_merge($row, !empty($operations) ? $operations : array(
      array(
        'data' => '',
        'colspan' => 3,
      ),
    ));
    $rows[] = $row;
  }
  $output = theme('table', $header, $rows, array(
    'class' => 'pm-manage-folders',
  )) . drupal_get_form('privatemsg_new_folder_form');
  return $output;
}