Adjusted week start for subgroups.
[timetracker.git] / WEB-INF / lib / form / DateField.class.php
index db59a3b..a197126 100644 (file)
@@ -33,63 +33,59 @@ class DateField extends TextField {
   var $mWeekStartDay = 0;
   var $mDateFormat  = "d/m/Y";
   var $lToday      = "Today";
-
   var $mDateObj;
-  var $cClassName  = "DateField";
 
   var $lCalendarButtons = array('today'=>'Today', 'close'=>'Close');
 
   function __construct($name) {
-    $this->mName  = $name;
-    $this->mDateObj  = new DateAndTime();
-
-    if (isset($GLOBALS["I18N"])) {
-      $this->setLocalization($GLOBALS["I18N"]);
-    }
+    $this->class = 'DateField';
+    $this->name = $name;
+    $this->mDateObj = new DateAndTime();
+    $this->localize();
   }
 
-  function setLocalization($i18n)  {
-       global $user;
+  function localize()  {
+    global $user;
+    global $i18n;
        
-    FormElement::setLocalization($i18n);
-    $this->mDateObj->setFormat($user->date_format);
+    $this->mDateObj->setFormat($user->getDateFormat());
 
     $this->mMonthNames = $i18n->monthNames;
     $this->mWeekDayShortNames = $i18n->weekdayShortNames;
-    $this->lToday = $i18n->getKey('label.today');
-    $this->lCalendarButtons['today'] = $i18n->getKey('label.today');
-    $this->lCalendarButtons['close'] = $i18n->getKey('button.close');
+    $this->lToday = $i18n->get('label.today');
+    $this->lCalendarButtons['today'] = $i18n->get('label.today');
+    $this->lCalendarButtons['close'] = $i18n->get('button.close');
 
-    $this->mDateFormat = $user->date_format;
-    $this->mWeekStartDay = $user->week_start;
+    $this->mDateFormat = $user->getDateFormat();
+    $this->mWeekStartDay = $user->getWeekStart();
   }
 
   // set current value taken from session or database
   function setValueSafe($value)  {
     if (isset($value) && (strlen($value) > 0)) {
       $this->mDateObj->parseVal($value, DB_DATEFORMAT);
-      $this->mValue = $this->mDateObj->toString($this->mDateFormat); //?
+      $this->value = $this->mDateObj->toString($this->mDateFormat); //?
     }
   }
   // get value for storing in session or database
   function getValueSafe() {
-    if (strlen($this->mValue)>0) {
-      $this->mDateObj->parseVal($this->mValue, $this->mDateFormat);  //?
+    if (strlen($this->value)>0) {
+      $this->mDateObj->parseVal($this->value, $this->mDateFormat);  //?
       return $this->mDateObj->toString(DB_DATEFORMAT);
     } else {
       return null;
     }
   }
 
-  function toStringControl()  {
-    if (!$this->isRenderable()) return "";
+  function getHtml() {
+    global $user;
 
-    if (!$this->isEnable()) {
+    if (!$this->isEnabled()) {
       $html = htmlspecialchars($this->getValue()).
-        "<input type=\"hidden\" name=\"$this->mName\" value=\"".htmlspecialchars($this->getValue())."\">\n";
+        "<input type=\"hidden\" name=\"$this->name\" value=\"".htmlspecialchars($this->getValue())."\">\n";
     } else {
 
-        if ($this->mId=="") $this->mId = $this->mName;
+        if ($this->id=="") $this->id = $this->name;
 
       $html = "";
 
@@ -299,9 +295,7 @@ class DateField extends TextField {
 
 
             function getDateString(dateVal) {\n";
-            if (isset($GLOBALS['i18n'])) {
-              $html .= "dateVal.locale = \"".$GLOBALS['i18n']->lang."\";\n";
-            }
+            $html .= "dateVal.locale = \"".$user->lang."\";\n";
             $html .=  "return dateVal.strftime(dateFormat);
             }
 
@@ -393,24 +387,21 @@ class DateField extends TextField {
       $html .= "</script>\n";
 
       $html .= "\n\t<input type=\"text\"";
-      $html .= " name=\"$this->mName\" id=\"$this->mId\"";
+      $html .= " name=\"$this->name\" id=\"$this->id\"";
 
-      if ($this->mSize!="")
-        $html .= " size=\"$this->mSize\"";
+      if ($this->size!="")
+        $html .= " size=\"$this->size\"";
 
-      if ($this->mStyle!="")
-         $html .= " style=\"$this->mStyle\"";
+      if ($this->style!="")
+         $html .= " style=\"$this->style\"";
 
         $html .= " maxlength=\"50\"";
 
-      if ($this->mOnChange!="")
-         $html .= " onchange=\"$this->mOnChange\"";
-
-      if ($this->mOnClick!="")
-         $html .= " onclick=\"$this->mOnClick\"";
+      if ($this->on_change!="")
+         $html .= " onchange=\"$this->on_change\"";
 
-      if ($this->mOnFocus!="")
-         $html .= " onfocus=\"$this->mOnFocus\"";
+      if ($this->on_click!="")
+         $html .= " onclick=\"$this->on_click\"";
 
       $html .= " value=\"".htmlspecialchars($this->getValue())."\"";
       $html .= ">";
@@ -418,7 +409,7 @@ class DateField extends TextField {
       if (APP_NAME)
        $app_root = '/'.APP_NAME;
 
-      $html .= "&nbsp;<img src=\"".$app_root."/images/calendar.gif\" width=\"16\" height=\"16\" onclick=\"displayDatePicker('".$this->mName."');\">\n";
+      $html .= "&nbsp;<img src=\"".$app_root."/images/calendar.gif\" width=\"16\" height=\"16\" onclick=\"displayDatePicker('".$this->name."');\">\n";
     }
 
     return $html;