phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: email/inc class.bofilters.inc.php,1.7,1.8 class.


From: Angelo Tony Puglisi <address@hidden>
Subject: [Phpgroupware-cvs] CVS: email/inc class.bofilters.inc.php,1.7,1.8 class.uifilters.inc.php,1.5,1.6
Date: Sat, 26 Jan 2002 02:55:56 -0500

Update of /cvsroot/phpgroupware//email/inc
In directory subversions:/tmp/cvs-serv9504/email/inc

Modified Files:
        class.bofilters.inc.php class.uifilters.inc.php 
Log Message:
first try at filter list page

Index: class.bofilters.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware//email/inc/class.bofilters.inc.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** class.bofilters.inc.php     25 Jan 2002 21:41:02 -0000      1.7
--- class.bofilters.inc.php     26 Jan 2002 07:55:52 -0000      1.8
***************
*** 17,21 ****
                var $public_functions = array(
                        'process_submitted_data'        => True,
!                       'run_single_filter'     => True
                );
                
--- 17,23 ----
                var $public_functions = array(
                        'process_submitted_data'        => True,
!                       'delete_filter' => True,
!                       'run_single_filter'     => True,
!                       'run_all_filters'       => True
                );
                
***************
*** 23,26 ****
--- 25,29 ----
                var $filter_num = 0;
                //var $this_filter = Array();
+               var $add_new_filter_token = 'add_new';
                var $template = '';
                var $finished_mlist = '';
