class/pear/Calendar/docs/examples/6.php
<?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 (!@require_once \dirname(__DIR__, 2) . '/Calendar.php') {
if (!@require __DIR__ . '/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 = [$Day];
#-----------------------------------------------------------------------------#
if (isset($_GET['mime']) && 'wml' === $_GET['mime']) {
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>
<span style="font-size: large;"><strong>Personal Planner Rendered with WML</strong></span>
<?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 (false !== ($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 (false !== ($Day = $Month->fetch())) {
if ($Day->isFirst()) {
echo "<tr>\n";
}
if ($Day->isEmpty()) {
echo "<td></td>\n";
} elseif ($Day->isSelected()) {
echo '<td><anchor><strong><u>' . $Day->thisDay() . "</u></strong>\n<go href=\"" . $_SERVER['SCRIPT_NAME'] . '?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['SCRIPT_NAME']; ?>">Back to HTML</a></p>
<?php echo '<p>Took: ' . (getmicrotime() - $start) . ' seconds</p>'; ?>
</wml>
<?php
#-----------------------------------------------------------------------------#
} else {
?>
<!DOCTYPE html>
<html lang="en" xml:lang="en">
<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['SCRIPT_NAME']; ?>?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 (false !== ($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 (false !== ($Day = $Month->fetch())) {
if ($Day->isFirst()) {
echo "<tr>\n";
}
if ($Day->isEmpty()) {
echo "<td></td>\n";
} elseif ($Day->isSelected()) {
echo '<td><a href="' . $_SERVER['SCRIPT_NAME'] . '?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['SCRIPT_NAME'] . '?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
}