{!--
Page:          promotion/valentines-day
Created:       Jan 27 2007
Last Modified: Feb 01 2007
===============================
ryan masuga, masugadesign.com
ryan@masugadesign.com 
=============================== --}

<?php
/* In EE, you have to declare your variables as globals. */
error_reporting(E_ALL^E_NOTICE); // this NEEDS to be set here for the validation to work
global $errbox, $error, $field, $fieldname;

$fullurl = "http://" . $_SERVER['HTTP_HOST'] . "/";
$email_pattern = '/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/';
$phone_pattern = '/^[\(]?(\d{0,3})[\)]?[\s]?[\-]?(\d{3})[\s]?[\-]?(\d{4})[\s]?[x]?(\d*)$/';
$number_pattern = '^[0-9]+$';

// this validates north american and/or canadian zipcodes
		$nazip_pattern = '/^((\d{5}-\d{4})|(\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d))$/';

// these two functions are used for forms that require validation
function error_bool($error, $field) {
         if($error[$field]) {
             print("style=\"font-weight:bold;color:#850202;\"");
         }
    }

 function field_required($error, $field, $fieldname) {
         if($error[$field]) {
            print("<label for=\"".$field."\" style=\"font-weight:bold;color:#850202;\">".$fieldname."</label>");
         } else {
						print("<label for=\"".$field."\">".$fieldname."</label>");
				}
    }

