<?

/**
 * display.mod.php
 * @package   Modules
 */

/**
 * Name of this module
 */
define("MOD_DISPLAY",$name);
/**
 * Optionname Show
 */
define("SHOW",0);
/**
 * Optionname Redirect
 */
define("REDIRECT",1);
/**
 * Optionname Showblank
 */
define("SHOWBLANK",2);

$modules[$name]= new DisplayModule();

/**
 * DisplayModule
 *
 * This is the defaultmodule for buffering all output and displaying it at
 * one of the highest runlevels.
 * @package   Modules
 * @author    Herman Suijs
 */

class DisplayModule extends Module {
  var 
$name "DisplayModule";
  var 
$id MOD_DISPLAY;
  var 
$dont_show = array();
  var 
$execlevel 25;
  
//var $messages = array();

  /**
   * Constructor
   *
   * Set options, start buffering output and call the superConstructor<br>
   * Start buffering output. This makes it possible to use header() and
   * cookie-headers even if output was already created. Output is
   * buffered, while header actions are performed immediately
   */
  
function DisplayModule() {
    
ob_start();
    
$this->options[SHOW] = new Option("display_view:display_show");
    
$this->options[REDIRECT] = new Option("redirect:sent:send:return_url_link");
    
$this->options[SHOWBLANK] = new Option("printblank:showblank:print_blank_fields");
    
$this->Module();
  } 
/* function DisplayModule() */

  // Extend so it can use a translation function. For this the message need
  // to be handed with the variables seperated e.g. ($message, $var1, $var2, ...)

  // Integrate the variables with the message.
  // m is short for message
  /*
  function integrate($m,$vars,$color=VARIABLE_COLOR) {
    if (is_array($color)) {
      $ndx = 1;
      while (list(,$use_color) = each($color)) {
    $m = ereg_replace("(\%$ndx)","<font color=$use_color>\\1</font>",$m);
    ++$ndx;
      }
    } else {
      $m = ereg_replace("(\%.)","<font color=$color>\\1</font>",$m);
    }
    // This while loop is copied from the phpgw translate function and
    // extended
    $ndx = 1;
    while ( list($key,$val) = each( $vars ) ) {
      // Make %s and %d substitution possible
      $m = preg_replace( "/%$ndx/", $val, $m );
      ++$ndx;
    }
    return $m;
  }
  */

  /**
   * En-/disable
   *
   * This module is not to be disabled
   */
  
function enable($bool) {
    
$this->enabled=true;
  } 
/* function enable($bool) */

  /**
   * Disable
   *
   * This module is not to be disabled
   */
  
function disable() {
    
$this->enabled=true;
  } 
/* function disable() */

  // This function handles displaying debug-messages because of other
  // output.
  /*
  function message_action($message, $header="") {
    print "<h3>$header</h3>\n";
    if (is_array($message)) {
      print "<p><li>" . join("\n<li>", $message);
    }
    else {
      print "\n<li>$message";
    }
    print "\n<p>";
  }

  // The function to show everything else
  function show($message, $v1="", $v2="", $v3="", $v4="", $v5="") {
    //printf("\n" . $message,$v1,$v2,$v3,$v4,$v5); // Change in sprintf ?
    $vars= array($v1,$v2,$v3,$v4,$v5);
    $colors = array("red","green");
    $this->messages[]=$this->integrate("$message",$vars,$colors) . "<br>";
  }

  function show($message, $v1="", $v2="", $v3="", $v4="", $v5="", $v6="", $v7="", $v8="", $v9="") {
    $vars = array($v1,$v2,$v3,$v4,$v5,$v6,,$v7,$v8,$v9);
    print $this->translate("$message",$vars);
  }

  */

  /**
   * Before action
   *
   * Check the options
   */
  
function before_action() {
    
$this->check_options();
  } 
/* function before_action() */

  /**
   * Do action
   *
   * Put Error or Succes output on the screen and call the DebugMessage to
   * display Debug-messages if necessary. Eventually stop buffering output.
   */
  
function do_action() {
    global 
$error,$debug,$formHandler;
    
$this->action();
    
//echo fh_serialize($error->is_enabled());
    
if ($error->is_enabled()) {
      
$error->display();
      
//$debug->display();
      //print $formHandler->get_content(ERROR_CONTENT,true);
    
} else { /* if ($error->is_enabled()) */
      
$formHandler->set_html(true,DISPLAY_CONTENT);
      print 
$formHandler->get_content(DISPLAY_CONTENT,true);
      
// This needs to be done in the wrapup to catch all debug messages
      //$debug->display();

      // Redirect if set
      
if (isset($this->options[REDIRECT])) {
    if (
$debug->is_enabled()||$debug->noop()) {
      print(
"Location: "$this->options[REDIRECT]->value);
    } 
/* if ($debug->is_enabled()||$deb... */
    
else {
      
header("Location: "$this->options[REDIRECT]->value);
      return 
false;
    } 
/* else */
      
/* if (isset($this->options[REDIR... */

   
/* if ($error->is_enabled()) { ..... */

    /*
    reset($this->messages);
    while (list(,$message) = each($this->messages)) {
      print $message;
    }
    */

    
ob_end_flush();

   } 
/* if ($error->is_enabled()) { ..... */

  /**
   * After action
   *
   * Cleanup
   */
  
function after_action() {
    
ob_end_clean();
    
$this->clean_up();
  } 
/* function after_action() */

/* if ($error->is_enabled()) { ..... */