<?php
date_default_timezone_set("Europe/London");
include ("variables.php");

require_once 'webaddress.php';
require_once 'adminEmailAddress.php';

$submit=$_POST['submit'];
$info=$_POST['information'];
$booked=$_POST['booked'];
$fakeid=$_POST['id'];
$extraprint="";


if ($fakeid!="")
	{


	if ($submit)
		{

		$aid=$_POST['activityid'];
		$answer1=$_POST['answer1'];
		$answer2=$_POST['answer2'];
		$isq=$_POST['isquestion'];

		$id=$fakeid/562106562106;
		if ($fakeid=="")
			{
			echo "You need to login before viewing this page. You can do that <a href=\"members.php\">here</a>.";
			}
		else
			{
			?>


<html>
	<head>
		<title>Members Section</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<link rel="stylesheet" href="assets2/css/main.css" />
	</head>
	<body class="is-preload">

			<?php


			$alreadybooked=0;
			$query="select * from yc_event_signup WHERE aid='$aid' and kid='$id'";
			$mysql_result=mysql_query($query, $db);
			while ($row = mysql_fetch_row($mysql_result))
				{
				$alreadybooked=1;
				}

			if ($alreadybooked==1)
				{
	
				$extraprint="<table><tr><td bgcolor=\"EEFFFF\"><h2>According to our records you have already booked onto this activity. If you wish to book additional places for friends etc you will need to <a href=\"contact.php\">contact us.</a></h2></td></tr></table>";
				}
			else
				{
				$query="SELECT * FROM yc_event where id=$aid";
				$mysql_result=mysql_query($query, $db);
				while ($row = mysql_fetch_row($mysql_result))
					{
						$actname=stripslashes ($row[1]);
						$isquestion=$row[14];
						$question1=stripslashes ($row[15]);
						$question2=stripslashes ($row[17]);
						$compquestion=stripslashes ($row[24]);
						$companswer=stripslashes ($row[25]);
						$acttype=$row[20];
						$pricepayg=$row[4];
						$pricept=$row[5];
					}

				if ($isq!="") { $isquestion=$isq; }

				if ($isquestion!=1)
					{
						$extraprint=$extraprint. "<Table><Tr><td><font color=\"red\">Thank you for expressing interest in $actname. Before I can make a provisional booking, please answer the following question";

						if ($isquestion==3) { echo "s"; }

						$extraprint=$extraprint. ", which will assist us when trying to do the admin for this activity!<p>If the question below involves transport, please ensure you have adequate insurance on your vehicle before offering lifts.<b>If you booked this activity in error, please click the back button in your internet browser and try again.</b><p><form action=\"login_bookactivity.php\" method=\"post\">";

						$extraprint=$extraprint. "<table><tr><td><b><font color=\"blue\">Question 1:</b></td><td>$question1</td><td><input type=\"text\" name=\"answer1\"></td></tr>";

						if ($isquestion==3)
							{
							$extraprint=$extraprint. "<tr><td><b><font color=\"blue\">Question 2:</b></td><td>$question2</td><td><input type=\"text\" name=\"answer2\" </td></tr>";
							}

						$extraprint=$extraprint. "<tr><td colspan=2><input type=\"submit\" name=\"submit\" value=\"Continue...\"><input type=\"hidden\" name=\"isquestion\" value=\"1\"><input type=\"hidden\" name=\"id\" value=\"$fakeid\"><input type=\"hidden\" name=\"submit\" value=\"submit\"><input type=\"hidden\" name=\"activityid\" value=\"$aid\"></form></td></tr></table></td></tr></table></div>";

						}

					elseif ($compquestion)

						{

						$extraprint=$extraprint. "<div><big><font color=\"red\">Thank you for expressing interest in $actname. Before I can make a provisional booking, please answer the following question, which will assist us when trying to do the admin for this activity!<p>If the question below involves transport, please ensure you have adequate insurance on your vehicle before offering lifts.<p><b>If you booked this activity in error, please click the back button in your internet browser and try again.</b><p><form action=\"login_bookactivitycomp.php\" method=\"post\">";

						$extraprint=$extraprint. "<table><tr><td><font color=\"blue\">$compquestion</td><td><Select name=\"companswer\">$companswer</select></td></tr></table>";

						$extraprint=$extraprint. "<tr><td colspan=2><input type=\"submit\" name=\"submit\" value=\"Continue...\"><input type=\"hidden\" name=\"id\" value=\"$fakeid\"><input type=\"hidden\" name=\"submit\" value=\"submit\"><input type=\"hidden\" name=\"activityid\" value=\"$aid\"></form></td></tr></table>";

						}
	
					else

						{

						$query="SELECT * FROM yc_iyouth where id=$id";
						$mysql_result=mysql_query($query, $db);
						while ($row = mysql_fetch_row($mysql_result))
							{
							$fname=stripslashes ($row[1]);
							$sname=stripslashes ($row[2]);
							$name=$fname.' '.$sname;
							$yeargroup=$row[11];

							$email1=$row[4];
							$email2=$row[5];
							$email3=$row[6];
							$status=$row[10];
							if ($status==1)
								{
								$price=$pricept;
								}
								else
								{
								$price=$pricepayg;
								}
							if ($email1!="") { $email1=decodeemail($email1); $email1=$emaildecode; $emaildecode=""; }
							if ($email2!="") { $email2=decodeemail($email2); $email2=$emaildecode; $emaildecode=""; }
							if ($email3!="") { $email3=decodeemail($email3); $email3=$emaildecode; $emaildecode=""; }
							}


						$from="From:$name <$email1>";
						$subject="$name wishes to go on $actname";
						$body="$name wishes to go on $actname\r\n$question1 : $answer1 \r\n $question2 : $answer2\r\nSecond email: $email2\r\nThird email: $email3\r\n";
						mail ($routineNotificationEmailAddr, $subject, $body, $from);
						if ($yeargroup>8) { mail ($adminNotificationEmailAddr, $subject, $body, $from); }
						if ($yeargroup<9) { mail ($adminNotificationEmailAddr, $subject, $body, $from); }

						$extraprint="<table><tr><td bgcolor=\"EEFFFF\"><h2>";


						if ($acttype==2)
							{ 

							$query="insert into yc_event_signup (kid,aid,paid,status,price) VALUES ('$id','$aid','0','1','$price')";
							$mysql_result=mysql_query($query, $db);

							$extraprint=$extraprint. "Thank you. I have signed up $fname for $actname. If you wish to pay for this now, please click the paypal button on the right hand side of the page.</h2></td></tr></table>";
							}

						else
							{

							$query="insert into yc_event_signup (kid,aid,paid,status,price) VALUES ('$id','$aid','0','0','$price')";
							$mysql_result=mysql_query($query, $db);

							$extraprint=$extraprint. "Thank you. I have booked $fname onto $actname.</h2><p>Please note: This booking will be provisional until we have checked there are enough spaces on the activity and that your child is within the correct age range etc to take part in it. You will be sent an email when the booking has been confirmed.</p></td></tr></table>";
							}
						}
					}
				}
			include ("logininclude.php");

			?>
			<p><small>	
			Online club CMS Copyright (c) 2006-2024 James Bentall.

			</td></tr></table>

			</td></tr></table>
			</body></html>
			<?

		}
	if ($info)
		{

		$fakeid=$_POST['id'];
		$aid=$_POST['activityid'];
		?>
<html>
	<head>
		<title>Members Section</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<link rel="stylesheet" href="assets2/css/main.css" />
	</head>
	<body class="is-preload">
	
	
		<?php
		$extraprint="<table><tr><td bgcolor=\"EEFFFF\"><h2>Please find the information about the activity you are interested in below:</h2><table>";

		$query="SELECT * FROM yc_event where id=$aid";
		$mysql_result=mysql_query($query, $db);
		while ($row = mysql_fetch_row($mysql_result))
			{
			$aname=stripslashes ($row[7]);
			$thedate=stripslashes ($row[8]);
			$thetime=stripslashes ($row[9]);
			$theprice1=stripslashes ($row[10]);
			$theprice2=stripslashes ($row[11]);
			$meetcollect=stripslashes ($row[12]);
			$allyouneedtoknow=stripslashes ($row[13]);
			}

		$id=$fakeid/562106562106;

		$query="SELECT * FROM yc_iyouth where id=$id";
		$mysql_result=mysql_query($query, $db);
		while ($row = mysql_fetch_row($mysql_result))
			{
			$surname=stripslashes ($row[2]);
			$day=substr ($row[3],8,2);
			$month=substr ($row[3],5,2);
			$year=substr ($row[3],0,4);
			$status=$row[10];
			}

		$extraprint=$extraprint. "<tr><td valign=top><b>Event Name:</b></td><td>$aname</td></tr>";

		$extraprint=$extraprint. "<tr><td valign=top><b>Date:</b></td><td>$thedate</td></tr>";
		$extraprint=$extraprint. "<tr><td valign=top><b>Time:</b></td><td>$thetime</td></tr>";

		if ($status==1)
			{
			$extraprint=$extraprint. "<tr><td valign=top><b>Price:</b></td><td>$theprice1<br><small></td></tr>";
			}
		else
			{
			$extraprint=$extraprint. "<tr><td valign=top><b>Price:</b></td><td>$theprice2</td></tr>";
			}	
		$extraprint=$extraprint. "<tr><td valign=top><b>Meet and Collect:</b></td><td>$meetcollect</td></tr>";
		$extraprint=$extraprint. "<tr><td valign=top><b>All you need to know:</b></td><td>$allyouneedtoknow</td></tr>";

		$extraprint=$extraprint. "</table>";
$extraprint=$extraprint."</h2></td></tr></table>";
		include ("logininclude.php");

		}

	if ($booked)	
		{
		?>
		<html>
	<head>
		<title>Members Section</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
		<link rel="stylesheet" href="assets2/css/main.css" />
	</head>
	<body class="is-preload">
	<?
		$fakeid=$_POST['id'];
		$aid=$_POST['activityid'];
		$answer1=$_POST['answer1'];
		$answer2=$_POST['answer2'];
		$isq=$_POST['isquestion'];

		$id=$fakeid/562106562106;

		$query="SELECT * FROM yc_event where id=$aid";
		$mysql_result=mysql_query($query, $db);
		while ($row = mysql_fetch_row($mysql_result))
			{
			$extraprint=$extraprint. "<table><tr><td bgcolor=\"EEFFFF\"><h2>Event Name: <b>$row[1]</b></h2><p>The following members are currently booked into this activity:</p><table><tr>";
			$dadetails=stripslashes ($row[9]);
			$counter=0;
			}

		$query="SELECT * FROM yc_iyouth order by surname,firstname";
		$mysql_result=mysql_query($query, $db);
		while ($row = mysql_fetch_row($mysql_result))
			{

			$queryz="SELECT * from yc_event_signup where aid=$aid and status=1";
			$mysql_resultz=mysql_query($queryz, $db);
			while ($rowz = mysql_fetch_row($mysql_resultz))
				{
				if ($row[0]==$rowz[1])
					{
					$kidid=$row[0]*562106562106;
					$sname=stripslashes ($row[2]);
					$fname=stripslashes ($row[1]);
					$name=$fname.' '.$sname;
					$extraprint=$extraprint. "<li>$name";
					$counter=$counter+1;
//					if ($counter==6) { $counter=0; $extraprint=$extraprint. "</tr><tr>"; }
					}
				}
			}
			include ("logininclude.php");

		}

	}		
else
	{
	echo " You need to <A href=\"$webaddr/members.php\">login</a> before viewing this page, sorry.";
	}

?>