[ Index ]
 

Code source de IMP H3 (4.1.5)

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> folders.php (source)

   1  <?php
   2  /**
   3   * $Horde: imp/folders.php,v 2.309.2.35 2007/01/02 13:54:54 jan Exp $
   4   *
   5   * Copyright 2000-2007 Charles J. Hagenbuch <chuck@horde.org>
   6   * Copyright 2000-2007 Jon Parise <jon@horde.org>
   7   * Copyright 2000-2007 Anil Madhavapeddy <avsm@horde.org>
   8   * Copyright 2003-2007 Michael Slusarz <slusarz@bigworm.colorado.edu>
   9   *
  10   * See the enclosed file COPYING for license information (GPL).  If you
  11   * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  12   */
  13  
  14  /**
  15   * Utility function to return a url for the various images.
  16   */
  17  function _image($name, $alt, $type)
  18  {
  19      static $cache;
  20  
  21      if (!isset($cache)) {
  22          $cache = array();
  23      } elseif (!empty($cache[$type][$name])) {
  24          return $cache[$type][$name];
  25      }
  26  
  27      if ($type == 'folder') {
  28          $cache[$type][$name] = Horde::img('folders/' . $name, $alt, 'style="vertical-align:middle"');
  29      } else {
  30          $cache[$type][$name] = Horde::img('tree/' . $name, $alt, 'style="vertical-align:middle"', $GLOBALS['registry']->getImageDir('horde'));
  31      }
  32  
  33      return $cache[$type][$name];
  34  }
  35  
  36  @define('IMP_BASE', dirname(__FILE__));
  37  $authentication = OP_HALFOPEN;
  38  require_once  IMP_BASE . '/lib/base.php';
  39  require_once  IMP_BASE . '/lib/IMAP/Tree.php';
  40  require_once  IMP_BASE . '/lib/Folder.php';
  41  require_once 'Horde/Identity.php';
  42  require_once 'Horde/Template.php';
  43  Horde::addScriptFile('folders.js', 'imp');
  44  
  45  /* Redirect back to the mailbox if folder use is not allowed. */
  46  if (!$conf['user']['allow_folders']) {
  47      $notification->push(_("Folder use is not enabled."), 'horde.error');
  48      header('Location: ' . Horde::applicationUrl('mailbox.php', true));
  49      exit;
  50  }
  51  
  52  /* Get quota information. */
  53  if (isset($imp['quota']) && is_array($imp['quota'])) {
  54      require_once  IMP_BASE . '/lib/Quota.php';
  55      $quotaDriver = &IMP_Quota::singleton($imp['quota']['driver'], $imp['quota']['params']);
  56      if ($quotaDriver !== false) {
  57          $quota = $quotaDriver->getQuota();
  58      }
  59      IMP::checkAuthentication(OP_HALFOPEN, true);
  60  }
  61  
  62  /* Initialize the user's identities. */
  63  $identity = &Identity::singleton(array('imp', 'imp'));
  64  
  65  /* Decide whether or not to show all the unsubscribed folders */
  66  $subscribe = $prefs->getValue('subscribe');
  67  $showAll = (!$subscribe || $imp['showunsub']);
  68  
  69  /* Get the base URL for this page. */
  70  $folders_url = Horde::selfUrl();
  71  
  72  /* Initialize the IMP_Folder object. */
  73  $imp_folder = &IMP_Folder::singleton();
  74  
  75  /* Initialize the IMP_Tree object. */
  76  $imptree = &IMP_Tree::singleton();
  77  
  78  $folder_list = Util::getFormData('folder_list', array());
  79  $refresh_time = $prefs->getValue('refresh_time');
  80  
  81  /* Run through the action handlers. */
  82  $actionID = Util::getFormData('actionID');
  83  switch ($actionID) {
  84  case 'collapse_folder':
  85  case 'expand_folder':
  86      $folder = Util::getFormData('folder');
  87      if (!empty($folder)) {
  88          ($actionID == 'expand_folder') ? $imptree->expand($folder) : $imptree->collapse($folder);
  89      }
  90      break;
  91  
  92  case 'expand_all_folders':
  93      $imptree->expandAll();
  94      break;
  95  
  96  case 'collapse_all_folders':
  97      $imptree->collapseAll();
  98      break;
  99  
 100  case 'rebuild_tree':
 101      $imptree->init();
 102      break;
 103  
 104  case 'expunge_folder':
 105      if (!empty($folder_list)) {
 106          require_once  IMP_BASE . '/lib/Message.php';
 107          $imp_message = &IMP_Message::singleton();
 108          $imp_message->expungeMailbox($folder_list);
 109      }
 110      break;
 111  
 112  case 'delete_folder':
 113      if (!empty($folder_list)) {
 114          $imp_folder->delete($folder_list, $subscribe);
 115      }
 116      break;
 117  
 118  case 'delete_search_query':
 119      $queryid = Util::getFormData('queryid');
 120      if (!empty($queryid)) {
 121          $imp_search->deleteSearchQuery($queryid);
 122      }
 123      break;
 124  
 125  case 'download_folder':
 126  case 'download_folder_zip':
 127      if (!empty($folder_list)) {
 128          $mbox = $imp_folder->generateMbox($folder_list, false);
 129          if ($actionID == 'download_folder') {
 130              $browser->downloadHeaders($folder_list[0] . '.mbox', null, false, strlen($mbox));
 131          } else {
 132              require_once 'Horde/Compress.php';
 133              $horde_compress = &Horde_Compress::singleton('zip');
 134              $mbox = $horde_compress->compress(array(array('data' => $mbox, 'name' => $folder_list[0] . '.mbox')));
 135              $browser->downloadHeaders($folder_list[0] . '.zip', 'application/zip', false, strlen($mbox));
 136          }
 137          echo $mbox;
 138          exit;
 139      }
 140      break;
 141  
 142  case 'import_mbox':
 143      $import_folder = Util::getFormData('import_folder');
 144      if (!empty($import_folder)) {
 145          $res = Browser::wasFileUploaded('mbox_upload', _("mailbox file"));
 146          if (!is_a($res, 'PEAR_Error')) {
 147              $res = $imp_folder->importMbox($import_folder, $_FILES['mbox_upload']['tmp_name']);
 148              if ($res === false) {
 149                  $notification->push(sprintf(_("There was an error importing %s."), basename($_FILES['mbox_upload']['name'])), 'horde.error');
 150              } else {
 151                  $notification->push(sprintf(_("Imported %d messages from %s."), $res,  basename($_FILES['mbox_upload']['name'])), 'horde.success');
 152              }
 153          } else {
 154              $notification->push($res, 'horde.error');
 155          }
 156          $actionID = null;
 157      } else {
 158          $refresh_time = null;
 159      }
 160      break;
 161  
 162  case 'create_folder':
 163      $new_mailbox = Util::getFormData('new_mailbox');
 164      if (!empty($new_mailbox)) {
 165          $new_mailbox = String::convertCharset($new_mailbox, NLS::getCharset(), 'UTF7-IMAP');
 166          if (count($folder_list) == 1) {
 167              $namespace_info = IMP::getNamespace($folder_list[0]);
 168              $new_mailbox = $folder_list[0] . $namespace_info['delimiter'] . $new_mailbox;
 169          } else {
 170              $new_mailbox = IMP::appendNamespace($new_mailbox);
 171          }
 172          $imp_folder->create($new_mailbox, $subscribe);
 173      }
 174      break;
 175  
 176  case 'rename_folder':
 177      $new_names = explode("\n", Util::getFormData('new_names'));
 178      $old_names = explode("\n", Util::getFormData('old_names'));
 179      $iMax = count($new_names);
 180      if (!empty($new_names) &&
 181          !empty($old_names) &&
 182          ($iMax == count($old_names))) {
 183          for ($i = 0; $i < $iMax; $i++) {
 184              $oldname = trim($old_names[$i], "\r\n");
 185              $newname = trim($new_names[$i], "\r\n");
 186              $newname = String::convertCharset($newname, NLS::getCharset(), 'UTF7-IMAP');
 187              $imp_folder->rename($oldname, IMP::appendNamespace($newname));
 188          }
 189      }
 190      break;
 191  
 192  case 'subscribe_folder':
 193  case 'unsubscribe_folder':
 194      if (!empty($folder_list)) {
 195          if ($actionID == 'subscribe_folder') {
 196              $imp_folder->subscribe($folder_list);
 197          } else {
 198              $imp_folder->unsubscribe($folder_list);
 199          }
 200      } else {
 201          $notification->push(_("No folders were specified"), 'horde.message');
 202      }
 203      break;
 204  
 205  case 'toggle_subscribed_view':
 206      if ($subscribe) {
 207          $showAll = !$showAll;
 208          $imp['showunsub'] = $showAll;
 209          $imptree->showUnsubscribed($showAll);
 210      }
 211      break;
 212  
 213  case 'poll_folder':
 214      if (!empty($folder_list)) {
 215          $imptree->addPollList($folder_list);
 216          $imp_search->createVINBOXFolder();
 217      }
 218      break;
 219  
 220  case 'nopoll_folder':
 221      if (!empty($folder_list)) {
 222          $imptree->removePollList($folder_list);
 223          $imp_search->createVINBOXFolder();
 224      }
 225      break;
 226  
 227  case 'folders_empty_mailbox':
 228      if (!empty($folder_list)) {
 229          include_once  IMP_BASE . '/lib/Message.php';
 230          $imp_message = &IMP_Message::singleton();
 231          $imp_message->emptyMailbox($folder_list);
 232      }
 233      break;
 234  
 235  case 'mark_folder_seen':
 236  case 'mark_folder_unseen':
 237      if (!empty($folder_list)) {
 238          include_once  IMP_BASE . '/lib/Message.php';
 239          $imp_message = &IMP_Message::singleton();
 240          $imp_message->flagAllInMailbox("\\SEEN", $folder_list, ($actionID == 'mark_folder_seen'));
 241      }
 242      break;
 243  
 244  case 'login_compose':
 245      $open_compose_window = IMP::openComposeWin();
 246      break;
 247  
 248  case 'delete_folder_confirm':
 249  case 'folders_empty_mailbox_confirm':
 250      if (!empty($folder_list)) {
 251          $title = _("Folder Actions - Confirmation");
 252          require IMP_TEMPLATES . '/common-header.inc';
 253          require IMP_TEMPLATES . '/menu.inc';
 254  
 255          $loop = array();
 256          $rowct = 0;
 257  
 258          foreach ($folder_list as $val) {
 259              $data = array(
 260                  'class' => (++$rowct % 2) ? 'item0' : 'item1',
 261                  'name' => IMP::displayFolder($val),
 262                  'val' => $val
 263              );
 264              $loop[] = $data;
 265          }
 266  
 267          $template = &new Horde_Template();
 268          $template->setOption('gettext', true);
 269          $template->set('cancel', _("Cancel"));
 270          $template->set('delete', ($actionID == 'delete_folder_confirm') ? _("Delete Selected Folders") : '', true);
 271          $template->set('empty', ($actionID == 'folders_empty_mailbox_confirm') ? _("Empty Selected Folders") : '', true);
 272          $template->set('folders', $loop);
 273          $template->set('folders_url', $folders_url);
 274          echo $template->fetch(IMP_TEMPLATES . '/folders/folders_confirm.html');
 275  
 276          require $registry->get('templates', 'horde') . '/common-footer.inc';
 277          exit;
 278      }
 279      break;
 280  }
 281  
 282  /* Display the correct message on the action bar */
 283  $subToggleText = $showAll ? _("Hide Unsubscribed") : _("Show Unsubscribed");
 284  
 285  /* Set the URL to refresh the page to in the META tag */
 286  $refresh_url = Horde::applicationUrl('folders.php', true);
 287  
 288  $title = _("Folder Navigator");
 289  require IMP_TEMPLATES . '/common-header.inc';
 290  require IMP_TEMPLATES . '/menu.inc';
 291  IMP::status();
 292  
 293  /* Print quota information. */
 294  if (isset($quota)) {
 295      require IMP_TEMPLATES . '/quota/quota.inc';
 296  }
 297  
 298  $i = $rowct = 0;
 299  $displayNames = $newmsgs = array();
 300  
 301  if ($imp['file_upload'] && ($actionID == 'import_mbox')) {
 302      require IMP_TEMPLATES . '/folders/import.inc';
 303      require $registry->get('templates', 'horde') . '/common-footer.inc';
 304      exit;
 305  } else {
 306      require IMP_TEMPLATES . '/folders/head.inc';
 307      require IMP_TEMPLATES . '/folders/actions.inc';
 308  }
 309  
 310  /* Get special folders. */
 311  $trash = IMP::folderPref($prefs->getValue('trash_folder'), true);
 312  $draft = IMP::folderPref($prefs->getValue('drafts_folder'), true);
 313  $sent = $identity->getAllSentmailFolders();
 314  
 315  $name_url = Util::addParameter(Horde::applicationUrl('mailbox.php'), 'no_newmail_popup', 1);
 316  
 317  $mbox_icons = $morembox = $rows = array();
 318  
 319  /* Call the mailbox icon hook, if requested. */
 320  if (!empty($conf['hooks']['mbox_icon'])) {
 321      require_once HORDE_BASE . '/config/hooks.php';
 322      if (function_exists('_imp_hook_mbox_icons')) {
 323          $mbox_icons = call_user_func('_imp_hook_mbox_icons');
 324      }
 325  }
 326  
 327  /* Start iterating through the list of mailboxes, displaying them. */
 328  $mailbox = $imptree->reset();
 329  do {
 330      $msgs_info = $row = array();
 331      $row['show_msgs'] = false;
 332      $row['nocheckbox'] = false;
 333      $row['vfolder'] = false;
 334      $mailbox['label'] = htmlspecialchars($mailbox['label']);
 335  
 336      if (!$imptree->isContainer($mailbox)) {
 337          /* We are dealing with mailboxes here.
 338           * Determine if we need to poll this mailbox for new messages. */
 339          if ($imptree->isPolled($mailbox)) {
 340              $row['show_msgs'] = true;
 341              /* If we need message information for this folder, update it
 342               * now. */
 343              $msgs_info = $imptree->getElementInfo($mailbox['value']);
 344              if (!empty($msgs_info)) {
 345                  /* Populate the $newmsgs hash with the new msgs count. */
 346                  if (!empty($msgs_info['newmsg'])) {
 347                      $newmsgs[$mailbox['value']] = $msgs_info['newmsg'];
 348                  }
 349  
 350                  /* Identify the number of messages in the folder. */
 351                  $row['msgs'] = $msgs_info['messages'];
 352  
 353                  /* Highlight mailboxes with unread messages in bold. */
 354                  $row['new'] = $msgs_info['unseen'];
 355                  if (!empty($row['new'])) {
 356                      $mailbox['label'] = '<strong>' . $mailbox['label'] . '</strong>';
 357                  }
 358              }
 359          }
 360  
 361          $row['name'] = Horde::link(Util::addParameter($name_url, 'mailbox', $mailbox['value']), sprintf(_("View messages in %s"), ($imptree->isVFolder($mailbox)) ? $mailbox['label'] : IMP::displayFolder($mailbox['value']))) . $mailbox['label'] . '</a>';
 362  
 363          switch ($mailbox['value']) {
 364          case 'INBOX':
 365              $dir2 = _image('inbox.png', _("Inbox"), 'folder');
 366              break;
 367  
 368          case $trash:
 369              $dir2 = ($prefs->getValue('use_vtrash')) ? _image(($imptree->isOpen($mailbox)) ? 'folder_open.png' : 'folder.png', _("Mailbox"), 'folder') :_image('trash.png', _("Trash folder"), 'folder');
 370              break;
 371  
 372          case $draft:
 373              $dir2 = _image('drafts.png', _("Draft folder"), 'folder');
 374              break;
 375  
 376          default:
 377              if (in_array($mailbox['value'], $sent)) {
 378                  $dir2 = _image('sent.png', _("Sent mail folder"), 'folder');
 379              } else {
 380                  if (isset($mbox_icons[$mailbox['value']])) {
 381                      $dir2 = $mbox_icons[$mailbox['value']];
 382                  } else {
 383                      $dir2 = _image(($imptree->isOpen($mailbox)) ? 'folder_open.png' : 'folder.png', _("Mailbox"), 'folder');
 384                  }
 385              }
 386              break;
 387          }
 388  
 389          /* Virtual folders. */
 390          if ($imptree->isVFolder($mailbox)) {
 391              $row['nocheckbox'] = true;
 392              if ($imp_search->isVTrashFolder($mailbox['value'])) {
 393                  $row['vfolder'] = false;
 394                  $dir2 = _image('trash.png', _("Virtual Trash Folder"), 'folder');
 395              } elseif ($imp_search->isVINBOXFolder($mailbox['value'])) {
 396                  $row['vfolder'] = false;
 397                  $dir2 = _image('inbox.png', _("Virtual INBOX Folder"), 'folder');
 398              } else {
 399                  $row['vfolder'] = true;
 400                  $row['delvfolder'] = Horde::link($imp_search->deleteURL($mailbox['value']), _("Delete Virtual Folder")) . _("Delete") . '</a>';
 401                  $row['editvfolder'] = Horde::link($imp_search->editURL($mailbox['value']), _("Edit Virtual Folder")) . _("Edit") . '</a>';
 402              }
 403          }
 404      } else {
 405          /* We are dealing with folders here. */
 406          $row['name'] = $mailbox['label'];
 407          if ($imptree->isOpen($mailbox)) {
 408              $dir2 = _image('folder_open.png', _("Opened Folder"), 'folder');
 409          } else {
 410              $dir2 = _image('folder.png', _("Closed Folder"), 'folder');
 411          }
 412  
 413          /* Virtual folders. */
 414          if ($imptree->isVFolder($mailbox)) {
 415              $row['nocheckbox'] = true;
 416          }
 417      }
 418  
 419      $peek = $imptree->peek();
 420  
 421      if ($imptree->hasChildren($mailbox, true)) {
 422          $dir = Util::addParameter($folders_url, 'folder', $mailbox['value']);
 423          if ($imptree->isOpen($mailbox)) {
 424              $dir = Util::addParameter($dir, 'actionID', 'collapse_folder');
 425              if ($mailbox['value'] == 'INBOX') {
 426                  $minus_img = 'minustop.png';
 427              } else {
 428                  $minus_img = ($peek) ? 'minus.png' : 'minusbottom.png';
 429              }
 430              $dir = Horde::link($dir, _("Collapse Folder")) . _image($minus_img, _("Collapse"), 'tree') . "</a>$dir2";
 431          } else {
 432              $dir = Util::addParameter($dir, 'actionID', 'expand_folder');
 433              if ($mailbox['value'] == 'INBOX') {
 434                  $plus_img = 'plustop.png';
 435              } else {
 436                  $plus_img = ($peek) ? 'plus.png' : 'plusbottom.png';
 437              }
 438              $dir = Horde::link($dir, _("Expand Folder")) . _image($plus_img, _("Expand"), 'tree') . "</a>$dir2";
 439          }
 440      } else {
 441          if ($mailbox['value'] == 'INBOX') {
 442              $join_img = ($peek) ? 'joinbottom-down.png' : 'blank.png';
 443          } else {
 444              $join_img = ($peek) ? 'join.png' : 'joinbottom.png';
 445          }
 446          $dir = _image($join_img, '', 'tree') . $dir2;
 447      }
 448  
 449      /* Highlight line differently if folder/mailbox is
 450       * unsubscribed. */
 451      $row['class'] = (++$rowct % 2) ? 'item0' : 'item1';
 452      if ($showAll && $subscribe && !$imptree->isSubscribed($mailbox) && !$imptree->isContainer($mailbox)) {
 453          $row['class'] .= ' folderunsub';
 454      }
 455  
 456      $row['mbox_val'] = htmlspecialchars($mailbox['value']);
 457      $row['line'] = '';
 458      $morembox[$mailbox['level']] = $peek;
 459      for ($i = 0; $i < $mailbox['level']; $i++) {
 460          $row['line'] .= _image(($morembox[$i]) ? 'line.png' : 'blank.png', '', 'tree');
 461      }
 462      $row['line'] .= $dir;
 463  
 464      /* Hide folder prefixes from the user. */
 465      if ($mailbox['level'] >= 0) {
 466          $rows[] = $row;
 467          $displayNames[] = addslashes(IMP::displayFolder($mailbox['value']));
 468      }
 469  
 470  } while (($mailbox = $imptree->next()));
 471  
 472  /* Check to see if user wants new mail notification */
 473  if ($prefs->getValue('nav_popup')) {
 474      $notification->push(IMP::getNewMessagePopup($newmsgs), 'javascript');
 475  }
 476  if ($prefs->getValue('nav_audio')) {
 477      $play = false;
 478      foreach ($newmsgs as $mb => $nm) {
 479          if ($nm > 0) {
 480              $play = true;
 481              break;
 482          }
 483      }
 484      if ($play) {
 485          $notification->push($registry->getImageDir() . '/audio/theetone.wav',
 486                              'audio');
 487      }
 488  }
 489  
 490  /* Render the rows now. */
 491  $template = &new Horde_Template();
 492  $template->set('rows', $rows, true);
 493  echo $template->fetch(IMP_TEMPLATES . '/folders/folders.html');
 494  if ($rowct > 10) {
 495      $i++;
 496      require IMP_TEMPLATES . '/folders/actions.inc';
 497  }
 498  
 499  require IMP_TEMPLATES . '/folders/foot.inc';
 500  
 501  if (!empty($open_compose_window)) {
 502      $args = 'popup=1';
 503      if (!isset($options)) {
 504          $options = array();
 505      }
 506      foreach (array_merge($options, IMP::getComposeArgs()) as $arg => $value) {
 507          $args .= !empty($value) ? '&' . $arg . '=' . urlencode($value) : '';
 508      }
 509      Horde::addScriptFile('popup.js');
 510      echo "<script type='text/javascript'>popup_imp('" . Horde::applicationUrl('compose.php') . "',700,650,'" . addslashes($args) . "');</script>";
 511  }
 512  
 513  /* BC check. */
 514  if (class_exists('Notification_Listener_audio')) {
 515      $notification->notify(array('listeners' => 'audio'));
 516  }
 517  require $registry->get('templates', 'horde') . '/common-footer.inc';


Généré le : Thu Nov 29 12:30:07 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics