From 366b06acb5a1ee14bfb8dded5e33c3f62992b85b Mon Sep 17 00:00:00 2001 From: jennylee Date: Mon, 3 Dec 2012 18:47:53 -0400 Subject: [PATCH 1/2] BUG-7569 Date Fields are not applying the mask when displaying saved dates. When applying the mask it was showing a rear message. I added some mask letters in 'masktophp' function, to give solution this issue, and I added some validations to apply the mask when displaying saved dates. --- gulliver/system/class.xmlform.php | 58 +++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index 589007a0c..2360d6de2 100755 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -4057,10 +4057,12 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText //$this->defaultValue = G::replaceDataField( $this->defaultValue, $owner->values); $id = "form[$this->name]"; - if ($this->renderMode != 'edit' && $value == 'today') { - $mask = str_replace( "%", "", $this->mask ); - $value = date( masktophp($mask) ); - return $value; + if ($this->renderMode == 'edit' && $this->renderMode == 'view') { + if ($value == 'today') { + $mask = str_replace( "%", "", $this->mask ); + $value = date( masktophp($mask) ); + return $value; + } } return $this->__draw_widget( $id, $value, $owner ); } @@ -4169,8 +4171,8 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText $mask = '%Y-%m-%d'; //set default } - if ($this->defaultValue == "today") { - $defaultValue = masktophp( $mask ); + if ($this->defaultValue != "") { + $defaultValue = masktophp( $mask ); } if (strpos( $mask, '%' ) === false) { @@ -4210,15 +4212,8 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText if (trim( $value ) == '' or $value == null) { $value = ''; //date ($tmp); } else { - switch (strtolower( $value )) { - case 'today': - $value = masktophp( $mask ); // $value = date($tmp); - break; - default: - if (! $this->verifyDateFormat( $value )) { - //$value=''; - break; - } + if ($value != "") { + $value = masktophp( $mask ); } } @@ -5473,6 +5468,39 @@ function masktophp ($mask) if (preg_match('/S/',$tmp)) { $tmp = str_replace("S", "s", $tmp); } + if (preg_match('/o/',$tmp)) { + $tmp = str_replace("o", "n", $tmp); + } + if (preg_match('/a/',$tmp)) { + $tmp = str_replace("a", "D", $tmp); + } + if (preg_match('/l/',$tmp)) { + $tmp = str_replace("l", "g", $tmp); + } + if (preg_match('/A/',$tmp)) { + $tmp = str_replace("A", "l", $tmp); + } + if (preg_match('/I/',$tmp)) { + $tmp = str_replace("I", "h", $tmp); + } + if (preg_match('/j/',$tmp)) { + $tmp = str_replace("j", "z", $tmp); + } + if (preg_match('/k/',$tmp)) { + $tmp = str_replace("k", "G", $tmp); + } + if (preg_match('/e/',$tmp)) { + $tmp = str_replace("e", "j", $tmp); + } + if (preg_match('/u/',$tmp)) { + $tmp = str_replace("u", "N", $tmp); + } + if (preg_match('/p/',$tmp)) { + $tmp = str_replace("p", "A", $tmp); + } + if (preg_match('/P/',$tmp)) { + $tmp = str_replace("P", "a", $tmp); + } $value = date($tmp); return $value; } From 70a735b501bea48b4833dd3768c24e7b48c83904 Mon Sep 17 00:00:00 2001 From: jennylee Date: Tue, 4 Dec 2012 12:07:30 -0400 Subject: [PATCH 2/2] BUG-7569 Date Fields are not applying the mask when displaying saved dates. When applaying the mask it was showing a rear message. I add some mask letters to function masktophp to solution this issue, and add some validations to applay the mask when displaying saved dates. --- gulliver/system/class.xmlform.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index 2360d6de2..276ad9bed 100755 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -4057,13 +4057,6 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText //$this->defaultValue = G::replaceDataField( $this->defaultValue, $owner->values); $id = "form[$this->name]"; - if ($this->renderMode == 'edit' && $this->renderMode == 'view') { - if ($value == 'today') { - $mask = str_replace( "%", "", $this->mask ); - $value = date( masktophp($mask) ); - return $value; - } - } return $this->__draw_widget( $id, $value, $owner ); } @@ -4096,7 +4089,7 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText } if ($v == 'today') { $mask = str_replace( "%", "", $this->mask ); - $v = date( masktophp($mask) ); + $v = date( masktophp($mask, $v) ); } $html = 'NSRequiredValue() . ' class="module_app_input___gray" id="form[' . $owner->name . '][' . $r . '][' . $this->name . ']" name="form[' . $owner->name . '][' . $r . '][' . $this->name . ']" type ="text" size="' . $this->size . '" maxlength="' . $this->maxLength . '" value="' . $this->htmlentities( $v, ENT_COMPAT, 'utf-8' ) . '" required="' . $isRequired . '" style="display:none;' . htmlentities( $this->style, ENT_COMPAT, 'utf-8' ) . '"/>' . htmlentities( $v, ENT_COMPAT, 'utf-8' ); } else { @@ -4172,7 +4165,7 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText } if ($this->defaultValue != "") { - $defaultValue = masktophp( $mask ); + $defaultValue = masktophp( $mask, $defaultValue); } if (strpos( $mask, '%' ) === false) { @@ -4213,7 +4206,7 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText $value = ''; //date ($tmp); } else { if ($value != "") { - $value = masktophp( $mask ); + $value = masktophp( $mask, $value); } } @@ -5453,7 +5446,7 @@ class XmlForm_Field_Image extends XmlForm_Field } //mask function to php -function masktophp ($mask) +function masktophp ($mask, $value) { $tmp = str_replace("%", "", $mask); if (preg_match('/M/',$tmp)) { @@ -5501,7 +5494,12 @@ function masktophp ($mask) if (preg_match('/P/',$tmp)) { $tmp = str_replace("P", "a", $tmp); } - $value = date($tmp); + + if ($value == 'today') { + $value = date($tmp); + } else { + $value = date($tmp, strtotime ($value)); + } return $value; }