/trunk/classes/pear/Calendar/docs/Readme |
---|
New file |
0,0 → 1,3 |
Readme |
See the PEAR manual at http://pear.php.net/manual/en/package.datetime.calendar.php for details. |
/trunk/classes/pear/Calendar/docs/examples/10.phps |
---|
New file |
0,0 → 1,93 |
<?php |
/** |
* Description: demonstrates a decorator to provide simple output formatting |
* on the month while still allowing the days to be accessed via the decorator |
* In practice you _wouldn't_ do this - each decorator comes with a performance |
* hit for extra method calls. For this example some simple functions could help |
* format the month while the days are accessed via the normal Month object |
*/ |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Decorator.php'; |
// Decorate a Month with methods to improve formatting |
class MonthDecorator extends Calendar_Decorator { |
/** |
* @param Calendar_Month |
*/ |
function MonthDecorator(& $Month) { |
parent::Calendar_Decorator($Month); |
} |
/** |
* Override the prevMonth method to format the output |
*/ |
function prevMonth() { |
$prevStamp = parent::prevMonth(TRUE); |
// Build the URL for the previous month |
return $_SERVER['PHP_SELF'].'?y='.date('Y',$prevStamp). |
'&m='.date('n',$prevStamp).'&d='.date('j',$prevStamp); |
} |
/** |
* Override the thisMonth method to format the output |
*/ |
function thisMonth() { |
$thisStamp = parent::thisMonth(TRUE); |
// A human readable string from this month |
return date('F Y',$thisStamp); |
} |
/** |
* Override the nextMonth method to format the output |
*/ |
function nextMonth() { |
$nextStamp = parent::nextMonth(TRUE); |
// Build the URL for next month |
return $_SERVER['PHP_SELF'].'?y='.date('Y',$nextStamp). |
'&m='.date('n',$nextStamp).'&d='.date('j',$nextStamp); |
} |
} |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('n'); |
// Creata a month as usual |
$Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']); |
// Pass it to the decorator and use the decorator from now on... |
$MonthDecorator = new MonthDecorator($Month); |
$MonthDecorator->build(); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> A Simple Decorator </title> |
</head> |
<body> |
<h1>A Simple Decorator</h1> |
<table> |
<caption><?php echo ( $MonthDecorator->thisMonth() ); ?></caption> |
<?php |
while ( $Day = $MonthDecorator->fetch() ) { |
if ( $Day->isFirst() ) { |
echo ( "\n<tr>\n" ); |
} |
if ( $Day->isEmpty() ) { |
echo ( "<td> </td>" ); |
} else { |
echo ( "<td>".$Day->thisDay()."</td>" ); |
} |
if ( $Day->isLast() ) { |
echo ( "\n</tr>\n" ); |
} |
} |
?> |
<tr> |
<td><a href="<?php echo ($MonthDecorator->prevMonth()); ?>">Prev</a></td> |
<td colspan="5"> </td> |
<td><a href="<?php echo ($MonthDecorator->nextMonth()); ?>">Next</a></td> |
</tr> |
</table> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/20.phps |
---|
New file |
0,0 → 1,240 |
<?php |
/** |
* Description: demonstrates a decorator used to "attach a payload" to a selection |
* to make it available when iterating over calendar children |
*/ |
//if you use ISO-8601 dates, switch to PearDate engine |
define('CALENDAR_ENGINE', 'PearDate'); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT . 'Month/Weekdays.php'; |
require_once CALENDAR_ROOT . 'Day.php'; |
require_once CALENDAR_ROOT . 'Decorator.php'; |
// accepts multiple entries |
class DiaryEvent extends Calendar_Decorator |
{ |
var $entries = array(); |
function DiaryEvent($calendar) { |
Calendar_Decorator::Calendar_Decorator($calendar); |
} |
function addEntry($entry) { |
$this->entries[] = $entry; |
} |
function getEntry() { |
$entry = each($this->entries); |
if ($entry) { |
return $entry['value']; |
} else { |
reset($this->entries); |
return false; |
} |
} |
} |
class MonthPayload_Decorator extends Calendar_Decorator |
{ |
//Calendar engine |
var $cE; |
var $tableHelper; |
var $year; |
var $month; |
var $firstDay = false; |
function build($events=array()) |
{ |
require_once CALENDAR_ROOT . 'Day.php'; |
require_once CALENDAR_ROOT . 'Table/Helper.php'; |
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay); |
$this->cE = & $this->getEngine(); |
$this->year = $this->thisYear(); |
$this->month = $this->thisMonth(); |
$daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); |
for ($i=1; $i<=$daysInMonth; $i++) { |
$Day = new Calendar_Day(2000,1,1); // Create Day with dummy values |
$Day->setTimeStamp($this->cE->dateToStamp($this->year, $this->month, $i)); |
$this->children[$i] = new DiaryEvent($Day); |
} |
if (count($events) > 0) { |
$this->setSelection($events); |
} |
Calendar_Month_Weekdays::buildEmptyDaysBefore(); |
Calendar_Month_Weekdays::shiftDays(); |
Calendar_Month_Weekdays::buildEmptyDaysAfter(); |
Calendar_Month_Weekdays::setWeekMarkers(); |
return true; |
} |
function setSelection($events) |
{ |
$daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); |
for ($i=1; $i<=$daysInMonth; $i++) { |
$stamp1 = $this->cE->dateToStamp($this->year, $this->month, $i); |
$stamp2 = $this->cE->dateToStamp($this->year, $this->month, $i+1); |
foreach ($events as $event) { |
if (($stamp1 >= $event['start'] && $stamp1 < $event['end']) || |
($stamp2 >= $event['start'] && $stamp2 < $event['end']) || |
($stamp1 <= $event['start'] && $stamp2 > $event['end']) |
) { |
$this->children[$i]->addEntry($event); |
$this->children[$i]->setSelected(); |
} |
} |
} |
} |
function fetch() |
{ |
$child = each($this->children); |
if ($child) { |
return $child['value']; |
} else { |
reset($this->children); |
return false; |
} |
} |
} |
// Calendar instance used to get the dates in the preferred format: |
// you can switch Calendar Engine and the example still works |
$cal = new Calendar; |
$events = array(); |
//add some events |
$events[] = array( |
'start' => $cal->cE->dateToStamp(2004, 6, 1, 10), |
'end' => $cal->cE->dateToStamp(2004, 6, 1, 12), |
'desc' => 'Important meeting' |
); |
$events[] = array( |
'start' => $cal->cE->dateToStamp(2004, 6, 1, 21), |
'end' => $cal->cE->dateToStamp(2004, 6, 1, 23, 59), |
'desc' => 'Dinner with the boss' |
); |
$events[] = array( |
'start' => $cal->cE->dateToStamp(2004, 6, 5), |
'end' => $cal->cE->dateToStamp(2004, 6, 10, 23, 59), |
'desc' => 'Holidays!' |
); |
$Month = & new Calendar_Month_Weekdays(2004, 6); |
$MonthDecorator = new MonthPayload_Decorator($Month); |
$MonthDecorator->build($events); |
?> |
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar </title> |
<style text="text/css"> |
table { |
border-collapse: collapse; |
} |
caption { |
font-family: verdana; |
font-size: 14pt; |
padding-bottom: 4pt; |
} |
th { |
font-family: verdana; |
font-size: 11px; |
text-align: center; |
background-color: #e7e3e7; |
padding: 5pt; |
line-height: 150%; |
border: 1px solid #ccc; |
} |
td { |
font-family: verdana; |
font-size: 11px; |
text-align: left; |
vertical-align: top; |
} |
td.calCell { |
border: 1px solid #b5bece; |
padding: 3px; |
} |
td.calCellEmpty { |
background-color: #f3f3f7; |
} |
td.calCellBusy { |
background-color: #efeffa; |
} |
div.dayNumber { |
text-align: right; |
background-color: #f8f8f8; |
border-bottom: 1px solid #ccc; |
} |
ul { |
margin-left: 0; |
margin-top: 5pt; |
padding: 0 10pt 0 12pt; |
list-style-type: square; |
} |
</style> |
</head> |
<body> |
<h2>Sample Calendar Payload Decorator (using <?php echo CALENDAR_ENGINE; ?> engine)</h2> |
<table class="calendar" width="98%" cellspacing="0" cellpadding="0"> |
<caption> |
<?php echo $MonthDecorator->thisMonth().' / '.$MonthDecorator->thisYear(); ?> |
</caption> |
<tr> |
<th>Monday</th> |
<th>Tuesday</th> |
<th>Wednesday</th> |
<th>Thursday</th> |
<th>Friday</th> |
<th>Saturday</th> |
<th>Sunday</th> |
</tr> |
<?php |
while ($Day = $MonthDecorator->fetch()) { |
if ($Day->isFirst()) { |
echo "<tr>\n"; |
} |
echo '<td class="calCell'; |
if ($Day->isSelected()) { |
echo ' calCellBusy'; |
} elseif ($Day->isEmpty()) { |
echo ' calCellEmpty'; |
} |
echo '">'; |
echo '<div class="dayNumber">'.$Day->thisDay().'</div>'; |
if ($Day->isEmpty()) { |
echo ' '; |
} else { |
echo '<div class="dayContents"><ul>'; |
while ($entry = $Day->getEntry()) { |
echo '<li>'.$entry['desc'].'</li>'; |
//you can print the time range as well |
} |
echo '</ul></div>'; |
} |
echo '</td>'; |
if ($Day->isLast()) { |
echo "</tr>\n"; |
} |
} |
?> |
</table> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/12.phps |
---|
New file |
0,0 → 1,116 |
<?php |
/** |
* Description: a complete year |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Year.php'; |
define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); |
if ( !isset($_GET['year']) ) $_GET['year'] = date('Y'); |
$Year = new Calendar_Year($_GET['year']); |
$Year->build(); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> <?php echo ( $Year->thisYear() ); ?> </title> |
<style type="text/css"> |
body { |
font-family: Georgia, serif; |
} |
caption.year { |
font-weight: bold; |
font-size: 120%; |
font-color: navy; |
} |
caption.month { |
font-size: 110%; |
font-color: navy; |
} |
table.month { |
border: thin groove #800080 |
} |
tr { |
vertical-align: top; |
} |
th, td { |
text-align: right; |
font-size: 70%; |
} |
#prev { |
float: left; |
font-size: 70%; |
} |
#next { |
float: right; |
font-size: 70%; |
} |
</style> |
</head> |
<body> |
<table> |
<caption class="year"> |
<?php echo ( $Year->thisYear() ); ?> |
<div id="next"> |
<a href="?year=<?php echo ( $Year->nextYear() ); ?>">>></a> |
</div> |
<div id="prev"> |
<a href="?year=<?php echo ( $Year->prevYear() ); ?>"><<</a> |
</div> |
</caption> |
<?php |
$i = 0; |
while ( $Month = $Year->fetch() ) { |
switch ( $i ) { |
case 0: |
echo ( "<tr>\n" ); |
break; |
case 3: |
case 6: |
case 9: |
echo ( "</tr>\n<tr>\n" ); |
break; |
case 12: |
echo ( "</tr>\n" ); |
break; |
} |
echo ( "<td>\n<table class=\"month\">\n" ); |
echo ( "<caption class=\"month\">".date('F',$Month->thisMonth(TRUE))."</caption>" ); |
echo ( "<tr>\n<th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th>\n</tr>" ); |
$Month->build(); |
while ( $Day = $Month->fetch() ) { |
if ( $Day->isFirst() ) { |
echo ( "<tr>\n" ); |
} |
if ( $Day->isEmpty() ) { |
echo ( "<td> </td>\n" ); |
} else { |
echo ( "<td>".$Day->thisDay()."</td>\n" ); |
} |
if ( $Day->isLast() ) { |
echo ( "</tr>\n" ); |
} |
} |
echo ( "</table>\n</td>\n" ); |
$i++; |
} |
?> |
</table> |
<p>Took: <?php echo ((getmicrotime()-$start)); ?></p> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/22.phps |
---|
New file |
0,0 → 1,46 |
<?php |
/** |
* Description: demonstrates using the Uri util |
*/ |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Util/Uri.php'; |
if (!isset($_GET['jahr'])) $_GET['jahr'] = date('Y'); |
if (!isset($_GET['monat'])) $_GET['monat'] = date('m'); |
// Build the month |
$Calendar = new Calendar_Month_Weekdays($_GET['jahr'], $_GET['monat']); |
echo ( '<p>The current month is ' |
.$Calendar->thisMonth().' of year '.$Calendar->thisYear().'</p>'); |
$Uri = & new Calendar_Util_Uri('jahr','monat'); |
$Uri->setFragments('jahr','monat'); |
echo "\"Vector\" URIs<pre>"; |
echo ( "Previous Uri:\t".htmlentities($Uri->prev($Calendar, 'month'))."\n" ); |
echo ( "This Uri:\t".htmlentities($Uri->this($Calendar, 'month'))."\n" ); |
echo ( "Next Uri:\t".htmlentities($Uri->next($Calendar, 'month'))."\n" ); |
echo "</pre>"; |
// Switch to scalar URIs |
$Uri->separator = '/'; // Default is & |
$Uri->scalar = true; // Omit variable names |
echo "\"Scalar\" URIs<pre>"; |
echo ( "Previous Uri:\t".$Uri->prev($Calendar, 'month')."\n" ); |
echo ( "This Uri:\t".$Uri->this($Calendar, 'month')."\n" ); |
echo ( "Next Uri:\t".$Uri->next($Calendar, 'month')."\n" ); |
echo "</pre>"; |
// Restore the vector URIs |
$Uri->separator = '&'; |
$Uri->scalar = false; |
?> |
<p> |
<a href="<?php echo($_SERVER['PHP_SELF'].'?'.$Uri->prev($Calendar, 'month'));?>">Prev</a> : |
<a href="<?php echo($_SERVER['PHP_SELF'].'?'.$Uri->next($Calendar, 'month'));?>">Next</a> |
</p> |
/trunk/classes/pear/Calendar/docs/examples/14.phps |
---|
New file |
0,0 → 1,141 |
<?php |
/** |
* Description: same as 3.php, but using the PEAR::Date engine |
* Note: make sure PEAR::Date is a stable release!!! |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
// Switch to PEAR::Date engine |
define('CALENDAR_ENGINE', 'PearDate'); |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
// Initialize GET variables if not set |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('m'); |
if (!isset($_GET['d'])) $_GET['d'] = date('d'); |
// Build the month |
$month = new Calendar_Month_Weekdays($_GET['y'], $_GET['m']); |
// Create an array of days which are "selected" |
// Used for Week::build() below |
$selectedDays = array ( |
new Calendar_Day($_GET['y'], $_GET['m'], $_GET['d']), |
new Calendar_Day($_GET['y'], 12, 25), |
); |
// Build the days in the month |
$month->build($selectedDays); |
// Construct strings for next/previous links |
$PMonth = $month->prevMonth('object'); // Get previous month as object |
$prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); |
$NMonth = $month->nextMonth('object'); |
$next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); |
$thisDate = new Date($month->thisMonth('timestamp')); |
?> |
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar using PEAR::Date Engine </title> |
<style text="text/css"> |
table { |
background-color: silver; |
} |
caption { |
font-family: verdana; |
font-size: 12px; |
background-color: while; |
} |
.prevMonth { |
font-size: 10px; |
text-align: left; |
} |
.nextMonth { |
font-size: 10px; |
text-align: right; |
} |
th { |
font-family: verdana; |
font-size: 11px; |
color: navy; |
text-align: right; |
} |
td { |
font-family: verdana; |
font-size: 11px; |
text-align: right; |
} |
.selected { |
background-color: yellow; |
} |
</style> |
</head> |
<body> |
<h2>Calendar using PEAR::Date Engine</h2> |
<table class="calendar"> |
<caption> |
<?php echo $thisDate->format('%B %Y'); ?> |
</caption> |
<tr> |
<th>M</th> |
<th>T</th> |
<th>W</th> |
<th>T</th> |
<th>F</th> |
<th>S</th> |
<th>S</th> |
</tr> |
<?php |
while ($day = $month->fetch()) { |
// Build a link string for each day |
$link = $_SERVER['PHP_SELF']. |
'?y='.$day->thisYear(). |
'&m='.$day->thisMonth(). |
'&d='.$day->thisDay(); |
// isFirst() to find start of week |
if ($day->isFirst()) |
echo "<tr>\n"; |
if ($day->isSelected()) { |
echo '<td class="selected">'.$day->thisDay().'</td>'."\n"; |
} else if ($day->isEmpty()) { |
echo '<td> </td>'."\n"; |
} else { |
echo '<td><a href="'.$link.'">'.$day->thisDay().'</a></td>'."\n"; |
} |
// isLast() to find end of week |
if ($day->isLast()) { |
echo "</tr>\n"; |
} |
} |
?> |
<tr> |
<td> |
<a href="<?php echo $prev; ?>" class="prevMonth"><< </a> |
</td> |
<td colspan="5"> </td> |
<td> |
<a href="<?php echo $next; ?>" class="nextMonth"> >></a> |
</td> |
</tr> |
</table> |
<?php |
echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>'; |
?> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/16.phps |
---|
New file |
0,0 → 1,31 |
<?php |
/** |
* Description: demonstrates using the Uri decorator |
*/ |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Decorator/Uri.php'; |
if (!isset($_GET['jahr'])) $_GET['jahr'] = date('Y'); |
if (!isset($_GET['monat'])) $_GET['monat'] = date('m'); |
// Build the month |
$Calendar = new Calendar_Month_Weekdays($_GET['jahr'], $_GET['monat']); |
echo ( '<p>The current month is ' |
.$Calendar->thisMonth().' of year '.$Calendar->thisYear().'</p>'); |
$Uri = & new Calendar_Decorator_Uri($Calendar); |
$Uri->setFragments('jahr','monat'); |
// $Uri->setSeperator('/'); // Default is & |
// $Uri->setScalar(); // Omit variable names |
echo ( "<pre>Previous Uri:\t".$Uri->prev('month')."\n" ); |
echo ( "This Uri:\t".$Uri->this('month')."\n" ); |
echo ( "Next Uri:\t".$Uri->next('month')."\n</pre>" ); |
?> |
<p> |
<a href="<?php echo($_SERVER['PHP_SELF'].'?'.$Uri->prev('month'));?>">Prev</a> : |
<a href="<?php echo($_SERVER['PHP_SELF'].'?'.$Uri->next('month'));?>">Next</a> |
</p> |
/trunk/classes/pear/Calendar/docs/examples/18.phps |
---|
New file |
0,0 → 1,36 |
<?php |
/** |
* Description: demonstrates using the Wrapper decorator |
*/ |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Month.php'; |
require_once CALENDAR_ROOT.'Decorator.php'; // Not really needed but added to help this make sense |
require_once CALENDAR_ROOT.'Decorator/Wrapper.php'; |
class MyBoldDecorator extends Calendar_Decorator |
{ |
function MyBoldDecorator(&$Calendar) |
{ |
parent::Calendar_Decorator($Calendar); |
} |
function thisDay() |
{ |
return '<b>'.parent::thisDay().'</b>'; |
} |
} |
$Month = new Calendar_Month(date('Y'), date('n')); |
$Wrapper = & new Calendar_Decorator_Wrapper($Month); |
$Wrapper->build(); |
echo '<h2>The Wrapper decorator</h2>'; |
echo '<i>Day numbers are rendered in bold</i><br /> <br />'; |
while ($DecoratedDay = $Wrapper->fetch('MyBoldDecorator')) { |
echo $DecoratedDay->thisDay().'<br />'; |
} |
?> |
/trunk/classes/pear/Calendar/docs/examples/20.php |
---|
New file |
0,0 → 1,240 |
<?php |
/** |
* Description: demonstrates a decorator used to "attach a payload" to a selection |
* to make it available when iterating over calendar children |
*/ |
//if you use ISO-8601 dates, switch to PearDate engine |
define('CALENDAR_ENGINE', 'PearDate'); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT . 'Month/Weekdays.php'; |
require_once CALENDAR_ROOT . 'Day.php'; |
require_once CALENDAR_ROOT . 'Decorator.php'; |
// accepts multiple entries |
class DiaryEvent extends Calendar_Decorator |
{ |
var $entries = array(); |
function DiaryEvent($calendar) { |
Calendar_Decorator::Calendar_Decorator($calendar); |
} |
function addEntry($entry) { |
$this->entries[] = $entry; |
} |
function getEntry() { |
$entry = each($this->entries); |
if ($entry) { |
return $entry['value']; |
} else { |
reset($this->entries); |
return false; |
} |
} |
} |
class MonthPayload_Decorator extends Calendar_Decorator |
{ |
//Calendar engine |
var $cE; |
var $tableHelper; |
var $year; |
var $month; |
var $firstDay = false; |
function build($events=array()) |
{ |
require_once CALENDAR_ROOT . 'Day.php'; |
require_once CALENDAR_ROOT . 'Table/Helper.php'; |
$this->tableHelper = & new Calendar_Table_Helper($this, $this->firstDay); |
$this->cE = & $this->getEngine(); |
$this->year = $this->thisYear(); |
$this->month = $this->thisMonth(); |
$daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); |
for ($i=1; $i<=$daysInMonth; $i++) { |
$Day = new Calendar_Day(2000,1,1); // Create Day with dummy values |
$Day->setTimeStamp($this->cE->dateToStamp($this->year, $this->month, $i)); |
$this->children[$i] = new DiaryEvent($Day); |
} |
if (count($events) > 0) { |
$this->setSelection($events); |
} |
Calendar_Month_Weekdays::buildEmptyDaysBefore(); |
Calendar_Month_Weekdays::shiftDays(); |
Calendar_Month_Weekdays::buildEmptyDaysAfter(); |
Calendar_Month_Weekdays::setWeekMarkers(); |
return true; |
} |
function setSelection($events) |
{ |
$daysInMonth = $this->cE->getDaysInMonth($this->year, $this->month); |
for ($i=1; $i<=$daysInMonth; $i++) { |
$stamp1 = $this->cE->dateToStamp($this->year, $this->month, $i); |
$stamp2 = $this->cE->dateToStamp($this->year, $this->month, $i+1); |
foreach ($events as $event) { |
if (($stamp1 >= $event['start'] && $stamp1 < $event['end']) || |
($stamp2 >= $event['start'] && $stamp2 < $event['end']) || |
($stamp1 <= $event['start'] && $stamp2 > $event['end']) |
) { |
$this->children[$i]->addEntry($event); |
$this->children[$i]->setSelected(); |
} |
} |
} |
} |
function fetch() |
{ |
$child = each($this->children); |
if ($child) { |
return $child['value']; |
} else { |
reset($this->children); |
return false; |
} |
} |
} |
// Calendar instance used to get the dates in the preferred format: |
// you can switch Calendar Engine and the example still works |
$cal = new Calendar; |
$events = array(); |
//add some events |
$events[] = array( |
'start' => $cal->cE->dateToStamp(2004, 6, 1, 10), |
'end' => $cal->cE->dateToStamp(2004, 6, 1, 12), |
'desc' => 'Important meeting' |
); |
$events[] = array( |
'start' => $cal->cE->dateToStamp(2004, 6, 1, 21), |
'end' => $cal->cE->dateToStamp(2004, 6, 1, 23, 59), |
'desc' => 'Dinner with the boss' |
); |
$events[] = array( |
'start' => $cal->cE->dateToStamp(2004, 6, 5), |
'end' => $cal->cE->dateToStamp(2004, 6, 10, 23, 59), |
'desc' => 'Holidays!' |
); |
$Month = & new Calendar_Month_Weekdays(2004, 6); |
$MonthDecorator = new MonthPayload_Decorator($Month); |
$MonthDecorator->build($events); |
?> |
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar </title> |
<style text="text/css"> |
table { |
border-collapse: collapse; |
} |
caption { |
font-family: verdana; |
font-size: 14pt; |
padding-bottom: 4pt; |
} |
th { |
font-family: verdana; |
font-size: 11px; |
text-align: center; |
background-color: #e7e3e7; |
padding: 5pt; |
line-height: 150%; |
border: 1px solid #ccc; |
} |
td { |
font-family: verdana; |
font-size: 11px; |
text-align: left; |
vertical-align: top; |
} |
td.calCell { |
border: 1px solid #b5bece; |
padding: 3px; |
} |
td.calCellEmpty { |
background-color: #f3f3f7; |
} |
td.calCellBusy { |
background-color: #efeffa; |
} |
div.dayNumber { |
text-align: right; |
background-color: #f8f8f8; |
border-bottom: 1px solid #ccc; |
} |
ul { |
margin-left: 0; |
margin-top: 5pt; |
padding: 0 10pt 0 12pt; |
list-style-type: square; |
} |
</style> |
</head> |
<body> |
<h2>Sample Calendar Payload Decorator (using <?php echo CALENDAR_ENGINE; ?> engine)</h2> |
<table class="calendar" width="98%" cellspacing="0" cellpadding="0"> |
<caption> |
<?php echo $MonthDecorator->thisMonth().' / '.$MonthDecorator->thisYear(); ?> |
</caption> |
<tr> |
<th>Monday</th> |
<th>Tuesday</th> |
<th>Wednesday</th> |
<th>Thursday</th> |
<th>Friday</th> |
<th>Saturday</th> |
<th>Sunday</th> |
</tr> |
<?php |
while ($Day = $MonthDecorator->fetch()) { |
if ($Day->isFirst()) { |
echo "<tr>\n"; |
} |
echo '<td class="calCell'; |
if ($Day->isSelected()) { |
echo ' calCellBusy'; |
} elseif ($Day->isEmpty()) { |
echo ' calCellEmpty'; |
} |
echo '">'; |
echo '<div class="dayNumber">'.$Day->thisDay().'</div>'; |
if ($Day->isEmpty()) { |
echo ' '; |
} else { |
echo '<div class="dayContents"><ul>'; |
while ($entry = $Day->getEntry()) { |
echo '<li>'.$entry['desc'].'</li>'; |
//you can print the time range as well |
} |
echo '</ul></div>'; |
} |
echo '</td>'; |
if ($Day->isLast()) { |
echo "</tr>\n"; |
} |
} |
?> |
</table> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/21.php |
---|
New file |
0,0 → 1,139 |
<?php |
/** |
* Description: a complete year with numeric week numbers |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Year.php'; |
require_once CALENDAR_ROOT.'Month/Weeks.php'; |
define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); |
if (!isset($_GET['year'])) $_GET['year'] = date('Y'); |
$week_types = array( |
'n_in_year', |
'n_in_month', |
); |
if (!isset($_GET['week_type']) || !in_array($_GET['week_type'],$week_types) ) { |
$_GET['week_type'] = 'n_in_year'; |
} |
$Year = new Calendar_Year($_GET['year']); |
$Year->build(); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> <?php echo $Year->thisYear(); ?> </title> |
<style type="text/css"> |
body { |
font-family: Georgia, serif; |
} |
caption.year { |
font-weight: bold; |
font-size: 120%; |
font-color: navy; |
} |
caption.month { |
font-size: 110%; |
font-color: navy; |
} |
table.month { |
border: thin groove #800080 |
} |
tr { |
vertical-align: top; |
} |
th, td { |
text-align: right; |
font-size: 70%; |
} |
#prev { |
float: left; |
font-size: 70%; |
} |
#next { |
float: right; |
font-size: 70%; |
} |
#week_type { |
float: none; |
font-size: 70%; |
} |
.weekNumbers { |
background-color: #e5e5f5; |
padding-right: 3pt; |
} |
</style> |
</head> |
<body> |
<table> |
<caption class="year"> |
<?php echo $Year->thisYear(); ?> |
<div id="next"> |
<a href="?year=<?php echo $Year->nextYear(); ?>&week_type=<?php echo $_GET['week_type']; ?>">>></a> |
</div> |
<div id="prev"> |
<a href="?year=<?php echo $Year->prevYear(); ?>&week_type=<?php echo $_GET['week_type']; ?>"><<</a> |
</div> |
<div id="week_type"> |
<a href="?year=<?php echo $Year->thisYear(); ?>&week_type=n_in_year">Weeks by Year</a> : |
<a href="?year=<?php echo $Year->thisYear(); ?>&week_type=n_in_month">Weeks by Month</a> |
</div> |
</caption> |
<?php |
$i = 0; |
while ($Month = $Year->fetch()) { |
switch ($i) { |
case 0: |
echo "<tr>\n"; |
break; |
case 3: |
case 6: |
case 9: |
echo "</tr>\n<tr>\n"; |
break; |
case 12: |
echo "</tr>\n"; |
break; |
} |
echo "<td>\n<table class=\"month\">\n"; |
echo '<caption class="month">'.date('F', $Month->thisMonth(TRUE)).'</caption>'; |
echo '<colgroup><col class="weekNumbers"><col span="7"></colgroup>'."\n"; |
echo "<tr>\n<th>Week</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th>\n</tr>"; |
$Month->build(); |
while ($Week = $Month->fetch()) { |
echo "<tr>\n"; |
echo '<td>'.$Week->thisWeek($_GET['week_type'])."</td>\n"; |
$Week->build(); |
while ($Day = $Week->fetch()) { |
if ($Day->isEmpty()) { |
echo "<td> </td>\n"; |
} else { |
echo "<td>".$Day->thisDay()."</td>\n"; |
} |
} |
} |
echo "</table>\n</td>\n"; |
$i++; |
} |
?> |
</table> |
<p>Took: <?php echo ((getmicrotime()-$start)); ?></p> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/22.php |
---|
New file |
0,0 → 1,46 |
<?php |
/** |
* Description: demonstrates using the Uri util |
*/ |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Util/Uri.php'; |
if (!isset($_GET['jahr'])) $_GET['jahr'] = date('Y'); |
if (!isset($_GET['monat'])) $_GET['monat'] = date('m'); |
// Build the month |
$Calendar = new Calendar_Month_Weekdays($_GET['jahr'], $_GET['monat']); |
echo ( '<p>The current month is ' |
.$Calendar->thisMonth().' of year '.$Calendar->thisYear().'</p>'); |
$Uri = & new Calendar_Util_Uri('jahr','monat'); |
$Uri->setFragments('jahr','monat'); |
echo "\"Vector\" URIs<pre>"; |
echo ( "Previous Uri:\t".htmlentities($Uri->prev($Calendar, 'month'))."\n" ); |
echo ( "This Uri:\t".htmlentities($Uri->this($Calendar, 'month'))."\n" ); |
echo ( "Next Uri:\t".htmlentities($Uri->next($Calendar, 'month'))."\n" ); |
echo "</pre>"; |
// Switch to scalar URIs |
$Uri->separator = '/'; // Default is & |
$Uri->scalar = true; // Omit variable names |
echo "\"Scalar\" URIs<pre>"; |
echo ( "Previous Uri:\t".$Uri->prev($Calendar, 'month')."\n" ); |
echo ( "This Uri:\t".$Uri->this($Calendar, 'month')."\n" ); |
echo ( "Next Uri:\t".$Uri->next($Calendar, 'month')."\n" ); |
echo "</pre>"; |
// Restore the vector URIs |
$Uri->separator = '&'; |
$Uri->scalar = false; |
?> |
<p> |
<a href="<?php echo($_SERVER['PHP_SELF'].'?'.$Uri->prev($Calendar, 'month'));?>">Prev</a> : |
<a href="<?php echo($_SERVER['PHP_SELF'].'?'.$Uri->next($Calendar, 'month'));?>">Next</a> |
</p> |
/trunk/classes/pear/Calendar/docs/examples/23.php |
---|
New file |
0,0 → 1,66 |
<?php |
/** |
* Description: demonstrates using the Textual util |
*/ |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php'; |
require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Textual.php'; |
// Could change language like this |
// setlocale (LC_TIME, "de_DE"); // Unix based (probably) |
// setlocale (LC_TIME, "ge"); // Windows |
echo "<hr>Calling: Calendar_Util_Textual::monthNames('long');<pre>"; |
print_r(Calendar_Util_Textual::monthNames('long')); |
echo '</pre>'; |
echo "<hr>Calling: Calendar_Util_Textual::weekdayNames('two');<pre>"; |
print_r(Calendar_Util_Textual::weekdayNames('two')); |
echo '</pre>'; |
echo "<hr>Creating: new Calendar_Day(date('Y'), date('n'), date('d'));<br />"; |
$Calendar = new Calendar_Day(date('Y'), date('n'), date('d')); |
echo '<hr>Previous month is: '.Calendar_Util_Textual::prevMonthName($Calendar,'two').'<br />'; |
echo 'This month is: '.Calendar_Util_Textual::thisMonthName($Calendar,'short').'<br />'; |
echo 'Next month is: '.Calendar_Util_Textual::nextMonthName($Calendar).'<br /><hr />'; |
echo 'Previous day is: '.Calendar_Util_Textual::prevDayName($Calendar).'<br />'; |
echo 'This day is: '.Calendar_Util_Textual::thisDayName($Calendar,'short').'<br />'; |
echo 'Next day is: '.Calendar_Util_Textual::nextDayName($Calendar,'one').'<br /><hr />'; |
echo "Creating: new Calendar_Month_Weekdays(date('Y'), date('n'), 6); - Saturday is first day of week<br />"; |
$Calendar = new Calendar_Month_Weekdays(date('Y'), date('n'), 6); |
?> |
<p>Rendering calendar....</p> |
<table> |
<caption><?php echo Calendar_Util_Textual::thisMonthName($Calendar).' '.$Calendar->thisYear(); ?></caption> |
<tr> |
<?php |
$dayheaders = Calendar_Util_Textual::orderedWeekdays($Calendar,'short'); |
foreach ($dayheaders as $dayheader) { |
echo '<th>'.$dayheader.'</th>'; |
} |
?> |
</tr> |
<?php |
$Calendar->build(); |
while ($Day = $Calendar->fetch()) { |
if ($Day->isFirst()) { |
echo "<tr>\n"; |
} |
if ($Day->isEmpty()) { |
echo '<td> </td>'; |
} else { |
echo '<td>'.$Day->thisDay().'</td>'; |
} |
if ($Day->isLast()) { |
echo "</tr>\n"; |
} |
} |
?> |
</table> |
/trunk/classes/pear/Calendar/docs/examples/2.phps |
---|
New file |
0,0 → 1,142 |
<?php |
/** |
* Description: Demonstrates building a calendar for a month using the Week class |
* Uses UnixTs engine |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
// Force UnixTs engine (default setting) |
define('CALENDAR_ENGINE','UnixTS'); |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weeks.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
// Initialize GET variables if not set |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('m'); |
if (!isset($_GET['d'])) $_GET['d'] = date('d'); |
// Build a month object |
$Month = new Calendar_Month_Weeks($_GET['y'], $_GET['m']); |
// Create an array of days which are "selected" |
// Used for Week::build() below |
$selectedDays = array ( |
new Calendar_Day($_GET['y'],$_GET['m'], $_GET['d']), |
new Calendar_Day($_GET['y'], 12, 25), |
new Calendar_Day(date('Y'), date('m'), date('d')), |
); |
// Instruct month to build Week objects |
$Month->build(); |
// Construct strings for next/previous links |
$PMonth = $Month->prevMonth('object'); // Get previous month as object |
$prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); |
$NMonth = $Month->nextMonth('object'); |
$next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); |
?> |
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar </title> |
<style text="text/css"> |
table { |
background-color: silver; |
} |
caption { |
font-family: verdana; |
font-size: 12px; |
background-color: while; |
} |
.prevMonth { |
font-size: 10px; |
text-align: left; |
} |
.nextMonth { |
font-size: 10px; |
text-align: right; |
} |
th { |
font-family: verdana; |
font-size: 11px; |
color: navy; |
text-align: right; |
} |
td { |
font-family: verdana; |
font-size: 11px; |
text-align: right; |
} |
.selected { |
background-color: yellow; |
} |
.empty { |
color: white; |
} |
</style> |
</head> |
<body> |
<h2>Build with Calendar_Month_Weeks::build() then Calendar_Week::build()</h2> |
<table class="calendar"> |
<caption> |
<?php echo date('F Y', $Month->getTimeStamp()); ?> |
</caption> |
<tr> |
<th>M</th> |
<th>T</th> |
<th>W</th> |
<th>T</th> |
<th>F</th> |
<th>S</th> |
<th>S</th> |
</tr> |
<?php |
while ($Week = $Month->fetch()) { |
echo "<tr>\n"; |
// Build the days in the week, passing the selected days |
$Week->build($selectedDays); |
while ($Day = $Week->fetch()) { |
// Build a link string for each day |
$link = $_SERVER['PHP_SELF']. |
'?y='.$Day->thisYear(). |
'&m='.$Day->thisMonth(). |
'&d='.$Day->thisDay(); |
// Check to see if day is selected |
if ($Day->isSelected()) { |
echo '<td class="selected">'.$Day->thisDay().'</td>'."\n"; |
// Check to see if day is empty |
} else if ($Day->isEmpty()) { |
echo '<td class="empty">'.$Day->thisDay().'</td>'."\n"; |
} else { |
echo '<td><a href="'.$link.'">'.$Day->thisDay().'</a></td>'."\n"; |
} |
} |
echo '</tr>'."\n"; |
} |
?> |
<tr> |
<td> |
<a href="<?php echo $prev; ?>" class="prevMonth"><< </a> |
</td> |
<td colspan="5"> </td> |
<td> |
<a href="<?php echo $next; ?>" class="nextMonth"> >></a> |
</td> |
</tr> |
</table> |
<?php |
echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>'; |
?> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/4.phps |
---|
New file |
0,0 → 1,49 |
<?php |
/** |
* Description: shows how to perform validation with PEAR::Calendar |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(' ', microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Second.php'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('n'); |
if (!isset($_GET['d'])) $_GET['d'] = date('j'); |
if (!isset($_GET['h'])) $_GET['h'] = date('H'); |
if (!isset($_GET['i'])) $_GET['i'] = date('i'); |
if (!isset($_GET['s'])) $_GET['s'] = date('s'); |
$Unit = & new Calendar_Second($_GET['y'], $_GET['m'], $_GET['d'], $_GET['h'], $_GET['i'], $_GET['s']); |
echo '<p><b>Result:</b> '.$Unit->thisYear().'-'.$Unit->thisMonth().'-'.$Unit->thisDay(). |
' '.$Unit->thisHour().':'.$Unit->thisMinute().':'.$Unit->thisSecond(); |
if ($Unit->isValid()) { |
echo ' is valid!</p>'; |
} else { |
$V= & $Unit->getValidator(); |
echo ' is invalid:</p>'; |
while ($error = $V->fetch()) { |
echo $error->toString() .'<br />'; |
} |
} |
?> |
<p>Enter a date / time to validate:</p> |
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> |
Year: <input type="text" name="y" value="2039"><br /> |
Month: <input type="text" name="m" value="13"><br /> |
Day: <input type="text" name="d" value="32"><br /> |
Hour: <input type="text" name="h" value="24"><br /> |
Minute: <input type="text" name="i" value="-1"><br /> |
Second: <input type="text" name="s" value="60"><br /> |
<input type="submit" value="Validate"> |
</form> |
<p><b>Note:</b> Error messages can be controlled with the constants <code>CALENDAR_VALUE_TOOSMALL</code> and <code>CALENDAR_VALUE_TOOLARGE</code> - see <code>Calendar_Validator.php</code></p> |
<?php echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>'; ?> |
/trunk/classes/pear/Calendar/docs/examples/6.phps |
---|
New file |
0,0 → 1,210 |
<?php |
/** |
* Description: A "personal planner" with some WML for fun |
* Note this is done the stupid way - a giant if/else for WML or HTML |
* could be greatly simplified with some HTML/WML rendering classes... |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('n'); |
if (!isset($_GET['d'])) $_GET['d'] = date('j'); |
$Month = & new Calendar_Month_Weekdays($_GET['y'],$_GET['m']); |
$Day = & new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']); |
$selection = array($Day); |
#-----------------------------------------------------------------------------# |
if ( isset($_GET['mime']) && $_GET['mime']=='wml' ) { |
header ('Content-Type: text/vnd.wap.wml'); |
echo ( '<?xml version="1.0"?>' ); |
?> |
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> |
<wml> |
<big><strong>Personal Planner Rendered with WML</strong></big> |
<?php |
if ( isset($_GET['viewday']) ) { |
?> |
<p><strong>Viewing <?php echo ( date('l, jS of F, Y',$Day->getTimeStamp()) ); ?></strong></p> |
<p> |
<anchor> |
Back to Month View |
<go href="<?php |
echo ( "?y=".$Day->thisYear()."&m=". |
$Day->thisMonth()."&d=".$Day->thisDay()."&mime=wml" ); |
?>"/> |
</anchor> |
</p> |
<table> |
<?php |
$Day->build(); |
while ( $Hour = & $Day->fetch() ) { |
echo ( "<tr>\n" ); |
echo ( "<td>".date('g a',$Hour->getTimeStamp())."</td><td>Free time!</td>\n" ); |
echo ( "</tr>\n" ); |
} |
?> |
</table> |
<?php |
} else { |
?> |
<p><strong><?php echo ( date('F Y',$Month->getTimeStamp()) ); ?></strong></p> |
<table> |
<tr> |
<td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td><td>S</td> |
</tr> |
<?php |
$Month->build($selection); |
while ( $Day = $Month->fetch() ) { |
if ( $Day->isFirst() ) { |
echo ( "<tr>\n" ); |
} |
if ( $Day->isEmpty() ) { |
echo ( "<td></td>\n" ); |
} else if ( $Day->isSelected() ) { |
echo ( "<td><anchor><strong><u>".$Day->thisDay()."</u></strong>\n<go href=\"".$_SERVER['PHP_SELF']."?viewday=true&y=". |
$Day->thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). |
"&mime=wml\" />\n</anchor></td>\n" ); |
} else { |
echo ( "<td><anchor>".$Day->thisDay()."\n<go href=\"?viewday=true&y=". |
$Day->thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). |
"&mime=wml\" /></anchor></td>\n" ); |
} |
if ( $Day->isLast() ) { |
echo ( "</tr>\n" ); |
} |
} |
?> |
<tr> |
<td> |
<anchor> |
<< |
<go href="<?php |
echo ( "?y=".$Month->thisYear()."&m=". |
$Month->prevMonth()."&d=".$Month->thisDay()."&mime=wml" ); |
?>"/> |
</anchor> |
</td> |
<td></td><td></td><td></td><td></td><td></td> |
<td> |
<anchor> |
>> |
<go href="<?php |
echo ( "?y=".$Month->thisYear()."&m=". |
$Month->nextMonth()."&d=".$Month->thisDay()."&mime=wml" ); |
?>"/> |
</anchor> |
</td> |
</tr> |
</table> |
<?php |
} |
?> |
<p><a href="<?php echo ( $_SERVER['PHP_SELF'] ); ?>">Back to HTML</a></p> |
<?php echo ( '<p>Took: '.(getmicrotime()-$start).' seconds</p>' ); ?> |
</wml> |
<?php |
#-----------------------------------------------------------------------------# |
} else { |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> HTML (+WML) Personal Planner </title> |
</head> |
<body> |
<h1>Personal Planner Rendered with HTML</h1> |
<p>To view in WML, click <a href="<?php echo ( $_SERVER['PHP_SELF'] ); ?>?mime=wml">here</a> or place a ?mime=wml at the end of any URL. |
Note that <a href="http://www.opera.com/download">Opera</a> supports WML natively and Mozilla / Firefox has the WMLBrowser |
plugin: <a href="http://wmlbrowser.mozdev.org">wmlbrowser.mozdev.org</a></p> |
<?php |
if ( isset($_GET['viewday']) ) { |
?> |
<p><strong>Viewing <?php echo ( date('l, jS of F, Y',$Day->getTimeStamp()) ); ?></strong></p> |
<p> |
<anchor> |
<a href="<?php |
echo ( "?y=".$Day->thisYear()."&m=". |
$Day->thisMonth()."&d=".$Day->thisDay()); |
?>">Back to Month View</a> |
</p> |
<table> |
<?php |
$Day->build(); |
while ( $Hour = & $Day->fetch() ) { |
echo ( "<tr>\n" ); |
echo ( "<td>".date('g a',$Hour->getTimeStamp())."</td><td>Free time!</td>\n" ); |
echo ( "</tr>\n" ); |
} |
?> |
</table> |
<?php |
} else { |
?> |
<p><strong><?php echo ( date('F Y',$Month->getTimeStamp()) ); ?></strong></p> |
<table> |
<tr> |
<td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td><td>S</td> |
</tr> |
<?php |
$Month->build($selection); |
while ( $Day = $Month->fetch() ) { |
if ( $Day->isFirst() ) { |
echo ( "<tr>\n" ); |
} |
if ( $Day->isEmpty() ) { |
echo ( "<td></td>\n" ); |
} else if ( $Day->isSelected() ) { |
echo ( "<td><a href=\"".$_SERVER['PHP_SELF']."?viewday=true&y=". |
$Day->thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). |
"&wml\"><strong><u>".$Day->thisDay()."</u></strong></a></td>\n" ); |
} else { |
echo ( "<td><a href=\"".$_SERVER['PHP_SELF']."?viewday=true&y=". |
$Day->thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). |
"\">".$Day->thisDay()."</a></td>\n" ); |
} |
if ( $Day->isLast() ) { |
echo ( "</tr>\n" ); |
} |
} |
?> |
<tr> |
<td> |
<a href="<?php |
echo ( "?y=".$Month->thisYear()."&m=". |
$Month->prevMonth()."&d=".$Month->thisDay() ); |
?>"> |
<<</a> |
</td> |
<td></td><td></td><td></td><td></td><td></td> |
<td> |
<a href="<?php |
echo ( "?y=".$Month->thisYear()."&m=". |
$Month->nextMonth()."&d=".$Month->thisDay() ); |
?>">>></a> |
</td> |
</tr> |
</table> |
<?php |
} |
?> |
<?php echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); ?> |
</body> |
</html> |
<?php |
} |
?> |
/trunk/classes/pear/Calendar/docs/examples/8.phps |
---|
New file |
0,0 → 1,70 |
<?php |
/** |
* Description: client for the SOAP Calendar Server |
*/ |
if ( version_compare(phpversion(), "5.0.0", ">") ) { |
die('PHP 5 has problems with PEAR::SOAP Client (8.0RC3) |
- remove @ before include below to see why'); |
} |
if (!@include('SOAP'.DIRECTORY_SEPARATOR.'Client.php')) { |
die('You must have PEAR::SOAP installed'); |
} |
// Just to save manaul modification... |
$basePath = explode('/', $_SERVER['SCRIPT_NAME']); |
array_pop($basePath); |
$basePath = implode('/', $basePath); |
$url = 'http://'.$_SERVER['SERVER_NAME'].$basePath.'/7.php?wsdl'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('n'); |
$wsdl = new SOAP_WSDL ($url); |
echo ( '<pre>'.$wsdl->generateProxyCode().'</pre>' ); |
$calendarClient = $wsdl->getProxy(); |
$month = $calendarClient->getMonth((int)$_GET['y'],(int)$_GET['m']); |
if ( PEAR::isError($month) ) { |
die ( $month->toString() ); |
} |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar over the Wire </title> |
</head> |
<body> |
<h1>Calendar Over the Wire (featuring PEAR::SOAP)</h1> |
<table> |
<caption><b><?php echo ( $month->monthname );?></b></caption> |
<tr> |
<th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th> |
</tr> |
<?php |
foreach ( $month->days as $day ) { |
if ( $day->isFirst === 1 ) |
echo ( "<tr>\n" ); |
if ( $day->isEmpty === 1 ) { |
echo ( "<td></td>" ); |
} else { |
echo ( "<td>".$day->day."</td>" ); |
} |
if ( $day->isLast === 1 ) |
echo ( "</tr>\n" ); |
} |
?> |
<tr> |
</table> |
<p>Enter Year and Month to View:</p> |
<form action="<?php echo ( $_SERVER['PHP_SELF'] ); ?>" method="get"> |
Year: <input type="text" size="4" name="y" value="<?php echo ( $_GET['y'] ); ?>"> |
Month: <input type="text" size="2" name="m" value="<?php echo ( $_GET['m'] ); ?>"> |
<input type="submit" value="Fetch Calendar"> |
</form> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/1.php |
---|
New file |
0,0 → 1,92 |
<?php |
/** |
* Description: Passes through all main calendar classes, beginning with year |
* and down to seconds, skipping weeks. Useful to test Calendar is (basically) |
* working correctly |
* |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
if (!isset($_GET['y'])) $_GET['y'] = 2003; |
if (!isset($_GET['m'])) $_GET['m'] = 8; |
if (!isset($_GET['d'])) $_GET['d'] = 9; |
if (!isset($_GET['h'])) $_GET['h'] = 12; |
if (!isset($_GET['i'])) $_GET['i'] = 34; |
if (!isset($_GET['s'])) $_GET['s'] = 46; |
switch ( @$_GET['view'] ) { |
default: |
$_GET['view'] = 'calendar_year'; |
case 'calendar_year': |
require_once CALENDAR_ROOT.'Year.php'; |
$c = new Calendar_Year($_GET['y']); |
break; |
case 'calendar_month': |
require_once CALENDAR_ROOT.'Month.php'; |
$c = new Calendar_Month($_GET['y'],$_GET['m']); |
break; |
case 'calendar_day': |
require_once CALENDAR_ROOT.'Day.php'; |
$c = new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']); |
break; |
case 'calendar_hour': |
require_once CALENDAR_ROOT.'Hour.php'; |
$c = new Calendar_Hour($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h']); |
break; |
case 'calendar_minute': |
require_once CALENDAR_ROOT.'Minute.php'; |
$c = new Calendar_Minute($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i']); |
break; |
case 'calendar_second': |
require_once CALENDAR_ROOT.'Second.php'; |
$c = new Calendar_Second($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i'],$_GET['s']); |
break; |
} |
echo ( 'Viewing: '.@$_GET['view'].'<br />' ); |
echo ( 'The time is now: '.date('Y M d H:i:s',$c->getTimestamp()).'<br >' ); |
$i = 1; |
echo ( '<h1>First Iteration</h1>' ); |
echo ( '<p>The first iteration is more "expensive", the calendar data |
structures having to be built.</p>' ); |
$start = getmicrotime(); |
$c->build(); |
while ( $e = $c->fetch() ) { |
$class = strtolower(get_class($e)); |
$link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). |
"&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); |
$method = 'this'.str_replace('calendar_','',$class); |
echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " ); |
if ( ($i % 10) == 0 ) { |
echo ( '<br>' ); |
} |
$i++; |
} |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
$i = 1; |
echo ( '<h1>Second Iteration</h1>' ); |
echo ( '<p>This second iteration is faster, the data structures |
being re-used</p>' ); |
$start = getmicrotime(); |
while ( $e = $c->fetch() ) { |
$class = strtolower(get_class($e)); |
$link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). |
"&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); |
$method = 'this'.str_replace('calendar_','',$class); |
echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " ); |
if ( ($i % 10) == 0 ) { |
echo ( '<br>' ); |
} |
$i++; |
} |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
?> |
/trunk/classes/pear/Calendar/docs/examples/2.php |
---|
New file |
0,0 → 1,142 |
<?php |
/** |
* Description: Demonstrates building a calendar for a month using the Week class |
* Uses UnixTs engine |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
// Force UnixTs engine (default setting) |
define('CALENDAR_ENGINE','UnixTS'); |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weeks.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
// Initialize GET variables if not set |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('m'); |
if (!isset($_GET['d'])) $_GET['d'] = date('d'); |
// Build a month object |
$Month = new Calendar_Month_Weeks($_GET['y'], $_GET['m']); |
// Create an array of days which are "selected" |
// Used for Week::build() below |
$selectedDays = array ( |
new Calendar_Day($_GET['y'],$_GET['m'], $_GET['d']), |
new Calendar_Day($_GET['y'], 12, 25), |
new Calendar_Day(date('Y'), date('m'), date('d')), |
); |
// Instruct month to build Week objects |
$Month->build(); |
// Construct strings for next/previous links |
$PMonth = $Month->prevMonth('object'); // Get previous month as object |
$prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); |
$NMonth = $Month->nextMonth('object'); |
$next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); |
?> |
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar </title> |
<style text="text/css"> |
table { |
background-color: silver; |
} |
caption { |
font-family: verdana; |
font-size: 12px; |
background-color: while; |
} |
.prevMonth { |
font-size: 10px; |
text-align: left; |
} |
.nextMonth { |
font-size: 10px; |
text-align: right; |
} |
th { |
font-family: verdana; |
font-size: 11px; |
color: navy; |
text-align: right; |
} |
td { |
font-family: verdana; |
font-size: 11px; |
text-align: right; |
} |
.selected { |
background-color: yellow; |
} |
.empty { |
color: white; |
} |
</style> |
</head> |
<body> |
<h2>Build with Calendar_Month_Weeks::build() then Calendar_Week::build()</h2> |
<table class="calendar"> |
<caption> |
<?php echo date('F Y', $Month->getTimeStamp()); ?> |
</caption> |
<tr> |
<th>M</th> |
<th>T</th> |
<th>W</th> |
<th>T</th> |
<th>F</th> |
<th>S</th> |
<th>S</th> |
</tr> |
<?php |
while ($Week = $Month->fetch()) { |
echo "<tr>\n"; |
// Build the days in the week, passing the selected days |
$Week->build($selectedDays); |
while ($Day = $Week->fetch()) { |
// Build a link string for each day |
$link = $_SERVER['PHP_SELF']. |
'?y='.$Day->thisYear(). |
'&m='.$Day->thisMonth(). |
'&d='.$Day->thisDay(); |
// Check to see if day is selected |
if ($Day->isSelected()) { |
echo '<td class="selected">'.$Day->thisDay().'</td>'."\n"; |
// Check to see if day is empty |
} else if ($Day->isEmpty()) { |
echo '<td class="empty">'.$Day->thisDay().'</td>'."\n"; |
} else { |
echo '<td><a href="'.$link.'">'.$Day->thisDay().'</a></td>'."\n"; |
} |
} |
echo '</tr>'."\n"; |
} |
?> |
<tr> |
<td> |
<a href="<?php echo $prev; ?>" class="prevMonth"><< </a> |
</td> |
<td colspan="5"> </td> |
<td> |
<a href="<?php echo $next; ?>" class="nextMonth"> >></a> |
</td> |
</tr> |
</table> |
<?php |
echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>'; |
?> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/3.php |
---|
New file |
0,0 → 1,134 |
<?php |
/** |
* Description: Performs same behaviour as 2.php but uses Month::buildWeekDays() |
* and is faster |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('m'); |
if (!isset($_GET['d'])) $_GET['d'] = date('d'); |
// Build the month |
$Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']); |
// Construct strings for next/previous links |
$PMonth = $Month->prevMonth('object'); // Get previous month as object |
$prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); |
$NMonth = $Month->nextMonth('object'); |
$next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); |
?> |
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar </title> |
<style text="text/css"> |
table { |
background-color: silver; |
} |
caption { |
font-family: verdana; |
font-size: 12px; |
background-color: while; |
} |
.prevMonth { |
font-size: 10px; |
text-align: left; |
} |
.nextMonth { |
font-size: 10px; |
text-align: right; |
} |
th { |
font-family: verdana; |
font-size: 11px; |
color: navy; |
text-align: right; |
} |
td { |
font-family: verdana; |
font-size: 11px; |
text-align: right; |
} |
.selected { |
background-color: yellow; |
} |
</style> |
</head> |
<body> |
<?php |
$selectedDays = array ( |
new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']), |
new Calendar_Day($_GET['y'],12,25), |
); |
// Build the days in the month |
$Month->build($selectedDays); |
?> |
<h2>Built with Calendar_Month_Weekday::build()</h2> |
<table class="calendar"> |
<caption> |
<?php echo ( date('F Y',$Month->getTimeStamp())); ?> |
</caption> |
<tr> |
<th>M</th> |
<th>T</th> |
<th>W</th> |
<th>T</th> |
<th>F</th> |
<th>S</th> |
<th>S</th> |
</tr> |
<?php |
while ( $Day = $Month->fetch() ) { |
// Build a link string for each day |
$link = $_SERVER['PHP_SELF']. |
'?y='.$Day->thisYear(). |
'&m='.$Day->thisMonth(). |
'&d='.$Day->thisDay(); |
// isFirst() to find start of week |
if ( $Day->isFirst() ) |
echo ( "<tr>\n" ); |
if ( $Day->isSelected() ) { |
echo ( "<td class=\"selected\">".$Day->thisDay()."</td>\n" ); |
} else if ( $Day->isEmpty() ) { |
echo ( "<td> </td>\n" ); |
} else { |
echo ( "<td><a href=\"".$link."\">".$Day->thisDay()."</a></td>\n" ); |
} |
// isLast() to find end of week |
if ( $Day->isLast() ) |
echo ( "</tr>\n" ); |
} |
?> |
<tr> |
<td> |
<a href="<?php echo ($prev);?>" class="prevMonth"><< </a> |
</td> |
<td colspan="5"> </td> |
<td> |
<a href="<?php echo ($next);?>" class="nextMonth"> >></a> |
</td> |
</tr> |
</table> |
<?php |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
?> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/4.php |
---|
New file |
0,0 → 1,49 |
<?php |
/** |
* Description: shows how to perform validation with PEAR::Calendar |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(' ', microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Second.php'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('n'); |
if (!isset($_GET['d'])) $_GET['d'] = date('j'); |
if (!isset($_GET['h'])) $_GET['h'] = date('H'); |
if (!isset($_GET['i'])) $_GET['i'] = date('i'); |
if (!isset($_GET['s'])) $_GET['s'] = date('s'); |
$Unit = & new Calendar_Second($_GET['y'], $_GET['m'], $_GET['d'], $_GET['h'], $_GET['i'], $_GET['s']); |
echo '<p><b>Result:</b> '.$Unit->thisYear().'-'.$Unit->thisMonth().'-'.$Unit->thisDay(). |
' '.$Unit->thisHour().':'.$Unit->thisMinute().':'.$Unit->thisSecond(); |
if ($Unit->isValid()) { |
echo ' is valid!</p>'; |
} else { |
$V= & $Unit->getValidator(); |
echo ' is invalid:</p>'; |
while ($error = $V->fetch()) { |
echo $error->toString() .'<br />'; |
} |
} |
?> |
<p>Enter a date / time to validate:</p> |
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> |
Year: <input type="text" name="y" value="2039"><br /> |
Month: <input type="text" name="m" value="13"><br /> |
Day: <input type="text" name="d" value="32"><br /> |
Hour: <input type="text" name="h" value="24"><br /> |
Minute: <input type="text" name="i" value="-1"><br /> |
Second: <input type="text" name="s" value="60"><br /> |
<input type="submit" value="Validate"> |
</form> |
<p><b>Note:</b> Error messages can be controlled with the constants <code>CALENDAR_VALUE_TOOSMALL</code> and <code>CALENDAR_VALUE_TOOLARGE</code> - see <code>Calendar_Validator.php</code></p> |
<?php echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>'; ?> |
/trunk/classes/pear/Calendar/docs/examples/5.php |
---|
New file |
0,0 → 1,132 |
<?php |
/** |
* Description: generating elements of a form with PEAR::Calendar, using |
* selections as well as validating the submission |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Year.php'; |
require_once CALENDAR_ROOT.'Month.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Hour.php'; |
require_once CALENDAR_ROOT.'Minute.php'; |
require_once CALENDAR_ROOT.'Second.php'; |
// Initialize if not set |
if (!isset($_POST['y'])) $_POST['y'] = date('Y'); |
if (!isset($_POST['m'])) $_POST['m'] = date('n'); |
if (!isset($_POST['d'])) $_POST['d'] = date('j'); |
if (!isset($_POST['h'])) $_POST['h'] = date('H'); |
if (!isset($_POST['i'])) $_POST['i'] = date('i'); |
if (!isset($_POST['s'])) $_POST['s'] = date('s'); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Select and Update </title> |
</head> |
<body> |
<h1>Select and Update</h1> |
<?php |
if ( isset($_POST['update']) ) { |
$Second = & new Calendar_Second($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i'],$_POST['s']); |
if ( !$Second->isValid() ) { |
$V= & $Second->getValidator(); |
echo ('<p>Validation failed:</p>' ); |
while ( $error = $V->fetch() ) { |
echo ( $error->toString() .'<br>' ); |
} |
} else { |
echo ('<p>Validation success.</p>' ); |
echo ( '<p>New timestamp is: '.$Second->getTimeStamp().' which could be used to update a database, for example'); |
} |
} else { |
$Year = new Calendar_Year($_POST['y']); |
$Month = new Calendar_Month($_POST['y'],$_POST['m']); |
$Day = new Calendar_Day($_POST['y'],$_POST['m'],$_POST['d']); |
$Hour = new Calendar_Hour($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h']); |
$Minute = new Calendar_Minute($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i']); |
$Second = new Calendar_Second($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i'],$_POST['s']); |
?> |
<p><b>Set the alarm clock</p></p> |
<form action="<?php echo ( $_SERVER['PHP_SELF'] ); ?>" method="post"> |
Year: <input type="text" name="y" value="<?php echo ( $_POST['y'] ); ?>" size="4"> |
Month:<select name="m"> |
<?php |
$selection = array($Month); |
$Year->build($selection); |
while ( $Child = & $Year->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisMonth()."\" selected>".$Child->thisMonth()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisMonth()."\">".$Child->thisMonth()."\n" ); |
} |
} |
?> |
</select> |
Day:<select name="d"> |
<?php |
$selection = array($Day); |
$Month->build($selection); |
while ( $Child = & $Month->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisDay()."\" selected>".$Child->thisDay()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisDay()."\">".$Child->thisDay()."\n" ); |
} |
} |
?> |
</select> |
Hour:<select name="h"> |
<?php |
$selection = array($Hour); |
$Day->build($selection); |
while ( $Child = & $Day->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisHour()."\" selected>".$Child->thisHour()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisHour()."\">".$Child->thisHour()."\n" ); |
} |
} |
?> |
</select> |
Minute:<select name="i"> |
<?php |
$selection = array($Minute); |
$Hour->build($selection); |
while ( $Child = & $Hour->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisMinute()."\" selected>".$Child->thisMinute()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisMinute()."\">".$Child->thisMinute()."\n" ); |
} |
} |
?> |
</select> |
Second:<select name="s"> |
<?php |
$selection = array($Second); |
$Minute->build($selection); |
while ( $Child = & $Minute->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisSecond()."\" selected>".$Child->thisSecond()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisSecond()."\">".$Child->thisSecond()."\n" ); |
} |
} |
?> |
</select> |
<input type="submit" name="update" value="Set Alarm"><br> |
<?php |
} |
?> |
<?php echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); ?> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/11.phps |
---|
New file |
0,0 → 1,109 |
<?php |
/** |
* Description: demonstrates a decorator used to "attach a payload" to a selection |
* to make it available when iterating over calendar children |
*/ |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Hour.php'; |
require_once CALENDAR_ROOT.'Decorator.php'; |
// Decorator to "attach" functionality to selected hours |
class DiaryEvent extends Calendar_Decorator { |
var $entry; |
function DiaryEvent($calendar) { |
Calendar_Decorator::Calendar_Decorator($calendar); |
} |
function setEntry($entry) { |
$this->entry = $entry; |
} |
function getEntry() { |
return $this->entry; |
} |
} |
// Create a day to view the hours for |
$Day = & new Calendar_Day(2003,10,24); |
// A sample query to get the data for today (NOT ACTUALLY USED HERE) |
$sql = " |
SELECT |
* |
FROM |
diary |
WHERE |
eventtime >= '".$Day->thisDay(TRUE)."' |
AND |
eventtime < '".$Day->nextDay(TRUE)."';"; |
// An array simulating data from a database |
$result = array ( |
array('eventtime'=>mktime(9,0,0,10,24,2003),'entry'=>'Meeting with sales team'), |
array('eventtime'=>mktime(11,0,0,10,24,2003),'entry'=>'Conference call with Widget Inc.'), |
array('eventtime'=>mktime(15,0,0,10,24,2003),'entry'=>'Presentation to board of directors') |
); |
// An array to place selected hours in |
$selection = array(); |
// Loop through the "database result" |
foreach ( $result as $row ) { |
$Hour = new Calendar_Hour(2000,1,1,1); // Create Hour with dummy values |
$Hour->setTimeStamp($row['eventtime']); // Set the real time with setTimeStamp |
// Create the decorator, passing it the Hour |
$DiaryEvent = new DiaryEvent($Hour); |
// Attach the payload |
$DiaryEvent->setEntry($row['entry']); |
// Add the decorator to the selection |
$selection[] = $DiaryEvent; |
} |
// Build the hours in that day, passing the selection |
$Day->build($selection); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Passing a Selection Payload with a Decorator </title> |
</head> |
<body> |
<h1>Passing a Selection "Payload" using a Decorator</h1> |
<table> |
<caption><b>Your Schedule for <?php echo ( date('D nS F Y',$Day->thisDay(TRUE)) ); ?></b></caption> |
<tr> |
<th width="5%">Time</th> |
<th>Entry</th> |
</tr> |
<?php |
while ( $Hour = & $Day->fetch() ) { |
$hour = $Hour->thisHour(); |
$minute = $Hour->thisMinute(); |
// Office hours only... |
if ( $hour >= 8 && $hour <= 18 ) { |
echo ( "<tr>\n" ); |
echo ( "<td>$hour:$minute</td>\n" ); |
// If the hour is selected, call the decorator method... |
if ( $Hour->isSelected() ) { |
echo ( "<td bgcolor=\"silver\">".$Hour->getEntry()."</td>\n" ); |
} else { |
echo ( "<td> </td>\n" ); |
} |
echo ( "</tr>\n" ); |
} |
} |
?> |
</table> |
<p>The query to fetch this data, with help from PEAR::Calendar, might be;</p> |
<pre> |
<?php echo ( $sql ); ?> |
</pre> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/21.phps |
---|
New file |
0,0 → 1,139 |
<?php |
/** |
* Description: a complete year with numeric week numbers |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Year.php'; |
require_once CALENDAR_ROOT.'Month/Weeks.php'; |
define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); |
if (!isset($_GET['year'])) $_GET['year'] = date('Y'); |
$week_types = array( |
'n_in_year', |
'n_in_month', |
); |
if (!isset($_GET['week_type']) || !in_array($_GET['week_type'],$week_types) ) { |
$_GET['week_type'] = 'n_in_year'; |
} |
$Year = new Calendar_Year($_GET['year']); |
$Year->build(); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> <?php echo $Year->thisYear(); ?> </title> |
<style type="text/css"> |
body { |
font-family: Georgia, serif; |
} |
caption.year { |
font-weight: bold; |
font-size: 120%; |
font-color: navy; |
} |
caption.month { |
font-size: 110%; |
font-color: navy; |
} |
table.month { |
border: thin groove #800080 |
} |
tr { |
vertical-align: top; |
} |
th, td { |
text-align: right; |
font-size: 70%; |
} |
#prev { |
float: left; |
font-size: 70%; |
} |
#next { |
float: right; |
font-size: 70%; |
} |
#week_type { |
float: none; |
font-size: 70%; |
} |
.weekNumbers { |
background-color: #e5e5f5; |
padding-right: 3pt; |
} |
</style> |
</head> |
<body> |
<table> |
<caption class="year"> |
<?php echo $Year->thisYear(); ?> |
<div id="next"> |
<a href="?year=<?php echo $Year->nextYear(); ?>&week_type=<?php echo $_GET['week_type']; ?>">>></a> |
</div> |
<div id="prev"> |
<a href="?year=<?php echo $Year->prevYear(); ?>&week_type=<?php echo $_GET['week_type']; ?>"><<</a> |
</div> |
<div id="week_type"> |
<a href="?year=<?php echo $Year->thisYear(); ?>&week_type=n_in_year">Weeks by Year</a> : |
<a href="?year=<?php echo $Year->thisYear(); ?>&week_type=n_in_month">Weeks by Month</a> |
</div> |
</caption> |
<?php |
$i = 0; |
while ($Month = $Year->fetch()) { |
switch ($i) { |
case 0: |
echo "<tr>\n"; |
break; |
case 3: |
case 6: |
case 9: |
echo "</tr>\n<tr>\n"; |
break; |
case 12: |
echo "</tr>\n"; |
break; |
} |
echo "<td>\n<table class=\"month\">\n"; |
echo '<caption class="month">'.date('F', $Month->thisMonth(TRUE)).'</caption>'; |
echo '<colgroup><col class="weekNumbers"><col span="7"></colgroup>'."\n"; |
echo "<tr>\n<th>Week</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th>\n</tr>"; |
$Month->build(); |
while ($Week = $Month->fetch()) { |
echo "<tr>\n"; |
echo '<td>'.$Week->thisWeek($_GET['week_type'])."</td>\n"; |
$Week->build(); |
while ($Day = $Week->fetch()) { |
if ($Day->isEmpty()) { |
echo "<td> </td>\n"; |
} else { |
echo "<td>".$Day->thisDay()."</td>\n"; |
} |
} |
} |
echo "</table>\n</td>\n"; |
$i++; |
} |
?> |
</table> |
<p>Took: <?php echo ((getmicrotime()-$start)); ?></p> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/6.php |
---|
New file |
0,0 → 1,210 |
<?php |
/** |
* Description: A "personal planner" with some WML for fun |
* Note this is done the stupid way - a giant if/else for WML or HTML |
* could be greatly simplified with some HTML/WML rendering classes... |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('n'); |
if (!isset($_GET['d'])) $_GET['d'] = date('j'); |
$Month = & new Calendar_Month_Weekdays($_GET['y'],$_GET['m']); |
$Day = & new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']); |
$selection = array($Day); |
#-----------------------------------------------------------------------------# |
if ( isset($_GET['mime']) && $_GET['mime']=='wml' ) { |
header ('Content-Type: text/vnd.wap.wml'); |
echo ( '<?xml version="1.0"?>' ); |
?> |
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> |
<wml> |
<big><strong>Personal Planner Rendered with WML</strong></big> |
<?php |
if ( isset($_GET['viewday']) ) { |
?> |
<p><strong>Viewing <?php echo ( date('l, jS of F, Y',$Day->getTimeStamp()) ); ?></strong></p> |
<p> |
<anchor> |
Back to Month View |
<go href="<?php |
echo ( "?y=".$Day->thisYear()."&m=". |
$Day->thisMonth()."&d=".$Day->thisDay()."&mime=wml" ); |
?>"/> |
</anchor> |
</p> |
<table> |
<?php |
$Day->build(); |
while ( $Hour = & $Day->fetch() ) { |
echo ( "<tr>\n" ); |
echo ( "<td>".date('g a',$Hour->getTimeStamp())."</td><td>Free time!</td>\n" ); |
echo ( "</tr>\n" ); |
} |
?> |
</table> |
<?php |
} else { |
?> |
<p><strong><?php echo ( date('F Y',$Month->getTimeStamp()) ); ?></strong></p> |
<table> |
<tr> |
<td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td><td>S</td> |
</tr> |
<?php |
$Month->build($selection); |
while ( $Day = $Month->fetch() ) { |
if ( $Day->isFirst() ) { |
echo ( "<tr>\n" ); |
} |
if ( $Day->isEmpty() ) { |
echo ( "<td></td>\n" ); |
} else if ( $Day->isSelected() ) { |
echo ( "<td><anchor><strong><u>".$Day->thisDay()."</u></strong>\n<go href=\"".$_SERVER['PHP_SELF']."?viewday=true&y=". |
$Day->thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). |
"&mime=wml\" />\n</anchor></td>\n" ); |
} else { |
echo ( "<td><anchor>".$Day->thisDay()."\n<go href=\"?viewday=true&y=". |
$Day->thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). |
"&mime=wml\" /></anchor></td>\n" ); |
} |
if ( $Day->isLast() ) { |
echo ( "</tr>\n" ); |
} |
} |
?> |
<tr> |
<td> |
<anchor> |
<< |
<go href="<?php |
echo ( "?y=".$Month->thisYear()."&m=". |
$Month->prevMonth()."&d=".$Month->thisDay()."&mime=wml" ); |
?>"/> |
</anchor> |
</td> |
<td></td><td></td><td></td><td></td><td></td> |
<td> |
<anchor> |
>> |
<go href="<?php |
echo ( "?y=".$Month->thisYear()."&m=". |
$Month->nextMonth()."&d=".$Month->thisDay()."&mime=wml" ); |
?>"/> |
</anchor> |
</td> |
</tr> |
</table> |
<?php |
} |
?> |
<p><a href="<?php echo ( $_SERVER['PHP_SELF'] ); ?>">Back to HTML</a></p> |
<?php echo ( '<p>Took: '.(getmicrotime()-$start).' seconds</p>' ); ?> |
</wml> |
<?php |
#-----------------------------------------------------------------------------# |
} else { |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> HTML (+WML) Personal Planner </title> |
</head> |
<body> |
<h1>Personal Planner Rendered with HTML</h1> |
<p>To view in WML, click <a href="<?php echo ( $_SERVER['PHP_SELF'] ); ?>?mime=wml">here</a> or place a ?mime=wml at the end of any URL. |
Note that <a href="http://www.opera.com/download">Opera</a> supports WML natively and Mozilla / Firefox has the WMLBrowser |
plugin: <a href="http://wmlbrowser.mozdev.org">wmlbrowser.mozdev.org</a></p> |
<?php |
if ( isset($_GET['viewday']) ) { |
?> |
<p><strong>Viewing <?php echo ( date('l, jS of F, Y',$Day->getTimeStamp()) ); ?></strong></p> |
<p> |
<anchor> |
<a href="<?php |
echo ( "?y=".$Day->thisYear()."&m=". |
$Day->thisMonth()."&d=".$Day->thisDay()); |
?>">Back to Month View</a> |
</p> |
<table> |
<?php |
$Day->build(); |
while ( $Hour = & $Day->fetch() ) { |
echo ( "<tr>\n" ); |
echo ( "<td>".date('g a',$Hour->getTimeStamp())."</td><td>Free time!</td>\n" ); |
echo ( "</tr>\n" ); |
} |
?> |
</table> |
<?php |
} else { |
?> |
<p><strong><?php echo ( date('F Y',$Month->getTimeStamp()) ); ?></strong></p> |
<table> |
<tr> |
<td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td><td>S</td> |
</tr> |
<?php |
$Month->build($selection); |
while ( $Day = $Month->fetch() ) { |
if ( $Day->isFirst() ) { |
echo ( "<tr>\n" ); |
} |
if ( $Day->isEmpty() ) { |
echo ( "<td></td>\n" ); |
} else if ( $Day->isSelected() ) { |
echo ( "<td><a href=\"".$_SERVER['PHP_SELF']."?viewday=true&y=". |
$Day->thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). |
"&wml\"><strong><u>".$Day->thisDay()."</u></strong></a></td>\n" ); |
} else { |
echo ( "<td><a href=\"".$_SERVER['PHP_SELF']."?viewday=true&y=". |
$Day->thisYear()."&m=".$Day->thisMonth()."&d=".$Day->thisDay(). |
"\">".$Day->thisDay()."</a></td>\n" ); |
} |
if ( $Day->isLast() ) { |
echo ( "</tr>\n" ); |
} |
} |
?> |
<tr> |
<td> |
<a href="<?php |
echo ( "?y=".$Month->thisYear()."&m=". |
$Month->prevMonth()."&d=".$Month->thisDay() ); |
?>"> |
<<</a> |
</td> |
<td></td><td></td><td></td><td></td><td></td> |
<td> |
<a href="<?php |
echo ( "?y=".$Month->thisYear()."&m=". |
$Month->nextMonth()."&d=".$Month->thisDay() ); |
?>">>></a> |
</td> |
</tr> |
</table> |
<?php |
} |
?> |
<?php echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); ?> |
</body> |
</html> |
<?php |
} |
?> |
/trunk/classes/pear/Calendar/docs/examples/13.phps |
---|
New file |
0,0 → 1,99 |
<?php |
/** |
* Description: same as 1.php, but using the PEAR::Date engine |
* Notice the use of the CALENDAR_ENGINE constant, which |
* switches the calculation "engine" |
* Note: make sure PEAR::Date is a stable release!!! |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
// Switch to PEAR::Date engine |
define('CALENDAR_ENGINE','PearDate'); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
if (!isset($_GET['y'])) $_GET['y'] = 2003; |
if (!isset($_GET['m'])) $_GET['m'] = 8; |
if (!isset($_GET['d'])) $_GET['d'] = 9; |
if (!isset($_GET['h'])) $_GET['h'] = 12; |
if (!isset($_GET['i'])) $_GET['i'] = 34; |
if (!isset($_GET['s'])) $_GET['s'] = 46; |
switch ( @$_GET['view'] ) { |
default: |
$_GET['view'] = 'calendar_year'; |
case 'calendar_year': |
require_once CALENDAR_ROOT.'Year.php'; |
$c = new Calendar_Year($_GET['y']); |
break; |
case 'calendar_month': |
require_once CALENDAR_ROOT.'Month.php'; |
$c = new Calendar_Month($_GET['y'],$_GET['m']); |
break; |
case 'calendar_day': |
require_once CALENDAR_ROOT.'Day.php'; |
$c = new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']); |
break; |
case 'calendar_hour': |
require_once CALENDAR_ROOT.'Hour.php'; |
$c = new Calendar_Hour($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h']); |
break; |
case 'calendar_minute': |
require_once CALENDAR_ROOT.'Minute.php'; |
$c = new Calendar_Minute($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i']); |
break; |
case 'calendar_second': |
require_once CALENDAR_ROOT.'Second.php'; |
$c = new Calendar_Second($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i'],$_GET['s']); |
break; |
} |
// Convert timestamp to human readable date |
$date = new Date($c->getTimestamp()); |
echo ( '<h1>Using PEAR::Date engine</h1>' ); |
echo ( 'Viewing: '.@$_GET['view'].'<br />' ); |
echo ( 'The time is now: '.$date->format('%Y %a %e %T').'<br >' ); |
$i = 1; |
echo ( '<h1>First Iteration</h1>' ); |
echo ( '<p>The first iteration is more "expensive", the calendar data |
structures having to be built.</p>' ); |
$start = getmicrotime(); |
$c->build(); |
while ( $e = $c->fetch() ) { |
$class = strtolower(get_class($e)); |
$link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). |
"&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); |
$method = 'this'.str_replace('calendar_','',$class); |
echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " ); |
if ( ($i % 10) == 0 ) { |
echo ( '<br>' ); |
} |
$i++; |
} |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
$i = 1; |
echo ( '<h1>Second Iteration</h1>' ); |
echo ( '<p>This second iteration is faster, the data structures |
being re-used</p>' ); |
$start = getmicrotime(); |
while ( $e = $c->fetch() ) { |
$class = strtolower(get_class($e)); |
$link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). |
"&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); |
$method = 'this'.str_replace('calendar_','',$class); |
echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " ); |
if ( ($i % 10) == 0 ) { |
echo ( '<br>' ); |
} |
$i++; |
} |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
?> |
/trunk/classes/pear/Calendar/docs/examples/7.php |
---|
New file |
0,0 → 1,92 |
<?php |
/** |
* Description: a SOAP Calendar Server |
*/ |
if (!@include('SOAP'.DIRECTORY_SEPARATOR.'Server.php')) { |
die('You must have PEAR::SOAP installed'); |
} |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
class Calendar_Server |
{ |
var $__dispatch_map = array(); |
var $__typedef = array(); |
function Calendar_Server() |
{ |
$this->__dispatch_map['getMonth'] = |
array('in' => array('year' => 'int', 'month'=>'int'), |
'out' => array('month' => '{urn:PEAR_SOAP_Calendar}Month'), |
); |
$this->__typedef['Month'] = array ( |
'monthname' => 'string', |
'days' => '{urn:PEAR_SOAP_Calendar}MonthDays' |
); |
$this->__typedef['MonthDays'] = array (array ('{urn:PEAR_SOAP_Calendar}Day')); |
$this->__typedef['Day'] = array ( |
'isFirst' => 'int', |
'isLast' => 'int', |
'isEmpty' => 'int', |
'day' => 'int' ); |
} |
function __dispatch($methodname) |
{ |
if (isset($this->__dispatch_map[$methodname])) |
return $this->__dispatch_map[$methodname]; |
return NULL; |
} |
function getMonth($year, $month) |
{ |
require_once(CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php'); |
$Month = & new Calendar_Month_Weekdays($year,$month); |
if (!$Month->isValid()) { |
$V = & $Month->getValidator(); |
$errorMsg = ''; |
while ($error = $V->fetch()) { |
$errorMsg .= $error->toString()."\n"; |
} |
return new SOAP_Fault($errorMsg, 'Client'); |
} else { |
$monthname = date('F Y', $Month->getTimeStamp()); |
$days = array(); |
$Month->build(); |
while ($Day = & $Month->fetch()) { |
$day = array( |
'isFirst' => (int)$Day->isFirst(), |
'isLast' => (int)$Day->isLast(), |
'isEmpty' => (int)$Day->isEmpty(), |
'day' => (int)$Day->thisDay(), |
); |
$days[] = $day; |
} |
return array('monthname' => $monthname, 'days' => $days); |
} |
} |
} |
$server = new SOAP_Server(); |
$server->_auto_translation = true; |
$calendar = new Calendar_Server(); |
$server->addObjectMap($calendar, 'urn:PEAR_SOAP_Calendar'); |
if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') { |
$server->service($GLOBALS['HTTP_RAW_POST_DATA']); |
} else { |
require_once 'SOAP'.DIRECTORY_SEPARATOR.'Disco.php'; |
$disco = new SOAP_DISCO_Server($server, "PEAR_SOAP_Calendar"); |
if (isset($_SERVER['QUERY_STRING']) && |
strcasecmp($_SERVER['QUERY_STRING'], 'wsdl')==0) { |
header("Content-type: text/xml"); |
echo $disco->getWSDL(); |
} else { |
echo 'This is a PEAR::SOAP Calendar Server. For client try <a href="8.php">here</a><br />'; |
echo 'For WSDL try <a href="?wsdl">here</a>'; |
} |
exit; |
} |
?> |
/trunk/classes/pear/Calendar/docs/examples/23.phps |
---|
New file |
0,0 → 1,66 |
<?php |
/** |
* Description: demonstrates using the Textual util |
*/ |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php'; |
require_once CALENDAR_ROOT.'Util'.DIRECTORY_SEPARATOR.'Textual.php'; |
// Could change language like this |
// setlocale (LC_TIME, "de_DE"); // Unix based (probably) |
// setlocale (LC_TIME, "ge"); // Windows |
echo "<hr>Calling: Calendar_Util_Textual::monthNames('long');<pre>"; |
print_r(Calendar_Util_Textual::monthNames('long')); |
echo '</pre>'; |
echo "<hr>Calling: Calendar_Util_Textual::weekdayNames('two');<pre>"; |
print_r(Calendar_Util_Textual::weekdayNames('two')); |
echo '</pre>'; |
echo "<hr>Creating: new Calendar_Day(date('Y'), date('n'), date('d'));<br />"; |
$Calendar = new Calendar_Day(date('Y'), date('n'), date('d')); |
echo '<hr>Previous month is: '.Calendar_Util_Textual::prevMonthName($Calendar,'two').'<br />'; |
echo 'This month is: '.Calendar_Util_Textual::thisMonthName($Calendar,'short').'<br />'; |
echo 'Next month is: '.Calendar_Util_Textual::nextMonthName($Calendar).'<br /><hr />'; |
echo 'Previous day is: '.Calendar_Util_Textual::prevDayName($Calendar).'<br />'; |
echo 'This day is: '.Calendar_Util_Textual::thisDayName($Calendar,'short').'<br />'; |
echo 'Next day is: '.Calendar_Util_Textual::nextDayName($Calendar,'one').'<br /><hr />'; |
echo "Creating: new Calendar_Month_Weekdays(date('Y'), date('n'), 6); - Saturday is first day of week<br />"; |
$Calendar = new Calendar_Month_Weekdays(date('Y'), date('n'), 6); |
?> |
<p>Rendering calendar....</p> |
<table> |
<caption><?php echo Calendar_Util_Textual::thisMonthName($Calendar).' '.$Calendar->thisYear(); ?></caption> |
<tr> |
<?php |
$dayheaders = Calendar_Util_Textual::orderedWeekdays($Calendar,'short'); |
foreach ($dayheaders as $dayheader) { |
echo '<th>'.$dayheader.'</th>'; |
} |
?> |
</tr> |
<?php |
$Calendar->build(); |
while ($Day = $Calendar->fetch()) { |
if ($Day->isFirst()) { |
echo "<tr>\n"; |
} |
if ($Day->isEmpty()) { |
echo '<td> </td>'; |
} else { |
echo '<td>'.$Day->thisDay().'</td>'; |
} |
if ($Day->isLast()) { |
echo "</tr>\n"; |
} |
} |
?> |
</table> |
/trunk/classes/pear/Calendar/docs/examples/8.php |
---|
New file |
0,0 → 1,70 |
<?php |
/** |
* Description: client for the SOAP Calendar Server |
*/ |
if ( version_compare(phpversion(), "5.0.0", ">") ) { |
die('PHP 5 has problems with PEAR::SOAP Client (8.0RC3) |
- remove @ before include below to see why'); |
} |
if (!@include('SOAP'.DIRECTORY_SEPARATOR.'Client.php')) { |
die('You must have PEAR::SOAP installed'); |
} |
// Just to save manaul modification... |
$basePath = explode('/', $_SERVER['SCRIPT_NAME']); |
array_pop($basePath); |
$basePath = implode('/', $basePath); |
$url = 'http://'.$_SERVER['SERVER_NAME'].$basePath.'/7.php?wsdl'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('n'); |
$wsdl = new SOAP_WSDL ($url); |
echo ( '<pre>'.$wsdl->generateProxyCode().'</pre>' ); |
$calendarClient = $wsdl->getProxy(); |
$month = $calendarClient->getMonth((int)$_GET['y'],(int)$_GET['m']); |
if ( PEAR::isError($month) ) { |
die ( $month->toString() ); |
} |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar over the Wire </title> |
</head> |
<body> |
<h1>Calendar Over the Wire (featuring PEAR::SOAP)</h1> |
<table> |
<caption><b><?php echo ( $month->monthname );?></b></caption> |
<tr> |
<th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th> |
</tr> |
<?php |
foreach ( $month->days as $day ) { |
if ( $day->isFirst === 1 ) |
echo ( "<tr>\n" ); |
if ( $day->isEmpty === 1 ) { |
echo ( "<td></td>" ); |
} else { |
echo ( "<td>".$day->day."</td>" ); |
} |
if ( $day->isLast === 1 ) |
echo ( "</tr>\n" ); |
} |
?> |
<tr> |
</table> |
<p>Enter Year and Month to View:</p> |
<form action="<?php echo ( $_SERVER['PHP_SELF'] ); ?>" method="get"> |
Year: <input type="text" size="4" name="y" value="<?php echo ( $_GET['y'] ); ?>"> |
Month: <input type="text" size="2" name="m" value="<?php echo ( $_GET['m'] ); ?>"> |
<input type="submit" value="Fetch Calendar"> |
</form> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/15.phps |
---|
New file |
0,0 → 1,58 |
<?php |
/** |
* Shows more on how a week can be used |
*/ |
function getmicrotime() { |
list($usec, $sec) = explode(" ", microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Week.php'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('m'); |
if (!isset($_GET['d'])) $_GET['d'] = 1; |
// Build the month |
$Week = new Calendar_Week($_GET['y'], $_GET['m'], $_GET['d']); |
/* |
$Validator = $Week->getValidator(); |
if (!$Validator->isValidWeek()) { |
die ('Please enter a valid week!'); |
} |
*/ |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Paging Weeks </title> |
</head> |
<body> |
<h1>Paging Weeks</h1> |
<h2>Week: <?php echo $Week->thisWeek().' '.date('F Y',$Week->thisMonth(true)); ?></h2> |
<?php |
$Week->build(); |
while ($Day = $Week->fetch()) { |
echo '<p>'.date('jS F',$Day->thisDay(true))."</p>\n"; |
} |
$days = $Week->fetchAll(); |
$prevWeek = $Week->prevWeek('array'); |
$prevWeekLink = $_SERVER['PHP_SELF']. |
'?y='.$prevWeek['year']. |
'&m='.$prevWeek['month']. |
'&d='.$prevWeek['day']; |
$nextWeek = $Week->nextWeek('array'); |
$nextWeekLink = $_SERVER['PHP_SELF']. |
'?y='.$nextWeek['year']. |
'&m='.$nextWeek['month']. |
'&d='.$nextWeek['day']; |
?> |
<p><a href="<?php echo $prevWeekLink; ?>"><<</a> | <a href="<?php echo $nextWeekLink; ?>">>></a></p> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/9.php |
---|
New file |
0,0 → 1,16 |
<?php |
/** |
* Description: simple example on i18N |
*/ |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
$Day = & new Calendar_Day(2003,10,23); |
setlocale (LC_TIME, "de_DE"); // Unix based (probably) |
// setlocale (LC_TIME, "ge"); // Windows |
echo ( strftime('%A %d %B %Y',$Day->getTimeStamp())); |
?> |
/trunk/classes/pear/Calendar/docs/examples/17.phps |
---|
New file |
0,0 → 1,71 |
<?php |
/** |
* Description: demonstrates using the Textual decorator |
*/ |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php'; |
require_once CALENDAR_ROOT.'Decorator'.DIRECTORY_SEPARATOR.'Textual.php'; |
// Could change language like this |
// setlocale (LC_TIME, "de_DE"); // Unix based (probably) |
// setlocale (LC_TIME, "ge"); // Windows |
echo "<hr>Calling: Calendar_Decorator_Textual::monthNames('long');<pre>"; |
print_r(Calendar_Decorator_Textual::monthNames('long')); |
echo '</pre>'; |
echo "<hr>Calling: Calendar_Decorator_Textual::weekdayNames('two');<pre>"; |
print_r(Calendar_Decorator_Textual::weekdayNames('two')); |
echo '</pre>'; |
echo "<hr>Creating: new Calendar_Day(date('Y'), date('n'), date('d'));<br />"; |
$Calendar = new Calendar_Day(date('Y'), date('n'), date('d')); |
// Decorate |
$Textual = & new Calendar_Decorator_Textual($Calendar); |
echo '<hr>Previous month is: '.$Textual->prevMonthName('two').'<br />'; |
echo 'This month is: '.$Textual->thisMonthName('short').'<br />'; |
echo 'Next month is: '.$Textual->nextMonthName().'<br /><hr />'; |
echo 'Previous day is: '.$Textual->prevDayName().'<br />'; |
echo 'This day is: '.$Textual->thisDayName('short').'<br />'; |
echo 'Next day is: '.$Textual->nextDayName('one').'<br /><hr />'; |
echo "Creating: new Calendar_Month_Weekdays(date('Y'), date('n'), 6); - Saturday is first day of week<br />"; |
$Calendar = new Calendar_Month_Weekdays(date('Y'), date('n'), 6); |
// Decorate |
$Textual = & new Calendar_Decorator_Textual($Calendar); |
?> |
<p>Rendering calendar....</p> |
<table> |
<caption><?php echo $Textual->thisMonthName().' '.$Textual->thisYear(); ?></caption> |
<tr> |
<?php |
$dayheaders = $Textual->orderedWeekdays('short'); |
foreach ($dayheaders as $dayheader) { |
echo '<th>'.$dayheader.'</th>'; |
} |
?> |
</tr> |
<?php |
$Calendar->build(); |
while ($Day = $Calendar->fetch()) { |
if ($Day->isFirst()) { |
echo "<tr>\n"; |
} |
if ($Day->isEmpty()) { |
echo '<td> </td>'; |
} else { |
echo '<td>'.$Day->thisDay().'</td>'; |
} |
if ($Day->isLast()) { |
echo "</tr>\n"; |
} |
} |
?> |
</table> |
/trunk/classes/pear/Calendar/docs/examples/19.phps |
---|
New file |
0,0 → 1,24 |
<?php |
/** |
* Description: demonstrates using the Weekday decorator |
*/ |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Decorator/Weekday.php'; |
$Day = new Calendar_Day(date('Y'), date('n'),date('d')); |
$WeekDay = & new Calendar_Decorator_Weekday($Day); |
// $WeekDay->setFirstDay(0); // Make Sunday first Day |
echo 'Yesterday: '.$WeekDay->prevWeekDay().'<br>'; |
echo 'Today: '.$WeekDay->thisWeekDay().'<br>'; |
echo 'Tomorrow: '.$WeekDay->nextWeekDay().'<br>'; |
$WeekDay->build(); |
echo 'Hours today:<br>'; |
while ( $Hour = $WeekDay->fetch() ) { |
echo $Hour->thisHour().'<br>'; |
} |
?> |
/trunk/classes/pear/Calendar/docs/examples/10.php |
---|
New file |
0,0 → 1,93 |
<?php |
/** |
* Description: demonstrates a decorator to provide simple output formatting |
* on the month while still allowing the days to be accessed via the decorator |
* In practice you _wouldn't_ do this - each decorator comes with a performance |
* hit for extra method calls. For this example some simple functions could help |
* format the month while the days are accessed via the normal Month object |
*/ |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Decorator.php'; |
// Decorate a Month with methods to improve formatting |
class MonthDecorator extends Calendar_Decorator { |
/** |
* @param Calendar_Month |
*/ |
function MonthDecorator(& $Month) { |
parent::Calendar_Decorator($Month); |
} |
/** |
* Override the prevMonth method to format the output |
*/ |
function prevMonth() { |
$prevStamp = parent::prevMonth(TRUE); |
// Build the URL for the previous month |
return $_SERVER['PHP_SELF'].'?y='.date('Y',$prevStamp). |
'&m='.date('n',$prevStamp).'&d='.date('j',$prevStamp); |
} |
/** |
* Override the thisMonth method to format the output |
*/ |
function thisMonth() { |
$thisStamp = parent::thisMonth(TRUE); |
// A human readable string from this month |
return date('F Y',$thisStamp); |
} |
/** |
* Override the nextMonth method to format the output |
*/ |
function nextMonth() { |
$nextStamp = parent::nextMonth(TRUE); |
// Build the URL for next month |
return $_SERVER['PHP_SELF'].'?y='.date('Y',$nextStamp). |
'&m='.date('n',$nextStamp).'&d='.date('j',$nextStamp); |
} |
} |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('n'); |
// Creata a month as usual |
$Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']); |
// Pass it to the decorator and use the decorator from now on... |
$MonthDecorator = new MonthDecorator($Month); |
$MonthDecorator->build(); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> A Simple Decorator </title> |
</head> |
<body> |
<h1>A Simple Decorator</h1> |
<table> |
<caption><?php echo ( $MonthDecorator->thisMonth() ); ?></caption> |
<?php |
while ( $Day = $MonthDecorator->fetch() ) { |
if ( $Day->isFirst() ) { |
echo ( "\n<tr>\n" ); |
} |
if ( $Day->isEmpty() ) { |
echo ( "<td> </td>" ); |
} else { |
echo ( "<td>".$Day->thisDay()."</td>" ); |
} |
if ( $Day->isLast() ) { |
echo ( "\n</tr>\n" ); |
} |
} |
?> |
<tr> |
<td><a href="<?php echo ($MonthDecorator->prevMonth()); ?>">Prev</a></td> |
<td colspan="5"> </td> |
<td><a href="<?php echo ($MonthDecorator->nextMonth()); ?>">Next</a></td> |
</tr> |
</table> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/11.php |
---|
New file |
0,0 → 1,109 |
<?php |
/** |
* Description: demonstrates a decorator used to "attach a payload" to a selection |
* to make it available when iterating over calendar children |
*/ |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Hour.php'; |
require_once CALENDAR_ROOT.'Decorator.php'; |
// Decorator to "attach" functionality to selected hours |
class DiaryEvent extends Calendar_Decorator { |
var $entry; |
function DiaryEvent($calendar) { |
Calendar_Decorator::Calendar_Decorator($calendar); |
} |
function setEntry($entry) { |
$this->entry = $entry; |
} |
function getEntry() { |
return $this->entry; |
} |
} |
// Create a day to view the hours for |
$Day = & new Calendar_Day(2003,10,24); |
// A sample query to get the data for today (NOT ACTUALLY USED HERE) |
$sql = " |
SELECT |
* |
FROM |
diary |
WHERE |
eventtime >= '".$Day->thisDay(TRUE)."' |
AND |
eventtime < '".$Day->nextDay(TRUE)."';"; |
// An array simulating data from a database |
$result = array ( |
array('eventtime'=>mktime(9,0,0,10,24,2003),'entry'=>'Meeting with sales team'), |
array('eventtime'=>mktime(11,0,0,10,24,2003),'entry'=>'Conference call with Widget Inc.'), |
array('eventtime'=>mktime(15,0,0,10,24,2003),'entry'=>'Presentation to board of directors') |
); |
// An array to place selected hours in |
$selection = array(); |
// Loop through the "database result" |
foreach ( $result as $row ) { |
$Hour = new Calendar_Hour(2000,1,1,1); // Create Hour with dummy values |
$Hour->setTimeStamp($row['eventtime']); // Set the real time with setTimeStamp |
// Create the decorator, passing it the Hour |
$DiaryEvent = new DiaryEvent($Hour); |
// Attach the payload |
$DiaryEvent->setEntry($row['entry']); |
// Add the decorator to the selection |
$selection[] = $DiaryEvent; |
} |
// Build the hours in that day, passing the selection |
$Day->build($selection); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Passing a Selection Payload with a Decorator </title> |
</head> |
<body> |
<h1>Passing a Selection "Payload" using a Decorator</h1> |
<table> |
<caption><b>Your Schedule for <?php echo ( date('D nS F Y',$Day->thisDay(TRUE)) ); ?></b></caption> |
<tr> |
<th width="5%">Time</th> |
<th>Entry</th> |
</tr> |
<?php |
while ( $Hour = & $Day->fetch() ) { |
$hour = $Hour->thisHour(); |
$minute = $Hour->thisMinute(); |
// Office hours only... |
if ( $hour >= 8 && $hour <= 18 ) { |
echo ( "<tr>\n" ); |
echo ( "<td>$hour:$minute</td>\n" ); |
// If the hour is selected, call the decorator method... |
if ( $Hour->isSelected() ) { |
echo ( "<td bgcolor=\"silver\">".$Hour->getEntry()."</td>\n" ); |
} else { |
echo ( "<td> </td>\n" ); |
} |
echo ( "</tr>\n" ); |
} |
} |
?> |
</table> |
<p>The query to fetch this data, with help from PEAR::Calendar, might be;</p> |
<pre> |
<?php echo ( $sql ); ?> |
</pre> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/12.php |
---|
New file |
0,0 → 1,116 |
<?php |
/** |
* Description: a complete year |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Year.php'; |
define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); |
if ( !isset($_GET['year']) ) $_GET['year'] = date('Y'); |
$Year = new Calendar_Year($_GET['year']); |
$Year->build(); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> <?php echo ( $Year->thisYear() ); ?> </title> |
<style type="text/css"> |
body { |
font-family: Georgia, serif; |
} |
caption.year { |
font-weight: bold; |
font-size: 120%; |
font-color: navy; |
} |
caption.month { |
font-size: 110%; |
font-color: navy; |
} |
table.month { |
border: thin groove #800080 |
} |
tr { |
vertical-align: top; |
} |
th, td { |
text-align: right; |
font-size: 70%; |
} |
#prev { |
float: left; |
font-size: 70%; |
} |
#next { |
float: right; |
font-size: 70%; |
} |
</style> |
</head> |
<body> |
<table> |
<caption class="year"> |
<?php echo ( $Year->thisYear() ); ?> |
<div id="next"> |
<a href="?year=<?php echo ( $Year->nextYear() ); ?>">>></a> |
</div> |
<div id="prev"> |
<a href="?year=<?php echo ( $Year->prevYear() ); ?>"><<</a> |
</div> |
</caption> |
<?php |
$i = 0; |
while ( $Month = $Year->fetch() ) { |
switch ( $i ) { |
case 0: |
echo ( "<tr>\n" ); |
break; |
case 3: |
case 6: |
case 9: |
echo ( "</tr>\n<tr>\n" ); |
break; |
case 12: |
echo ( "</tr>\n" ); |
break; |
} |
echo ( "<td>\n<table class=\"month\">\n" ); |
echo ( "<caption class=\"month\">".date('F',$Month->thisMonth(TRUE))."</caption>" ); |
echo ( "<tr>\n<th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th>\n</tr>" ); |
$Month->build(); |
while ( $Day = $Month->fetch() ) { |
if ( $Day->isFirst() ) { |
echo ( "<tr>\n" ); |
} |
if ( $Day->isEmpty() ) { |
echo ( "<td> </td>\n" ); |
} else { |
echo ( "<td>".$Day->thisDay()."</td>\n" ); |
} |
if ( $Day->isLast() ) { |
echo ( "</tr>\n" ); |
} |
} |
echo ( "</table>\n</td>\n" ); |
$i++; |
} |
?> |
</table> |
<p>Took: <?php echo ((getmicrotime()-$start)); ?></p> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/1.phps |
---|
New file |
0,0 → 1,92 |
<?php |
/** |
* Description: Passes through all main calendar classes, beginning with year |
* and down to seconds, skipping weeks. Useful to test Calendar is (basically) |
* working correctly |
* |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
if (!isset($_GET['y'])) $_GET['y'] = 2003; |
if (!isset($_GET['m'])) $_GET['m'] = 8; |
if (!isset($_GET['d'])) $_GET['d'] = 9; |
if (!isset($_GET['h'])) $_GET['h'] = 12; |
if (!isset($_GET['i'])) $_GET['i'] = 34; |
if (!isset($_GET['s'])) $_GET['s'] = 46; |
switch ( @$_GET['view'] ) { |
default: |
$_GET['view'] = 'calendar_year'; |
case 'calendar_year': |
require_once CALENDAR_ROOT.'Year.php'; |
$c = new Calendar_Year($_GET['y']); |
break; |
case 'calendar_month': |
require_once CALENDAR_ROOT.'Month.php'; |
$c = new Calendar_Month($_GET['y'],$_GET['m']); |
break; |
case 'calendar_day': |
require_once CALENDAR_ROOT.'Day.php'; |
$c = new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']); |
break; |
case 'calendar_hour': |
require_once CALENDAR_ROOT.'Hour.php'; |
$c = new Calendar_Hour($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h']); |
break; |
case 'calendar_minute': |
require_once CALENDAR_ROOT.'Minute.php'; |
$c = new Calendar_Minute($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i']); |
break; |
case 'calendar_second': |
require_once CALENDAR_ROOT.'Second.php'; |
$c = new Calendar_Second($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i'],$_GET['s']); |
break; |
} |
echo ( 'Viewing: '.@$_GET['view'].'<br />' ); |
echo ( 'The time is now: '.date('Y M d H:i:s',$c->getTimestamp()).'<br >' ); |
$i = 1; |
echo ( '<h1>First Iteration</h1>' ); |
echo ( '<p>The first iteration is more "expensive", the calendar data |
structures having to be built.</p>' ); |
$start = getmicrotime(); |
$c->build(); |
while ( $e = $c->fetch() ) { |
$class = strtolower(get_class($e)); |
$link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). |
"&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); |
$method = 'this'.str_replace('calendar_','',$class); |
echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " ); |
if ( ($i % 10) == 0 ) { |
echo ( '<br>' ); |
} |
$i++; |
} |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
$i = 1; |
echo ( '<h1>Second Iteration</h1>' ); |
echo ( '<p>This second iteration is faster, the data structures |
being re-used</p>' ); |
$start = getmicrotime(); |
while ( $e = $c->fetch() ) { |
$class = strtolower(get_class($e)); |
$link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). |
"&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); |
$method = 'this'.str_replace('calendar_','',$class); |
echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " ); |
if ( ($i % 10) == 0 ) { |
echo ( '<br>' ); |
} |
$i++; |
} |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
?> |
/trunk/classes/pear/Calendar/docs/examples/13.php |
---|
New file |
0,0 → 1,99 |
<?php |
/** |
* Description: same as 1.php, but using the PEAR::Date engine |
* Notice the use of the CALENDAR_ENGINE constant, which |
* switches the calculation "engine" |
* Note: make sure PEAR::Date is a stable release!!! |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
// Switch to PEAR::Date engine |
define('CALENDAR_ENGINE','PearDate'); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
if (!isset($_GET['y'])) $_GET['y'] = 2003; |
if (!isset($_GET['m'])) $_GET['m'] = 8; |
if (!isset($_GET['d'])) $_GET['d'] = 9; |
if (!isset($_GET['h'])) $_GET['h'] = 12; |
if (!isset($_GET['i'])) $_GET['i'] = 34; |
if (!isset($_GET['s'])) $_GET['s'] = 46; |
switch ( @$_GET['view'] ) { |
default: |
$_GET['view'] = 'calendar_year'; |
case 'calendar_year': |
require_once CALENDAR_ROOT.'Year.php'; |
$c = new Calendar_Year($_GET['y']); |
break; |
case 'calendar_month': |
require_once CALENDAR_ROOT.'Month.php'; |
$c = new Calendar_Month($_GET['y'],$_GET['m']); |
break; |
case 'calendar_day': |
require_once CALENDAR_ROOT.'Day.php'; |
$c = new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']); |
break; |
case 'calendar_hour': |
require_once CALENDAR_ROOT.'Hour.php'; |
$c = new Calendar_Hour($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h']); |
break; |
case 'calendar_minute': |
require_once CALENDAR_ROOT.'Minute.php'; |
$c = new Calendar_Minute($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i']); |
break; |
case 'calendar_second': |
require_once CALENDAR_ROOT.'Second.php'; |
$c = new Calendar_Second($_GET['y'],$_GET['m'],$_GET['d'],$_GET['h'],$_GET['i'],$_GET['s']); |
break; |
} |
// Convert timestamp to human readable date |
$date = new Date($c->getTimestamp()); |
echo ( '<h1>Using PEAR::Date engine</h1>' ); |
echo ( 'Viewing: '.@$_GET['view'].'<br />' ); |
echo ( 'The time is now: '.$date->format('%Y %a %e %T').'<br >' ); |
$i = 1; |
echo ( '<h1>First Iteration</h1>' ); |
echo ( '<p>The first iteration is more "expensive", the calendar data |
structures having to be built.</p>' ); |
$start = getmicrotime(); |
$c->build(); |
while ( $e = $c->fetch() ) { |
$class = strtolower(get_class($e)); |
$link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). |
"&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); |
$method = 'this'.str_replace('calendar_','',$class); |
echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " ); |
if ( ($i % 10) == 0 ) { |
echo ( '<br>' ); |
} |
$i++; |
} |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
$i = 1; |
echo ( '<h1>Second Iteration</h1>' ); |
echo ( '<p>This second iteration is faster, the data structures |
being re-used</p>' ); |
$start = getmicrotime(); |
while ( $e = $c->fetch() ) { |
$class = strtolower(get_class($e)); |
$link ="&y=".$e->thisYear()."&m=".$e->thisMonth()."&d=".$e->thisDay(). |
"&h=".$e->thisHour()."&i=".$e->thisMinute()."&s=".$e->thisSecond(); |
$method = 'this'.str_replace('calendar_','',$class); |
echo ( "<a href=\"".$_SERVER['PHP_SELF']."?view=".$class.$link."\">".$e->{$method}()."</a> : " ); |
if ( ($i % 10) == 0 ) { |
echo ( '<br>' ); |
} |
$i++; |
} |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
?> |
/trunk/classes/pear/Calendar/docs/examples/14.php |
---|
New file |
0,0 → 1,141 |
<?php |
/** |
* Description: same as 3.php, but using the PEAR::Date engine |
* Note: make sure PEAR::Date is a stable release!!! |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
// Switch to PEAR::Date engine |
define('CALENDAR_ENGINE', 'PearDate'); |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
// Initialize GET variables if not set |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('m'); |
if (!isset($_GET['d'])) $_GET['d'] = date('d'); |
// Build the month |
$month = new Calendar_Month_Weekdays($_GET['y'], $_GET['m']); |
// Create an array of days which are "selected" |
// Used for Week::build() below |
$selectedDays = array ( |
new Calendar_Day($_GET['y'], $_GET['m'], $_GET['d']), |
new Calendar_Day($_GET['y'], 12, 25), |
); |
// Build the days in the month |
$month->build($selectedDays); |
// Construct strings for next/previous links |
$PMonth = $month->prevMonth('object'); // Get previous month as object |
$prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); |
$NMonth = $month->nextMonth('object'); |
$next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); |
$thisDate = new Date($month->thisMonth('timestamp')); |
?> |
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar using PEAR::Date Engine </title> |
<style text="text/css"> |
table { |
background-color: silver; |
} |
caption { |
font-family: verdana; |
font-size: 12px; |
background-color: while; |
} |
.prevMonth { |
font-size: 10px; |
text-align: left; |
} |
.nextMonth { |
font-size: 10px; |
text-align: right; |
} |
th { |
font-family: verdana; |
font-size: 11px; |
color: navy; |
text-align: right; |
} |
td { |
font-family: verdana; |
font-size: 11px; |
text-align: right; |
} |
.selected { |
background-color: yellow; |
} |
</style> |
</head> |
<body> |
<h2>Calendar using PEAR::Date Engine</h2> |
<table class="calendar"> |
<caption> |
<?php echo $thisDate->format('%B %Y'); ?> |
</caption> |
<tr> |
<th>M</th> |
<th>T</th> |
<th>W</th> |
<th>T</th> |
<th>F</th> |
<th>S</th> |
<th>S</th> |
</tr> |
<?php |
while ($day = $month->fetch()) { |
// Build a link string for each day |
$link = $_SERVER['PHP_SELF']. |
'?y='.$day->thisYear(). |
'&m='.$day->thisMonth(). |
'&d='.$day->thisDay(); |
// isFirst() to find start of week |
if ($day->isFirst()) |
echo "<tr>\n"; |
if ($day->isSelected()) { |
echo '<td class="selected">'.$day->thisDay().'</td>'."\n"; |
} else if ($day->isEmpty()) { |
echo '<td> </td>'."\n"; |
} else { |
echo '<td><a href="'.$link.'">'.$day->thisDay().'</a></td>'."\n"; |
} |
// isLast() to find end of week |
if ($day->isLast()) { |
echo "</tr>\n"; |
} |
} |
?> |
<tr> |
<td> |
<a href="<?php echo $prev; ?>" class="prevMonth"><< </a> |
</td> |
<td colspan="5"> </td> |
<td> |
<a href="<?php echo $next; ?>" class="nextMonth"> >></a> |
</td> |
</tr> |
</table> |
<?php |
echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>'; |
?> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/index.html |
---|
New file |
0,0 → 1,50 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
<head> |
<title>PEAR::Calendar Examples</title> |
<style type="text/css"> |
body { |
font-family: georgia, serif; |
} |
pre { |
background-color: silver; |
} |
code { |
color: navy; |
background-color: #e2e3e4; |
} |
</style> |
</head> |
<body> |
<h1>PEAR::Calendar Examples</h1> |
<p>$Id: index.html,v 1.6 2004/08/17 09:10:53 hfuecks Exp $</p> |
<ul> |
<li><a href="1.php">1.php</a> [<a href="1.phps">src</a>] - shows basic usage, passing all the way down from <code>Calendar_Year</code> to <code>Calendar_Second</code> - more of a quick test it's working</li> |
<li><a href="2.php">2.php</a> [<a href="2.phps">src</a>] - shows how to build a tabular month using <code>Calendar_Month_Weeks</code>, <code>Calendar_Week</code>, <code>Calendar_Day</code> as well as selecting some dates.</li> |
<li><a href="3.php">3.php</a> [<a href="3.phps">src</a>] - shows how to build a tabular month using <code>Calendar_Month_Weekdays</code> and <code>Calendar_Day</code>, as well as selecting some dates (this method is faster).</li> |
<li><a href="4.php">4.php</a> [<a href="4.phps">src</a>] - shows how to use PEAR::Calendar for validation.</li> |
<li><a href="5.php">5.php</a> [<a href="5.phps">src</a>] - shows PEAR::Calendar in use to help generate a form.</li> |
<li><a href="6.php">6.php</a> [<a href="6.phps">src</a>] - a month and day "planner" calendar, which can be rendered both as HTML and WML.</li> |
<li><a href="7.php">7.php</a> [<a href="7.phps">src</a>] - a simple SOAP Calendar Server, using PEAR::SOAP and PEAR::Calendar</li> |
<li><a href="8.php">8.php</a> [<a href="8.phps">src</a>] - a WSDL SOAP client for the SOAP Calendar Server</li> |
<li><a href="9.php">9.php</a> [<a href="9.phps">src</a>] - quick example of i18n with <code>setlocale</code> (not working on SF)</li> |
<li><a href="10.php">10.php</a> [<a href="10.phps">src</a>] - an example of extending <code>Calendar_Decorator</code> to modify output</li> |
<li><a href="11.php">11.php</a> [<a href="11.phps">src</a>] - attaching a "payload" (e.g. results of a DB query) to a calendar using <code>Calendar_Decorator</code> to allow the payload to be available inside the main loop.</li> |
<li><a href="12.php">12.php</a> [<a href="12.phps">src</a>] - a complete year with months.</li> |
<li><a href="13.php">13.php</a> [<a href="13.phps">src</a>] - same as 1.php but using <code>Calendar_Engine_PearDate</code>, (see <a href="http://pear.php.net/Date">PEAR::Date</a>).</li> |
<li><a href="14.php">14.php</a> [<a href="14.phps">src</a>] - same as 3.php but using <code>Calendar_Engine_PearDate</code></li> |
<li><a href="15.php">15.php</a> [<a href="15.phps">src</a>] - paging through weeks </li> |
<li><a href="16.php">16.php</a> [<a href="16.phps">src</a>] - example of <code>Calendar_Decorator_Uri</code>. <i>Note</i> you should prefer <code>Calendar_Util_Uri</code> (see below) in most cases, for performance </li> |
<li><a href="17.php">17.php</a> [<a href="17.phps">src</a>] - example of <code>Calendar_Decorator_Textual</code>. <i>Note</i> you should prefer <code>Calendar_Util_Textual</code> (see below) in most cases, for performance</li> |
<li><a href="18.php">18.php</a> [<a href="18.phps">src</a>] - example of <code>Calendar_Decorator_Wrapper</code>.</li> |
<li><a href="19.php">19.php</a> [<a href="19.phps">src</a>] - example of <code>Calendar_Decorator_Weekday</code>.</li> |
<li><a href="20.php">20.php</a> [<a href="20.phps">src</a>] - shows how to attach a "payload" spanning multiple days, with more than one entry per day</li> |
<li><a href="21.php">21.php</a> [<a href="21.phps">src</a>] - same as 12.php but using <code>Calendar_Month_Weeks</code> instead of <code>Calendar_Month_Weekdays</code> to allow the week in the year or week in the month to be displayed.</li> |
<li><a href="22.php">22.php</a> [<a href="22.phps">src</a>] - demonstrates use of <code>Calendar_Util_Uri</code>.</li> |
<li><a href="23.php">23.php</a> [<a href="23.phps">src</a>] - demonstrates use of <code>Calendar_Util_Textual</code>.</li> |
<li><a href="24.php">24.php</a> [<a href="24.phps">src</a>] - <code>Calendar_Decorator_Weekday</code> combined with <code>Calendar_Decorator_Wrapper</code> to decorate days in the month.</li> |
</ul> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/3.phps |
---|
New file |
0,0 → 1,134 |
<?php |
/** |
* Description: Performs same behaviour as 2.php but uses Month::buildWeekDays() |
* and is faster |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('m'); |
if (!isset($_GET['d'])) $_GET['d'] = date('d'); |
// Build the month |
$Month = new Calendar_Month_Weekdays($_GET['y'],$_GET['m']); |
// Construct strings for next/previous links |
$PMonth = $Month->prevMonth('object'); // Get previous month as object |
$prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay(); |
$NMonth = $Month->nextMonth('object'); |
$next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay(); |
?> |
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Calendar </title> |
<style text="text/css"> |
table { |
background-color: silver; |
} |
caption { |
font-family: verdana; |
font-size: 12px; |
background-color: while; |
} |
.prevMonth { |
font-size: 10px; |
text-align: left; |
} |
.nextMonth { |
font-size: 10px; |
text-align: right; |
} |
th { |
font-family: verdana; |
font-size: 11px; |
color: navy; |
text-align: right; |
} |
td { |
font-family: verdana; |
font-size: 11px; |
text-align: right; |
} |
.selected { |
background-color: yellow; |
} |
</style> |
</head> |
<body> |
<?php |
$selectedDays = array ( |
new Calendar_Day($_GET['y'],$_GET['m'],$_GET['d']), |
new Calendar_Day($_GET['y'],12,25), |
); |
// Build the days in the month |
$Month->build($selectedDays); |
?> |
<h2>Built with Calendar_Month_Weekday::build()</h2> |
<table class="calendar"> |
<caption> |
<?php echo ( date('F Y',$Month->getTimeStamp())); ?> |
</caption> |
<tr> |
<th>M</th> |
<th>T</th> |
<th>W</th> |
<th>T</th> |
<th>F</th> |
<th>S</th> |
<th>S</th> |
</tr> |
<?php |
while ( $Day = $Month->fetch() ) { |
// Build a link string for each day |
$link = $_SERVER['PHP_SELF']. |
'?y='.$Day->thisYear(). |
'&m='.$Day->thisMonth(). |
'&d='.$Day->thisDay(); |
// isFirst() to find start of week |
if ( $Day->isFirst() ) |
echo ( "<tr>\n" ); |
if ( $Day->isSelected() ) { |
echo ( "<td class=\"selected\">".$Day->thisDay()."</td>\n" ); |
} else if ( $Day->isEmpty() ) { |
echo ( "<td> </td>\n" ); |
} else { |
echo ( "<td><a href=\"".$link."\">".$Day->thisDay()."</a></td>\n" ); |
} |
// isLast() to find end of week |
if ( $Day->isLast() ) |
echo ( "</tr>\n" ); |
} |
?> |
<tr> |
<td> |
<a href="<?php echo ($prev);?>" class="prevMonth"><< </a> |
</td> |
<td colspan="5"> </td> |
<td> |
<a href="<?php echo ($next);?>" class="nextMonth"> >></a> |
</td> |
</tr> |
</table> |
<?php |
echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); |
?> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/15.php |
---|
New file |
0,0 → 1,58 |
<?php |
/** |
* Shows more on how a week can be used |
*/ |
function getmicrotime() { |
list($usec, $sec) = explode(" ", microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Week.php'; |
if (!isset($_GET['y'])) $_GET['y'] = date('Y'); |
if (!isset($_GET['m'])) $_GET['m'] = date('m'); |
if (!isset($_GET['d'])) $_GET['d'] = 1; |
// Build the month |
$Week = new Calendar_Week($_GET['y'], $_GET['m'], $_GET['d']); |
/* |
$Validator = $Week->getValidator(); |
if (!$Validator->isValidWeek()) { |
die ('Please enter a valid week!'); |
} |
*/ |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Paging Weeks </title> |
</head> |
<body> |
<h1>Paging Weeks</h1> |
<h2>Week: <?php echo $Week->thisWeek().' '.date('F Y',$Week->thisMonth(true)); ?></h2> |
<?php |
$Week->build(); |
while ($Day = $Week->fetch()) { |
echo '<p>'.date('jS F',$Day->thisDay(true))."</p>\n"; |
} |
$days = $Week->fetchAll(); |
$prevWeek = $Week->prevWeek('array'); |
$prevWeekLink = $_SERVER['PHP_SELF']. |
'?y='.$prevWeek['year']. |
'&m='.$prevWeek['month']. |
'&d='.$prevWeek['day']; |
$nextWeek = $Week->nextWeek('array'); |
$nextWeekLink = $_SERVER['PHP_SELF']. |
'?y='.$nextWeek['year']. |
'&m='.$nextWeek['month']. |
'&d='.$nextWeek['day']; |
?> |
<p><a href="<?php echo $prevWeekLink; ?>"><<</a> | <a href="<?php echo $nextWeekLink; ?>">>></a></p> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/16.php |
---|
New file |
0,0 → 1,31 |
<?php |
/** |
* Description: demonstrates using the Uri decorator |
*/ |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Month/Weekdays.php'; |
require_once CALENDAR_ROOT.'Decorator/Uri.php'; |
if (!isset($_GET['jahr'])) $_GET['jahr'] = date('Y'); |
if (!isset($_GET['monat'])) $_GET['monat'] = date('m'); |
// Build the month |
$Calendar = new Calendar_Month_Weekdays($_GET['jahr'], $_GET['monat']); |
echo ( '<p>The current month is ' |
.$Calendar->thisMonth().' of year '.$Calendar->thisYear().'</p>'); |
$Uri = & new Calendar_Decorator_Uri($Calendar); |
$Uri->setFragments('jahr','monat'); |
// $Uri->setSeperator('/'); // Default is & |
// $Uri->setScalar(); // Omit variable names |
echo ( "<pre>Previous Uri:\t".$Uri->prev('month')."\n" ); |
echo ( "This Uri:\t".$Uri->this('month')."\n" ); |
echo ( "Next Uri:\t".$Uri->next('month')."\n</pre>" ); |
?> |
<p> |
<a href="<?php echo($_SERVER['PHP_SELF'].'?'.$Uri->prev('month'));?>">Prev</a> : |
<a href="<?php echo($_SERVER['PHP_SELF'].'?'.$Uri->next('month'));?>">Next</a> |
</p> |
/trunk/classes/pear/Calendar/docs/examples/5.phps |
---|
New file |
0,0 → 1,132 |
<?php |
/** |
* Description: generating elements of a form with PEAR::Calendar, using |
* selections as well as validating the submission |
*/ |
function getmicrotime(){ |
list($usec, $sec) = explode(" ",microtime()); |
return ((float)$usec + (float)$sec); |
} |
$start = getmicrotime(); |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Year.php'; |
require_once CALENDAR_ROOT.'Month.php'; |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Hour.php'; |
require_once CALENDAR_ROOT.'Minute.php'; |
require_once CALENDAR_ROOT.'Second.php'; |
// Initialize if not set |
if (!isset($_POST['y'])) $_POST['y'] = date('Y'); |
if (!isset($_POST['m'])) $_POST['m'] = date('n'); |
if (!isset($_POST['d'])) $_POST['d'] = date('j'); |
if (!isset($_POST['h'])) $_POST['h'] = date('H'); |
if (!isset($_POST['i'])) $_POST['i'] = date('i'); |
if (!isset($_POST['s'])) $_POST['s'] = date('s'); |
?> |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
<html> |
<head> |
<title> Select and Update </title> |
</head> |
<body> |
<h1>Select and Update</h1> |
<?php |
if ( isset($_POST['update']) ) { |
$Second = & new Calendar_Second($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i'],$_POST['s']); |
if ( !$Second->isValid() ) { |
$V= & $Second->getValidator(); |
echo ('<p>Validation failed:</p>' ); |
while ( $error = $V->fetch() ) { |
echo ( $error->toString() .'<br>' ); |
} |
} else { |
echo ('<p>Validation success.</p>' ); |
echo ( '<p>New timestamp is: '.$Second->getTimeStamp().' which could be used to update a database, for example'); |
} |
} else { |
$Year = new Calendar_Year($_POST['y']); |
$Month = new Calendar_Month($_POST['y'],$_POST['m']); |
$Day = new Calendar_Day($_POST['y'],$_POST['m'],$_POST['d']); |
$Hour = new Calendar_Hour($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h']); |
$Minute = new Calendar_Minute($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i']); |
$Second = new Calendar_Second($_POST['y'],$_POST['m'],$_POST['d'],$_POST['h'],$_POST['i'],$_POST['s']); |
?> |
<p><b>Set the alarm clock</p></p> |
<form action="<?php echo ( $_SERVER['PHP_SELF'] ); ?>" method="post"> |
Year: <input type="text" name="y" value="<?php echo ( $_POST['y'] ); ?>" size="4"> |
Month:<select name="m"> |
<?php |
$selection = array($Month); |
$Year->build($selection); |
while ( $Child = & $Year->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisMonth()."\" selected>".$Child->thisMonth()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisMonth()."\">".$Child->thisMonth()."\n" ); |
} |
} |
?> |
</select> |
Day:<select name="d"> |
<?php |
$selection = array($Day); |
$Month->build($selection); |
while ( $Child = & $Month->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisDay()."\" selected>".$Child->thisDay()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisDay()."\">".$Child->thisDay()."\n" ); |
} |
} |
?> |
</select> |
Hour:<select name="h"> |
<?php |
$selection = array($Hour); |
$Day->build($selection); |
while ( $Child = & $Day->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisHour()."\" selected>".$Child->thisHour()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisHour()."\">".$Child->thisHour()."\n" ); |
} |
} |
?> |
</select> |
Minute:<select name="i"> |
<?php |
$selection = array($Minute); |
$Hour->build($selection); |
while ( $Child = & $Hour->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisMinute()."\" selected>".$Child->thisMinute()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisMinute()."\">".$Child->thisMinute()."\n" ); |
} |
} |
?> |
</select> |
Second:<select name="s"> |
<?php |
$selection = array($Second); |
$Minute->build($selection); |
while ( $Child = & $Minute->fetch() ) { |
if ( $Child->isSelected() ) { |
echo ( "<option value=\"".$Child->thisSecond()."\" selected>".$Child->thisSecond()."\n" ); |
} else { |
echo ( "<option value=\"".$Child->thisSecond()."\">".$Child->thisSecond()."\n" ); |
} |
} |
?> |
</select> |
<input type="submit" name="update" value="Set Alarm"><br> |
<?php |
} |
?> |
<?php echo ( '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>' ); ?> |
</body> |
</html> |
/trunk/classes/pear/Calendar/docs/examples/17.php |
---|
New file |
0,0 → 1,71 |
<?php |
/** |
* Description: demonstrates using the Textual decorator |
*/ |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php'; |
require_once CALENDAR_ROOT.'Decorator'.DIRECTORY_SEPARATOR.'Textual.php'; |
// Could change language like this |
// setlocale (LC_TIME, "de_DE"); // Unix based (probably) |
// setlocale (LC_TIME, "ge"); // Windows |
echo "<hr>Calling: Calendar_Decorator_Textual::monthNames('long');<pre>"; |
print_r(Calendar_Decorator_Textual::monthNames('long')); |
echo '</pre>'; |
echo "<hr>Calling: Calendar_Decorator_Textual::weekdayNames('two');<pre>"; |
print_r(Calendar_Decorator_Textual::weekdayNames('two')); |
echo '</pre>'; |
echo "<hr>Creating: new Calendar_Day(date('Y'), date('n'), date('d'));<br />"; |
$Calendar = new Calendar_Day(date('Y'), date('n'), date('d')); |
// Decorate |
$Textual = & new Calendar_Decorator_Textual($Calendar); |
echo '<hr>Previous month is: '.$Textual->prevMonthName('two').'<br />'; |
echo 'This month is: '.$Textual->thisMonthName('short').'<br />'; |
echo 'Next month is: '.$Textual->nextMonthName().'<br /><hr />'; |
echo 'Previous day is: '.$Textual->prevDayName().'<br />'; |
echo 'This day is: '.$Textual->thisDayName('short').'<br />'; |
echo 'Next day is: '.$Textual->nextDayName('one').'<br /><hr />'; |
echo "Creating: new Calendar_Month_Weekdays(date('Y'), date('n'), 6); - Saturday is first day of week<br />"; |
$Calendar = new Calendar_Month_Weekdays(date('Y'), date('n'), 6); |
// Decorate |
$Textual = & new Calendar_Decorator_Textual($Calendar); |
?> |
<p>Rendering calendar....</p> |
<table> |
<caption><?php echo $Textual->thisMonthName().' '.$Textual->thisYear(); ?></caption> |
<tr> |
<?php |
$dayheaders = $Textual->orderedWeekdays('short'); |
foreach ($dayheaders as $dayheader) { |
echo '<th>'.$dayheader.'</th>'; |
} |
?> |
</tr> |
<?php |
$Calendar->build(); |
while ($Day = $Calendar->fetch()) { |
if ($Day->isFirst()) { |
echo "<tr>\n"; |
} |
if ($Day->isEmpty()) { |
echo '<td> </td>'; |
} else { |
echo '<td>'.$Day->thisDay().'</td>'; |
} |
if ($Day->isLast()) { |
echo "</tr>\n"; |
} |
} |
?> |
</table> |
/trunk/classes/pear/Calendar/docs/examples/18.php |
---|
New file |
0,0 → 1,36 |
<?php |
/** |
* Description: demonstrates using the Wrapper decorator |
*/ |
if (!@include 'Calendar/Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Month.php'; |
require_once CALENDAR_ROOT.'Decorator.php'; // Not really needed but added to help this make sense |
require_once CALENDAR_ROOT.'Decorator/Wrapper.php'; |
class MyBoldDecorator extends Calendar_Decorator |
{ |
function MyBoldDecorator(&$Calendar) |
{ |
parent::Calendar_Decorator($Calendar); |
} |
function thisDay() |
{ |
return '<b>'.parent::thisDay().'</b>'; |
} |
} |
$Month = new Calendar_Month(date('Y'), date('n')); |
$Wrapper = & new Calendar_Decorator_Wrapper($Month); |
$Wrapper->build(); |
echo '<h2>The Wrapper decorator</h2>'; |
echo '<i>Day numbers are rendered in bold</i><br /> <br />'; |
while ($DecoratedDay = $Wrapper->fetch('MyBoldDecorator')) { |
echo $DecoratedDay->thisDay().'<br />'; |
} |
?> |
/trunk/classes/pear/Calendar/docs/examples/7.phps |
---|
New file |
0,0 → 1,92 |
<?php |
/** |
* Description: a SOAP Calendar Server |
*/ |
if (!@include('SOAP'.DIRECTORY_SEPARATOR.'Server.php')) { |
die('You must have PEAR::SOAP installed'); |
} |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
class Calendar_Server |
{ |
var $__dispatch_map = array(); |
var $__typedef = array(); |
function Calendar_Server() |
{ |
$this->__dispatch_map['getMonth'] = |
array('in' => array('year' => 'int', 'month'=>'int'), |
'out' => array('month' => '{urn:PEAR_SOAP_Calendar}Month'), |
); |
$this->__typedef['Month'] = array ( |
'monthname' => 'string', |
'days' => '{urn:PEAR_SOAP_Calendar}MonthDays' |
); |
$this->__typedef['MonthDays'] = array (array ('{urn:PEAR_SOAP_Calendar}Day')); |
$this->__typedef['Day'] = array ( |
'isFirst' => 'int', |
'isLast' => 'int', |
'isEmpty' => 'int', |
'day' => 'int' ); |
} |
function __dispatch($methodname) |
{ |
if (isset($this->__dispatch_map[$methodname])) |
return $this->__dispatch_map[$methodname]; |
return NULL; |
} |
function getMonth($year, $month) |
{ |
require_once(CALENDAR_ROOT.'Month'.DIRECTORY_SEPARATOR.'Weekdays.php'); |
$Month = & new Calendar_Month_Weekdays($year,$month); |
if (!$Month->isValid()) { |
$V = & $Month->getValidator(); |
$errorMsg = ''; |
while ($error = $V->fetch()) { |
$errorMsg .= $error->toString()."\n"; |
} |
return new SOAP_Fault($errorMsg, 'Client'); |
} else { |
$monthname = date('F Y', $Month->getTimeStamp()); |
$days = array(); |
$Month->build(); |
while ($Day = & $Month->fetch()) { |
$day = array( |
'isFirst' => (int)$Day->isFirst(), |
'isLast' => (int)$Day->isLast(), |
'isEmpty' => (int)$Day->isEmpty(), |
'day' => (int)$Day->thisDay(), |
); |
$days[] = $day; |
} |
return array('monthname' => $monthname, 'days' => $days); |
} |
} |
} |
$server = new SOAP_Server(); |
$server->_auto_translation = true; |
$calendar = new Calendar_Server(); |
$server->addObjectMap($calendar, 'urn:PEAR_SOAP_Calendar'); |
if (strtoupper($_SERVER['REQUEST_METHOD'])=='POST') { |
$server->service($GLOBALS['HTTP_RAW_POST_DATA']); |
} else { |
require_once 'SOAP'.DIRECTORY_SEPARATOR.'Disco.php'; |
$disco = new SOAP_DISCO_Server($server, "PEAR_SOAP_Calendar"); |
if (isset($_SERVER['QUERY_STRING']) && |
strcasecmp($_SERVER['QUERY_STRING'], 'wsdl')==0) { |
header("Content-type: text/xml"); |
echo $disco->getWSDL(); |
} else { |
echo 'This is a PEAR::SOAP Calendar Server. For client try <a href="8.php">here</a><br />'; |
echo 'For WSDL try <a href="?wsdl">here</a>'; |
} |
exit; |
} |
?> |
/trunk/classes/pear/Calendar/docs/examples/19.php |
---|
New file |
0,0 → 1,24 |
<?php |
/** |
* Description: demonstrates using the Weekday decorator |
*/ |
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') { |
define('CALENDAR_ROOT', '../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
require_once CALENDAR_ROOT.'Decorator/Weekday.php'; |
$Day = new Calendar_Day(date('Y'), date('n'),date('d')); |
$WeekDay = & new Calendar_Decorator_Weekday($Day); |
// $WeekDay->setFirstDay(0); // Make Sunday first Day |
echo 'Yesterday: '.$WeekDay->prevWeekDay().'<br>'; |
echo 'Today: '.$WeekDay->thisWeekDay().'<br>'; |
echo 'Tomorrow: '.$WeekDay->nextWeekDay().'<br>'; |
$WeekDay->build(); |
echo 'Hours today:<br>'; |
while ( $Hour = $WeekDay->fetch() ) { |
echo $Hour->thisHour().'<br>'; |
} |
?> |
/trunk/classes/pear/Calendar/docs/examples/9.phps |
---|
New file |
0,0 → 1,16 |
<?php |
/** |
* Description: simple example on i18N |
*/ |
if ( !@include 'Calendar/Calendar.php' ) { |
define('CALENDAR_ROOT','../../'); |
} |
require_once CALENDAR_ROOT.'Day.php'; |
$Day = & new Calendar_Day(2003,10,23); |
setlocale (LC_TIME, "de_DE"); // Unix based (probably) |
// setlocale (LC_TIME, "ge"); // Windows |
echo ( strftime('%A %d %B %Y',$Day->getTimeStamp())); |
?> |