|
Class: Calendar
Source Location: Program_Root/Date/Calendar.php
HtmlLayout
|
--Calendar
Calendar implements a graphical calendar generator. This class derives most of its functionality from the saf.GUI.Layout package, so for more information and additional functionality, please read up on that one as well.
Author(s)
Version
- 1.2, 2003-01-20, $Id: Calendar.php,v 1.2 2005/07/06 15:30:56 lux Exp $
Copyright
- Copyright (C) 2001-2003, Simian Systems Inc.
|
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
[line 289]
Calendar implements a graphical calendar generator. This class derives most of its functionality from the saf.GUI.Layout package, so for more information and additional functionality, please read up on that one as well. New in 1.2: - Stopped using saf.Template in favour of saf.Template.Simple. Templates
now use the {tagname} syntax instead of ##tagname##.
- Modified the example to include saf/init.php instead of the more
verbose stuff that was there before.
1 <?php 2 3 // let's create a browseable daily, weekly, and monthly calendar with next|previous links 4 5 // load the necessary packages 6 include_once ('saf/init.php'); 7 8 $loader->inc ('saf.Date.Calendar'); 9 $loader->inc ('saf.Database'); 10 $loader->inc ('saf.Template.Simple'); 11 $loader->inc ('saf.CGI'); 12 13 // create a few supporting objects 14 // adjust database parameters as necessary (for more info see saf.Database) 15 $db = new Database ('MySQL:www.sitellite3.lo:DBNAME', 'USER', 'PASS'); 16 $simple = new SimpleTemplate; 17 $cgi = new CGI; 18 19 // set a few defaults for $cgi params 20 if (empty ($cgi->date)) { 21 $cgi->date = date ('Y-m-d'); 22 } 23 24 if (empty ($cgi->show)) { 25 $cgi->show = 'week'; 26 } 27 28 if (empty ($cgi->startOn)) { 29 $cgi->startOn = 'Sun'; 30 } 31 32 // create our calendar 33 $c = new Calendar ($cgi->date, $cgi->show, $cgi->startOn); 34 35 // set some visual properties for the cell and table elements in our calendar 36 $c->cell['width'] = '14%'; 37 $c->cell['height'] = '75'; 38 $c->cell['style'] = "border: #000 1px solid; font: 12px Arial"; 39 $c->table['style'] = "border: #000 1px solid"; 40 $c->table['border'] = "1"; 41 $c->table['width'] = "100%"; 42 43 if ($c->showPeriod == 'day') { 44 // initialize day view 45 46 // height limit of 75 not wanted 47 unset ($c->cell['height']); 48 49 // only show from 9 to 5 (4 & 4:30, but not 5 itself) 50 $c->showFromHour = 9; 51 $c->showToHour = 16; 52 53 // fill the calendar with pretty things from the database 54 $res = $c->fillCalendar ( 55 'select * from sitellite_event order by date asc', 56 'date', 57 '<a href="/index/events/id.{id}">{title}</a><br />' 58 ); 59 60 // create the header of the calendar 61 $yesterday = Date::subtract ($cgi->date, '1 day'); 62 $tomorrow = Date::add ($cgi->date, '1 day'); 63 64 $c->makeHeader ( 65 '<h1>' . Date::format ($cgi->date, 'F jS, Y') . '</h1>' . 66 '<p><a href="caltest.php' . $cgi->makeQuery ('date') . '&date=' . $yesterday . '">' . 67 Date::format ($yesterday, 'F jS, Y') . '</a> | <a href="caltest.php' . 68 $cgi->makeQuery ('date') . '&date=' . $tomorrow . '">' . 69 Date::format ($tomorrow, 'F jS, Y') . '</a></p>', 70 array ( 71 'style' => 'background-color: #69c; font: 14px Arial', 72 'align' => 'center', 73 'valign' => 'middle', 74 'width' => '100%', 75 'height' => '25', 76 ), 77 array ( 78 'style' => 'background-color: #9cf; font: 12px Arial; font-weight: bold', 79 'align' => 'center', 80 'valign' => 'middle', 81 'height' => '20', 82 ) 83 ); 84 85 // this is another way we could add content to a specific cell 86 //$c->append ('_9am', 'Foo bar'); 87 88 } elseif ($c->showPeriod == 'week') { 89 // initialize week view 90 91 // fill the calendar with pretty things from the database 92 $res = $c->fillCalendar ( 93 'select * from sitellite_event order by date asc', 94 'date', 95 '<a href="/index/events/id.{id}">{title}</a><br />', 96 '{day}<br />' 97 ); 98 99 // shade today's box 100 if (is_object ($c->{$c->activeCells[date ('Y-m-d')]})) { 101 $c->set ($c->activeCells[date ('Y-m-d')], 'bgcolor', '#ffffdd'); 102 } 103 104 // create the header of the calendar 105 $lastWeek = Date::subtract ($cgi->date, '1 week'); 106 $nextWeek = Date::add ($cgi->date, '1 week'); 107 108 $c->makeHeader ( 109 '<h1>Week of ' . Date::format ($c->firstDay, 'F jS, Y') . '</h1>' . 110 '<p><a href="caltest.php' . $cgi->makeQuery ('date') . '&date=' . $lastWeek . 111 '">Week of ' . Date::format ($lastWeek, 'F jS, Y') . '</a> | <a href="caltest.php' . 112 $cgi->makeQuery ('date') . '&date=' . $nextWeek . '">Week of ' . 113 Date::format ($nextWeek, 'F jS, Y') . '</a></p>', 114 array ( 115 'style' => 'background-color: #69c; font: 14px Arial', 116 'align' => 'center', 117 'valign' => 'middle', 118 'width' => '100%', 119 'height' => '25', 120 ), 121 array ( 122 'style' => 'background-color: #9cf; font: 12px Arial; font-weight: bold', 123 'align' => 'center', 124 'valign' => 'middle', 125 'height' => '20', 126 ), 127 array ( 128 'style' => 'background-color: #ccc', 129 ), 130 array ( 131 'style' => 'background-color: #ccc', 132 ) 133 ); 134 135 // this is another way we could add content to a specific cell 136 //$c->append ('_5th', 'Foo bar'); 137 138 } elseif ($c->showPeriod == 'month') { 139 // initialize month view 140 141 // fill the calendar with pretty things from the database 142 $res = $c->fillCalendar ( 143 'select * from sitellite_event order by date asc', 144 'date', 145 '<a href="/index/events/id.{id}">{title}</a><br />', 146 '{day}<br />' 147 ); 148 149 // shade today's box 150 if (is_object ($c->{$c->activeCells[date ('Y-m-d')]})) { 151 $c->set ($c->activeCells[date ('Y-m-d')], 'bgcolor', '#ffffdd'); 152 } 153 154 // create the header of the calendar 155 $lastMonth = Date::subtract ($cgi->date, '1 month'); 156 $nextMonth = Date::add ($cgi->date, '1 month'); 157 158 $c->makeHeader ( 159 '<h1>' . Date::format ($cgi->date, 'F, Y') . '</h1>' . 160 '<p><a href="caltest.php' . $cgi->makeQuery ('date') . '&date=' . $lastMonth . '">' . 161 Date::format ($lastMonth, 'F, Y') . '</a> | <a href="caltest.php' . 162 $cgi->makeQuery ('date') . '&date=' . $nextMonth . '">' . 163 Date::format ($nextMonth, 'F, Y') . '</a></p>', 164 array ( 165 'style' => 'background-color: #69c; font: 14px Arial', 166 'align' => 'center', 167 'valign' => 'middle', 168 'width' => '100%', 169 'height' => '25', 170 ), 171 array ( 172 'style' => 'background-color: #9cf; font: 12px Arial; font-weight: bold', 173 'align' => 'center', 174 'valign' => 'middle', 175 'height' => '20', 176 ), 177 array ( 178 'style' => 'background-color: #ccc', 179 ), 180 array ( 181 'style' => 'background-color: #ccc', 182 ) 183 ); 184 } 185 186 // the following is a bunch of form junk to make the calendar view user-definable 187 if ($cgi->show == 'day') { 188 $showDay = ' selected="selected"'; 189 } elseif ($cgi->show == 'week') { 190 $showWeek = ' selected="selected"'; 191 } elseif ($cgi->show == 'month') { 192 $showMonth = ' selected="selected"'; 193 } 194 195 if ($cgi->startOn == 'Sun') { 196 $startSun = ' selected="selected"'; 197 } elseif ($cgi->startOn == 'Mon') { 198 $startMon = ' selected="selected"'; 199 } elseif ($cgi->startOn == 'Tue') { 200 $startTue = ' selected="selected"'; 201 } elseif ($cgi->startOn == 'Wed') { 202 $startWed = ' selected="selected"'; 203 } elseif ($cgi->startOn == 'Thu') { 204 $startThu = ' selected="selected"'; 205 } elseif ($cgi->startOn == 'Fri') { 206 $startFri = ' selected="selected"'; 207 } elseif ($cgi->startOn == 'Sat') { 208 $startSat = ' selected="selected"'; 209 } 210 211 ? ><form method="get"> 212 <p align="right"> 213 <input type="hidden" name="date" value="<?php echo $cgi->date; ? >" /> 214 View: <select name="show"> 215 <option value="day"<?php echo $showDay; ? >>Day</option> 216 <option value="week"<?php echo $showWeek; ? >>Week</option> 217 <option value="month"<?php echo $showMonth; ? >>Month</option> 218 </select> 219 , Start Week On: <select name="startOn"> 220 <option value="Sun"<?php echo $startSun; ? >>Sun</option> 221 <option value="Mon"<?php echo $startMon; ? >>Mon</option> 222 <option value="Tue"<?php echo $startTue; ? >>Tue</option> 223 <option value="Wed"<?php echo $startWed; ? >>Wed</option> 224 <option value="Thu"<?php echo $startThu; ? >>Thu</option> 225 <option value="Fri"<?php echo $startFri; ? >>Fri</option> 226 <option value="Sat"<?php echo $startSat; ? >>Sat</option> 227 </select> 228 <input type="submit" value="Go" /> 229 </p> 230 </form><?php 231 232 // display the calendar 233 if ($res) { 234 echo $c->render (); 235 } else { 236 echo $c->error; 237 } 238 239 ? >
Tags:
Class Variables
$activeCells = array ()
[line 360]
Contains a list of the active cells in the Calendar matrix. Active cells are the days that are in use.
Tags:
$beginWeekOn =
[line 307]
Tells the calendar what day of the week to start the calendar on. Value may be one of 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', and 'Sat'.
Tags:
$bottomBlock =
[line 388]
Reference to the cell that contains the space after the last day of the month in the 'month' $showPeriod.
Tags:
$cellTemplate =
[line 370]
Contains a default template for use in each cell. The cell template is not to be confused with the item template, which displays an individual item on any given day.
Tags:
$currentDay =
[line 324]
Contains the current date (Y-m-d format).
Tags:
$error =
[line 397]
If an error has occured within this class, you'll find it in $error.
Tags:
$firstDay =
[line 316]
Contains the date (Y-m-d format) of the first day to include in the current calendar view.
Tags:
$lastDay =
[line 333]
Contains the date (Y-m-d format) of the last day to include in the current calendar view.
Tags:
$showFromHour = 0
[line 342]
Tells Calendar to limit the hours displayed in 'day' view. Must be an integer from 0 to 23.
Tags:
$showPeriod =
[line 297]
Tells the calendar what to display on a single screen. May be 'day', 'week', or 'month'.
Tags:
$showToHour = 23
[line 351]
Tells Calendar to limit the hours displayed in 'day' view. Must be an integer from 0 to 23.
Tags:
$topBlock =
[line 379]
Reference to the cell that contains the space before the first day of the month in the 'month' $showPeriod.
Tags:
Class Methods
|
|