ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDateTimeInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  protected $date_obj = null;
14  protected $date;
15  protected $showdate = true;
16  protected $time = "00:00:00";
17  protected $showtime = false;
18  protected $showseconds = false;
19  protected $minute_step_size = 1;
20  protected $show_empty = false;
21  protected $startyear = '';
22 
23  protected $activation_title = '';
24  protected $activation_post_var = '';
25 
32  function __construct($a_title = "", $a_postvar = "")
33  {
34  parent::__construct($a_title, $a_postvar);
35  $this->setType("datetime");
36  }
37 
48  public function enableDateActivation($a_title,$a_postvar,$a_checked = true)
49  {
50  $this->activation_title = $a_title;
51  $this->activation_post_var = $a_postvar;
52  $this->activation_checked = $a_checked;
53  }
54 
61  public function getActivationPostVar()
62  {
64  }
65 
77  function setDate(ilDateTime $a_date)
78  {
79  $this->date = $a_date;
80  }
81 
87  function getDate()
88  {
89  return $this->date;
90  }
91 
97  function setShowDate($a_showdate)
98  {
99  $this->showdate = $a_showdate;
100  }
101 
107  function getShowDate()
108  {
109  return $this->showdate;
110  }
111 
117  function setShowTime($a_showtime)
118  {
119  $this->showtime = $a_showtime;
120  }
121 
127  function getShowTime()
128  {
129  return $this->showtime;
130  }
131 
137  function setShowEmpty($a_empty)
138  {
139  $this->show_empty = $a_empty;
140  }
141 
147  function getShowEmpty()
148  {
149  return $this->show_empty;
150  }
151 
157  function setStartYear($a_year)
158  {
159  $this->startyear = $a_year;
160  }
161 
167  function getStartYear()
168  {
169  return $this->startyear;
170  }
171 
180  public function setMinuteStepSize($a_step_size)
181  {
182  $this->minute_step_size = $a_step_size;
183  }
184 
191  public function getMinuteStepSize()
192  {
194  }
195 
196 
197 
203  function setShowSeconds($a_showseconds)
204  {
205  $this->showseconds = $a_showseconds;
206  }
207 
213  function getShowSeconds()
214  {
215  return $this->showseconds;
216  }
217 
223  function setValueByArray($a_values)
224  {
225  global $ilUser;
226 
227  if(isset($a_values[$this->getPostVar()]["time"]))
228  {
229  $this->setDate(new ilDateTime($a_values[$this->getPostVar()]["date"].' '.$a_values[$this->getPostVar()]["time"],
230  IL_CAL_DATETIME,$ilUser->getTimeZone()));
231  }
232  else
233  {
234  if (isset($a_values[$this->getPostVar()]["date"]))
235  {
236  $this->setDate(new ilDate($a_values[$this->getPostVar()]["date"],
237  IL_CAL_DATE));
238  }
239  }
240  foreach($this->getSubItems() as $item)
241  {
242  $item->setValueByArray($a_values);
243  }
244  }
245 
251  function checkInput()
252  {
253  global $lng,$ilUser;
254 
255  $ok = true;
256 
257  if (!$this->getDisabled())
258  {
259  $_POST[$this->getPostVar()]["date"]["y"] =
260  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["y"]);
261  $_POST[$this->getPostVar()]["date"]["m"] =
262  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["m"]);
263  $_POST[$this->getPostVar()]["date"]["d"] =
264  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["d"]);
265  $_POST[$this->getPostVar()]["time"]["h"] =
266  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["h"]);
267  $_POST[$this->getPostVar()]["time"]["m"] =
268  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["m"]);
269  $_POST[$this->getPostVar()]["time"]["s"] =
270  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["s"]);
271 
272  // verify date
273 
274  $dt['year'] = (int) $_POST[$this->getPostVar()]['date']['y'];
275  $dt['mon'] = (int) $_POST[$this->getPostVar()]['date']['m'];
276  $dt['mday'] = (int) $_POST[$this->getPostVar()]['date']['d'];
277  $dt['hours'] = (int) $_POST[$this->getPostVar()]['time']['h'];
278  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['time']['m'];
279  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['time']['s'];
280  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
281  $timestamp = $date->get(IL_CAL_UNIX);
282  if ($_POST[$this->getPostVar()]["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
283  $_POST[$this->getPostVar()]["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
284  $_POST[$this->getPostVar()]["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
285  {
286  $this->setAlert($lng->txt("exc_date_not_valid"));
287  $ok = false;
288  }
289 
290  $_POST[$this->getPostVar()]['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
291  $_POST[$this->getPostVar()]['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
292 
293  /*
294  $_POST[$this->getPostVar()]["time"] =
295  str_pad($_POST[$this->getPostVar()]["time"]["h"], 2 , "0", STR_PAD_LEFT).":".
296  str_pad($_POST[$this->getPostVar()]["time"]["m"], 2 , "0", STR_PAD_LEFT).":".
297  str_pad($_POST[$this->getPostVar()]["time"]["s"], 2 , "0", STR_PAD_LEFT);
298 
299  $_POST[$this->getPostVar()]["date"] =
300  str_pad($_POST[$this->getPostVar()]["date"]["y"], 4 , "0", STR_PAD_LEFT)."-".
301  str_pad($_POST[$this->getPostVar()]["date"]["m"], 2 , "0", STR_PAD_LEFT)."-".
302  str_pad($_POST[$this->getPostVar()]["date"]["d"], 2 , "0", STR_PAD_LEFT);
303  */
304  $this->setDate($date);
305  }
306  return $ok;
307  }
308 
313  function render()
314  {
315  global $lng,$ilUser;
316 
317  $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
318 
319  if(is_a($this->getDate(),'ilDate'))
320  {
321  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'','UTC');
322  }
323  elseif(is_a($this->getDate(),'ilDateTime'))
324  {
325  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
326  }
327  else
328  {
329  $this->setDate(new ilDateTime(time(), IL_CAL_UNIX));
330  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
331  //$date_info = getdate(time());
332  }
333 
334  $lng->loadLanguageModule("jscalendar");
335  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
337 
338  if(strlen($this->getActivationPostVar()))
339  {
340  $tpl->setCurrentBlock('prop_date_activation');
341  $tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
342  $tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
343  $tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
344  $tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
345  $tpl->parseCurrentBlock();
346  }
347 
348  if ($this->getShowDate())
349  {
350  $tpl->setCurrentBlock("prop_date");
351  $tpl->setVariable("IMG_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
352  $tpl->setVariable("TXT_DATE_CALENDAR", $lng->txt("open_calendar"));
353  $tpl->setVariable("DATE_ID", $this->getPostVar());
354  $tpl->setVariable("INPUT_FIELDS_DATE", $this->getPostVar()."[date]");
355  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
356  $tpl->setVariable('DATE_FIRST_DAY',ilCalendarUserSettings::_getInstance()->getWeekStart());
357  $tpl->setVariable("DATE_SELECT",
358  ilUtil::makeDateSelect($this->getPostVar()."[date]", $date_info['year'], $date_info['mon'], $date_info['mday'],
359  $this->startyear,true,array('disabled' => $this->getDisabled()), $this->getShowEmpty()));
360  $tpl->parseCurrentBlock();
361 
362  }
363  if($this->getShowTime())
364  {
365  $tpl->setCurrentBlock("prop_time");
366  #$time = explode(":", $this->getTime());
367  $tpl->setVariable("TIME_SELECT",
368  ilUtil::makeTimeSelect($this->getPostVar()."[time]", !$this->getShowSeconds(),
369  $date_info['hours'], $date_info['minutes'], $date_info['seconds'],
370  true,array('minute_steps' => $this->getMinuteStepSize(),
371  'disabled' => $this->getDisabled())));
372 
373 
374  $tpl->setVariable("TXT_TIME", $this->getShowSeconds()
375  ? "(".$lng->txt("hh_mm_ss").")"
376  : "(".$lng->txt("hh_mm").")");
377  $tpl->parseCurrentBlock();
378  }
379 
380  if ($this->getShowTime() && $this->getShowDate())
381  {
382  $tpl->setVariable("DELIM", "<br />");
383  }
384 
385  return $tpl->get();
386  }
387 
393  function insert(&$a_tpl)
394  {
395  $html = $this->render();
396 
397  $a_tpl->setCurrentBlock("prop_generic");
398  $a_tpl->setVariable("PROP_GENERIC", $html);
399  $a_tpl->parseCurrentBlock();
400  }
401 
406  {
407  $html = $this->render();
408  return $html;
409  }
410 
414  function serializeData()
415  {
416  return serialize($this->getDate());
417  }
418 
422  function unserializeData($a_data)
423  {
424  $data = unserialize($a_data);
425 
426  if (is_object($data))
427  {
428  $this->setDate($data);
429  }
430  }
431 
432 }
433 
434 ?>