<?

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

// This class should probably be a subclass from the mailclass.
/**
 * Module name
 */
define("MOD_REPLY",$name);
//define("REGEX_REPLY","(^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$)");
// REGEX MAIL is used in different files. Should be defined in configfile
// or something.

define("RECIPIENT",0);
define("SUBJECT",1);
define("FROM",2);
define("CC",3);
define("BCC",4);
define("HEADERS",5);
define("REPLY",6);
define("FORMREPLY_CONTENT",7);

//define("DEFAULT_MAIL","herman@suijsmail.com");
define("DEFAULT_SUBJECT","FH Reply");
define("DEFAULT_FROM","Website form <>");
define("DEFAULT_CONTENT","This is the default content used for the reply\n\n");


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

/**
 * ReplyModule
 *
 * This module sends a reply to the submitter of the form when (s)he leaves
 * an emailaddress.
 * @package   Modules
 * @author    Herman Suijs
 */
class ReplyModule extends Module {
  var 
$name "ReplyModule";
  var 
$id MOD_REPLY;
  var 
$execlevel 23;

  
/**
   * Constructor
   *
   * Set options and call the superConstructor
   */
  
function ReplyModule() {
    global 
$formHandler;
    
//$this->options[REPLY] = new Option("reply:courtesy_reply","",true,false);
    
$this->options[RECIPIENT] = new Option("email:e-mail:mail:emailaddress:e-mailaddress:mailaddress:email-address:mail-address:emailadres",REGEX_MAIL,true,false);
    
$this->options[SUBJECT] = new Option("reply_subject:courtesy_reply","",false,true,DEFAULT_SUBJECT);
    
//$this->options[CC] = new Option("cc:copy",REGEX_REPLY);
    //$this->options[BCC] = new Option("bcc:blindcopy",REGEX_REPLY);
    
$this->options[FROM] = new Option("reply_from:courtesy_from:reply_address:replyaddress","",false,true,DEFAULT_FROM);
    
$this->options[HEADERS] = new Option("replyheader:replyheaders");
    
$this->options[FORMREPLY_CONTENT] = new Option("replycontent:reply_content:replytext:reply_text");
    
$formHandler->set_content(DEFAULT_CONTENT .$this->options[FORMREPLY_CONTENT]->value,REPLY_CONTENT);
    
$this->Module();
  } 
/* function ReplyModule() */
  
  /**
   * Before action
   *
   * Check options
   */
  
function before_action() {
    
$this->check_options();
  } 
/* function before_action() */

  /**
   * Do action
   *
   * Set all values for sending a reply mail and send the mail
   */
  
function do_action() {
    global 
$formHandler;

    
$recipient $this->options[RECIPIENT]->value;
    
$subject $this->options[SUBJECT]->value;
    
$from $this->options[FROM]->value;
    
//$content = $this->options[FORMREPLY_CONTENT]->value;
    //if (!$content) {
      // Get the content
      
$content$formHandler->get_content(REPLY_CONTENT,true);
    
//} else $content = $con /* //if (!$content) */tent . "\n";
    //$cc = $this->options[CC]->value;
    //$bcc = $this->options[BCC]->value;
    
$replyheaders $this->options[HEADERS]->value;

    
// Fillin the headers
    
$headers"";
    if (
$from$headers .= "From: $from\n";
    if (
$cc$headers .= "Cc: $cc\n";
    if (
$bcc$headers .= "Bcc: $bcc\n";
    if (
$replyheaders$headers .= "$replyheaders\n";

    if(
$this->action()) {
      
mail($recipient,$subject,$content,$headers);
      
//echo "Reply send <br>";
    
} elseif($debug->enabled) { /* if($this->action()) */
      
$debug->add_message("reply($recipient,$subject,$content,$headers)",$this->name);
   
/* if($this->action()) { ... } el... */  } else {
      
//echo "No reply send";
    
/* /* if($this->action()) { ... }... */
  
/* function do_action() */

  /**
   * After action
   *
   * Cleanup
   */
  
function after_action() {
    
$this->clean_up();
  } 
/* function after_action() */
/* class ReplyModule extends Modu... */