ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDurationInputGUI.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 $months = 0;
34  protected $days = 0;
35  protected $hours = 0;
36  protected $minutes = 0;
37  protected $seconds = 0;
38  protected $showmonths = false;
39  protected $showdays = false;
40  protected $showhours = true;
41  protected $showminutes = true;
42  protected $showseconds = false;
43 
50  function __construct($a_title = "", $a_postvar = "")
51  {
52  parent::__construct($a_title, $a_postvar);
53  $this->setType("duration");
54  }
55 
61  function setDays($a_days)
62  {
63  $this->days = $a_days;
64  }
65 
71  function getDays()
72  {
73  return $this->days;
74  }
75 
81  function setHours($a_hours)
82  {
83  $this->hours = $a_hours;
84  }
85 
91  function getHours()
92  {
93  return $this->hours;
94  }
95 
101  function setMinutes($a_minutes)
102  {
103  $this->minutes = $a_minutes;
104  }
105 
111  function getMinutes()
112  {
113  return $this->minutes;
114  }
115 
121  function setSeconds($a_seconds)
122  {
123  $this->seconds = $a_seconds;
124  }
125 
133  public function setMonths($a_months)
134  {
135  $this->months = $a_months;
136  }
137 
144  public function getMonths()
145  {
146  return $this->months;
147  }
148 
154  function getSeconds()
155  {
156  return $this->seconds;
157  }
158 
165  public function setShowMonths($a_show_months)
166  {
167  $this->showmonths = $a_show_months;
168  }
169 
175  public function getShowMonths()
176  {
177  return $this->showmonths;
178  }
179 
185  function setShowDays($a_showdays)
186  {
187  $this->showdays = $a_showdays;
188  }
189 
195  function getShowDays()
196  {
197  return $this->showdays;
198  }
199 
205  function setShowHours($a_showhours)
206  {
207  $this->showhours = $a_showhours;
208  }
209 
215  function getShowHours()
216  {
217  return $this->showhours;
218  }
219 
225  function setShowMinutes($a_showminutes)
226  {
227  $this->showminutes = $a_showminutes;
228  }
229 
235  function getShowMinutes()
236  {
237  return $this->showminutes;
238  }
239 
245  function setShowSeconds($a_showseconds)
246  {
247  $this->showseconds = $a_showseconds;
248  }
249 
255  function getShowSeconds()
256  {
257  return $this->showseconds;
258  }
259 
265  function setValueByArray($a_values)
266  {
267  $this->setMonths($a_values[$this->getPostVar()]["MM"]);
268  $this->setDays($a_values[$this->getPostVar()]["dd"]);
269  $this->setHours($a_values[$this->getPostVar()]["hh"]);
270  $this->setMinutes($a_values[$this->getPostVar()]["mm"]);
271  $this->setSeconds($a_values[$this->getPostVar()]["ss"]);
272  }
273 
279  function checkInput()
280  {
281  global $lng;
282 
283  $_POST[$this->getPostVar()]["MM"] =
284  ilUtil::stripSlashes($_POST[$this->getPostVar()]["MM"]);
285  $_POST[$this->getPostVar()]["dd"] =
286  ilUtil::stripSlashes($_POST[$this->getPostVar()]["dd"]);
287  $_POST[$this->getPostVar()]["hh"] =
288  ilUtil::stripSlashes($_POST[$this->getPostVar()]["hh"]);
289  $_POST[$this->getPostVar()]["mm"] =
290  ilUtil::stripSlashes($_POST[$this->getPostVar()]["mm"]);
291  $_POST[$this->getPostVar()]["ss"] =
292  ilUtil::stripSlashes($_POST[$this->getPostVar()]["ss"]);
293 
294  return true;
295  }
296 
302  function insert(&$a_tpl)
303  {
304  $html = $this->render();
305 
306  $a_tpl->setCurrentBlock("prop_generic");
307  $a_tpl->setVariable("PROP_GENERIC", $html);
308  $a_tpl->parseCurrentBlock();
309  }
310 
315  function render()
316  {
317  global $lng;
318 
319  $tpl = new ilTemplate("tpl.prop_duration.html", true, true, "Services/Form");
320 
321  if($this->getShowMonths())
322  {
323  $tpl->setCurrentBlock("dur_months");
324  $tpl->setVariable("TXT_MONTHS", $lng->txt("form_months"));
325  $val = array();
326  for ($i=0; $i<=36; $i++)
327  {
328  $val[$i] = $i;
329  }
330  $tpl->setVariable("SELECT_MONTHS",
331  ilUtil::formSelect($this->getMonths(), $this->getPostVar()."[MM]",
332  $val, false, true));
333  $tpl->parseCurrentBlock();
334  }
335  if ($this->getShowDays())
336  {
337  $tpl->setCurrentBlock("dur_days");
338  $tpl->setVariable("TXT_DAYS", $lng->txt("form_days"));
339  $val = array();
340  for ($i=0; $i<=366; $i++)
341  {
342  $val[$i] = $i;
343  }
344  $tpl->setVariable("SELECT_DAYS",
345  ilUtil::formSelect($this->getDays(), $this->getPostVar()."[dd]",
346  $val, false, true));
347  $tpl->parseCurrentBlock();
348  }
349  if ($this->getShowHours())
350  {
351  $tpl->setCurrentBlock("dur_hours");
352  $tpl->setVariable("TXT_HOURS", $lng->txt("form_hours"));
353  $val = array();
354  for ($i=0; $i<=23; $i++)
355  {
356  $val[$i] = $i;
357  }
358  $tpl->setVariable("SELECT_HOURS",
359  ilUtil::formSelect($this->getHours(), $this->getPostVar()."[hh]",
360  $val, false, true));
361  $tpl->parseCurrentBlock();
362  }
363  if ($this->getShowMinutes())
364  {
365  $tpl->setCurrentBlock("dur_minutes");
366  $tpl->setVariable("TXT_MINUTES", $lng->txt("form_minutes"));
367  $val = array();
368  for ($i=0; $i<=59; $i++)
369  {
370  $val[$i] = $i;
371  }
372  $tpl->setVariable("SELECT_MINUTES",
373  ilUtil::formSelect($this->getMinutes(), $this->getPostVar()."[mm]",
374  $val, false, true));
375  $tpl->parseCurrentBlock();
376  }
377  if ($this->getShowSeconds())
378  {
379  $tpl->setCurrentBlock("dur_seconds");
380  $tpl->setVariable("TXT_SECONDS", $lng->txt("form_seconds"));
381  $val = array();
382  for ($i=0; $i<=59; $i++)
383  {
384  $val[$i] = $i;
385  }
386  $tpl->setVariable("SELECT_SECONDS",
387  ilUtil::formSelect($this->getSeconds(), $this->getPostVar()."[ss]",
388  $val, false, true));
389  $tpl->parseCurrentBlock();
390  }
391 
392  return $tpl->get();
393  }
394 
399  {
400  $html = $this->render();
401  return $html;
402  }
403 
407  function serializeData()
408  {
409  $data = array("months" => $this->getMonths(),
410  "days" => $this->getDays(),
411  "hours" => $this->getHours(),
412  "minutes" => $this->getMinutes(),
413  "seconds" => $this->getSeconds());
414 
415  return serialize($data);
416  }
417 
421  function unserializeData($a_data)
422  {
423  $data = unserialize($a_data);
424 
425  $this->setMonths($data["months"]);
426  $this->setDays($data["days"]);
427  $this->setHours($data["hours"]);
428  $this->setMinutes($data["minutes"]);
429  $this->setSeconds($data["seconds"]);
430  }
431 
437  public function getValueInSeconds()
438  {
439  $value = 0;
440  if($this->getShowMonths())
441  {
442  $value += $this->getMonths()*30*24*60*60;
443  }
444  if($this->getShowDays())
445  {
446  $value += $this->getDays()*24*60*60;
447  }
448  if($this->getShowHours())
449  {
450  $value += $this->getHours()*60*60;
451  }
452  if($this->getShowMinutes())
453  {
454  $value += $this->getMinutes()*60;
455  }
456  if($this->getShowSeconds())
457  {
458  $value += $this->getSeconds();
459  }
460  return $value;
461  }
462 }
463 ?>