topical media & game development
basic-web-php-PHP-Example03.php / php
<?php
// Set up the variables (today, month, year, cmd)
// today = m/d/y
// cmd = 1 (add month) or -1 (sub month)
function setvars() {
// Default is today
month = year = today = today['mday']."/"._POST) && count(_POST['month'])) {
_POST['month']; }
if (isset(year = _POST['next'])) {
_POST['prev'])) {
_GET) && count(_GET['month'])) {
_GET['month']; }
if (isset(year = _GET['next'])) {
_GET['prev'])) {
cmd)) {
cmd;
// Adjust month over or underrun
if (month = 1;
month <= 0) {
year -= 1;
}
}
// Return vars in an array
return array("today" => month,
"year" => cmd);
} // End setvars()
// Do the document header
function docheader(year) {
// Set script to return to (form action)
_SERVER['PHP_SELF'];
month."/1/".Month this_script" method="post">
<table border="1">
<!-- Controls and calendar title (month) -->
<tr>
<td colspan="1" align="left">
<input type="submit" name="prev" value="<<" />
</td>
<td colspan="5" align="center">
<strong>
year
</strong>
<input type="hidden" name="month" value="year" />
</td>
<td colspan="1" align="right">
<input type="submit" name="next" value=">>" />
</td>
</tr>
<!-- Day of week header row -->
<tr class="weekdays">
<th>Sunday</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
</tr>
<!-- Calendar (days) start here -->
HTML;
} // End docheader()
// Do the document footer (close tags, end doc)
function docfooter() {
print <<<HTML
<!-- Close all open tags, end document -->
</table>
</form>
</body>
</html>
HTML;
} // End docfooter()
// Print an empty day (cell)
function emptyday() {
print <<<HTML
<td align="right" valign="top"> </td>
HTML;
} // End emptyday()
// Print a day cell
function day(month,year) {
month."/".year;
if (today) {
font = "";
}
print <<< HTML
<td align="right" valign="top" day</td>
HTML;
} // End day()
// Open or close a row
function weekrow(cmd) {
case "open":
print "<tr class=\"week\">\n";
break;
case "close":
print "</tr>\n";
break;
}
} // End weekrow()
// Main program body
function main() {
// Set the date vars by default, POST, or GET
today = month = year = cmd = month,first_weekday = date("w",strtotime(year)) + 1;
weekday = 1; first_weekday; month,year)) {
// If SUN, open the row
if (today,day,weekday++;
weekday > 7) {
weekrow("close");
weekday != 1 && weekday++;
}
// Close document
docfooter();
} // End main();
// Kick it all off
main();
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.