<?php include "../header.php";    
include "config.php"; 

?> 

<style>
.top_main {
 margin-top:30px;
 width:750px;
}
.headings {
 font-size:18px;
  margin-bottom:15px;
}
#number_of_tickets {
 margin-left: 5px;
 margin-right: 9px;
}
.first_block {
  float:left;
  width:340px;
}
.second_block {
  float:left;
  width:340px;
}
.ticket_details {
  line-height: 2.5;
	font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
  margin-top:5px;
  float:left;
border: 1px solid #999;
  padding: 10px;	
  margin-bottom:10px;
}
.additional_buyers {
  line-height: 2.5;
	font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
  margin-top:0px;
  float:left;
}
.add_more_guests {
  margin-top:10px;
}
.remove_ticket_forms {
  margin-top: -22px;
text-align: right;
width: 100%;
height: 20px;
margin-left: 19px;
}
.error {
  color: red;
}
.errormsg {
  color: red;
}
.email_information {
  margin: 20px; 
}
.submit_now {
margin: 20px;
text-align: center;
font-size: 17px;
}
.submit_now input {
  font-size:16px;
}
</style>

<?php

function unique_id($l = 8) {
    return substr(md5(uniqid(mt_rand(), true)), 0, $l);
}

$errormsg = "";
if(isset($_POST['submit'])) {
$errormsg = "Fields with * are mandatory";
	//$i=0;
	
	if(!empty($_POST['user_main_email'])){

	$numOfForms = $_POST['how_many_forms'];
	//echo "<pre>";
	//print_r($_POST);
	//exit;	
	$userMainEmail = $_POST['user_main_email'];	
	$uniqueKey = unique_id(16);
	$parentId = "";
	
	for($i=0;$i<=$numOfForms;$i++) {
		echo $i."<br>";
	if(!empty($_POST['fname_'.$i.''])){
		echo "value Fill into database<br>";
		if( $_POST['fname_'.$i.''] == "" || 
			$_POST['lname_'.$i.''] == "" || 
			$_POST['city_'.$i.''] == "" || 
			$_POST['age_'.$i.''] == "" || 
			$_POST['address1_'.$i.''] == "" || 
			$_POST['province_'.$i.''] == "" || 
			$_POST['zip_'.$i.''] == "" || 
			$_POST['telephone_'.$i.''] == "" || 
			$_POST['event_'.$i.''] == "" || 
			$_POST['cat_'.$i.''] == "" || 
			$_POST['email_'.$i.''] == "" ) {
			//$errormsg = "Fields with * are mandatory";
		} else {
			
			$donationAmount = 0;
            if($_POST['cat_'.$i.''] == "vvip") {
                $donationAmount = "250";
            } else if($_POST['cat_'.$i.''] == "vip") {
                $donationAmount = "150";
            } else if($_POST['cat_'.$i.''] == "general") {
                $donationAmount = "100";
            }

		    if($_POST['age_'.$i.''] <= 10){
	     		$donationAmount = $donationAmount - 50;
		    }
		
			$date = date('Y-m-d H:i:s');

			$getHighestId	 = mysql_query("SELECT * FROM user_information ORDER BY id DESC LIMIT 1");
			$resutlHighestId = mysql_fetch_array($getHighestId);

			if($resutlHighestId) {
				$lastTableId = $resutlHighestId['0'];
				$parentId = $lastTableId+1;
			} else {
				$parentId = 1;
			}
			
			
			$sql = "INSERT INTO user_information (`first_name`, `middle_name`, `last_name`, `age`, `address1`, `address2`, `city`, `state`,
		                         `zip_code`, `telephone`, `event_selected`, `category_selected`, `email_address`,
		                          `is_donated`,`donation_amount`,`is_ticket_generated`,`ticket_number`,`unique_number`,`inserted_date`,`parent_id`,`parent_email` ) 
								                VALUES ('".$_POST['fname_'.$i.'']."',
										                '".$_POST['mname_'.$i.'']."',
										                '".$_POST['lname_'.$i.'']."',
										                '".$_POST['age_'.$i.'']."',
										                '".$_POST['address1_'.$i.'']."',
										                '".$_POST['address2_'.$i.'']."',
										                '".$_POST['city_'.$i.'']."',
										                '".$_POST['province_'.$i.'']."',
										                '".$_POST['zip_'.$i.'']."',
										                '".$_POST['telephone_'.$i.'']."',
										                '".$_POST['event_'.$i.'']."',
										                '".$_POST['cat_'.$i.'']."',
										                '".$_POST['email_'.$i.'']."',
										                '0',
										                '".$donationAmount."',
										                '0',
										                '',
										                '".$uniqueKey."',
										                '".$date."',
										                '".$parentId."',
														'".$userMainEmail."'
									                )";
			
			//$fireQuery = mysql_query($sql);
			
		}
	} else {
	
	
	echo "Fill All Box<br>";
	
	}
	
	
}

exit;
	if($fireQuery) {
?>
		<script type="text/javascript">
			window.location = "new_pay.php?id=<?php echo $uniqueKey;?>&email=<?php echo $userMainEmail;?>";
		</script>
<?php	
		}
//Values for storing in database
		}
	}
	



?>

<script type="text/javascript">
var count = 0;
$(document).ready(function(){

	$("#how_many_forms").val(count);
    $("#bring_more_guests").click(function () {
		count++;
		jQuery.ajax({
			url : 'getTicketForms.php',
			type : 'post',
			dataType : 'html',
			data : { ticket_form_number : count },
			success: function(html){
				//alert(html);
				$(".additional_buyers").append(html);
				$("#how_many_forms").val(count);
		  	}
		});
	}); 
});

