private static function loadHolidaysSettings()
 {
     global $AppUI;
     if (is_null(self::$holiday_manual)) {
         // Query database for settings
         $q = new w2p_Database_Query();
         $q->addTable("holiday_settings");
         $q->addQuery("holiday_manual, holiday_auto, holiday_driver, holiday_filter");
         $settings = $q->loadHash();
         self::$holiday_manual = $settings['holiday_manual'];
         self::$holiday_auto = $settings['holiday_auto'];
         self::$holiday_driver = $settings['holiday_driver'];
         self::$holiday_filter = $settings['holiday_filter'];
     }
     if (self::$holiday_auto && self::$holiday_filter >= 0 && is_null(self::$holiday_filter_instance)) {
         $filters_alloc = Date_Holidays::getInstalledFilters();
         require_once dirname(__FILE__) . "/PEAR/Holidays/Filter/" . str_replace("_", "/", $filters_alloc[self::$holiday_filter]['title']) . ".php";
         $filterclass = "Date_Holidays_Filter_" . $filters_alloc[self::$holiday_filter]['title'];
         self::$holiday_filter_instance = new $filterclass();
     }
     if (self::$holiday_auto && self::$holiday_driver >= 0 && is_null(self::$holiday_driver_instance)) {
         $drivers_alloc = Date_Holidays::getInstalledDrivers();
         self::$holiday_driver_instance = Date_Holidays::factory($drivers_alloc[self::$holiday_driver]['title'], null, $AppUI->user_locale);
     }
 }
function isHoliday($date = 0)
{
    // Query database for settings
    $holiday_manual = db_loadResult('SELECT holiday_manual FROM holiday_settings');
    $holiday_auto = db_loadResult('SELECT holiday_auto FROM holiday_settings');
    $holiday_driver = db_loadResult('SELECT holiday_driver FROM holiday_settings');
    if (!$date) {
        $date = new CDate();
    }
    if ($holiday_manual) {
        // Check whether the date is blacklisted
        $sql = "SELECT * FROM holiday ";
        $sql .= "WHERE ( date(holiday_start_date) <= '";
        $sql .= $date->format('%Y-%m-%d');
        $sql .= "' AND date(holiday_end_date) >= '";
        $sql .= $date->format('%Y-%m-%d');
        $sql .= "' AND holiday_white=0 ) ";
        $sql .= "OR ( ";
        $sql .= " DATE_FORMAT(holiday_start_date, '%m-%d') <= '";
        $sql .= $date->format('%m-%d');
        $sql .= "' AND DATE_FORMAT(holiday_end_date, '%m-%d') >= '";
        $sql .= $date->format('%m-%d');
        $sql .= "' AND holiday_annual=1";
        $sql .= " AND holiday_white=0 ) ";
        if (db_loadResult($sql)) {
            return 0;
        }
        // Check if we have a whitelist item for this date
        $sql = "SELECT * FROM holiday ";
        $sql .= "WHERE ( date(holiday_start_date) <= '";
        $sql .= $date->format('%Y-%m-%d');
        $sql .= "' AND date(holiday_end_date) >= '";
        $sql .= $date->format('%Y-%m-%d');
        $sql .= "' AND holiday_white=1 ) ";
        $sql .= "OR ( ";
        $sql .= " DATE_FORMAT(holiday_start_date, '%m-%d') <= '";
        $sql .= $date->format('%m-%d');
        $sql .= "' AND DATE_FORMAT(holiday_end_date, '%m-%d') >= '";
        $sql .= $date->format('%m-%d');
        $sql .= "' AND holiday_annual=1";
        $sql .= " AND holiday_white=1 ) ";
        if (db_loadResult($sql)) {
            return 1;
        }
    }
    if ($holiday_auto) {
        // Still here? Ok, lets poll the automatic system
        $drivers_alloc = Date_Holidays::getInstalledDrivers();
        $driver_object = Date_Holidays::factory($drivers_alloc[$holiday_driver]['title'], $date->getYear(), 'en_EN');
        if (!Date_Holidays::isError($driver_object)) {
            if ($driver_object->getHolidayForDate($date)) {
                return 1;
            }
        }
    }
    // No hits, must be a working day
    return 0;
}
 /**
  * Factory method that creates a driver-object
  *
  * @param string  $isoCode  ISO3166 code identifying the driver
  * @param string  $year     year
  * @param string  $locale   locale name
  * @param boolean $external external driver
  *
  * @static
  * @access   public
  * @return   object  Date_Holidays driver-object on success, otherwise
  *                   a PEAR_Error object
  * @throws   object PEAR_Error
  */
 function factoryISO3166($isoCode, $year = null, $locale = null, $external = false)
 {
     $driverDir = dirname(__FILE__) . '/Holidays/Driver';
     if (!is_dir($driverDir)) {
         return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND, 'Date_Holidays driver directory does not exist');
     }
     $driverMappings = array();
     $driverFiles = array();
     $dh = opendir($driverDir);
     while (false !== ($filename = readdir($dh))) {
         array_push($driverFiles, $filename);
     }
     foreach ($driverFiles as $driverFileName) {
         $file = dirname(__FILE__) . '/Holidays/Driver/' . $driverFileName;
         if (!is_file($file)) {
             continue;
         }
         $driverId = str_replace('.php', '', $driverFileName);
         $driverClass = 'Date_Holidays_Driver_' . $driverId;
         $driverFilePath = $driverDir . '/' . $driverFileName;
         @(include_once $driverFilePath);
         if (!class_exists($driverClass)) {
             return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND, 'Couldn\'t find file of the driver-class ' . $driverClass . ',  filename: ' . $driverFilePath);
         }
         $isoCodes = call_user_func(array($driverClass, DATE_HOLIDAYS_DRIVER_IDENTIFY_ISO3166_METHOD));
         foreach ($isoCodes as $code) {
             if (strtolower($code) === $isoCode) {
                 return Date_Holidays::factory($driverId, $year, $locale, $external);
             }
         }
     }
     /*
      * If this line is reached the iso-code couldn't be mapped to
      * a driver-class and an error will be thrown.
      */
     return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND, 'Couldn\'t find a driver for the given ISO 3166 code: ' . $isoCode);
 }
Exemple #4
0
 /**
  * @throws Kronolith_Exception
  * @throws Horde_Exception_NotFound
  */
 public function getEvent($eventId = null)
 {
     if (!$eventId) {
         $date = new Date();
         return new Kronolith_Event_Holidays($this, new Date_Holidays_Holiday(null, null, $date, null));
     }
     list($id, $date) = explode('-', $eventId, 2);
     $year = substr($date, 0, 4);
     $dh = Date_Holidays::factory($this->calendar, $year, $this->_params['language']);
     if (Date_Holidays::isError($dh)) {
         Horde::log(sprintf('Factory was unable to produce driver object for driver %s in year %s with locale %s', $this->calendar, $year, $this->_params['language']), 'ERR');
         return false;
     }
     $dh->addTranslation($this->_params['language']);
     $event = $dh->getHoliday($id);
     if ($event instanceof PEAR_Error) {
         throw new Horde_Exception_NotFound($event);
     }
     return new Kronolith_Event_Holidays($this, $event);
 }