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: same as 3.php, but using the PEAR::Date engine
4
* Note: make sure PEAR::Date is a stable release!!!
5
*/
6
function getmicrotime(){
7
    list($usec, $sec) = explode(" ",microtime());
8
    return ((float)$usec + (float)$sec);
9
}
10
$start = getmicrotime();
11
 
12
// Switch to PEAR::Date engine
13
define('CALENDAR_ENGINE', 'PearDate');
14
 
15
if (!@include 'Calendar'.DIRECTORY_SEPARATOR.'Calendar.php') {
16
    define('CALENDAR_ROOT','../../');
17
}
18
require_once CALENDAR_ROOT.'Month/Weekdays.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 the month
27
$month = new Calendar_Month_Weekdays($_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
    );
35
 
36
// Build the days in the month
37
$month->build($selectedDays);
38
 
39
// Construct strings for next/previous links
40
$PMonth = $month->prevMonth('object'); // Get previous month as object
41
$prev = $_SERVER['PHP_SELF'].'?y='.$PMonth->thisYear().'&m='.$PMonth->thisMonth().'&d='.$PMonth->thisDay();
42
$NMonth = $month->nextMonth('object');
43
$next = $_SERVER['PHP_SELF'].'?y='.$NMonth->thisYear().'&m='.$NMonth->thisMonth().'&d='.$NMonth->thisDay();
44
 
45
$thisDate = new Date($month->thisMonth('timestamp'));
46
?>
47
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
48
<html>
49
<head>
50
<title> Calendar using PEAR::Date Engine </title>
51
<style text="text/css">
52
table {
53
    background-color: silver;
54
}
55
caption {
56
    font-family: verdana;
57
    font-size: 12px;
58
    background-color: while;
59
}
60
.prevMonth {
61
    font-size: 10px;
62
    text-align: left;
63
}
64
.nextMonth {
65
    font-size: 10px;
66
    text-align: right;
67
}
68
th {
69
    font-family: verdana;
70
    font-size: 11px;
71
    color: navy;
72
    text-align: right;
73
}
74
td {
75
    font-family: verdana;
76
    font-size: 11px;
77
    text-align: right;
78
}
79
.selected {
80
    background-color: yellow;
81
}
82
</style>
83
</head>
84
 
85
<body>
86
 
87
<h2>Calendar using PEAR::Date Engine</h2>
88
<table class="calendar">
89
<caption>
90
<?php echo $thisDate->format('%B %Y'); ?>
91
</caption>
92
<tr>
93
<th>M</th>
94
<th>T</th>
95
<th>W</th>
96
<th>T</th>
97
<th>F</th>
98
<th>S</th>
99
<th>S</th>
100
</tr>
101
<?php
102
while ($day = $month->fetch()) {
103
    // Build a link string for each day
104
    $link = $_SERVER['PHP_SELF'].
105
                '?y='.$day->thisYear().
106
                '&m='.$day->thisMonth().
107
                '&d='.$day->thisDay();
108
 
109
    // isFirst() to find start of week
110
    if ($day->isFirst())
111
        echo "<tr>\n";
112
 
113
    if ($day->isSelected()) {
114
       echo '<td class="selected">'.$day->thisDay().'</td>'."\n";
115
    } else if ($day->isEmpty()) {
116
        echo '<td>&nbsp;</td>'."\n";
117
    } else {
118
        echo '<td><a href="'.$link.'">'.$day->thisDay().'</a></td>'."\n";
119
    }
120
 
121
    // isLast() to find end of week
122
    if ($day->isLast()) {
123
        echo "</tr>\n";
124
    }
125
}
126
?>
127
<tr>
128
<td>
129
<a href="<?php echo $prev; ?>" class="prevMonth"><< </a>
130
</td>
131
<td colspan="5">&nbsp;</td>
132
<td>
133
<a href="<?php echo $next; ?>" class="nextMonth"> >></a>
134
</td>
135
</tr>
136
</table>
137
<?php
138
echo '<p><b>Took: '.(getmicrotime()-$start).' seconds</b></p>';
139
?>
140
</body>
141
</html>