<?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 */
  require_once "/var/www/thishost/yourdomain.com/httpdocs/CMSbuilder/lib/viewer_functions.php";

?> 
<?PHP  
  function maxWords($textOrHtml, $maxWords) { 
    $text=str_replace("<p>","*P*",$textOrHtml); 
    $text= str_replace("</p>","*/P*",$text); 
    $text = strip_tags($text);   
    $words = preg_split("/\s+/", $text, $maxWords+1);   
    if (count($words) > $maxWords) { unset($words[$maxWords]); }   
    $output = join(' ', $words);   
    $output=str_replace("*P*","<p>",$output); 
    $output=str_replace("*/P*","</p>",$output); 
    $output.="</p>"; 
 
    return $output;   
  }   
?>
<!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"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Zickey Calendar</title>
<link rel="stylesheet" href="css/zickey_calendar.css" type="text/css" />
</head> 
 
<body> 
<div id="cal_container"> 
<!-- calendar --> 
<?php 
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); 
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); 
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); 
 
$cMonth = $_REQUEST["month"]; 
$cYear = $_REQUEST["year"]; 
 
$prev_year = $cYear; 
$next_year = $cYear; 
 
$prev_month = $cMonth-1; 
$next_month = $cMonth+1; 
 
if ($prev_month == 0 ) { 
$prev_month = 12; 
$prev_year = $cYear - 1; 
} 
if ($next_month == 13 ) { 
$next_month = 1; 
$next_year = $cYear + 1; 
} 
 
// get event records for the selected month 
list($eventsRecords, $eventsMetaData) = getRecords(array( 
  'tableName' => 'events', 
  'where'     => mysql_escapef('MONTH(date) = ? AND YEAR(date) = ?', $cMonth, $cYear), 
)); 
 
// organize events into an array indexed by 'day', each element being a list of events on that day 
$eventsByDay = array(); 
foreach ($eventsRecords as $event) {  
  $day = intval(date('d', strtotime($event['date'])));
  if (!array_key_exists($day, $eventsByDay)) { $eventsByDay[$day] = array(); } 
  $eventsByDay[$day][] = $event; 
} 
 
?> 
<div id="calendar_div" name="calendar_div"> 
<table border="0" cellpadding="1" cellspacing="0" bgcolor="#333333"> 
<tr align="center"> 
<td bgcolor="#333333"><table width="100%" border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td width="50%" align="left">&nbsp;&nbsp;<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" class="CalNextPrevious">Previous</a></td> 
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" class="CalNextPrevious">Next</a>&nbsp;&nbsp;</td> 
</tr> 
</table></td> 
</tr> 
<tr> 
<td align="center"><table border="0" cellpadding="0" cellspacing="0" id="CalTB"> 
<tr align="center"> 
<td colspan="7" class="CalMonth" ><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></td> 
</tr> 
<tr> 
<td class="CalDayofWeek">Sunday</td> 
<td class="CalDayofWeek">Monday</td> 
<td class="CalDayofWeek">Tuesday</td> 
<td class="CalDayofWeek">Wednesday</td> 
<td class="CalDayofWeek">Thursday</td> 
<td class="CalDayofWeek">Friday</td> 
<td class="CalDayofWeek">Saturday</td> 
</tr> 
<?php 
$timestamp = mktime(0,0,0,$cMonth,1,$cYear); 
$maxday = date("t",$timestamp); 
$thismonth = getdate ($timestamp); 
$startday = $thismonth['wday']; 
 
for ($i=0; $i<($maxday+$startday); $i++) { 
if(($i % 7) == 0 ) echo "<tr>\n"; 
if($i < $startday) { 
  echo "<td></td>\n"; 
} 
else { 
  $day = $i - $startday + 1; 
  echo "<td class='CalDates'><div id='CalDateBox'>". $day . "</div>"; 
  // check if there are any events for this day 
  if (array_key_exists($day, $eventsByDay)) { 
    // list all events for this day 
    foreach ($eventsByDay[$day] as $record) { 
      ?> <div id="calFonts">
        <h1><?php echo $record['title'] ?></h1> 
        <h3>Time: <?php echo date("g:i:s a", strtotime($record['date'])) ?></h3>
		<!--<h3>Where: <?php echo $record['location'] ?></h3>--> 
        <p><!--Description: --><?php echo maxWords($record['description'], 12); ?><!--<?php echo $record['description'] ?>--></p> 
         
       <!-- <p>Content: <?php echo $record['content'] ?></p>--> 
        <p><strong>Details: <a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></strong></p> </div>
      <?php 
    } 
  } 
  echo "</td>\n"; 
} 
if(($i % 7) == 6 ) echo "</tr>\n"; 
} 
?> 
 
</table></td> 
</tr> 
</table> 
<br /> 
<!-- /calendar --></div> 
<!-- /container --></div> 
</body> 
</html>