* @copyright 2004-2007 The SquirrelMail Project Team, Alexandros Vellis * @package plugins * @subpackage avelsieve */ /** Includes */ include_once(SM_PATH . 'plugins/avelsieve/include/html_main.inc.php'); /** * HTML Output functions for rule editing / adding */ class avelsieve_html_rules extends avelsieve_html { /** * @param array SIEVE Rules that are to be printed. */ var $rules = array(); /** * @param string Display mode: 'verbose','terse','source' or 'debug' */ var $mode = 'terse'; /** * Constructor function, that initializes the environment for proper * displaying of the rules table. * * @return void */ function avelsieve_html_rules(&$rules, $mode = 'terse') { global $avelsieve_maintypes, $scriptHints; $this->avelsieve_html(); $this->rules = $rules; $this->mode = $mode; // These UI "hints" are initialized and discovered in the table.php script. if(isset($scriptHints)) { $this->scriptHints = $scriptHints; } } /** * "Create new rules" text, for when no rules exist. * @return string */ function rules_create_new() { return '

'. _("Here you can add or delete filtering rules for your email account. These filters will always apply to your incoming mail, wherever you check your email."). '

' . '

' . _("You don't have any rules yet. Feel free to add any with the button "Add a New Rule". When you are done, please select "Save Changes" to get back to the main options screen.") . "

"; } /** * Introductory text. * @return string */ function rules_blurb() { global $color, $conservative, $scriptinfo; $out = ''; if(sizeof($this->rules) < 3) { $out = "

"._("Here you can add or delete filtering rules for your email account. These filters will always apply to your incoming mail, wherever you check your email.")."

"; } if($conservative) { $out .= "

"._("When you are done with editing, remember to select "Save Changes" to activate your changes!")."

"; } $out .= $this->rules_confirmation_text(); if(isset($scriptinfo['created'])) { $out .= $this->scriptinfo($scriptinfo); } $out .= $this->scripthints(); // Removed ATM $dummy = "

"._("The following table summarizes your current mail filtering rules.")."

"; return $out; } /** * Output UI-friendly script "hints": * 1) "inconsistent" folders: a folder is mentioned in "fileinto", but the * actual folder does not exist. * 2) warning that vacation rule is active. (so that the user will not forget * to disable it when she comes from vacation). * * @return string */ function scripthints() { global $color; $out = ''; // 1) inconsistent folders / fileinto if(!empty($this->scriptHints['inconsistent_folders'])) { $out .= '

' . ($this->useimages ? '(!)'. ' ' : '' ) . _("Warning: In your rules, you have defined an action that refers to a folder that does not exist or a folder where you do not have permission to append to.") . '

'; } // 2) vacation rule is active if(!empty($this->scriptHints['vacation_rules'])) { $fnum = $this->scriptHints['vacation_rules'][0]; // First rule number $out .= '

' . ($this->useimages ? '(i)'. ' ' : '' ) . sprintf( _("Note: A Vacation Autoresponder is active (Rule #%s in your current Mail Filtering Rules).
Don't forget to disable it or delete it when you are back."), 'edit.php?edit='.$fnum, '#rule_row_'.$fnum, $fnum+1) . '

'; } return $out; } /** * Rules Table Header + 1st row, which is the heading * @return string */ function rules_table_header() { global $color, $displaymodes; $out = ' '. ''. "\n"; return $out; } /** * Returns the 'communication' aka 'comm' string from the previous screen, * for instance edit.php. * @return string */ function rules_confirmation_text() { $out = $this->retrieve_avelsieve_messages(); unset($_SESSION['comm']); return $out; } /** * Footer * @return string */ function rules_table_footer() { return '
'; $out .= _("No") . ''. _("Options").''. _("Description of Rule"). ' (' . _("Display as:"); foreach($displaymodes as $id=>$info) { if($this->mode == $id) { $out .= ' '.$info[0].''; } else { $out .= ' '.$info[0].''; } } $out .= ')'. ''. _("Position") .'
'; } /** * Searches the available rules in a script for the rules that are of "unique" * type. E.g. whitelist, Junk Mail. * * @todo Probably a duplicate-rule supression / notification could be handy. * However, it will do no major harm to leave this without one. * * @todo This is a good place to do the suggesting of rule placement. * * @return array Key: the rule number, Value: the rule position. */ function discoverUniqueRules() { global $avelsieve_enable_rules, $avelsieve_maintypes; $ret = array(); foreach($avelsieve_maintypes as $no=>$info) { if($info['unique']) { for($i=0; $irules); $i++) { if(isset($this->rules[$i]['type']) && $this->rules[$i]['type'] == $no) { $ret[$no] = $i; continue 2; } } } } } /** * Submit Links / Buttons for adding new rules and edit screens. * * @param boolean $horizontal * @return string */ function button_addnewrule($horizontal = false) { global $avelsieve_enable_rules, $avelsieve_maintypes; if($horizontal) { $links_delimiter = ' | '; } else { $links_delimiter = '
'; } $out = ' '. ($this->useimages == true ? '[] ' : '') . '' . _("Add a new Rule") . ''; if(!empty($avelsieve_enable_rules)) { $uniqueRulesPositions = $this->discoverUniqueRules(); foreach($avelsieve_enable_rules as $r) { if(!isset($avelsieve_maintypes[$r]['linktext'])) continue; if($r == 12 && isset($uniqueRulesPositions[12])) { // Global whitelist special: edit existing whitelist $href = 'edit.php?edit='.$uniqueRulesPositions[12].'&type='.$r; } else { $href = 'edit.php?addnew=1&type='.$r; } $out .= $links_delimiter . ''. ($this->useimages == true ? '[] ' : '') . '' . $avelsieve_maintypes[$r]['linktext'] . ''; } } $null = null; $out .= concat_hook_function('avelsieve_rulestable_buttons', $null); return $out; } /** * Submit button for deleting selected rules * @return string */ function button_deleteselected() { return ''; } /** * Submit button for enabling selected rules * @return string */ function button_enableselected() { return ''; } /** * Submit button for disabling selected rules * @return string */ function button_disableselected() { return ''; } function rules_footer() { global $conservative; $out = ''; if($conservative) { $out = '

'. _("When you are done, please click the button below to return to your webmail."). '

'; } return $out; } /** * Output link for corresponding rule function (such as edit, delete, move). * * @param string $name * @param int $i * @param string $url Which page to link to * @param string $xtra Extra stuff to be passed to URL * @param array $attribs Additional attributes for element. * @param boolean $showText Show the relevant Text alongside * @return string */ function toolicon ($name, $i, $url = "table.php", $xtra = "", $attribs=array(), $showText = false) { global $imagetheme, $location, $avelsievetools; $desc = $avelsievetools[$name]['desc']; $img = $avelsievetools[$name]['img']; $out = ' 0) { foreach($attribs as $key=>$val) { $out .= ' '.$key.'="'.$val.'"'; } } $out .= '>'; if($this->useimages) { $out .= ''.$desc.''; if($showText) { $out .= ' '.$desc; } } else { $out .= $desc; } $out .= ''; return $out; } /** * Output script information (last modification date etc.) * @param array $scriptinfo * @return string * @todo Move these to a different page, so that it will not clutter the * main table screen. */ function scriptinfo($scriptinfo) { $out = ''; if(function_exists('getLongDateString')) { sq_bindtextdomain('squirrelmail', SM_PATH . 'locale'); textdomain('squirrelmail'); $cr = getLongDateString($scriptinfo['created']); $mo = getLongDateString($scriptinfo['modified']); sq_bindtextdomain ('avelsieve', SM_PATH . 'plugins/avelsieve/locale'); textdomain ('avelsieve'); // $out = '

'. _("Last modified:").' '.$mo.'

'; /* $out = '

'._("Created:").' '.$cr.'.
'. _("Last modified:").' '.$mo.'

'; */ } else { /* Pretty useless information to be displayed every time */ $dummy = _("Created:"); /* $out = '

'._("Created:").' '. date("Y-m-d H:i:s",$scriptinfo['created']).'. '. */ $dummy = _("Last modified:"); // ' '. //date("Y-m-d H:i:s",$scriptinfo['modified']).'

'; } if(AVELSIEVE_DEBUG > 0) { global $avelsieve_version; $out .= '

Versioning Information:

' . ''; } return $out; } /** * */ function rules_confirmation() { global $color; $out = $this->table_header( _("Current Mail Filtering Rules") ). $this->all_sections_start(). $this->rules_confirmation_text(). $this->all_sections_end(). '
'; $this->table_footer(); return $out; } /** * Main function to output a whole table of SIEVE rules. * @return string */ function rules_table() { global $color, $avelsieve_maintypes; $null = null; // For plugin hooks and PHP4/5 compatibility $out = '
'. ''. ""; if(empty($this->rules)) { $out .= $this->table_header(_("No Filtering Rules Defined Yet")). $this->all_sections_start(). ''. $this->rules_create_new(). $this->button_addnewrule(). $this->rules_footer(). ''. $this->all_sections_end() . $this->table_footer(). '
'; return $out; } $out .= // $this->all_sections_start(). $this->table_header( _("Current Mail Filtering Rules") ). '

'. $this->button_addnewrule(true) . '

'. // ''. $this->rules_blurb(). $this->rules_table_header(); // ''; $toggle = false; for ($i=0; $irules); $i++) { $bgcolor = ($toggle? $color[12] : $color[4]); $out .="\n" . ''. ''.($i+1).''; /* === Column:: Checkbox === */ $out .= ''. 'js ? 'onclick="if(this.checked) { document.getElementById(\'rule_row_'.$i.'\').style.backgroundColor = \''.$color[16].'\'; } else { document.getElementById(\'rule_row_'.$i.'\').style.backgroundColor = \''.$bgcolor.'\'; }; return true; " ' : '' ) . ' />'; /* === Column:: Controls (Edit/ Delete), Buttons === */ $out .= ''; /* 1) Important controls: Edit, Move Up, Move Down, Delete */ /* Edit */ if($this->rules[$i]['type'] < 100) { $out .= $this->toolicon('edit', $i, 'edit.php', "type=".$this->rules[$i]['type'],array(),true); } else { $args = do_hook('avelsieve_edit_link', $null); $out .= $this->toolicon('edit', $i, $args[0], $args[1]); unset($args); } /* Delete */ if(!$avelsieve_maintypes[$this->rules[$i]['type']]['undeletable']) { $out .= '
'.$this->toolicon("rm", $i, "table.php", "", array('onclick'=>'return confirm(\''._("Really delete this rule?").'\')'), true); } /* Duplicate */ /* if($this->rules[$i]['type'] < 100) { $out .= $this->toolicon('dup', $i, "edit.php", "type=".$this->rules[$i]['type']."&dup=1"); } else { $args = do_hook('avelsieve_duplicate_link', $null); $out .= $this->toolicon('dup', $i, $args[0], $args[1]); unset($args); } */ if($this->js) { $out .= '
'; $out .= ''; } $out .= '
js ? ' style="display:none"' : '' ) . '>'; $out .= ''. '
'; // Future functionality: $dummy = ''; if(!$this->js) { $out .= ''; } $out .= ''; /* Column:: Rule description */ $out .= ''. makesinglerule($this->rules[$i], $this->mode) .''; /* Column:: Movement controls */ $out .= ''. ($i != 0 ? $this->toolicon("mvup", $i, "table.php", "") : ' '). ($i != sizeof($this->rules)-1 ? $this->toolicon("mvdn", $i, "table.php", "") : ' '). "\n"; if(!$toggle) { $toggle = true; } elseif($toggle) { $toggle = false; } } $out .=''. '
'. _("Action for Selected Rules:") . '
' . $this->button_enableselected(). $this->button_disableselected(). '
' . $this->button_deleteselected(). '
' . '
'. $this->button_addnewrule(). '
'. ''. $this->rules_footer(). $this->all_sections_end() . $this->table_footer(). ''; return $out; } }