ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilCalendarUtil.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once './Services/Calendar/classes/class.ilCalendarSettings.php';
25 
34 {
35  private static $today = null;
36  private static $default_calendar = array();
37  static $init_done;
38  static protected $init_datetimepicker;
39 
46  public static function _isToday($date)
47  {
48  global $ilUser;
49 
50 
51  if(!is_object(self::$today))
52  {
53  self::$today = new ilDateTime(time(),IL_CAL_UNIX,$ilUser->getTimeZone());
54  }
55  return ilDateTime::_equals(self::$today,$date,IL_CAL_DAY,$ilUser->getTimeZone());
56  }
57 
67  public static function _numericMonthToString($a_month,$a_long = true)
68  {
69  global $lng;
70 
71  $month = $a_month < 10 ? '0'.$a_month : $a_month;
72 
73  return $a_long ? $lng->txt('month_'.$month.'_long') : $lng->txt('month_'.$month.'_short');
74  }
75 
85  public static function _numericDayToString($a_day,$a_long = true)
86  {
87  global $lng;
88 
89  $lng->loadLanguageModule('dateplaner');
90  static $days = array('Su','Mo','Tu','We','Th','Fr','Sa','Su');
91 
92  return $a_long ? $lng->txt($days[$a_day].'_long') : $lng->txt($days[$a_day].'_short');
93  }
94 
104  public static function _buildWeekDayList($a_day,$a_weekstart)
105  {
106  include_once('Services/Calendar/classes/class.ilDateList.php');
107  $day_list = new ilDateList(ilDateList::TYPE_DATE);
108 
109  $start = clone $a_day;
110  $start_info = $start->get(IL_CAL_FKT_GETDATE,'','UTC');
111  $day_diff = $a_weekstart - $start_info['isoday'];
112  if($day_diff == 7)
113  {
114  $day_diff = 0;
115  }
116  $start->increment(IL_CAL_DAY,$day_diff);
117  $day_list->add($start);
118  for($i = 1; $i < 7;$i++)
119  {
120  $start->increment(IL_CAL_DAY,1);
121  $day_list->add($start);
122  }
123  return $day_list;
124  }
125 
136  public static function _buildMonthDayList($a_month,$a_year,$weekstart)
137  {
138  include_once('Services/Calendar/classes/class.ilDateList.php');
139  $day_list = new ilDateList(ilDateList::TYPE_DATE);
140 
141  $prev_month = ($a_month == 1) ? 12 : $a_month - 1;
142  $prev_year = ($prev_month == 12) ? $a_year - 1 : $a_year;
143  $next_month = $a_month == 12 ? 1 : $a_month + 1;
144  $next_year = $a_month == 12 ? $a_year + 1 : $a_year;
145 
146  $days_in_month = self::_getMaxDayOfMonth($a_year,$a_month);
147  $days_in_prev_month = self::_getMaxDayOfMonth($a_year,$prev_month);
148 
149  $week_day['year'] = $a_year;
150  $week_day['mon'] = $a_month;
151  $week_day['mday'] = 1;
152  $week_day['hours'] = 0;
153  $week_day['minutes'] = 0;
154  $week_day = new ilDate($week_day,IL_CAL_FKT_GETDATE);
155 
156  $weekday = $week_day->get(IL_CAL_FKT_DATE,'w');
157  $first_day_offset = (($weekday - $weekstart) < 0) ? 6 : $weekday - $weekstart;
158 
159 
160  for($i = 0;$i < 42;$i++)
161  {
162 
163  if($i < $first_day_offset)
164  {
165  $day = $days_in_prev_month - $first_day_offset + $i + 1;
166 
167  $day_list->add(new ilDate(gmmktime(0,0,0,$prev_month,
168  $days_in_prev_month - $first_day_offset + $i + 1,
169  $prev_year),
170  IL_CAL_UNIX));
171  }
172  elseif($i < $days_in_month + $first_day_offset)
173  {
174  $day = $i - $first_day_offset + 1;
175 
176 
177  $day_list->add(new ilDate(gmmktime(0,0,0,$a_month,
178  $i - $first_day_offset + 1,
179  $a_year),
180  IL_CAL_UNIX));
181  }
182  else
183  {
184  $day = $i - $days_in_month - $first_day_offset + 1;
185  $day_list->add(new ilDate(gmmktime(0,0,0,$next_month,
186  $i - $days_in_month - $first_day_offset + 1,
187  $next_year),
188  IL_CAL_UNIX));
189  }
190  if($i == 34 and ($day < 15 or $day == $days_in_month))
191  {
192  break;
193  }
194  }
195  return $day_list;
196  }
197 
201  static function initJSCalendar()
202  {
203  global $tpl, $lng;
204 
205  if (self::$init_done == "done")
206  {
207  return;
208  }
209 
210  $lng->loadLanguageModule("jscalendar");
211  $tpl->addBlockFile("CALENDAR_LANG_JAVASCRIPT", "calendar_javascript", "tpl.calendar.html",
212  "Services/Calendar");
213  $tpl->setCurrentBlock("calendar_javascript");
214  $tpl->setVariable("FULL_SUNDAY", $lng->txt("l_su"));
215  $tpl->setVariable("FULL_MONDAY", $lng->txt("l_mo"));
216  $tpl->setVariable("FULL_TUESDAY", $lng->txt("l_tu"));
217  $tpl->setVariable("FULL_WEDNESDAY", $lng->txt("l_we"));
218  $tpl->setVariable("FULL_THURSDAY", $lng->txt("l_th"));
219  $tpl->setVariable("FULL_FRIDAY", $lng->txt("l_fr"));
220  $tpl->setVariable("FULL_SATURDAY", $lng->txt("l_sa"));
221  $tpl->setVariable("SHORT_SUNDAY", $lng->txt("s_su"));
222  $tpl->setVariable("SHORT_MONDAY", $lng->txt("s_mo"));
223  $tpl->setVariable("SHORT_TUESDAY", $lng->txt("s_tu"));
224  $tpl->setVariable("SHORT_WEDNESDAY", $lng->txt("s_we"));
225  $tpl->setVariable("SHORT_THURSDAY", $lng->txt("s_th"));
226  $tpl->setVariable("SHORT_FRIDAY", $lng->txt("s_fr"));
227  $tpl->setVariable("SHORT_SATURDAY", $lng->txt("s_sa"));
228  $tpl->setVariable("FULL_JANUARY", $lng->txt("l_01"));
229  $tpl->setVariable("FULL_FEBRUARY", $lng->txt("l_02"));
230  $tpl->setVariable("FULL_MARCH", $lng->txt("l_03"));
231  $tpl->setVariable("FULL_APRIL", $lng->txt("l_04"));
232  $tpl->setVariable("FULL_MAY", $lng->txt("l_05"));
233  $tpl->setVariable("FULL_JUNE", $lng->txt("l_06"));
234  $tpl->setVariable("FULL_JULY", $lng->txt("l_07"));
235  $tpl->setVariable("FULL_AUGUST", $lng->txt("l_08"));
236  $tpl->setVariable("FULL_SEPTEMBER", $lng->txt("l_09"));
237  $tpl->setVariable("FULL_OCTOBER", $lng->txt("l_10"));
238  $tpl->setVariable("FULL_NOVEMBER", $lng->txt("l_11"));
239  $tpl->setVariable("FULL_DECEMBER", $lng->txt("l_12"));
240  $tpl->setVariable("SHORT_JANUARY", $lng->txt("s_01"));
241  $tpl->setVariable("SHORT_FEBRUARY", $lng->txt("s_02"));
242  $tpl->setVariable("SHORT_MARCH", $lng->txt("s_03"));
243  $tpl->setVariable("SHORT_APRIL", $lng->txt("s_04"));
244  $tpl->setVariable("SHORT_MAY", $lng->txt("s_05"));
245  $tpl->setVariable("SHORT_JUNE", $lng->txt("s_06"));
246  $tpl->setVariable("SHORT_JULY", $lng->txt("s_07"));
247  $tpl->setVariable("SHORT_AUGUST", $lng->txt("s_08"));
248  $tpl->setVariable("SHORT_SEPTEMBER", $lng->txt("s_09"));
249  $tpl->setVariable("SHORT_OCTOBER", $lng->txt("s_10"));
250  $tpl->setVariable("SHORT_NOVEMBER", $lng->txt("s_11"));
251  $tpl->setVariable("SHORT_DECEMBER", $lng->txt("s_12"));
252  $tpl->setVariable("ABOUT_CALENDAR", $lng->txt("about_calendar"));
253  $tpl->setVariable("ABOUT_CALENDAR_LONG", $lng->txt("about_calendar_long"));
254  $tpl->setVariable("ABOUT_TIME_LONG", $lng->txt("about_time"));
255  $tpl->setVariable("PREV_YEAR", $lng->txt("prev_year"));
256  $tpl->setVariable("PREV_MONTH", $lng->txt("prev_month"));
257  $tpl->setVariable("GO_TODAY", $lng->txt("go_today"));
258  $tpl->setVariable("NEXT_MONTH", $lng->txt("next_month"));
259  $tpl->setVariable("NEXT_YEAR", $lng->txt("next_year"));
260  $tpl->setVariable("SEL_DATE", $lng->txt("select_date"));
261  $tpl->setVariable("DRAG_TO_MOVE", $lng->txt("drag_to_move"));
262  $tpl->setVariable("PART_TODAY", $lng->txt("part_today"));
263  $tpl->setVariable("DAY_FIRST", $lng->txt("day_first"));
264  $tpl->setVariable("CLOSE", $lng->txt("close"));
265  $tpl->setVariable("TODAY", $lng->txt("today"));
266  $tpl->setVariable("TIME_PART", $lng->txt("time_part"));
267  $tpl->setVariable("DEF_DATE_FORMAT", $lng->txt("def_date_format"));
268  $tpl->setVariable("TT_DATE_FORMAT", $lng->txt("tt_date_format"));
269  $tpl->setVariable("WK", $lng->txt("wk"));
270  $tpl->setVariable("TIME", $lng->txt("time"));
271  $tpl->parseCurrentBlock();
272  $tpl->setCurrentBlock("CalendarJS");
273  $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR", "./Services/Calendar/js/calendar.js");
274  $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_SETUP", "./Services/Calendar/js/calendar-setup.js");
275  $tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_STYLESHEET", "./Services/Calendar/css/calendar.css");
276  $tpl->parseCurrentBlock();
277 
278  self::$init_done = "done";
279  }
280 
281  public static function getZoneInfoFile($a_tz)
282  {
283  if(!array_key_exists($a_tz, self::_getShortTimeZoneList()))
284  {
285  return '';
286  }
287  $timezone_filename = str_replace('/', '_', $a_tz);
288  $timezone_filename .= '.ics';
289  return './Services/Calendar/zoneinfo/'.$timezone_filename;
290  }
291 
292 
301  public static function _getShortTimeZoneList()
302  {
303  return array(
304  'Pacific/Samoa' => 'GMT-11: Midway Islands, Samoa',
305  'US/Hawaii' => 'GMT-10:00: Hawaii, Polynesia',
306  'US/Alaska' => 'GMT-9:00: Alaska',
307  'America/Los_Angeles' => 'GMT-8:00: Tijuana, Los Angeles, Seattle, Vancouver',
308  'US/Arizona' => 'GMT-7:00: Arizona',
309  'America/Chihuahua' => 'GMT-7:00: Chihuahua, La Paz, Mazatlan',
310  'America/Denver' => 'GMT-7:00: Arizona, Denver, Salt Lake City, Calgary',
311  'America/Chicago' => 'GMT-6:00: Chicago, Dallas, Kansas City, Winnipeg',
312  'America/Monterrey' => 'GMT-6:00: Guadalajara, Mexico City, Monterrey',
313  'Canada/Saskatchewan' => 'GMT-6:00: Saskatchewan',
314  'US/Central' => 'GMT-6:00: Central America',
315  'America/Bogota' => 'GMT-5:00: Bogota, Lima, Quito',
316  'US/East-Indiana' => 'GMT-5:00: East-Indiana',
317  'America/New_York' => 'GMT-5:00: New York, Miami, Atlanta, Detroit, Toronto',
318  'Canada/Atlantic' => 'GMT-4:00: Atlantic (Canada)',
319  'America/La_Paz' => 'GMT-4:00: Carcas, La Paz',
320  'America/Santiago' => 'GMT-4:00: Santiago',
321  'Canada/Newfoundland' => 'GMT-3:00: Newfoundland',
322  'Brazil/East' => 'GMT-3:00: Sao Paulo',
323  'America/Argentina/Buenos_Aires' => 'GMT-3:00: Buenes Aires, Georgtown',
324  'Etc/GMT+3' => 'GMT-3:00: Greenland, Uruguay, Surinam',
325  'Atlantic/Cape_Verde' => 'GMT-2:00: Cape Verde, Greenland, South Georgia',
326  'Atlantic/Azores' => 'GMT-1:00: Azores',
327  'Africa/Casablanca' => 'GMT+0:00: Casablanca, Monrovia',
328  'Europe/London' => 'GMT+0:00: Dublin, Edinburgh, Lisbon, London',
329  'Europe/Berlin' => 'GMT+1:00: Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
330  'Europe/Belgrade' => 'GMT+1:00: Belgrade, Bratislava, Budapest, Ljubljana, Prague',
331  'Europe/Paris' => 'GMT+1:00: Brussels, Copenhagen, Paris, Madrid',
332  'Europe/Sarajevo' => 'GMT+1:00: Sarajevo, Skopje, Warsaw, Zagreb',
333  'Africa/Lagos' => 'GMT+1:00: West-Central Africa',
334  'Europe/Athens' => 'GMT+2:00: Athens, Beirut, Istanbul, Minsk',
335  'Europe/Bucharest' => 'GMT+2:00: Bucharest',
336  'Africa/Harare' => 'GMT+2:00: Harare, Pratoria',
337  'Europe/Helsinki' => 'GMT+2:00: Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius',
338  'Asia/Jerusalem' => 'GMT+2:00: Jerusalem',
339  'Africa/Cairo' => 'GMT+2:00: Cairo',
340  'Asia/Baghdad' => 'GMT+3:00: Baghdad',
341  'Asia/Kuwait' => 'GMT+3:00: Kuwait, Riyadh',
342  'Europe/Moscow' => 'GMT+3:00: Moscow, Saint Petersburg',
343  'Africa/Nairobi' => 'GMT+3:00: Nairobi',
344  'Asia/Tehran' => 'GMT+3:30: Tehran',
345  'Asia/Muscat' => 'GMT+4:00: Abu Dhabi, Muscat',
346  'Asia/Baku' => 'GMT+4:00: Baku, Tbilisi, Erivan',
347  'Asia/Kabul' => 'GMT+4:00: Kabul',
348  'Asia/Karachi' => 'GMT+5:00: Islamabad, Karachi, Taschkent',
349  'Asia/Yekaterinburg' => 'GMT+5:00: Yekaterinburg',
350  'Asia/Calcutta' => 'GMT+5:30: New Dehli',
351  'Asia/Katmandu' => 'GMT+5:45: Katmandu',
352  'Asia/Novosibirsk' => 'GMT+6:00: Almaty, Novosibirsk',
353  'Asia/Dhaka' => 'GMT+6:00: Astana, Dhaka',
354  'Asia/Rangoon' => 'GMT+6:00: Sri Jayawardenepura, Rangoon',
355  'Asia/Jakarta' => 'GMT+7:00: Bangkok, Hanoi, Jakarta',
356  'Asia/Krasnoyarsk' => 'GMT+7:00: Krasnoyarsk',
357  'Asia/Irkutsk' => 'GMT+8:00: Irkutsk, Ulan Bator',
358  'Asia/Singapore' => 'GMT+8:00: Kuala Lumpour, Singapore',
359  'Asia/Hong_Kong' => 'GMT+8:00: Beijing, Chongqing, Hong kong, Urumchi',
360  'Australia/Perth' => 'GMT+8:00: Perth',
361  'Asia/Taipei' => 'GMT+8:00: Taipei',
362  'Asia/Yakutsk' => 'GMT+9:00: Yakutsk',
363  'Asia/Tokyo' => 'GMT+9:00: Osaka, Sapporo, Tokyo',
364  'Asia/Seoul' => 'GMT+9:00: Seoul, Darwin, Adelaide',
365  'Australia/Brisbane' => 'GMT+10:00: Brisbane',
366  'Australia/Sydney' => 'GMT+10:00: Canberra, Melbourne, Sydney',
367  'Pacific/Guam' => 'GMT+10:00: Guam, Port Moresby',
368  'Australia/Hobart' => 'GMT+10:00: Hobart',
369  'Asia/Vladivostok' => 'GMT+10:00: Vladivostok',
370  'Asia/Magadan' => 'GMT+11:00: Salomon Islands, New Caledonia, Magadan',
371  'Pacific/Auckland' => 'GMT+12:00: Auckland, Wellington',
372  'Pacific/Fiji' => 'GMT+12:00: Fiji, Kamchatka, Marshall-Islands');
373  }
374 
375 
383  public static function _isLeapYear($a_year)
384  {
385  $is_leap = false;
386 
387  if($a_year % 4 == 0)
388  {
389  $is_leap = true;
390  if($a_year % 100 == 0)
391  {
392  $is_leap = false;
393  if($a_year % 400)
394  {
395  return true;
396  }
397  }
398  }
399  return $is_leap;
400  }
401 
411  public static function _getMaxDayOfMonth($a_year,$a_month)
412  {
413  if(@function_exists('cal_days_in_month'))
414  {
415  return cal_days_in_month(CAL_GREGORIAN,$a_month,$a_year);
416  }
417  $months = array(0,31,
418  self::_isLeapYear($a_year) ? 29 : 28,
419  31,30,31,30,31,31,30,31,30,31);
420  return $months[(int) $a_month];
421  }
422 
431  public static function calculateFontColor($a_html_color_code)
432  {
433  if(strpos($a_html_color_code,'#') !== 0 or strlen($a_html_color_code) != 7)
434  {
435  return '#000000';
436  }
437 
438  // http://en.wikipedia.org/wiki/Luminance_(relative)
439  $lum = round(hexdec(substr($a_html_color_code, 1, 2))*0.2126+
440  hexdec(substr($a_html_color_code, 3, 2))*0.7152+
441  hexdec(substr($a_html_color_code, 5, 2))*0.0722);
442 
443  return ($lum <= 128) ? "#FFFFFF" : "#000000";
444 
445  /*
446  $hex = str_replace('#','0x',$a_html_color_code);
447  return hexdec($hex) > 8000000 ? '#000000' : '#FFFFFF';
448  */
449  }
450 
456  public static function getHourSelection($a_format)
457  {
458  switch($a_format)
459  {
461  for($i = 0; $i < 24; $i++)
462  {
463  $options[$i] = sprintf('%02d:00',$i);
464  }
465  break;
466 
468  for($i = 0; $i < 24; $i++)
469  {
470  $options[$i] = date('h a',mktime($i,0,0,1,1,2000));
471  }
472  break;
473  }
474  return $options ? $options : array();
475 
476  }
477 
486  public static function initDefaultCalendarByType($a_type_id, $a_usr_id, $a_title, $a_create = false)
487  {
488  global $ilDB;
489 
490  if(isset(self::$default_calendar[$a_usr_id]) and isset(self::$default_calendar[$a_usr_id][$a_type_id]))
491  {
492  return self::$default_calendar[$a_usr_id][$a_type_id];
493  }
494 
495  include_once './Services/Calendar/classes/class.ilCalendarCategory.php';
496 
497  $query = "SELECT cat_id FROM cal_categories ".
498  "WHERE obj_id = ".$ilDB->quote($a_usr_id,'integer')." ".
499  "AND type = ".$ilDB->quote($a_type_id,'integer');
500  $res = $ilDB->query($query);
501  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
502  {
503  return self::$default_calendar[$a_usr_id][$a_type_id] = new ilCalendarCategory($row->cat_id);
504  }
505 
506  if(!$a_create)
507  {
508  return null;
509  }
510 
511  // Create default calendar
512  self::$default_calendar[$a_usr_id][$a_type_id] = new ilCalendarCategory();
513  self::$default_calendar[$a_usr_id][$a_type_id]->setType($a_type_id);
514  self::$default_calendar[$a_usr_id][$a_type_id]->setColor(ilCalendarCategory::DEFAULT_COLOR);
515  self::$default_calendar[$a_usr_id][$a_type_id]->setTitle($a_title);
516  self::$default_calendar[$a_usr_id][$a_type_id]->setObjId($a_usr_id);
517  self::$default_calendar[$a_usr_id][$a_type_id]->add();
518 
519  return self::$default_calendar[$a_usr_id][$a_type_id];
520  }
521 
522 
523  //
524  // BOOTSTRAP DATEPICKER
525  //
526 
534  public static function getUserDateFormat($a_add_time = false, $a_for_parsing = false)
535  {
536  global $ilUser;
537 
538  // getDateFormat() should return calendar defaults for ANONYMOUS user
539  switch($ilUser->getDateFormat())
540  {
542  $format = "DD.MM.YYYY";
543  break;
544 
546  $format = "YYYY-MM-DD";
547  break;
548 
550  $format = "MM/DD/YYYY";
551  break;
552  }
553  if($a_add_time)
554  {
555  $format .= " ".(($ilUser->getTimeFormat() == ilCalendarSettings::TIME_FORMAT_24)
556  ? "HH:mm"
557  : "hh:mma");
558  if($a_add_time == 2)
559  {
560  $format .= ":ss";
561  }
562  }
563 
564  // translate datepicker format to PHP format
565  if((bool)$a_for_parsing)
566  {
567  $format = str_replace("DD", "d", $format);
568  $format = str_replace("MM", "m", $format);
569  $format = str_replace("mm", "i", $format);
570  $format = str_replace("YYYY", "Y", $format);
571  $format = str_replace("HH", "H", $format);
572  $format = str_replace("hh", "h", $format);
573  }
574 
575  return $format;
576  }
577 
578  public static function initDateTimePicker()
579  {
580  global $tpl;
581 
582  if(!self::$init_datetimepicker)
583  {
584  $tpl->addJavaScript("./libs/composer/vendor/moment/moment/min/moment-with-locales.min.js");
585 
586  // unminified version does not work with jQuery 3.0
587  // https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1684
588  $tpl->addJavaScript("./Services/Calendar/lib/bootstrap3_datepicker/bootstrap-datetimepicker.min.js");
589 
590  $tpl->addJavaScript("Services/Form/js/Form.js"); // see ilPropertyFormGUI
591 
592  self::$init_datetimepicker = true;
593  }
594  }
595 
608  public static function addDateTimePicker($a_id, $a_add_time = null, array $a_custom_config = null, $a_id2 = null, $a_custom_config2 = null, $a_toggle_id = null, $a_subform_id = null)
609  {
610  global $tpl, $ilUser;
611 
612  self::initDateTimePicker();
613 
614  // weekStart is currently governed by locale and cannot be changed
615 
616  // fix for mantis 22994 => default to english language
617  $language = 'en';
618  if($ilUser->getLanguage() != 'ar')
619  {
620  $language = $ilUser->getLanguage();
621  }
622  $default = array(
623  'locale' => $language
624  ,'stepping' => 5
625  ,'useCurrent' => false
626  ,'calendarWeeks' => true
627  ,'toolbarPlacement' => 'top'
628  // ,'showTodayButton' => true
629  ,'showClear' => true
630  // ,'showClose' => true
631  ,'keepInvalid' => true
632  ,'sideBySide' => true
633  // ,'collapse' => false
634  ,'format' => self::getUserDateFormat($a_add_time)
635  );
636 
637  $config = (!$a_custom_config)
638  ? $default
639  : array_merge($default, $a_custom_config);
640 
641  $tpl->addOnLoadCode('$("#'.$a_id.'").datetimepicker('.json_encode($config).')');
642 
643 
644  // optional 2nd picker aka duration
645  if($a_id2)
646  {
647  $config2 = (!$a_custom_config2)
648  ? $default
649  : array_merge($default, $a_custom_config2);
650 
651  $config2["useCurrent"] = false; //Important! See issue #1075
652 
653  $tpl->addOnLoadCode('$("#'.$a_id2.'").datetimepicker('.json_encode($config2).')');
654 
655  // duration limits, diff and subform handling
656  $tpl->addOnLoadCode('il.Form.initDateDurationPicker("'.$a_id.'","'.$a_id2.'","'.$a_toggle_id.'","'.$a_subform_id.'");');
657  }
658  else if($a_subform_id)
659  {
660  // subform handling
661  $tpl->addOnLoadCode('il.Form.initDatePicker("'.$a_id.'","'.$a_subform_id.'");');
662  }
663  }
664 
671  public static function parseDateString($a_date, $a_add_time = null, $a_use_generic_format = false)
672  {
673  global $ilUser;
674 
675  if(!$a_use_generic_format)
676  {
677  $out_format = self::getUserDateFormat($a_add_time, true);
678  }
679  else
680  {
681  $out_format = $a_add_time
682  ? "Y-m-d H:i:s"
683  : "Y-m-d";
684  }
685  $tmp = date_parse_from_format($out_format, $a_date);
686 
687  $date = null;
688 
689  if(!$tmp["error_count"] &&
690  !$tmp["warning_count"])
691  {
692  $format = $tmp["year"]."-".
693  str_pad($tmp["month"], 2, "0", STR_PAD_LEFT)."-".
694  str_pad($tmp["day"], 2, "0", STR_PAD_LEFT);
695 
696  if($a_add_time)
697  {
698  $format .= " ".
699  str_pad($tmp["hour"], 2, "0", STR_PAD_LEFT).":".
700  str_pad($tmp["minute"], 2, "0", STR_PAD_LEFT).":".
701  str_pad($tmp["second"], 2, "0", STR_PAD_LEFT);
702 
703  $date = new ilDateTime($format, IL_CAL_DATETIME, $ilUser->getTimeZone());
704  }
705  else
706  {
707  $date = new ilDate($format, IL_CAL_DATE);
708  }
709  }
710 
711  return array(
712  "date" => $date
713  , "warnings" => sizeof($tmp["warnings"])
714  ? $tmp["warnings"]
715  : null
716  , "errors" => sizeof($tmp["errors"])
717  ? $tmp["errors"]
718  : null
719  );
720  }
721 
729  public static function parseIncomingDate($a_value, $a_add_time = null)
730  {
731  // already datetime object?
732  if(is_object($a_value) &&
733  $a_value instanceof ilDateTime)
734  {
735  return $a_value;
736  }
737  else if(trim($a_value))
738  {
739  // try user-specific format
740  $parsed = self::parseDateString($a_value, $a_add_time);
741  if(is_object($parsed["date"]))
742  {
743  return $parsed["date"];
744  }
745  else
746  {
747  // try generic format
748  $parsed = self::parseDateString($a_value, $a_add_time, true);
749  if(is_object($parsed["date"]))
750  {
751  return $parsed["date"];
752  }
753  }
754  }
755  }
756 }
757 ?>
static _buildMonthDayList($a_month, $a_year, $weekstart)
Build a month day list.
const IL_CAL_DATETIME
static _numericDayToString($a_day, $a_long=true)
get
static getHourSelection($a_format)
Get hour selectio depending on user specific hour format.
static _isLeapYear($a_year)
check if a given year is a leap year
static getZoneInfoFile($a_tz)
Stores calendar categories.
static _buildWeekDayList($a_day, $a_weekstart)
build week day list
const IL_CAL_UNIX
static _getShortTimeZoneList()
get short timezone list
static _numericMonthToString($a_month, $a_long=true)
numeric month to string
static _getMaxDayOfMonth($a_year, $a_month)
get max day of month 2008,2 => 29
global $tpl
Definition: ilias.php:8
const IL_CAL_DAY
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
Class for single dates.
if(!is_array($argv)) $options
static getUserDateFormat($a_add_time=false, $a_for_parsing=false)
Parse current user setting into date/time format.
static addDateTimePicker($a_id, $a_add_time=null, array $a_custom_config=null, $a_id2=null, $a_custom_config2=null, $a_toggle_id=null, $a_subform_id=null)
Add date time picker to element.
List of dates.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
const IL_CAL_FKT_DATE
Date and time handling
$ilUser
Definition: imgupload.php:18
static calculateFontColor($a_html_color_code)
Calculate best font color from html hex color code.
Create styles array
The data for the language used.
const IL_CAL_FKT_GETDATE
const IL_CAL_DATE
static parseDateString($a_date, $a_add_time=null, $a_use_generic_format=false)
Parse (incoming) string to date/time object.
global $lng
Definition: privfeed.php:17
global $ilDB
static initDefaultCalendarByType($a_type_id, $a_usr_id, $a_title, $a_create=false)
Init the default calendar for given type and user.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static initJSCalendar()
Init Javascript Calendar.
Class ilCalendarUtil.
static _isToday($date)
check if a date is today
static parseIncomingDate($a_value, $a_add_time=null)
Try to parse incoming value to date object.