4
* File: calendar.php | (c) dynarch.com 2004
5
* Distributed as part of "The Coolest DHTML Calendar"
6
* under the same terms.
7
* -----------------------------------------------------------------
8
* This file implements a simple PHP wrapper for the calendar. It
9
* allows you to easily include all the calendar files and setup the
10
* calendar by instantiating and calling a PHP object.
13
define('NEWLINE', "\n");
15
class DHTML_Calendar {
16
var $calendar_lib_path;
19
var $calendar_lang_file;
20
var $calendar_setup_file;
21
var $calendar_theme_file;
22
var $calendar_options;
24
function DHTML_Calendar($calendar_lib_path = '/calendar/',
26
$theme = 'calendar-win2k-1',
29
$this->calendar_file = 'calendar_stripped.js';
30
$this->calendar_setup_file = 'calendar-setup_stripped.js';
32
$this->calendar_file = 'calendar.js';
33
$this->calendar_setup_file = 'calendar-setup.js';
35
$this->calendar_lang_file = 'lang/calendar-' . $lang . '.js';
36
$this->calendar_theme_file = $theme.'.css';
37
$this->calendar_lib_path = preg_replace('/\/+$/', '/', $calendar_lib_path);
38
$this->calendar_options = array('ifFormat' => '%Y/%m/%d',
39
'daFormat' => '%Y/%m/%d');
42
function set_option($name, $value) {
43
$this->calendar_options[$name] = $value;
46
function load_files() {
47
echo $this->get_load_files_code();
50
function get_load_files_code() {
51
$code = ( '<link rel="stylesheet" type="text/css" media="all" href="' .
52
$this->calendar_lib_path . $this->calendar_theme_file .
54
$code .= ( '<script type="text/javascript" src="' .
55
$this->calendar_lib_path . $this->calendar_file .
56
'"></script>' . NEWLINE );
57
$code .= ( '<script type="text/javascript" src="' .
58
$this->calendar_lib_path . $this->calendar_lang_file .
59
'"></script>' . NEWLINE );
60
$code .= ( '<script type="text/javascript" src="' .
61
$this->calendar_lib_path . $this->calendar_setup_file .
66
function _make_calendar($other_options = array()) {
67
$js_options = $this->_make_js_hash(array_merge($this->calendar_options, $other_options));
68
$code = ( '<script type="text/javascript">Calendar.setup({' .
74
function make_input_field($cal_options = array(), $field_attributes = array()) {
75
$id = $this->_gen_id();
76
$attrstr = $this->_make_html_attr(array_merge($field_attributes,
77
array('id' => $this->_field_id($id),
79
echo '<input ' . $attrstr .'/>';
80
echo '<a href="#" id="'. $this->_trigger_id($id) . '">' .
81
'<img align="middle" border="0" src="' . $this->calendar_lib_path . 'img.gif" alt="" /></a>';
83
$options = array_merge($cal_options,
84
array('inputField' => $this->_field_id($id),
85
'button' => $this->_trigger_id($id)));
86
echo $this->_make_calendar($options);
91
function _field_id($id) { return 'f-calendar-field-' . $id; }
92
function _trigger_id($id) { return 'f-calendar-trigger-' . $id; }
93
function _gen_id() { static $id = 0; return ++$id; }
95
function _make_js_hash($array) {
98
while (list($key, $val) = each($array)) {
100
$val = $val ? 'true' : 'false';
101
else if (!is_numeric($val))
103
if ($jstr) $jstr .= ',';
104
$jstr .= '"' . $key . '":' . $val;
109
function _make_html_attr($array) {
112
while (list($key, $val) = each($array)) {
113
$attrstr .= $key . '="' . $val . '" ';
b'\\ No newline at end of file'