From 9531d78fe190385bfdb30663ef8fc8f1a7c67ee5 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Fri, 12 Dec 2014 17:33:13 -0400 Subject: [PATCH] PM-1115 "16306: Date Field not showing next date after 1969" SOLVED MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: 16306: Date Field not showing next date after 1969 Cause: Esto se debe a la funcion "mktime" de PHP para Windows el cual tiene una limitante en el rango de fechas (rango valido entre 1901 y 2038). Para mas detalles visite el sgte link ----> http://php.net/manual/en/function.mktime.php Solution: Se ha mejorado el metodo "calculateBeforeFormat" de la clase "XmlForm_Field_Date" el cual verifica el total de aƱde la fecha que se obtiene con "mktime"; esto solo para servidores Windows --- gulliver/system/class.xmlform.php | 127 +++++++++++++++++++----------- 1 file changed, 80 insertions(+), 47 deletions(-) diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index 7911fec92..492e8081a 100755 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -738,53 +738,53 @@ class XmlForm_Field $aValues = explode( '|', $oOwner->fields[$this->pmconnection]->keys ); $i = 0; if($aData == "" || count($aData['FIELDS']) < 1){ - $message = G::LoadTranslation( 'ID_PMTABLE_NOT_FOUND' ); + $message = G::LoadTranslation( 'ID_PMTABLE_NOT_FOUND' ); G::SendMessageText( $message, "WARNING" ); $sValue = ""; } else { - foreach ($aData['FIELDS'] as $aField) { - if ($aField['FLD_KEY'] == '1') { - // note added by gustavo cruz gustavo[at]colosa[dot]com - // this additional [if] checks if a case variable has been set - // in the keys attribute, so it can be parsed and replaced for - // their respective value. - if (preg_match( "/@#/", $aValues[$i] )) { - // check if a case are running in order to prevent that preview is - // erroneous rendered. - if (isset( $_SESSION['APPLICATION'] )) { - G::LoadClass( 'case' ); - $oApp = new Cases(); - if ($oApp->loadCase( $_SESSION['APPLICATION'] ) != null) { - $aFields = $oApp->loadCase( $_SESSION['APPLICATION'] ); - $formVariable = substr( $aValues[$i], 2 ); - if (isset( $aFields['APP_DATA'][$formVariable] )) { - $formVariableValue = $aFields['APP_DATA'][$formVariable]; - $aKeys[$aField['FLD_NAME']] = (isset( $formVariableValue ) ? G::replaceDataField( $formVariableValue, $oOwner->values ) : ''); - } else { - $aKeys[$aField['FLD_NAME']] = ''; - } - } else { - $aKeys[$aField['FLD_NAME']] = ''; - } - } else { - $aKeys[$aField['FLD_NAME']] = ''; - } - } else { - $aKeys[$aField['FLD_NAME']] = (isset( $aValues[$i] ) ? G::replaceDataField( $aValues[$i], $oOwner->values ) : ''); - } - $i ++; - } + foreach ($aData['FIELDS'] as $aField) { + if ($aField['FLD_KEY'] == '1') { + // note added by gustavo cruz gustavo[at]colosa[dot]com + // this additional [if] checks if a case variable has been set + // in the keys attribute, so it can be parsed and replaced for + // their respective value. + if (preg_match( "/@#/", $aValues[$i] )) { + // check if a case are running in order to prevent that preview is + // erroneous rendered. + if (isset( $_SESSION['APPLICATION'] )) { + G::LoadClass( 'case' ); + $oApp = new Cases(); + if ($oApp->loadCase( $_SESSION['APPLICATION'] ) != null) { + $aFields = $oApp->loadCase( $_SESSION['APPLICATION'] ); + $formVariable = substr( $aValues[$i], 2 ); + if (isset( $aFields['APP_DATA'][$formVariable] )) { + $formVariableValue = $aFields['APP_DATA'][$formVariable]; + $aKeys[$aField['FLD_NAME']] = (isset( $formVariableValue ) ? G::replaceDataField( $formVariableValue, $oOwner->values ) : ''); + } else { + $aKeys[$aField['FLD_NAME']] = ''; + } + } else { + $aKeys[$aField['FLD_NAME']] = ''; + } + } else { + $aKeys[$aField['FLD_NAME']] = ''; + } + } else { + $aKeys[$aField['FLD_NAME']] = (isset( $aValues[$i] ) ? G::replaceDataField( $aValues[$i], $oOwner->values ) : ''); + } + $i ++; + } } - try { - $aData = $oAdditionalTables->getDataTable( $oOwner->fields[$this->pmconnection]->pmtable, $aKeys ); - } catch (Exception $oError) { - $aData = array (); - } - if (isset( $aData[$this->pmfield] )) { - $sValue = $aData[$this->pmfield]; + try { + $aData = $oAdditionalTables->getDataTable( $oOwner->fields[$this->pmconnection]->pmtable, $aKeys ); + } catch (Exception $oError) { + $aData = array (); + } + if (isset( $aData[$this->pmfield] )) { + $sValue = $aData[$this->pmfield]; } } - + } } } @@ -4493,17 +4493,50 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText { $part1 = $sign * substr( $date, 0, strlen( $date ) - 1 ); $part2 = substr( $date, strlen( $date ) - 1 ); + + $year = (int)(date("Y")); + $month = (int)(date("m")); + $day = (int)(date("d")); + + $osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != "WIN"; + $checkYear = false; + switch ($part2) { - case 'd': - $res = date( 'Y-m-d', mktime( 0, 0, 0, date( 'm' ), date( 'd' ) + $part1, date( 'Y' ) ) ); + case "y": + $year = $year + $part1; + + $res = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year)); + + $checkYear = true; break; - case 'm': - $res = date( 'Y-m-d', mktime( 0, 0, 0, date( 'm' ) + $part1, date( 'd' ), date( 'Y' ) ) ); + case "m": + $month = $month + $part1; + + $res = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year)); + + if ($month > 12) { + $year = $year + (int)($month / 12); + + $checkYear = true; + } break; - case 'y': - $res = date( 'Y-m-d', mktime( 0, 0, 0, date( 'm' ), date( 'd' ), date( 'Y' ) + $part1 ) ); + case "d": + $res = date("Y-m-d", mktime(0, 0, 0, $month, $day + $part1, $year)); + + $dayAux = ($month * 31) - (31 - $day) + $part1; + + if ($dayAux > 365) { + $year = $year + (int)($dayAux / 365); + + $checkYear = true; + } break; } + + if (!$osIsLinux && $checkYear && !preg_match("/^$year\-\d{2}\-\d{2}$/", $res)) { + $res = preg_replace("/^\d{4}(\-\d{2}\-\d{2})$/", "$year$1", $res); + } + return $res; }