<?php
// $Id: calendar.php,v 1.30.2.4 2002/07/11 16:45:15 epsilon7 Exp $
/********************************************************/
/* PostCalendar */
/* Version 2.6, see changes.txt for details */
/* Originally by Rob Sutton (Events Calendar) */
/* Development continued by */
/* */
/* The PostCalendar Development Team */
/* Mahmood Al-Yousif - hide@address.com */
/* Craig Hamlin - hide@address.com */
/* HotBird - hide@address.com */
/* Roger Raymond - hide@address.com */
/* */
/* This program is opensource so you can do whatever */
/* you want with it. However, I'm happy about any */
/* clever idea or nifty change you might have or have */
/* done, send them to */
/* hide@address.com */
/* */
/* Any new versions can be found at */
/* http://www.bahraini.tv first */
/********************************************************/
/**
* initialise block
*/
function PostCalendar_calendarblock_init()
{
// Security
pnSecAddSchema('PostCalendar:calendarblock:', 'Block title::');
}
/**
* get information on block
*/
function PostCalendar_calendarblock_info()
{
// Values
return array('text_type' => 'PostCalendar',
'module' => 'PostCalendar',
'text_type_long' => 'Calendar Block',
'allow_multiple' => true,
'form_content' => false,
'form_refresh' => false,
'show_preview' => true);
}
/**
* display block
*/
function PostCalendar_calendarblock_display($blockinfo)
{
// start the output container
$output = new pnHTML();
$output->SetInputMode(_PNH_VERBATIMINPUT);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
// You supposed to be here?
if (!pnSecAuthAction(0,'PostCalendar:calendarblock:',"$blockinfo[title]::",ACCESS_READ)) {
$output->Text(_PCB_NOAUTH);
return $output->GetOutput();
}
pnThemeLoad(pnUserGetTheme());
// get the theme globals :: is there a better way to do this?
global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5;
global $textcolor1, $textcolor2;
// if we've not been given a date, get the current one
if(!isset($Date)) {
//$Date = date('m/d/Y');
// this gets the correct user date
$time = time();
$time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
$Date = ml_ftime('%m/%d/%Y',$time);
//print($Date);
}
// get DB information
pnModDBInfoLoad('PostCalendar');
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
// link to the events tables
$events_table = $pntable['postcalendar_events'];
$events_column = &$pntable['postcalendar_events_column'];
// link to the topics table
$topics_table = $pntable['topics'];
$topics_column = &$pntable['topics_column'];
// let's load the User API so we can use it
if(!pnModAPILoad('PostCalendar','user')) {
die('Could not load PostCalendar user API');
}
// this should make things a bit clearer later on
//define('_EVENT_NONE' , -1);
//define('_EVENT_DAILY', 0);
//define('_EVENT_WEEKLY', 1);
//define('_EVENT_MONTHLY', 2);
//define('_EVENT_YEARLY', 3);
//define('_IS_SUNDAY', 0);
//define('_IS_MONDAY', 1);
//define('_IS_SATURDAY', 2);
//define('_RECUR_SAME_DAY', 0);
//define('_RECUR_SAME_DATE', 1);
// grab the modules information
$modinfo = pnModGetInfo(pnModGetIDFromName('PostCalendar'));
// Get variables from content block
$vars = pnBlockVarsFromContent($blockinfo['content']);
// set some variables
$bid = $blockinfo['bid'];
// block specific vars
$usepopups = pnModGetVar('PostCalendar_block_'.$bid,'pcbusepopups');
$showcalendar = pnModGetVar('PostCalendar_block_'.$bid,'pcbshowcalendar');
$showevents = pnModGetVar('PostCalendar_block_'.$bid,'pcbeventoverview');
$showcomingevents = pnModGetVar('PostCalendar_block_'.$bid,'pcbshowcomingevents');
$eventslimit = pnModGetVar('PostCalendar_block_'.$bid,'pcbeventslimit');
$nextevents = pnModGetVar('PostCalendar_block_'.$bid,'pcbnextevents');
$pcbshowdates = pnModGetVar('PostCalendar_block_'.$bid,'pcbeventsdatedisplay');
$pcbshowsslinks = pnModGetVar('PostCalendar_block_'.$bid,'pcbshowsslinks');
// postcalendar global vars
$useinternationaldates = pnModGetVar('PostCalendar','useinternationaldates');
$eventsopeninnewwindow = pnModGetVar('PostCalendar','eventsopeninnewwindow');
$dayhighlightcolor = pnModGetVar('PostCalendar','dayhighlightcolor');
$firstdayofweek = pnModGetVar('PostCalendar','firstdayofweek');
$displayballs = pnModGetVar('PostCalendar','displayballs');
// load the DHTML JavaScript code and insert it into the page
if ($usepopups) {
$output->Text(pnModAPIFunc('PostCalendar','user','loadPopups'));
}
// insert the js popup code into the page
if($eventsopeninnewwindow) {
$output->Text(pnModAPIFunc('PostCalendar','user','jsPopup'));
}
// Let's setup the info to build this sucka!
list($the_month,$the_day,$the_year) = explode('/',$Date);
// set up the next and previous months to move to
$prev_month = date('m/d/Y',mktime(0,0,0,$the_month-1,1,$the_year));
$next_month = date('m/d/Y',mktime(0,0,0,$the_month+1,1,$the_year));
$last_day = date('t',mktime(0,0,0,$the_month,1,$the_year));
$first_day = date('w',mktime(0,0,0,$the_month,1,$the_year));
//*******************************************************************
// Here we get the events for the current month view
//*******************************************************************
$day_of_week = 1;
$pc_short_day_names = array(_CALSUNDAYSHORT,
_CALMONDAYSHORT,
_CALTUESDAYSHORT,
_CALWEDNESDAYSHORT,
_CALTHURSDAYSHORT,
_CALFRIDAYSHORT,
_CALSATURDAYSHORT);
switch ($firstdayofweek)
{
case _IS_SUNDAY:
$pc_array_pos = 0;
$first_day = date('w',mktime(0,0,0,$the_month,1,$the_year));
break;
case _IS_MONDAY:
$pc_array_pos = 1;
$first_day = date('w',mktime(0,0,0,$the_month,0,$the_year));
break;
case _IS_SATURDAY:
$pc_array_pos = 6;
$first_day = date('w',mktime(0,0,0,$the_month,2,$the_year));
break;
default:
$pc_array_pos = 0;
$first_day = date('w',mktime(0,0,0,$the_month,1,$the_year));
break;
}
$sql = "SELECT $events_column[eid],
$events_column[title],
$events_column[hometext],
$events_column[eventDate],
$events_column[endDate],
$events_column[startTime],
$events_column[endTime],
$events_column[barcolor],
$events_column[recurrtype],
$events_column[recurrfreq],
$events_column[topic],
$events_column[alldayevent]
FROM $events_table
WHERE $events_column[eventstatus] = 1
ORDER BY $events_column[eventDate], $events_column[startTime] ASC";
//WHERE ($events_column[eventDate] >= '$the_year-$the_month-1' OR $events_column[endDate] <= '$the_year-$the_month-$last_day')
$result = $dbconn->Execute($sql);
// put the information into an array for easy access
$events = array();
if($result) {
for($i=0; !$result->EOF; $result->MoveNext()) {
list($eid,$title,$hometext,$eventDate,$endDate,$startTime,$endTime,$barcolor,$recurrtype,$recurrfreq,$topic,$alldayevent) = $result->fields;
$events[$i]['eid'] = $eid;
$events[$i]['title'] = $title;
$events[$i]['hometext'] = $hometext;
$events[$i]['eventDate'] = $eventDate;
$events[$i]['endDate'] = $endDate;
$events[$i]['startTime'] = $startTime;
$events[$i]['endTime'] = $endTime;
$events[$i]['barcolor'] = $barcolor;
$events[$i]['recurrtype'] = $recurrtype;
$events[$i]['recurrfreq'] = $recurrfreq;
$events[$i]['topic'] = $topic;
$events[$i]['alldayevent'] = $alldayevent;
$i++;
}
}
if($showcalendar) {
//*******************************************************************
// START month header and navigation
// << MONTH YEAR >>
//*******************************************************************
$output->Text('<table border="0" cellpadding="0" cellspacing="1" width="100%"><tr><td bgcolor="'.$bgcolor2.'">');
$output->Text('<table border="0" cellpadding="1" cellspacing="1" width="100%"><tr><td colspan="8" bgcolor="'.$bgcolor1.'">');
$output->TableStart();
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$pc_prev = pnModURL('PostCalendar','user','view',array('viewtype'=>'month','Date'=>$prev_month));
$pc_next = pnModURL('PostCalendar','user','view',array('viewtype'=>'month','Date'=>$next_month));
$pc_prev_url = $output->URL($pc_prev,'<<');
$pc_next_url = $output->URL($pc_next,'>>');
$pc_month_name = pnModAPIFunc('PostCalendar',
'user',
'getmonthname',
array('Date'=>mktime(0,0,0,$the_month,$the_day,$the_year)));
$month_link_url = pnModURL('PostCalendar',
'user',
'view',
array('viewtype'=>'month','Date'=>date('m/d/Y',mktime(0,0,0,$the_month,1,$the_year))));
$month_link_text = $pc_month_name.' '.$the_year;
$pc_link = $output->URL($month_link_url,$month_link_text);
$row = array();
$row[0]['content'] = $pc_prev_url;
$row[0]['align'] = 'left';
$row[0]['valign'] = 'middle';
$row[1]['content'] = $pc_link;
$row[1]['align'] = 'center';
$row[1]['valign'] = 'middle';
$row[2]['content'] = $pc_next_url;
$row[2]['align'] = 'right';
$row[2]['valign'] = 'middle';
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->TableAddRow($row);
$output->TableEnd();
$output->Text('</td></tr>');
//*******************************************************************
// END month header and navigation
// << Prev MONTH YEAR Next >>
//*******************************************************************
//*******************************************************************
// START CALENDAR TABLE
//*******************************************************************
// build the long day name header row
$header_width = 100/8;
$output->Text('<td align="center" bgcolor="'.$bgcolor1.'"width="'.$header_width.'%"> </td>');
$daynames_row = '';
for($i=0; $i < count($pc_short_day_names); $i++)
{
if($pc_array_pos >= count($pc_short_day_names)) {
$pc_array_pos = 0;
}
$daynames_row .= '<td align="center" bgcolor="'.$bgcolor1.'"width="'.$header_width.'%">';
$daynames_row .= $pc_short_day_names[$pc_array_pos];
$daynames_row .= '</td>';
$pc_array_pos++;
}
$output->Text($daynames_row);
//*******************************************************************
// Previous Month Grayed Out Days
//*******************************************************************
$day_of_week = 1;
$week_displayed = false;
while ($day_of_week <= $first_day) {
if (!$week_displayed) {
$output->Text('<tr><td valign="top">');
$week = date('Y-m-d',mktime(0,0,0,$the_month,$day_of_week-$first_day,$the_year));
$week_result = $dbconn->Execute("SELECT WEEK('$week')");
list($week) = $week_result->fields;
if ($firstdayofweek == _IS_SATURDAY) {
$week++;
}
if($week > 52) {
$week = 1;
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$this_date = date('m/d/Y',mktime(0,0,0,$the_month,$day_of_week-$first_day,$the_year));
$week_url = pnModURL('PostCalendar','user','view',array('viewtype'=>'week','Date'=>$this_date));
$week_link = $output->URL($week_url,'>>');
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->Text($week_link);
$output->Text('</td>');
$week_displayed = true;
continue;
}
$output->Text('<td bgcolor="'.$bgcolor2.'" align="center" valign="top">');
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$past_day = date('d',mktime(0,0,0,$the_month,$day_of_week-$first_day,$the_year));
$this_date = date('m/d/Y',mktime(0,0,0,$the_month,$day_of_week-$first_day,$the_year));
$day_url = pnModURL('PostCalendar','user','view',array('viewtype'=>'day','Date'=>$this_date));
$day_link = $output->URL($day_url,$past_day);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->Text($day_link);
$output->Text('</td>');
$day_of_week++;
}
//*******************************************************************
// Main Calendar Display Area
//*******************************************************************
$day = 1;
while ($day <= $last_day) {
if (!$week_displayed) {
$output->Text('<tr><td valign="top" bgcolor="'.$bgcolor1.'">');
$week = date('Y-m-d',mktime(0,0,0,$the_month,$day,$the_year));
$week_result = $dbconn->Execute("SELECT WEEK('$week')");
list($week) = $week_result->fields;
if ($firstdayofweek == _IS_SATURDAY) {
$week++;
}
if($week > 52) {
$week = 1;
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$this_date = date('m/d/Y',mktime(0,0,0,$the_month,$day,$the_year));
$week_url = pnModURL('PostCalendar','user','view',array('viewtype'=>'week','Date'=>$this_date));
$week_link = $output->URL($week_url,'>>');
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->Text($week_link);
$output->Text('</td>');
$week_displayed = true;
continue;
}
$highlight = date('d',mktime(0,0,0,$the_month,$day,$the_year)) == $the_day ? $dayhighlightcolor : $bgcolor1;
$output->Text('<td bgcolor="'.$highlight.'" align="center" valign="top">');
// *** Here's where we fill in the content for each day *** //
$events_found = 0;
$poptext = '';
for($i=0; $i<count($events); $i++) {
// start the tests
$this_date = date('m/d/Y',mktime(0,0,0,$the_month,$day,$the_year));
list($this_month,$this_day,$this_year) = explode('/',$this_date);
$compare_to_date = $the_year.'-'.$the_month.'-'.$this_day;
switch ($events[$i]['recurrtype']) {
case _EVENT_NONE :
// display an event on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
$events_found++;
if(!empty($poptext)) $poptext .= '<br /><br />';
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$poptext .= $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
array('event'=>$events[$i],
'dayofweek'=>1,
'forblock'=>true,
'usepopups'=>$usepopups)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
break;
case _EVENT_DAILY :
// display an event on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
$events_found++;
if(!empty($poptext)) $poptext .= '<br /><br />';
//list($eid,$title,$topic,$eventDate,$endDate,$startTime,$endTime) = $result->fields;
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$poptext .= $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
array('event'=>$events[$i],
'dayofweek'=>1,
'forblock'=>true,
'usepopups'=>$usepopups)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
break;
case _EVENT_WEEKLY :
// display an event weekly on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
list($event_year,$event_month,$event_day) = explode('-',$events[$i]['eventDate']);
$current_week_day = date('w',mktime(0,0,0,$this_month,$this_day,$this_year));
$event_week_day = date('w',mktime(0,0,0,$event_month,$event_day,$event_year));
if($current_week_day === $event_week_day) {
$events_found++;
if(!empty($poptext)) $poptext .= '<br><br>';
list($eid,$title,$topic,$eventDate,$endDate,$startTime,$endTime) = $result->fields;
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$poptext .= $output->Text(pnModAPIFunc('PostCalendar',
'user',
'createEventLink',
array('event'=>$events[$i],
'dayofweek'=>1,
'forblock'=>true,
'usepopups'=>$usepopups)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
break;
case _EVENT_MONTHLY :
// display an event once a month on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
list($event_year,$event_month,$event_day) = explode('-',$events[$i]['eventDate']);
/**
* Display event on same WEEK DAY each Month
* This will cause a monthly event to always show on the same day of the month
* If an event is started on the 1st Monday, it will always display on the 1st Monday
* of each month for it's duration.
*/
if($events[$i]['recurrfreq'] == _RECUR_SAME_DAY) {
$current_day_of_week = date('w',mktime(0,0,0,$this_month,$this_day,$this_year));
$event_day_of_week = date('w',mktime(0,0,0,$event_month,$event_day,$event_year));
$event_day_occurance=0;
for($d=1; $d<=$event_day; $d++) {
$current_day = date('w',mktime(0,0,0,$event_month,$d,$event_year));
if($current_day === $event_day_of_week) {
$event_day_occurance++;
}
}
$curr_day = date('d',mktime(0,0,0,$this_month,$this_day,$this_year));
$current_day_occurance=0;
for($d=1; $d<=$curr_day; $d++) {
$current_day = date('w',mktime(0,0,0,$this_month,$d,$this_year));
if($current_day === $current_day_of_week) {
$current_day_occurance++;
}
}
if($current_day_occurance === $event_day_occurance && $current_day_of_week === $event_day_of_week) {
$events_found++;
if(!empty($poptext)) $poptext .= '<br /><br />';
//list($eid,$title,$topic,$eventDate,$endDate,$startTime,$endTime) = $result->fields;
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$poptext .= $output->Text(pnModAPIFunc('PostCalendar',
'user',
'createEventLink',
array('event'=>$events[$i],
'dayofweek'=>1,
'forblock'=>true,
'usepopups'=>$usepopups)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
/**
* Display event on same DATE each Month
* This will cause a monthly event to always show on the same date of the month
* If an event is started on the 25th of the Month it will always display
* on the 25th of each month for its duration
* (this is not yet implemented as it needs DB changes
*/
if($events[$i]['recurrfreq'] == _RECUR_SAME_DATE) {
if($this_day === $event_day) {
$events_found++;
if(!empty($poptext)) $poptext .= '<br /><br />';
//list($eid,$title,$topic,$eventDate,$endDate,$startTime,$endTime) = $result->fields;
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$poptext .= $output->Text(pnModAPIFunc('PostCalendar',
'user',
'createEventLink',
array('event'=>$events[$i],
'dayofweek'=>1,
'forblock'=>true,
'usepopups'=>$usepopups)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
}
break;
case _EVENT_YEARLY :
// display an event once a year on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
list($event_year,$event_month,$event_day) = explode('-',$events[$i]['eventDate']);
/**
* Display event on same WEEK DAY each Month
* This will cause a monthly event to always show on the same day of the month
* If an event is started on the 1st Monday, it will always display on the 1st Monday
* of each month for it's duration.
*/
if($events[$i]['recurrfreq'] == _RECUR_SAME_DAY) {
$current_day_of_week = date('w',mktime(0,0,0,$this_month,$this_day,$this_year));
$event_day_of_week = date('w',mktime(0,0,0,$event_month,$event_day,$event_year));
$event_day_occurance=0;
for($d=1; $d<=$event_day; $d++) {
$current_day = date('w',mktime(0,0,0,$event_month,$d,$event_year));
if($current_day === $event_day_of_week) {
$event_day_occurance++;
}
}
$curr_day = date('d',mktime(0,0,0,$this_month,$this_day,$this_year));
$current_day_occurance=0;
for($d=1; $d<=$curr_day; $d++) {
$current_day = date('w',mktime(0,0,0,$this_month,$d,$this_year));
if($current_day === $current_day_of_week) {
$current_day_occurance++;
}
}
if( $current_day_occurance === $event_day_occurance
&& $current_day_of_week === $event_day_of_week
&& $this_month === $event_month) {
$events_found++;
if(!empty($poptext)) $poptext .= '<br /><br />';
//list($eid,$title,$topic,$eventDate,$endDate,$startTime,$endTime) = $result->fields;
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$poptext .= $output->Text(pnModAPIFunc('PostCalendar',
'user',
'createEventLink',
array('event'=>$events[$i],
'dayofweek'=>1,
'forblock'=>true,
'usepopups'=>$usepopups)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
/**
* Display event on same DATE each Month
* This will cause a monthly event to always show on the same date of the month
* If an event is started on the 25th of the Month it will always display
* on the 25th of each month for its duration
* (this is not yet implemented as it needs DB changes
*/
if($events[$i]['recurrfreq'] == _RECUR_SAME_DATE) {
if( $this_day === $event_day
&& $this_month === $event_month) {
$events_found++;
if(!empty($poptext)) $poptext .= '<br /><br />';
//list($eid,$title,$topic,$eventDate,$endDate,$startTime,$endTime) = $result->fields;
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$poptext .= $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
array('event'=>$events[$i],
'dayofweek'=>1,
'forblock'=>true,
'usepopups'=>$usepopups)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
}
break;
default:
break;
}
}
if($usepopups) {
if($blockinfo['position'] == 'l') {
$align = 'RIGHT';
} elseif($blockinfo['position'] == 'r') {
$align = 'LEFT';
} else {
$align = 'CENTER';
}
if(!empty($poptext)) {
$poptext = preg_replace('/[\r\n]/','',$poptext);
if($useinternationaldates) {
$caption = date('d/m/Y',mktime(0,0,0,$the_month,$day,$the_year));
} else {
$caption = date('m/d/Y',mktime(0,0,0,$the_month,$day,$the_year));
}
$popuptext = "onmouseover=\"return overlib('".$poptext."',CAPTION,'$caption',$align);\" onmouseout=\"return nd();\"";
} else {
$popuptext = '';
}
} else {
$popuptext = '';
}
// ok build the day
$this_date = date('m/d/Y',mktime(0,0,0,$the_month,$day,$the_year));
$day_date = date('d',mktime(0,0,0,$the_month,$day,$the_year));
$day_link = pnModURL('PostCalendar','user','view',array('viewtype'=>'day','Date'=>$this_date));
$output->Text("<a href=\"$day_link\" $popuptext>$day_date</a>");
if($displayballs) {
$ballnum = $events_found > 4 ? 4 : $events_found;
$pc_img_src = "<img width=\"13\" height=\"14\" border=\"0\" src=\"modules/$modinfo[directory]/pnimages/events$ballnum.gif\">";
$output->LineBreak();
$output->Text("<a href=\"$day_link\" $popuptext>$pc_img_src</a>");
}
// *** end content *** //
$output->Text('</td>');
$day++;
$day_of_week++;
if($day_of_week > 7) {
$day_of_week = 1;
$week_displayed = false;
$output->Text('</tr>');
}
}
//*******************************************************************
// Next Month Grayed Out Days
//*******************************************************************
$day=1;
while (($day_of_week <= 7) && ($day_of_week != 1)) {
$output->Text('<td bgcolor="'.$bgcolor2.'" align="center" valign="top">');
//$day = $day < 10 ? '0'.$day : $day;
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$this_date = date('m/d/Y',mktime(0,0,0,$the_month+1,$day,$the_year));
$day_date = date('d',mktime(0,0,0,$the_month+1,$day,$the_year));
$day_url = pnModURL('PostCalendar','user','view',array('viewtype'=>'day','Date'=>$this_date));
$day_link = $output->URL($day_url,$day_date);
$output->SetOutputMode(_PNH_KEEPOUTPUT);
$output->Text($day_link);
$output->Text('</td>');
$day_of_week++;
$day++;
}
//*******************************************************************
// END CALENDAR TABLE
//*******************************************************************
$output->Text('</tr></table>');
$output->Text('</td></tr></table>');
} // <----- end if showcalendar
if($showevents) {
//*******************************************************************
// START month header and navigation
// << MONTH YEAR >>
//*******************************************************************
if($showcalendar) { $output->Linebreak(); }
$output->Text('<table border="0" cellpadding="0" cellspacing="1" width="100%"><tr><td bgcolor="'.$bgcolor2.'">');
$output->Text('<table border="0" cellpadding="1" cellspacing="1" width="100%"><tr><td bgcolor="'.$bgcolor1.'">');
if($showcalendar) {
$output->TableStart();
$row = array();
$row[0]['content'] = '<b>'._PC_TODAYS_EVENTS.'</b>';
$row[0]['align'] = 'center';
$row[0]['valign'] = 'middle';
$output->TableAddRow($row);
$output->TableEnd();
$output->Text('</td></tr>');
$output->Text('<tr><td valign="top" align="left" bgcolor="'.$bgcolor1.'">');
}
// just align the popup
if($blockinfo['position'] == 'r') {
$align=6;
} elseif($blockinfo['position'] == 'l') {
$align=1;
} else {
$align=4;
}
$displayed_events = 0;
$display = '';
for($i=0; $i<count($events) && $displayed_events<$eventslimit; $i++) {
list($this_month,$this_day,$this_year) = explode('/',$Date);
$compare_to_date = $this_year.'-'.$this_month.'-'.$this_day;
switch ($events[$i]['recurrtype']) {
case _EVENT_NONE :
// display an event on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
$displayed_events++;
if(!empty($display)) {
$display .= '<br />';
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$display .= $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
array('event'=>$events[$i],
'dayofweek'=>$align,
'usepopups'=>$usepopups,
'showdates'=>$pcbshowdates)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
break;
case _EVENT_DAILY :
// display an event on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
$displayed_events++;
if(!empty($display)) {
$display .= '<br />';
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$display .= $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
array('event'=>$events[$i],
'dayofweek'=>$align,
'usepopups'=>$usepopups,
'showdates'=>$pcbshowdates)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
break;
case _EVENT_WEEKLY :
// display an event weekly on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
list($event_year,$event_month,$event_day) = explode('-',$events[$i]['eventDate']);
$current_week_day = date('w',mktime(0,0,0,$this_month,$this_day,$this_year));
$event_week_day = date('w',mktime(0,0,0,$event_month,$event_day,$event_year));
if($current_week_day === $event_week_day) {
$displayed_events++;
if(!empty($display)) {
$display .= '<br />';
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$display .= $output->Text(pnModAPIFunc('PostCalendar',
'user',
'createEventLink',
array('event'=>$events[$i],
'dayofweek'=>$align,
'usepopups'=>$usepopups,
'showdates'=>$pcbshowdates)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
break;
case _EVENT_MONTHLY :
// display an event once a month on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
list($event_year,$event_month,$event_day) = explode('-',$events[$i]['eventDate']);
/**
* Display event on same WEEK DAY each Month
* This will cause a monthly event to always show on the same day of the month
* If an event is started on the 1st Monday, it will always display on the 1st Monday
* of each month for it's duration.
*/
if($events[$i]['recurrfreq'] == _RECUR_SAME_DAY) {
$current_day_of_week = date('w',mktime(0,0,0,$this_month,$this_day,$this_year));
$event_day_of_week = date('w',mktime(0,0,0,$event_month,$event_day,$event_year));
$event_day_occurance=0;
for($d=1; $d<=$event_day; $d++) {
$current_day = date('w',mktime(0,0,0,$event_month,$d,$event_year));
if($current_day === $event_day_of_week) {
$event_day_occurance++;
}
}
$curr_day = date('d',mktime(0,0,0,$this_month,$this_day,$this_year));
$current_day_occurance=0;
for($d=1; $d<=$curr_day; $d++) {
$current_day = date('w',mktime(0,0,0,$this_month,$d,$this_year));
if($current_day === $current_day_of_week) {
$current_day_occurance++;
}
}
if($current_day_occurance === $event_day_occurance && $current_day_of_week === $event_day_of_week) {
$displayed_events++;
if(!empty($display)) {
$display .= '<br />';
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$display .= $output->Text(pnModAPIFunc('PostCalendar',
'user',
'createEventLink',
array('event'=>$events[$i],
'dayofweek'=>$align,
'usepopups'=>$usepopups,
'showdates'=>$pcbshowdates)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
/**
* Display event on same DATE each Month
* This will cause a monthly event to always show on the same date of the month
* If an event is started on the 25th of the Month it will always display
* on the 25th of each month for its duration
* (this is not yet implemented as it needs DB changes
*/
if($events[$i]['recurrfreq'] == _RECUR_SAME_DATE) {
if($this_day === $event_day) {
$displayed_events++;
if(!empty($display)) {
$display .= '<br />';
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$display .= $output->Text(pnModAPIFunc('PostCalendar',
'user',
'createEventLink',
array('event'=>$events[$i],
'dayofweek'=>$align,
'usepopups'=>$usepopups,
'showdates'=>$pcbshowdates)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
}
break;
case _EVENT_YEARLY :
// display an event once a year on a certain day
if($events[$i]['eventDate'] <= $compare_to_date && $events[$i]['endDate'] >= $compare_to_date) {
list($event_year,$event_month,$event_day) = explode('-',$events[$i]['eventDate']);
/**
* Display event on same WEEK DAY each Month
* This will cause a monthly event to always show on the same day of the month
* If an event is started on the 1st Monday, it will always display on the 1st Monday
* of each month for it's duration.
*/
if($events[$i]['recurrfreq'] == _RECUR_SAME_DAY) {
$current_day_of_week = date('w',mktime(0,0,0,$this_month,$this_day,$this_year));
$event_day_of_week = date('w',mktime(0,0,0,$event_month,$event_day,$event_year));
$event_day_occurance=0;
for($d=1; $d<=$event_day; $d++) {
$current_day = date('w',mktime(0,0,0,$event_month,$d,$event_year));
if($current_day === $event_day_of_week) {
$event_day_occurance++;
}
}
$curr_day = date('d',mktime(0,0,0,$this_month,$this_day,$this_year));
$current_day_occurance=0;
for($d=1; $d<=$curr_day; $d++) {
$current_day = date('w',mktime(0,0,0,$this_month,$d,$this_year));
if($current_day === $current_day_of_week) {
$current_day_occurance++;
}
}
if( $current_day_occurance === $event_day_occurance
&& $current_day_of_week === $event_day_of_week
&& $this_month === $event_month) {
$displayed_events++;
if(!empty($display)) {
$display .= '<br />';
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$display .= $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
array('event'=>$events[$i],
'dayofweek'=>$align,
'usepopups'=>$usepopups,
'showdates'=>$pcbshowdates)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
/**
* Display event on same DATE each Month
* This will cause a monthly event to always show on the same date of the month
* If an event is started on the 25th of the Month it will always display
* on the 25th of each month for its duration
* (this is not yet implemented as it needs DB changes
*/
if($events[$i]['recurrfreq'] == _RECUR_SAME_DATE) {
if( $this_day === $event_day
&& $this_month === $event_month) {
$displayed_events++;
if(!empty($display)) {
$display .= '<br />';
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$display .= $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
array('event'=>$events[$i],
'dayofweek'=>$align,
'usepopups'=>$usepopups,
'showdates'=>$pcbshowdates)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
}
break;
default:
break;
}
}
if(!empty($display)) {
$output->Text($display);
} else {
$output->Text(_PC_BLOCK_NO_EVENTS);
}
$output->Text('</td></tr></table>');
$output->Text('</td></tr></table>');
} // <--- end if showevents
if($nextevents) {
//*******************************************************************
// START block header
//*******************************************************************
if($showevents || $showcalendar) { $output->Linebreak(); }
$output->Text('<table border="0" cellpadding="0" cellspacing="1" width="100%"><tr><td bgcolor="'.$bgcolor2.'">');
$output->Text('<table border="0" cellpadding="1" cellspacing="1" width="100%"><tr><td bgcolor="'.$bgcolor1.'">');
if($showevents || $showcalendar) {
$output->TableStart();
$row = array();
$row[0]['content'] = '<b>'._PC_UPCOMING_EVENTS.'</b>';
$row[0]['align'] = 'center';
$row[0]['valign'] = 'middle';
$output->TableAddRow($row);
$output->TableEnd();
$output->Text('</td></tr>');
$output->Text('<tr><td valign="top" align="left" bgcolor="'.$bgcolor1.'">');
}
// just align the popup
if($blockinfo['position'] == 'r') {
$align=6;
} elseif($blockinfo['position'] == 'l') {
$align=1;
} else {
$align=4;
}
$displayed_events = 0;
$display = '';
$poptext = '';
for($i=0; $i<count($events) && $displayed_events<$eventslimit; $i++) {
list($this_month,$this_day,$this_year) = explode('/',$Date);
$compare_to_date = date('Y-m-d'.mktime(0,0,0,$this_month,$this_day+1,$this_year));
//$compare_to_date = $this_year.'-'.$this_month.'-'.$this_day;
if(($events[$i]['eventDate'] <= $compare_to_date || $events[$i]['eventDate'] >= $compare_to_date)
&& $events[$i]['endDate'] >= $compare_to_date) {
$displayed_events++;
if(!empty($display)) {
$display .= '<br />';
}
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$display .= $output->Text(pnModAPIFunc('PostCalendar','user','createEventLink',
array('event'=>$events[$i],
'dayofweek'=>$align,
'usepopups'=>$usepopups,
'showdates'=>$pcbshowdates)));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
}
}
if(!empty($display)) {
$output->Text($display);
} else {
$output->Text(_PC_BLOCK_NO_EVENTS);
}
$output->Text('</td></tr></table>');
$output->Text('</td></tr></table>');
} // <--- end if nextevents
if($pcbshowsslinks) {
$output->Linebreak();
$submit_event_url = pnModURL('PostCalendar','user','submit');
$search_event_url = pnModURL('PostCalendar','user','search');
$output->Text('<center>');
$output->Text('[ <a href="'.$submit_event_url.'">'._PC_SUBMIT_EVENT.'</a> ] ');
$output->Text('[ <a href="'.$search_event_url.'">'._PC_SEARCH_EVENT.'</a> ]');
$output->Text('</center>');
}
// Populate block info and pass to theme
$blockinfo['content'] = $output->GetOutput();
return themesideblock($blockinfo);
}
/**
* modify block settings
*/
function PostCalendar_calendarblock_modify($blockinfo)
{
// Security check
if (!pnSecAuthAction(0,'PostCalendar:calendarblock:',"$blockinfo[title]::",ACCESS_EDIT)) {
return false;
}
// Create output object
$output = new pnHTML();
// Get current content
$vars = pnBlockVarsFromContent($blockinfo['content']);
//get the block id
$bid = pnVarCleanFromInput('bid');
$output->SetOutputMode(_PNH_RETURNOUTPUT);
$settings[0][] = $output->Text(_PC_BLOCK_SHOW_CALENDAR);
$settings[0][] = $output->FormCheckBox('pcbshowcalendar', pnModGetVar('PostCalendar_block_'.$bid,'pcbshowcalendar'));
//$settings[1][] = $output->Text(_PC_BLOCK_TOPIC_DISPLAY);
//$settings[1][] = $output->FormCheckBox('pcbtopicdisplay', pnModGetVar('PostCalendar_block_'.$bid,'pcbtopicdisplay'));
$settings[1][] = $output->Text(_PC_BLOCK_EVENTS_DATE_DISPLAY);
$settings[1][] = $output->FormCheckBox('pcbeventsdatedisplay', pnModGetVar('PostCalendar_block_'.$bid,'pcbeventsdatedisplay'));
//$settings[3][] = $output->Text(_PC_BLOCK_LOCATION_DISPLAY);
//$settings[3][] = $output->FormCheckBox('pcblocationdisplay', pnModGetVar('PostCalendar_block_'.$bid,'pcblocationdisplay'));
$settings[2][] = $output->Text(_PC_BLOCK_EVENT_OVERVIEW);
$settings[2][] = $output->FormCheckBox('pcbeventoverview', pnModGetVar('PostCalendar_block_'.$bid,'pcbeventoverview'));
$settings[3][] = $output->Text(_PC_BLOCK_UPCOMING_EVENTS);
$settings[3][] = $output->FormCheckBox('pcbnextevents', pnModGetVar('PostCalendar_block_'.$bid,'pcbnextevents'));
$settings[4][] = $output->Text(_PC_BLOCK_EVENTS_DISPLAY_LIMIT);
$settings[4][] = $output->FormText('pcbeventslimit', pnModGetVar('PostCalendar_block_'.$bid,'pcbeventslimit'),5);
$settings[5][] = $output->Text(_PC_BLOCK_USE_POPUPS);
$settings[5][] = $output->FormCheckBox('pcbusepopups', pnModGetVar('PostCalendar_block_'.$bid,'pcbusepopups'));
$settings[6][] = $output->Text(_PC_SHOW_SS_LINKS);
$settings[6][] = $output->FormCheckBox('pcbshowsslinks', pnModGetVar('PostCalendar_block_'.$bid,'pcbshowsslinks'));
$output->SetOutputMode(_PNH_KEEPOUTPUT);
// Add row
$output->SetInputMode(_PNH_VERBATIMINPUT);
for($i=0; $i<count($settings); $i++) {
$output->TableAddRow($settings[$i], 'left');
}
$output->SetInputMode(_PNH_PARSEINPUT);
// Return output
return $output->GetOutput();
}
/**
* update block settings
*/
function PostCalendar_calendarblock_update($blockinfo)
{
//get the block id
$bid = pnVarCleanFromInput('bid');
list($pcbshowcalendar,
$pcbtopicdisplay,
$pcbeventsdatedisplay,
$pcblocationdisplay,
$pcbeventslimit,
$pcbeventoverview,
$pcbusepopups,
$pcbnextevents,
$pcbshowsslinks) = pnVarCleanFromInput('pcbshowcalendar',
'pcbtopicdisplay',
'pcbeventsdatedisplay',
'pcblocationdisplay',
'pcbeventslimit',
'pcbeventoverview',
'pcbusepopups',
'pcbnextevents',
'pcbshowsslinks');
if(!isset($pcbshowcalendar)) { $pcbshowcalendar=0; }
if(!isset($pcbtopicdisplay)) { $pcbtopicdisplay=0; }
if(!isset($pcbeventsdatedisplay)) { $pcbeventsdatedisplay=0; }
if(!isset($pcblocationdisplay)) { $pcblocationdisplay=0; }
if(!isset($pcbeventslimit)) { $pcbeventslimit=5; }
if(!isset($pcbeventoverview)) { $pcbeventoverview=0; }
if(!isset($pcbusepopups)) { $pcbusepopups=0; }
if(!isset($pcbnextevents)) { $pcbnextevents=0; }
if(!isset($pcbshowsslinks)) { $pcbshowsslinks=0; }
pnModSetVar('PostCalendar_block_'.$bid, 'pcbshowcalendar', $pcbshowcalendar);
pnModSetVar('PostCalendar_block_'.$bid, 'pcbtopicdisplay', $pcbtopicdisplay);
pnModSetVar('PostCalendar_block_'.$bid, 'pcbeventsdatedisplay', $pcbeventsdatedisplay);
pnModSetVar('PostCalendar_block_'.$bid, 'pcblocationdisplay', $pcblocationdisplay);
pnModSetVar('PostCalendar_block_'.$bid, 'pcbeventslimit', $pcbeventslimit);
pnModSetVar('PostCalendar_block_'.$bid, 'pcbeventoverview', $pcbeventoverview);
pnModSetVar('PostCalendar_block_'.$bid, 'pcbusepopups', $pcbusepopups);
pnModSetVar('PostCalendar_block_'.$bid, 'pcbnextevents', $pcbnextevents);
pnModSetVar('PostCalendar_block_'.$bid, 'pcbshowsslinks', $pcbshowsslinks);
//$blockinfo['content'] = pnBlockVarsToContent($vars);
return $blockinfo;
}
?>