ILIAS  Release_4_4_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-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Table/interfaces/interface.ilTableFilterItem.php';
5 
15 {
16  protected $start = null;
17  protected $startyear = null;
18 
19  protected $start_text = '';
20  protected $end_text = '';
21 
22  protected $minute_step_size = 5;
23  protected $end = null;
24 
28  protected $activation_title = '';
29  protected $activation_post_var = '';
30  protected $activation_checked = true;
31 
35  protected $toggle_fulltime = false;
36  protected $toggle_fulltime_txt = '';
37  protected $toggle_fulltime_checked = false;
38 
39  protected $show_date = true;
40  protected $show_empty = false;
41  protected $show_time = true;
42 
49  public function __construct($a_title = "", $a_postvar = "")
50  {
51  parent::__construct($a_title, $a_postvar);
52  $this->setType("dateduration");
53  }
54 
65  public function enableDateActivation($a_title,$a_postvar,$a_checked = true)
66  {
67  $this->activation_title = $a_title;
68  $this->activation_post_var = $a_postvar;
69  $this->activation_checked = $a_checked;
70  }
71 
78  public function enableToggleFullTime($a_title,$a_checked)
79  {
80  $this->toggle_fulltime_txt = $a_title;
81  $this->toggle_fulltime_checked = $a_checked;
82  $this->toggle_fulltime = true;
83  }
84 
89  public function enabledToggleFullTime()
90  {
92  }
93 
100  public function getActivationPostVar()
101  {
103  }
104 
116  public function setStart(ilDateTime $a_date)
117  {
118  $this->start = $a_date;
119  }
120 
126  public function setStartText($a_txt)
127  {
128  $this->start_text = $a_txt;
129  }
130 
135  public function getStartText()
136  {
137  return $this->start_text;
138  }
139 
145  public function setEndText($a_txt)
146  {
147  $this->end_text = $a_txt;
148  }
149 
154  public function getEndText()
155  {
156  return $this->end_text;
157  }
158 
164  public function getStart()
165  {
166  return $this->start;
167  }
168 
180  public function setEnd(ilDateTime $a_date)
181  {
182  $this->end = $a_date;
183  }
184 
190  public function getEnd()
191  {
192  return $this->end;
193  }
194 
200  public function setShowDate($a_showdate)
201  {
202  $this->showdate = $a_showdate;
203  }
204 
210  public function getShowDate()
211  {
212  return $this->showdate;
213  }
214 
220  function setShowEmpty($a_empty)
221  {
222  $this->show_empty = $a_empty;
223  }
224 
230  function getShowEmpty()
231  {
232  return $this->show_empty;
233  }
234 
235 
241  public function setShowTime($a_showtime)
242  {
243  $this->showtime = $a_showtime;
244  }
245 
251  public function getShowTime()
252  {
253  return $this->showtime;
254  }
255 
260  public function getShowSeconds()
261  {
262  return false;
263  }
264 
270  public function setStartYear($a_year)
271  {
272  $this->startyear = $a_year;
273  }
274 
280  public function getStartYear()
281  {
282  return $this->startyear;
283  }
284 
293  public function setMinuteStepSize($a_step_size)
294  {
295  $this->minute_step_size = $a_step_size;
296  }
297 
304  public function getMinuteStepSize()
305  {
307  }
308 
314  public function setValueByArray($a_values)
315  {
316  global $ilUser;
317 
318  try {
319  if(isset($a_values[$this->getPostVar()]['start']["time"]))
320  {
321  $this->setStart(new ilDateTime($a_values[$this->getPostVar()]['start']["date"].' '.$a_values[$this->getPostVar()]['start']["time"],
322  IL_CAL_DATETIME,$ilUser->getTimeZone()));
323  }
324  else
325  {
326  if (isset($a_values[$this->getPostVar()]['start']["date"]))
327  {
328  $this->setStart(new ilDate($a_values[$this->getPostVar()]['start']["date"],
329  IL_CAL_DATE));
330  }
331  }
332  if(isset($a_values[$this->getPostVar()]['end']["time"]))
333  {
334  $this->setEnd(new ilDateTime($a_values[$this->getPostVar()]['end']["date"].' '.$a_values[$this->getPostVar()]['end']["time"],
335  IL_CAL_DATETIME,$ilUser->getTimeZone()));
336  }
337  else
338  {
339  if (isset($a_values[$this->getPostVar()]['end']["date"]))
340  {
341  $this->setEnd(new ilDate($a_values[$this->getPostVar()]['end']["date"],
342  IL_CAL_DATE));
343  }
344  }
345  foreach($this->getSubItems() as $item)
346  {
347  $item->setValueByArray($a_values);
348  }
349  }
350  catch(ilDateTimeException $e)
351  {
352  // Nothing
353  }
354  }
355 
361  public function checkInput()
362  {
363  global $lng,$ilUser;
364 
365  if($this->getDisabled())
366  {
367  return true;
368  }
369 
370 
371  $ok = true;
372 
373  // Start
374  $_POST[$this->getPostVar()]['start']["date"]["y"] =
375  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["y"]);
376  $_POST[$this->getPostVar()]['start']["date"]["m"] =
377  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["m"]);
378  $_POST[$this->getPostVar()]['start']["date"]["d"] =
379  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["d"]);
380  $_POST[$this->getPostVar()]['start']["time"]["h"] =
381  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["h"]);
382  $_POST[$this->getPostVar()]['start']["time"]["m"] =
383  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["m"]);
384  $_POST[$this->getPostVar()]['start']["time"]["s"] =
385  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["s"]);
386 
387  // verify date
388  $dt['year'] = (int) $_POST[$this->getPostVar()]['start']['date']['y'];
389  $dt['mon'] = (int) $_POST[$this->getPostVar()]['start']['date']['m'];
390  $dt['mday'] = (int) $_POST[$this->getPostVar()]['start']['date']['d'];
391  $dt['hours'] = (int) $_POST[$this->getPostVar()]['start']['time']['h'];
392  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['start']['time']['m'];
393  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['start']['time']['s'];
394 
395 
396  if($this->getShowTime())
397  {
398  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
399  }
400  else
401  {
402  $date = new ilDate($dt,IL_CAL_FKT_GETDATE);
403  }
404  if ($_POST[$this->getPostVar()]['start']["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
405  $_POST[$this->getPostVar()]['start']["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
406  $_POST[$this->getPostVar()]['start']["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
407  {
408  // #11847
409  $this->invalid_input['start'] = $_POST[$this->getPostVar()]['start']["date"];
410  $this->setAlert($lng->txt("exc_date_not_valid"));
411  $ok = false;
412  }
413 
414  #$_POST[$this->getPostVar()]['start']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
415  #$_POST[$this->getPostVar()]['start']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
416 
417  $this->setStart($date);
418 
419  // End
420  $_POST[$this->getPostVar()]['end']["date"]["y"] =
421  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["y"]);
422  $_POST[$this->getPostVar()]['end']["date"]["m"] =
423  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["m"]);
424  $_POST[$this->getPostVar()]['end']["date"]["d"] =
425  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["d"]);
426  $_POST[$this->getPostVar()]['end']["time"]["h"] =
427  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["h"]);
428  $_POST[$this->getPostVar()]['end']["time"]["m"] =
429  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["m"]);
430  $_POST[$this->getPostVar()]['end']["time"]["s"] =
431  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["s"]);
432 
433  // verify date
434  $dt['year'] = (int) $_POST[$this->getPostVar()]['end']['date']['y'];
435  $dt['mon'] = (int) $_POST[$this->getPostVar()]['end']['date']['m'];
436  $dt['mday'] = (int) $_POST[$this->getPostVar()]['end']['date']['d'];
437  $dt['hours'] = (int) $_POST[$this->getPostVar()]['end']['time']['h'];
438  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['end']['time']['m'];
439  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['end']['time']['s'];
440 
441  if($this->getShowTime())
442  {
443  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
444  }
445  else
446  {
447  $date = new ilDate($dt,IL_CAL_FKT_GETDATE);
448  }
449  if ($_POST[$this->getPostVar()]['end']["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
450  $_POST[$this->getPostVar()]['end']["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
451  $_POST[$this->getPostVar()]['end']["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
452  {
453  $this->invalid_input['end'] = $_POST[$this->getPostVar()]['end']["date"];
454  $this->setAlert($lng->txt("exc_date_not_valid"));
455  $ok = false;
456  }
457 
458  #$_POST[$this->getPostVar()]['end']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
459  #$_POST[$this->getPostVar()]['end']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
460 
461  $this->setEnd($date);
462 
463  return $ok;
464  }
465 
470  public function render()
471  {
472  global $lng,$ilUser;
473 
474  $tpl = new ilTemplate("tpl.prop_datetime_duration.html", true, true, "Services/Form");
475 
476  // Init start
477  if(is_a($this->getStart(),'ilDate'))
478  {
479  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'','UTC');
480  }
481  elseif(is_a($this->getStart(),'ilDateTime'))
482  {
483  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
484  }
485  else
486  {
487  $this->setStart(new ilDateTime(time(), IL_CAL_UNIX));
488  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
489  }
490  // display invalid input again
491  if(is_array($this->invalid_input['start']))
492  {
493  $start_info['year'] = $this->invalid_input['start']['y'];
494  $start_info['mon'] = $this->invalid_input['start']['m'];
495  $start_info['mday'] = $this->invalid_input['start']['d'];
496  }
497 
498  // Init end
499  if(is_a($this->getEnd(),'ilDate'))
500  {
501  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'','UTC');
502  }
503  elseif(is_a($this->getEnd(),'ilDateTime'))
504  {
505  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
506  }
507  else
508  {
509  $this->setEnd(new ilDateTime(time(), IL_CAL_UNIX));
510  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
511  }
512  // display invalid input again
513  if(is_array($this->invalid_input['end']))
514  {
515  $end_info['year'] = $this->invalid_input['end']['y'];
516  $end_info['mon'] = $this->invalid_input['end']['m'];
517  $end_info['mday'] = $this->invalid_input['end']['d'];
518  }
519 
520  $lng->loadLanguageModule("jscalendar");
521  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
523 
524  if(strlen($this->getActivationPostVar()))
525  {
526  $tpl->setCurrentBlock('prop_date_activation');
527  $tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
528  $tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
529  $tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
530  $tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
531  $tpl->parseCurrentBlock();
532  }
533 
534  if(strlen($this->getStartText()))
535  {
536  $tpl->setVariable('TXT_START',$this->getStartText());
537  }
538  if(strlen($this->getEndText()))
539  {
540  $tpl->setVariable('TXT_END',$this->getEndText());
541  }
542 
543  // Toggle fullday
544  if($this->enabledToggleFullTime())
545  {
546  $tpl->setCurrentBlock('toggle_fullday');
547  $tpl->setVariable('FULLDAY_POSTVAR',$this->getPostVar());
548  $tpl->setVariable('FULLDAY_TOGGLE_NAME',$this->getPostVar().'[fulltime]');
549  $tpl->setVariable('FULLDAY_TOGGLE_CHECKED',$this->toggle_fulltime_checked ? 'checked="checked"' : '');
550  $tpl->setVariable('FULLDAY_TOGGLE_DISABLED',$this->getDisabled() ? 'disabled="disabled"' : '');
551  $tpl->setVariable('TXT_TOGGLE_FULLDAY',$this->toggle_fulltime_txt);
552  $tpl->parseCurrentBlock();
553  }
554 
555 
556  if ($this->getShowDate() or 1)
557  {
558  $tpl->setVariable('POST_VAR',$this->getPostVar());
559  $tpl->setVariable("IMG_START_CALENDAR", ilUtil::getImagePath("calendar.png"));
560  $tpl->setVariable("TXT_START_CALENDAR", $lng->txt("open_calendar"));
561  $tpl->setVariable("START_ID", $this->getPostVar());
562  $tpl->setVariable("DATE_ID_START", $this->getPostVar());
563 
564  $tpl->setVariable("INPUT_FIELDS_START", $this->getPostVar()."[start][date]");
565  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
566  $tpl->setVariable('DATE_FIRST_DAY',ilCalendarUserSettings::_getInstance()->getWeekStart());
567  $tpl->setVariable("START_SELECT",
569  $this->getPostVar()."[start][date]",
570  $start_info['year'], $start_info['mon'], $start_info['mday'],
571  $this->getStartYear(),
572  true,
573  array(
574  'disabled' => $this->getDisabled(),
575  'select_attributes' => array('onchange' => 'ilUpdateEndDate();')
576  ),
577  $this->getShowEmpty()));
578 
579  $tpl->setVariable("IMG_END_CALENDAR", ilUtil::getImagePath("calendar.png"));
580  $tpl->setVariable("TXT_END_CALENDAR", $lng->txt("open_calendar"));
581  $tpl->setVariable("END_ID", $this->getPostVar());
582  $tpl->setVariable("DATE_ID_END", $this->getPostVar());
583  $tpl->setVariable("INPUT_FIELDS_END", $this->getPostVar()."[end][date]");
584  $tpl->setVariable("END_SELECT",
586  $this->getPostVar()."[end][date]",
587  $end_info['year'], $end_info['mon'], $end_info['mday'],
588  $this->getStartYear(),
589  true,
590  array(
591  'disabled' => $this->getDisabled()
592  ),
593  $this->getShowEmpty()));
594  }
595  if($this->getShowTime())
596  {
597  $tpl->setCurrentBlock("show_start_time");
598  $tpl->setVariable("START_TIME_SELECT",
600  $this->getPostVar()."[start][time]",
601  !$this->getShowSeconds(),
602  $start_info['hours'], $start_info['minutes'], $start_info['seconds'],
603  true,
604  array(
605  'minute_steps' => $this->getMinuteStepSize(),
606  'disabled' => $this->getDisabled(),
607  'select_attributes' => array('onchange' => 'ilUpdateEndDate();')
608  )
609  ));
610 
611  $tpl->setVariable("TXT_START_TIME", $this->getShowSeconds()
612  ? "(".$lng->txt("hh_mm_ss").")"
613  : "(".$lng->txt("hh_mm").")");
614  $tpl->parseCurrentBlock();
615 
616  $tpl->setCurrentBlock("show_end_time");
617  $tpl->setVariable("END_TIME_SELECT",
618  ilUtil::makeTimeSelect($this->getPostVar()."[end][time]", !$this->getShowSeconds(),
619  $end_info['hours'], $end_info['minutes'], $end_info['seconds'],
620  true,array('minute_steps' => $this->getMinuteStepSize(),
621  'disabled' => $this->getDisabled())));
622 
623  $tpl->setVariable("TXT_END_TIME", $this->getShowSeconds()
624  ? "(".$lng->txt("hh_mm_ss").")"
625  : "(".$lng->txt("hh_mm").")");
626  $tpl->parseCurrentBlock();
627  }
628 
629  if ($this->getShowTime() && $this->getShowDate())
630  {
631  $tpl->setVariable("DELIM", "<br />");
632  }
633 
634  return $tpl->get();
635  }
636 
642  public function insert(&$a_tpl)
643  {
644  $html = $this->render();
645 
646  $a_tpl->setCurrentBlock("prop_generic");
647  $a_tpl->setVariable("PROP_GENERIC", $html);
648  $a_tpl->parseCurrentBlock();
649  }
650 
655  public function getTableFilterHTML()
656  {
657  return $this->render();
658  }
659 
664  public function getValue()
665  {
666  return array(
667  'start' => $this->getStart()->get(IL_CAL_UNIX),
668  'end' => $this->getEnd()->get(IL_CAL_UNIX)
669  );
670  }
671 
678  public function setValue($value)
679  {
680  if(is_array($value))
681  {
682  $this->setStart(new ilDateTime($value['start'], IL_CAL_UNIX));
683  $this->setEnd(new ilDateTime($value['end'], IL_CAL_UNIX));
684  }
685  }
686 }