ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDateDurationInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
14  protected $start = null;
15  protected $start_year = null;
16 
17  protected $start_text = '';
18  protected $end_text = '';
19 
20  protected $minute_step_size = 5;
21  protected $end = null;
22 
26  protected $activation_title = '';
27  protected $activation_post_var = '';
28  protected $activation_checked = true;
29 
33  protected $toggle_fulltime = false;
34  protected $toggle_fulltime_txt = '';
35  protected $toggle_fulltime_checked = false;
36 
37  protected $show_date = true;
38  protected $show_empty = false;
39  protected $show_time = true;
40 
47  public function __construct($a_title = "", $a_postvar = "")
48  {
49  parent::__construct($a_title, $a_postvar);
50  $this->setType("dateduration");
51  }
52 
63  public function enableDateActivation($a_title,$a_postvar,$a_checked = true)
64  {
65  $this->activation_title = $a_title;
66  $this->activation_post_var = $a_postvar;
67  $this->activation_checked = $a_checked;
68  }
69 
76  public function enableToggleFullTime($a_title,$a_checked)
77  {
78  $this->toggle_fulltime_txt = $a_title;
79  $this->toggle_fulltime_checked = $a_checked;
80  $this->toggle_fulltime = true;
81  }
82 
87  public function enabledToggleFullTime()
88  {
90  }
91 
98  public function getActivationPostVar()
99  {
101  }
102 
114  public function setStart(ilDateTime $a_date)
115  {
116  $this->start = $a_date;
117  }
118 
124  public function setStartText($a_txt)
125  {
126  $this->start_text = $a_txt;
127  }
128 
133  public function getStartText()
134  {
135  return $this->start_text;
136  }
137 
143  public function setEndText($a_txt)
144  {
145  $this->end_text = $a_txt;
146  }
147 
152  public function getEndText()
153  {
154  return $this->end_text;
155  }
156 
162  public function getStart()
163  {
164  return $this->start;
165  }
166 
178  public function setEnd(ilDateTime $a_date)
179  {
180  $this->end = $a_date;
181  }
182 
188  public function getEnd()
189  {
190  return $this->end;
191  }
192 
198  public function setShowDate($a_showdate)
199  {
200  $this->showdate = $a_showdate;
201  }
202 
208  public function getShowDate()
209  {
210  return $this->showdate;
211  }
212 
218  function setShowEmpty($a_empty)
219  {
220  $this->show_empty = $a_empty;
221  }
222 
228  function getShowEmpty()
229  {
230  return $this->show_empty;
231  }
232 
233 
239  public function setShowTime($a_showtime)
240  {
241  $this->showtime = $a_showtime;
242  }
243 
249  public function getShowTime()
250  {
251  return $this->showtime;
252  }
253 
258  public function getShowSeconds()
259  {
260  return false;
261  }
262 
268  public function setStartYear($a_year)
269  {
270  $this->startyear = $a_year;
271  }
272 
278  public function getStartYear()
279  {
280  return $this->startyear;
281  }
282 
291  public function setMinuteStepSize($a_step_size)
292  {
293  $this->minute_step_size = $a_step_size;
294  }
295 
302  public function getMinuteStepSize()
303  {
305  }
306 
312  public function setValueByArray($a_values)
313  {
314  global $ilUser;
315 
316  if(isset($a_values[$this->getPostVar()]['start']["time"]))
317  {
318  $this->setStart(new ilDateTime($a_values[$this->getPostVar()]['start']["date"].' '.$a_values[$this->getPostVar()]['start']["time"],
319  IL_CAL_DATETIME,$ilUser->getTimeZone()));
320  }
321  else
322  {
323  if (isset($a_values[$this->getPostVar()]['start']["date"]))
324  {
325  $this->setStart(new ilDate($a_values[$this->getPostVar()]['start']["date"],
326  IL_CAL_DATE));
327  }
328  }
329  if(isset($a_values[$this->getPostVar()]['end']["time"]))
330  {
331  $this->setEnd(new ilDateTime($a_values[$this->getPostVar()]['end']["date"].' '.$a_values[$this->getPostVar()]['end']["time"],
332  IL_CAL_DATETIME,$ilUser->getTimeZone()));
333  }
334  else
335  {
336  if (isset($a_values[$this->getPostVar()]['end']["date"]))
337  {
338  $this->setEnd(new ilDate($a_values[$this->getPostVar()]['end']["date"],
339  IL_CAL_DATE));
340  }
341  }
342  foreach($this->getSubItems() as $item)
343  {
344  $item->setValueByArray($a_values);
345  }
346  }
347 
353  public function checkInput()
354  {
355  global $lng,$ilUser;
356 
357  if($this->getDisabled())
358  {
359  return true;
360  }
361 
362 
363  $ok = true;
364 
365  // Start
366  $_POST[$this->getPostVar()]['start']["date"]["y"] =
367  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["y"]);
368  $_POST[$this->getPostVar()]["date"]["m"] =
369  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["m"]);
370  $_POST[$this->getPostVar()]["date"]["d"] =
371  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["d"]);
372  $_POST[$this->getPostVar()]["time"]["h"] =
373  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["h"]);
374  $_POST[$this->getPostVar()]["time"]["m"] =
375  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["m"]);
376  $_POST[$this->getPostVar()]["time"]["s"] =
377  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["s"]);
378 
379  // verify date
380  $dt['year'] = (int) $_POST[$this->getPostVar()]['start']['date']['y'];
381  $dt['mon'] = (int) $_POST[$this->getPostVar()]['start']['date']['m'];
382  $dt['mday'] = (int) $_POST[$this->getPostVar()]['start']['date']['d'];
383  $dt['hours'] = (int) $_POST[$this->getPostVar()]['start']['time']['h'];
384  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['start']['time']['m'];
385  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['start']['time']['s'];
386  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
387  $timestamp = $date->get(IL_CAL_UNIX);
388  if ($_POST[$this->getPostVar()]['start']["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
389  $_POST[$this->getPostVar()]['start']["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
390  $_POST[$this->getPostVar()]['start']["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
391  {
392  $this->setAlert($lng->txt("exc_date_not_valid"));
393  $ok = false;
394  }
395 
396  $_POST[$this->getPostVar()]['start']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
397  $_POST[$this->getPostVar()]['start']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
398 
399  $this->setStart($date);
400 
401  // End
402  $_POST[$this->getPostVar()]['end']["date"]["y"] =
403  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["y"]);
404  $_POST[$this->getPostVar()]["date"]["m"] =
405  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["m"]);
406  $_POST[$this->getPostVar()]["date"]["d"] =
407  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["d"]);
408  $_POST[$this->getPostVar()]["time"]["h"] =
409  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["h"]);
410  $_POST[$this->getPostVar()]["time"]["m"] =
411  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["m"]);
412  $_POST[$this->getPostVar()]["time"]["s"] =
413  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["s"]);
414 
415  // verify date
416  $dt['year'] = (int) $_POST[$this->getPostVar()]['end']['date']['y'];
417  $dt['mon'] = (int) $_POST[$this->getPostVar()]['end']['date']['m'];
418  $dt['mday'] = (int) $_POST[$this->getPostVar()]['end']['date']['d'];
419  $dt['hours'] = (int) $_POST[$this->getPostVar()]['end']['time']['h'];
420  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['end']['time']['m'];
421  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['end']['time']['s'];
422  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
423  $timestamp = $date->get(IL_CAL_UNIX);
424  if ($_POST[$this->getPostVar()]['end']["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
425  $_POST[$this->getPostVar()]['end']["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
426  $_POST[$this->getPostVar()]['end']["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
427  {
428  $this->setAlert($lng->txt("exc_date_not_valid"));
429  $ok = false;
430  }
431 
432  $_POST[$this->getPostVar()]['end']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
433  $_POST[$this->getPostVar()]['end']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
434 
435  $this->setEnd($date);
436 
437  return $ok;
438  }
439 
444  public function render()
445  {
446  global $lng,$ilUser;
447 
448  $tpl = new ilTemplate("tpl.prop_datetime_duration.html", true, true, "Services/Form");
449 
450  // Init start
451  if(is_a($this->getStart(),'ilDate'))
452  {
453  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'','UTC');
454  }
455  elseif(is_a($this->getStart(),'ilDateTime'))
456  {
457  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
458  }
459  else
460  {
461  $this->setStart(new ilDateTime(time(), IL_CAL_UNIX));
462  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
463  }
464  // Init end
465  if(is_a($this->getEnd(),'ilDate'))
466  {
467  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'','UTC');
468  }
469  elseif(is_a($this->getEnd(),'ilDateTime'))
470  {
471  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
472  }
473  else
474  {
475  $this->setEnd(new ilDateTime(time(), IL_CAL_UNIX));
476  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
477  }
478 
479  $lng->loadLanguageModule("jscalendar");
480  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
482 
483  if(strlen($this->getActivationPostVar()))
484  {
485  $tpl->setCurrentBlock('prop_date_activation');
486  $tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
487  $tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
488  $tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
489  $tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
490  $tpl->parseCurrentBlock();
491  }
492 
493  if(strlen($this->getStartText()))
494  {
495  $tpl->setVariable('TXT_START',$this->getStartText());
496  }
497  if(strlen($this->getEndText()))
498  {
499  $tpl->setVariable('TXT_END',$this->getEndText());
500  }
501 
502  // Toggle fullday
503  if($this->enabledToggleFullTime())
504  {
505  $tpl->setCurrentBlock('toggle_fullday');
506  $tpl->setVariable('FULLDAY_POSTVAR',$this->getPostVar());
507  $tpl->setVariable('FULLDAY_TOGGLE_NAME',$this->getPostVar().'[fulltime]');
508  $tpl->setVariable('FULLDAY_TOGGLE_CHECKED',$this->toggle_fulltime_checked ? 'checked="checked"' : '');
509  $tpl->setVariable('FULLDAY_TOGGLE_DISABLED',$this->getDisabled() ? 'disabled="disabled"' : '');
510  $tpl->setVariable('TXT_TOGGLE_FULLDAY',$this->toggle_fulltime_txt);
511  $tpl->parseCurrentBlock();
512  }
513 
514 
515  if ($this->getShowDate() or 1)
516  {
517  $tpl->setVariable('POST_VAR',$this->getPostVar());
518  $tpl->setVariable("IMG_START_CALENDAR", ilUtil::getImagePath("calendar.png"));
519  $tpl->setVariable("TXT_START_CALENDAR", $lng->txt("open_calendar"));
520  $tpl->setVariable("START_ID", $this->getPostVar());
521  $tpl->setVariable("DATE_ID_START", $this->getPostVar());
522 
523  $tpl->setVariable("INPUT_FIELDS_START", $this->getPostVar()."[start][date]");
524  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
525  $tpl->setVariable('DATE_FIRST_DAY',ilCalendarUserSettings::_getInstance()->getWeekStart());
526  $tpl->setVariable("START_SELECT",
528  $this->getPostVar()."[start][date]",
529  $start_info['year'], $start_info['mon'], $start_info['mday'],
530  $this->start_year,
531  true,
532  array(
533  'disabled' => $this->getDisabled(),
534  'select_attributes' => array('onchange' => 'ilUpdateEndDate();')
535  ),
536  $this->getShowEmpty()));
537 
538  $tpl->setVariable("IMG_END_CALENDAR", ilUtil::getImagePath("calendar.png"));
539  $tpl->setVariable("TXT_END_CALENDAR", $lng->txt("open_calendar"));
540  $tpl->setVariable("END_ID", $this->getPostVar());
541  $tpl->setVariable("DATE_ID_END", $this->getPostVar());
542  $tpl->setVariable("INPUT_FIELDS_END", $this->getPostVar()."[end][date]");
543  $tpl->setVariable("END_SELECT",
545  $this->getPostVar()."[end][date]",
546  $end_info['year'], $end_info['mon'], $end_info['mday'],
547  $this->start_year,
548  true,
549  array(
550  'disabled' => $this->getDisabled()
551  ),
552  $this->getShowEmpty()));
553  }
554  if($this->getShowTime())
555  {
556  $tpl->setCurrentBlock("show_start_time");
557  $tpl->setVariable("START_TIME_SELECT",
559  $this->getPostVar()."[start][time]",
560  !$this->getShowSeconds(),
561  $start_info['hours'], $start_info['minutes'], $start_info['seconds'],
562  true,
563  array(
564  'minute_steps' => $this->getMinuteStepSize(),
565  'disabled' => $this->getDisabled(),
566  'select_attributes' => array('onchange' => 'ilUpdateEndDate();')
567  )
568  ));
569 
570  $tpl->setVariable("TXT_START_TIME", $this->getShowSeconds()
571  ? "(".$lng->txt("hh_mm_ss").")"
572  : "(".$lng->txt("hh_mm").")");
573  $tpl->parseCurrentBlock();
574 
575  $tpl->setCurrentBlock("show_end_time");
576  $tpl->setVariable("END_TIME_SELECT",
577  ilUtil::makeTimeSelect($this->getPostVar()."[end][time]", !$this->getShowSeconds(),
578  $end_info['hours'], $end_info['minutes'], $end_info['seconds'],
579  true,array('minute_steps' => $this->getMinuteStepSize(),
580  'disabled' => $this->getDisabled())));
581 
582  $tpl->setVariable("TXT_END_TIME", $this->getShowSeconds()
583  ? "(".$lng->txt("hh_mm_ss").")"
584  : "(".$lng->txt("hh_mm").")");
585  $tpl->parseCurrentBlock();
586  }
587 
588  if ($this->getShowTime() && $this->getShowDate())
589  {
590  $tpl->setVariable("DELIM", "<br />");
591  }
592 
593  return $tpl->get();
594  }
595 
601  public function insert(&$a_tpl)
602  {
603  $html = $this->render();
604 
605  $a_tpl->setCurrentBlock("prop_generic");
606  $a_tpl->setVariable("PROP_GENERIC", $html);
607  $a_tpl->parseCurrentBlock();
608  }
609 
610 }