{!--
Site:          chrysalis-designs.com
Page:          promotion/administrative-assistants-day
Created:       Apr 17 2007
Last Modified: Mar 30 2009
=================================================
ryan masuga, masugadesign.com
ryan@masugadesign.com | Copyright 2007-2008
================================================= --}
{preload_replace:category="19"}
<?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
?>
{exp:channel:entries channel="promo_offerings" dynamic="off" status="open|Sold Out" disable="trackbacks|pagination|member_data" category="{category}"}
<?php
if(trim($_POST['{url_title}'])!='') { 
	if(!ereg($number_pattern, $_POST['{url_title}'])) {
		$error_msg.="<li>Please enter numbers only ({title})</li>"; $errcount++; $error['{url_title}'] = true;
	}
} 
?>
{/exp:channel:entries}

<?php
// 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'] == 'deliver 2/13' )|| ($_POST['delivery'] == 'deliver 2/14')) { 
	// 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
?>

<?php
/* $rose_intuition = $_POST['{url_title}'];
$rose_bigfun = $_POST['rose_bigfun'];
$rose_charlotte = $_POST['rose_charlotte'];
$rose_malibu = $_POST['rose_malibu'];
$rose_versillia = $_POST['rose_versillia'];
$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'];
$aanames = nl2br(stripslashes($_POST['aanames']));
$giftcard = nl2br(stripslashes($_POST['giftcard']));

$stack = array();
$t=0;

?>
{exp:channel:entries channel="promo_offerings" dynamic="off" status="open|Sold Out" disable="trackbacks|pagination|member_data" category="{category}"}
<?php
$promoprice = {promo_price_nbr_tax};
	if($_POST['{url_title}'] > 0) { 
		$t = ($promoprice*$_POST['{url_title}']);
		}
array_push($stack, $t);
$t=0;
//$countx++;
?>
{/exp:channel:entries}
<?php

$grandtotal = array_sum($stack);

// also mail to the person who filled out the form - as a receipt
$recipient = "Chrysalis Design <tuckersweitzer@mac.com>";
// TESTING emails
//$recipient = "Chrysalis Design <ryan@masugadesign.com>";
$subject = "Chrysalis Admin. Assistant Day 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 .= 'Cc:'.$name.' <'.$theemail.'>' . "\r\n";
$mailheader .= 'Bcc:"MDesign" <monitor@masugadesign.com>' . "\r\n";
$mailheader .= 'Reply-To: "Tucker Sweitzer" <tuckersweitzer@mac.com>' . "\r\n";
$mailheader .= 'X-Mailer: PHP/' . phpversion();

$formcontent = "<html><head><title>Chrysalis Admin. Assistant Day 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 ($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 />";
?>

{exp:selecteditems name="admin_assistant_day"}
{exp:channel:entries channel="promo_offerings" dynamic="off" status="open|Sold Out" entry_id="{selecteditems_id}" orderby="selecteditems" disable="trackbacks|pagination|member_data" category="{category}"}
<?php
if ($_POST['{url_title}'] != "") { $formcontent .= "<strong>{title}:</strong> ".$_POST['{url_title}']." {promo_price_txt}<br />";}
?>
{/exp:channel:entries}
{/exp:selecteditems}

<?php
$formcontent .= "<br />";
//$formcontent .= "<strong>Subtotal:</strong> $$subtotal<br />";
//$formcontent .= "<strong>Tax (6%):</strong> $$tax<br />";
$formcontent .= "<strong>TOTAL:</strong> $$grandtotal<br /><br />";
if ($aanames != "") { $formcontent .= "<strong>Admin Name(s):</strong><br /> $aanames<br /><br />";}
if ($giftcard != "") { $formcontent .= "<strong>Gift Card Msg:</strong><br /> $giftcard<br /><br />";}
if ($instructions != "") { $formcontent .= "<strong>Comments:</strong><br /> $instructions<br />";}
$formcontent .= "<br /><br />";
$formcontent .= "If you have questions about your order, please contact Tucker at (203) 376-2841.";
$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;

// ==================================================================================
// ERROR BOX STUFF
			} 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>';
			}
}
?>

{preload_replace:page_title="Chrysalis Design Services, LLC | {static_page_name}"}
{!-- {preload_replace:body_class="home"} --}
{preload_replace:body_class="promotion"}
{preload_replace:body_id="{static_page_short_name}"}
{embed="common/pagetop" page_title="{page_title}"}
{embed="common/javascript"}
<script type="text/javascript" src="{site_url}js/prototype.js"></script>
<script type="text/javascript" src="{site_url}js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="{site_url}js/lightbox.js"></script>
<script type="text/javascript" src="{site_url}js/functions.js"></script>
<script type="text/javascript" src="{site_url}js/jquery-1.2.2.pack.js"></script>
<script type="text/javascript" src="{site_url}js/jquery.numeric.js"></script>

<script type="text/javascript">
var j = jQuery.noConflict();

j(document).ready(function() {	
	j("#form-contact dd.amt input").numeric();
});

</script>

{embed="common/styles"}
<style type="text/css" media="screen">
	.calcResult {
		display:none;
	}
	#totals {
		clear: both;
		border-bottom: 1px solid #D5CFA4;
		padding-left: 90px;
		height: 80px;
	}
</style>
</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.<br />
	If you have questions about your order, please contact Tucker at (203) 376-2841.</p>

<p>
{!-- <strong>Subtotal:</strong> $<?php echo $subtotalShow; ?><br />
<strong>Tax (6%):</strong> $<?php echo $taxShow; ?><br /> --}
<strong>TOTAL:</strong> $<?php echo $grandtotal; ?>
</p>

{if member_id == '1'}
<?php 
/* print_r($stack);
echo "<br /><br />";
echo "countx: ".$countx;
echo "<br /><br />";
echo "Array Stack<br />";
foreach ($stack as $value) {
echo "$value<br />\n";
} */
?>
{/if}