***************
*** 78,89 ****
                        if ($this->debug > 1) { echo 'email.bofilters. 
*constructor*: call msg->begin_request with args 
array:'.serialize($args_array).'<br>'; }
                        $GLOBALS['phpgw']->msg->begin_request($args_array);
-                       $already_initialized = True;
-                       if ($this->debug > 0) { echo 'email.bofilters. 
*constructor*: LEAVING<br>'; }
                        
                }
                
!               function obtain_filer_num()
                {
                        if ((isset($GLOBALS['HTTP_POST_VARS']['filter_num']))
                        && ((string)$GLOBALS['HTTP_POST_VARS']['filter_num'] != 
''))
                        {
--- 81,127 ----
                        if ($this->debug > 1) { echo 'email.bofilters. 
*constructor*: call msg->begin_request with args 
array:'.serialize($args_array).'<br>'; }
                        $GLOBALS['phpgw']->msg->begin_request($args_array);
                        
+                       if ($this->debug > 0) { echo 'email.bofilters. 
*constructor*: calling $this->read_filter_data_from_prefs<br>'; }
+                       $this->read_filter_data_from_prefs();
+                       if ($this->debug > 0) { echo 'email.bofilters. 
*constructor*: LEAVING<br>'; }
+               }
+               
+               function read_filter_data_from_prefs()
+               {
+                       /*
+                       $this->all_filters = array();
+                       // read sublevel data from prefs
+                       // since we know the constructor called begin_request, 
we know we can get that data here:
+                       if 
((isset($GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters']))
+                       && 
(is_array($GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters']))
+                       && 
(count($GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters']) > 0)
+                       && 
(isset($GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters'][0]['source_accounts'])))
+                       {
+                               $this->all_filters = 
$GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters'];
+                       }
+                       return $this->all_filters;
+                       */
+                       $this->all_filters = array();
+                       if 
((isset($GLOBALS['phpgw']->preferences->data['email']['filters']))
+                       && 
(is_array($GLOBALS['phpgw']->preferences->data['email']['filters'])))
+                       {
+                               $this->all_filters = 
$GLOBALS['phpgw']->preferences->data['email']['filters'];
+                       }
+                       return $this->all_filters;
                }
                
!               function obtain_filer_num($get_next_avail_if_none=True)
                {
                        if ((isset($GLOBALS['HTTP_POST_VARS']['filter_num']))
+                       && ((string)$GLOBALS['HTTP_POST_VARS']['filter_num'] == 
$this->add_new_filter_token))
+                       {
+                               $filter_num = $this->get_next_avail_num();
+                       }
+                       elseif ((isset($GLOBALS['HTTP_GET_VARS']['filter_num']))
+                       && ((string)$GLOBALS['HTTP_GET_VARS']['filter_num'] == 
$this->add_new_filter_token))
+                       {
+                               $filter_num = $this->get_next_avail_num();
+                       }
+                       elseif 
((isset($GLOBALS['HTTP_POST_VARS']['filter_num']))
                        && ((string)$GLOBALS['HTTP_POST_VARS']['filter_num'] != 
''))
                        {
***************
*** 95,109 ****
                                $filter_num = 
(int)$GLOBALS['HTTP_GET_VARS']['filter_num'];
                        }
!                       else
                        {
                                $filter_num = $this->get_next_avail_num();
                        }
!                       return $filter_num;
                }
                
                function get_next_avail_num()
                {
!                       // NOT coded yet
!                       return 0;
                }
                
--- 133,150 ----
                                $filter_num = 
(int)$GLOBALS['HTTP_GET_VARS']['filter_num'];
                        }
!                       elseif($get_next_avail_if_none == True)
                        {
                                $filter_num = $this->get_next_avail_num();
                        }
!                       else
!                       {
!                               $filter_num = False;
!                       }
!                       return (int)$filter_num;
                }
                
                function get_next_avail_num()
                {
!                       return count($this->all_filters)+4;
                }
                
***************
*** 129,136 ****
                function filter_exists($feed_filter_num)
                {
!                       if (count($this->all_filters) == 0)
!                       {
!                               $this->read_filter_data_from_prefs();
!                       }
                        if ((isset($this->all_filters[$feed_filter_num]))
                        && 
(isset($this->all_filters[$feed_filter_num]['source_accounts'])))
--- 170,174 ----
                function filter_exists($feed_filter_num)
                {
!                       $feed_filter_num = (int)$feed_filter_num;
                        if ((isset($this->all_filters[$feed_filter_num]))
                        && 
(isset($this->all_filters[$feed_filter_num]['source_accounts'])))
***************
*** 156,170 ****
                        
                        // FILTER NUMBER
!                       if ((isset($GLOBALS['HTTP_POST_VARS']['filter_num']))
!                       && ((string)$GLOBALS['HTTP_POST_VARS']['filter_num'] != 
''))
!                       {
!                               $this_filter['filter_num'] = 
(int)$GLOBALS['HTTP_POST_VARS']['filter_num'];
!                       }
!                       else
                        {
                                echo 'bofilters.process_submitted_data: LEAVING 
with ERROR, unable to obtain POST filter_num';
                                return;
                        }
!                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: $this_filter[filter_num]: 
['.$this_filter['filter_num'].']<br>'; }
                        
                        // FILTER NAME
--- 194,207 ----
                        
                        // FILTER NUMBER
!                       //$found_filter_num = $this->obtain_filer_num(False);
!                       $found_filter_num = $this->obtain_filer_num();
!                       // is_bool is in the php3 compat library
!                       if ((is_bool($found_filter_num))
!                       && ($found_filter_num == False))
                        {
                                echo 'bofilters.process_submitted_data: LEAVING 
with ERROR, unable to obtain POST filter_num';
                                return;
                        }
!                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: $this_filter[filter_num]: 
['.$found_filter_num.']<br>'; }
                        
                        // FILTER NAME
***************
*** 176,180 ****
                        else
                        {
!                               $this_filter['filtername'] = 'Filter 
'.$this_filter['filter_num'];
                        }
                        if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: $this_filter[filtername]: 
['.$this_filter['filtername'].']<br>'; }
--- 213,218 ----
                        else
                        {
!                               //$this_filter['filtername'] = 'Filter 
'.$found_filter_num;
!                               $this_filter['filtername'] = 'My Mail Filter';
                        }
                        if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: $this_filter[filtername]: 
['.$this_filter['filtername'].']<br>'; }
***************
*** 260,373 ****
                        }
                        if ($this->debug_set_prefs > 2) { echo 
'bofilters.process_submitted_data: $this_filter[] dump <strong><pre>'; 
print_r($this_filter); echo "</pre></strong>\r\n"; }
                        
-                       // SAVE TO PREFS DATABASE
-                       // we called begin_request in the constructor, so we 
know the prefs object exists
-                       // filters are based at [filters][X] where X is the 
filter_num, based on the [email] top level array tree
-                       // first we delete any existing data at the desired 
prefs location
-                       $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']';
-                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->delete_struct("email", 
$pref_struct_str) which will eval $pref_struct_str='.$pref_struct_str.'<br>'; }
-                       
$GLOBALS['phpgw']->preferences->delete_struct('email',$pref_struct_str);
                        // now add this filter piece by piece
                        // we can only set a non-array value, but we can use 
array string for the base
                        // but we can grab structures
                        
!                       // $this_filter['filter_num']   integer use this as the 
array key based on [filters]
!                       // $this_filter['filtername']   string (will require 
htmlslecialchars_encode and decode
!                       $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["filtername"]';
!                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['filtername'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                       $GLOBALS['phpgw']->preferences->add_struct('email', 
$pref_struct_str, $this_filter['filtername']);
! 
!                       // $this_filter['source_accounts']      array
!                       // $this_filter['source_accounts'][X]   array
!                       // $this_filter['source_accounts'][X]['folder'] string
!                       // $this_filter['source_accounts'][X]['acctnum']        
integer
!                       for ($i=0; $i < count($this_filter['source_accounts']); 
$i++)
!                       {
!                               // folder
!                               $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["source_accounts"]['.$i.']["folder"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['source_accounts'][$i]['folder'].') which will 
eval $pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['source_accounts'][$i]['folder']);
!                               // acctnum
!                               $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["source_accounts"]['.$i.']["acctnum"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['source_accounts'][$i]['acctnum'].') which 
will eval $pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['source_accounts'][$i]['acctnum']);
!                       }
!                       
!                       // $this_filter['matches']      Array
!                       // $this_filter['matches'][X]   Array
!                       // $this_filter['matches'][X]['andor']  UNSET for 
$this_filter['matches'][0], SET for all the rest : and | or | ignore_me
!                       // $this_filter['matches'][X]['examine']                
known_string : IMAP search keys
!                       // $this_filter['matches'][X]['comparator']     
known_string : contains | notcontains
!                       // $this_filter['matches'][X]['matchthis']      
user_string
!                       for ($i=0; $i < count($this_filter['matches']); $i++)
!                       {
!                               // andor
!                               if (isset($this_filter['matches'][$i]['andor']))
!                               {
!                                       $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["matches"]['.$i.']["andor"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['matches'][$i]['andor'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['matches'][$i]['andor']);
!                               }
!                               // examine
!                               $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["matches"]['.$i.']["examine"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['matches'][$i]['examine'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['matches'][$i]['examine']);
!                               // comparator
!                               $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["matches"]['.$i.']["comparator"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['matches'][$i]['comparator'].') which will 
eval $pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['matches'][$i]['comparator']);
!                               // matchthis
!                               // user_string, may need 
htmlslecialchars_encode decode and/or the user may forget to tnter data here
!                               if 
((!isset($this_filter['matches'][$i]['matchthis']))
!                               || 
(trim($this_filter['matches'][$i]['matchthis']) == ''))
!                               {
!                                       
$this_filter['matches'][$i]['matchthis'] = 'user_string_not_filled_by_user';
!                               }
!                               $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["matches"]['.$i.']["matchthis"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['matches'][$i]['matchthis'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['matches'][$i]['matchthis']);
!                       }
!                       
!                       // $this_filter['actions']      Array
!                       // $this_filter['actions'][X]           Array
!                       // $this_filter['actions'][X]['judgement']      
known_string
!                       // $this_filter['actions'][X]['folder']         string 
contains URI style data ex. "&folder=INBOX.Trash&acctnum=0"
!                       // $this_filter['actions'][X]['actiontext']     
user_string
!                       // $this_filter['actions'][X]['stop_filtering'] UNSET | 
SET string "True"
!                       for ($i=0; $i < count($this_filter['actions']); $i++)
!                       {
!                               // judgement
!                               $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["actions"]['.$i.']["judgement"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['actions'][$i]['judgement'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['actions'][$i]['judgement']);
!                               // folder
!                               $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["actions"]['.$i.']["folder"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['actions'][$i]['folder'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['actions'][$i]['folder']);
!                               // actiontext
!                               $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["actions"]['.$i.']["actiontext"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['actions'][$i]['actiontext'].') which will 
eval $pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['actions'][$i]['actiontext']);
!                               // stop_filtering
!                               if 
(isset($this_filter['actions'][$i]['stop_filtering']))
!                               {
!                                       $pref_struct_str = 
'["filters"]['.$this_filter['filter_num'].']["actions"]['.$i.']["stop_filtering"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: using preferences->add_struct("email", 
$pref_struct_str, '.$this_filter['actions'][$i]['stop_filtering'].') which will 
eval $pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['actions'][$i]['stop_filtering']);
!                               }
!                       }
!                       // SORT THAT ARRAY by key, so the integer array heys go 
from lowest to hightest
!                       
ksort($GLOBALS['phpgw']->preferences->data['email']['filters']);
!                       if ($this->debug_set_prefs > 2) { echo 
'bofilters.process_submitted_data: direct pre-save 
$GLOBALS[phpgw]->preferences->data[email][filters] DUMP:<pre>'; 
print_r($GLOBALS['phpgw']->preferences->data['email']['filters']); echo 
'</pre>'; }
                        
                        // DONE processing prefs, SAVE to the Repository
!                       if ($this->debug_set_prefs > 1) 
                        {
!                               echo 'bofilters.process_submitted_data: *debug* 
at ['.$this->debug_set_prefs.'] so skipping save_repository<br>';
                        }
                        else
                        {
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.process_submitted_data: SAVING REPOSITORY<br>'; }
                                
$GLOBALS['phpgw']->preferences->save_repository();
                        }
                        // end the email session
--- 298,473 ----
                        }
                        if ($this->debug_set_prefs > 2) { echo 
'bofilters.process_submitted_data: $this_filter[] dump <strong><pre>'; 
print_r($this_filter); echo "</pre></strong>\r\n"; }
+                       $this->all_filters[$found_filter_num] = array();
+                       $this->all_filters[$found_filter_num] = $this_filter;
+                       $this->save_all_filters_to_repository();
+               }
+               
+               function squash_all_filters_gap()
+               {
+                       $did_squash = False;
+                       //for ($i=0; $i < count($this->all_filters); $i++)
+                       for ($i=0; $i < 20; $i++)
+                       {
+                               if ((!isset($this->all_filters[$i]))
+                               && (!isset($this->all_filters[$i+1])))
+                               {
+                                       // ok
+                               }
+                               elseif ((isset($this->all_filters[$i]))
+                               && (isset($this->all_filters[$i+1])))
+                               {
+                                       // good
+                               }
+                               elseif ((!isset($this->all_filters[$i]))
+                               && (isset($this->all_filters[$i+1]))
+                               && ($this->filter_exists($i+1)))
+                               {
+                                       $move_me_down = array();
+                                       $move_me_down = 
$this->all_filters[$i+1];
+                                       $this->all_filters[$i] = array();
+                                       $this->all_filters[$i] = $move_me_down;
+                                       $this->all_filters[$i+1] = array();
+                                       unset($this->all_filters[$i+1]);
+                                       $did_squash = True;
+                                       break;
+                               }
+                       }
+                       return $did_squash;
+               }
+               
+               function save_all_filters_to_repository()
+               {
+                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: ENTERING<br>'; }
+                       // KEY SORT so the filters are numbered in acending 
array index order
+                       ksort($this->all_filters);
+                       // SQUASH / COMPACT $this->all_prefs so there are NO 
GAPS
+                       // use a while statement in the future, for now use $i 
loop so we won't loop forever if something goes wrong
+                       for ($i=0; $i < 11; $i++)
+                       {
+                               $did_squash = $this->squash_all_filters_gap();
+                               if ($did_squash == False)
+                               {
+                                       break;
+                               }
+                       }
+                       
+                       // KEY SORT so the filters are numbered in acending 
array index order
+                       ksort($this->all_filters);
                        
                        // now add this filter piece by piece
                        // we can only set a non-array value, but we can use 
array string for the base
                        // but we can grab structures
                        
!                       // first we delete any existing data at the desired 
prefs location
!                       $pref_struct_str = '["filters"]';
!                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->delete_struct("email", $pref_struct_str) which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                       
$GLOBALS['phpgw']->preferences->delete_struct('email',$pref_struct_str);
!                       
!                       for ($filter_idx=0; $filter_idx < 
count($this->all_filters); $filter_idx++)
!                       {
!                               // SAVE TO PREFS DATABASE
!                               // we called begin_request in the constructor, 
so we know the prefs object exists
!                               
!                               $this_filter = $this->all_filters[$filter_idx];
!                               // filters are based at [filters][X] where X is 
the filter_num, based on the [email] top level array tree
!                               
!                               // $this_filter['filtername']   string (will 
require htmlslecialchars_encode and decode
!                               $pref_struct_str = 
'["filters"]['.$filter_idx.']["filtername"]';
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['filtername'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['filtername']);
!                               
!                               // $this_filter['source_accounts']      array
!                               // $this_filter['source_accounts'][X]   array
!                               // $this_filter['source_accounts'][X]['folder'] 
string
!                               // 
$this_filter['source_accounts'][X]['acctnum']        integer
!                               for ($i=0; $i < 
count($this_filter['source_accounts']); $i++)
!                               {
!                                       // folder
!                                       $pref_struct_str = 
'["filters"]['.$filter_idx.']["source_accounts"]['.$i.']["folder"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['source_accounts'][$i]['folder'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['source_accounts'][$i]['folder']);
!                                       // acctnum
!                                       $pref_struct_str = 
'["filters"]['.$filter_idx.']["source_accounts"]['.$i.']["acctnum"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['source_accounts'][$i]['acctnum'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['source_accounts'][$i]['acctnum']);
!                               }
!                               
!                               // $this_filter['matches']      Array
!                               // $this_filter['matches'][X]   Array
!                               // $this_filter['matches'][X]['andor']  UNSET 
for $this_filter['matches'][0], SET for all the rest : and | or | ignore_me
!                               // $this_filter['matches'][X]['examine']        
        known_string : IMAP search keys
!                               // $this_filter['matches'][X]['comparator']     
known_string : contains | notcontains
!                               // $this_filter['matches'][X]['matchthis']      
user_string
!                               for ($i=0; $i < count($this_filter['matches']); 
$i++)
!                               {
!                                       // andor
!                                       if 
(isset($this_filter['matches'][$i]['andor']))
!                                       {
!                                               $pref_struct_str = 
'["filters"]['.$filter_idx.']["matches"]['.$i.']["andor"]';
!                                               if ($this->debug_set_prefs > 1) 
{ echo 'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['matches'][$i]['andor'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['matches'][$i]['andor']);
!                                       }
!                                       // examine
!                                       $pref_struct_str = 
'["filters"]['.$filter_idx.']["matches"]['.$i.']["examine"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['matches'][$i]['examine'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['matches'][$i]['examine']);
!                                       // comparator
!                                       $pref_struct_str = 
'["filters"]['.$filter_idx.']["matches"]['.$i.']["comparator"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['matches'][$i]['comparator'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['matches'][$i]['comparator']);
!                                       // matchthis
!                                       // user_string, may need 
htmlslecialchars_encode decode and/or the user may forget to tnter data here
!                                       if 
((!isset($this_filter['matches'][$i]['matchthis']))
!                                       || 
(trim($this_filter['matches'][$i]['matchthis']) == ''))
!                                       {
!                                               
$this_filter['matches'][$i]['matchthis'] = 'user_string_not_filled_by_user';
!                                       }
!                                       $pref_struct_str = 
'["filters"]['.$filter_idx.']["matches"]['.$i.']["matchthis"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['matches'][$i]['matchthis'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['matches'][$i]['matchthis']);
!                               }
!                               
!                               // $this_filter['actions']      Array
!                               // $this_filter['actions'][X]           Array
!                               // $this_filter['actions'][X]['judgement']      
known_string
!                               // $this_filter['actions'][X]['folder']         
string contains URI style data ex. "&folder=INBOX.Trash&acctnum=0"
!                               // $this_filter['actions'][X]['actiontext']     
user_string
!                               // $this_filter['actions'][X]['stop_filtering'] 
UNSET | SET string "True"
!                               for ($i=0; $i < count($this_filter['actions']); 
$i++)
!                               {
!                                       // judgement
!                                       $pref_struct_str = 
'["filters"]['.$filter_idx.']["actions"]['.$i.']["judgement"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['actions'][$i]['judgement'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['actions'][$i]['judgement']);
!                                       // folder
!                                       $pref_struct_str = 
'["filters"]['.$filter_idx.']["actions"]['.$i.']["folder"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['actions'][$i]['folder'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['actions'][$i]['folder']);
!                                       // actiontext
!                                       $pref_struct_str = 
'["filters"]['.$filter_idx.']["actions"]['.$i.']["actiontext"]';
!                                       if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['actions'][$i]['actiontext'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                       
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['actions'][$i]['actiontext']);
!                                       // stop_filtering
!                                       if 
(isset($this_filter['actions'][$i]['stop_filtering']))
!                                       {
!                                               $pref_struct_str = 
'["filters"]['.$filter_idx.']["actions"]['.$i.']["stop_filtering"]';
!                                               if ($this->debug_set_prefs > 1) 
{ echo 'bofilters.save_all_filters_to_repository: using 
preferences->add_struct("email", $pref_struct_str, 
'.$this_filter['actions'][$i]['stop_filtering'].') which will eval 
$pref_struct_str='.$pref_struct_str.'<br>'; }
!                                               
$GLOBALS['phpgw']->preferences->add_struct('email', $pref_struct_str, 
$this_filter['actions'][$i]['stop_filtering']);
!                                       }
!                               }
!                       }
                        
                        // DONE processing prefs, SAVE to the Repository
!                       if ($this->debug_set_prefs > 3) 
                        {
!                               echo 'bofilters.save_all_filters_to_repository: 
*debug* at ['.$this->debug_set_prefs.'] so skipping save_repository<br>';
                        }
                        else
                        {
!                               if ($this->debug_set_prefs > 2) { echo 
'bofilters.save_all_filters_to_repository: direct pre-save 
$GLOBALS[phpgw]->preferences->data[email][filters] DUMP:<pre>'; 
print_r($GLOBALS['phpgw']->preferences->data['email']['filters']); echo 
'</pre>'; }
!                               if ($this->debug_set_prefs > 1) { echo 
'bofilters.save_all_filters_to_repository: SAVING REPOSITORY<br>'; }
                                
$GLOBALS['phpgw']->preferences->save_repository();
+                               // re-grab data from prefs
+                               
                        }
                        // end the email session
***************
*** 379,420 ****
                                                                                
'menuaction=email.uifilters.filters_list');
                        
!                       if ($this->debug_set_prefs > 0) { echo 
'bofilters.process_submitted_data: almost LEAVING, about to issue a redirect 
to:<br>'.$take_me_to_url.'<br>'; }
                        if ($this->debug_set_prefs > 1) 
                        {
!                               echo 'bofilters.process_submitted_data: 
LEAVING, *debug* at ['.$this->debug_set_prefs.'] so skipping Header redirection 
to: ['.$take_me_to_url.']<br>';
                        }
                        else
                        {
!                               if ($this->debug_set_prefs > 0) { echo 
'bofilters.process_submitted_data: LEAVING with redirect to: 
<br>'.$take_me_to_url.'<br>'; }
                                Header('Location: ' . $take_me_to_url);
                        }
                }
                
!               
!               function read_filter_data_from_prefs()
                {
!                       $this->all_filters = array();
!                       // read sublevel data from prefs
!                       // since we know the constructor called begin_request, 
we know we can get that data here:
!                       if 
((isset($GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters']))
!                       && 
(is_array($GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters']))
!                       && 
(count($GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters']) > 0)
!                       && 
(isset($GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters'][0]['source_accounts'])))
                        {
!                               $this->all_filters = 
$GLOBALS['phpgw']->msg->unprocessed_prefs['email']['filters'];
                        }
!                       return $this->all_filters;
                }
                
                
                
!               function run_single_filter()
                {
                        if ($this->debug > 0) { echo 
'bofilters.run_single_filter: ENTERING<br>'; }
                        if (count($this->all_filters) == 0)
                        {
!                               $this->read_filter_data_from_prefs();
                        }
-                       $filter_num = $this->obtain_filer_num();
                        $filter_exists = $this->filter_exists($filter_num);
                        if (!$filter_exists)
--- 479,543 ----
                                                                                
'menuaction=email.uifilters.filters_list');
                        
!                       if ($this->debug_set_prefs > 0) { echo 
'bofilters.save_all_filters_to_repository: almost LEAVING, about to issue a 
redirect to:<br>'.$take_me_to_url.'<br>'; }
                        if ($this->debug_set_prefs > 1) 
                        {
!                               echo 'bofilters.save_all_filters_to_repository: 
LEAVING, *debug* at ['.$this->debug_set_prefs.'] so skipping Header redirection 
to: ['.$take_me_to_url.']<br>';
                        }
                        else
                        {
!                               if ($this->debug_set_prefs > 0) { echo 
'bofilters.save_all_filters_to_repository: LEAVING with redirect to: 
<br>'.$take_me_to_url.'<br>'; }
                                Header('Location: ' . $take_me_to_url);
                        }
                }
                
!               function delete_filter()
                {
!                       if ($this->debug_set_prefs > 0) { echo 
'bofilters.delete_filter: ENTERING<br>'; }
!                       // FILTER NUMBER
!                       $filter_num = $this->obtain_filer_num();
!                       
!                       if (!$this->filter_exists($filter_num))
                        {
!                               echo 'bofilters.delete_filter: LEAVING with 
ERROR, filter $filter_num ['.serialize($filter_num).'] does not even exist';
!                               return;
                        }
!                       
!                       // by now it's ok to unset the target filter
!                       $this->all_filters[$filter_num] = array();
!                       unset($this->all_filters[$filter_num]);
!                       $this->save_all_filters_to_repository();
!                       if ($this->debug_set_prefs > 0) { echo 
'bofilters.delete_filter: LEAVING<br>'; }
                }
                
                
+               function run_all_filters()
+               {
+                       if ($this->debug > 0) { echo 
'bofilters.run_all_filters: ENTERING<br>'; }
+                       if (count($this->all_filters) == 0)
+                       {
+                               if ($this->debug > 0) { echo 
'bofilters.run_all_filters: LEAVING with ERROR, no filters exist<br>'; }
+                       }
+                       
+                       for ($filter_idx=0; $filter_idx < 
count($this->all_filters); $filter_idx++)
+                       {
+                               // APPLY THIS FILTER
+                               if ($this->debug > 1) { echo 
'bofilters.run_all_filters: calling 
$this->run_single_filter['.$filter_idx.']<br>'; }
+                               $this->run_single_filter[$filter_idx];
+                       }
+                       if ($this->debug > 0) { echo 
'bofilters.run_all_filters: LEAVING<br>'; }
+               }
                
!               function run_single_filter($filter_num='')
                {
                        if ($this->debug > 0) { echo 
'bofilters.run_single_filter: ENTERING<br>'; }
                        if (count($this->all_filters) == 0)
                        {
!                               if ($this->debug > 0) { echo 
'bofilters.run_single_filter: LEAVING with ERROR, no filters exist<br>'; }
!                       }
!                       if ((!isset($filter_num))
!                       || (trim((string)$filter_num) == ''))
!                       {
!                               $filter_num = $this->obtain_filer_num();
                        }
                        $filter_exists = $this->filter_exists($filter_num);
                        if (!$filter_exists)

Index: class.uifilters.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware//email/inc/class.uifilters.inc.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** class.uifilters.inc.php     25 Jan 2002 13:28:25 -0000      1.5
--- class.uifilters.inc.php     26 Jan 2002 07:55:52 -0000      1.6
***************
*** 19,37 ****
                        'filters_edit' => True
                );
!               var $bo;                
                var $debug = 0;
  
                function uifilters()
                {
!                       
!               }
!               
!               function filters_list()
!               {                       
!                       // FUTURE
!                       // for now, pass off to edit so we at leadt show 
something
!                       if ($this->debug > 0) { echo 'uifilters.filters_list: 
function not coded yet, pass off to $this->filters_edit()<br>'."\r\n"; }
!                       $this->filters_edit();
!                       
                }
                
--- 19,33 ----
                        'filters_edit' => True
                );
!               var $bo;
!               var $theme;
!               var $nextmatchs;
                var $debug = 0;
  
                function uifilters()
                {
!                       $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
!                       $this->theme = $GLOBALS['phpgw_info']['theme'];
!                       // make the filters object
!                       $this->bo = CreateObject("email.bofilters");
                }
                
***************
*** 97,102 ****
                        
                        
-                       // make the filters object
-                       $this->bo = CreateObject("email.bofilters");
                        // get all filters
                        $this->bo->read_filter_data_from_prefs();
--- 93,96 ----
***************
*** 156,160 ****
                        else
                        {
!                               $filter_name_box_value = 'Filter '.$filter_num;
                        }
                        
--- 150,155 ----
                        else
                        {
!                               //$filter_name_box_value = 'Filter 
'.$filter_num;
!                               $filter_name_box_value = 'My Mail Filter';
                        }
                        
***************
*** 412,419 ****
                        
$GLOBALS['phpgw']->template->set_var('form_cancel_action',$form_cancel_action);
                        
!                       
$GLOBALS['phpgw']->template->set_var('body_bg_color',$GLOBALS['phpgw_info']['theme']['bg_color']);
!                       
$GLOBALS['phpgw']->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']);
!                       
$GLOBALS['phpgw']->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
!                       
$GLOBALS['phpgw']->template->set_var('row_text',$GLOBALS['phpgw_info']['theme']['row_text']);
                        
                        
--- 407,414 ----
                        
$GLOBALS['phpgw']->template->set_var('form_cancel_action',$form_cancel_action);
                        
!                       
$GLOBALS['phpgw']->template->set_var('body_bg_color',$this->theme['bg_color']);
!                       
$GLOBALS['phpgw']->template->set_var('row_on',$this->theme['row_on']);
!                       
$GLOBALS['phpgw']->template->set_var('row_off',$this->theme['row_off']);
!                       
$GLOBALS['phpgw']->template->set_var('row_text',$this->theme['row_text']);
                        
                        
***************
*** 440,443 ****
--- 435,441 ----
                        
$GLOBALS['phpgw']->template->set_var('V_mlist_html',$mlist_html);
                        
+                       
$GLOBALS['phpgw']->template->pparse('out','T_filters_out');
+                       
+                       $GLOBALS['phpgw']->msg->end_request();
                        
                        // GENERAL INFO
***************
*** 488,497 ****
                        echo 'SE_NOPREFETCH: 
['.(string)SE_NOPREFETCH.']<br>'."\r\n";
                        */
                        
!                       
$GLOBALS['phpgw']->template->pparse('out','T_filters_out');
                        
!                       $GLOBALS['phpgw']->msg->end_request();
!               
                }
        }
  ?>
--- 486,598 ----
                        echo 'SE_NOPREFETCH: 
['.(string)SE_NOPREFETCH.']<br>'."\r\n";
                        */
+               }
+               
+               
+               function filters_list()
+               {
+                       unset($GLOBALS['phpgw_info']['flags']['noheader']);
+                       unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
+                       $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
+                       $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
+                       $GLOBALS['phpgw']->common->phpgw_header();
                        
!                       $GLOBALS['phpgw']->template->set_file(
!                               Array(
!                                       'T_filters_list'        => 
'filters_list.tpl'
!                               )
!                       );
!                       
$GLOBALS['phpgw']->template->set_block('T_filters_list','B_filter_list_row','V_filter_list_row');
                        
!                       $var = Array(
!                               'pref_errors'           => '',
!                               'font'                          => 
$this->theme['font'],
!                               'tr_titles_color'       => 
$this->theme['th_bg'],
!                               'page_title'            => lang('E-Mail INBOX 
Filters List'),
!                               'filter_name_header' => lang('Filter [number] 
and Name'),
!                               'lang_move_up'          => lang('Move Up'),
!                               'lang_move_down'                => lang('Move 
Down'),
!                               'lang_edit'                     => lang('Edit'),
!                               'lang_delete'           => lang('Delete')
!                       );
!                       $GLOBALS['phpgw']->template->set_var($var);
!                       
!                       $filters_list = array();
!                       // get all filters
!                       $filters_list = 
$this->bo->read_filter_data_from_prefs();
!                       
!                       
!                       if ($this->debug > 2) { echo 
'email.uifilters.filters_list: $filters_list dump<pre>'; 
print_r($filters_list); echo '</pre>'; }
!                       
!                       $tr_color = $this->theme['row_off'];
!                       $loops = count($filters_list);
!                       if ($loops == 0)
!                       {
!                               $nothing = '&nbsp;';
!                               $tr_color = 
$this->nextmatchs->alternate_row_color($tr_color);
!                               
$GLOBALS['phpgw']->template->set_var('tr_color',$tr_color);
!                               
$GLOBALS['phpgw']->template->set_var('filter_identity',$nothing);
!                               
$GLOBALS['phpgw']->template->set_var('move_up_href',$nothing);
!                               
$GLOBALS['phpgw']->template->set_var('move_down_href',$nothing);
!                               
$GLOBALS['phpgw']->template->set_var('edit_href',$nothing);
!                               
$GLOBALS['phpgw']->template->set_var('delete_href',$nothing);
!                               
$GLOBALS['phpgw']->template->parse('V_filter_list_row','B_filter_list_row');
!                       }
!                       else
!                       {
!                               for($i=0; $i < $loops; $i++)
!                               {
!                                       // add extra display and handling data
!                                       $filters_list[$i]['display_string'] = 
'['.$i.'] '.$filters_list[$i]['filtername'];
!                                       $tr_color = 
$this->nextmatchs->alternate_row_color($tr_color);
!                                       
!                                       $filters_list[$i]['edit_url'] = 
$GLOBALS['phpgw']->link(
!                                                                       
'/index.php',
!                                                                        
'menuaction=email.uifilters.filters_edit'
!                                                                       
.'&filter_num='.$i);
!                                       $filters_list[$i]['edit_href'] = '<a 
href="'.$filters_list[$i]['edit_url'].'">'.lang('Edit').'</a>';
!                                       
!                                       $filters_list[$i]['delete_url'] = 
$GLOBALS['phpgw']->link(
!                                                                       
'/index.php',
!                                                                        
'menuaction=email.bofilters.delete_filter'
!                                                                       
.'&filter_num='.$i);
!                                       $filters_list[$i]['delete_href'] = '<a 
href="'.$filters_list[$i]['delete_url'].'">'.lang('Delete').'</a>';
!                                       
!                                       
$GLOBALS['phpgw']->template->set_var('tr_color',$tr_color);
!                                       
$GLOBALS['phpgw']->template->set_var('filter_identity',$filters_list[$i]['display_string']);
!                                       
$GLOBALS['phpgw']->template->set_var('move_up_href',$filters_list[$i]['move_up_href']);
!                                       
$GLOBALS['phpgw']->template->set_var('move_down_href',$filters_list[$i]['move_down_href']);
!                                       
$GLOBALS['phpgw']->template->set_var('edit_href',$filters_list[$i]['edit_href']);
!                                       
$GLOBALS['phpgw']->template->set_var('delete_href',$filters_list[$i]['delete_href']);
!                                       
$GLOBALS['phpgw']->template->parse('V_filter_list_row','B_filter_list_row', 
True);
!                               }
!                       }
!                       $add_new_filter_url = $GLOBALS['phpgw']->link(
!                                                                       
'/index.php',
!                                                                        
'menuaction=email.uifilters.filters_edit'
!                                                                       
.'&filter_num='.$this->bo->add_new_filter_token);
!                       $add_new_filter_href = '<a 
href="'.$add_new_filter_url.'">'.lang('New Filter').'</a>';
!                       
$GLOBALS['phpgw']->template->set_var('add_new_filter_href',$add_new_filter_href);
!                       
!                       $done_url = $GLOBALS['phpgw']->link(
!                                                                       
'/preferences/index.php');
!                       $done_href = '<a 
href="'.$done_url.'">'.lang('Done').'</a>';
!                       
$GLOBALS['phpgw']->template->set_var('done_href',$done_href);
!                       
!                       // TEST AND APPLY LINKS
!                       $run_all_filters_url = $GLOBALS['phpgw']->link(
!                                                                       
'/index.php',
!                                                                        
'menuaction=email.bofilters.run_all_filters');
!                       $run_all_filters_href = '<a 
href="'.$run_all_filters_url.'">'.lang('Run ALL Filters').'</a>';
!                       
$GLOBALS['phpgw']->template->set_var('run_all_filters_href',$run_all_filters_href);
!                       
!                       $test_all_filters_url = 
$run_all_filters_url.'&filter_test=1';
!                       $test_all_filters_href = '<a 
href="'.$test_all_filters_url.'">Test Run All Filters</a>';
!                       
$GLOBALS['phpgw']->template->set_var('test_all_filters_href',$test_all_filters_href);
!                       
!                       // output the template
!                       
$GLOBALS['phpgw']->template->pfp('out','T_filters_list');
                }
+               
+               
        }
  ?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]