|
@@ -1,5 +1,5 @@
|
|
<?php
|
|
<?php
|
|
-// Copyright (C) 2011 Combodo SARL
|
|
|
|
|
|
+// Copyright (C) 2011-2012 Combodo SARL
|
|
//
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// it under the terms of the GNU General Public License as published by
|
|
@@ -26,6 +26,7 @@ define('CASELOG_SEPARATOR', "\n".'========== %1$s : %2$s (%3$d) ============'."\
|
|
class ormCaseLog {
|
|
class ormCaseLog {
|
|
protected $m_sLog;
|
|
protected $m_sLog;
|
|
protected $m_aIndex;
|
|
protected $m_aIndex;
|
|
|
|
+ protected $m_bModified;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Initializes the log with the first (initial) entry
|
|
* Initializes the log with the first (initial) entry
|
|
@@ -36,6 +37,7 @@ class ormCaseLog {
|
|
{
|
|
{
|
|
$this->m_sLog = $sLog;
|
|
$this->m_sLog = $sLog;
|
|
$this->m_aIndex = $aIndex;
|
|
$this->m_aIndex = $aIndex;
|
|
|
|
+ $this->m_bModified = false;
|
|
}
|
|
}
|
|
|
|
|
|
public function GetText()
|
|
public function GetText()
|
|
@@ -53,13 +55,25 @@ class ormCaseLog {
|
|
return $this->m_sLog;
|
|
return $this->m_sLog;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function ClearModifiedFlag()
|
|
|
|
+ {
|
|
|
|
+ $this->m_bModified = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
public function GetAsHTML(WebPage $oP = null, $bEditMode = false, $aTransfoHandler = null)
|
|
public function GetAsHTML(WebPage $oP = null, $bEditMode = false, $aTransfoHandler = null)
|
|
{
|
|
{
|
|
$sHtml = '<table style="width:100%;table-layout:fixed"><tr><td>'; // Use table-layout:fixed to force the with to be independent from the actual content
|
|
$sHtml = '<table style="width:100%;table-layout:fixed"><tr><td>'; // Use table-layout:fixed to force the with to be independent from the actual content
|
|
$iPos = 0;
|
|
$iPos = 0;
|
|
- for($index=count($this->m_aIndex)-1 ; $index >= 0 ; $index--)
|
|
|
|
|
|
+ $aIndex = $this->m_aIndex;
|
|
|
|
+ if (($bEditMode) && (count($aIndex) > 0) && $this->m_bModified)
|
|
{
|
|
{
|
|
- if ($index < count($this->m_aIndex) - CASELOG_VISIBLE_ITEMS)
|
|
|
|
|
|
+ // Don't display the first element, that is still considered as editable
|
|
|
|
+ $iPos = $aIndex[0]['separator_length'] + $aIndex[0]['separator_length'];
|
|
|
|
+ array_shift($aIndex);
|
|
|
|
+ }
|
|
|
|
+ for($index=count($aIndex)-1 ; $index >= 0 ; $index--)
|
|
|
|
+ {
|
|
|
|
+ if ($index < count($aIndex) - CASELOG_VISIBLE_ITEMS)
|
|
{
|
|
{
|
|
$sOpen = '';
|
|
$sOpen = '';
|
|
$sDisplay = 'style="display:none;"';
|
|
$sDisplay = 'style="display:none;"';
|
|
@@ -69,31 +83,31 @@ class ormCaseLog {
|
|
$sOpen = ' open';
|
|
$sOpen = ' open';
|
|
$sDisplay = '';
|
|
$sDisplay = '';
|
|
}
|
|
}
|
|
- $iPos += $this->m_aIndex[$index]['separator_length'];
|
|
|
|
- $sTextEntry = substr($this->m_sLog, $iPos, $this->m_aIndex[$index]['text_length']);
|
|
|
|
|
|
+ $iPos += $aIndex[$index]['separator_length'];
|
|
|
|
+ $sTextEntry = substr($this->m_sLog, $iPos, $aIndex[$index]['text_length']);
|
|
$sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
|
|
$sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
|
|
if (!is_null($aTransfoHandler))
|
|
if (!is_null($aTransfoHandler))
|
|
{
|
|
{
|
|
$sTextEntry = call_user_func($aTransfoHandler, $sTextEntry);
|
|
$sTextEntry = call_user_func($aTransfoHandler, $sTextEntry);
|
|
}
|
|
}
|
|
- $iPos += $this->m_aIndex[$index]['text_length'];
|
|
|
|
|
|
+ $iPos += $aIndex[$index]['text_length'];
|
|
|
|
|
|
$sEntry = '<div class="caselog_header'.$sOpen.'">';
|
|
$sEntry = '<div class="caselog_header'.$sOpen.'">';
|
|
// Workaround: PHP < 5.3 cannot unserialize correctly DateTime objects,
|
|
// Workaround: PHP < 5.3 cannot unserialize correctly DateTime objects,
|
|
// therefore we have changed the format. To preserve the compatibility with existing
|
|
// therefore we have changed the format. To preserve the compatibility with existing
|
|
// installations of iTop, both format are allowed:
|
|
// installations of iTop, both format are allowed:
|
|
// the 'date' item is either a DateTime object, or a unix timestamp
|
|
// the 'date' item is either a DateTime object, or a unix timestamp
|
|
- if (is_int($this->m_aIndex[$index]['date']))
|
|
|
|
|
|
+ if (is_int($aIndex[$index]['date']))
|
|
{
|
|
{
|
|
// Unix timestamp
|
|
// Unix timestamp
|
|
- $sDate = date(Dict::S('UI:CaseLog:DateFormat'), $this->m_aIndex[$index]['date']);
|
|
|
|
|
|
+ $sDate = date(Dict::S('UI:CaseLog:DateFormat'),$aIndex[$index]['date']);
|
|
}
|
|
}
|
|
- elseif (is_object($this->m_aIndex[$index]['date']))
|
|
|
|
|
|
+ elseif (is_object($aIndex[$index]['date']))
|
|
{
|
|
{
|
|
if (version_compare(phpversion(), '5.3.0', '>='))
|
|
if (version_compare(phpversion(), '5.3.0', '>='))
|
|
{
|
|
{
|
|
// DateTime
|
|
// DateTime
|
|
- $sDate = $this->m_aIndex[$index]['date']->format(Dict::S('UI:CaseLog:DateFormat'));
|
|
|
|
|
|
+ $sDate = $aIndex[$index]['date']->format(Dict::S('UI:CaseLog:DateFormat'));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -101,7 +115,7 @@ class ormCaseLog {
|
|
$sDate = '';
|
|
$sDate = '';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- $sEntry .= sprintf(Dict::S('UI:CaseLog:Header_Date_UserName'), $sDate, $this->m_aIndex[$index]['user_name']);
|
|
|
|
|
|
+ $sEntry .= sprintf(Dict::S('UI:CaseLog:Header_Date_UserName'), $sDate, $aIndex[$index]['user_name']);
|
|
$sEntry .= '</div>';
|
|
$sEntry .= '</div>';
|
|
$sEntry .= '<div class="caselog_entry"'.$sDisplay.'>';
|
|
$sEntry .= '<div class="caselog_entry"'.$sDisplay.'>';
|
|
$sEntry .= $sTextEntry;
|
|
$sEntry .= $sTextEntry;
|
|
@@ -150,11 +164,13 @@ class ormCaseLog {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Add a new entry to the log and updates the internal index
|
|
|
|
|
|
+ * Add a new entry to the log or merge the given text into the currently modified entry
|
|
|
|
+ * and updates the internal index
|
|
* @param $sText string The text of the new entry
|
|
* @param $sText string The text of the new entry
|
|
*/
|
|
*/
|
|
public function AddLogEntry($sText, $sOnBehalfOf = '')
|
|
public function AddLogEntry($sText, $sOnBehalfOf = '')
|
|
{
|
|
{
|
|
|
|
+ $bMergeEntries = false;
|
|
$sDate = date(Dict::S('UI:CaseLog:DateFormat'));
|
|
$sDate = date(Dict::S('UI:CaseLog:DateFormat'));
|
|
if ($sOnBehalfOf == '')
|
|
if ($sOnBehalfOf == '')
|
|
{
|
|
{
|
|
@@ -165,17 +181,61 @@ class ormCaseLog {
|
|
{
|
|
{
|
|
$iUserId = null;
|
|
$iUserId = null;
|
|
}
|
|
}
|
|
- $sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId);
|
|
|
|
- $iSepLength = strlen($sSeparator);
|
|
|
|
- $iTextlength = strlen($sText);
|
|
|
|
- $this->m_sLog = $sSeparator.$sText.$this->m_sLog; // Latest entry printed first
|
|
|
|
- $this->m_aIndex[] = array(
|
|
|
|
- 'user_name' => $sOnBehalfOf,
|
|
|
|
- 'user_id' => $iUserId,
|
|
|
|
- 'date' => time(),
|
|
|
|
- 'text_length' => $iTextlength,
|
|
|
|
- 'separator_length' => $iSepLength,
|
|
|
|
- );
|
|
|
|
|
|
+ if ($this->m_bModified)
|
|
|
|
+ {
|
|
|
|
+ $aLatestEntry = end($this->m_aIndex);
|
|
|
|
+ if ($aLatestEntry['user_name'] != $sOnBehalfOf)
|
|
|
|
+ {
|
|
|
|
+ $bMergeEntries = false;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $bMergeEntries = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($bMergeEntries)
|
|
|
|
+ {
|
|
|
|
+ $aLatestEntry = end($this->m_aIndex);
|
|
|
|
+ $this->m_sLog = substr($this->m_sLog, $aLatestEntry['separator_length']);
|
|
|
|
+ $sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId);
|
|
|
|
+ $iSepLength = strlen($sSeparator);
|
|
|
|
+ $iTextlength = strlen($sText."\n");
|
|
|
|
+ $this->m_sLog = $sSeparator.$sText.$this->m_sLog; // Latest entry printed first
|
|
|
|
+ $this->m_aIndex[] = array(
|
|
|
|
+ 'user_name' => $sOnBehalfOf,
|
|
|
|
+ 'user_id' => $iUserId,
|
|
|
|
+ 'date' => time(),
|
|
|
|
+ 'text_length' => $aLatestEntry['text_length'] + $iTextlength,
|
|
|
|
+ 'separator_length' => $iSepLength,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId);
|
|
|
|
+ $iSepLength = strlen($sSeparator);
|
|
|
|
+ $iTextlength = strlen($sText);
|
|
|
|
+ $this->m_sLog = $sSeparator.$sText.$this->m_sLog; // Latest entry printed first
|
|
|
|
+ $this->m_aIndex[] = array(
|
|
|
|
+ 'user_name' => $sOnBehalfOf,
|
|
|
|
+ 'user_id' => $iUserId,
|
|
|
|
+ 'date' => time(),
|
|
|
|
+ 'text_length' => $iTextlength,
|
|
|
|
+ 'separator_length' => $iSepLength,
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ $this->m_bModified = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function GetModifiedEntry()
|
|
|
|
+ {
|
|
|
|
+ $sModifiedEntry = '';
|
|
|
|
+ if ($this->m_bModified)
|
|
|
|
+ {
|
|
|
|
+ $sModifiedEntry = $this->GetLatestEntry();
|
|
|
|
+ }
|
|
|
|
+ return $sModifiedEntry;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -200,4 +260,4 @@ class ormCaseLog {
|
|
return $iLast;
|
|
return $iLast;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-?>
|
|
|
|
|
|
+?>
|