Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
calendar.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * File: calendar.php | (c) dynarch.com 2004
9  * Distributed as part of "The Coolest DHTML Calendar"
10  * under the same terms.
11  * -----------------------------------------------------------------
12  * This file implements a simple PHP wrapper for the calendar. It
13  * allows you to easily include all the calendar files and setup the
14  * calendar by instantiating and calling a PHP object.
15  * @package FDL
16  */
17 
18 define('NEWLINE', "\n");
19 
21 {
23 
29 
30  function DHTML_Calendar($calendar_lib_path = '/calendar/', $lang = 'en', $theme = 'calendar-win2k-1', $stripped = true)
31  {
32  if ($stripped) {
33  $this->calendar_file = 'calendar_stripped.js';
34  $this->calendar_setup_file = 'calendar-setup_stripped.js';
35  } else {
36  $this->calendar_file = 'calendar.js';
37  $this->calendar_setup_file = 'calendar-setup.js';
38  }
39  $this->calendar_lang_file = 'lang/calendar-' . $lang . '.js';
40  $this->calendar_theme_file = $theme . '.css';
41  $this->calendar_lib_path = preg_replace('/\/+$/', '/', $calendar_lib_path);
42  $this->calendar_options = array(
43  'ifFormat' => '%Y/%m/%d',
44  'daFormat' => '%Y/%m/%d'
45  );
46  }
47 
48  function set_option($name, $value)
49  {
50  $this->calendar_options[$name] = $value;
51  }
52 
53  function load_files()
54  {
55  echo $this->get_load_files_code();
56  }
57 
59  {
60  $code = ('<link rel="stylesheet" type="text/css" media="all" href="' . $this->calendar_lib_path . $this->calendar_theme_file . '" />' . NEWLINE);
61  $code.= ('<script type="text/javascript" src="' . $this->calendar_lib_path . $this->calendar_file . '"></script>' . NEWLINE);
62  $code.= ('<script type="text/javascript" src="' . $this->calendar_lib_path . $this->calendar_lang_file . '"></script>' . NEWLINE);
63  $code.= ('<script type="text/javascript" src="' . $this->calendar_lib_path . $this->calendar_setup_file . '"></script>');
64  return $code;
65  }
66 
67  function _make_calendar($other_options = array())
68  {
69  $js_options = $this->_make_js_hash(array_merge($this->calendar_options, $other_options));
70  $code = ('<script type="text/javascript">Calendar.setup({' . $js_options . '});</script>');
71  return $code;
72  }
73 
74  function make_input_field($cal_options = array() , $field_attributes = array())
75  {
76  $id = $this->_gen_id();
77  $attrstr = $this->_make_html_attr(array_merge($field_attributes, array(
78  'id' => $this->_field_id($id) ,
79  'type' => 'text'
80  )));
81  echo '<input ' . $attrstr . '/>';
82  echo '<a href="#" id="' . $this->_trigger_id($id) . '">' . '<img align="middle" border="0" src="' . $this->calendar_lib_path . 'img.gif" alt="" /></a>';
83 
84  $options = array_merge($cal_options, array(
85  'inputField' => $this->_field_id($id) ,
86  'button' => $this->_trigger_id($id)
87  ));
88  echo $this->_make_calendar($options);
89  }
90  /// PRIVATE SECTION
91  function _field_id($id)
92  {
93  return 'f-calendar-field-' . $id;
94  }
95  function _trigger_id($id)
96  {
97  return 'f-calendar-trigger-' . $id;
98  }
99  function _gen_id()
100  {
101  static $id = 0;
102  return ++$id;
103  }
104 
105  function _make_js_hash($array)
106  {
107  $jstr = '';
108  reset($array);
109  foreach ($array as $key => $val) {
110  if (is_bool($val)) $val = $val ? 'true' : 'false';
111  else if (!is_numeric($val)) $val = '"' . $val . '"';
112  if ($jstr) $jstr.= ',';
113  $jstr.= '"' . $key . '":' . $val;
114  }
115  return $jstr;
116  }
117 
118  function _make_html_attr($array)
119  {
120  $attrstr = '';
121  reset($array);
122  foreach ($array as $key => $val) {
123  $attrstr.= $key . '="' . $val . '" ';
124  }
125  return $attrstr;
126  }
127 };
128 ?>
_trigger_id($id)
Definition: calendar.php:95
_make_js_hash($array)
Definition: calendar.php:105
_make_html_attr($array)
Definition: calendar.php:118
$lang
Definition: lang.php:18
get_load_files_code()
Definition: calendar.php:58
_make_calendar($other_options=array())
Definition: calendar.php:67
make_input_field($cal_options=array(), $field_attributes=array())
Definition: calendar.php:74
const NEWLINE
Definition: calendar.php:18
DHTML_Calendar($calendar_lib_path= '/calendar/', $lang= 'en', $theme= 'calendar-win2k-1', $stripped=true)
Definition: calendar.php:30
set_option($name, $value)
Definition: calendar.php:48
$value
_field_id($id)
PRIVATE SECTION.
Definition: calendar.php:91
← centre documentaire © anakeen