40
|
1 |
<?php
|
|
2 |
|
|
3 |
/**
|
|
4 |
* @author Bettina Schwarzer, Fritz-Haber-Institut
|
|
5 |
* @copyright 8/2013
|
|
6 |
*/
|
|
7 |
|
|
8 |
error_reporting(E_ALL ^ E_NOTICE);
|
|
9 |
|
|
10 |
$sub = $_POST["sub"];
|
|
11 |
$month = $_POST["mon"];
|
|
12 |
$year = $_POST["yr"];
|
|
13 |
?>
|
|
14 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
15 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
16 |
|
|
17 |
<head>
|
|
18 |
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
|
|
19 |
<link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS" media="screen"/>
|
|
20 |
<link href="/fhiiqm/css/db_print.css" rel="STYLESHEET" type="TEXT/CSS" media="print"/>
|
|
21 |
<title>Kalender Test</title>
|
|
22 |
</head>
|
|
23 |
|
|
24 |
<body>
|
|
25 |
|
|
26 |
<?php
|
|
27 |
$amon = array("1"=>"Januar","2"=>"Februar","3"=>"März","4"=>"April","5"=>"Mai","6"=>"Juni","7"=>"Juli","8"=>"August","9"=>"September","10"=>"Oktober","11"=>"November","12"=>"Dezember");
|
|
28 |
$aday = array("0"=>"Mo","1"=>"Di","2"=>"Mi","3"=>"Do","4"=>"Fr","5"=>"Sa","6"=>"So");
|
|
29 |
|
|
30 |
//This gets today's date
|
|
31 |
if ($sub == ">")
|
|
32 |
{
|
|
33 |
$month += 1;
|
|
34 |
if ($month > 12)
|
|
35 |
{
|
|
36 |
$month=1;
|
|
37 |
$year += 1;
|
|
38 |
}
|
|
39 |
}
|
|
40 |
if ($sub == "<")
|
|
41 |
{
|
|
42 |
$month -= 1;
|
|
43 |
if ($month < 1)
|
|
44 |
{
|
|
45 |
$month=12;
|
|
46 |
$year -= 1;
|
|
47 |
}
|
|
48 |
}
|
|
49 |
if ($sub && $month && $year)
|
|
50 |
$date = mktime(0,0,0,$month,1,$year);
|
|
51 |
else
|
|
52 |
$date = time () ;
|
|
53 |
//This puts the day, month, and year in seperate variables
|
|
54 |
$day = date('d', $date) ;
|
|
55 |
$month = date('m', $date) ;
|
|
56 |
$year = date('Y', $date) ;
|
|
57 |
//echo "mon = $month, jahr = $year, dat = $day.".".$month.".".$year<br />";
|
|
58 |
|
|
59 |
//Here we generate the first day of the month
|
|
60 |
$first_day = mktime(0,0,0,$month, 1, $year) ;
|
|
61 |
$first_day_prev = mktime(0,0,0,$month-1, 1, $year) ;
|
|
62 |
$first_day_next= mktime(0,0,0,$month+1, 1, $year) ;
|
|
63 |
|
|
64 |
//This gets us the month name
|
|
65 |
$title = $amon[date('n', $first_day)] ;
|
|
66 |
$titlep = $amon[date('n', $first_day_prev)] ;
|
|
67 |
$titlen = $amon[date('n', $first_day_next)] ;
|
|
68 |
|
|
69 |
//Here we find out what day of the week the first day of the month falls on
|
|
70 |
$day_of_week = date('D', $first_day) ;
|
|
71 |
$day_of_weekp = date('D', $first_day_prev) ;
|
|
72 |
$day_of_weekn = date('D', $first_day_next) ;
|
|
73 |
|
|
74 |
//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
|
|
75 |
|
|
76 |
switch($day_of_week)
|
|
77 |
{
|
|
78 |
case "Mon": $blank = 0; $day_nr = 0; break;
|
|
79 |
case "Tue": $blank = 1; $day_nr = 1; break;
|
|
80 |
case "Wed": $blank = 2; $day_nr = 2; break;
|
|
81 |
case "Thu": $blank = 3; $day_nr = 3; break;
|
|
82 |
case "Fri": $blank = 4; $day_nr = 4; break;
|
|
83 |
case "Sat": $blank = 5; $day_nr = 5; break;
|
|
84 |
case "Sun": $blank = 6; $day_nr = 6; break;
|
|
85 |
}
|
|
86 |
switch($day_of_weekp)
|
|
87 |
{
|
|
88 |
case "Mon": $day_nrp = 0; break;
|
|
89 |
case "Tue": $day_nrp = 1; break;
|
|
90 |
case "Wed": $day_nrp = 2; break;
|
|
91 |
case "Thu": $day_nrp = 3; break;
|
|
92 |
case "Fri": $day_nrp = 4; break;
|
|
93 |
case "Sat": $day_nrp = 5; break;
|
|
94 |
case "Sun": $day_nrp = 6; break;
|
|
95 |
}
|
|
96 |
switch($day_of_weekn)
|
|
97 |
{
|
|
98 |
case "Mon": $day_nrn = 0; break;
|
|
99 |
case "Tue": $day_nrn = 1; break;
|
|
100 |
case "Wed": $day_nrn = 2; break;
|
|
101 |
case "Thu": $day_nrn = 3; break;
|
|
102 |
case "Fri": $day_nrn = 4; break;
|
|
103 |
case "Sat": $day_nrn = 5; break;
|
|
104 |
case "Sun": $day_nrn = 6; break;
|
|
105 |
}
|
|
106 |
|
|
107 |
//We then determine how many days are in the current month
|
|
108 |
|
|
109 |
$days_month = cal_days_in_month(0, $month, $year) ;
|
|
110 |
$monthn = $month+1;
|
|
111 |
$yearn = $year;
|
|
112 |
if ($monthn == 13) {$monthn = 1; $yearn = $year+1;}
|
|
113 |
$days_monthn = cal_days_in_month(0, $monthn, $yearn) ;
|
|
114 |
$monthp = $month-1;
|
|
115 |
$yearp = $year;
|
|
116 |
if ($monthp == 0) {$monthp = 12; $yearp = $year-1;}
|
|
117 |
$days_monthp = cal_days_in_month(0, $monthp, $yearp) ;
|
|
118 |
//echo "aktueller Monat=$month, vorheriger Monat=$monthp, nächster Monat=$monthn<br />";
|
|
119 |
/*
|
|
120 |
//Here we start building the table heads
|
|
121 |
echo "<div align='center'>";
|
|
122 |
echo "<table border=1 width=294>";
|
|
123 |
|
|
124 |
echo "<tr><th colspan=7> $title $year </th></tr>";
|
|
125 |
|
|
126 |
echo "<tr><td width=42>Mo</td><td width=42>Di</td><td width=42>Mi</td><td width=42>Do</td><td width=42>Fr</td><td width=42>Sa</td><td width=42>So</td></tr>";
|
|
127 |
|
|
128 |
//This counts the days in the week, up to 7
|
|
129 |
|
|
130 |
$day_count = 1;
|
|
131 |
echo "<tr>";
|
|
132 |
|
|
133 |
//first we take care of those blank days
|
|
134 |
|
|
135 |
while ( $blank > 0 )
|
|
136 |
{
|
|
137 |
echo "<td></td>";
|
|
138 |
$blank = $blank-1;
|
|
139 |
$day_count++;
|
|
140 |
}
|
|
141 |
|
|
142 |
//sets the first day of the month to 1
|
|
143 |
|
|
144 |
$day_num = 1;
|
|
145 |
|
|
146 |
//count up the days, untill we've done all of them in the month
|
|
147 |
|
|
148 |
while ( $day_num <= $days_in_month )
|
|
149 |
{
|
|
150 |
echo "<td> $day_num </td>";
|
|
151 |
$day_num++;
|
|
152 |
$day_count++;
|
|
153 |
//Make sure we start a new row every week
|
|
154 |
if ($day_count > 7)
|
|
155 |
{
|
|
156 |
echo "</tr><tr>";
|
|
157 |
$day_count = 1;
|
|
158 |
}
|
|
159 |
}
|
|
160 |
//Finaly we finish out the table with some blank details if needed
|
|
161 |
|
|
162 |
while ( $day_count >1 && $day_count <=7 )
|
|
163 |
{
|
|
164 |
echo "<td> </td>";
|
|
165 |
$day_count++;
|
|
166 |
}
|
|
167 |
echo "</tr></table>";
|
|
168 |
echo "</div>";
|
|
169 |
*/
|
|
170 |
// Kalender als 1 Zeile
|
|
171 |
echo "<div align='center'>";
|
|
172 |
echo "<h3> Belegung Appartments FHI</h3>";
|
|
173 |
|
|
174 |
include_once($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/inc/dbconnect.inc.php");
|
|
175 |
if (!isset($dbc) || !$dbc) $dbc = new dbconnection("fhi");
|
|
176 |
|
|
177 |
$sql = "SELECT id, name, apt, von, bis FROM wover
|
|
178 |
WHERE Year(von) >= $year-1
|
|
179 |
ORDER BY von DESC, apt";
|
|
180 |
if ($result = $dbc -> queryObjectArray($sql))
|
|
181 |
{
|
|
182 |
// echo "<table>";
|
|
183 |
foreach ($result as $row)
|
|
184 |
{
|
|
185 |
if ($row->von)
|
|
186 |
{
|
|
187 |
$vond = new DateTime($row->von);
|
|
188 |
$vond = $vond -> format("d.m.Y");
|
|
189 |
}
|
|
190 |
else $vonf = $row->von;
|
|
191 |
if ($row->bis)
|
|
192 |
{
|
|
193 |
$bisd = new DateTime($row->bis);
|
|
194 |
$bisd = $bisd -> format("d.m.Y");
|
|
195 |
}
|
|
196 |
else $bisf = $row->bis;
|
|
197 |
// echo "<tr><td>".$row->name . "</td><td>" .$row->apt . "</td><td>" .$vond . "</td><td>" .$bisd . "</td></tr>";
|
|
198 |
$aresv["id"][] = $row->id;
|
|
199 |
$aresv["name"][] = $row->name;
|
|
200 |
$aresv["apt"][] = $row->apt;
|
|
201 |
$aresv["von"][] = $row->von;
|
|
202 |
$aresv["bis"][] = $row->bis;
|
|
203 |
}
|
|
204 |
// echo "</table>";
|
|
205 |
// print_r ($aresv); echo "<br /><br />";
|
|
206 |
}
|
|
207 |
|
|
208 |
function aptres($daynr,$month,$year,$von,$bis,$name,$pos)
|
|
209 |
{
|
|
210 |
$aktdat = date('Y-m-d',mktime(0,0,0,$month,$daynr+1,$year));
|
|
211 |
if ($von <= $aktdat && $bis >= $aktdat)
|
|
212 |
return substr($name,$pos,1);
|
|
213 |
else return null;
|
|
214 |
}
|
|
215 |
|
|
216 |
function monat($day_nr,$days_month,$month,$year,$tit,$mon="")
|
|
217 |
{
|
|
218 |
global $aday;
|
|
219 |
global $aresv;
|
|
220 |
$clg = "class='bgmarkg1 center'";
|
|
221 |
$cl1 = "class='bgmarkg1 center'";
|
|
222 |
$cl2 = "class='bgmarkg2 center'";
|
|
223 |
echo "<table border=1 cellspacing='0' cellpadding='0'>";
|
|
224 |
echo "<tr><th class='center' colspan='$days_month' >$tit $year </th></tr>";
|
|
225 |
echo "<tr>";
|
|
226 |
$dnr = $day_nr;
|
|
227 |
// daynames
|
|
228 |
for ($i=0;$i<$days_month;$i++)
|
|
229 |
{
|
|
230 |
if ($dnr > 4) $cl = " class = 'bgmarkwe'"; else $cl = "";
|
|
231 |
if (($mon == "") || ($mon == "p" && $i>14) || ($mon == "n" && $i<15))
|
|
232 |
echo "<td$cl width='18'>".$aday[$dnr]."</td>\n";
|
|
233 |
if ($dnr<6) $dnr += 1; else $dnr = 0;
|
|
234 |
}
|
|
235 |
echo "</tr>\n";
|
|
236 |
echo "<tr>";
|
|
237 |
$dnr = $day_nr;
|
|
238 |
// daynumbers
|
|
239 |
for ($i=0;$i<$days_month;$i++)
|
|
240 |
{
|
|
241 |
if ($dnr > 4) $cl = " class = 'bgmarkwe center'"; else $cl = " class = 'center'";
|
|
242 |
if (($mon == "") || ($mon == "p" && $i>14) || ($mon == "n" && $i<15))
|
|
243 |
echo "<td$cl>".($i+1)."</td>\n";
|
|
244 |
if ($dnr<6) $dnr += 1; else $dnr = 0;
|
|
245 |
}
|
|
246 |
echo "</tr>";
|
|
247 |
for ($j=0; $j<11; $j++)
|
|
248 |
for ($i=0;$i<$days_month;$i++)
|
|
249 |
for ($k=0; $k<count($aresv["id"]);$k++)
|
|
250 |
{
|
|
251 |
$gn[$j][$i][$k] = "";
|
|
252 |
$pos[$j][$k] = 0;
|
|
253 |
}
|
|
254 |
// appartments
|
|
255 |
for ($j=0; $j<11; $j++)
|
|
256 |
{
|
|
257 |
if ($j == 3) $j +=1; // kein apt. 4
|
|
258 |
$dnr = $day_nr;
|
|
259 |
echo "<tr>";
|
|
260 |
for ($i=0;$i<$days_month;$i++)
|
|
261 |
{
|
|
262 |
if ($dnr > 4) $cl = " class = 'bgmarkwe center'"; else $cl = " class = 'center'";
|
|
263 |
if (($mon == "") || ($mon == "p" && $i>14) || ($mon == "n" && $i<15))
|
|
264 |
{
|
|
265 |
$anznam = 0;
|
|
266 |
for ($k=0; $k<count($aresv["id"]);$k++)
|
|
267 |
{
|
|
268 |
if ($aresv["apt"][$k] == ($j+1))
|
|
269 |
{
|
|
270 |
if ($namv[$i][$k] == $aresv["name"][$k]) $pos[$k] +=1;
|
|
271 |
// $nam = aptres($i,$month,$year,strtotime($aresv["von"][$k]),strtotime($aresv["bis"][$k]),$aresv["name"][$k]);
|
|
272 |
$nam = aptres($i,$month,$year,$aresv["von"][$k],$aresv["bis"][$k],$aresv["name"][$k],$pos[$j][$k]);
|
|
273 |
if ($nam)
|
|
274 |
{
|
|
275 |
if ($pos[$j][$k] == 0 && $clg == $cl1) $clg = $cl2;
|
|
276 |
elseif ($pos[$j][$k] == 0 && $clg == $cl2) $clg = $cl1;
|
|
277 |
$addr = "<a href='reserv_ed.php?i=".$aresv["id"][$k]."'>$nam</a>";
|
|
278 |
echo "<td $clg>".$addr."</td>\n";
|
|
279 |
if ($gn[$j][$i-1][$k] == $aresv["name"][$k]);
|
|
280 |
{
|
|
281 |
$pos[$j][$k] +=1;
|
|
282 |
}
|
|
283 |
$gn[$j][$i][$k] = $aresv["name"][$k];
|
|
284 |
$anznam +=1;
|
|
285 |
}
|
|
286 |
}
|
|
287 |
}
|
|
288 |
if (!$anznam)
|
|
289 |
{
|
|
290 |
echo "<td$cl>"." "."</td>\n";
|
|
291 |
}
|
|
292 |
}
|
|
293 |
if ($dnr<6) $dnr += 1; else $dnr = 0;
|
|
294 |
}
|
|
295 |
echo "</tr>";
|
|
296 |
}
|
|
297 |
echo "</table>\n";
|
|
298 |
}
|
|
299 |
|
|
300 |
echo "<table border='0' cellspacing='0' cellpadding='0'><tr>";
|
|
301 |
echo "<td><table border=1 cellspacing='0' cellpadding='0'><tr><td rowspan='3'> </td><td> </td></tr>\n";
|
|
302 |
echo "<tr><td> </td></tr><tr><td> </td></tr>";
|
|
303 |
echo "<tr><td colspan='2' height='18'>Apt. 1</td></tr>";
|
|
304 |
echo "<tr><td colspan='2' height='18'>Apt. 2</td></tr>";
|
|
305 |
echo "<tr><td colspan='2' height='18'>Apt. 3</td></tr>";
|
|
306 |
// echo "<tr><td colspan='2'>Apt. 4</td></tr>";
|
|
307 |
echo "<tr><td colspan='2' height='18'>Apt. 5</td></tr>";
|
|
308 |
echo "<tr><td colspan='2' height='18'>Apt. 6</td></tr>";
|
|
309 |
echo "<tr><td colspan='2' height='18'>Apt. 7</td></tr>";
|
|
310 |
echo "<tr><td colspan='2' height='18'>Apt. 8</td></tr>";
|
|
311 |
echo "<tr><td colspan='2' height='18'>Apt. 9</td></tr>";
|
|
312 |
echo "<tr><td colspan='2' height='18'>Apt. 10</td></tr>";
|
|
313 |
echo "<tr><td colspan='2' height='18'>Apt. 11</td></tr></table></td><td>";
|
|
314 |
monat($day_nrp,$days_monthp,$monthp,$yearp,$titlep,"p");
|
|
315 |
echo "</td><td>";
|
|
316 |
monat($day_nr,$days_month,$month,$year,$title);
|
|
317 |
echo "</td><td>";
|
|
318 |
monat($day_nrn,$days_monthn,$monthn,$yearn,$titlen,"n");
|
|
319 |
echo "</td></tr></table>\n";
|
|
320 |
|
|
321 |
echo "<form action=\"".$_SERVER['PHP_SELF'] ."\" method=\"post\" enctype=\"application/x-www-form-urlencoded\" name=\"form_w\">";
|
|
322 |
echo "<p><input class=\"button\" type=\"submit\" name=\"sub\" value=\"<\" title='mon-1'>";
|
|
323 |
echo " ";
|
|
324 |
echo "<input class=\"button\" type=\"submit\" name=\"sub\" value=\">\" title='mon+1'></p>\n";
|
|
325 |
echo "<input type=\"hidden\" name=\"mon\" value=\"$month\">";
|
|
326 |
echo "<input type=\"hidden\" name=\"yr\" value=\"$year\">";
|
|
327 |
echo "</form>";
|
|
328 |
echo "</div>";
|
|
329 |
|
|
330 |
?>
|
|
331 |
</body>
|
|
332 |
</html> |