<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/usr/local/pem/vhosts/101154/webspace/httpdocs/~murraysb/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("../$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records
  list($snippetsRecords, $snippetsMetaData) = getRecords(array(
    'tableName'   => 'snippets',
    'allowSearch' => '0',
    'limit'       => '1',
  ));
  $snippetsRecord = @$snippetsRecords[0]; // get first record

  // load records
  list($gigs_eventsRecords,) = getRecords(array(
    'tableName'   => 'gigs_events',
	'where'       => 'location="Manly" AND date >= TIMESTAMP( DATE(NOW()) ) ',
	'allowSearch' => true,
  ));

  $artistNums = join(',', array_pluck($gigs_eventsRecords, 'artist'));  
   
  if (!$artistNums) { $artistNums = "0"; } 
    
  list($artistRecords,) = getRecords(array(  
    'tableName'   => 'artist',  
    'where'       => "num IN ($artistNums)",  
    'allowSearch' => false,  
  ));
   
  $artistsByNum = array_combine(array_pluck($artistRecords, 'num'), $artistRecords); 
 
?> 
<?php
include('../avs/config.php');
include('../avs/require_verification.php');
?><!doctype html>
<html>
<head>
<title><?php echo $snippetsRecord['seo_title'] ?></title>
<meta charset="utf-8" />

<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<meta name="keywords" content="<?php echo $snippetsRecord['seo_keywords'] ?>">
<meta name="description" content="<?php echo $snippetsRecord['seo_description'] ?>">

<?php include_once("../_insertHeaderCode.php") ?>
</head>
<body>
<div id="pagewidth" >
	<div id="header">
    <?php include_once("../_insertSiteNavigation.php") ?>
    </div>
<div id="wrapper" class="clearfix">
	<div id="maincol">
        <?php include_once("../_insertSecondNavigation_Manly.php") ?>
        
<div class="mainGigContent">
<?php $lastMonth = ''; ?>			  
<?php foreach ($gigs_eventsRecords as $gigs_events): ?>   
            <?php if ($lastMonth != date("M", strtotime($gigs_events['date']))): ?>  
            <div style="margin:40px 40px 20px 40px;"><img src="../assets/images/divider_jughailer_680px.png"></div>
            <h1><?php echo date("F", strtotime($gigs_events['date'])) ?></h1>  
            <?php endif; ?>  
            <div class="gigItem">  
				<?php $artist = $artistsByNum[$gigs_events['artist']] ?>  
                <?php foreach ($artist['image'] as $upload): ?>  
                    <img src="<?php echo $upload['urlPath'] ?>" style="float:left; margin-right:20px;">  
                <?php endforeach ?>  
                <h2><?php echo $gigs_events['artist:label'] ?><br />   
                <?php if ($gigs_events['location'] == 'Manly'): ?>at Manly  
                <?php elseif ($gigs_events['location'] == 'Brewery'): ?>at Bob's Farm  
                <?php endif ?></h2>  
                <?php echo date("l jS", strtotime($gigs_events['date'])) ?>, <?php echo $gigs_events['time'] ?><br />  
                <p><?php echo $gigs_events['description'] ?><p>  
                <?php if ($artist['url']): ?><a href="<?php echo $artist['url'] ?>" target="_blank"><img src="../assets/images/link_website.png" alt="Website"></a><?php endif ?>  
                <?php if ($artist['facebook']): ?><a href="<?php echo $artist['facebook'] ?>" target="_blank"><img src="../assets/images/link_facebook.png" alt="Facebook"></a><?php endif ?>  
                <?php if ($artist['twitter']): ?><a href="<?php echo $artist['twitter'] ?>" target="_blank"><img src="../assets/images/link_twitter.png" alt="Twitter"></a><?php endif ?>  
                      
                <div class="clearfix"></div>
            </div>
			<?php $lastMonth = date("M", strtotime($gigs_events['date'])); ?>  
			<?php endforeach ?>  
          
            <?php if (!$gigs_eventsRecords): ?>  
              Nada - come back soon!  
            <?php endif ?>
            </div>
    </div>
	<div id="leftcol">
        <?php include_once("../_insertSideNavigation.php") ?>
    </div>
  </div>
<?php include_once("../_insertFooter.php") ?>
