ILIAS  release_4-3 Revision
 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  try {
317  if(isset($a_values[$this->getPostVar()]['start']["time"]))
318  {
319  $this->setStart(new ilDateTime($a_values[$this->getPostVar()]['start']["date"].' '.$a_values[$this->getPostVar()]['start']["time"],
320  IL_CAL_DATETIME,$ilUser->getTimeZone()));
321  }
322  else
323  {
324  if (isset($a_values[$this->getPostVar()]['start']["date"]))
325  {
326  $this->setStart(new ilDate($a_values[$this->getPostVar()]['start']["date"],
327  IL_CAL_DATE));
328  }
329  }
330  if(isset($a_values[$this->getPostVar()]['end']["time"]))
331  {
332  $this->setEnd(new ilDateTime($a_values[$this->getPostVar()]['end']["date"].' '.$a_values[$this->getPostVar()]['end']["time"],
333  IL_CAL_DATETIME,$ilUser->getTimeZone()));
334  }
335  else
336  {
337  if (isset($a_values[$this->getPostVar()]['end']["date"]))
338  {
339  $this->setEnd(new ilDate($a_values[$this->getPostVar()]['end']["date"],
340  IL_CAL_DATE));
341  }
342  }
343  foreach($this->getSubItems() as $item)
344  {
345  $item->setValueByArray($a_values);
346  }
347  }
348  catch(ilDateTimeException $e)
349  {
350  // Nothing
351  }
352  }
353 
359  public function checkInput()
360  {
361  global $lng,$ilUser;
362 
363  if($this->getDisabled())
364  {
365  return true;
366  }
367 
368 
369  $ok = true;
370 
371  // Start
372  $_POST[$this->getPostVar()]['start']["date"]["y"] =
373  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["y"]);
374  $_POST[$this->getPostVar()]['start']["date"]["m"] =
375  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["m"]);
376  $_POST[$this->getPostVar()]['start']["date"]["d"] =
377  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["date"]["d"]);
378  $_POST[$this->getPostVar()]['start']["time"]["h"] =
379  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["h"]);
380  $_POST[$this->getPostVar()]['start']["time"]["m"] =
381  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["m"]);
382  $_POST[$this->getPostVar()]['start']["time"]["s"] =
383  ilUtil::stripSlashes($_POST[$this->getPostVar()]['start']["time"]["s"]);
384 
385  // verify date
386  $dt['year'] = (int) $_POST[$this->getPostVar()]['start']['date']['y'];
387  $dt['mon'] = (int) $_POST[$this->getPostVar()]['start']['date']['m'];
388  $dt['mday'] = (int) $_POST[$this->getPostVar()]['start']['date']['d'];
389  $dt['hours'] = (int) $_POST[$this->getPostVar()]['start']['time']['h'];
390  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['start']['time']['m'];
391  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['start']['time']['s'];
392 
393 
394  if($this->getShowTime())
395  {
396  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
397  }
398  else
399  {
400  $date = new ilDate($dt,IL_CAL_FKT_GETDATE);
401  }
402  if ($_POST[$this->getPostVar()]['start']["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
403  $_POST[$this->getPostVar()]['start']["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
404  $_POST[$this->getPostVar()]['start']["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
405  {
406  $this->setAlert($lng->txt("exc_date_not_valid"));
407  $ok = false;
408  }
409 
410  #$_POST[$this->getPostVar()]['start']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
411  #$_POST[$this->getPostVar()]['start']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
412 
413  $this->setStart($date);
414 
415  // End
416  $_POST[$this->getPostVar()]['end']["date"]["y"] =
417  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["y"]);
418  $_POST[$this->getPostVar()]['end']["date"]["m"] =
419  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["m"]);
420  $_POST[$this->getPostVar()]['end']["date"]["d"] =
421  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["date"]["d"]);
422  $_POST[$this->getPostVar()]['end']["time"]["h"] =
423  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["h"]);
424  $_POST[$this->getPostVar()]['end']["time"]["m"] =
425  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["m"]);
426  $_POST[$this->getPostVar()]['end']["time"]["s"] =
427  ilUtil::stripSlashes($_POST[$this->getPostVar()]['end']["time"]["s"]);
428 
429  // verify date
430  $dt['year'] = (int) $_POST[$this->getPostVar()]['end']['date']['y'];
431  $dt['mon'] = (int) $_POST[$this->getPostVar()]['end']['date']['m'];
432  $dt['mday'] = (int) $_POST[$this->getPostVar()]['end']['date']['d'];
433  $dt['hours'] = (int) $_POST[$this->getPostVar()]['end']['time']['h'];
434  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['end']['time']['m'];
435  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['end']['time']['s'];
436 
437  if($this->getShowTime())
438  {
439  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
440  }
441  else
442  {
443  $date = new ilDate($dt,IL_CAL_FKT_GETDATE);
444  }
445  if ($_POST[$this->getPostVar()]['end']["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
446  $_POST[$this->getPostVar()]['end']["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
447  $_POST[$this->getPostVar()]['end']["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
448  {
449  $this->setAlert($lng->txt("exc_date_not_valid"));
450  $ok = false;
451  }
452 
453  #$_POST[$this->getPostVar()]['end']['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
454  #$_POST[$this->getPostVar()]['end']['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
455 
456  $this->setEnd($date);
457 
458  return $ok;
459  }
460 
465  public function render()
466  {
467  global $lng,$ilUser;
468 
469  $tpl = new ilTemplate("tpl.prop_datetime_duration.html", true, true, "Services/Form");
470 
471  // Init start
472  if(is_a($this->getStart(),'ilDate'))
473  {
474  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'','UTC');
475  }
476  elseif(is_a($this->getStart(),'ilDateTime'))
477  {
478  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
479  }
480  else
481  {
482  $this->setStart(new ilDateTime(time(), IL_CAL_UNIX));
483  $start_info = $this->getStart()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
484  }
485  // Init end
486  if(is_a($this->getEnd(),'ilDate'))
487  {
488  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'','UTC');
489  }
490  elseif(is_a($this->getEnd(),'ilDateTime'))
491  {
492  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
493  }
494  else
495  {
496  $this->setEnd(new ilDateTime(time(), IL_CAL_UNIX));
497  $end_info = $this->getEnd()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
498  }
499 
500  $lng->loadLanguageModule("jscalendar");
501  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
503 
504  if(strlen($this->getActivationPostVar()))
505  {
506  $tpl->setCurrentBlock('prop_date_activation');
507  $tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
508  $tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
509  $tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
510  $tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
511  $tpl->parseCurrentBlock();
512  }
513 
514  if(strlen($this->getStartText()))
515  {
516  $tpl->setVariable('TXT_START',$this->getStartText());
517  }
518  if(strlen($this->getEndText()))
519  {
520  $tpl->setVariable('TXT_END',$this->getEndText());
521  }
522 
523  // Toggle fullday
524  if($this->enabledToggleFullTime())
525  {
526  $tpl->setCurrentBlock('toggle_fullday');
527  $tpl->setVariable('FULLDAY_POSTVAR',$this->getPostVar());
528  $tpl->setVariable('FULLDAY_TOGGLE_NAME',$this->getPostVar().'[fulltime]');
529  $tpl->setVariable('FULLDAY_TOGGLE_CHECKED',$this->toggle_fulltime_checked ? 'checked="checked"' : '');
530  $tpl->setVariable('FULLDAY_TOGGLE_DISABLED',$this->getDisabled() ? 'disabled="disabled"' : '');
531  $tpl->setVariable('TXT_TOGGLE_FULLDAY',$this->toggle_fulltime_txt);
532  $tpl->parseCurrentBlock();
533  }
534 
535 
536  if ($this->getShowDate() or 1)
537  {
538  $tpl->setVariable('POST_VAR',$this->getPostVar());
539  $tpl->setVariable("IMG_START_CALENDAR", ilUtil::getImagePath("calendar.png"));
540  $tpl->setVariable("TXT_START_CALENDAR", $lng->txt("open_calendar"));
541  $tpl->setVariable("START_ID", $this->getPostVar());
542  $tpl->setVariable("DATE_ID_START", $this->getPostVar());
543 
544  $tpl->setVariable("INPUT_FIELDS_START", $this->getPostVar()."[start][date]");
545  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
546  $tpl->setVariable('DATE_FIRST_DAY',ilCalendarUserSettings::_getInstance()->getWeekStart());
547  $tpl->setVariable("START_SELECT",
549  $this->getPostVar()."[start][date]",
550  $start_info['year'], $start_info['mon'], $start_info['mday'],
551  $this->start_year,
552  true,
553  array(
554  'disabled' => $this->getDisabled(),
555  'select_attributes' => array('onchange' => 'ilUpdateEndDate();')
556  ),
557  $this->getShowEmpty()));
558 
559  $tpl->setVariable("IMG_END_CALENDAR", ilUtil::getImagePath("calendar.png"));
560  $tpl->setVariable("TXT_END_CALENDAR", $lng->txt("open_calendar"));
561  $tpl->setVariable("END_ID", $this->getPostVar());
562  $tpl->setVariable("DATE_ID_END", $this->getPostVar());
563  $tpl->setVariable("INPUT_FIELDS_END", $this->getPostVar()."[end][date]");
564  $tpl->setVariable("END_SELECT",
566  $this->getPostVar()."[end][date]",
567  $end_info['year'], $end_info['mon'], $end_info['mday'],
568  $this->start_year,
569  true,
570  array(
571  'disabled' => $this->getDisabled()
572  ),
573  $this->getShowEmpty()));
574  }
575  if($this->getShowTime())
576  {
577  $tpl->setCurrentBlock("show_start_time");
578  $tpl->setVariable("START_TIME_SELECT",
580  $this->getPostVar()."[start][time]",
581  !$this->getShowSeconds(),
582  $start_info['hours'], $start_info['minutes'], $start_info['seconds'],
583  true,
584  array(
585  'minute_steps' => $this->getMinuteStepSize(),
586  'disabled' => $this->getDisabled(),
587  'select_attributes' => array('onchange' => 'ilUpdateEndDate();')
588  )
589  ));
590 
591  $tpl->setVariable("TXT_START_TIME", $this->getShowSeconds()
592  ? "(".$lng->txt("hh_mm_ss").")"
593  : "(".$lng->txt("hh_mm").")");
594  $tpl->parseCurrentBlock();
595 
596  $tpl->setCurrentBlock("show_end_time");
597  $tpl->setVariable("END_TIME_SELECT",
598  ilUtil::makeTimeSelect($this->getPostVar()."[end][time]", !$this->getShowSeconds(),
599  $end_info['hours'], $end_info['minutes'], $end_info['seconds'],
600  true,array('minute_steps' => $this->getMinuteStepSize(),
601  'disabled' => $this->getDisabled())));
602 
603  $tpl->setVariable("TXT_END_TIME", $this->getShowSeconds()
604  ? "(".$lng->txt("hh_mm_ss").")"
605  : "(".$lng->txt("hh_mm").")");
606  $tpl->parseCurrentBlock();
607  }
608 
609  if ($this->getShowTime() && $this->getShowDate())
610  {
611  $tpl->setVariable("DELIM", "<br />");
612  }
613 
614  return $tpl->get();
615  }
616 
622  public function insert(&$a_tpl)
623  {
624  $html = $this->render();
625 
626  $a_tpl->setCurrentBlock("prop_generic");
627  $a_tpl->setVariable("PROP_GENERIC", $html);
628  $a_tpl->parseCurrentBlock();
629  }
630 
631 }