ILIAS  Release_5_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-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_empty = false;
40  protected $showtime = false;
41 
48  public function __construct($a_title = "", $a_postvar = "")
49  {
50  parent::__construct($a_title, $a_postvar);
51  $this->setType("dateduration");
52  }
53 
64  public function enableDateActivation($a_title,$a_postvar,$a_checked = true)
65  {
66  $this->activation_title = $a_title;
67  $this->activation_post_var = $a_postvar;
68  $this->activation_checked = $a_checked;
69  }
70 
77  public function enableToggleFullTime($a_title,$a_checked)
78  {
79  $this->toggle_fulltime_txt = $a_title;
80  $this->toggle_fulltime_checked = $a_checked;
81  $this->toggle_fulltime = true;
82  }
83 
88  public function enabledToggleFullTime()
89  {
91  }
92 
99  public function getActivationPostVar()
100  {
102  }
103 
115  public function setStart(ilDateTime $a_date)
116  {
117  $this->start = $a_date;
118  }
119 
125  public function setStartText($a_txt)
126  {
127  $this->start_text = $a_txt;
128  }
129 
134  public function getStartText()
135  {
136  return $this->start_text;
137  }
138 
144  public function setEndText($a_txt)
145  {
146  $this->end_text = $a_txt;
147  }
148 
153  public function getEndText()
154  {
155  return $this->end_text;
156  }
157 
163  public function getStart()
164  {
165  return $this->start;
166  }
167 
179  public function setEnd(ilDateTime $a_date)
180  {
181  $this->end = $a_date;
182  }
183 
189  public function getEnd()
190  {
191  return $this->end;
192  }
193 
199  function setShowEmpty($a_empty)
200  {
201  $this->show_empty = $a_empty;
202  }
203 
209  function getShowEmpty()
210  {
211  return $this->show_empty;
212  }
213 
214 
220  public function setShowTime($a_showtime)
221  {
222  $this->showtime = $a_showtime;
223  }
224 
230  public function getShowTime()
231  {
232  return $this->showtime;
233  }
234 
239  public function getShowSeconds()
240  {
241  return false;
242  }
243 
249  public function setStartYear($a_year)
250  {
251  $this->startyear = $a_year;
252  }
253 
259  public function getStartYear()
260  {
261  return $this->startyear;
262  }
263 
272  public function setMinuteStepSize($a_step_size)
273  {
274  $this->minute_step_size = $a_step_size;
275  }
276 
283  public function getMinuteStepSize()
284  {
286  }
287 
293  public function setValueByArray($a_values)
294  {
295  global $ilUser;
296 
297  try {
298  if(isset($a_values[$this->getPostVar()]['start']["time"]))
299  {
300  $this->setStart(new ilDateTime($a_values[$this->getPostVar()]['start']["date"].' '.$a_values[$this->getPostVar()]['start']["time"],
301  IL_CAL_DATETIME,$ilUser->getTimeZone()));
302  }
303  else
304  {
305  if (isset($a_values[$this->getPostVar()]['start']["date"]))
306  {
307  $this->setStart(new ilDate($a_values[$this->getPostVar()]['start']["date"],
308  IL_CAL_DATE));
309  }
310  }
311  if(isset($a_values[$this->getPostVar()]['end']["time"]))
312  {
313  $this->setEnd(new ilDateTime($a_values[$this->getPostVar()]['end']["date"].' '.$a_values[$this->getPostVar()]['end']["time"],
314  IL_CAL_DATETIME,$ilUser->getTimeZone()));
315  }
316  else
317  {
318  if (isset($a_values[$this->getPostVar()]['end']["date"]))
319  {
320  $this->setEnd(new ilDate($a_values[$this->getPostVar()]['end']["date"],
321  IL_CAL_DATE));
322  }
323  }
324  foreach($this->getSubItems() as $item)
325  {
326  $item->setValueByArray($a_values);
327  }
328  }
329  catch(ilDateTimeException $e)
330  {
331  // Nothing
332  }
333  }
334 
340  public function checkInput()
341  {
342  global $lng,$ilUser;
343 
344  if($this->getDisabled())
345  {
346  return true;
347  }
348 
349 
350  $ok = true;
351 
352  // Start
353  $_POST[$this->getPostVar()]['start']["date"]["y"] =
354  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["y"]);
355  $_POST[$this->getPostVar()]['start']["date"]["m"] =
356  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["m"]);
357  $_POST[$this->getPostVar()]['start']["date"]["d"] =
358  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["d"]);
359  $_POST[$this->getPostVar()]['start']["time"]["h"] =
360  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["h"]);
361  $_POST[$this->getPostVar()]['start']["time"]["m"] =
362  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["m"]);
363  $_POST[$this->getPostVar()]['start']["time"]["s"] =
364  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["s"]);
365 
366  // verify date
367  $dt['year'] = (int) $_POST[$this->getPostVar()]['start']['date']['y'];
368  $dt['mon'] = (int) $_POST[$this->getPostVar()]['start']['date']['m'];
369  $dt['mday'] = (int) $_POST[$this->getPostVar()]['start']['date']['d'];
370  $dt['hours'] = (int) $_POST[$this->getPostVar()]['start']['time']['h'];
371  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['start']['time']['m'];
372  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['start']['time']['s'];
373 
374 
375  if($this->getShowTime())
376  {
377  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
378  }
379  else
380  {
381  $date = new ilDate($dt,IL_CAL_FKT_GETDATE);
382  }
383  if ($_POST[$this->getPostVar()]['start']["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
384  $_POST[$this->getPostVar()]['start']["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
385  $_POST[$this->getPostVar()]['start']["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
386  {
387  // #11847
388  $this->invalid_input['start'] = $_POST[$this->getPostVar()]['start']["date"];
389  $this->setAlert($lng->txt("exc_date_not_valid"));
390  $ok = false;
391  }
392 
393  #$_POST[$this->getPostVar()]['start']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
394  #$_POST[$this->getPostVar()]['start']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
395 
396  $this->setStart($date);
397 
398  // End
399  $_POST[$this->getPostVar()]['end']["date"]["y"] =
400  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["y"]);
401  $_POST[$this->getPostVar()]['end']["date"]["m"] =
402  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["m"]);
403  $_POST[$this->getPostVar()]['end']["date"]["d"] =
404  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["d"]);
405  $_POST[$this->getPostVar()]['end']["time"]["h"] =
406  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["h"]);
407  $_POST[$this->getPostVar()]['end']["time"]["m"] =
408  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["m"]);
409  $_POST[$this->getPostVar()]['end']["time"]["s"] =
410  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["s"]);
411 
412  // verify date
413  $dt['year'] = (int) $_POST[$this->getPostVar()]['end']['date']['y'];
414  $dt['mon'] = (int) $_POST[$this->getPostVar()]['end']['date']['m'];
415  $dt['mday'] = (int) $_POST[$this->getPostVar()]['end']['date']['d'];
416  $dt['hours'] = (int) $_POST[$this->getPostVar()]['end']['time']['h'];
417  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['end']['time']['m'];
418  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['end']['time']['s'];
419 
420  if($this->getShowTime())
421  {
422  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
423  }
424  else
425  {
426  $date = new ilDate($dt,IL_CAL_FKT_GETDATE);
427  }
428  if ($_POST[$this->getPostVar()]['end']["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
429  $_POST[$this->getPostVar()]['end']["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
430  $_POST[$this->getPostVar()]['end']["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
431  {
432  $this->invalid_input['end'] = $_POST[$this->getPostVar()]['end']["date"];
433  $this->setAlert($lng->txt("exc_date_not_valid"));
434  $ok = false;
435  }
436 
437  #$_POST[$this->getPostVar()]['end']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
438  #$_POST[$this->getPostVar()]['end']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
439 
440  $this->setEnd($date);
441 
442  return $ok;
443  }
444 
449  public function render()
450  {
451  global $lng,$ilUser;
452 
453  $tpl = new ilTemplate("tpl.prop_datetime_duration.html", true, true, "Services/Form");
454 
455  // Init start
456  if(is_a($this->getStart(),'ilDate'))
457  {
458  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'','UTC');
459  }
460  elseif(is_a($this->getStart(),'ilDateTime'))
461  {
462  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
463  }
464  else
465  {
466  $this->setStart(new ilDateTime(time(), IL_CAL_UNIX));
467  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
468  }
469  // display invalid input again
470  if(is_array($this->invalid_input['start']))
471  {
472  $start_info['year'] = $this->invalid_input['start']['y'];
473  $start_info['mon'] = $this->invalid_input['start']['m'];
474  $start_info['mday'] = $this->invalid_input['start']['d'];
475  }
476 
477  // Init end
478  if(is_a($this->getEnd(),'ilDate'))
479  {
480  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'','UTC');
481  }
482  elseif(is_a($this->getEnd(),'ilDateTime'))
483  {
484  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
485  }
486  else
487  {
488  $this->setEnd(new ilDateTime(time(), IL_CAL_UNIX));
489  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
490  }
491  // display invalid input again
492  if(is_array($this->invalid_input['end']))
493  {
494  $end_info['year'] = $this->invalid_input['end']['y'];
495  $end_info['mon'] = $this->invalid_input['end']['m'];
496  $end_info['mday'] = $this->invalid_input['end']['d'];
497  }
498 
499  $lng->loadLanguageModule("jscalendar");
500  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
502 
503  if(strlen($this->getActivationPostVar()))
504  {
505  $tpl->setCurrentBlock('prop_date_activation');
506  $tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
507  $tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
508  $tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
509  $tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
510  $tpl->parseCurrentBlock();
511  }
512 
513  if(strlen($this->getStartText()))
514  {
515  $tpl->setVariable('TXT_START',$this->getStartText());
516  }
517  if(strlen($this->getEndText()))
518  {
519  $tpl->setVariable('TXT_END',$this->getEndText());
520  }
521 
522  // Toggle fullday
523  if($this->enabledToggleFullTime())
524  {
525  $tpl->setCurrentBlock('toggle_fullday');
526  $tpl->setVariable('FULLDAY_POSTVAR',$this->getPostVar());
527  $tpl->setVariable('FULLDAY_TOGGLE_NAME',$this->getPostVar().'[fulltime]');
528  $tpl->setVariable('FULLDAY_TOGGLE_CHECKED',$this->toggle_fulltime_checked ? 'checked="checked"' : '');
529  $tpl->setVariable('FULLDAY_TOGGLE_DISABLED',$this->getDisabled() ? 'disabled="disabled"' : '');
530  $tpl->setVariable('TXT_TOGGLE_FULLDAY',$this->toggle_fulltime_txt);
531  $tpl->parseCurrentBlock();
532  }
533 
534  $tpl->setVariable('POST_VAR',$this->getPostVar());
535  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
536  $tpl->setVariable("IMG_START_CALENDAR", ilGlyphGUI::get(ilGlyphGUI::CALENDAR, $lng->txt("open_calendar")));
537 
538  $tpl->setVariable("START_ID", $this->getPostVar());
539  $tpl->setVariable("DATE_ID_START", $this->getPostVar());
540 
541  $tpl->setVariable("INPUT_FIELDS_START", $this->getPostVar()."[start][date]");
542  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
543  $tpl->setVariable('DATE_FIRST_DAY',ilCalendarUserSettings::_getInstance()->getWeekStart());
544  $tpl->setVariable("START_SELECT",
546  $this->getPostVar()."[start][date]",
547  $start_info['year'], $start_info['mon'], $start_info['mday'],
548  $this->getStartYear(),
549  true,
550  array(
551  'disabled' => $this->getDisabled(),
552  'select_attributes' => array('onchange' => 'ilUpdateEndDate();')
553  ),
554  $this->getShowEmpty()));
555 
556  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
557  $tpl->setVariable("IMG_END_CALENDAR", ilGlyphGUI::get(ilGlyphGUI::CALENDAR, $lng->txt("open_calendar")));
558 
559  $tpl->setVariable("END_ID", $this->getPostVar());
560  $tpl->setVariable("DATE_ID_END", $this->getPostVar());
561  $tpl->setVariable("INPUT_FIELDS_END", $this->getPostVar()."[end][date]");
562  $tpl->setVariable("END_SELECT",
564  $this->getPostVar()."[end][date]",
565  $end_info['year'], $end_info['mon'], $end_info['mday'],
566  $this->getStartYear(),
567  true,
568  array(
569  'disabled' => $this->getDisabled()
570  ),
571  $this->getShowEmpty()));
572 
573  if($this->getShowTime())
574  {
575  $tpl->setCurrentBlock("show_start_time");
576  $tpl->setVariable("START_TIME_SELECT",
578  $this->getPostVar()."[start][time]",
579  !$this->getShowSeconds(),
580  $start_info['hours'], $start_info['minutes'], $start_info['seconds'],
581  true,
582  array(
583  'minute_steps' => $this->getMinuteStepSize(),
584  'disabled' => $this->getDisabled(),
585  'select_attributes' => array('onchange' => 'ilUpdateEndDate();')
586  )
587  ));
588 
589  $tpl->setVariable("TXT_START_TIME", $this->getShowSeconds()
590  ? "(".$lng->txt("hh_mm_ss").")"
591  : "(".$lng->txt("hh_mm").")");
592  $tpl->parseCurrentBlock();
593 
594  $tpl->setCurrentBlock("show_end_time");
595  $tpl->setVariable("END_TIME_SELECT",
596  ilUtil::makeTimeSelect($this->getPostVar()."[end][time]", !$this->getShowSeconds(),
597  $end_info['hours'], $end_info['minutes'], $end_info['seconds'],
598  true,array('minute_steps' => $this->getMinuteStepSize(),
599  'disabled' => $this->getDisabled())));
600 
601  $tpl->setVariable("TXT_END_TIME", $this->getShowSeconds()
602  ? "(".$lng->txt("hh_mm_ss").")"
603  : "(".$lng->txt("hh_mm").")");
604  $tpl->parseCurrentBlock();
605  }
606 
607  if ($this->getShowTime())
608  {
609  $tpl->setVariable("DELIM", "<br />");
610  }
611 
612  return $tpl->get();
613  }
614 
620  public function insert(&$a_tpl)
621  {
622  $html = $this->render();
623 
624  $a_tpl->setCurrentBlock("prop_generic");
625  $a_tpl->setVariable("PROP_GENERIC", $html);
626  $a_tpl->parseCurrentBlock();
627  }
628 
633  public function getTableFilterHTML()
634  {
635  return $this->render();
636  }
637 
642  public function getValue()
643  {
644  return array(
645  'start' => $this->getStart()->get(IL_CAL_UNIX),
646  'end' => $this->getEnd()->get(IL_CAL_UNIX)
647  );
648  }
649 
656  public function setValue($value)
657  {
658  if(is_array($value))
659  {
660  $this->setStart(new ilDateTime($value['start'], IL_CAL_UNIX));
661  $this->setEnd(new ilDateTime($value['end'], IL_CAL_UNIX));
662  }
663  }
664 }