summaryrefslogtreecommitdiff
path: root/forum/utils/calendar.php
blob: 0e7dba548fd5d1cc0f9f826f4cfba00d0be787c1 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
function calendar()
{
	global $UTIL_DIR, $ZEND_DIR, $DOKUWIKI_CALENDAR, $GLOBALS,
		$current_user, $DATA_DIR;

	include_once($UTIL_DIR . "/events.php");
	include_once($UTIL_DIR . "/notify.php");
	if($ZEND_DIR != "") include_once($UTIL_DIR . "/googlecalendar.php");

	$str = "";

	$events = new Events($DATA_DIR . "/calendar.xml");

	foreach($events->events as $e) {
		if($e->concert == "true") $str .= $e->show_simple();
	}

	if(!isset($GLOBALS['date']))
		$date = time() - (date("N", time()) - 1) * 24 * 60 * 60;
	else
		$date = $GLOBALS['date'] - (date("N", $GLOBALS['date'])-1) * 24 * 60 * 60; 

	if($GLOBALS['action'] =="addentry") {
		$title = stripslashes($GLOBALS['title']);
		$description = stripslashes($GLOBALS['description']);
		if($GLOBALS['concert'] == "on") $concert = "true";
		else $concert = "false";

		$time = strtotime($GLOBALS['txtdate'] . " " .
											$GLOBALS['txttimefrom'] . ":00");
		if($time !== FALSE) {
			$duration = strtotime($GLOBALS['txtdate'] . " " .
														$GLOBALS['txttimeto'] . ":00") - $time;
			$eid = time();
			$event = new Event($eid, $title, $concert, $time, $duration, $description,
												 $current_user->uid);
			$events->add($event);
			$events->write();
			
			if($ZEND_DIR != "") googleCalendarEvent($event);
			
			if($DOKUWIKI_CALENDAR != "") {
				$file = $DOKUWIKI_CALENDAR;
				$fp = fopen($file, "w");
				
				fprintf($fp, "=====DIEs calendar=====\n");
				fprintf($fp, "Do not edit this file - it is automatically generated " .
								"by the ExecutionRoom CMS.\n\n");
				fprintf($fp, "====Events====\n");
				foreach($events->events as $event) {
					fprintf($fp, "  * %s - %s %s: %s\n",
									date("j.n.Y G:i", $event->starttime),
									date("j.n.Y G:i", $event->starttime + $event->duration),
									$event->title, $event->description);
				}
				fclose($fp);
			}
			
			notify("calendar", "New calendar entry:\n" . $GLOBALS['title'] . "\n" .
						 date("r", $time) . "\n" . $GLOBALS['description'] . "\n" .
						 $FORUM_URL . "/?mode=calendar&date=" . $time);
			
			$str .= "		<meta http-equiv=\"refresh\" content=\"0; " .
				"URL=?mode=calendar&amp;date=" . $time . "\"/>\n";
			
		} else {
			$str .= "<div class=\"error\">ERROR: Date is not in the correct " .
				"format! It was NOT posted. Please try again.</div>\n";
		}
	}

	if($GLOBALS['action'] =="delete") {
			$events->delete($GLOBALS['eid']);
			$events->write();
	}

	$str .= "<p style=\"text-align: center;\">\n";
	$str .= "<a href=\"?mode=calendar&amp;date=" .
		sprintf("%d", $date - 7 * 24 * 60 * 60) . "\">[&lt;]</a>\n";
	$str .= "&nbsp;&nbsp;\n";
	$str .= "<a href=\"?mode=calendar&amp;date=" .
		sprintf("%d", $date - 31 * 24 * 60 * 60) . "\">[&lt;&lt;]</a>\n"; 
	$str .= "&nbsp;&nbsp;\n";
	$str .= date("F Y", $date) . "\n";
	$str .= "&nbsp;&nbsp;\n";
	$str .= "<a href=\"?mode=calendar&amp;date=" .
		sprintf("%d", $date + 31 * 24 * 60 * 60) . "\">[&gt;&gt;]</a> \n";
	$str .= "&nbsp;&nbsp;\n";
	$str .= "<a href=\"?mode=calendar&amp;date=" .
		sprintf("%d", $date + 7 * 24 * 60 * 60) . "\">[&gt;]</a><br/>\n";
	$str .= "<a href=\"?mode=calendar\">[Today]</a><br/>\n";
	$str .= "</p>\n";

	if($client_is_mobile_device) {
		for($day = 0; $day < 7; $day++) {
			$str .= "  <div class=\"mobilecalentry\">\n";
			$str .= "    <div class=\"mobilecalheader\">\n";
			$t = $date + $day * 24 * 60 * 60;
			$str .= "      " . date("l j/n", $t) . "\n";
			$str .= "<a style=\"text-decoration: none;\" " .
				"href=\"?mode=calendar&amp;date=". 
				sprintf("%d", $date) . "&amp;adddate=". $t .
				"&amp;action=add\">[+]</a>\n";
			$str .= "    </div>\n";

			$t = strtotime(date("F j Y", $date + $day * 24 * 60 * 60));
			$str .=  "    <div class=\"mobilecalcontent\"";
			if($t ==  strtotime(date("F j Y", time())))
				$str .= " style=\"background: #113;\"";
			elseif($day > 4) $str .=  " style=\"background: #311;\"";
			$str .=  ">\n";

			$str .= $events->show($t, $t + 24 * 60 * 60);

			$str .=  "    </div>\n";
			$str .=  "  </div>\n";

		}
	} else {

		$str .= "<table class=\"week\">\n";
		$str .= "  <tr class=\"day\">\n";

		for($day = 0; $day < 7; $day++) {
			$str .=  "    <td class=\"header\">\n";
			$t = $date + $day * 24 * 60 * 60;
			$str .=  "      " . date("l j/n", $t) . "\n";
			$str .=  "    </td>\n";
		}

		$str .= " </tr>\n";
		$str .= "  <tr class=\"day\">\n";

		for($day = 0; $day < 7; $day++) {
			$t = strtotime(date("F j Y", $date + $day * 24 * 60 * 60));

			$str .=  "    <td class=\"content\"";
			if($t ==  strtotime(date("F j Y", time())))
				$str .=  " style=\"background: #113;\"";
			elseif($day > 4) $str .=  " style=\"background: #311;\"";
			$str .=  ">\n";

			$str .=  "     <a class=\"button\" href=\"?mode=calendar&amp;date=" .
				sprintf("%d", $date) . "&amp;adddate=". $t .
				"&amp;action=add\">Add</a>\n";

			$str .= $events->show($t, $t + 24 * 60 * 60);
			$str .=  "    </td>\n";
		}

		$str .= " </tr>\n";
		$str .= "</table>\n";
	}

	if($GLOBALS['adddate'] != "") {
		$str .= "<form method=\"post\" action=\"?mode=calendar&amp;action=" .
			"addentry\">\n";
		$str .= "Title: <input name=\"title\" value=\"\"><br/>\n";
		$str .= "Concert: <input type=\"checkbox\" name=\"concert\"/><br/>\n";
		$str .= "Desription: <textarea name=\"description\"></textarea><br/>\n";
		$str .= "Date: <input name=\"txtdate\" value=\"".
			date("F j Y", $GLOBALS['adddate']) . "\"><br/>\n";
		$str .= "From-Time: <input name=\"txttimefrom\" value=\"19:00\"><br/>\n";
		$str .= "To-Time: <input name=\"txttimeto\" value=\"22:00\"><br/>\n";
		$str .= "<br/>\n";
		$str .= "<button type=\"submit\">Add</button>\n";
		$str .= "</form>\n";
	}

	return $str;
}
?>