PageRenderTime 80ms CodeModel.GetById 45ms RepoModel.GetById 1ms app.codeStats 0ms

/js/calendar/calendar.php

https://github.com/devbeans/VisionPOS
PHP | 124 lines | 97 code | 17 blank | 10 comment | 9 complexity | 7e9729aaac84857e88cd3154420a05e5 MD5 | raw file
  1. <?php
  2. /**
  3. * File: calendar.php | (c) dynarch.com 2004
  4. * Distributed as part of "The Coolest DHTML Calendar"
  5. * under the same terms.
  6. * -----------------------------------------------------------------
  7. * This file implements a simple PHP wrapper for the calendar. It
  8. * allows you to easily include all the calendar files and setup the
  9. * calendar by instantiating and calling a PHP object.
  10. */
  11. define('NEWLINE', "\n");
  12. class DHTML_Calendar {
  13. var $calendar_lib_path;
  14. var $calendar_file;
  15. var $calendar_lang_file;
  16. var $calendar_setup_file;
  17. var $calendar_theme_file;
  18. var $calendar_options;
  19. function DHTML_Calendar($calendar_lib_path = '/calendar/',
  20. $lang = 'en',
  21. $theme = 'calendar-win2k-1',
  22. $stripped = true) {
  23. if ($stripped) {
  24. $this->calendar_file = 'calendar_stripped.js';
  25. $this->calendar_setup_file = 'calendar-setup_stripped.js';
  26. } else {
  27. $this->calendar_file = 'calendar.js';
  28. $this->calendar_setup_file = 'calendar-setup.js';
  29. }
  30. $this->calendar_lang_file = 'lang/calendar-' . $lang . '.js';
  31. $this->calendar_theme_file = $theme.'.css';
  32. $this->calendar_lib_path = preg_replace('/\/+$/', '/', $calendar_lib_path);
  33. $this->calendar_options = array('ifFormat' => '%Y/%m/%d',
  34. 'daFormat' => '%Y/%m/%d');
  35. }
  36. function set_option($name, $value) {
  37. $this->calendar_options[$name] = $value;
  38. }
  39. function load_files() {
  40. echo $this->get_load_files_code();
  41. }
  42. function get_load_files_code() {
  43. $code = ( '<link rel="stylesheet" type="text/css" media="all" href="' .
  44. $this->calendar_lib_path . $this->calendar_theme_file .
  45. '" />' . NEWLINE );
  46. $code .= ( '<script type="text/javascript" src="' .
  47. $this->calendar_lib_path . $this->calendar_file .
  48. '"></script>' . NEWLINE );
  49. $code .= ( '<script type="text/javascript" src="' .
  50. $this->calendar_lib_path . $this->calendar_lang_file .
  51. '"></script>' . NEWLINE );
  52. $code .= ( '<script type="text/javascript" src="' .
  53. $this->calendar_lib_path . $this->calendar_setup_file .
  54. '"></script>' );
  55. return $code;
  56. }
  57. function _make_calendar($other_options = array()) {
  58. $js_options = $this->_make_js_hash(array_merge($this->calendar_options, $other_options));
  59. $code = ( '<script type="text/javascript">Calendar.setup({' .
  60. $js_options .
  61. '});</script>' );
  62. return $code;
  63. }
  64. function make_input_field($cal_options = array(), $field_attributes = array(), $output = true) {
  65. $result = "";
  66. $id = $this->_gen_id();
  67. $attrstr = $this->_make_html_attr(array_merge($field_attributes,
  68. array('id' => $this->_field_id($id),
  69. 'type' => 'text')));
  70. $result.= '<input ' . $attrstr .'/>';
  71. $result.= '<a href="#" id="'. $this->_trigger_id($id) . '">' .
  72. '<img align="middle" border="0" src="' . $this->calendar_lib_path . 'img.gif" alt="" /></a>';
  73. $options = array_merge($cal_options,
  74. array('inputField' => $this->_field_id($id),
  75. 'button' => $this->_trigger_id($id)));
  76. $result.= $this->_make_calendar($options);
  77. if ($output)
  78. echo $output;
  79. return $output;
  80. }
  81. /// PRIVATE SECTION
  82. function _field_id($id) { return 'f-calendar-field-' . $id; }
  83. function _trigger_id($id) { return 'f-calendar-trigger-' . $id; }
  84. function _gen_id() { static $id = 0; return ++$id; }
  85. function _make_js_hash($array) {
  86. $jstr = '';
  87. reset($array);
  88. while (list($key, $val) = each($array)) {
  89. if (is_bool($val))
  90. $val = $val ? 'true' : 'false';
  91. else if (!is_numeric($val))
  92. $val = '"'.$val.'"';
  93. if ($jstr) $jstr .= ',';
  94. $jstr .= '"' . $key . '":' . $val;
  95. }
  96. return $jstr;
  97. }
  98. function _make_html_attr($array) {
  99. $attrstr = '';
  100. reset($array);
  101. while (list($key, $val) = each($array)) {
  102. $attrstr .= $key . '="' . $val . '" ';
  103. }
  104. return $attrstr;
  105. }
  106. };
  107. ?>