-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_calendar.php
89 lines (76 loc) · 2.76 KB
/
get_calendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
error_reporting(0); ini_set("display_errors", 0);
if(isset($_POST['month']) && $_POST['month'] > 0 && isset($_POST['year']) && $_POST['year'] > 0)
{
$curr_month = $_POST['month'];
$curr_year = $_POST['year'];
$prev_month = $curr_month-1 < 1?12:$curr_month-1;
$next_month = $curr_month+1 > 12?1:$curr_month+1;
$prev_year = $curr_year-1 > 1901?$curr_year-1:1902;
$next_year = $curr_year+1 < 2038?$curr_year+1:date("Y");
$lastday = date('t',strtotime($curr_month.'/1/'.$curr_year));
$notes_exist = array();
$id = strtotime(date($curr_year."-".$curr_month."-1"));
$week_start_day = date( "w", $id);
$wdays = 7;
$wdays-=$week_start_day;
$source = 'events.xml';
$sitemap = new SimpleXMLElement($source,null,true);
for($i=1; $i <= $lastday; $i++)
{
$id = strtotime(date($curr_year."-".$curr_month."-".$i));
$data = $sitemap->xpath('/root/notes[timestamp='.$id.']');
if(count($data)) {
$notes_exist[] = $i;
}
}
$cal = '<table class="cal_nav" border="0"><tr>
<td><a href="javascript:void(0);" title="previous year" onClick="get_calendar('.$curr_month.', '.$prev_year.')"> << Year </a>
<a href="javascript:void(0);" title="previous month" onClick="get_calendar('.$prev_month.', '.$curr_year.')"> << Month </a>
<a href="javascript:void(0);" title="next month" onClick="get_calendar('.$next_month.', '.$curr_year.')"> Month >> </a>
<a href="javascript:void(0);" title="next year" onClick="get_calendar('.$curr_month.', '.$next_year.')"> Year >> </a>
</td></tr></table>';
$cal .= '<table class="week_days" width="300" border="0"><tr><td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td></tr></table>';
$cal .= '<table class="calendar" width="300" border="0"><tr>';
for($j=0; $j < $week_start_day; $j++)
{
$cal .= '<td> </td>';
}
$c=0;
for($i=1; $i <= $wdays; $i++)
{
if(!in_array($i, $notes_exist)) {
if($week_start_day==$c && $i == 1) {
$bg_color = ' style="background-color:#FF9898;"';
}else{
$bg_color = ' style="background-color:#f5f5f5;"';
}
}
else {
$bg_color = ' style="background-color:#8AC007;"';
}
$cal .= '<td><span id="day_'.$i.'"'.$bg_color.' onClick="get_notes('.$i.','.$curr_month.','.$curr_year.');">'.$i.'</span></td>';
++$c;
if($i % $wdays == 0) $cal .= '</tr><tr>';
}
$cc=0;
for($i=$wdays+1; $i <= $lastday; $i++)
{
++$cc;
if(!in_array($i, $notes_exist)) {
if(($cc-1)%7 ==0) {
$bg_color = ' style="background-color:#FF9898;"';
}else{
$bg_color = ' style="background-color:#f5f5f5;"';
}
}
else {
$bg_color = ' style="background-color:#8AC007;"';
}
$cal .= '<td><span id="day_'.$i.'"'.$bg_color.' onClick="get_notes('.$i.','.$curr_month.','.$curr_year.');">'.$i.'</span></td>';
if($cc % 7 == 0) $cal .= '</tr><tr>';
}
$cal .= '</tr></table>';
echo $cal;
}
?>