ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDateTimeInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
33  protected $date_obj = null;
34  protected $date;
35  protected $showdate = true;
36  protected $time = "00:00:00";
37  protected $showtime = false;
38  protected $showseconds = false;
39  protected $minute_step_size = 1;
40 
41  protected $activation_title = '';
42  protected $activation_post_var = '';
43 
50  function __construct($a_title = "", $a_postvar = "")
51  {
52  parent::__construct($a_title, $a_postvar);
53  $this->setType("datetime");
54  }
55 
66  public function enableDateActivation($a_title,$a_postvar,$a_checked = true)
67  {
68  $this->activation_title = $a_title;
69  $this->activation_post_var = $a_postvar;
70  $this->activation_checked = $a_checked;
71  }
72 
79  public function getActivationPostVar()
80  {
82  }
83 
95  function setDate(ilDateTime $a_date)
96  {
97  $this->date = $a_date;
98  }
99 
105  function getDate()
106  {
107  return $this->date;
108  }
109 
115  function setShowDate($a_showdate)
116  {
117  $this->showdate = $a_showdate;
118  }
119 
125  function getShowDate()
126  {
127  return $this->showdate;
128  }
129 
135  function setShowTime($a_showtime)
136  {
137  $this->showtime = $a_showtime;
138  }
139 
145  function getShowTime()
146  {
147  return $this->showtime;
148  }
149 
158  public function setMinuteStepSize($a_step_size)
159  {
160  $this->minute_step_size = $a_step_size;
161  }
162 
169  public function getMinuteStepSize()
170  {
172  }
173 
174 
175 
181  function setShowSeconds($a_showseconds)
182  {
183  $this->showseconds = $a_showseconds;
184  }
185 
191  function getShowSeconds()
192  {
193  return $this->showseconds;
194  }
195 
201  function setValueByArray($a_values)
202  {
203  global $ilUser;
204 
205  if(isset($a_values[$this->getPostVar()]["time"]))
206  {
207  $this->setDate(new ilDateTime($a_values[$this->getPostVar()]["date"].' '.$a_values[$this->getPostVar()]["time"],
208  IL_CAL_DATETIME,$ilUser->getTimeZone()));
209  }
210  else
211  {
212  $this->setDate(new ilDate($a_values[$this->getPostVar()]["date"],
213  IL_CAL_DATE));
214  }
215  foreach($this->getSubItems() as $item)
216  {
217  $item->setValueByArray($a_values);
218  }
219  }
220 
226  function checkInput()
227  {
228  global $lng,$ilUser;
229 
230  $ok = true;
231 
232  $_POST[$this->getPostVar()]["date"]["y"] =
233  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["y"]);
234  $_POST[$this->getPostVar()]["date"]["m"] =
235  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["m"]);
236  $_POST[$this->getPostVar()]["date"]["d"] =
237  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["d"]);
238  $_POST[$this->getPostVar()]["time"]["h"] =
239  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["h"]);
240  $_POST[$this->getPostVar()]["time"]["m"] =
241  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["m"]);
242  $_POST[$this->getPostVar()]["time"]["s"] =
243  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["s"]);
244 
245  // verify date
246 
247  $dt['year'] = (int) $_POST[$this->getPostVar()]['date']['y'];
248  $dt['mon'] = (int) $_POST[$this->getPostVar()]['date']['m'];
249  $dt['mday'] = (int) $_POST[$this->getPostVar()]['date']['d'];
250  $dt['hours'] = (int) $_POST[$this->getPostVar()]['time']['h'];
251  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['time']['m'];
252  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['time']['s'];
253  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
254  $timestamp = $date->get(IL_CAL_UNIX);
255  if ($_POST[$this->getPostVar()]["date"]["d"] != $date->get(IL_CAL_FKT_DATE,'d',$ilUser->getTimeZone()) ||
256  $_POST[$this->getPostVar()]["date"]["m"] != $date->get(IL_CAL_FKT_DATE,'m',$ilUser->getTimeZone()) ||
257  $_POST[$this->getPostVar()]["date"]["y"] != $date->get(IL_CAL_FKT_DATE,'Y',$ilUser->getTimeZone()))
258  {
259  $this->setAlert($lng->txt("exc_date_not_valid"));
260  $ok = false;
261  }
262 
263  $_POST[$this->getPostVar()]['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
264  $_POST[$this->getPostVar()]['time'] = $date->get(IL_CAL_FKT_DATE,'H:i:s',$ilUser->getTimeZone());
265 
266  /*
267  $_POST[$this->getPostVar()]["time"] =
268  str_pad($_POST[$this->getPostVar()]["time"]["h"], 2 , "0", STR_PAD_LEFT).":".
269  str_pad($_POST[$this->getPostVar()]["time"]["m"], 2 , "0", STR_PAD_LEFT).":".
270  str_pad($_POST[$this->getPostVar()]["time"]["s"], 2 , "0", STR_PAD_LEFT);
271 
272  $_POST[$this->getPostVar()]["date"] =
273  str_pad($_POST[$this->getPostVar()]["date"]["y"], 4 , "0", STR_PAD_LEFT)."-".
274  str_pad($_POST[$this->getPostVar()]["date"]["m"], 2 , "0", STR_PAD_LEFT)."-".
275  str_pad($_POST[$this->getPostVar()]["date"]["d"], 2 , "0", STR_PAD_LEFT);
276  */
277  $this->setDate($date);
278  return $ok;
279  }
280 
285  function insert(&$a_tpl)
286  {
287  global $lng,$ilUser;
288 
289  if(is_a($this->getDate(),'ilDate'))
290  {
291  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'','UTC');
292  }
293  elseif(is_a($this->getDate(),'ilDateTime'))
294  {
295  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
296  }
297  else
298  {
299  $this->setDate(new ilDateTime(time(), IL_CAL_UNIX));
300  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'',$ilUser->getTimeZone());
301  //$date_info = getdate(time());
302  }
303 
304  $lng->loadLanguageModule("jscalendar");
305  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
307 
308  if(strlen($this->getActivationPostVar()))
309  {
310  $a_tpl->setCurrentBlock('prop_date_activation');
311  $a_tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
312  $a_tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
313  $a_tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
314  $a_tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
315  $a_tpl->parseCurrentBlock();
316  }
317 
318  if ($this->getShowDate())
319  {
320  $a_tpl->setCurrentBlock("prop_date");
321  $a_tpl->setVariable("IMG_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
322  $a_tpl->setVariable("TXT_DATE_CALENDAR", $lng->txt("open_calendar"));
323  $a_tpl->setVariable("DATE_ID", $this->getPostVar());
324  $a_tpl->setVariable("INPUT_FIELDS_DATE", $this->getPostVar()."[date]");
325  $a_tpl->setVariable("DATE_SELECT",
326  ilUtil::makeDateSelect($this->getPostVar()."[date]", $date_info['year'], $date_info['mon'], $date_info['mday'],
327  '',true,array('disabled' => $this->getDisabled())));
328  $a_tpl->parseCurrentBlock();
329 
330  }
331  if($this->getShowTime())
332  {
333  $a_tpl->setCurrentBlock("prop_time");
334  #$time = explode(":", $this->getTime());
335  $a_tpl->setVariable("TIME_SELECT",
336  ilUtil::makeTimeSelect($this->getPostVar()."[time]", !$this->getShowSeconds(),
337  $date_info['hours'], $date_info['minutes'], $date_info['seconds'],
338  true,array('minute_steps' => $this->getMinuteStepSize(),
339  'disabled' => $this->getDisabled())));
340 
341 
342  $a_tpl->setVariable("TXT_TIME", $this->getShowSeconds()
343  ? "(".$lng->txt("hh_mm_ss").")"
344  : "(".$lng->txt("hh_mm").")");
345  $a_tpl->parseCurrentBlock();
346  }
347  $a_tpl->setCurrentBlock("prop_datetime");
348  if ($this->getShowTime() && $this->getShowDate())
349  {
350  $a_tpl->setVariable("DELIM", "<br />");
351  }
352  $a_tpl->parseCurrentBlock();
353  }
354 
355 }
356