Source for file options.php

Documentation is available at options.php

  1. <?php
  2.  
  3. /**
  4.  * Message and Spam Filter Plugin - Filtering Options
  5.  *
  6.  * @copyright 1999-2012 The SquirrelMail Project Team
  7.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8.  * @version $Id: options.php 14346 2012-12-09 12:06:30Z kink $
  9.  * @package plugins
  10.  * @subpackage filters
  11.  */
  12.  
  13. /**
  14.  * Include the SquirrelMail initialization file.
  15.  */
  16. require('../../include/init.php');
  17. include_once(SM_PATH 'functions/imap_general.php');
  18. include_once(SM_PATH 'functions/forms.php');
  19. include_once(SM_PATH 'plugins/filters/filters.php');
  20.  
  21.  
  22. /* get globals */
  23. sqgetGlobalVar('delimiter'$delimiterSQ_SESSION);
  24.  
  25. sqgetGlobalVar('theid'$theid);
  26. sqgetGlobalVar('action'$actionSQ_GET);
  27.  
  28. if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST)) {
  29.  
  30.     if(isset($theid) ) $theid 0;
  31.  
  32.     $complete_post=true;
  33.  
  34.     // FIXME: write human readable error messages
  35.     sqgetGlobalVar('filter_what'$filter_whatSQ_POST);
  36.     if (!sqgetGlobalVar('filter_what'$filter_whatSQ_POST)) {
  37.         do_error("Post error");
  38.         $complete_post=false;
  39.     }
  40.  
  41.     sqgetGlobalVar('filter_where'$filter_whereSQ_POST);
  42.     if (!sqgetGlobalVar('filter_where'$filter_whereSQ_POST)) {
  43.         do_error("Post error");
  44.         $complete_post=false;
  45.     }
  46.  
  47.     sqgetGlobalVar('filter_folder'$filter_folderSQ_POST);
  48.     if (!sqgetGlobalVar('filter_folder'$filter_folderSQ_POST)) {
  49.         do_error("Post error");
  50.         $complete_post=false;
  51.     }
  52.  
  53.     if ($complete_post{
  54.         $filter_what str_replace(',''###COMMA###'$filter_what);
  55.         $filter_what str_replace("\\\\""\\"$filter_what);
  56.         $filter_what str_replace("\\\""'"'$filter_what);
  57.         $filter_what str_replace('"''&quot;'$filter_what);
  58.  
  59.         if (empty($filter_what)) {
  60.             do_error(_("WARNING! You must enter something to search for."));
  61.             $action 'edit';
  62.         }
  63.  
  64.         if (($filter_where == 'Header'&& (strchr($filter_what,':'== '')) {
  65.             do_error(_("WARNING! Header filters should be of the format &quot;Header: value&quot;"));
  66.             $action 'edit';
  67.         }
  68.         if ($action != 'edit'{
  69.         setPref($data_dir$username'filter'.$theid$filter_where.','.$filter_what.','.$filter_folder);
  70.         }
  71.         $filters[$theid]['where'$filter_where;
  72.         $filters[$theid]['what'$filter_what;
  73.         $filters[$theid]['folder'$filter_folder;
  74.     }
  75. elseif (isset($action&& $action == 'delete'{
  76.       remove_filter($theid);
  77. elseif (isset($action&& $action == 'move_up'{
  78.       filter_swap($theid$theid 1);
  79. elseif (isset($action&& $action == 'move_down'{
  80.       filter_swap($theid$theid 1);
  81. elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) {
  82.     sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST);
  83.     setPref($data_dir$username'filters_user_scan'$filters_user_scan_set);
  84.     echo '<br /><div style="text-align: center;"><b>'._("Saved Scan type")."</b></div>\n";
  85. }
  86.  
  87.    $filters load_filters();
  88.    $filters_user_scan getPref($data_dir$username'filters_user_scan');
  89.  
  90.    echo html_tag'table',
  91.             html_tag'tr',
  92.                 html_tag'td',
  93.                     '<div style="text-align: center;"><b>' _("Options"' - ' _("Message Filtering"'</b></div>' ,
  94.                     'left'$color[0]
  95.                 )
  96.             ),
  97.             'center''''width="95%" border="0" cellpadding="2" cellspacing="0"'
  98.         .
  99.         '<br /><form method="post" action="options.php">'.
  100.         html_tag'table''''center''''border="0" cellpadding="2" cellspacing="0"' .
  101.             html_tag'tr' .
  102.                 html_tag'th'_("What to Scan:")'right''''style="white-space: nowrap;"' .
  103.                 html_tag'td''''left' .
  104.             '<select name="filters_user_scan_set">'.
  105.             '<option value=""';
  106.     if ($filters_user_scan == ''{
  107.         echo ' selected="selected"';
  108.     }
  109.     echo '>' _("All messages"'</option>'.
  110.             '<option value="new"';
  111.     if ($filters_user_scan == 'new'{
  112.         echo ' selected="selected"';
  113.     }
  114.     echo '>' _("Only unread messages"'</option>' .
  115.             '</select>'.
  116.         '</td>'.
  117.         html_tag'td''<input type="submit" name="user_submit" value="' _("Save"'" />''left' .
  118.         '</table>'.
  119.         '</form>'.
  120.  
  121.         html_tag'div''[<a href="options.php?action=add">' _("New".
  122.             '</a>] - [<a href="'.SM_PATH.'src/options.php">' _("Done"'</a>]' ,
  123.         'center' '<br />';
  124.  
  125.     if (isset($action&& ($action == 'add' || $action == 'edit')) {
  126.  
  127.         $imapConnection sqimap_login($usernamefalse$imapServerAddress$imapPort0);
  128.         $boxes sqimap_mailbox_list($imapConnection);
  129.  
  130.         for ($a 0$cnt count($boxes)$a $cnt$a++{
  131.             if (strtolower($boxes[$a]['formatted']== 'inbox'{
  132.                 unset($boxes[$a]);
  133.             }
  134.         }
  135.  
  136.         sqimap_logout($imapConnection);
  137.         if !isset($theid) ) {
  138.             $theid count($filters);
  139.         }
  140.         echo html_tag'div''''center' .
  141.              '<form action="options.php" method="post">'.
  142.              html_tag'table''''''''border="0" cellpadding="2" cellspacing="0"' .
  143.              html_tag'tr' .
  144.                 html_tag'td'_("Match:")'left' .
  145.                 html_tag'td''''left' .
  146.                     '<select name="filter_where">';
  147.  
  148.         $L = isset($filters[$theid]['where']);
  149.  
  150.         $sel (($L && $filters[$theid]['where'== 'From')?' selected="selected"':'');
  151.         echo "<option value=\"From\"$sel>_("From"'</option>';
  152.  
  153.         $sel (($L && $filters[$theid]['where'== 'To')?' selected="selected"':'');
  154.         echo "<option value=\"To\"$sel>_("To"'</option>';
  155.  
  156.         $sel (($L && $filters[$theid]['where'== 'Cc')?' selected="selected"':'');
  157.         echo "<option value=\"Cc\"$sel>_("Cc"'</option>';
  158.  
  159.         $sel (($L && $filters[$theid]['where'== 'To or Cc')?' selected="selected"':'');
  160.         echo "<option value=\"To or Cc\"$sel>_("To or Cc"'</option>';
  161.  
  162.         $sel (($L && $filters[$theid]['where'== 'Subject')?' selected="selected"':'');
  163.         echo "<option value=\"Subject\"$sel>_("Subject"'</option>';
  164.  
  165.         $sel (($L && $filters[$theid]['where'== 'Message Body')?' selected="selected"':'');
  166.         echo "<option value=\"Message Body\"$sel>_("Message Body"'</option>';
  167.  
  168.         $sel (($L && $filters[$theid]['where'== 'Header and Body')?' selected="selected"':'');
  169.         echo "<option value=\"Header and Body\"$sel>_("Header and Body"'</option>';
  170.  
  171.         $sel (($L && $filters[$theid]['where'== 'Header')?' selected="selected"':'');
  172.         echo "<option value=\"Header\"$sel>_("Header"'</option>';
  173.  
  174.         echo         '</select>'.
  175.                 '</td>'.
  176.             '</tr>'.
  177.             html_tag'tr' .
  178.                 html_tag'td'_("Contains:")'right' .
  179.                 html_tag'td''''left' .
  180.                     '<input type="text" size="32" name="filter_what" value="';
  181.         if (isset($filters[$theid]['what'])) {
  182.             echo sm_encode_html_special_chars($filters[$theid]['what']);
  183.         }
  184.         echo '" />'.
  185.                 '</td>'.
  186.             '</tr>'.
  187.             html_tag'tr' .
  188.                 html_tag'td'_("Move to:")'left' .
  189.                 html_tag'td''''left' .
  190.                     '<tt>'.
  191.                     '<select name="filter_folder">';
  192.         $selected 0;
  193.         if isset($filters[$theid]['folder']) )
  194.           $selected array(strtolower($filters[$theid]['folder']));
  195.         echo sqimap_mailbox_option_list(0$selected0$boxes);
  196.         echo        '</select>'.
  197.                     '</tt>'.
  198.                 '</td>'.
  199.             '</tr>'.
  200.             '</table>'.
  201.             '<input type="submit" name="filter_submit" value="' _("Submit""\" />\n".
  202.             addHidden('theid'$theid).
  203.             '</form>'.
  204.             '</div>';
  205.  
  206.     }
  207.  
  208. if (count($filters)) {
  209.     echo html_tag'table''''center''''border="0" cellpadding="3" cellspacing="0"' );
  210.  
  211.     for ($i=0$num count($filters)$i $num$i++{
  212.  
  213.         $clr (($i 2)?$color[0]:$color[9]);
  214.         $fdr ($folder_prefix)?str_replace($folder_prefix""$filters[$i]["folder"]):$filters[$i]["folder"];
  215.         echo html_tag'tr'''''$clr .
  216.                    html_tag'td',
  217.                        '<small>' .
  218.                        "[<a href=\"options.php?theid=$i&amp;action=edit\">_("Edit"'</a>]'.
  219.                        '</small>' ,
  220.                    'left' .
  221.                    html_tag'td',
  222.                        '<small>' .
  223.                        "[<a href=\"options.php?theid=$i&amp;action=delete\">_("Delete"'</a>]'.
  224.                        '</small>' ,
  225.                    'left' );
  226.  
  227.         if ($num 1{
  228.             echo html_tag'td''''center' '<small>[';
  229.             if (isset($filters[$i 1])) {
  230.                 echo "<a href=\"options.php?theid=$i&amp;action=move_down\">_("Down"'</a>';
  231.                 if ($i 0{
  232.                     echo '&nbsp;|&nbsp;';
  233.                 }
  234.             }
  235.             if ($i 0{
  236.                 echo "<a href=\"options.php?theid=$i&amp;action=move_up\">_("Up"'</a>';
  237.             }
  238.             echo ']</small></td>';
  239.         }
  240.         echo html_tag'td''-''left' .
  241.              html_tag'td''''left' );
  242.         printf_("If %s contains %s then move to %s"),
  243.             '<b>'.$filters[$i]['where'].'</b>',
  244.             '<b>'.$filters[$i]['what'].'</b>',
  245.             '<b>'.sm_encode_html_special_chars(imap_utf7_decode_local($fdr)).'</b>');
  246.         echo '</td></tr>';
  247.  
  248.     }
  249.     echo '</table>';
  250. }
  251.     echo html_tag'table',
  252.             html_tag'tr',
  253.                 html_tag'td''&nbsp;''left' )
  254.             ,
  255.         'center''''width="80%" border="0" cellpadding="2" cellspacing="0"' );
  256.     echo '</body></html>';

Documentation generated on Sat, 25 May 2013 04:20:00 +0200 by phpDocumentor 1.4.3