###################################################################### ###### # Genric setup code ###### global $gIncludePath; unset($gIncludePath); include_once("./php/LocalSettings.php"); $include_path = ini_get("include_path"); ini_set("include_path", "$gIncludePath:$include_path"); include_once("Setup.php"); $monthName = array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December "); ###### # If we arrive with a campaign code, store it in a cookie ###### $campaignCode = trim($_REQUEST['c']); if ($campaignCode && preg_match("/^[a-zA-Z0-9]+$/", $campaignCode)) { if (!$_COOKIE["rbcc_$campaignCode"]) { $sql = "update rb12CampaignCode set num_landings=num_landings+1 WHERE code='".dbStrencode($campaignCode)."'"; $res = $gDB->query($sql);
setcookie("code", $campaignCode, time()+86400);
}
} else {
if ($_COOKIE['code']) { $campaignCode = $_COOKIE['code']; }
}
if ($campaignCode) {
setcookie("rbcc_$campaignCode", 1, time()+86400);
}
######
# Get all list of months + years
######
$sql = "select distinct year(showDate) as showYear,month(showDate) as showMonth from rb12Schedule where (public=1) and (datediff(now(),showDate) <= 0) order by showDate"; $res = $gDB->query($sql);
$showDates = array();
while ($row = $gDB->fetchObject($res)) {
$row->{showDate} = sprintf("%04d-%02d-01", $row->{'showYear'}, $row->{'showMonth'});
$showDates[] = $row;
}
######
# Get calendar HTML for each month
######
$calendars = array();
foreach ($showDates as $showDate) {
# Limit to shows for this month
$sql = "SELECT *,DATEDIFF(NOW(),modified) AS age FROM rb12Schedule WHERE (YEAR(showDate)={$showDate->{'showYear'}}) AND (MONTH(showDate)={$showDate->{'showMonth'}}) AND (public=1)";
$res = $gDB->query($sql);
$shows = array();
while ($row = $gDB->fetchObject($res)) {
list($y,$m,$d) = explode('-', $row->{showDate});
$d = intval($d);
if (!array_key_exists($d, $shows)) { $shows[$d] = array(); }
$shows[$d][] = $row;
}
$html = drawCalendar($showDate->{'showMonth'}, $showDate->{'showYear'}, $shows);
$calendars[] = array ('year' => $showDate->{'showYear'}, 'month' => $showDate->{'showMonth'}, 'showDate' => $showDate->{'showDate'}, 'html' => $html );
}
######
# Display the page
######
$gSmarty->assign("calendars", $calendars);
$gSmarty->display("calendar.tpl");
exit;
######################################################################
######################################################################
# drawCalendar($month, $year)
#
function drawCalendar( $month, $year, $shows ) {
$html = "";
$today = date('Ymd');
$firstDay = date('w',mktime(0,0,0,$month,1,$year));
$numDaysInMonth = date('t',mktime(0,0,0,$month,1,$year));
$count = 0;
$doDates = 1;
$day = 1 - $firstDay;
$done = 0;
$html .= "
";
while (($day <= $numDaysInMonth) || $doDates) { if ($count == 7) { $lst_td = "";} else { $lst_td = ""; } # First time through, do the date numbers. Second time through, do the show content. if ($doDates) { if (($day <= 0) || ($day> $numDaysInMonth)) {
$html .= " ";
} else {
$html .= " $day";
}
} else {
if (($day <= 0) || ($day> $numDaysInMonth)) {
$html .= " ";
} else {
$showDate = sprintf("%04d%02d%02d", $year, $month, $day);
# Get shows. See if sold out or not. Etc.
if ($shows[$day]) {
$show_html = "";
# Sort our shows for this day by time
$day_shows = $shows[$day];
uasort($day_shows, 'byTime');
$last_artist = "";
foreach($day_shows as $show) {
if ($show->age <= 3) { $new = "
NEW"; } else { $new = ""; }
if (!$last_artist || ($show->artistName != $last_artist)) {
$show_html .= "$new
{$show->artistName}id}\">{$show->showTime} ";
} else {
$show_html .= "
id}\">{$show->showTime}
";
}
$last_artist = $show->artistName;
}
} else {
$show_html = " ";
}
# If the date is before today, use an "expired" class
if ($showDate < $today) { $expire=" "; } else { $expire="";} $html .= " $show_html";
}
}
$count++;
$day++;
if ($count == 7) {
$count = 0;
$html .= " ";
if ($doDates) {
$doDates = 0;
$day -= 7;
$html .= "";
} else {
if ($day <= $numDaysInMonth) { $doDates = 1; $html .= "
";
$done = 1;
}
}
}
}
# Finish month with blank spaces
if (!$done) {
while ($count < 7) { $html .= " (d{$count})";
$count++;
}
$html .= "
";
}
return $html;
}
######################################################################
######################################################################
# byTime($a, $b)
# A user-callback sort comparison function expecting the values of
# show rows/objects to sort by time (noting am/pm).
#
function byTime($a, $b) {
$showtime_a = $a->{showTime};
$showtime_b = $b->{showTime};
$timea = 0;
$timeb = 0;
if (preg_match("/(\d+)(:(\d+))?\s*(AM|PM)?/i", $showtime_a, $m)) {
$hra = $m[1];
$mna = $m[3];
$ta = strtoupper($m[4]);
# Assume PM
if ($ta == "") { $ta = "PM"; }
# Go military time on hours
if (($ta == "PM") && ($hra < 12)) { $hra += 12; } # For AM shows, put them *after* PM shows, these are early morning shows if (($ta == "AM") && (($hra < 8) || ($hra == 12))) { $hra += 24; } # Calculate a decimal time to use in sort comparison $timea = $hra + $mna / 60; } if (preg_match("/(\d+)(:(\d+))?\s*(AM|PM)?/i", $showtime_b, $m)) { $hrb = $m[1]; $mnb = $m[3]; $tb = strtoupper($m[4]); # Assume PM if ($tb == "") { $tb = "PM"; } # Go militbry time on hours if (($tb == "PM") && ($hrb < 12)) { $hrb += 12; } # For AM shows, put them *after* PM shows, these are early morning shows if (($tb == "AM") && (($hrb < 8) || ($hrb == 12))) { $hrb += 24; } # Calculate a decimal time to use in sort comparison $timeb = $hrb + $mnb / 60; } if ($timea == $timeb) { return 0; } return ($timea < $timeb) ? -1 : 1; } ###################################################################### ?>