function deleteForm(number) {
	//alert(number);
	$("#div_form_"+number).remove();
}
</script>


<div class="content_container">		
	<div class="top_main">
		<div class="headings">Welcome! How many tickets do you want to purchase?</div>
		<div class="errormsg"><?php if($errormsg) { echo $errormsg; } ?></div>
			
			<!--<input type="text" name="number_of_tickets" id="number_of_tickets" size="5">
			<input type="submit" name="go" id="go" value="GO">-->
			
			<form name="form_0" method="post" id="form_0" action="">
			<div class="payer_information">
				
				<div class="email_information">Please enter your email address here<span class="error">*</span>&nbsp;&nbsp; <input type="text" name="user_main_email" id="user_main_email" value="<?php echo $_POST['user_main_email'];?>"> &nbsp;&nbsp; <br/><span class="note">(Note<span class="error">*</span> - Link for downloading tickets will send to this email address)</span></div>
				<div class="ticket_details">
					
					<div class="first_block">
						<table style="width:100%">
							<tr>
								<td width="30%">First Name<span class="error">*</span></td>
								<td width="70%"><input type="text" name="fname_0" id="fname_0" value="<?php echo $_POST['fname_0'];?>"></td>
							</tr>
							<tr>						
								<td width="30%">Middle Name</td>
								<td width="70%"><input type="text" name="mname_0" id="mname_0" value="<?php echo $_POST['mname_0'];?>"></td>						
							</tr>
							<tr>
								<td width="30%">Last Name<span class="error">*</span></td>
								<td width="70%"><input type="text" name="lname_0" id="lname_0" value="<?php echo $_POST['lname_0'];?>"></td>
							</tr>
							<tr>
								<td width="30%">Age<span class="error">*</span></td>
								<td width="70%"><input type="text" name="age_0" id="age_0" value="<?php echo $_POST['age_0'];?>"></td>
		</tr>
							<tr>
								<td width="30%">Email<span class="error">*</span></td>
								<td width="70%"><input type="text" name="email_0" id="email_0" value="<?php echo $_POST['email_0'];?>"></td>
							</tr>
							<tr>							
								<td width="40%">Category Selected<span class="error">*</span></td>
								<td width="60%">

									<select name="cat_0" id="cat_0" style="width:80%">
										<option value="">Select Cateory </option>	
										<option value="vvip" <?php if($_POST['cat_0']=="vvip"){ echo "selected";} ?>>VVIP - $250/ticket</option>
										<option value="vip" <?php if($_POST['cat_0']=="vip"){ echo "selected";} ?>>VIP - $150/ticket</option>
										<option value="general" <?php if($_POST['cat_0']=="general"){ echo "selected";} ?>>General - $100/ticket</option>
									</select>
								</td>						
							</tr>	
							<tr>
								<td width="40%">Select Event<span class="error">*</span></td>				
								<td width="60%">
									<select name="event_0" id="event_0" style="width:80%">
										<option value="">Select Event </option>
										<option value="26" <?php if($_POST['event_0']=="26"){ echo "selected";} ?> >A Night With Rabbi Shergill - DC (26th July 2014: 7:30pm)</option>
										<option value="27" <?php if($_POST['event_0']=="27"){ echo "selected";} ?>>A Night with Rabbi Shergill - NYC (27th July: 6:30pm)</option>
									</select>
								</td>
							</tr>					
						</table>
					</div>
					<div class="second_block">
						<table>
							<tr>
								<td width="30%">Address<span class="error">*</span></td>
								<td width="70%"><input type="text" name="address1_0" id="address1_0" value="<?php echo $_POST['address1_0'];?>"></td>						
							</tr>	
							<tr>
								<td width="40%">Street Address</td>
								<td width="60%"><input type="text" name="address2_0" id="address2_0" value="<?php echo $_POST['address2_0'];?>"></td>
		</tr>
							<tr>
								<td width="40%">City<span class="error">*</span></td>
								<td width="60%"><input type="text" name="city_0" id="city_0" value="<?php echo $_POST['city_0'];?>"></td>
		</tr>
							<tr>
								<td width="40%">Province<span class="error">*</span></td>
								<td width="60%"><input type="text" name="province_0" id="province_0" value="<?php echo $_POST['province_0'];?>"></td>
		</tr>
							<tr>
								<td width="40%">Zip<span class="error">*</span></td>
								<td width="60%"><input type="text" name="zip_0" id="zip_0" value="<?php echo $_POST['zip_0'];?>"></td>
					
							</tr>	
							<tr>
								<td width="40%">Telephone<span class="error">*</span></td>
								<td width="60%"><input type="text" name="telephone_0" id="telephone_0" value="<?php echo $_POST['telephone_0'];?>"></td>
		</tr>					
					
						</table>
						
					</div>	
					
				</div>
				
				<div class="additional_buyers"></div>
				
			</div>
			<div class="add_more_guests"><input type="button" name="bring_more_guests" id="bring_more_guests" value="Bring More Guests"></div>	
			<div class="submit_now">
			<input type="hidden" name="how_many_forms" id="how_many_forms" value="">
			<input type="submit" name="submit" id="submit" value="Submit"></div>
			</form>
		
	</div>
</div>

<?php include "footer.php";?>    
