<?php
/**
 * Landing page for presale events with optional password protection.
 * Please copy this file, along with the image and css files, for each
 * new page and update the config section with relevant data.
 * 
 * @author    Phil Moorhouse <phil@ticketline.co.uk>
 * @version   1.0
 *  
 */

###########################################################
###################### START CONFIG #######################

# Debug
error_reporting(E_ALL | E_STRICT);                    
ini_set('display_errors', 0);                 # set to 0 before releasing to live

# Defaults - no need to modify these
date_default_timezone_set('Europe/London');   # set the default timezone
$dateFormat        = 'D d-M-y';               # set the default date format (see http://uk.php.net/manual/en/function.date.php for details)

# Event info - set the details for the event here
$eventPreTitle     = 'Kennedy Street by arr with Solo present';   # appears before the event name, leave blank if unneeded
$eventName         = 'Simple Minds';                              # name of the event
$eventSubTitle     = 'plus special guests OMD';                   # appears after the event name, leave blank if unneeded
# extra information, use html if required, leave blank if unneeded
$eventExtra        = '<p><strong>The special priority booking period begins on Wednesday 27th May at 10:00am.</strong></p>
                      <p>Tickets will then go on general sale on Friday 29th May.</p>';

# Sessions - create as many as required, remember to update the index (the number in the square brackets) for each line
$sessions[0]       = array('id' => '13235552', 'venueName' => 'Aberdeen Exhibition Centre', 'date' => '2009-12-12');
# ...etc

# Security
$protected         = false;                     # toggles the password protection on or off
$validPasswords    = array('underground');     # list of acceptable passwords, use lowercase if the case isn't important
$caseSensitive     = false;                    # if true, case of password must match, e.g. "PASS" is not the same as "pass"
$passwordValid     = false;                    # initial password state, do not change


####################### END CONFIG ########################
###########################################################


/**
 * converts natural english text into text safe for urls
 *
 * @param string $text
 * @return string $text
 */
function stripText($text)
{
	$text = strtolower($text);
	$search =  array('&amp;', '@');
	$replace = array(' and ', ' at ');
	$text = str_replace($search, $replace, $text);

	// strip all non word chars
	$text = preg_replace('/\W/', ' ', $text);
	// replace all white space sections with a dash
	$text = preg_replace('/\ +/', '-', $text);
	// remove leading and trailing dashes
	$text = trim($text, '-');

	return $text;
}


// if a password has been entered
if(isset($_POST['submit']))
{
	// trim any white space
	$password = trim($_POST['password']);
	
	// if we don't care about the case
	if(!$caseSensitive)
	{
		// convert the password to lowercase
		$password = strtolower($password);
	}
	
	// compare it against our list of valid passwords, if it matches, set flag to true
	if(in_array($password, $validPasswords))
	{
		$passwordValid = true;
	}
}



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <meta name="description" content="Ticketline: Your independent tickets source: Buy tickets online for Simple Minds" />
  
  <meta  name="keywords" content="ticketline, tickets, festivals, concerts, gigs, concert tickets, gig tickets,
                                  festival tickets, online tickets, music listings, tour listings, shows, show tickets,
                                  ticket sales, box office, clubs, club tickets, advance tickets, music tickets, ticket agencies,
                                  ticket agent, buy tickets, buy online, book tickets, music festival tickets, music festivals,
                                  live music, tour news, tour dates, tours, music venues, gig venues, concert venues, bands, rock, pop" />

	<link rel="stylesheet" type="text/css" media="screen" href="presale.css" />
	
	<title><?php echo $eventName ?> Tickets at Ticketline</title>
</head>

<body>

	<div id="wrapper">
	
		<div id="header">
			<img src="logo_presale_zone.gif" id="logo"><img src="swirl.gif" id="swirl">
		</div>
	
		<div id="main">
			<?php if(!empty($eventPreTitle)): ?>
				<h2><?php echo $eventPreTitle ?></h2>
			<?php endif; ?>
		
			<h1><?php echo $eventName ?></h1>
			
			<?php if(!empty($eventSubTitle)): ?>
				<h2><?php echo $eventSubTitle ?></h2>
			<?php endif; ?>
			
			<?php if($passwordValid || !$protected): ?>
			
				<?php if(!empty($sessions)): ?>
					<table>
						<tr>
							<th>Date</th>
							<th>Venue</th>
							<th>Link</th>
						</tr>
						<?php foreach($sessions as $session): ?>
							<tr>
								<td class="date"><?php echo date($dateFormat, strtotime($session['date'])) ?></td>
								<td class="venue"><?php echo $session['venueName'] ?></td>
								<td class="link">
									<a href="https://secure.ticketline.co.uk/tickets/<?php echo $session['id'].'/'.$session['venueName'].'/'.$session['date'] ?>">Buy Tickets</a>
								</td>
							</tr>
						<?php endforeach; ?>
					</table>
				<?php endif; ?>
			
			<?php else: ?>
			
				<form name="presaleSecure" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
					<?php if(isset($_POST['password']) && !$passwordValid): ?>
					<p class="error">Sorry, the password you entered was not recognised.</p>
					<?php endif; ?>
					<input type="text" name="fixie" value="1" style="display: none" />
					<label for="password">Password:</label>
					<input type="text" name="password" value="" />
					<input type="submit" name="submit" value="Enter" />
				</form>
				
			<?php endif; ?>
		
			<?php if(!empty($eventExtra)): ?>
				<?php echo $eventExtra ?>
			<?php endif; ?>
			
			<div id="footer">
				<p>Ticketline</p>
				<a href="http://www.ticketline.co.uk">www.ticketline.co.uk</a>
				<p>0871 424 4444</p>
				<a href="mailto:customerservices@ticketline.co.uk">customerservices@ticketline.co.uk</a>
			</div>
			
		</div>
		
	</div>

</body>

</html>
