Browse Source

Validate date/time fields using their regular expression during an import to avoid passing wrong formats as-is (e.g. 01/02/16 can become 01/02/0016 instead of 01/02/2016 if you use the 4 digits format for years and pass only 2 digits !)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4090 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 9 years ago
parent
commit
efeda4cc5d
1 changed files with 14 additions and 7 deletions
  1. 14 7
      core/bulkchange.class.inc.php

+ 14 - 7
core/bulkchange.class.inc.php

@@ -827,17 +827,24 @@ class BulkChange
 							{
 								$sFormat = $sDateFormat;
 							}
-							$oDate = DateTime::createFromFormat($sFormat, $this->m_aData[$iRow][$iCol]);
-							if ($oDate !== false)
+							if (!preg_match('/'.$sRegExp.'/', $this->m_aData[$iRow][$iCol]))
 							{
-								$sNewDate = $oDate->format($oAttDef->GetInternalFormat());
-								$this->m_aData[$iRow][$iCol] = $sNewDate;
+								$aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
 							}
 							else
 							{
-								// Leave the cell unchanged
-								$aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
-								$aResult[$iRow][$sAttCode] = new CellStatus_Issue(null, $this->m_aData[$iRow][$iCol], Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
+								$oDate = DateTime::createFromFormat($sFormat, $this->m_aData[$iRow][$iCol]);
+								if ($oDate !== false)
+								{
+									$sNewDate = $oDate->format($oAttDef->GetInternalFormat());
+									$this->m_aData[$iRow][$iCol] = $sNewDate;
+								}
+								else
+								{
+									// Leave the cell unchanged
+									$aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
+									$aResult[$iRow][$sAttCode] = new CellStatus_Issue(null, $this->m_aData[$iRow][$iCol], Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
+								}
 							}
 						}
 						else