[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_handlers/calendar/ -> calendar_class.php (source)

   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  
  12  define('NEWLINE', "\n");
  13  
  14  class DHTML_Calendar
  15  {
  16      var $calendar_file;
  17      var $calendar_lang_file;
  18      var $calendar_setup_file;
  19      var $calendar_theme_file;
  20      var $calendar_options;
  21      var $calendar_img;
  22  
  23  	function DHTML_Calendar($stripped = true)
  24      {
  25          if ($stripped)
  26          {
  27              $this->calendar_file = e_HANDLER.'calendar/calendar_stripped.js';
  28              $this->calendar_setup_file = e_HANDLER.'calendar/calendar-setup_stripped.js';
  29          }
  30          else
  31          {
  32              $this->calendar_file = e_HANDLER.'calendar/calendar.js';
  33              $this->calendar_setup_file = e_HANDLER.'calendar/calendar-setup.js';
  34          }
  35  
  36  
  37          if(file_exists(e_HANDLER.'calendar/language/'.e_LANGUAGE.'.js'))
  38          {
  39              $this->calendar_lang_file = e_HANDLER.'calendar/language/'.e_LANGUAGE.'.js';
  40          }
  41          else
  42          {
  43              $this->calendar_lang_file = e_HANDLER.'calendar/language/English.js';
  44          }
  45  
  46          if(defined('CALENDAR_IMG'))
  47          {
  48              $this->calendar_img = CALENDAR_IMG;
  49          }
  50          else
  51          {
  52              $this->calendar_img = "<img style='vertical-align:middle; border:0px' src='".e_HANDLER."calendar/cal.gif'  alt='' />";
  53          }
  54  
  55          if(file_exists(THEME."calendar.css"))
  56          {
  57              $this->calendar_theme_file = THEME."calendar.css";
  58          }
  59          else
  60          {
  61              $this->calendar_theme_file = e_HANDLER."calendar/calendar.css";
  62          }
  63  
  64          $this->calendar_options = array('ifFormat' => '%Y/%m/%d', 'daFormat' => '%Y/%m/%d');
  65      }
  66  
  67  	function set_option($name, $value) {
  68          $this->calendar_options[$name] = $value;
  69      }
  70  
  71  	function load_files() {
  72          return $this->get_load_files_code();
  73      }
  74  
  75  	function get_load_files_code() {
  76          $code  = ( '<link rel="stylesheet" type="text/css" media="all" href="' . $this->calendar_theme_file . '" />' . NEWLINE );
  77          $code .= ( '<script type="text/javascript" src="'.$this->calendar_file.'"></script>' . NEWLINE );
  78          $code .= ( '<script type="text/javascript" src="'.$this->calendar_setup_file.'"></script>' . NEWLINE );
  79          $code .= ( '<script type="text/javascript" src="'.$this->calendar_lang_file.'"></script>' . NEWLINE );
  80          return $code;
  81      }
  82  
  83  	function _make_calendar($other_options = array()) {
  84          $js_options = $this->_make_js_hash(array_merge($this->calendar_options, $other_options));
  85          $code  = ( '<script type="text/javascript">Calendar.setup({' . $js_options . '});</script>' );
  86          return $code;
  87      }
  88  
  89  	function make_input_field($cal_options = array(), $field_attributes = array())
  90      {
  91          $ret = "";
  92          $id = $this->_gen_id();
  93          $attrstr = $this->_make_html_attr(array_merge($field_attributes, array('id'   => $this->_field_id($id), 'type' => 'text')));
  94          $ret .= '<input ' . $attrstr .'/> ';
  95          $ret .= "<a href='#' id='".$this->_trigger_id($id)."'>".$this->calendar_img."</a>";
  96          $options = array_merge($cal_options, array('inputField' => $this->_field_id($id), 'button' => $this->_trigger_id($id)));
  97          $ret .= $this->_make_calendar($options);
  98          return $ret;
  99      }
 100  
 101      /// PRIVATE SECTION
 102  
 103  	function _field_id($id) { return 'f-calendar-field-' . $id; }
 104  	function _trigger_id($id) { return 'f-calendar-trigger-' . $id; }
 105  	function _gen_id() { static $id = 0; return ++$id; }
 106  
 107  	function _make_js_hash($array) {
 108          $jstr = '';
 109          reset($array);
 110          while (list($key, $val) = each($array))
 111          {
 112              if (is_bool($val))
 113              {
 114                  $val = $val ? 'true' : 'false';
 115              }
 116              elseif (!is_numeric($val))
 117              {
 118                  $val = '"'.$val.'"';
 119              }
 120              if ($jstr)
 121              {
 122                  $jstr .= ',';
 123              }
 124  
 125              $jstr .= '"' . $key . '":' . $val;
 126          }
 127          return $jstr;
 128      }
 129  
 130  	function _make_html_attr($array) {
 131          $attrstr = '';
 132          reset($array);
 133          while (list($key, $val) = each($array))
 134          {
 135              $attrstr .= $key . '="' . $val . '" ';
 136          }
 137          return $attrstr;
 138      }
 139  }
 140  
 141  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7