Source for file setup.php

Documentation is available at setup.php

  1. <?php
  2.  
  3. /**
  4.  * setup.php
  5.  *
  6.  * delete_move_next
  7.  *   deletes or moves currently displayed message and displays
  8.  *   next or previous message.
  9.  *
  10.  * Copyright (c) 1999-2018 The SquirrelMail Project Team
  11.  * Licensed under the GNU GPL. For full terms see the file COPYING.
  12.  *
  13.  * $Id: setup.php 14749 2018-01-16 23:36:07Z pdontthink $
  14.  * @package plugins
  15.  * @subpackage delete_move_next
  16.  */
  17.  
  18. //FIXME: all functionality needs to be moved out of the setup.php file!
  19.  
  20. /**
  21.  * Initialize the plugin
  22.  * @return void 
  23.  */
  24.     global $squirrelmail_plugin_hooks;
  25.  
  26.     $squirrelmail_plugin_hooks['html_top']['delete_move_next''delete_move_next_action';
  27.     $squirrelmail_plugin_hooks['right_main_after_header']['delete_move_next''delete_move_next_action';
  28.     $squirrelmail_plugin_hooks['read_body_bottom']['delete_move_next''delete_move_next_read_b';
  29.     $squirrelmail_plugin_hooks['read_body_menu_bottom']['delete_move_next''delete_move_next_read_t';
  30.  
  31.     // Show options on display preferences page
  32.     //
  33.     $squirrelmail_plugin_hooks['optpage_loadhook_display']['delete_move_next']
  34.       = 'delete_move_next_display_options';
  35.  
  36.     // $squirrelmail_plugin_hooks['options_display_inside']['delete_move_next'] = 'delete_move_next_display_inside';
  37.     // $squirrelmail_plugin_hooks['options_display_save']['delete_move_next'] = 'delete_move_next_display_save';
  38.     $squirrelmail_plugin_hooks['loading_prefs']['delete_move_next''delete_move_next_loading_prefs';
  39. }
  40.  
  41. /* fixes the sort_array for the prev_del/next_del links when 
  42.  * using server side sorting or thread sorting 
  43.  */
  44.  
  45. function fix_sort_array ({
  46.     global $username$data_dir$allow_server_sort$allow_thread_sort,
  47.     $thread_sort_messages
  48.     $mailbox$imapConnection$sort$uid_support$mbx_response;
  49.  
  50.     // Got to grab this out of prefs, since it isn't saved from mailbox_view.php
  51.     if ($allow_thread_sort{
  52.         $thread_sort_messages getPref($data_dir$username"thread_$mailbox",0);
  53.     }
  54.  
  55.     switch (true{
  56.       case ($allow_thread_sort && $thread_sort_messages):
  57.           $server_sort_array get_thread_sort($imapConnection);
  58.           break;
  59.       case ($allow_server_sort):
  60.           $server_sort_array sqimap_get_sort_order($imapConnection$sort$mbx_response);
  61.           break;
  62.       case ($uid_support):
  63.           $server_sort_array sqimap_get_php_sort_order($imapConnection$mbx_response);
  64.           break;
  65.       default:
  66.           break;
  67.     }
  68. }
  69.  
  70. /*
  71.  * Warning: this function relies on the internal representation of
  72.  * of the message cache for the current mailbox. As such, it is fragile
  73.  * because the underlying implementation can change. I will present it
  74.  * to the squirrelmail maintainers as a proposed addition to the API,
  75.  * perhaps even as inline code to sqimap_mailbox_expunge(). In the 
  76.  * meantime, you have been warned. [alane@geeksrus.net 2001/05/06]
  77.  */
  78.  
  79. function delete_move_del_arr_elem($arr$index{
  80.     $tmp array();
  81.     $j 0;
  82.     foreach ($arr as $v{
  83.         if ($j != $index{
  84.            $tmp[$v;
  85.          }
  86.          $j++;
  87.     }
  88.     return $tmp;
  89. }
  90.  
  91.     global $msort$msgs;
  92.     $keys array_keys($msort);
  93.     for ($i 0$i count($keys)$i++{
  94.         echo '<p>key ' $keys[$i' msgid ' $msgs[$keys[$i]]['ID''</p>';
  95.     }
  96. }
  97.  
  98.     global $msgs$msort$sort$imapConnection,
  99.            $mailbox$uid_support$server_sort_array;
  100.     $delAt = -1;
  101.  
  102.     if (is_array($server_sort_array&& !empty($server_sort_array)) {
  103.         foreach ($server_sort_array as $k => $v{
  104.             if ($v === $id{
  105.                 $server_sort_array delete_move_del_arr_elem($server_sort_array$k);
  106.                 break;
  107.             }
  108.         }
  109.         sqsession_register($server_sort_array'server_sort_array');
  110.     }
  111.  
  112.     if(isset($msort&& count($msort0{
  113.         for ($i 0$i count($msort)$i++{
  114.             if ($msgs[$i]['ID'== $id{
  115.                 $delAt $i;
  116.             elseif ($msgs[$i]['ID'$id{
  117.                 if (!$uid_support{
  118.                    $msgs[$i]['ID']--;
  119.                 }
  120.             }
  121.         }
  122.  
  123.         $msgs delete_move_del_arr_elem($msgs$delAt);
  124.         $msort delete_move_del_arr_elem($msort$delAt);
  125.         if ($sort 6{
  126.             if ($sort 2{
  127.                 asort($msort);
  128.             else {
  129.                 arsort($msort);
  130.             }
  131.         }
  132.         sqsession_register($msgs'msgs');
  133.         sqsession_register($msort'msort');
  134.     }
  135.  
  136.     sqimap_mailbox_expunge($imapConnection$mailboxtrue);
  137. }
  138.  
  139.  
  140.     if sqgetGlobalVar('unread_id'$unread_idSQ_GET) ) {
  141.         delete_move_next_unread();
  142.     else if sqgetGlobalVar('delete_id'$delete_idSQ_GET) ) {
  143.         delete_move_next_delete();
  144.         fix_sort_array();
  145.     else if sqgetGlobalVar('move_id'$move_idSQ_POST) ) {
  146.         delete_move_next_move();
  147.         fix_sort_array();
  148.     }
  149. }
  150.  
  151.  
  152.     global $delete_move_next_t;
  153.  
  154.     if($delete_move_next_t == SMPREF_ON{
  155.         delete_move_next_read('top');
  156.     }
  157. }
  158.  
  159.  
  160.     global $delete_move_next_b;
  161.  
  162.     if ($delete_move_next_b != SMPREF_NO{
  163.         delete_move_next_read('bottom');
  164.     }
  165. }
  166.  
  167. function delete_move_next_read($currloc{
  168.     global $delete_move_next_formATtop$delete_move_next_formATbottom,
  169.            $color$where$what$currentArrayIndex$passed_id,
  170.            $mailbox$sort$startMessage$delete_id$move_id$base_uri,
  171.            $imapConnection$auto_expunge$move_to_trash$mbx_response,
  172.            $uid_support$passed_ent_id$delete_move_next_show_unread,
  173.            $delete_move_next_return_to_message_list;
  174.  
  175.     $urlMailbox urlencode($mailbox);
  176.  
  177.     if (!isset($passed_ent_id)) $passed_ent_id 0;
  178.  
  179.     if (!(($where && $what|| ($currentArrayIndex == -1)) && !$passed_ent_id{
  180.         $next findNextMessage($passed_id);
  181.         $prev findPreviousMessage($mbx_response['EXISTS']$passed_id);
  182.         $prev_if_del $prev;
  183.         $next_if_del $next;
  184.         if (!$uid_support && ($auto_expunge || $move_to_trash)) {
  185.             if ($prev_if_del $passed_id{
  186.                 $prev_if_del--;
  187.             }
  188.             if ($next_if_del $passed_id{
  189.                 $next_if_del--;
  190.             }
  191.         }
  192.  
  193.         /* Base is illegal within documents 
  194.         * $location = get_location();
  195.         * echo "<base href=\"$location/\">" . */
  196.         echo '<table cellspacing="0" width="100%" border="0" cellpadding="2">'.
  197.              '<tr>'.
  198.                  "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\"><small>";
  199.  
  200.         if ($prev 0){
  201.             echo "<a href=\"" $base_uri "src/read_body.php?passed_id=$prev_if_del&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0&amp;delete_id=$passed_id&amp;smtoken=sm_generate_security_token("\">" _("Delete &amp; Prev""</a>" "&nbsp;|&nbsp;";
  202.             if ($delete_move_next_show_unread == SMPREF_ON{
  203.                 echo "<a href=\"" $base_uri "src/read_body.php?passed_id=$prev_if_del&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0&amp;unread_id=$passed_id&amp;smtoken=sm_generate_security_token("\">" _("Unread &amp; Prev""</a>" "&nbsp;|&nbsp;";
  204.             }
  205.         }
  206.         else {
  207.             echo _("Delete &amp; Prev""&nbsp;|&nbsp;";
  208.             if ($delete_move_next_show_unread == SMPREF_ON{
  209.                 echo _("Unread &amp; Prev""&nbsp;|&nbsp;";
  210.             }
  211.         }
  212.         if ($next 0){
  213.             if ($delete_move_next_show_unread == SMPREF_ON{
  214.                 echo "<a href=\"" $base_uri "src/read_body.php?passed_id=$next_if_del&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0&amp;unread_id=$passed_id&amp;smtoken=sm_generate_security_token("\">" _("Unread &amp; Next""</a>&nbsp;|&nbsp;";
  215.             }
  216.             echo "<a href=\"" $base_uri "src/read_body.php?passed_id=$next_if_del&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0&amp;delete_id=$passed_id&amp;smtoken=sm_generate_security_token("\">" _("Delete &amp; Next""</a>";
  217.         else {
  218.             if ($delete_move_next_show_unread == SMPREF_ON{
  219.                 echo _("Unread &amp; Next""&nbsp;|&nbsp;";
  220.             }
  221.             echo _("Delete &amp; Next");
  222.         }
  223.         echo '</small></td></tr>';
  224.  
  225.         if ($next_if_del 0{
  226.             $next_if_del $prev_if_del;
  227.         }
  228.         if (($delete_move_next_formATtop == SMPREF_ON&& ($currloc == 'top')) {
  229.             if (!$delete_move_next_return_to_message_list
  230.              && $next_if_del 0{
  231.                 delete_move_next_moveNextForm($next_if_del);
  232.             else {
  233.                 delete_move_next_moveRightMainForm();
  234.             }
  235.         }
  236.         if (($delete_move_next_formATbottom != SMPREF_NO&& ($currloc == 'bottom')) {
  237.             if (!$delete_move_next_return_to_message_list
  238.              && $next_if_del 0{
  239.                 delete_move_next_moveNextForm($next_if_del);
  240.             else {
  241.                 delete_move_next_moveRightMainForm();
  242.             }
  243.         }
  244.         echo '</table>';
  245.     }
  246. }
  247.  
  248. function get_move_target_list({
  249.     global $imapConnection$lastTargetMailbox;
  250.     if (isset($lastTargetMailbox&& !empty($lastTargetMailbox)) {
  251.         echo sqimap_mailbox_option_list($imapConnectionarray(strtolower($lastTargetMailbox)));
  252.     }
  253.     else {
  254.         echo sqimap_mailbox_option_list($imapConnection);
  255.     }
  256. }
  257.  
  258. function delete_move_next_moveNextForm($next{
  259.  
  260.     global $color$where$what$currentArrayIndex$passed_id,
  261.            $mailbox$sort$startMessage$delete_id$move_id,
  262.            $imapConnection$base_uri;
  263.  
  264.     $urlMailbox urlencode($mailbox);
  265.  
  266.     echo '<tr>'.
  267.          "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
  268.            "<form style=\"display:inline; margin:0\" action=\"" $base_uri "src/read_body.php?mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;passed_id=$next\" method=\"post\"><small>".
  269.             "<input type=\"hidden\" name=\"show_more\" value=\"0\">".
  270.             "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">".
  271.             "<input type=\"hidden\" name=\"smtoken\" value=\"" sm_generate_security_token("\">".
  272.             _("Move to:".
  273.             ' <select name="targetMailbox">';
  274.     echo    '</select> '.
  275.             '<input type="submit" value="' _("Move"'">'.
  276.             '</small>'.
  277.            '</form>'.
  278.          '</td>'.
  279.          '</tr>';
  280. }
  281.  
  282.  
  283.     global $color$where$what$currentArrayIndex$passed_id,
  284.            $mailbox$sort$startMessage$delete_id$move_id,
  285.            $imapConnection$base_uri;
  286.  
  287.     $urlMailbox urlencode($mailbox);
  288.  
  289.     echo '<tr>' .
  290.             "<td bgcolor=\"$color[9]\" width=\"100%\" align=\"center\">".
  291.             "<form style=\"display:inline; margin:0\" action=\"" $base_uri "src/right_main.php?mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage\" method=\"post\"><small>.
  292.             "<input type=\"hidden\" name=\"move_id\" value=\"$passed_id\">".
  293.             "<input type=\"hidden\" name=\"smtoken\" value=\"" sm_generate_security_token("\">".
  294.             _("Move to:".
  295.             ' <select name="targetMailbox">';
  296.     echo    ' </select> ' .
  297.             '<input type=submit value="' _("Move"'">'.
  298.             '</small>'.
  299.          '</form>' .
  300.          '</td>'.
  301.          '</tr>';
  302. }
  303.  
  304.     global $imapConnection;
  305.  
  306.     sqgetGlobalVar('unread_id'$unread_idSQ_GET);
  307.     if (!sqgetGlobalVar('smtoken',$submitted_tokenSQ_GET)) {
  308.         $submitted_token '';
  309.     }
  310.  
  311.     // first, validate security token
  312.     sm_validate_security_token($submitted_token-1TRUE);
  313.  
  314.     sqimap_toggle_flag($imapConnection$unread_id'\\Seen'falsetrue);
  315. }
  316.  
  317.     global $imapConnection$auto_expunge;
  318.  
  319.     sqgetGlobalVar('delete_id'$delete_idSQ_GET);
  320.     sqgetGlobalVar('mailbox'$mailboxSQ_GET);
  321.     if (!sqgetGlobalVar('smtoken',$submitted_tokenSQ_GET)) {
  322.         $submitted_token '';
  323.     }
  324.  
  325.     // first, validate security token
  326.     sm_validate_security_token($submitted_token-1TRUE);
  327.  
  328.     sqimap_msgs_list_delete($imapConnection$mailbox$delete_id);
  329.     if ($auto_expunge{
  330.         delete_move_expunge_from_all($delete_id);
  331.         // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
  332.     }
  333. }
  334.  
  335. function delete_move_next_move({
  336.     global $imapConnection$mailbox$auto_expunge$lastTargetMailbox;
  337.  
  338.     sqgetGlobalVar('move_id'$move_idSQ_POST);
  339.     sqgetGlobalVar('mailbox'$mailboxSQ_FORM);
  340.     sqgetGlobalVar('targetMailbox'$targetMailboxSQ_POST);
  341.     if (!sqgetGlobalVar('smtoken',$submitted_tokenSQ_POST)) {
  342.         $submitted_token '';
  343.     }
  344.  
  345.     // first, validate security token
  346.     sm_validate_security_token($submitted_token-1TRUE);
  347.  
  348.     // Move message
  349.     sqimap_msgs_list_move($imapConnection$move_id$targetMailbox);
  350.     if ($auto_expunge{
  351.         delete_move_expunge_from_all($move_id);
  352.         // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
  353.     }
  354.  
  355.     if ($targetMailbox != $lastTargetMailbox{
  356.         $lastTargetMailbox $targetMailbox;
  357.         sqsession_register($lastTargetMailbox'lastTargetMailbox');
  358.     }
  359. }
  360.  
  361. /**
  362.   * Show options on display preferences page
  363.   *
  364.   */
  365. {
  366.    global $optpage_data$do_not_convert_delete_move_next_legacy_preferences;
  367.  
  368.    // convert legacy on/off values to standardized values
  369.    //
  370.    // IF YOUR INSTALLATION IS NEW, OR ALL USER PREFS HAVE BEEN CONVERTED
  371.    // FROM "on"/"off" to 0/1 THEN YOU CAN ADD THE FOLLOWING TO SQUIRRELMAIL'S
  372.    // config/config_local.php TO AVOID CONVERTING LEGACY VALUES OVER AND OVER:
  373.    //
  374.    //    $do_not_convert_delete_move_next_legacy_preferences = TRUE;
  375.    //
  376.    // unfortunately, SquirrelMail's prefs storage does a lazy == comparison to the prefs cache,
  377.    // which means saving a pref as zero will appear equal to "on" (or "off", but that's irrelevant)
  378.    // so the only way to upgrade these prefs is to save any that are already "on" as 1 (so that
  379.    // subsequent requests to turn off prefs will actually work)
  380.    //
  381.    if (!@include_once(SM_PATH 'plugins/delete_move_next/config.php'))
  382.       @include_once(SM_PATH 'plugins/delete_move_next/config_default.php');
  383.    if (!$do_not_convert_delete_move_next_legacy_preferences)
  384.    {
  385.       global $data_dir$username$delete_move_next_t,
  386.              $delete_move_next_formATtop$delete_move_next_b,
  387.              $delete_move_next_formATbottom$delete_move_next_show_unread;
  388.  
  389.       if ($delete_move_next_t == SMPREF_ON)
  390.          setPref($data_dir$username'delete_move_next_t'SMPREF_ON);
  391.       if ($delete_move_next_b == SMPREF_ON)
  392.          setPref($data_dir$username'delete_move_next_b'SMPREF_ON);
  393.       if ($delete_move_next_formATtop == SMPREF_ON)
  394.          setPref($data_dir$username'delete_move_next_formATtop'SMPREF_ON);
  395.       if ($delete_move_next_formATbottom == SMPREF_ON)
  396.          setPref($data_dir$username'delete_move_next_formATbottom'SMPREF_ON);
  397.       if ($delete_move_next_show_unread == SMPREF_ON)
  398.          setPref($data_dir$username'delete_move_next_show_unread'SMPREF_ON);
  399.    }
  400.  
  401.    // $optpage_data['vals'][2] is the "Message Display" section
  402.    //
  403.    $optpage_data['vals'][2][array(
  404.       'name'          => 'delete_move_next_t',
  405.       'caption'       => _("Display Delete/Move/Next Controls At Top"),
  406.       'type'          => SMOPT_TYPE_BOOLEAN,
  407.       'refresh'       => SMOPT_REFRESH_NONE,
  408.    );
  409.    $optpage_data['vals'][2][array(
  410.       'name'          => 'delete_move_next_formATtop',
  411.       'caption'       => _("Include Move Control At Top"),
  412.       'type'          => SMOPT_TYPE_BOOLEAN,
  413.       'refresh'       => SMOPT_REFRESH_NONE,
  414.    );
  415.    $optpage_data['vals'][2][array(
  416.       'name'          => 'delete_move_next_b',
  417.       'caption'       => _("Display Delete/Move/Next Controls At Bottom"),
  418.       'type'          => SMOPT_TYPE_BOOLEAN,
  419.       'refresh'       => SMOPT_REFRESH_NONE,
  420.    );
  421.    $optpage_data['vals'][2][array(
  422.       'name'          => 'delete_move_next_formATbottom',
  423.       'caption'       => _("Include Move Control At Bottom"),
  424.       'type'          => SMOPT_TYPE_BOOLEAN,
  425.       'refresh'       => SMOPT_REFRESH_NONE,
  426.    );
  427.    $optpage_data['vals'][2][array(
  428.       'name'          => 'delete_move_next_show_unread',
  429.       'caption'       => _("Show Unread & Previous/Next Options"),
  430.       'type'          => SMOPT_TYPE_BOOLEAN,
  431.       'refresh'       => SMOPT_REFRESH_NONE,
  432.    );
  433.    $optpage_data['vals'][2][array(
  434.       'name'          => 'delete_move_next_return_to_message_list',
  435.       'caption'       => _("Return To Message List After Move"),
  436.       'type'          => SMOPT_TYPE_BOOLEAN,
  437.       'refresh'       => SMOPT_REFRESH_NONE,
  438.    );
  439.  
  440.  
  441. }
  442.  
  443.     global $username,$data_dir$delete_move_next_show_unread,
  444.            $delete_move_next_t$delete_move_next_formATtop,
  445.            $delete_move_next_b$delete_move_next_formATbottom,
  446.            $delete_move_next_return_to_message_list,
  447.            $do_not_convert_delete_move_next_legacy_preferences;
  448.  
  449.     $delete_move_next_t getPref($data_dir$username'delete_move_next_t');
  450.     $delete_move_next_b getPref($data_dir$username'delete_move_next_b');
  451.     $delete_move_next_formATtop getPref($data_dir$username'delete_move_next_formATtop');
  452.     $delete_move_next_formATbottom getPref($data_dir$username'delete_move_next_formATbottom');
  453.     $delete_move_next_show_unread getPref($data_dir$username'delete_move_next_show_unread');
  454.     $delete_move_next_return_to_message_list getPref($data_dir$username'delete_move_next_return_to_message_list'1);
  455.  
  456.     // convert legacy on/off values to standardized values
  457.     //
  458.     if (!$do_not_convert_delete_move_next_legacy_preferences)
  459.     {
  460.         if (empty($delete_move_next_t|| $delete_move_next_t == 'off')
  461.             $delete_move_next_t SMPREF_OFF;
  462.         else
  463.             $delete_move_next_t SMPREF_ON;
  464.  
  465.         if (empty($delete_move_next_b|| $delete_move_next_b == 'off')
  466.             $delete_move_next_b SMPREF_OFF;
  467.         else
  468.             $delete_move_next_b SMPREF_ON;
  469.  
  470.         if (empty($delete_move_next_formATtop|| $delete_move_next_formATtop == 'off')
  471.             $delete_move_next_formATtop SMPREF_OFF;
  472.         else
  473.             $delete_move_next_formATtop SMPREF_ON;
  474.  
  475.         if (empty($delete_move_next_formATbottom|| $delete_move_next_formATbottom == 'off')
  476.             $delete_move_next_formATbottom SMPREF_OFF;
  477.         else
  478.             $delete_move_next_formATbottom SMPREF_ON;
  479.  
  480.         if (empty($delete_move_next_show_unread|| $delete_move_next_show_unread == 'off')
  481.             $delete_move_next_show_unread SMPREF_OFF;
  482.         else
  483.             $delete_move_next_show_unread SMPREF_ON;
  484.     }
  485. }

Documentation generated on Sat, 15 Dec 2018 04:25:14 +0100 by phpDocumentor 1.4.3