demo
templates
install
contact
Home Tips Calendar

Month & Year Icons on other pages

The Month & Year icoms are shown on the default calendar page, but not on another page where the [events] tag is used. To get around this, a calendar page can be instead [include]'ed on the page. To avoid the neted inclusion of the menus and other page layout features, a different template that is very plain & simple must be used.

Here's the template:


<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td><?php echo $content; ?></td>
    <td valign="top"><?php echo $sidebar; ?></td>
  </tr>
</table>

This is saved to the root of the web site as 'incTemplate.php'.

Then, include a calendar into another page (such as 'News' or 'Events') with an include tag such as [include]http://contentor.net/calendar?template=incTemplate.php[/include]

The result is shown below:


http://contentor.net/ include ('util/config.inc.php'); include ('util/functions.php'); $edit_path = "$index_name/help/cannotedit"; $content = '
'; $loggedin = false; include('util/login.php'); $exclude_robots = ""; if ($curpath[1] == $home_page) { array_splice($curpath, 1, 1); } $arg_cnt = count($curpath); $valid_page = true; $page_title = _default_page_title . ' - Calendar'; function smallCalendar($y, $m) { global $contents_table; $timestamp = mktime(0,0,0,$m,1,$y); // 1st day of month $wkdy = strftime('%w', $timestamp); // first day of week in calendar - SUN == 0 $month = strftime('%B', $timestamp); $build = "
"; foreach(array('S', 'M', 'T', 'W', 'T', 'F', 'S') as $mtmp) { $build .= ""; } $build .= ""; if ($wkdy > 0) { $build .= ""; } $st = strftime('%Y-%m-%d %T', $timestamp); $en = strftime('%Y-%m-%d %T', mktime(23,59,59,($m+1),0,$y)); $find_content = mysql_query ("SELECT * FROM `$contents_table` USE INDEX (event) WHERE `event` BETWEEN '$st' AND '$en'"); $num_rows = mysql_num_rows($find_content); $has_event = array(); for($j=0; $j<$num_rows; $j++) { $field_data = mysql_fetch_array($find_content); $event_date = explode('-',$field_data['event']); $event_day = (int) substr($event_date['2'], 0, 2); $has_event[$event_day] = True; } $dim = date('t', $timestamp); // returns Days In Month for ($d=1; $d<=$dim; $d++) { $build .= ""; } else { $build .= "$d"; } $wkdy = (($wkdy + 1) % 7); // easier & faster to track day of week myself... if (($wkdy == 0) && ($d<$dim)) { $build .= ""; } } if ($wkdy > 0) { $i = 7 - $wkdy; $build .= ""; } $build .= "
$month $y
$mtmp
 "; if ($has_event[$d]==True) { $build .= "$d
 
"; return $build; } function largeCalendar($y, $m) { global $now, $contents_table, $loggedin, $index_name, $valid_page; $valid_page = false; // assume an empty month $month = strftime('%B', mktime(0,0,0,$m,1,$y)); $build = "
"; $build .= ""; foreach(array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') as $mtmp) { $build .= ""; } $build .= ""; if ($wkdy > 0) { $set = 14.28 * $wkdy; $build .= ""; } $dim = date('t', $timestamp); // returns Days In Month for ($d=1; $d<=$dim; $d++) { $timestamp = mktime(0,0,0,$m,$d,$y); $st = strftime('%Y-%m-%d', $timestamp); $en = $st . ' 23:59:59'; $find_content = mysql_query ("SELECT * FROM `$contents_table` USE INDEX (event) WHERE `event` BETWEEN '$st' AND '$en'"); $num_sections = mysql_num_rows($find_content); $build .= ""; $wkdy = (($wkdy + 1) % 7); if ($wkdy == 0) { $build .= ""; } } if ($wkdy > 0) { $i = 7 - $wkdy; $set = 14.28 * $i; $build .= ""; } $build .= "
"; $timestamp = mktime(0,0,0, ($m-1), 1, $y); $build .= strftime(_date_link_month, $timestamp) . ' ' . strftime(_date_link_year, $timestamp); $build .= "

$month $y

