Source for file options_order.php

Documentation is available at options_order.php

  1. <?php
  2. /**
  3.  * options_order.php
  4.  *
  5.  * Displays messagelist column order options
  6.  *
  7.  * @copyright 1999-2020 The SquirrelMail Project Team
  8.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9.  * @version $Id: options_order.php 14845 2020-01-07 08:09:34Z pdontthink $
  10.  * @package squirrelmail
  11.  * @subpackage prefs
  12.  */
  13.  
  14. /** This is the options_order page */
  15. define('PAGE_NAME', 'options_order');
  16.  
  17. /**
  18.  * Include the SquirrelMail initialization file.
  19.  */
  20. require('../include/init.php');
  21.  
  22. /* SquirrelMail required files. */
  23. require_once(SM_PATH . 'functions/forms.php');
  24.  
  25. /* get globals */
  26. if (sqgetGlobalVar('num',       $num,       SQ_GET)) {
  27.    $num = (int) $num;
  28. } else {
  29.    $num = false;
  30. }
  31. if (!sqgetGlobalVar('method', $method)) {
  32.     $method = '';
  33. } else {
  34.     $method = sm_encode_html_special_chars($method);
  35. }
  36. if (!sqgetGlobalVar('positions', $pos, SQ_GET)) {
  37.     $pos = 0;
  38. } else {
  39.     $pos = (int) $pos;
  40. }
  41.  
  42. if (!sqgetGlobalVar('account', $account, SQ_GET)) {
  43.     $iAccount = 0;
  44. } else {
  45.     $iAccount = (int) $account;
  46. }
  47.  
  48. if (sqgetGlobalVar('mailbox', $mailbox, SQ_GET)) {
  49.    $aMailboxPrefs = unserialize(getPref($data_dir, $username, "pref_".$iAccount.'_'.$mailbox));
  50.    if (isset($aMailboxPrefs[MBX_PREF_COLUMNS])) {
  51.        $index_order = $aMailboxPrefs[MBX_PREF_COLUMNS];
  52.    }
  53. } else {
  54.     $index_order_ser = getPref($data_dir, $username, 'index_order');
  55.     if ($index_order_ser) {
  56.         $index_order=unserialize($index_order_ser);
  57.     }
  58. }
  59. if (!isset($index_order)) {
  60.     if (isset($internal_date_sort) && $internal_date_sort == false) {
  61.     } else {
  62.     }
  63. }
  64.  
  65. if (!sqgetGlobalVar('account', $account,  SQ_GET)) {
  66.    $account = 0; // future work, multiple imap accounts
  67. } else {
  68.    $account = (int) $account;
  69. }
  70.  
  71. /* end of get globals */
  72.  
  73. /***************************************************************/
  74. /* Finally, display whatever page we are supposed to show now. */
  75. /***************************************************************/
  76.  
  77. displayPageHeader($color, null, (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
  78.  
  79.  
  80. /**
  81.  * Change the column order of a mailbox
  82.  *
  83.  * @param array  $index_order (reference) contains an ordered list with columns
  84.  * @param string $method action to take, move, add and remove are supported
  85.  * @param int    $num target column
  86.  * @param int    $pos positions to move a column in the index_order array
  87.  * @return bool  $r A change in the ordered list took place.
  88.  */
  89. function change_columns_list(&$index_order,$method,$num,$pos=0) {
  90.     $r = false;
  91.     switch ($method) {
  92.       case 'move': $r = sqm_array_move_value($index_order,$num,$pos); break;
  93.       case 'add':
  94.           $index_order[] = (int) $num;
  95.           $r = true;
  96.           /**
  97.            * flush the cache in order to retrieve the new columns
  98.            */
  99.           sqsession_unregister('mailbox_cache');
  100.           break;
  101.       case 'remove':
  102.         if(in_array($num, $index_order)) {
  103.             unset($index_order[array_search($num, $index_order)]);
  104.             $index_order = array_values($index_order);
  105.             $r = true;
  106.         }
  107.         break;
  108.       default: break;
  109.     }
  110.     return $r;
  111. }
  112.  
  113. /**
  114.  * Column to string translation array
  115.  */
  116. $available[SQM_COL_CHECK]      = _("Checkbox");
  117. $available[SQM_COL_FROM]       = _("From");
  118. $available[SQM_COL_DATE]       = _("Date");
  119. $available[SQM_COL_SUBJ]       = _("Subject");
  120. $available[SQM_COL_FLAGS]      = _("Flags");
  121. $available[SQM_COL_SIZE]       = _("Size");
  122. $available[SQM_COL_PRIO]       = _("Priority");
  123. $available[SQM_COL_ATTACHMENT] = _("Attachments");
  124. $available[SQM_COL_INT_DATE]   = _("Received");
  125. $available[SQM_COL_TO]         = _("To");
  126. $available[SQM_COL_CC]         = _("Cc");
  127. $available[SQM_COL_BCC]        = _("Bcc");
  128.  
  129. if (change_columns_list($index_order,$method,$num,$pos)) {
  130.     if ($method) {
  131.         // TODO, bound index_order to mailbox and make a difference between the global index_order and mailbox bounded index_order
  132.         setPref($data_dir, $username, 'index_order', serialize($index_order));
  133.     }
  134. }
  135.  
  136.  
  137. $opts = array();
  138. if (count($index_order) != count($available)) {
  139.     for ($i=0; $i < count($available); $i++) {
  140.         if (!in_array($i,$index_order)) {
  141.              $opts[$i] = $available[$i];
  142.          }
  143.     }
  144. }
  145.  
  146. // FIXME: why are we using this?  $PHP_SELF is already a global var processed (and therefore trustworthy) by init.php
  147. sqgetGlobalVar('PHP_SELF', $PHP_SELF, SQ_SERVER);
  148. $x = isset($mailbox) && $mailbox ? '&amp;mailbox='.urlencode($mailbox) : '';
  149.  
  150. $oTemplate->assign('fields', $available);
  151. $oTemplate->assign('current_order', $index_order);
  152. $oTemplate->assign('not_used', $opts);
  153. $oTemplate->assign('always_show', array(SQM_COL_SUBJ, SQM_COL_FLAGS));
  154.  
  155. // FIXME: (related to the above) $PHP_SELF might already have a query string... don't assume otherwise here by adding the ? sign!!
  156. $oTemplate->assign('move_up', $PHP_SELF .'?method=move&amp;positions=-1'. $x .'&amp;num=');
  157. $oTemplate->assign('move_down', $PHP_SELF .'?method=move&amp;positions=1'. $x .'&amp;num=');
  158. $oTemplate->assign('remove', $PHP_SELF .'?method=remove'. $x .'&amp;num=');
  159. $oTemplate->assign('add', $PHP_SELF.'?method=add'.$x.'&amp;num=');
  160. $oTemplate->assign('addField_action', $PHP_SELF);
  161.  
  162. $oTemplate->display('options_order.tpl');
  163.  
  164. $oTemplate->display('footer.tpl');

Documentation generated on Mon, 13 Jan 2020 04:23:19 +0100 by phpDocumentor 1.4.3