[ PHPXref.com ] [ Generated: Sun Jul 20 20:47:44 2008 ] [ TUTOS 1.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/php/ -> Date.pinc (source)

   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 = Date("H");
 393        $this->min = Date("i");
 394        $this->sec = Date("s");
 395        $this->ts = time();
 396        $this->ts_def = $this->ts;
 397        if ( isset($current_user) && ($current_user->offset != 0) ) {
 398          $this->ts_def -= $current_user->offset;
 399        }
 400        $this->tz = Date("T");
 401        $this->offset = Date("Z");
 402        $this->format = -1;
 403      } else {
 404        if (($str == "0") || ($str == "")) {
 405          $this->setNoTime();
 406        } else {
 407          $this->setDateTime($str);
 408        }
 409      }
 410    }
 411    /**
 412     * set datetime to nothing
 413     */
 414    function setNoTime() {
 415      $this->notime = 1;
 416      $this->day = -1;
 417      $this->month = -1;
 418      $this->year = -1;
 419      $this->hour = -1;
 420      $this->min = -1;
 421      $this->sec = 0;
 422      $this->ts = -1;
 423    }
 424    /**
 425     * set datetime for a timestamp
 426     * ts is assumed in current_users TZ
 427     */
 428    function setDateTimeTS($ts,$notz = 0) {
 429      global $current_user;
 430  
 431      if ( $ts != -1 ) {
 432        $this->notime  = 0;
 433      }
 434      $this->day = (integer)Date("d",$ts);
 435      $this->month = (integer)Date("m",$ts);
 436      $this->year = (integer)Date("Y",$ts);
 437      $this->hour = (integer)Date("H",$ts);
 438      $this->min = (integer)Date("i",$ts);
 439      $this->sec = (integer)Date("s",$ts);
 440      $this->ts = adodb_mktime($this->hour,$this->min,$this->sec,$this->month,$this->day,$this->year);
 441      $this->orig = "TS";
 442      $this->format = "TS";
 443      $this->ts_def = $ts;
 444      if ( ($current_user->offset != 0) && ($notz == 0) ) {
 445        $this->ts_def -= $current_user->offset;
 446      }
 447    }
 448    /**
 449     * set DateTime by variables (incoming variables are in the users TZ)
 450     * used via form
 451     */
 452    function setDateTimeF($str,$notz = 0) {
 453      global $current_user;
 454  
 455      $this->orig = "fields $str";
 456      $this->format = "fields";
 457      if ( count($_GET) ) {
 458        foreach ($_GET as $i => $f) {
 459          $x[$i] = $f;
 460        }
 461      }
 462      if ( count($_POST) ) {
 463        foreach ($_POST as $i => $f) {
 464          $x[$i] = $f;
 465        }
 466      }
 467  
 468      $v = sprintf("%s_d",$str);
 469      if ( isset($x[$v]) ) {
 470        $this->day   = (integer)$x[$v];
 471      }
 472      $v = sprintf("%s_m",$str);
 473      if ( isset($x[$v]) ) {
 474        $this->month = (integer)$x[$v];
 475      }
 476      $v = sprintf("%s_y",$str);
 477      if ( isset($x[$v]) ) {
 478        $this->year  = (integer)$x[$v];
 479      }
 480      $v = sprintf("%s_H",$str);
 481      if ( isset($x[$v]) ) {
 482        $this->hour  = (integer)$x[$v];
 483      } else {
 484        $this->hour   = 0;
 485      }
 486      $v = sprintf("%s_M",$str);
 487      if ( isset($x[$v]) ) {
 488        $this->min   = (integer)$x[$v];
 489      } else {
 490        $this->min   = 0;
 491      }
 492      $this->sec   = 0;
 493  
 494      $this->ts = adodb_mktime($this->hour,$this->min,$this->sec,$this->month,$this->day,$this->year);
 495  
 496      if ( ($this->day < 1) || ($this->month < 1) || ($this->year < 1) ) {
 497        $this->setNoTime();
 498      } else {
 499        $this->notime  = 0;
 500      }
 501      if ( $this->checkDMY() == false) {
 502        $this->setNoTime();
 503      }
 504  #    settype($this->day,"integer");
 505  #    settype($this->month,"integer");
 506  #    settype($this->year,"integer");
 507  
 508      $this->ts_def = $this->ts;
 509      if ( ($current_user->offset != 0) && ($notz == 0) ) {
 510        $this->ts_def -= $current_user->offset;
 511      }
 512    }
 513    /**
 514     * Checks if DMY fields are valid
 515     */
 516    function checkDMY($notime_allowed = false) {
 517      if ( $this->notime  == 1 ) {
 518        return $notime_allowed;
 519      }
 520  
 521      if ( $this->day < 1 ) { return 0;}
 522      if ( $this->day > 31 ) { return 0;}
 523      if ( $this->month < 1 ) { return 0;}
 524      if ( $this->month > 12 ) { return 0;}
 525      if ( $this->hour < 0 ) { return 0;}
 526      if ( $this->hour > 23 ) { return 0;}
 527      if ( $this->min < 0 ) { return 0;}
 528      if ( $this->min > 59 ) { return 0;}
 529  
 530      if ( (Date("n-j",$this->ts) != $this->month ."-". $this->day) && ($this->ts >= 0)  ) {
 531        return false;
 532      }
 533      return true;
 534    }
 535    /**
 536     *
 537     * On MySQL the given time is in tutos[defaultTZ] we have to fix the offset
 538     * On Postgres it is in the current users TZ
 539     *
 540     */
 541    function setDateTime($str,$notz = 0) {
 542      global $current_user , $tutos;
 543  
 544      if ( ! isset ($str) ) return;
 545      if ( empty ($str) ) return;
 546  
 547      $this->format = 0;
 548      $this->orig = $str;
 549      $this->notime  = 0;
 550      $regs = array();
 551  
 552      if ( $str == "epoch" ) {
 553        $this->setNoTime();
 554        return;
 555      };
 556      if (($str == "0") || ($str == "") || ($str== "--------") || ($str == "------------") ) {
 557        $this->setNoTime();
 558        return;
 559      };
 560  
 561      # check the registered formats
 562      foreach($tutos['dateformat'] as $f) {
 563        @$f($this,$str);
 564        if ($this->format != 0) {
 565  #        echo $str." ". $f ."<br />";
 566          break;
 567        }
 568      }
 569  #    if ($this->format == 0) {
 570  #      echo $str." X<br />";
 571  #   }
 572  
 573      if ($this->format != 0) {
 574      } else
 575      if ( ereg( "^([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})\.([0-9]+) ([a-z]*)$", $str, $regs ) ) {
 576        # Init via DB 06.02.2001 17:39:32.00 CET  Postgres 7.1
 577        $this->month = (integer)$regs[1];
 578        $this->day   = (integer)$regs[2];
 579        $this->year  = (integer)$regs[3];
 580        $this->hour  = (integer)$regs[4];
 581        $this->min   = (integer)$regs[5];
 582        $this->sec   = (integer)$regs[6];
 583        $this->format = 10;
 584      } else
 585      if ( ereg( "^([0-1][0-9])([0-3][0-9])([0-9]{4})$", $str, $regs ) ) {
 586        # Init via DB MMDDYYYY
 587        $this->month = (integer)$regs[1];
 588        $this->day   = (integer)$regs[2];
 589        $this->year  = (integer)$regs[3];
 590        $this->hour  = 0;
 591        $this->min   = 0;
 592        $this->sec   = 0;
 593        $this->format = 4;
 594      } else
 595      if ( ereg( "^([0-9]{4})-?([0-1][0-9])-?([0-3][0-9]) ?([0-2][0-9]):?([0-5][0-9]):?([0-5][0-9])$", $str, $regs ) ) {
 596        # Init via YYYYMMDDHHMMSS  or YYYY-MM-DD HH:MM:SS used in calendar
 597        $this->year  = (integer)$regs[1];
 598        $this->month = (integer)$regs[2];
 599        $this->day   = (integer)$regs[3];
 600        $this->hour  = (integer)$regs[4];
 601        $this->min   = (integer)$regs[5];
 602        $this->sec   = (integer)$regs[6];
 603        $this->format = 5;
 604      } else
 605      if ( ereg( "([0-9]{4})([0-1][0-9])([0-3][0-9])([0-2][0-9])([0-5][0-9])", $str, $regs ) ) {
 606        # Init via YYYYMMDDHHMM
 607        $this->year  = (integer)$regs[1];
 608        $this->month = (integer)$regs[2];
 609        $this->day   = (integer)$regs[3];
 610        $this->hour  = (integer)$regs[4];
 611        $this->min   = (integer)$regs[5];
 612        $this->sec   = 0;
 613        $this->format = 6;
 614      } else
 615      if ( ereg( "^([0-9]{4})([0-1][0-9])([0-3][0-9])$", $str, $regs ) ) {
 616        # Init via YYYYMMDD used in calendar
 617        $this->year  = (integer)$regs[1];
 618        $this->month = (integer)$regs[2];
 619        $this->day   = (integer)$regs[3];
 620        $this->hour  = 0;
 621        $this->min   = 0;
 622        $this->sec   = 0;
 623        $this->format = 7;
 624      } else
 625      if ( ereg( "^([0-1][0-9])-([0-3][0-9])-([0-9]{4})$", $str, $regs ) ) {
 626        # Init via MM-DD-YYYY
 627        $this->month = (integer)$regs[1];
 628        $this->day   = (integer)$regs[2];
 629        $this->year  = (integer)$regs[3];
 630        $this->hour  = 0;
 631        $this->min   = 0;
 632        $this->sec   = 0;
 633        $this->format = 8;
 634      } else {
 635        echo "<br />DT: Unknown DateTimeFormat <span class=\"warn\">". $str ."</span> fix it in Date.pinc or register a DB specific format<br />";
 636        return;
 637      }
 638  
 639      $this->ts = adodb_mktime($this->hour,$this->min,$this->sec,$this->month,$this->day,$this->year);
 640  
 641      $this->ts_def = $this->ts;
 642      if ( ($current_user->offset != 0) && ($notz == 0) ) {
 643        $this->ts += $current_user->offset;
 644        // Set the fields according to offset
 645        $this->setDateTimeTS($this->ts);
 646      }
 647    }
 648    /**
 649     * part of a form used to enter a day
 650     */
 651    function EnterDay($name,$none = 0) {
 652      $x = sprintf("%s_d",$name );
 653      echo "<select id=\"". $x ."\" name=\"". $x ."\">";
 654      $day=0;
 655      if ( ($none == 1) || ($this->day == -1) ) {
 656        echo "<option value=\"-1\"";
 657        if ( $this->day == -1 ) {
 658          echo " selected=\"selected\"";
 659        }
 660        echo ">--</option>\n";
 661      }
 662      while($day < 31) {
 663        $day++;
 664        echo "<option value=\"". $day ."\"";
 665        if ( $day == $this->day ) {
 666          echo " selected=\"selected\" ";
 667        }
 668        echo ">";
 669        printf ("%02d\n",$day);
 670        echo "</option>\n";
 671      }
 672      echo "</select>\n";
 673    }
 674    /**
 675     * parts of a form used to enter a month
 676     */
 677    function EnterMonth($name,$none = 0) {
 678      $x = sprintf("%s_m",$name );
 679      echo "<select id=\"". $x ."\" name=\"". $x ."\">";
 680      $mon=0;
 681      if ( ($none == 1) || ($this->month == -1) ) {
 682        echo "<option value=\"-1\"";
 683        if ( $this->month == -1 ) {
 684          echo " selected=\"selected\"";
 685        }
 686        echo ">--</option>\n";
 687      }
 688      while($mon < 12) {
 689        $mon++;
 690        echo "<option value=\"". $mon ."\"";
 691        if ( $mon == $this->month ) {
 692          echo " selected=\"selected\" ";
 693        }
 694        echo ">";
 695        printf ("%02d\n",$mon);
 696        echo "</option>\n";
 697      }
 698      echo "</select>\n";
 699    }
 700    /**
 701     * parts of a form used to enter a year
 702     * future_only = try to allow only date in the future (i.e. years)
 703     */
 704    function EnterYear($name,$none = 0,$future_only = false) {
 705      $x = sprintf("%s_y",$name );
 706      echo "<select id=\"". $x ."\" name=\"". $x ."\">";
 707      $year=  Date("Y") + 10;
 708      if ( ($none == 1) || ($this->year == -1) ) {
 709        echo "<option value=\"-1\"";
 710        if ( $this->year == -1 ) {
 711          echo " selected=\"selected\"";
 712        }
 713        echo ">----</option>\n";
 714      }
 715      if ($future_only) {
 716        $stop =  Date("Y");
 717      } else {
 718        $stop =  1900;
 719      }
 720      while($year >= $stop ) {
 721        # yes my grandma was born 1904 (I need this!)
 722        echo "<option value=\"". $year ."\"";
 723        if ( $year == $this->year ) {
 724          echo " selected=\"selected\" ";
 725        }
 726        echo ">". $year . "</option>\n";
 727        $year--;
 728      }
 729      echo "</select>\n";
 730    }
 731  
 732    function ShowMinical($name, $none = 0) {
 733      global $tutos, $lang;
 734      
 735      if ( !isset($_SERVER['HTTP_USER_AGENT']) || ereg("Lynx",$_SERVER['HTTP_USER_AGENT']) || ereg("w3m",$_SERVER['HTTP_USER_AGENT']) ) {
 736        # Do nothing
 737      } else {
 738        echo "<a href=\"JavaScript:
 739  var d = document.forms[0];
 740  mywindow = window.open('', 'calendar', 'resizable=yes,width=200,height=200,top=100,left=100');
 741  mywindow.location.href = '". $tutos['base'] ."/php/minical.php?f=".$name."&amp;n=".$none."&amp;d=".
 742  $this->day ."&amp;m=". $this->month ."&amp;y=". $this->year
 743  ."&amp;". SID ."';
 744  mywindow.focus();
 745  \" onmouseover=\"self.status='" . $lang['MiniCalHeadline'] . "';return true;\">\n";
 746        echo "<font size=\"-1\">" . $lang['MiniCalHref'] . "</font>\n";
 747        echo "</a>\n";
 748      }
 749    }
 750    
 751    /**
 752     * ask for date
 753     * none = 0  (no date not allowed)
 754     * none = 1  (allowed to enter nothing)
 755     */
 756    function EnterDate($name,$none = 0,$future_only = false) {
 757      global $tutos;
 758  
 759      if ( $tutos['df'] == 1 ) {
 760        $this->EnterMonth($name,$none);
 761      } else {
 762        $this->EnterDay($name,$none);
 763      }
 764      echo "<b>.</b>&nbsp;";
 765      if ( $tutos['df'] == 1 ) {
 766        $this->EnterDay($name,$none);
 767      } else {
 768        $this->EnterMonth($name,$none);
 769      }
 770      echo "<b>.</b>&nbsp;";
 771      $this->EnterYear($name,$none,$future_only);
 772  
 773      $this->ShowMinical($name, $none);
 774    }
 775    /**
 776     * enter a time into a form
 777     */
 778    function EnterTime($name) {
 779      $h = sprintf("%s_H",$name );
 780      $m = sprintf("%s_M",$name );
 781  
 782      echo "<input id=\"". $h ."\" maxlength=\"2\" size=\"2\" name=\"". $h ."\" value=\"". sprintf("%02d",$this->hour) ."\" />\n";
 783      echo "&nbsp;<b>:</b>&nbsp;";
 784      echo "<input id=\"". $m ."\" maxlength=\"2\" size=\"2\" name=\"". $m ."\" value=\"". sprintf("%02d",$this->min) ."\" />\n";
 785    }
 786    /**
 787     * ask for date
 788     * none = 0  (no date not allowed)
 789     * none = 1  (allowed to enter nothing)
 790     * future_only = try to allow only date in the future (i.e. years)
 791     */
 792    function EnterDateTime($name,$none = 0,$future_only = false) {
 793      global $tutos;
 794  
 795      if ( $tutos['df'] == 1 ) {
 796        $this->EnterMonth($name,$none);
 797      } else {
 798        $this->EnterDay($name,$none);
 799      }
 800      echo "<b>.</b>&nbsp;";
 801      if ( $tutos['df'] == 1 ) {
 802        $this->EnterDay($name,$none);
 803      } else {
 804        $this->EnterMonth($name,$none);
 805      }
 806      echo "<b>.</b>&nbsp;";
 807      $this->EnterYear($name,$none,$future_only);
 808  
 809      $h = sprintf("%s_H",$name );
 810      $m = sprintf("%s_M",$name );
 811      
 812      echo "<input maxlength=\"2\" size=\"2\" name=\"". $h ."\" value=\"". ($this->hour == -1 ? "--":$this->hour)  ."\" />\n";
 813      echo "&nbsp;<b>:</b>&nbsp;";
 814      echo "<input maxlength=\"2\" size=\"2\" name=\"". $m ."\" value=\"". ($this->min == -1 ? "--":$this->min) ."\" />\n";
 815      
 816      $this->ShowMinical($name, $none);
 817    }
 818    /* ---------------------------------------------------------------------------
 819     */
 820    function getDateTimeShort() {
 821      global $lang;
 822  
 823      if ( $this->notime == 1) {
 824        return sprintf ($lang['DateTimeSFormat'],"--","--","--","--");
 825      }
 826      return strftime($lang['DateTimeSStr'],$this->ts);
 827    }
 828    /* ---------------------------------------------------------------------------
 829     */
 830    function getDateTime() {
 831      global $lang;
 832  
 833      if ( $this->notime == 1) {
 834        return sprintf ($lang['DateTimeFormat'],"--","--","----","--","--","   ");
 835      }
 836  #    return strftime($lang['DateTimeStr'],$this->ts);
 837      return Date($lang['DateTimePHP'],$this->ts);
 838    }
 839    /* ---------------------------------------------------------------------------
 840     */
 841    function getTime() {
 842      global $lang;
 843  
 844      if ( $this->notime == 1) {
 845        return sprintf ($lang['TimeFormat'],"--","--");
 846      }
 847      return strftime($lang['TimeFormatStr'],$this->ts);
 848    }
 849    /* ---------------------------------------------------------------------------
 850     */
 851    function getDate() {
 852      global $lang,$tutos;
 853  
 854      if ( $this->notime == 1) {
 855        return sprintf ($lang['DateFormat'],"--","--","----");
 856      }
 857      return sprintf ($lang['DateFormat'],$this->day,$this->month,$this->year);
 858    }
 859    /* ---------------------------------------------------------------------------
 860     */
 861    function getDateShort() {
 862      global $lang,$tutos;
 863  
 864      if ( $this->notime == 1) {
 865        return sprintf ($lang['DateShortFormat'],"--","--");
 866      }
 867      return sprintf ($lang['DateShortFormat'],$this->day,$this->month);
 868    }
 869    /* ---------------------------------------------------------------------------
 870     */
 871    function getYYYYMMDD() {
 872      if ( $this->notime == 1) {
 873        return "--------";
 874      }
 875      return sprintf ("%04d%02d%02d",$this->year,$this->month,$this->day);
 876    }
 877    /**
 878     * get date formatted as MONTH DAY
 879     * used in watchlist
 880     */
 881    function getMMDD() {
 882      if ( $this->notime == 1) {
 883        return "----";
 884      }
 885      return sprintf ("%02d%02d",$this->month,$this->day);
 886    }
 887    /* ---------------------------------------------------------------------------
 888     */
 889    function getYYYYMMDDHHMM() {
 890      if ( $this->notime == 1) {
 891        return "------------";
 892      }
 893      return sprintf ("%04d%02d%02d%02d%02d",$this->year,$this->month,$this->day,$this->hour,$this->min);
 894    }
 895    /* ---------------------------------------------------------------------------
 896     */
 897    function getYYYYMMDDHHMMSS() {
 898      if ( $this->notime == 1) {
 899        return "------------";
 900      }
 901      return sprintf ("%04d%02d%02d%02d%02d%02d",$this->year,$this->month,$this->day,$this->hour,$this->min,$this->sec);
 902    }
 903    /* ---------------------------------------------------------------------------
 904     */
 905    function getLinkDateTime() {
 906      global $current_user;
 907  
 908      if ( $this->notime == 1) {
 909        return "------";
 910      }
 911      if ( $current_user->feature_ok(usecalendar,PERM_SEE) ) {
 912        return makelink("calendar.php?t=".$this->getYYYYMMDD(),$this->getDateTime(),$this->getDateTime());
 913      } else {
 914        return $this->getDateTime();
 915      }
 916    }
 917    /* ---------------------------------------------------------------------------
 918     */
 919    function getLinkDate() {
 920      global $current_user;
 921  
 922      if ( $this->notime == 1) {
 923        return "------";
 924      }
 925      if ( $current_user->feature_ok(usecalendar,PERM_SEE) ) {
 926        return makelink("calendar.php?t=".$this->getYYYYMMDD(),$this->getDate(),$this->getDate());
 927      } else {
 928        return $this->getDate();
 929      }
 930    }
 931    /**
 932     * Data of XML export
 933     */
 934    function exportXML_body () {
 935      return $this->getYYYYMMDDHHMMSS();
 936    }
 937    /**
 938     * add given number of days to this date
 939     */
 940    function addDays($val) {
 941      if ( $this->notime == 1) {
 942        return -1;
 943      }
 944  
 945      $ts = adodb_mktime($this->hour,$this->min,$this->sec,$this->month,$this->day + $val ,$this->year);
 946      $this->setDateTimeTS($ts);
 947    }
 948    /**
 949     * add given number of days to this date
 950     */
 951    function isWorkday(&$user) {
 952      if ( $this->notime == 1) {
 953        return 0;
 954      }
 955      $wd = Date("w",$this->ts);
 956      if ($user->isWorkDay($wd)) {
 957        return 1;
 958      }
 959      return 0;
 960    }
 961    /**
 962     * get a unix timestamp
 963     */
 964    function getTimestamp() {
 965      if ( $this->notime == 1) {
 966        return -1;
 967      }
 968      return adodb_mktime($this->hour,$this->min,$this->sec,$this->month,$this->day,$this->year);
 969    }
 970    /**
 971     * get DateTime formatted for ical
 972     */
 973    function getIcal() {
 974      if ( $this->notime == 1) {
 975        return "";
 976      }
 977      # contrib by Danilo Beuche <danilo at epost.de>
 978      # UH HU THIS IS A BAD HACK, BUT iCal Times have to be in UTC  
 979      $x = adodb_mktime($this->hour,$this->min,$this->sec,$this->month,$this->day,$this->year);
 980      $y = adodb_gmmktime($this->hour,$this->min,$this->sec,$this->month,$this->day,$this->year);
 981      $diff = $y - $x;
 982  
 983      return strftime("%Y%m%dT%H%M%SZ",$x - $diff);
 984  
 985  #    return sprintf ("%04d%02d%02dT%02d%02d%02dZ",$this->year,$this->month,$this->day,$this->hour,$this->min,$this->sec);
 986    }
 987  
 988    function lessthan( &$DateObj ) {
 989      return( $this->ts < $DateObj->ts );
 990    }
 991  
 992    /* Ala strcmp : returns <0, 0 or >0... */
 993    function datecmp( &$DateObj ) {
 994      return $this->ts - $DateObj->ts;
 995    }
 996  }
 997  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]