if (isset($_POST['btnSubmit'])) { /* if submit has been clicked, validate, tally errors, draw box, etc. */
// variables
		$error_msg='';
		$errcount = 0;

/*
Server-side form validation for the contact form
==================================================================== */
// validations
if(trim($_POST['rose_intuition'])!='') { 
	if(!ereg($number_pattern, $_POST['rose_intuition'])) {
		$error_msg.="<li>Please enter numbers only (Rose - Intuition)</li>"; $errcount++; $error['rose_intuition'] = true;
	}
}
if(trim($_POST['rose_engagement'])!='') { 
	if(!ereg($number_pattern, $_POST['rose_engagement'])) {
		$error_msg.="<li>Please enter numbers only (Rose - Engagement)</li>"; $errcount++; $error['rose_engagement'] = true;
	}
}
if(trim($_POST['rose_charlotte'])!='') { 
	if(!ereg($number_pattern, $_POST['rose_charlotte'])) {
		$error_msg.="<li>Please enter numbers only (Rose - Charlotte)</li>"; $errcount++; $error['rose_charlotte'] = true;
	}
}
if(trim($_POST['rose_vogue'])!='') { 
	if(!ereg($number_pattern, $_POST['rose_vogue'])) {
		$error_msg.="<li>Please enter numbers only (Rose - Vogue)</li>"; $errcount++; $error['rose_vogue'] = true;
	}
}
if(trim($_POST['rose_lipstick'])!='') { 
	if(!ereg($number_pattern, $_POST['rose_lipstick'])) {
		$error_msg.="<li>Please enter numbers only (Rose - Lipstick)</li>"; $errcount++; $error['rose_lipstick'] = true;
	}
}
if(trim($_POST['orchid_2028'])!='') { 
	if(!ereg($number_pattern, $_POST['orchid_2028'])) {
		$error_msg.="<li>Please enter numbers only (Orchid - 20-28)</li>"; $errcount++; $error['orchid_2028'] = true;
	}
}
if(trim($_POST['orchid_1216'])!='') { 
	if(!ereg($number_pattern, $_POST['orchid_1216'])) {
		$error_msg.="<li>Please enter numbers only (Orchid - 12-16)</li>"; $errcount++; $error['orchid_1216'] = true;
	}
}

// check that name is not empty
if(trim($_POST['name'])=='') { $error_msg.="<li>Please enter your name</li>"; $errcount++; $error['name'] = true;}

//check email address
if(trim($_POST['email_address'])=='') {$error_msg.="<li>Please enter an email address</li>"; $errcount++; $error['email_address'] = true;
 		} else { // check if email is a valid address in this format username@domain.com
      if(!preg_match($email_pattern, $_POST['email_address'])) { 
				$error_msg.="<li>Please enter a valid email address (<em>you@address.com</em>)</li>"; $errcount++; $error['email_address'] = true;}}

		if(trim($_POST['phone_01'])=='') {$error_msg.="<li>Please enter a phone number</li>"; $errcount++; $error['phone_01'] = true;
 		} else { // check if phone is a valid format 
			if(!preg_match($phone_pattern, $_POST['phone_01'])) {	$error_msg.="<li>Please enter a valid phone number</li>"; $errcount++; $error['phone_01'] = true;}
		}
		
		if($_POST['phone_02']) {
		 	if(!preg_match($phone_pattern, $_POST['phone_02'])) {	$error_msg.="<li>Please enter a valid alt phone number</li>"; $errcount++; $error['phone_02'] = true;}
		}


if(is_null($_POST['delivery'])) { $error_msg.="<li>Please select a delivery method</li>"; $errcount++; $error['delivery'] = true;

} else {

if(($_POST['delivery'] == 'deliver213' )|| ($_POST['delivery'] == 'deliver214')) { 
	// validate the further fields
	if(trim($_POST['address01'])=='') { $error_msg.="<li>Please enter your address</li>"; $errcount++; $error['address01'] = true;}
	if(trim($_POST['city01'])=='') { $error_msg.="<li>Please enter your city</li>"; $errcount++; $error['city01'] = true;}
	if(trim($_POST['state'])=='') { $error_msg.="<li>Please enter your state</li>"; $errcount++; $error['state'] = true;}
	$zip= trim($_POST['zipcode01']);
	if(!preg_match($nazip_pattern, $zip)) { $error_msg.="<li>Please enter your zipcode</li>"; $errcount++; $error['zipcode01'] = true;}	
	}
}
/* ERROR MESSAGE - Display if any, if not, proceed to other processing */

			if($error_msg=='') {

// ==================================================================================
$currentFile = $_SERVER["SCRIPT_NAME"]; // full path to current script
$parts = explode('/', $currentFile); //split apart the string at the slashes
$thispage = $parts[count($parts) - 1]; // collect part after the last slash

// General Form Info variables
// for the record, variables from checkboxes are called/stored like this: $food = $HTTP_POST_VARS["food"];
$formname = $_POST['form_name'];
$date = $_POST['todays_date'];

// flowers
$rose_intuition = $_POST['rose_intuition'];
$rose_engagement = $_POST['rose_engagement'];
$rose_charlotte = $_POST['rose_charlotte'];
$rose_vogue = $_POST['rose_vogue'];
$rose_lipstick = $_POST['rose_lipstick'];
$orchid_2028 = $_POST['orchid_2028'];
$orchid_1216 = $_POST['orchid_1216'];

$name = $_POST['name']; // required
$theemail = $_POST['email_address']; // required
$phone01 = $_POST['phone_01']; // required
$phone02 = $_POST['phone_02'];
$delivery = $_POST['delivery']; // required

//these only get checked if someone selects deliver1 or deliver2
// i.e. if $delivery = $_POST['delivery']; = deliver1 or deliver2
$company = $_POST['company'];
$address01 = $_POST['address01'];
$address02 = $_POST['address02'];
$city = $_POST['city01'];
$state = $_POST['state'];
$zip = $_POST['zipcode01'];

$instructions = nl2br(stripslashes($_POST['instructions']));
$submit = $_POST['btnSubmit'];

//need to do math here
$t1 = 0;
$t2 = 0;
$t3 = 0;
$t4 = 0;
$t5 = 0;
$t6 = 0;
$t7 = 0;

if($rose_intuition > 0) { 
	$t1 = 60*$rose_intuition;
}

if($rose_engagement > 0) { 
	$t2 = 48*$rose_engagement; 
}

if($rose_charlotte > 0) { 
	$t3 = 48*$rose_charlotte;
}
if($rose_vogue > 0) { 
	$t4 = 48*$rose_vogue;
}
if($rose_lipstick > 0) { 
	$t5 = 48*$rose_lipstick;
}
if($orchid_2028 > 0) { 
	$t6 = 48*$orchid_2028;
}
if($orchid_1216 > 0) { 
	$t7 = 35*$orchid_1216;
}
$subtotal = $t1+$t2+$t3+$t4+$t5+$t6+$t7;
$tax = $subtotal*.06;
$grandtotal = number_format(($subtotal+$tax),2);


// also mail to the person who filled out the form - as a receipt
$recipient = "$theemail,tucker@speakeasy.net";
//$recipient = "$theemail,ryan@masugadesign.com";
$subject = "Chrysalis Valentines Order";

// set up the mail (send 2 mails!)
$mailheader = 'MIME-Version: 1.0'. "\r\n";
$mailheader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mailheader .= 'From: Chrysalis Orders <orders@chrysalis-designs.com>' . "\r\n";
$mailheader .= 'Bcc:"MDesign" <monitor@masugadesign.com>' . "\r\n";
$mailheader .= 'Reply-To: "Tucker Sweitzer" <tucker@speakeasy.net>' . "\r\n";
$mailheader .= 'X-Mailer: PHP/' . phpversion();

$formcontent = "<html><head><title>Chrysalis Valentines Order</title></head><body>";
$formcontent .= "<strong>$formname</strong><br />";
$formcontent .= "<strong>Submitted:</strong> $date<br /><br />";
$formcontent .= "<strong>Name:</strong> $name<br />";
$formcontent .= "<strong>Email:</strong> $theemail<br />";
$formcontent .= "<strong>Phone:</strong> $phone01<br />";
if ($phone02 != "") { $formcontent .= "<strong>Alt Phone:</strong> $phone02<br />";}
$formcontent .= "<strong>Delivery:</strong> $delivery<br />";

if(($delivery == 'deliver213') || ($delivery == 'deliver214')) {
if ($company != "") { $formcontent .= "<strong>Company:</strong> $company<br />";}
$formcontent .= "<strong>Address:</strong> <br />$address01<br />";
if ($address02 != "") { $formcontent .= "$address02<br />";}
$formcontent .= "$city, $state $zip<br />";
}
$formcontent .= "<br />";
$formcontent .= "<strong>Order:</strong><br />";
if ($rose_intuition != "") { $formcontent .= "<strong>Rose Intuition:</strong> $rose_intuition dozen ($$t1)<br />";}
if ($rose_engagement != "") { $formcontent .= "<strong>Rose Engagement:</strong> $rose_engagement dozen ($$t2)<br />";}
if ($rose_charlotte != "") { $formcontent .= "<strong>Rose Charlotte:</strong> $rose_charlotte dozen ($$t3)<br />";}
if ($rose_vogue != "") { $formcontent .= "<strong>Rose Vogue:</strong> $rose_vogue dozen ($$t4)<br />";}
if ($rose_lipstick != "") { $formcontent .= "<strong>Rose Lipstick:</strong> $rose_lipstick dozen ($$t5)<br />";}
if ($orchid_2028 != "") { $formcontent .= "<strong>Orchid 20-28:</strong> $orchid_2028 /10 stems ($$t6)<br />";}
if ($orchid_1216 != "") { $formcontent .= "<strong>Orchid 12-16:</strong> $orchid_1216 /10 stems ($$t7)<br />";}
$formcontent .= "<br />";
$formcontent .= "<strong>Subtotal:</strong> $$subtotal<br />";
$formcontent .= "<strong>Tax (6%):</strong> $$tax<br />";
$formcontent .= "<strong>TOTAL:</strong> $$grandtotal<br /><br />";
if ($instructions != "") { $formcontent .= "<strong>Comments:</strong> $instructions<br />";}
$formcontent .= "<br /><br />";
$formcontent .= "</body></html>";

// mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] )
mail($recipient, $subject, $formcontent, $mailheader) or die("Sorry, but this form failed to send your email!");
// header("Location: ".$fullurl."contact/thank-you.php");

$mailgoodandsent = true;

// ==================================================================================
//global $FNS;
//$FNS->redirect('http://'.$_SERVER['HTTP_HOST'].'/thank-you/');
//$FNS->redirect($fullurl.'/thank-you/');
	
				/* Redirect to a different page in the current directory that was requested */
				//$host  = $_SERVER['HTTP_HOST'];
				//$uri  = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
				//$extra = 'update-successful.php';
				//header("Location: http://$host$uri/$extra");
				//header("Location: http://$host/thank-you/");
				//exit; /* Make sure that code below does not get executed when we do our thing here. */


			} else {
        $errbox = "";
        $errbox .= '<div class="errorexplanation" id="errorexplanation">';
				if ($errcount > 1){
        $errbox .= '<h2 class="error">There were '.$errcount.' errors with the form</h2>';
			} else {
				$errbox .= '<h2 class="error">There was an error with the form</h2>';
			}
        $errbox .= '<p>Please correct the following errors and try submitting again:</p>';
        $errbox .= '<ul>';
        $errbox .= $error_msg;
        $errbox .= '</ul>';
        $errbox .= '</div>';
			}
}


