* @copyright 2004-2007 The SquirrelMail Project Team, Alexandros Vellis * @package plugins * @subpackage avelsieve */ /** * Global HTML Output functions. These contain functions for starting/ending * sections, helper functions for determining and printing HTML snippets, * as well as header/footer thingies. */ class avelsieve_html { /** * @var int Level of Javascript support */ var $js = 0; /** * @param boolean Flag for image usage */ var $useimages = true; /** * Constructor function will initialize some variables, depending on the * environment. */ function avelsieve_html() { global $plugins, $javascript_on, $useimages; if($javascript_on) { $this->js++; if(in_array('javascript_libs', $plugins)) { $this->js++; } } $this->useimages = $useimages; $this->baseuri = sqm_baseuri(); $this->imageuri = $this->baseuri . 'plugins/avelsieve/images/'; $this->iconuri = $this->baseuri . 'plugins/avelsieve/images/icons/'; } /** * Page Header */ function header($customtitle = '') { $out = '

'._("Server-Side Mail Filtering"); if($customtitle) { $out .= ' - '.$customtitle; } $out .= '

'; return $out; } function my_header() { global $color; return '
'. '
' . _("Server-Side Mail Filtering"). '
'. '
'; } /** * Squirrelmail-style table header * @return string */ function table_header($customtitle) { global $color; $out = "\n
". '
'. _("Server-Side Mail Filtering") . ( !empty($customtitle) ? ' - '.$customtitle : '' ) . '
'; return $out; } /** * Squirrelmail-style table footer * @return string */ function table_footer() { return '
'. '
'; } /** * All sections table start * @return string */ function all_sections_start() { return ''; } /** * All sections table end * @return string */ function all_sections_end() { return '
'; } /** * Table 'section' start * @return string */ function section_start($title = '') { global $color; if(empty($title)) { return "\n". ''; } else { return "\n". ''. ''.$title.''. ''; } } /** * Table 'section' end * @return string */ function section_end() { global $color; $out = "\n". " \n"; return $out; } /** * Generic Listbox widget * * @param $selected_header Selected header * @param $n option number */ function generic_listbox($name, $options, $selected_option = '') { $out = ''; return $out; } /** * Explicitly set Error Messages that might have occured from an external * source. * * Inside the classes themselves, I use * $this->errmsg[] = 'Message' ... * * @param array $array * @return void */ function set_errmsg($array) { $this->errmsg = array_merge($this->errmsg, $array); } /** * Access the messages queue from session variables, and return what should * be displayed in the end to the user. * * @todo Implement a proper message queue. * @return array */ function retrieve_avelsieve_messages() { global $color; $out = ''; $msgs = array(); if(isset($_SESSION['comm'])) { $comm = $_SESSION['comm']; $out .= '

'. ($this->useimages == true? '(OK) ' : ''); if (isset($comm['raw'])) { $out .= $comm['raw']; } elseif(isset($comm['new'])) { $out .= _("Successfully added new rule."); } elseif (isset($comm['edited'])) { $out .= sprintf( _("Successfully updated rule #%s"), $comm['edited']+1); } elseif (isset($comm['deleted'])) { if(is_array($comm['deleted'])) { $deletedRulesNumbers = ''; for ($i=0; $ijs == 0) { $js = 0; } elseif(empty($js)) { $js = $this->js; } if(empty($imageChange)) $imageChange = $this->useimages; if($js == 2) { /* Scriptaculous */ if($imageChange) { return 'AVELSIEVE.edit.toggleShowDivWithImg(\''.$divname.'\', 1);'; } else { return 'Effect.toggle(\''.$divname.'\', \'slide\');'; } } elseif($js == 1) { /* Simple javascript */ if($imageChange) { return 'AVELSIEVE.edit.toggleShowDivWithImg(\''.$divname.'\');'; } else { return 'AVELSIEVE.edit.toggleShowDiv(\''.$divname.'\');'; } } } /** * Print formatted error message(s), if they exist. * * @return string */ function print_errmsg() { $out = ''; if(!empty($this->errmsg)) { global $color; $out .= $this->section_start( _("Error Encountered:") ). '

'; if(is_array($this->errmsg)) { $out .= ''; } else { $out .= '

'.$this->errmsg .'

'; } $out .= '

'. _("You must correct the above errors before continuing."). '

'; $out .= '
' . $this->section_end(); } return $out; } /** * Helper function: Find if the option $optname is on, in the current rule. * (Checks if $this->rule[$optname] evaluates to true). * * @param string $optname * @return boolean */ function determineState($optname) { if(!isset($this->rule[$optname])) { return false; } if($this->rule[$optname] == 0) { return false; } if($this->rule[$optname] || $this->rule[$optname] == 'on' || $this->rule[$optname] == true) { return true; } return false; } /** * Returns the checked state for a checkbox that corresponds to option * $optname. (Helper function). * * @param string $optname * @return string */ function stateCheckbox($optname) { if($this->determineState($optname) === true) { return 'checked="" '; } else { return ''; } } /** * Returns the visibility state for a div that corresponds to more options * under the "top" option $optname. (Helper function). * * @param string $optname * @return string */ function stateVisibility($optname) { if($this->determineState($optname) === true) { return ''; } else { return ' style="display:none;" '; } } }