ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBirthdayInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Form/classes/class.ilDateTimeInputGUI.php");
5 
14 {
20  function setValueByArray($a_values)
21  {
22  if (is_array($a_values[$this->getPostVar()]["date"]))
23  {
24  if (@checkdate($a_values[$this->getPostVar()]["date"]['m'], $a_values[$this->getPostVar()]["date"]['d'], $a_values[$this->getPostVar()]["date"]['y']))
25  {
26  parent::setValueByArray($a_values);
27  return;
28  }
29  }
30  else
31  {
32  if (!is_array($a_values[$this->getPostVar()]) && strlen($a_values[$this->getPostVar()]))
33  {
34  $this->setDate(new ilDate($a_values[$this->getPostVar()], IL_CAL_DATE));
35  }
36  else
37  {
38  $this->date = null;
39  }
40  }
41  foreach($this->getSubItems() as $item)
42  {
43  $item->setValueByArray($a_values);
44  }
45  }
46 
52  function checkInput()
53  {
54  global $lng,$ilUser;
55 
56  $ok = true;
57 
58  $_POST[$this->getPostVar()]["date"]["y"] =
59  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["y"]);
60  $_POST[$this->getPostVar()]["date"]["m"] =
61  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["m"]);
62  $_POST[$this->getPostVar()]["date"]["d"] =
63  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["d"]);
64  $_POST[$this->getPostVar()]["time"]["h"] =
65  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["h"]);
66  $_POST[$this->getPostVar()]["time"]["m"] =
67  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["m"]);
68  $_POST[$this->getPostVar()]["time"]["s"] =
69  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["s"]);
70 
71  // verify date
72 
73  $dt['year'] = (int) $_POST[$this->getPostVar()]['date']['y'];
74  $dt['mon'] = (int) $_POST[$this->getPostVar()]['date']['m'];
75  $dt['mday'] = (int) $_POST[$this->getPostVar()]['date']['d'];
76  $dt['hours'] = (int) $_POST[$this->getPostVar()]['time']['h'];
77  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['time']['m'];
78  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['time']['s'];
79  if ($dt['year'] == 0 && $dt['mon'] == 0 && $dt['mday'] == 0 && $this->getRequired())
80  {
81  $this->date = null;
82  $this->setAlert($lng->txt("msg_input_is_required"));
83  return false;
84  }
85  else if ($dt['year'] == 0 && $dt['mon'] == 0 && $dt['mday'] == 0)
86  {
87  $this->date = null;
88  }
89  else
90  {
91  if (!checkdate((int)$dt['mon'], (int)$dt['mday'], (int)$dt['year']))
92  {
93  $this->date = null;
94  $this->setAlert($lng->txt("exc_date_not_valid"));
95  return false;
96  }
97  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
98  $_POST[$this->getPostVar()]['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
99  $this->setDate($date);
100  }
101  return true;
102  }
103 
108  function render()
109  {
110  global $lng,$ilUser;
111 
112  $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
113  if (is_object($this->getDate()))
114  {
115  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'','UTC');
116  }
117  else
118  {
119  $date_info = array(
120  'year' => $_POST[$this->getPostVar()]['date']['y'],
121  'mon' => $_POST[$this->getPostVar()]['date']['m'],
122  'mday' => $_POST[$this->getPostVar()]['date']['d']
123  );
124  }
125 
126  $lng->loadLanguageModule("jscalendar");
127  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
129 
130  if(strlen($this->getActivationPostVar()))
131  {
132  $tpl->setCurrentBlock('prop_date_activation');
133  $tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
134  $tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
135  $tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
136  $tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
137  $tpl->parseCurrentBlock();
138  }
139 
140  if ($this->getShowDate())
141  {
142  $tpl->setCurrentBlock("prop_date");
143  $tpl->setVariable("IMG_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
144  $tpl->setVariable("TXT_DATE_CALENDAR", $lng->txt("open_calendar"));
145  $tpl->setVariable("DATE_ID", $this->getPostVar());
146  $tpl->setVariable("INPUT_FIELDS_DATE", $this->getPostVar()."[date]");
147  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
148  $tpl->setVariable('DATE_FIRST_DAY',ilCalendarUserSettings::_getInstance()->getWeekStart());
149  $tpl->setVariable("DATE_SELECT",
150  ilUtil::makeDateSelect($this->getPostVar()."[date]", $date_info['year'], $date_info['mon'], $date_info['mday'],
151  $this->startyear,true,array('disabled' => $this->getDisabled()), $this->getShowEmpty()));
152  $tpl->parseCurrentBlock();
153 
154  }
155  return $tpl->get();
156  }
157 }
158 ?>