Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
493 ddelon 1
<?php
2
/**
3
* Description: Demonstrates building a calendar for a month using the Week class
4
* Uses UnixTs engine
5
*/
6
function getmicrotime(){
7
    list($usec, $sec) = explode(" ",microtime());
8
    return ((float)$usec + (float)$sec);
9
}
10
$start = getmicrotime();
11
 
12
// Force UnixTs engine (default setting)
13
define('CALENDAR_ENGINE','UnixTs');
14
 
15
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') {
16
    define('CALENDAR_ROOT', '../../');
17
}
18
require_once CALENDAR_ROOT.'Month/Weeks.php';
19
require_once CALENDAR_ROOT.'Day.php';
20
 
21
// Initialize GET variables if not set
22
if (!isset($_GET['y'])) $_GET['y'] = date('Y');
23
if (!isset($_GET['m'])) $_GET['m'] = date('m');
24
if (!isset($_GET['d'])) $_GET['d'] = date('d');
25
 
26
// Build a month object
27
$Month = new Calendar_Month_Weeks($_GET['y'], $_GET['m']);
28
 
29
// Create an array of days which are "selected"
30
// Used for Week::build() below
31
$selectedDays = array (
32
    new Calendar_Day($_GET['y'],$_GET['m'], $_GET['d']),
33
    new Calendar_Day($_GET['y'], 12, 25),
34
    new Calendar_Day(date('Y'), date('m'), date('d')),
35
    );
36
 
37
// Instruct month to build Week objects
38
$Month->build();
39
 
40
// Construct strings for next/previous links
41
$PMonth = $Month->prevMonth('object'); // Get previous month as object
42
$prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay();
43
$NMonth = $Month->nextMonth('object');
44
$next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay();
45
?>
46
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
47
<html>
48
<head>
49
<title> Calendar </title>
50
<style text="text/css">
51
table {
52
    background-color: silver;
53
}
54
caption {
55
    font-family: verdana;
56
    font-size: 12px;
57
    background-color: while;
58
}
59
.prevMonth {
60
    font-size: 10px;
61
    text-align: left;
62
}
63
.nextMonth {
64
    font-size: 10px;
65
    text-align: right;
66
}
67
th {
68
    font-family: verdana;
69
    font-size: 11px;
70
    color: navy;
71
    text-align: right;
72
}
73
td {
74
    font-family: verdana;
75
    font-size: 11px;
76
    text-align: right;
77
}
78
.selected {
79
    background-color: yellow;
80
}
81
.empty {
82
    color: white;
83
}
84
</style>
85
</head>
86
 
87
<body>
88
<h2>Build with Calendar_Month_Weeks::build() then Calendar_Week::build()</h2>
89
<table class="calendar">
90
<caption>
91
<?php echo date('F Y', $Month->getTimeStamp()); ?>
92
</caption>
93
<tr>
94
<th>M</th>
95
<th>T</th>
96
<th>W</th>
97
<th>T</th>
98
<th>F</th>
99
<th>S</th>
100
<th>S</th>
101
</tr>
102
<?php
103
while ($Week = $Month->fetch()) {
104
    echo "<tr>\n";
105
    // Build the days in the week, passing the selected days
106
    $Week->build($selectedDays);
107
    while ($Day = $Week->fetch()) {
108
 
109
        // Build a link string for each day
110
        $link = $_SERVER['PHP_SELF'].
111
                    '?y='.$Day->thisYear().
112
                    '&m='.$Day->thisMonth().
113
                    '&d='.$Day->thisDay();
114
 
115
        // Check to see if day is selected
116
        if ($Day->isSelected()) {
117
            echo '<td class="selected">'.$Day->thisDay().'</td>'."\n";
118
        // Check to see if day is empty
119
        } else if ($Day->isEmpty()) {
120
            echo '<td class="empty">'.$Day->thisDay().'</td>'."\n";
121
        } else {
122
            echo '<td><a href="'.$link.'">'.$Day->thisDay().'</a></td>'."\n";
123
        }
124
    }
125
    echo '</tr>'."\n";
126
}
127
?>
128
<tr>
129
<td>
130
<a href="<?php echo $prev; ?>" class="prevMonth"><< </a>
131
</td>
132
<td colspan="5">&nbsp;</td>
133
<td>
134
<a href="<?php echo $next; ?>" class="nextMonth"> >></a>
135
</td>
136
</tr>
137
</table>
138
<?php
139
echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>';
140
?>
141
</body>
142
</html>