<?
    require_once('control/include/user.php');
	require_once('control/include/mysql.php');
	require_once('control/include/functions.php');
	require_once('control/include/fb.php');
	
	ob_start();
	session_start();
	
	// SETUP MYSQL HANDLERS
	$mysqldb1 = new mysql($host, $user, $pswd, $db); $mysqldb1->connect(); $mysqldb1->select();
?>
<!-- <div class="column_module"> -->
<!-- <div class="column_module_heading">Event Calendar</div> -->
<?
	$time = time(); 

	if ($_GET['go'] == 'next') { 
		$_SESSION['month']++;
	} elseif ($_GET['go'] == 'prev') { 
		$_SESSION['month']--;
	} else {
		if ($_GET['year'] == '') { $_SESSION['year'] = date('Y', $time); } else { $_SESSION['year'] = $_GET['year']; }
		if ($_GET['month'] == '') { $_SESSION['month'] = date('n', $time); } else { $_SESSION['month'] = $_GET['month']; }
	}
	
	if ($_SESSION['month'] == 13) { $_SESSION['month'] = 1; $_SESSION['year']++; }
	if ($_SESSION['month'] == 0) { $_SESSION['month'] = 12; $_SESSION['year']--; }
	
	fb('MONTH: '.$_SESSION['month']);
	fb('YEAR: '.$_SESSION['year']);
	
	$today = date('j', $time); 
	if (($_SESSION['month'] == date('n', $time)) and ($_SESSION['year'] == date('Y', $time))) {
		$days[$today] = array(NULL, 'calendar_today', $today);
	}
	$query = "
	SELECT 
		id, 
		DATE_FORMAT(start_date, '%e') AS day_int, 
		DATE_FORMAT(start_date, '%c') AS month_int, 
		DATE_FORMAT(start_date, '%Y') AS year_int 
	FROM 
		event 
	WHERE 
		DATE_FORMAT(start_date, '%c')=".$_SESSION['month']." AND 
		DATE_FORMAT(start_date, '%Y')=".$_SESSION['year']." AND 
		start_date!='0000-00-00' AND 
		status='enabled' 
	ORDER BY 
		day_int ASC";
	//fb($query);
	$mysqldb1->query($query);
	$event_records = $mysqldb1->affectedRows();
	while ($row1 = $mysqldb1->fetchObject()) {
		$days[$row1->day_int] = array('/events/'.$row1->year_int.'/'.$row1->month_int.'/'.$row1->day_int, 'calendar_day_link');
	}
	
	$navigate = array('<img src="/website/styles/default/calendar_prev.png" border="0" />' => 'javascript:prevMonth();', '<img src="/website/styles/default/calendar_next.png" border="0" />' => 'javascript:nextMonth();');
	
	$month_href = '';
	if ($event_records > 0) {
		$month_href = '/events/'.$_SESSION['year'].'/'.$_SESSION['month'];
	}
?>
<!-- <div class="column_module_body"> -->
<?
	print generate_calendar($_SESSION['year'], $_SESSION['month'], $days, 2, $month_href, 0, $navigate);
?>
<!-- </div> -->
<!-- </div> -->
<?
	$mysqldb1->close();
?>
        
      
