$regexList["empty"] = "^.+$";
$regexList["date"] = "(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])";
$formdata["fields"]["sm_Name"] = "";
$formdata["fields"]["sm_Area"] = "46";
$formdata["fields"]["sm_Address"] = "";
$formdata["fields"]["sm_pcs"] = "1";
$formdata["fields"]["sm_Zip"] = "";
$formdata["fields"]["sm_City"] = "";
$formdata["fields"]["sm_Country"] = "";
$formdata["fields"]["sm_Phone"] = "";
$formdata["fields"]["sm_Email"] = "";
$formdata["validations"]["sm_Email"][0]["type"] = 1;
$formdata["validations"]["sm_Email"][0]["rule"] = $regexList["empty"]; // not empty
$formdata["validations"]["sm_Email"][0]["errmsg"] = "Email cannot be empty";
$formdata["validations"]["sm_Phone"][0]["type"] = 1;
$formdata["validations"]["sm_Phone"][0]["rule"] = $regexList["empty"]; // not empty
$formdata["validations"]["sm_Phone"][0]["errmsg"] = "Phone cannot be empty";
$formdata["validations"]["sm_Address"][0]["type"] = 1;
$formdata["validations"]["sm_Address"][0]["rule"] = $regexList["empty"]; // not empty
$formdata["validations"]["sm_Address"][0]["errmsg"] = "Address cannot be empty";
$formdata["validations"]["sm_pcs"][0]["type"] = 1;
$formdata["validations"]["sm_pcs"][0]["rule"] = $regexList["empty"]; // not empty
$formdata["validations"]["sm_pcs"][0]["errmsg"] = "How many cannot be empty";
$formdata["validations"]["sm_Zip"][0]["type"] = 1;
$formdata["validations"]["sm_Zip"][0]["rule"] = $regexList["empty"]; // not empty
$formdata["validations"]["sm_Zip"][0]["errmsg"] = "Zip Code cannot be empty";
$formdata["validations"]["sm_City"][0]["type"] = 1;
$formdata["validations"]["sm_City"][0]["rule"] = $regexList["empty"]; // not empty
$formdata["validations"]["sm_City"][0]["errmsg"] = "City cannot be empty";
$formdata["validations"]["sm_Name"][0]["type"] = 1;
$formdata["validations"]["sm_Name"][0]["rule"] = $regexList["empty"]; // not empty
$formdata["validations"]["sm_Name"][0]["errmsg"] = "Name cannot be empty";
class formHandler{
var $postData = Array();
var $formData = Array();
var $query;
var $errormessages = Array();
function setFormData($xformdata){
$this->formData = $xformdata;
}
function getFormData(){
return $this->formData;
}
function init(){
$this->mapValues();
}
function checkValues(){
$this->init();
}
function getErrorMessages(){
return $this->errormessages;
}
function mapValues(){
//$fields = $this->formData["fields"];
$errcnt =0;
if(isset($_POST)){
//print_r($this->formData);
foreach ($_POST as $post_key=>$post_value){
//echo $post_key."\n";
if(array_key_exists($post_key,$this->formData["fields"])){
//echo "\n exists: ".$post_key;
$this->formData["fields"][$post_key] = addslashes($post_value);
if(array_key_exists($post_key,$this->formData["validations"])){
$validations = $this->formData["validations"][$post_key];
for($y=0;$yerrormessages[$errcnt]["msg"] = $validations[$y]["errmsg"];
$this->errormessages[$errcnt]["field"] = $post_key;
$errcnt++;
}
}
}
}
}else{
//echo "\n Not exists: ".$post_key;
}
}
}
}
}
/********************************
MailSender Class
for Symbase CM
Ville Siren
All rights Reserved 2007
Version history
V0.1 23.4.2007 Initial Version Created
Future Improvements
- Make input data sortabel by using inputPrefix + _1_ i.e. sm_1_
- Add HTML support
********************************/
class CMFeedbackManager{
var $version = "0.1";
var $thankYouPage;
var $errorPage;
var $useDB = false;
var $contentType = "text/plain; charset=ISO-8859-1";
var $inputPrefix = "sm_"; //to be used with the form so that each of the
var $useInputPrefixOrdering = false;
var $headers = Array();
var $inputData = Array();
var $wordWrap = 75;
var $subjectField = "subject";
var $headerCloseString = "\r\n";
var $bodyHeader;
/*** END RESULT MAIL VARIABLES ****/
var $mailBody;
var $mailHeaders;
var $mailSubject;
var $mailReceiver;
var $mailCC;
var $mailBCC;
var $mailFrom;
var $mailReplyTo;
var $mailXMailer = "CM FeedbackManager by Symbase /";
var $mailSubjectPrefix;
function setReceiver($xreceiver){
// WHERE THE EMAIL IS SENT
$this->mailReceiver = $xreceiver;
}
function setUseDB($xusedb){
//IF THE ENTRY WILL BE STORED IN DATABASE, REMEMBER THAT DB AND TABLEMSUT EXIST
$this->useDB = $xusedb;
}
function setThankYouPage($xthankspage){
// WHERE TO REDIRECT AFTER SUCCESSFULL MAIL SEND
$this->thankYouPage = $xthankspage;
}
function setContentType($xcontenttype){
// CONTENT TYPE OF THE EMAIL CAN,
$this->mailContentType = $xcontentype;
}
function setCC($xcc){
// CONTENT TYPE OF THE EMAIL CAN,
$this->mailCC = $xcc;
}
function setBCC($xbcc){
// CONTENT TYPE OF THE EMAIL CAN,
$this->mailBCC = $xbcc;
//$this->headers[]["type"] = "Bcc";
//$this->headers[]["content"] = = $xbcc;
}
function setFrom($xfrom){
// CONTENT TYPE OF THE EMAIL CAN,
$this->mailFrom = $xfrom;
}
function setReplyTo($xreplyto){
// CONTENT TYPE OF THE EMAIL CAN,
$this->mailReplyTo = $xreplyto;
}
function setErrorPage($xerrorpage){
// WHERE TO REDIRECT AFTER FAILED MAIL SEND
$this->errorPage = $xerrorpage;
}
function setHeaders($xheaders){
// SET ADDITIONAL HEADER
$this->headers = $xheaders;
}
function setWordWrap($xwordwrap){
// SET WORDWRAP FOR THE PAGE
$this->wordWrap = $xwordwrap;
}
function setMailSubjectPrefix($xmsp){
// SET WORDWRAP FOR THE PAGE
$this->mailSubjectPrefix = $xmsp;
}
function setSubjectField($xsubjectfield){
// SET WHICH FIELD IS THE FIELD THAT THE SUBJECT IS TAKEN FROM
$this->subjectField = $xsubjectfield;
}
function setBodyHeader($xbodyheader){
// SET WHICH FIELD IS THE FIELD THAT THE SUBJECT IS TAKEN FROM
$this->bodyHeader = $xbodyheader;
}
function runFeedbackManager(){
$this->gatherInput();
$this->createheaders();
$this->createMailBody();
$this->sendMail();
}
function gatherInput(){
if(isset($_POST)){
foreach ($_POST as $post_key=>$post_value){
if($post_key == $this->subjectField){
$this->mailSubject = $this->mailSubjectPrefix.$post_value;
}else{
if(substr($post_key,0,strlen($this->inputPrefix)) == $this->inputPrefix){
$this->inputData[trim(substr($post_key,strlen($this->inputPrefix)))] = $post_value;
}
}
}
if(!isset($this->mailSubject)){
$this->mailSubject = $this->mailSubjectPrefix;
}
}
}
function createMailBody(){
$this->mailBody = $this->bodyHeader."\n\n";
//$xkeys = array_keys($this->inputData);
$this->mailBody .= "Thank you for your order.\n\n";
$this->mailBody .= "You have ordered ".$this->inputData["pcs"]." copies of the NORTH POLE – ARCTIC CHALLENGE books.\n";
$summa = $this->inputData["pcs"]*$this->inputData["Area"];
$this->mailBody .= "Total costs: ".$summa." EUR (incl. shipping to ";
if($this->inputData["Area"] == 46){
$this->mailBody .= "Finland";
}elseif($this->inputData["Area"] == 52){
$this->mailBody .= "Europe";
}elseif($this->inputData["Area"] == 58){
$this->mailBody .= "Worldwide";
}
$this->mailBody .= ")\n";
$this->mailBody .= "\nInvoice will enclose to the chart.\n\n";
$this->mailBody .= "Delivery address:.\n";
$this->mailBody .= $this->inputData["Name"]."\n";
$this->mailBody .= $this->inputData["Address"]."\n";
$this->mailBody .= $this->inputData["Zip"]." ";
$this->mailBody .= $this->inputData["City"]."\n";
$this->mailBody .= $this->inputData["Country"]."\n\n";
$this->mailBody .= "Phone: ".$this->inputData["Phone"]."\n";
$this->mailBody .= "Email: ".$this->inputData["Email"]."\n\n";
$this->mailBody .= "Books will send you immediately. Shipping time depend on shipping area (2-12 days)\n\n";
$this->mailBody .= "Best Regards\n";
$this->mailBody .= "Kari Poppis Suomela\n\n";
$this->mailBody .= "----------------------------------------------------\n";
$this->mailBody .= "POPPICOK\n";
$this->mailBody .= "OUTDOOR PHOTOGRAPHY AND JOURNALISM\n";
$this->mailBody .= "Tykkimäentie 14\n";
$this->mailBody .= "Fin-05200 Rajamäki\n";
$this->mailBody .= "+358-400-420002\n";
$this->mailBody .= "poppis@poppicok.fi\n";
$this->mailBody .= "www.poppicok.fi\n";
/*
foreach($this->inputData as $xkey => $xvalue){
$this->mailBody .= "#".$xkey.":\n";
$this->mailBody .= "\t".$xvalue."\n\n";
//echo "\nxxx".$xvalue."xxx\n";
}
*/
}
function createHeaders(){
if(isset($this->contentType)){
$this->mailHeaders .= "Content-Type: ".$this->contentType.$this->headerCloseString;
}
if(isset($this->mailFrom)){
$this->mailHeaders .= "From: ".$this->mailFrom.$this->headerCloseString;
}
if(isset($this->mailCC)){
$this->mailHeaders .= "Cc: ".$this->mailCC.$this->headerCloseString;
}
if(isset($this->mailBCC)){
$this->mailHeaders .= "Bcc: ".$this->mailBCC.$this->headerCloseString;
}
if(isset($this->mailReplyTo)){
$this->mailHeaders .= "Reply-To: ".$this->mailReplyTo.$this->headerCloseString;
}
$this->mailHeaders .= "X-Mailer: ".$this->mailXMailer.$this->version.$this->headerCloseString;
}
function sendMail(){
$message = wordwrap($this->mailBody, 75, "\n");
if(mail($this->mailReceiver, $this->mailSubject, $message, $this->mailHeaders)){
if(isset($this->thankYouPage)){
header("Location: ".$this->thankYouPage); /* Redirect browser */
exit;
}
}else{
if(isset($this->errorPage)){
header("Location: ".$this->errorPage); /* Redirect browser */
exit;
}
}
}
}
$fh = &new formHandler;
$fbm = &new CMFeedbackManager;
//
//$fbm->setCC("ville.siren@iki.fi");
$fbm->setBCC("antti@valotukku.fi");
$fbm->setFrom("Online Order - Poppicok.fi ");
$fbm->setMailSubjectPrefix("NORTH POLE – ARCTIC CHALLENGE order");
$fbm->setBodyHeader("NORTH POLE – ARCTIC CHALLENGE order");
//$fbm->setSubjectField("sm_Nimi");
if(count($_POST)>0){
if($_POST["action"]=="Send order"){
$fh->setFormData($formdata);
$fh->checkValues();
$errmsg = $fh->getErrorMessages();
if(count($errmsg)>0){
$formdata = $fh->getFormData();
$nextPage = 0;
}else{
$fbm->setReceiver($_POST["sm_Email"]);
$fbm->runFeedbackManager();
$nextPage = 1;
}
}
}else{
$nextPage = 0;
}
?>
NORTH POLE – ARCTIC CHALLENGE books
switch ($nextPage){
case 0:
if(count($errmsg) > 0){?>
for($x=0;$x
echo $errmsg[$x]["msg"]; ?>
} ?>
} ?>
Terms of delivery
Delivery time depend on shipping area, Europe 2-6 days, outside Europe 4-12 days
Invoice will enclose to the chart.
All prices include VAT.
If you have some question, please contact poppis@poppicok.fi