<p>
Please remit payment to:<br /><br />
Chrysalis Design Services, l.l.c.<br />
179 Cold Spring Street<br />
New Haven, Connecticut  06511<br /><br />
</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:channel:entries channel="static_pages" disable="trackbacks|pagination|member_data" category="{static_page}"}
{body}
{/exp:channel: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">

{!-- FLOWERS --}
{exp:selecteditems name="admin_assistant_day"}
{exp:channel:entries channel="promo_offerings" dynamic="off" status="open|Sold Out" entry_id="{selecteditems_id}" orderby="selecteditems" disable="trackbacks|pagination|member_data" category="{category}"}
  <dl class="clearfix flowerblock">
	
		<dt><label for="{url_title}">{title}</label></dt>

		<dd class="img">
			{if promo_img}
				{if promo_img_large}
				
					<a class="imgLink" href="{promo_img_large}" rel="lightbox[valentines]">
						<div class="enlargeImg"></div>
						{embed="promotion/_flower_image" image="/{exp:extract_url_plus show='relativeurl'}{promo_img}{/exp:extract_url_plus}" title="{title}"}
					</a>
				{if:else}
					{embed="promotion/_flower_image" image="/{exp:extract_url_plus show='relativeurl'}{promo_img}{/exp:extract_url_plus}" title="{title}"}
				{/if}
			{if:else}
			<div style="height:80px;width:80px;float:left;">&nbsp;</div>
			{/if}
		</dd>
		
		<dd class="desc">{promo_shortdesc} - <span class="price">${promo_price_nbr}{if promo_price_txt}/{promo_price_txt}{/if}</span></dd>
		{if status =="Sold Out"}
 <dd class="soldout">SOLD OUT</dd>  
{if:else}  
<dd class="amt"><input id="{url_title}" name="{url_title}" size="3" type="text" value="<?php echo $_POST['{url_title}']; ?>" />{if promo_price_txt}&nbsp;&nbsp;{promo_price_txt}{/if}</dd>
{/if}
 </dl> 
{/exp:channel:entries}
{/exp:selecteditems}

<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>

{!-- Delivery Options --}

<dt><?php field_required($error, "delivery", "Fulfillment"); ?> <span class="required">*</span></dt>
<dd>
{exp:channel:entries channel="misc" disable="categories|category_fields|member_data|pagination|trackbacks" dynamic="off" entry_id="46"}
{misc_adminassistant_dates}
<input type="radio" name="delivery" value="{delivery_option}" <?php if (isset($_POST['delivery']) and ($_POST['delivery'] == '{delivery_option}' )) echo 'checked="checked"'; ?> />&nbsp;{delivery_desc}<br />
{/misc_adminassistant_dates}
{/exp:channel:entries}
</dd>

<?php /* 
<dt><?php field_required($error, "delivery", "Fulfillment"); ?> <span class="required">*</span></dt>
<dd>
<input type="radio" name="delivery" value="deliver-wed" <?php if (isset($_POST['delivery']) and ($_POST['delivery'] == 'deliver-wed' )) echo 'checked="checked"'; ?> />&nbsp;Delivery - Wednesday<br />
<input type="radio" name="delivery" value="deliver-thu" <?php if (isset($_POST['delivery']) and ($_POST['delivery'] == 'deliver-thu' )) echo 'checked="checked"'; ?> />&nbsp;Delivery - Thursday<br />
<input type="radio" name="delivery" value="deliver-fri" <?if (isset($_POST['delivery']) and ($_POST['delivery'] == 'deliver-fri' )) echo 'checked="checked"'; ?> />&nbsp;Delivery - Friday<br />
</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>Administrative Assistant Name(s)</dt>
		<dd>
			You may enter multiple names, either one name per row or separated by commas.
			<textarea name="aanames" id="aanames" cols="36" rows="6"><?php echo stripslashes($_POST['aanames']); ?></textarea>
		</dd>

<dt>Gift Card Message</dt>
<dd>
	 (Optional) If you would like a gift card with a personal message to be included, please write out your message as you would like it to appear on the card:<br />
	<textarea name="giftcard" id="giftcard" cols="36" rows="6"><?php echo stripslashes($_POST['giftcard']); ?></textarea>
</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 Admin. Assistants Day Order" id="form_name" />
				<input type="hidden" name="todays_date" value="<?php echo date('F d, Y'); ?>" id="todays_date" />
	</fieldset>
	
</form>
</div>

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

<?php
} // end else statement
?>

{embed="common/footer"}