| [ PHPXref.com ] | [ Generated: Sun Jul 20 20:47:44 2008 ] | [ TUTOS 1.2 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Copyright 1999 - 2004 by Gero Kohnert 4 * 5 * CVS Info: $Id: Date.pinc,v 1.97.2.3 2005/08/11 07:28:50 gokohnert Exp $ 6 * $Author: gokohnert $ 7 */ 8 9 include_once 'adodb-time.inc.php'; 10 /** 11 * format a floating hour number 12 */ 13 function hour_format($hours) { 14 if ( ! is_numeric($hours) ) return; 15 $h = floor($hours); 16 $m = 60.0 * ($hours - $h); 17 return $h .":".sprintf("%02.0f",$m); 18 } 19 /** 20 * Return Noon of the next day after t (t is noon) 21 */ 22 function NextDay ($t) { 23 /* Add One Day plus one possible DST hour */ 24 $t += 90000; 25 $t = MkTime(12,0,0,Date("m",$t),Date("d",$t),Date("Y",$t)); 26 return ($t); 27 }; 28 29 function dow($d, $m, $y) { 30 $ret = date("w", adodb_mktime(0,0,0,$m,$d,$y)); 31 return $ret; 32 } 33 34 function ndays($m, $y) { 35 $n = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 36 $ret = $n[$m-1]; 37 if ($m == 2 && ($y % 4 == 0) && (($y % 100 != 0) || $y % 400 == 0)) { 38 $ret++; 39 } 40 return $ret; 41 } 42 43 function nthday($n, $wd, $m, $y) { 44 if ($n == -1) { 45 # Last 46 $days = ndays($m, $y); 47 $ret = $days - (dow($days, $m, $y) - $wd + 7) % 7; 48 } 49 else { 50 $ret = ($n-1)*7 + 1 + (7 + $wd - dow(($n-1)*7 + 1, $m, $y)) % 7; 51 } 52 return $ret; 53 } 54 55 /* 56 * Read and fill the holiday array 57 */ 58 function ReadHolidayInfo() { 59 global $current_user,$tutos; 60 61 $tutos[cal] = array(); 62 63 # Read Custom Holidays , like company anniversary etc. 64 if ( file_exists(getcwd()."/".$tutos['base']."/php/localization/holiday_custom.pinc") && is_readable(getcwd()."/".$tutos['base']."/php/localization/holiday_custom.pinc") ) { 65 include "localization/holiday_custom.pinc"; 66 } 67 68 foreach($tutos[holiday] as $i => $f) { 69 $i = strtolower($i); 70 if ( ($f == 1) && ($current_user->holiday[$i] == 1) ) { 71 error_reporting(E_ALL); 72 include "localization/holiday_". $i .".pinc"; 73 error_reporting($tutos['error_reporting']); 74 } 75 } 76 77 return; 78 } 79 /* 80 * Read and fill the namedays array 81 */ 82 function ReadNamedayInfo() { 83 global $current_user,$tutos; 84 85 $tutos['nd'] = array(); 86 87 @reset($tutos[nameday]); 88 while( list ($i,$f) = @each ($tutos[nameday])) { 89 $i = strtolower($i); 90 if ( ($f == 1) && ($current_user->nameday[$i] == 1) ) { 91 include "localization/namedays_". $i .".p3"; 92 } 93 } 94 95 return; 96 } 97 /* 98 * Check if the given date is a holiday in one of the enabled holidy sets 99 * if user wants to show namedays, then do it 100 * t = Date in timestamp format 101 */ 102 function GetExtendedDayInfo($t) { 103 global $tutos, $current_user; 104 105 $desc = ""; 106 $mark = 0; 107 108 $today = getdate($t); 109 110 $wd = Date("D",$t); 111 $month = Date("m",$t); 112 113 114 /* Yearly Days */ 115 $day = Date("d-m",$t); 116 117 # We need the easter date for some calculation 118 $J = Date("Y",$t); 119 $a = $J % 19; 120 $b = $J % 4; 121 $c = $J % 7; 122 $d = (19 * $a + 24) % 30; 123 $e = (2 * $b + 4 * $c + 6 * $d + 5) % 7; 124 $OT = 22 + $d + $e; 125 $OM = 3; 126 if ( $OT > 31 ) { 127 $OT = $d + $e - 9; 128 $OM = 4; 129 } 130 if ( ($OT == 26) && ($OM == 4) ) { 131 $OT = 19; 132 } 133 if ( ($OT == 25) && ($OM == 4) && ($d == 28) && ($e == 6) && ($a > 10) ) { 134 $OT = 18; 135 } 136 137 $br = "<br />"; 138 139 # Walk over namedays 140 $nd = Date("j",$t); 141 $nm = Date("n",$t); 142 for ($ii = 0 ; $ii < count($tutos['nd']); $ii++) { 143 if ( isset($tutos['nd'][$ii][$nm][$nd]) ) { 144 $desc .= $tutos['nd'][$ii][$nm][$nd].$br; 145 } 146 } 147 148 # Walk over claendars 149 for ($ii = 0 ; $ii < count($tutos[cal]); $ii++) { 150 151 $cnt = count($tutos[cal][$ii]); 152 153 for ($ij = 0 ; $ij < $cnt; $ij++) { 154 if ( ! isset($tutos[cal][$ii][$ij][type])) { 155 $tutos[cal][$ii][$ij][type] = 1; 156 } 157 /* Yearly Days */ 158 if ($tutos[cal][$ii][$ij][Date] == $day) { 159 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 160 $mark += $tutos[cal][$ii][$ij][type]; 161 continue; 162 } 163 164 /* Holidays defined by Weekday */ 165 if ( $wd == "Mon" ) { 166 /* Date calculation for Dutch carnaval monday by Robert Brouwer */ 167 if ($tutos[cal][$ii][$ij][Date] == "CARNAVALMON") { 168 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 169 $tp -= (7*7) * 86400; 170 $tp += 2*86400; 171 $pday = Date("d-m",$tp); 172 if ( $day == $pday ) { 173 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 174 $mark += $tutos[cal][$ii][$ij][type]; 175 } 176 } 177 elseif ($tutos[cal][$ii][$ij][Date] == "EASTERMONDAY") { 178 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 179 $tp += 86400; 180 $pday = Date("d-m",$tp); 181 if ( $day == $pday ) { 182 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 183 $mark += $tutos[cal][$ii][$ij][type]; 184 } 185 } 186 elseif ($tutos[cal][$ii][$ij][Date] == "WHITMONDAY") { 187 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 188 $tp += 7 * 7 * 86400; 189 $tp += 86400; 190 $pday = Date("d-m",$tp); 191 if ( $day == $pday ) { 192 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 193 $mark += $tutos[cal][$ii][$ij][type]; 194 } 195 } 196 elseif (($tutos[cal][$ii][$ij][Date] == "MARTINLUTHERKING") && ($month == "01") && 197 ($today['mday'] == nthday(3, $today['wday'], $today['mon'], $today['year'])) ) { 198 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 199 $mark += $tutos[cal][$ii][$ij][type]; 200 } 201 elseif (($tutos[cal][$ii][$ij][Date] == "WASHINGTON") && ($month == "02") && 202 ($today['mday'] == nthday(3, $today['wday'], $today['mon'], $today['year'])) ) { 203 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 204 $mark += $tutos[cal][$ii][$ij][type]; 205 } 206 elseif (($tutos[cal][$ii][$ij][Date] == "MEMORIALDAY") && ($month == "05") && 207 ($today['mday'] == nthday(-1, $today['wday'], $today['mon'], $today['year'])) ) { 208 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 209 $mark += $tutos[cal][$ii][$ij][type]; 210 } 211 elseif (($tutos[cal][$ii][$ij][Date] == "LABORDAY") && ($month == "09") && 212 ($today['mday'] == nthday(1, 1, $today['mon'], $today['year'])) ) { 213 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 214 $mark += $tutos[cal][$ii][$ij][type]; 215 } 216 elseif (($tutos[cal][$ii][$ij][Date] == "COLUMBUSDAY") && ($month == "10") && 217 ($today['mday'] == nthday(2, 1, $today['mon'], $today['year'])) ) { 218 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 219 $mark += $tutos[cal][$ii][$ij][type]; 220 } 221 } 222 elseif ( $wd == "Tue" ) { 223 /* Date calculation for Dutch 'Prinsjesdag' by Robert Brouwer */ 224 if ($tutos[cal][$ii][$ij][Date] == "PRINSDAY" && ($month == "09") && 225 ($today['mday'] == nthday(3, $today['wday'], $today['mon'], $today['year']))) { 226 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 227 $mark += $tutos[cal][$ii][$ij][type]; 228 } 229 /* Date calculation for Dutch carnaval tuesday by Robert Brouwer */ 230 elseif ($tutos[cal][$ii][$ij][Date] == "CARNAVALTUE") { 231 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 232 $tp -= (7*7) * 86400; 233 $tp += 3* 86400; 234 $pday = Date("d-m",$tp); 235 if ( $day == $pday ) { 236 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 237 $mark += $tutos[cal][$ii][$ij][type]; 238 } 239 } 240 } 241 elseif ( $wd == "Wed" ) { 242 /* Date calculation for Dutch carnaval wednesday by Robert Brouwer */ 243 if ($tutos[cal][$ii][$ij][Date] == "CARNAVALWED") { 244 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 245 $tp -= (7*7) * 86400; 246 $tp += 4 * 86400; 247 $pday = Date("d-m",$tp); 248 if ( $day == $pday ) { 249 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 250 $mark += $tutos[cal][$ii][$ij][type]; 251 } 252 } 253 } 254 elseif ( $wd == "Thu" ) { 255 # Christ Himmelfahrt 256 if ($tutos[cal][$ii][$ij][Date] == "ASCENSIONDAY") { 257 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 258 $tp += (5*7 +4) * 86400; 259 $pday = Date("d-m",$tp); 260 if ( $day == $pday ) { 261 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 262 $mark += $tutos[cal][$ii][$ij][type]; 263 } 264 } 265 elseif ($tutos[cal][$ii][$ij][Date] == "FRONLEICHNAM") { 266 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 267 $tp += (8*7 +4) * 86400; 268 $pday = Date("d-m",$tp); 269 if ( $day == $pday ) { 270 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 271 $mark += $tutos[cal][$ii][$ij][type]; 272 } 273 } 274 elseif (($tutos[cal][$ii][$ij][Date] == "THANKSGIVING") && ($month == "11") && 275 ($today['mday'] == nthday(4, $today['wday'], $today['mon'], $today['year'])) ) { 276 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 277 $mark += $tutos[cal][$ii][$ij][type]; 278 } 279 } 280 elseif ( $wd == "Fri" ) { 281 if ($tutos[cal][$ii][$ij][Date] == "GOODFRIDAY") { 282 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 283 $tp -= 2 * 86400; 284 $pday = Date("d-m",$tp); 285 if ( $day == $pday ) { 286 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 287 $mark += $tutos[cal][$ii][$ij][type]; 288 } 289 } 290 } 291 elseif ( $wd == "Sun" ) { 292 if ($tutos[cal][$ii][$ij][Date] == "EASTERSUNDAY") { 293 if ( $day == sprintf("%02d-%02d",$OT,$OM) ) { 294 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 295 $mark += $tutos[cal][$ii][$ij][type]; 296 } 297 /* Date calculation for Dutch 'Moederdag' (Mothersday') by Robert Brouwer */ 298 } elseif ($tutos[cal][$ii][$ij][Date] == "MOTHERDAY" && 299 ($month == "5") && ($today['mday'] == nthday(2, $today['wday'], $today['mon'], $today['year'])) ) { 300 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 301 $mark += $tutos[cal][$ii][$ij][type]; 302 /* Date calculation for Dutch 'Vaderdag' (Fathersday') by Robert Brouwer */ 303 } elseif ($tutos[cal][$ii][$ij][Date] == "FATHERDAY" && 304 ($month == "6") && ($today['mday'] == nthday(3, $today['wday'], $today['mon'], $today['year'])) ) { 305 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 306 $mark += $tutos[cal][$ii][$ij][type]; 307 } elseif ($tutos[cal][$ii][$ij][Date] == "WHITSUNDAY") { 308 $tp = adodb_mktime (0,0,0,$OM,$OT,$J); 309 $tp += 7 * 7 * 86400; 310 $pday = Date("d-m",$tp); 311 if ( $day == $pday ) { 312 $desc .= $tutos[cal][$ii][$ij][Desc].$br; 313 $mark += $tutos[cal][$ii][$ij][type]; 314 } 315 } 316 } 317 } 318 } 319 320 if ( $desc == "" ) { 321 return array(color => "appday"); 322 } else { 323 if ( $mark > 0 ) { 324 return array(color => "holiday", Desc => "<font size=\"-3\">".substr($desc,0,-1*strlen($br))."</font>"); 325 } else { 326 return array(color => "appday", Desc => "<font size=\"-3\">".substr($desc,0,-1*strlen($br))."</font>"); 327 } 328 } 329 } 330 /* --------------------------------------------------------------------------- 331 * Evaluate the Color for day t 332 * t = Date in timestamp format 333 * 334 */ 335 function GetDaysInfo($t) { 336 337 $dinfo = GetExtendedDayInfo($t); 338 339 if (!empty($dinfo[Desc])) { 340 $dinfo[popinfo] = '<html><body>'; 341 $dinfo[popinfo] .= '<table class="inner" border="0" cellspacing="0" cellpadding="1">'; 342 $dinfo[popinfo] .= '<tr><td valign="top"><font size="-1"><strong>'; 343 $dinfo[popinfo] .= eregi_replace("'","\'",$dinfo[Desc]); 344 $dinfo[popinfo] .= '</strong></font></td></tr></table></body></html>'; 345 } 346 347 # Today 348 if ( Date("d.m.Y",$t) == Date("d.m.Y") ) { 349 $dinfo[color] = "today"; 350 return $dinfo; 351 } 352 353 $wd = Date("D",$t); 354 $month = Date("m",$t); 355 356 # Change here for islamic/arabic week scheme 357 # Sundays are free 358 if ( $wd == "Sun" ) { 359 $dinfo[color] = "holiday"; 360 return $dinfo; 361 } 362 363 # Saturdays are something special 364 if ( $wd == "Sat" ) { 365 $dinfo[color] = "freeday"; 366 return $dinfo; 367 } 368 369 return $dinfo; 370 }; 371 372 /** 373 * Intern Representation of Date and Time 374 * 375 * @package BASE 376 * @module DateTime 377 */ 378 class DateTime { 379 /** 380 * str is whatever a database gives us 381 * -1 = now 382 */ 383 function DateTime( $str = "-1" ) { 384 global $current_user; 385 386 $this->notime = 0; 387 $this->orig = $str; 388 if ( $str == -1 ) { 389 $this->day = Date("j"); 390 $this->month = Date("n"); 391 $this->year = Date("Y"); 392 $this->hour =