read($tplname, $id); } function read ($tplname, $id=0) { $this->tplname=$tplname; if ($id!==0) { $this->tplname.=$id; } if(($fp = @fopen ($this->tpldir . $tplname,"r"))==NULL) { $log=new log(); $log->create("Failed to open file", "tpl", 1, $this->tpldir. "/" . $tplname); } $this->template=fread($fp, filesize($this->tpldir . $tplname)); fclose($fp); } // fill the template with either an array or a string for input function fill ($replaceitems, $show=true, $newinstance=true) { /* reads all keys (template vars) and values (replacement items) */ if ($newinstance) $this->output.=$this->template; // add new instance if (is_array($replaceitems)) { foreach ($replaceitems as $key => $value) $this->fill_var($key, $value); } else if (is_string($replaceitems)) { $this->parseVars (); if ($replaceitems!="") { $replaceitems=explode ("\xFE\xFF", $replaceitems); for ($i=0; $i < count($this->tplitems); $i++) { if (!isset($replaceitems[$i])) break; $this->output=str_replace ("<#" . $this->tplitems[$i] . "#>", $replaceitems[$i], $this->output); } } else for ($i=0; $i < count($this->tplitems); $i++) $this->output=str_replace ("<#" . $this->tplitems[$i] . "#>", "", $this->output); } else if (is_object($replaceitems)) $this->output=str_replace ("<#" . $replaceitems->tplname . "#>", $replaceitems->output, $this->output); else { $log=new log(); $log->create("Function: 'fill' not Properly called - $replaceitems, $show, $newinstance", "tpl", 2, $this->tplname); } /* show is true by default; so the template is shown unless true has been specified */ if ($show) $this->show(); return $this->output; } function fill_var ($key, $value) { $this->output=ereg_replace ("<#" . $key . "#>", (string) $value, $this->output); } // show the (filled) template function show () { $this->clearVars(); // clear all leftovers echo $this->output; } // parse vars into an array, suitable for specifying only values in a string function parseVars () { $offset=0; $i=0; while (($posend=strpos ($this->output, "#>", $offset))) { $posstart=strpos ($this->output, "<#", $offset); $tmp[$i]=substr ($this->output, $posstart+2, $posend-$posstart-2); $offset=++$posend; // add one to posend to start searching for a $i++; // new pattern } $tmp=array_unique($tmp); // make it unique bro // en zet ze van tmp in tplitems $i=0; foreach ($tmp as $value) { $this->tplitems[$i++]=$value; } } // clear the template function clear () { $this->output=""; } // clear the template variables function clearVars () { $this->output=preg_replace("/(<#).+?(#>)/", "", $this->output); } // Generates an empty template in output function emptyTpl() { $this->output=$this->template; $this->clearVars(); } // kopieert een template function copyTpl() { $this->output.=$this->template; } } ?> "; var $xmailer="Shopbot"; var $contenttype="text/html; charset=iso-8859-1"; var $postvars; var $ref_to_bestelling; function showMail($to, $subject, $from="", $post, $ref_to_bestelling) { $this->postvars=$post; $this->ref_to_bestelling=$ref_to_bestelling; $this->clearVars(); // clear all leftovers if ($from!="") $this->from=$from; $headers="From: $this->from\nReply-To: $this->from\n"; $headers.="X-Mailer: $this->xmailer\nContent-type: $this->contenttype\n"; set_error_handler(array(&$this, 'catch_mail_errors')); if (@!mail ($to, $subject, $this->output, $headers)) { $log = new log(); $log->create("E-mail kon niet verzonden worden...", "MAIL ERROR", 3, $query="-"); } restore_error_handler(); } function catch_mail_errors($errno, $errstr, $errfile, $errline) { if (strpos ($errstr,"User unknown")!==false) { $categorie_id=array_pop($this->postvars); $this->ref_to_bestelling->weergeven("ongeldigemailadres.tpl", $this->postvars, $categorie_id); } else { $tpl_error=new template("mailerror.tpl"); $tpl_error->copyTpl(); $tpl_error->fill_var("errorstr", $errstr); $tpl_error->show(); } exit(); } } ?>