From 92b2131d3b9cd3edfa2d2d729600c24444272dc2 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Fri, 23 May 2014 12:32:08 +0000 Subject: [PATCH] #483 Added placeholders for the notifications: html(caselog), head_html(caselog), html(linkset). The HTML can be customized. Fixes the issue about lines being wrapped in a curious way (root cause: swift mailer). SVN:trunk[3167] --- core/dbobject.class.php | 6 ++- core/ormcaselog.class.inc.php | 78 +++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 6ea80b7be..f1005c15b 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -2088,7 +2088,10 @@ abstract class DBObject implements iDisplay { $oCaseLog = $this->Get($sAttCode); $aScalarArgs[$sArgName.'->'.$sAttCode] = $oCaseLog->GetText(); - $aScalarArgs[$sArgName.'->head('.$sAttCode.')'] = $oCaseLog->GetLatestEntry(); + $sHead = $oCaseLog->GetLatestEntry(); + $aScalarArgs[$sArgName.'->head('.$sAttCode.')'] = $sHead; + $aScalarArgs[$sArgName.'->head_html('.$sAttCode.')'] = '
'.str_replace(array("\r\n", "\n", "\r"), "
", htmlentities($sHead, ENT_QUOTES, 'UTF-8')).'
'; + $aScalarArgs[$sArgName.'->html('.$sAttCode.')'] = $oCaseLog->GetAsEmailHtml(); } elseif ($oAttDef->IsScalar()) { @@ -2119,6 +2122,7 @@ abstract class DBObject implements iDisplay } $sNames = implode("\n", $aNames); $aScalarArgs[$sArgName.'->'.$sAttCode] = $sNames; + $aScalarArgs[$sArgName.'->html('.$sAttCode.')'] = ''; } } diff --git a/core/ormcaselog.class.inc.php b/core/ormcaselog.class.inc.php index 25507f208..c96ffbda4 100644 --- a/core/ormcaselog.class.inc.php +++ b/core/ormcaselog.class.inc.php @@ -136,7 +136,85 @@ class ormCaseLog { { $this->m_bModified = false; } + + /** + * Produces an HTML representation, aimed at being used within an email + */ + public function GetAsEmailHtml() + { + $sStyleCaseLogHeader = ''; + $sStyleCaseLogEntry = ''; + + $sHtml = '
'; // Use table-layout:fixed to force the with to be independent from the actual content + $iPos = 0; + $aIndex = $this->m_aIndex; + for($index=count($aIndex)-1 ; $index >= 0 ; $index--) + { + $iPos += $aIndex[$index]['separator_length']; + $sTextEntry = substr($this->m_sLog, $iPos, $aIndex[$index]['text_length']); + $sTextEntry = str_replace(array("\r\n", "\n", "\r"), "
", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8')); + $iPos += $aIndex[$index]['text_length']; + + $sEntry = '
'; + // Workaround: PHP < 5.3 cannot unserialize correctly DateTime objects, + // therefore we have changed the format. To preserve the compatibility with existing + // installations of iTop, both format are allowed: + // the 'date' item is either a DateTime object, or a unix timestamp + if (is_int($aIndex[$index]['date'])) + { + // Unix timestamp + $sDate = date(Dict::S('UI:CaseLog:DateFormat'),$aIndex[$index]['date']); + } + elseif (is_object($aIndex[$index]['date'])) + { + if (version_compare(phpversion(), '5.3.0', '>=')) + { + // DateTime + $sDate = $aIndex[$index]['date']->format(Dict::S('UI:CaseLog:DateFormat')); + } + else + { + // No Warning... but the date is unknown + $sDate = ''; + } + } + $sEntry .= sprintf(Dict::S('UI:CaseLog:Header_Date_UserName'), ''.$sDate.'', ''.$aIndex[$index]['user_name'].''); + $sEntry .= '
'; + $sEntry .= '
'; + $sEntry .= $sTextEntry; + $sEntry .= '
'; + $sHtml = $sHtml.$sEntry; + } + + // Process the case of an eventual remainder (quick migration of AttributeText fields) + if ($iPos < (strlen($this->m_sLog) - 1)) + { + $sTextEntry = substr($this->m_sLog, $iPos); + $sTextEntry = str_replace(array("\r\n", "\n", "\r"), "
", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8')); + + if (count($this->m_aIndex) == 0) + { + $sHtml .= '
'; + $sHtml .= $sTextEntry; + $sHtml .= '
'; + } + else + { + $sHtml .= '
'; + $sHtml .= Dict::S('UI:CaseLog:InitialValue'); + $sHtml .= '
'; + $sHtml .= '
'; + $sHtml .= $sTextEntry; + $sHtml .= '
'; + } + } + $sHtml .= '
'; + return $sHtml; + } + /** + * Produces an HTML representation, aimed at being used within the iTop framework + */ public function GetAsHTML(WebPage $oP = null, $bEditMode = false, $aTransfoHandler = null) { $sHtml = '
'; // Use table-layout:fixed to force the with to be independent from the actual content