<?

/**
 * template.mod.php
 *
 * Dummy module. Should be extended by a functional module
 * @package   Modules
 */

//define("MOD_MAILTEMPLATE",$name);

require_once(INCLUDE_DIR."/template.inc.php");

//$modules[$name]= new MailTemplateModule();

/**
 * TemplateModule
 *
 * This module is a dummy module that is used for creating different pieces
 * of content from templates.
 * @package   Modules
 * @author    Herman Suijs
 */

class TemplateModule extends Module {
  
//var $name = "TemplateModule";
  //var $id = MOD_MAILTEMPLATE;
  //var $execlevel = 0;
  
var $templateID "template";
  var 
$templatefile "";
  var 
$start ""// Start-identifier for variable in template
  
var $stop "";
  var 
$tpl;
  var 
$content "";
  var 
$html false;

  
/**
   * Constructor
   *
   * Set options and call the superConstructor
   */
  
function TemplateModule() {
    
//$this->options[] = new Option("name:alias1:alias2","regular expression",required,stay_enabled_if_omitted,"default");
    //$this->options[] = new Option("mailtemplate:mailfile:templatemail","",true,false);
    
$this->options[] = new Option("identifiers","",false,true);
    
$this->tpl = new template;
    
$this->Module();
  } 
/* function TemplateModule() */
  
  /**
   * Before action
   *
   * Set values on template
   */
  
function before_action() {
    global 
$debug,$error,$formHandler;
    if (empty(
$this->content)) {
      
$error->add(ERR_DEV_CONT,$this->name,"Content needs to be defined in constructor: %s",$this->content);
      
$this->disable();
      return 
false;
    } 
/* if (empty($this->content)) */
    
$formHandler->set_html($this->html,$this->content);
    
$this->check_options();
    
$filename=TEMPLATE_DIR $this->options[0]->value;
    if (!
is_file($filename)) {
      
//$debug->add_message("Template $filename does not exist", $this->name);
      
$debug->add(DB_CONF,$this->name,"Template %s does not exist"$filename);
      unset(
$this->options[0]);
      
//$debug->add_message("Module disabled", $this->name);
      
$debug->add(DB_CONF,$this->name,"Module disabled");
      
$this->disable();
    } 
/* if (!is_file($filename)) */
    
else {
      
$this->tpl->load_file($this->templateID,$filename);
      
//$debug->add_message("Template $filename loaded.", $this->name);
      
$debug->add(DB_FLOW,$this->name,"Template %s loaded."$filename);
      if (isset(
$this->options[1])) {
    
$ids explode(ID_SPLIT,$this->options[1]->value);
    
//$debug->add_message("Changing template identifiers to $ids",$this->name);
    
$debug->add(DB_INFO,$this->name,"Changing template identifiers to %s",$ids);
    
$this->start $ids[0];
    
$this->stop $ids[1];
      } 
/* if (isset($this->options[1])) */
    
/* else */
  
/* function before_action() */

  /**
   * Template action
   *
   * Parse the template with the variables
   */
  
function template_action() {
    global 
$formHandler,$debug;
    if (
$this->action()) {
      
// Always use all vars for every template
      
$vars $formHandler->get_vars();
      
$this->tpl->register($this->templateID,$vars);
      
//$debug->add_message("Template vars added: " .  fh_serialize($vars),$this->name);
      
$debug->add(DB_DEV,$this->name,"Template vars added: %s",fh_serialize($vars));
      if (
$this->start&&$this->stop)
    
$this->tpl->set_identifiers($this->start,$this->stop);
      
$this->tpl->parse($this->templateID);
      
//$formHandler->set_content($this->tpl->return_file($this->templateID),CONTENT);
    
/* if ($this->action()) */
  
/* function template_action() */

  /**
   * Set content
   *
   * Store the parsed template in a content object in the
   * formhandler-module
   */
  
function set_content() {
    global 
$formHandler;
    
$formHandler->set_content($this->tpl->return_file($this->templateID),$this->content);
    
$formHandler->set_header("",$this->content);
    
$formHandler->set_footer("",$this->content);
  } 
/* function set_content() */

  /**
   * After action
   *
   * Cleanup
   */
  
function after_action() {
    unset(
$this->tpl);
    
$this->clean_up();
  } 
/* function after_action() */
/* class TemplateModule extends M... */