"; $timestamp = mktime(0,0,0, ($m+1), 1, $y); $build .= strftime(_date_link_month, $timestamp) . ' ' . strftime(_date_link_year, $timestamp); $timestamp = mktime(0,0,0,$m,1,$y); //1st day of month $wkdy = strftime('%w', $timestamp); //first day of week in calendar - SUN == 0 $month = strftime('%B', $timestamp); $build .= "
$mtmp
 "; if ($num_sections) { $build .= "$d
"; $valid_page = true; // got events on this page } else { $build .= "$d
"; } for($j=0; $j<$num_sections; $j++) { if ($j) { $build .= _event_postfix; } $field_data = mysql_fetch_array($find_content); $members_only = (strpos($field_data['section_opt'], "m") > -1); if ($members_only && (!$loggedin)) { $build .= "private event"; } else { $header = trim($field_data['section_header']); if (strlen($header) < 1) { $header = substr(trim(strip_tags($field_data['section_text'])), 0, 20) . '...'; } $header = bbencode($header); if (($field_data['date'] <= $now) && ($field_data['expire'] >= $now)) { $build .= "$header"; } else { $build .= $header; } } } $build .= "
 
"; // if (!$valid_page) { // header ("HTTP/1.0 404 Not Found"); // } return $build; } $y = date("Y"); $m = date("m"); $d = date("d"); switch ($arg_cnt) { case 4: $d = $curpath[3]; // set & fall thru case 3: $m = $curpath[2]; // set & fall thru case 2: $y = $curpath[1]; break; default: } $sidebar = ''; // template probably needs it empty if not used $timestamp = mktime(0,0,0, $m, $d, $y); $breadcrumbs .= "Calendar" . _breadcrumb_divider; $atc = ''; if ($y > 2037) { $content .= "The calendar currently only works through 2037 (a Y2.037K bug?)"; $valid_page = false; } else { $selectMonYr = "
\"month
month


year
\"year
"; switch ($arg_cnt) { case 4: $atc .= strftime(_date_link_day, $timestamp) . ', '; $sidebar .= $selectMonYr; case 3: $atc = strftime(_date_link_month, mktime(0,0,0, $m, 1, $y)) . ' ' . $atc; // bug fix for 31st of the month case 2: $atc .= strftime(_date_link_year, $timestamp); break; case 1: $atc = "Upcoming Events:"; $sidebar .= $selectMonYr; default: } $breadcrumbs .= $atc; switch ($arg_cnt) { case 4: $v = strftime('%Y-%m-%d', $timestamp); $content .= list_events($v, true); break; case 3: $content .= largeCalendar($y, $m); $page_head .= $exclude_robots; break; case 2: if ((int)$y > 0) { $content .= ''; if ($y < 1900) { $y = $y + 1900; } $prev_y = $y - 1; $next_y = $y + 1; $content .= ""; for ($mt=1; $mt<13; $mt++) { $content .= ""; } else { $content .= ""; } } $content .= "
$prev_y

$y

$next_y
"; $content .= smallCalendar($y, $mt); if (($mt % 4) == 0) { $content .= "
"; $page_head .= $exclude_robots; } else { $find_content = mysql_query ("SELECT * FROM `$contents_table` WHERE `dir`='/calendar$dir'"); $num_sections = mysql_num_rows($find_content); if ($num_sections) { header("Location: $path_url$index_name/calendar$dir"); exit; } else { $edit_path = "edit/calendar$dir"; $content .= "No content found for page: /calendar$dir"; header ("HTTP/1.0 404 Not Found"); $valid_page = false; } } break; default: $content .= bbencode(_calendar_default); // was list_events(6); } } $content .= '
'; $dir = '/calendar'; $dir_max = '/calendar/zzzzz'; if ($valid_page) { $pages = mysql_query("SELECT * FROM `$pages_table` WHERE `dir`='$dir'"); if ($hits = @mysql_fetch_array($pages)) { extract($hits); $page_views++; @mysql_query ("UPDATE `$pages_table` SET `last_visit`='$now', `page_views`='$page_views' WHERE `dir`='$dir'"); } else { $page_views = 1; @mysql_query("INSERT INTO `$pages_table` SET `dir`='$dir', `last_visit`='$now', `page_views`='$page_views'"); } } $page_head .= "$page_title\n"; array_unshift($curpath, "calendar", "calendar"); // do some shifting to keep the menu script happy $cur_dir = "/$curpath[1]/"; include ("$_SERVER[DOCUMENT_ROOT]/$template"); ?>