Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
js_calendar.inc
1 <?php
30 {
31 
36  var $settings = Array(
37  'cssURL' => null,
38  'imageURL' => null,
39  'fadeit' => true,
40  'scrollit' => false,
41  'onDayClick' => null,
42  'onWeekClick' => null,
43  'onYearClick' => null,
44  'height' => 200,
45  'width' => 200,
46  'day_name_length' => 2,
47  'week_start' => 1,
48  );
49 
50 
54  function JS_Calendar()
55  {
56  }//end constructor
57 
58 
67  function changeSetting($name, $value)
68  {
69  $this->settings[$name] = $value;
70 
71  }//end changeSetting()
72 
73 
84  function init()
85  {
86  if (!$this->isInit()) {
87  $css = array_get_index($this->settings,'cssURL',sq_web_path('fudge').'/js_calendar/js_calendar.css');
88  ?>
89  <!-- Start init of JS Calendar -->
90  <script src="<?php echo sq_web_path('fudge'); ?>/js_calendar/js_calendar.js" type="text/javascript"></script>
91  <script type="text/javascript">
92  addStyle('@import url("<?php echo $css; ?>");');
93  </script>
94  <!-- End init of JS Calendar -->
95  <?php
96  $GLOBALS['SQ_JS_CALENDAR_INIT'] = true;
97  }
98 
99  }//end init()
100 
101 
108  function isInit()
109  {
110  return (isset($GLOBALS['SQ_JS_CALENDAR_INIT']) && $GLOBALS['SQ_JS_CALENDAR_INIT'] === true);
111 
112  }//end isInit()
113 
114 
129  function paint($prefix, $container_name='', $popup=false, $container_exists=false)
130  {
131  $this->init();
132 
133  $this->settings['popup'] = $popup;
134  if (!isset($this->settings['imageURL']) || is_null($this->settings['imageURL'])) {
135  $this->settings['imageURL'] = sq_web_path('fudge').'/js_calendar/calendar.gif';
136  }
137 
138  if (empty($container_name)) {
139  $container_name = $prefix.'_js_calendar_span';
140  }
141 
142  $name_add_on = '';
143  if ($popup) {
144  if (array_get_index($GLOBALS, 'SQ_JS_CALENDAR_POPUP', false) === false) {
145  $GLOBALS['SQ_JS_CALENDAR_POPUP'] = $container_name;
146  ?><span id="<?php echo $container_name; ?>"></span><?php
147  } else {
148  $container_name = $GLOBALS['SQ_JS_CALENDAR_POPUP'];
149  }
150  } else {
151  if (array_get_index($GLOBALS, $container_name, false) === false) {
152  $GLOBALS[$container_name] = 1;
153  } else {
154  $GLOBALS[$container_name]++;
155  }
156  $name_add_on = ($GLOBALS[$container_name] == 1)?'':'_'.$GLOBALS[$container_name];
157  ?><span id="<?php echo $container_name.$name_add_on; ?>"></span><?php
158  }
159  if (!isset($this->settings['currentDate'])) {
160  $this->settings['currentDate'] = date('Y-m-d');
161  }
162 
163  list($year, $month, $day) = explode('-', $this->settings['currentDate']);
164  ?>
165  <script type="text/javascript">
166  //<![CDATA[
167  <?php echo $prefix; ?>_cal = new Calendar("<?php echo $prefix; ?>_cal", "<?php echo $container_name.$name_add_on; ?>", "<?php echo $this->settings['width'];?>","<?php echo $this->settings['height'];?>","<?php echo $year;?>","<?php echo $month;?>","<?php echo $day;?>");
168  <?php echo $prefix; ?>_cal.prefix = "<?php echo $prefix; ?>";
169  <?php
170  foreach ($this->settings as $name => $value) {
171  if (is_null($value) || $name == 'cssURL'){
172  continue;
173  }
174 
175  if (is_bool($value)) {
176  $value = ($value) ? 'true' : 'false';
177  } else if (!in_array($name, Array('onDayClick', 'onMonthClick', 'onYearClick', 'onWeekClick'))) {
178  $value = '"'.$value.'"';
179  }
180 
181  echo $prefix.'_cal.'.$name.' = '.$value.";\n";
182  }
183  ?>
184  <?php echo $prefix; ?>_cal.draw();
185  //]]>
186  </script>
187  <?php
188 
189  }//end paint()
190 
191 
192 }//end class
193 
194 ?>