?>

{assign_variable:page_title="Chrysalis Design Services, LLC | {static_page_name}"}
{!-- {assign_variable:body_class="home"} --}
{assign_variable:body_class="promotion"}
{assign_variable:body_id="{static_page_short_name}"}

{embed="common/pagetop" page_title="{page_title}"}
{embed="common/javascript"}

<script type="text/javascript">
function showdeliver(theid) {
	var el = document.getElementById(theid);
	el.style.display = "block";
	}

function hidedeliver(theid) {
	var el = document.getElementById(theid);
	el.style.display = "none";
	}
</script>
{embed="common/styles"}

</head>

{embed="common/header" body_class="{body_class}" body_id="{body_id}"}

<?php
if ($mailgoodandsent) {
?>

<h2>Thank you for your order!</h2>

<p>You have been sent an email with the contents of your order.</p>

<p><strong>Subtotal:</strong> $<?php echo $subtotal; ?><br />
<strong>Tax (6%):</strong> $<?php echo $tax; ?><br />
<strong>TOTAL:</strong> $<?php echo $grandtotal; ?>
</p>

{!-- <p>TESTING<br />
$t1 = <?php echo $t1; ?><br />
$t2 = <?php echo $t2; ?><br />
$t3 = <?php echo $t3; ?><br />
$t4 = <?php echo $t4; ?><br />
$t5 = <?php echo $t5; ?><br />
$t6 = <?php echo $t6; ?><br />
$t7 = <?php echo $t7; ?><br />
</p>
 --}
<?php 
$mailgoodandsent = FALSE;
}else{ 
	
	// echo 'root: '.$theroot.'<br />';
	// echo 'recipient: '.$recipient;
	
	?>

{exp:weblog:entries weblog="static_pages" disable="trackbacks|pagination|member_data" category="{static_page}"}
{body}
{/exp:weblog:entries}



<?php echo $errbox; ?>
<form id="form-contact" name="form-contact" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<div id="form-container">

  <fieldset class="formfields">

	
  <dl class="clearfix flowerblock">
		<dt><label for="rose_intuition">Premium Red Intuition Roses</label></dt>
		<dd class="img"><img src="/images/uploads/rose_intuition.jpg" width="80" height="80" alt="Premium Red Intuition Roses" /></dd>
		<dd class="desc">Marbelized two toned red roses - <span class="price">$60/dozen</span></dd>
		    <dd class="soldout">SOLD OUT</dd>
   {!--  <dd><input id="rose_intuition" name="rose_intuition" size="3" type="text" value="<?php echo $_POST['rose_intuition']; ?>" />&nbsp;&nbsp;dozen</dd> --}
 </dl> 

  <dl class="clearfix flowerblock">
		<dt><label for="rose_charlotte">Classy/Charlotte Red Roses</label></dt>
		<dd class="img"><img src="/images/uploads/rose_charlotte2.jpg" width="80" height="80" alt="Classy/Charlotte Red Roses" /></dd>
		<dd class="desc">Classic velvety red roses - <span class="price">$48/dozen</span></dd>
 <dd class="soldout">SOLD OUT</dd>    
{!-- <dd><input id="rose_charlotte" name="rose_charlotte" size="3" type="text" value="<?php echo $_POST['rose_charlotte']; ?>" />&nbsp;&nbsp;dozen</dd> --}
 </dl> 

{!--   <dl class="clearfix flowerblock">
		<dt><label for="rose_engagement">Classic Cezanne Roses</label></dt>
		<dd class="img"><img src="/images/uploads/rose_engagement.jpg" width="80" height="80" alt="Classic Cezanne Roses" /></dd>
		<dd class="desc">Pink edged ivory roses - <span class="price">$48/dozen</span></dd>
    <dd><input id="rose_engagement" name="rose_engagement" size="3" type="text" value="<?php echo $_POST['rose_engagement']; ?>" />&nbsp;&nbsp;dozen</dd>
 </dl> --} 

  <dl class="clearfix flowerblock">
		<dt><label for="rose_engagement">Engagement Roses</label></dt>
		<dd class="img"><img src="/images/uploads/rose_engagement.jpg" width="80" height="80" alt="Engagement Roses" /></dd>
		<dd class="desc">Romantic soft peach rose - <span class="price">$48/dozen</span></dd>
    <dd><input id="rose_engagement" name="rose_engagement" size="3" type="text" value="<?php echo $_POST['rose_engagement']; ?>" />&nbsp;&nbsp;dozen</dd>
 </dl>

  <dl class="clearfix flowerblock">
		<dt><label for="rose_vogue">Vogue Roses</label></dt>
		<dd class="img"><img src="/images/uploads/rose_vogue.jpg" width="80" height="80" alt="Vogue Roses" /></dd>
		<dd class="desc">Deep pink roses - <span class="price">$48/dozen</span></dd>
    {!-- <dd><input id="rose_vogue" name="rose_vogue" size="3" type="text" value="<?php echo $_POST['rose_vogue']; ?>" />&nbsp;&nbsp;dozen</dd> --}
<dd class="soldout">SOLD OUT</dd>
 </dl> 

  <dl class="clearfix flowerblock">
		<dt><label for="rose_lipstick">Lipstick Roses</label></dt>
		<dd class="img"><img src="/images/uploads/rose_lipstick.jpg" width="80" height="80" alt="Lipstick Roses" /></dd>
		<dd class="desc">Magenta pink edged yellow rose - <span class="price">$48/dozen</span></dd>
    <dd><input id="rose_lipstick" name="rose_lipstick" size="3" type="text" value="<?php echo $_POST['rose_lipstick']; ?>" />&nbsp;&nbsp;dozen</dd>
 </dl> 

  <dl class="clearfix flowerblock">
		<dt><label for="orchid_2028">Dendrobium Orchids Designer's Choice Colors</label></dt>
		<dd class="img"><img src="/images/uploads/orchid_01.jpg" width="80" height="80" alt="Dendrobium Orchids Designer's Choice Colors" /></dd>
		<dd class="desc">20-28" sprays - <span class="price">$48 / 10 stems</span></dd>
    <dd><input id="orchid_2028" name="orchid_2028" size="3" type="text" value="<?php echo $_POST['orchid_2028']; ?>" />&nbsp;&nbsp; (10 stems)</dd>
 </dl> 

  <dl class="clearfix flowerblock">
		<dt><label for="orchid_1216">Dendrobium Orchids Designer's Choice Colors</label></dt>
		<dd class="img"><img src="/images/uploads/orchid_02.jpg" width="80" height="80" alt="Dendrobium Orchids Designer's Choice Colors" /></dd>
		<dd class="desc">12-16" sprays - <span class="price">$35 / 10 stems</span></dd>
    <dd><input id="orchid_1216" name="orchid_1216" size="3" type="text" value="<?php echo $_POST['orchid_1216']; ?>" />&nbsp;&nbsp; (10 stems)</dd>
 </dl> 



<dl class="clearfix">
		<dt><?php field_required($error, "name", "Your Name"); ?> <span class="required">*</span></dt>
    <dd><input id="name" name="name" size="30" type="text" value="<?php echo $_POST['name']; ?>" /></dd>

<dt><?php field_required($error, "email_address", "Email Address"); ?> <span class="required">*</span></dt>
<dd><input name="email_address" id="email_address" type="text" size="20" value="<?php echo $_POST['email_address']; ?>" /></dd>

<dt><?php field_required($error, "phone_01", "Phone"); ?> <span class="required">*</span></dt>
		<dd><input name="phone_01" id="phone_01" type="text" size="20" value="<?php echo $_POST['phone_01']; ?>" /></dd>

<dt><?php field_required($error, "phone_02", "Alt Phone"); ?></dt>
		<dd><input name="phone_02" id="phone_02" type="text" size="20" value="<?php echo $_POST['phone_02']; ?>" /></dd>


<dt><?php field_required($error, "delivery", "Fulfillment"); ?> <span class="required">*</span></dt>
<dd>
<input type="radio" name="delivery" value="deliver213" <?php if (isset($_POST['delivery']) and ($_POST['delivery'] == 'deliver213' )) echo 'checked="checked"'; ?> />&nbsp;Delivery - Tuesday, 2/13<br />
<input type="radio" name="delivery" value="deliver214" <?php if (isset($_POST['delivery']) and ($_POST['delivery'] == 'deliver214' )) echo 'checked="checked"'; ?> />&nbsp;Delivery - Wednesday, 2/14<br />
<input type="radio" name="delivery" value="pickup213" <?if (isset($_POST['delivery']) and ($_POST['delivery'] == 'pickup213' )) echo 'checked="checked"'; ?> />&nbsp;Pick Up - Tuesday, 2/13 4:15pm - 6:30pm<br />
<input type="radio" name="delivery" value="pickup214" <?if (isset($_POST['delivery']) and ($_POST['delivery'] == 'pickup214' )) echo 'checked="checked"'; ?> />&nbsp;Pick Up - Wednesday, 2/14  4:15 - 6:30 pm
</dd>


<dt>Additional Info</dt>
<dd>For delivery, please enter the following address information:</dd>

<dt><?php field_required($error, "company", "Company"); ?></dt>
		<dd><input name="company" id="company" type="text" size="20" value="<?php echo $_POST['company']; ?>" /></dd>

<dt><?php field_required($error, "address01", "Address"); ?> <span class="required">*</span></dt>
		<dd><input name="address01" id="address01" type="text" size="20" value="<?php echo $_POST['address01']; ?>" /></dd>

		<dt><label for="address02">Address 2</label></dt>
		<dd><input name="address02" id="address02" type="text" size="20" value="<?php echo $_POST['address02']; ?>" /></dd>	
	
<dt><?php field_required($error, "city01", "City"); ?> <span class="required">*</span></dt>
		<dd><input name="city01" id="city01" type="text" size="20" value="<?php echo $_POST['city01']; ?>" /></dd>	
<dt><?php field_required($error, "state", "State"); ?> <span class="required">*</span></dt>
		<dd><input name="state" id="state" type="text" size="3" value="<?php if (!isset($_POST['state'])) { echo 'CT'; }else{echo $_POST['state']; }?>" /></dd>		
	
<dt><?php field_required($error, "zipcode01", "Zipcode"); ?> <span class="required">*</span></dt>
    <dd><input name="zipcode01" id="zipcode01" type="text" size="8" value="<?php echo $_POST['zipcode01']; ?>" /></dd>




<dt>Additional Instructions</dt>
		<dd>
			<textarea name="instructions" id="instructions" cols="36" rows="6"><?php echo stripslashes($_POST['instructions']); ?></textarea>
		</dd>

<dt></dt>
    <dd><input name="btnSubmit" type="submit" value="Submit Order" class="submit" /></dd>
  </dl>

				<input type="hidden" name="form_name" value="Chrysalis Design Valentines Order" id="form_name" />
				<input type="hidden" name="todays_date" value="<?php echo date('F d, Y'); ?>" id="todays_date" />
	</fieldset>
	
</form>
</div>

<p>I accept cash or personal check only. Please make checks payable to Chrysalis Design Services. Orders may be picked up at 179 Cold Spring Street.</p>
<br /><br /><br />
<?php
} // end else statement
?>

{embed="common/footer"}