• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Form/classes/class.ilDateTimeInputGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2007 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00031 class ilDateTimeInputGUI extends ilFormPropertyGUI
00032 {
00033         protected $date;
00034         protected $showdate = true;
00035         protected $time = "00:00:00";
00036         protected $showtime = false;
00037         protected $showseconds = false;
00038         protected $minute_step_size = 1;
00039         
00040         protected $activation_title = '';
00041         protected $activation_post_var = '';
00042         
00049         function __construct($a_title = "", $a_postvar = "")
00050         {
00051                 parent::__construct($a_title, $a_postvar);
00052                 $this->setType("datetime");
00053         }
00054         
00065         public function enableDateActivation($a_title,$a_postvar,$a_checked = true)
00066         {
00067                 $this->activation_title = $a_title;
00068                 $this->activation_post_var = $a_postvar;
00069                 $this->activation_checked = $a_checked;
00070         }
00071         
00078         public function getActivationPostVar()
00079         {
00080                 return $this->activation_post_var;
00081         }
00082         
00090         public function setUnixTime($a_time)
00091         {
00092                 if($a_time)
00093                 {
00094                         $this->setDate(date('Y-m-d',$a_time));
00095                         $this->setTime(date('G:i:s',$a_time));
00096                 }
00097         }
00098         
00099 
00105         function setDate($a_date)
00106         {
00107                 $this->date = $a_date;
00108         }
00109 
00115         function getDate()
00116         {
00117                 return $this->date;
00118         }
00119 
00125         function setShowDate($a_showdate)
00126         {
00127                 $this->showdate = $a_showdate;
00128         }
00129 
00135         function getShowDate()
00136         {
00137                 return $this->showdate;
00138         }
00139 
00145         function setTime($a_time)
00146         {
00147                 $this->time = $a_time;
00148         }
00149 
00155         function getTime()
00156         {
00157                 return $this->time;
00158         }
00159 
00165         function setShowTime($a_showtime)
00166         {
00167                 $this->showtime = $a_showtime;
00168         }
00169 
00175         function getShowTime()
00176         {
00177                 return $this->showtime;
00178         }
00179         
00188         public function setMinuteStepSize($a_step_size)
00189         {
00190                 $this->minute_step_size = $a_step_size;
00191         }
00192         
00199         public function getMinuteStepSize()
00200         {
00201                 return $this->minute_step_size;
00202         }
00203 
00204 
00205 
00211         function setShowSeconds($a_showseconds)
00212         {
00213                 $this->showseconds = $a_showseconds;
00214         }
00215 
00221         function getShowSeconds()
00222         {
00223                 return $this->showseconds;
00224         }
00225         
00231         function setValueByArray($a_values)
00232         {
00233                 $this->setDate($a_values[$this->getPostVar()]["date"]);
00234                 $this->setTime($a_values[$this->getPostVar()]["time"]);
00235         }
00236 
00242         function checkInput()
00243         {
00244                 global $lng;
00245                 
00246                 $ok = true;
00247                 
00248                 $_POST[$this->getPostVar()]["date"]["y"] = 
00249                         ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["y"]);
00250                 $_POST[$this->getPostVar()]["date"]["m"] = 
00251                         ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["m"]);
00252                 $_POST[$this->getPostVar()]["date"]["d"] = 
00253                         ilUtil::stripSlashes($_POST[$this->getPostVar()]["date"]["d"]);
00254                 $_POST[$this->getPostVar()]["time"]["h"] = 
00255                         ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["h"]);
00256                 $_POST[$this->getPostVar()]["time"]["m"] = 
00257                         ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["m"]);
00258                 $_POST[$this->getPostVar()]["time"]["s"] = 
00259                         ilUtil::stripSlashes($_POST[$this->getPostVar()]["time"]["s"]);
00260 
00261                 // verify date
00262                 $timestamp = mktime(0,0,0,
00263                         $_POST[$this->getPostVar()]["date"]["m"],
00264                         $_POST[$this->getPostVar()]["date"]["d"],
00265                         $_POST[$this->getPostVar()]["date"]["y"]);
00266 
00267                 if ($_POST[$this->getPostVar()]["date"]["d"] != (int) date("d",$timestamp) ||
00268                         $_POST[$this->getPostVar()]["date"]["m"] != (int) date("m",$timestamp) ||
00269                         $_POST[$this->getPostVar()]["date"]["y"] != (int) date("Y",$timestamp))
00270                 {
00271                         $this->setAlert($lng->txt("exc_date_not_valid"));
00272                         $ok = false;
00273                 }
00274                 
00275                 $_POST[$this->getPostVar()]["time"] =
00276                         str_pad($_POST[$this->getPostVar()]["time"]["h"], 2 , "0", STR_PAD_LEFT).":".
00277                         str_pad($_POST[$this->getPostVar()]["time"]["m"], 2 , "0", STR_PAD_LEFT).":".
00278                         str_pad($_POST[$this->getPostVar()]["time"]["s"], 2 , "0", STR_PAD_LEFT);
00279                         
00280                 $_POST[$this->getPostVar()]["date"] =
00281                         str_pad($_POST[$this->getPostVar()]["date"]["y"], 4 , "0", STR_PAD_LEFT)."-".
00282                         str_pad($_POST[$this->getPostVar()]["date"]["m"], 2 , "0", STR_PAD_LEFT)."-".
00283                         str_pad($_POST[$this->getPostVar()]["date"]["d"], 2 , "0", STR_PAD_LEFT);
00284 
00285                 return $ok;
00286         }
00287 
00292         function insert(&$a_tpl)
00293         {
00294                 global $lng;
00295                 
00296                 
00297                 $lng->loadLanguageModule("jscalendar");
00298                 require_once("./Services/Calendar/classes/class.ilCalendarUtil.php");
00299                 ilCalendarUtil::initJSCalendar();
00300                 
00301                 if(strlen($this->getActivationPostVar()))
00302                 {
00303                         $a_tpl->setCurrentBlock('prop_date_activation');
00304                         $a_tpl->setVariable('CHECK_ENABLED_DATE',$this->getActivationPostVar());
00305                         $a_tpl->setVariable('TXT_DATE_ENABLED',$this->activation_title);
00306                         $a_tpl->setVariable('CHECKED_ENABLED',$this->activation_checked ? 'checked="checked"' : '');
00307                         $a_tpl->setVariable('CHECKED_DISABLED',$this->getDisabled() ? 'disabled="disabled" ' : '');
00308                         $a_tpl->parseCurrentBlock();
00309                 }
00310                 
00311                 if ($this->getShowDate())
00312                 {
00313                         $a_tpl->setCurrentBlock("prop_date");
00314                         $a_tpl->setVariable("IMG_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
00315                         $a_tpl->setVariable("TXT_DATE_CALENDAR", $lng->txt("open_calendar"));
00316                         $a_tpl->setVariable("DATE_ID", $this->getPostVar());
00317                         $a_tpl->setVariable("INPUT_FIELDS_DATE", $this->getPostVar()."[date]");
00318                         $date = explode("-", $this->getDate());
00319                         $a_tpl->setVariable("DATE_SELECT",
00320                                 ilUtil::makeDateSelect($this->getPostVar()."[date]", $date[0], $date[1], $date[2],
00321                                         '','',array('disabled' => $this->getDisabled())));
00322                         $a_tpl->parseCurrentBlock();
00323                                 
00324                 }
00325                 if ($this->getShowTime())
00326                 {
00327                         $a_tpl->setCurrentBlock("prop_time");
00328                         $time = explode(":", $this->getTime());
00329                         $a_tpl->setVariable("TIME_SELECT",
00330                                 ilUtil::makeTimeSelect($this->getPostVar()."[time]", !$this->getShowSeconds(),
00331                                 $time[0], $time[1], $time[2],
00332                                 true,array('minute_steps' => $this->getMinuteStepSize(),
00333                                                         'disabled' => $this->getDisabled())));
00334                                 
00335                         
00336                         $a_tpl->setVariable("TXT_TIME", $this->getShowSeconds()
00337                                 ? "(".$lng->txt("hh_mm_ss").")"
00338                                 : "(".$lng->txt("hh_mm").")");
00339                         $a_tpl->parseCurrentBlock();
00340                 }
00341                 $a_tpl->setCurrentBlock("prop_datetime");
00342                 if ($this->getShowTime() && $this->getShowDate())
00343                 {
00344                         $a_tpl->setVariable("DELIM", "<br />");
00345                 }
00346                 $a_tpl->parseCurrentBlock();
00347         }
00348 
00349 }
00350 

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1