<?php

/**
 * @file
 * Include PHP 4 date handling files on systems where native date and
 * timezone handling won't work. This module will create the functions
 * date_create(), date_offset_get(), etc. that will work in PHP 4.
 *
 * This module is not needed on systems using PHP 5.2+ and won't be needed once
 * Drupal requires PHP 5.2.
 */

require_once('./'. drupal_get_path('module', 'date_php4') .'/date_php4.inc');

/**
 * Implementation of hook_perm().
 */
function date_php4_perm() {
  return array('administer date_php4 settings');
}

/**
 *  Implementation of hook_menu().
 */
function date_php4_menu() {
  $items = array();
  $items['admin/settings/date_php4'] = array(
    'title'    => 'Date PHP4',
    'description' => 'Date PHP4 setup.',
    'access arguments'   => array('administer date_php4 settings'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('date_php4_settings_form'),
    'type' => MENU_NORMAL_ITEM,
    'weight' => 6,
  );
  return $items;
}

/**
 *  Timezone handling.
 */
function date_php4_settings_form() {
  drupal_set_title(t('Date PHP4 Settings'));
  $form['date_use_server_zone'] = array(
    '#type' => 'select',
    '#options' => array(TRUE, t('TRUE'), FALSE => t('FALSE')),
    '#default_value' => variable_get('date_use_server_zone', FALSE),
    '#title' => t('Use PHP default timezone'),
    '#description' => t('Getting date computations working correctly in PHP versions earlier than PHP 5.2 involves extra computations that add a lot of overhead. These computations are needed because the timezone PHP uses on date computations may not match the site or user timezone or other date-specific timezones. We can speed processing up if we assume that PHP is using the correct timezone, but need to do more time-intensive processing if it is not. If timezone adjustments do not seem to be working correctly in your setup, you can set this option to FALSE to force the system to use the more accurate, but slower, timezone computations.'),
    );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    );
  return $form;
}

function date_php4_settings_form_submit($form, &$form_state) {
  variable_set('date_use_server_zone', $form_state['values']['date_use_server_zone']);
}
