ILIAS  Release_4_4_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 (isset($a_values[$this->getPostVar()]["date"]) && 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  elseif(is_array($a_values[$this->getPostVar()]) && isset($a_values[$this->getPostVar()]["date"]) && !is_array($a_values[$this->getPostVar()]["date"]))
31  {
32  $this->setDate(new ilDate($a_values[$this->getPostVar()]["date"], IL_CAL_DATE));
33  }
34  else
35  {
36  if (!is_array($a_values[$this->getPostVar()]) && strlen($a_values[$this->getPostVar()]))
37  {
38  $this->setDate(new ilDate($a_values[$this->getPostVar()], IL_CAL_DATE));
39  }
40  else
41  {
42  $this->date = null;
43  }
44  }
45  foreach($this->getSubItems() as $item)
46  {
47  $item->setValueByArray($a_values);
48  }
49  }
50 
56  function checkInput()
57  {
58  global $lng,$ilUser;
59 
60  $ok = true;
61 
62  $_POST[$this->getPostVar()]["date"]["y"] =
63  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["y"]);
64  $_POST[$this->getPostVar()]["date"]["m"] =
65  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["m"]);
66  $_POST[$this->getPostVar()]["date"]["d"] =
67  ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["d"]);
68  $_POST[$this->getPostVar()]["time"]["h"] =
69  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["h"]);
70  $_POST[$this->getPostVar()]["time"]["m"] =
71  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["m"]);
72  $_POST[$this->getPostVar()]["time"]["s"] =
73  ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["s"]);
74 
75  // verify date
76 
77  $dt['year'] = (int) $_POST[$this->getPostVar()]['date']['y'];
78  $dt['mon'] = (int) $_POST[$this->getPostVar()]['date']['m'];
79  $dt['mday'] = (int) $_POST[$this->getPostVar()]['date']['d'];
80  $dt['hours'] = (int) $_POST[$this->getPostVar()]['time']['h'];
81  $dt['minutes'] = (int) $_POST[$this->getPostVar()]['time']['m'];
82  $dt['seconds'] = (int) $_POST[$this->getPostVar()]['time']['s'];
83  if ($dt['year'] == 0 && $dt['mon'] == 0 && $dt['mday'] == 0 && $this->getRequired())
84  {
85  $this->date = null;
86  $this->setAlert($lng->txt("msg_input_is_required"));
87  return false;
88  }
89  else if ($dt['year'] == 0 && $dt['mon'] == 0 && $dt['mday'] == 0)
90  {
91  $this->date = null;
92  $_POST[$this->getPostVar()]['date'] = ""; // #10413
93  }
94  else
95  {
96  if (!checkdate((int)$dt['mon'], (int)$dt['mday'], (int)$dt['year']))
97  {
98  $this->date = null;
99  $this->setAlert($lng->txt("exc_date_not_valid"));
100  return false;
101  }
102  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
103  $_POST[$this->getPostVar()]['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
104  $this->setDate($date);
105  }
106  return true;
107  }
108 
113  function render()
114  {
115  global $lng,$ilUser;
116 
117  $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
118  if (is_object($this->getDate()))
119  {
120  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'','UTC');
121  }
122  else
123  {
124  $date_info = array(
125  'year' => $_POST[$this->getPostVar()]['date']['y'],
126  'mon' => $_POST[$this->getPostVar()]['date']['m'],
127  'mday' => $_POST[$this->getPostVar()]['date']['d']
128  );
129  }
130 
131  $lng->loadLanguageModule("jscalendar");
132  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
134 
135  if(strlen($this->getActivationPostVar()))
136  {
137  $tpl->setCurrentBlock('prop_date_activation');
138  $tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
139  $tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
140  $tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
141  $tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
142  $tpl->parseCurrentBlock();
143  }
144 
145  if ($this->getShowDate())
146  {
147  $tpl->setCurrentBlock("prop_date");
148  $tpl->setVariable("IMG_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
149  $tpl->setVariable("TXT_DATE_CALENDAR", $lng->txt("open_calendar"));
150  $tpl->setVariable("DATE_ID", $this->getPostVar());
151  $tpl->setVariable("INPUT_FIELDS_DATE", $this->getPostVar()."[date]");
152  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
153  $tpl->setVariable('DATE_FIRST_DAY',ilCalendarUserSettings::_getInstance()->getWeekStart());
154  $tpl->setVariable("DATE_SELECT",
155  ilUtil::makeDateSelect($this->getPostVar()."[date]", $date_info['year'], $date_info['mon'], $date_info['mday'],
156  $this->startyear,true,array('disabled' => $this->getDisabled()), $this->getShowEmpty()));
157  $tpl->parseCurrentBlock();
158 
159  }
160  return $tpl->get();
161  }
162 }
163 ?>