ILIAS  Release_4_2_x_branch Revision 61807
 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  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  }
93  else
94  {
95  if (!checkdate((int)$dt['mon'], (int)$dt['mday'], (int)$dt['year']))
96  {
97  $this->date = null;
98  $this->setAlert($lng->txt("exc_date_not_valid"));
99  return false;
100  }
101  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE,$ilUser->getTimeZone());
102  $_POST[$this->getPostVar()]['date'] = $date->get(IL_CAL_FKT_DATE,'Y-m-d',$ilUser->getTimeZone());
103  $this->setDate($date);
104  }
105  return true;
106  }
107 
112  function render()
113  {
114  global $lng,$ilUser;
115 
116  $tpl = new ilTemplate("tpl.prop_datetime.html", true, true, "Services/Form");
117  if (is_object($this->getDate()))
118  {
119  $date_info = $this->getDate()->get(IL_CAL_FKT_GETDATE,'','UTC');
120  }
121  else
122  {
123  $date_info = array(
124  'year' => $_POST[$this->getPostVar()]['date']['y'],
125  'mon' => $_POST[$this->getPostVar()]['date']['m'],
126  'mday' => $_POST[$this->getPostVar()]['date']['d']
127  );
128  }
129 
130  $lng->loadLanguageModule("jscalendar");
131  require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
133 
134  if(strlen($this->getActivationPostVar()))
135  {
136  $tpl->setCurrentBlock('prop_date_activation');
137  $tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
138  $tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
139  $tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
140  $tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
141  $tpl->parseCurrentBlock();
142  }
143 
144  if ($this->getShowDate())
145  {
146  $tpl->setCurrentBlock("prop_date");
147  $tpl->setVariable("IMG_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
148  $tpl->setVariable("TXT_DATE_CALENDAR", $lng->txt("open_calendar"));
149  $tpl->setVariable("DATE_ID", $this->getPostVar());
150  $tpl->setVariable("INPUT_FIELDS_DATE", $this->getPostVar()."[date]");
151  include_once './Services/Calendar/classes/class.ilCalendarUserSettings.php';
152  $tpl->setVariable('DATE_FIRST_DAY',ilCalendarUserSettings::_getInstance()->getWeekStart());
153  $tpl->setVariable("DATE_SELECT",
154  ilUtil::makeDateSelect($this->getPostVar()."[date]", $date_info['year'], $date_info['mon'], $date_info['mday'],
155  $this->startyear,true,array('disabled' => $this->getDisabled()), $this->getShowEmpty()));
156  $tpl->parseCurrentBlock();
157 
158  }
159  return $tpl->get();
160  }
161 }
162 ?>