<? 

include_once(INCLUDE_DIR."/modulebase.inc.php");

define("CONTENT_SEP","\n");

define("INC_CONTENT","content"); // ClassName

/**
 * Content object
 *
 * This object is dynamically created within the form-handler. It can be
 * used and dynamically changed to produce plain text or HTML output to be
 * used for mails or screen output (e.g. regular display or error).
 *
 * @package   Include
 * @author    Herman Suijs
 */
class Content extends ModuleBase {
  var 
$name "IncludeContent";
  var 
$id INC_CONTENT;
  
//var $vars = array();
  
var $text ""// Content
  
var $html false;
  var 
$title TITLE;
  var 
$header CONTENT_HEADER;
  var 
$footer CONTENT_FOOTER;
  var 
$title_changed false;
  var 
$header_changed false// implement if changed
  
var $footer_changed false;
  
//var $final = false;
  
var $isset false;

  
/**
   * Constructor
   */
  
function Content($name,$text="",$html=false) {
    
$this->name .= " ".$name;
    
//$this->text = $text;
    
if (!empty($text)) {
      
$this->set_content($text);
    } 
/* if (!empty($text)) */
    
$this->set_html($html);
    
$this->ModuleBase();
  } 
/* function Content($name,$text="... */

  /**
   * Set content to HTML
   */
  
function set_html($switch=true) {
    global 
$debug;
    
$this->html $switch;
    if (
$this->header_changed||$this->footer_changed) {
      
$debug->add(2,$this->name." set_html","Changed header or footer not discarded");
    } else { 
/* if ($this->header_changed||$th... */
      
if ($this->html) {
    
$this->header = (!$this->header_changed) ? CONTENT_HEADER_HTML $this->header;
    
$this->footer = (!$this->footer_changed) ? CONTENT_FOOTER_HTML $this->footer;
      } else { 
/* if ($this->html) */
    
$this->header = (!$this->header_changed) ? CONTENT_HEADER $this->header;
    
$this->footer = (!$this->footer_changed) ? CONTENT_FOOTER $this->footer;
   
/* if ($this->html) { ... } else */      }
   
/* if ($this->header_changed||$th... */  }
    
$title $this->title;
    
$this->title TITLE;
    if (
$this->title_changed) {
      
$this->set_title($title);
    } 
/* if ($this->title_changed) */
  
/* function set_html($switch=true... */

  /**
   * Convert content
   *
   * Create content based on variables
   */
  
function convert_content($vars) {
    global 
$formHandler,$debug;
    
$this->text "";
    if  (
$this->html) {
      while (list(
$name,$value) = each($vars)) {
    
$this->text .= $formHandler->translate(DEFAULT_VAR_HTMLCONTENT,$name,$value);
    
$this->text ereg_replace("\n","<br>",$this->text);
    
//$this->text .= sprintf("<li>%s: %s\n",$name,$value);
      
/* while (list($name,$value) = ea... */
    
} else { /* if  ($this->html) */
      
while (list($name,$value) = each($vars)) {
    
$this->text .= $formHandler->translate(DEFAULT_VAR_CONTENT,$name,$value);
      } 
/* while (list($name,$value) = ea... */
   /* if  ($this->html) { ... } else */    
}
    
$debug->add(DB_XFLOW,$this->name,"Content converted");
  } 
/* function convert_content($vars... */

  /**
   * Set content
   *
   * Store new content text
   */
  
function set_content($new_content) {
    global 
$error,$debug;
    if (empty(
$new_content)) {
      
$error->add(1,$this->name,"Empty content, nothing set");
      return 
false;
    } 
/* if (empty($new_content)) */
    
$this->text $new_content;
    
$debug->add(6,$this->name,"New content set");
    
$this->isset true;
    return 
true;
  } 
/* function set_content($new_cont... */

  /**
   * Add text to content
   */
  
function addto_content($add_content) {
    
$this->text .= $add_content;
  } 
/* function addto_content($add_co... */

  /**
   * Insert content
   *
   * Append text to content
   */
  
function insert_content($ins_content) {
    
$this->text $ins_content $this->content;
  } 
/* function insert_content($ins_c... */

  /**
   * Get content text
   */
  
function get_content($final=false,$vars="") {
    global 
$formHandler;
    if (
$final) {
      if (empty(
$this->text)) {
    if (
$vars=="") {
      
$vars $formHandler->get_vars(SHOW_VARS);
    } 
/* if ($vars=="") */
    
$this->convert_content($vars);
      } 
/* if (empty($this->text)) */
      
$content $this->header CONTENT_SEP $this->text CONTENT_SEP .  $this->footer;
    } else { 
/* if ($final) */
      
$content $this->text;
   
/* if ($final) { ... } else */ }
    return 
$content;
  } 
/* function get_content($final=fa... */

  /**
   * Set header
   */
  
function set_header($header) {
    global 
$debug;
    
$debug->add(DB_XFLOW,$this->name,"Set header to %s",$header);
    
$this->header $header;
    
$this->header_changed true;
  } 
/* function set_header($header) */

  /**
   * Set footer
   */
  
function set_footer($footer) {
    global 
$debug;
    
$debug->add(DB_XFLOW,$this->name,"Set footer to %s",$footer);
    
$this->footer $footer;
    
$this->footer_changed true;
  } 
/* function set_footer($footer) */

  /**
   * Set title
   */
  
function set_title($title) {
    
$this->header ereg_replace($this->title,$title,$this->header);
    
$this->title $title;
    
$this->title_changed true;
  } 
/* function set_title($title) */

  /**
   * Set title default
   */
  
function set_title_default() {
    global 
$debug;
    
$this->title TITLE;
    
$this->title_changed false;
    if (
$this->html) {
      
$debug->add(2,$this->name." set_title_default","Changed header not discarded");
      
$this->header = (!$this->header_changed) ? CONTENT_HEADER_HTML $this->header;
    } else { 
/* if ($this->html) */
      
$this->header = (!$this->header_changed) ? CONTENT_HEADER $this->header;
   
/* if ($this->html) { ... } else */    }
  } 
/* function set_title_default() */

  /**
   * Is content set
   *
   * Check if the content has been changed
   */
  
function isset_content() {
    return 
$this->isset;
  } 
/* function isset_content() */


// end class Content /* class Content extends ModuleBa... */