bulkchange.class.inc.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Bulk change facility (common to interactive and batch usages)
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. // The BOM is added at the head of exported UTF-8 CSV data, and removed (if present) from input UTF-8 data.
  25. // This helps MS-Excel (Version > 2007, Windows only) in changing its interpretation of a CSV file (by default Excel reads data as ISO-8859-1 -not 100% sure!)
  26. define('UTF8_BOM', chr(239).chr(187).chr(191)); // 0xEF, 0xBB, 0xBF
  27. /**
  28. * BulkChange
  29. * Interpret a given data set and update the DB accordingly (fake mode avail.)
  30. *
  31. * @package iTopORM
  32. */
  33. class BulkChangeException extends CoreException
  34. {
  35. }
  36. /**
  37. * CellChangeSpec
  38. * A series of classes, keeping the information about a given cell: could it be changed or not (and why)?
  39. *
  40. * @package iTopORM
  41. */
  42. abstract class CellChangeSpec
  43. {
  44. protected $m_proposedValue;
  45. protected $m_sOql; // in case of ambiguity
  46. public function __construct($proposedValue, $sOql = '')
  47. {
  48. $this->m_proposedValue = $proposedValue;
  49. $this->m_sOql = $sOql;
  50. }
  51. public function GetPureValue()
  52. {
  53. // Todo - distinguish both values
  54. return $this->m_proposedValue;
  55. }
  56. public function GetDisplayableValue()
  57. {
  58. return $this->m_proposedValue;
  59. }
  60. public function GetOql()
  61. {
  62. return $this->m_sOql;
  63. }
  64. abstract public function GetDescription();
  65. }
  66. class CellStatus_Void extends CellChangeSpec
  67. {
  68. public function GetDescription()
  69. {
  70. return '';
  71. }
  72. }
  73. class CellStatus_Modify extends CellChangeSpec
  74. {
  75. protected $m_previousValue;
  76. public function __construct($proposedValue, $previousValue = null)
  77. {
  78. // Unused (could be costly to know -see the case of reconciliation on ext keys)
  79. //$this->m_previousValue = $previousValue;
  80. parent::__construct($proposedValue);
  81. }
  82. public function GetDescription()
  83. {
  84. return Dict::S('UI:CSVReport-Value-Modified');
  85. }
  86. //public function GetPreviousValue()
  87. //{
  88. // return $this->m_previousValue;
  89. //}
  90. }
  91. class CellStatus_Issue extends CellStatus_Modify
  92. {
  93. protected $m_sReason;
  94. public function __construct($proposedValue, $previousValue, $sReason)
  95. {
  96. $this->m_sReason = $sReason;
  97. parent::__construct($proposedValue, $previousValue);
  98. }
  99. public function GetDescription()
  100. {
  101. if (is_null($this->m_proposedValue))
  102. {
  103. return Dict::Format('UI:CSVReport-Value-SetIssue', $this->m_sReason);
  104. }
  105. return Dict::Format('UI:CSVReport-Value-ChangeIssue', $this->m_proposedValue, $this->m_sReason);
  106. }
  107. }
  108. class CellStatus_SearchIssue extends CellStatus_Issue
  109. {
  110. public function __construct()
  111. {
  112. parent::__construct(null, null, null);
  113. }
  114. public function GetDescription()
  115. {
  116. return Dict::S('UI:CSVReport-Value-NoMatch');
  117. }
  118. }
  119. class CellStatus_NullIssue extends CellStatus_Issue
  120. {
  121. public function __construct()
  122. {
  123. parent::__construct(null, null, null);
  124. }
  125. public function GetDescription()
  126. {
  127. return Dict::S('UI:CSVReport-Value-Missing');
  128. }
  129. }
  130. class CellStatus_Ambiguous extends CellStatus_Issue
  131. {
  132. protected $m_iCount;
  133. public function __construct($previousValue, $iCount, $sOql)
  134. {
  135. $this->m_iCount = $iCount;
  136. $this->m_sQuery = $sOql;
  137. parent::__construct(null, $previousValue, '');
  138. }
  139. public function GetDescription()
  140. {
  141. $sCount = $this->m_iCount;
  142. return Dict::Format('UI:CSVReport-Value-Ambiguous', $sCount);
  143. }
  144. }
  145. /**
  146. * RowStatus
  147. * A series of classes, keeping the information about a given row: could it be changed or not (and why)?
  148. *
  149. * @package iTopORM
  150. */
  151. abstract class RowStatus
  152. {
  153. public function __construct()
  154. {
  155. }
  156. abstract public function GetDescription();
  157. }
  158. class RowStatus_NoChange extends RowStatus
  159. {
  160. public function GetDescription()
  161. {
  162. return Dict::S('UI:CSVReport-Row-Unchanged');
  163. }
  164. }
  165. class RowStatus_NewObj extends RowStatus
  166. {
  167. public function GetDescription()
  168. {
  169. return Dict::S('UI:CSVReport-Row-Created');
  170. }
  171. }
  172. class RowStatus_Modify extends RowStatus
  173. {
  174. protected $m_iChanged;
  175. public function __construct($iChanged)
  176. {
  177. $this->m_iChanged = $iChanged;
  178. }
  179. public function GetDescription()
  180. {
  181. return Dict::Format('UI:CSVReport-Row-Updated', $this->m_iChanged);
  182. }
  183. }
  184. class RowStatus_Disappeared extends RowStatus_Modify
  185. {
  186. public function GetDescription()
  187. {
  188. return Dict::Format('UI:CSVReport-Row-Disappeared', $this->m_iChanged);
  189. }
  190. }
  191. class RowStatus_Issue extends RowStatus
  192. {
  193. protected $m_sReason;
  194. public function __construct($sReason)
  195. {
  196. $this->m_sReason = $sReason;
  197. }
  198. public function GetDescription()
  199. {
  200. return Dict::Format('UI:CSVReport-Row-Issue', $this->m_sReason);
  201. }
  202. }
  203. /**
  204. * BulkChange
  205. *
  206. * @package iTopORM
  207. */
  208. class BulkChange
  209. {
  210. protected $m_sClass;
  211. protected $m_aData; // Note: hereafter, iCol maybe actually be any acceptable key (string)
  212. // #@# todo: rename the variables to sColIndex
  213. protected $m_aAttList; // attcode => iCol
  214. protected $m_aExtKeys; // aExtKeys[sExtKeyAttCode][sExtReconcKeyAttCode] = iCol;
  215. protected $m_aReconcilKeys; // attcode (attcode = 'id' for the pkey)
  216. protected $m_sSynchroScope; // OQL - if specified, then the missing items will be reported
  217. protected $m_aOnDisappear; // array of attcode => value, values to be set when an object gets out of scope (ignored if no scope has been defined)
  218. protected $m_sDateFormat; // Date format specification, see utils::StringToTime()
  219. protected $m_bLocalizedValues; // Values in the data set are localized (see AttributeEnum)
  220. public function __construct($sClass, $aData, $aAttList, $aExtKeys, $aReconcilKeys, $sSynchroScope = null, $aOnDisappear = null, $sDateFormat = null, $bLocalize = false)
  221. {
  222. $this->m_sClass = $sClass;
  223. $this->m_aData = $aData;
  224. $this->m_aAttList = $aAttList;
  225. $this->m_aReconcilKeys = $aReconcilKeys;
  226. $this->m_aExtKeys = $aExtKeys;
  227. $this->m_sSynchroScope = $sSynchroScope;
  228. $this->m_aOnDisappear = $aOnDisappear;
  229. $this->m_sDateFormat = $sDateFormat;
  230. $this->m_bLocalizedValues = $bLocalize;
  231. }
  232. protected $m_bReportHtml = false;
  233. protected $m_sReportCsvSep = ',';
  234. protected $m_sReportCsvDelimiter = '"';
  235. public function SetReportHtml()
  236. {
  237. $this->m_bReportHtml = true;
  238. }
  239. public function SetReportCsv($sSeparator = ',', $sDelimiter = '"')
  240. {
  241. $this->m_bReportHtml = false;
  242. $this->m_sReportCsvSep = $sSeparator;
  243. $this->m_sReportCsvDelimiter = $sDelimiter;
  244. }
  245. protected function ResolveExternalKey($aRowData, $sAttCode, &$aResults)
  246. {
  247. $oExtKey = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  248. $oReconFilter = new CMDBSearchFilter($oExtKey->GetTargetClass());
  249. foreach ($this->m_aExtKeys[$sAttCode] as $sForeignAttCode => $iCol)
  250. {
  251. // The foreign attribute is one of our reconciliation key
  252. $oForeignAtt = MetaModel::GetAttributeDef($oExtKey->GetTargetClass(), $sForeignAttCode);
  253. $value = $oForeignAtt->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  254. $oReconFilter->AddCondition($sForeignAttCode, $value);
  255. $aResults[$iCol] = new CellStatus_Void($aRowData[$iCol]);
  256. }
  257. $oExtObjects = new CMDBObjectSet($oReconFilter);
  258. $aKeys = $oExtObjects->ToArray();
  259. return array($oReconFilter->ToOql(), $aKeys);
  260. }
  261. // Returns true if the CSV data specifies that the external key must be left undefined
  262. protected function IsNullExternalKeySpec($aRowData, $sAttCode)
  263. {
  264. $oExtKey = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  265. foreach ($this->m_aExtKeys[$sAttCode] as $sForeignAttCode => $iCol)
  266. {
  267. // The foreign attribute is one of our reconciliation key
  268. if (strlen($aRowData[$iCol]) > 0)
  269. {
  270. return false;
  271. }
  272. }
  273. return true;
  274. }
  275. protected function PrepareObject(&$oTargetObj, $aRowData, &$aErrors)
  276. {
  277. $aResults = array();
  278. $aErrors = array();
  279. // External keys reconciliation
  280. //
  281. foreach($this->m_aExtKeys as $sAttCode => $aKeyConfig)
  282. {
  283. // Skip external keys used for the reconciliation process
  284. // if (!array_key_exists($sAttCode, $this->m_aAttList)) continue;
  285. $oExtKey = MetaModel::GetAttributeDef(get_class($oTargetObj), $sAttCode);
  286. if ($this->IsNullExternalKeySpec($aRowData, $sAttCode))
  287. {
  288. foreach ($aKeyConfig as $sForeignAttCode => $iCol)
  289. {
  290. // Default reporting
  291. $aResults[$iCol] = new CellStatus_Void($aRowData[$iCol]);
  292. }
  293. if ($oExtKey->IsNullAllowed())
  294. {
  295. $oTargetObj->Set($sAttCode, $oExtKey->GetNullValue());
  296. $aResults[$sAttCode]= new CellStatus_Void($oExtKey->GetNullValue());
  297. }
  298. else
  299. {
  300. $aErrors[$sAttCode] = Dict::S('UI:CSVReport-Value-Issue-Null');
  301. $aResults[$sAttCode]= new CellStatus_Issue(null, $oTargetObj->Get($sAttCode), Dict::S('UI:CSVReport-Value-Issue-Null'));
  302. }
  303. }
  304. else
  305. {
  306. $oReconFilter = new CMDBSearchFilter($oExtKey->GetTargetClass());
  307. foreach ($aKeyConfig as $sForeignAttCode => $iCol)
  308. {
  309. // The foreign attribute is one of our reconciliation key
  310. if ($sForeignAttCode == 'id')
  311. {
  312. $value = $aRowData[$iCol];
  313. }
  314. else
  315. {
  316. $oForeignAtt = MetaModel::GetAttributeDef($oExtKey->GetTargetClass(), $sForeignAttCode);
  317. $value = $oForeignAtt->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  318. }
  319. $oReconFilter->AddCondition($sForeignAttCode, $value, '=');
  320. $aResults[$iCol] = new CellStatus_Void($aRowData[$iCol]);
  321. }
  322. $oExtObjects = new CMDBObjectSet($oReconFilter);
  323. switch($oExtObjects->Count())
  324. {
  325. case 0:
  326. $aErrors[$sAttCode] = Dict::S('UI:CSVReport-Value-Issue-NotFound');
  327. $aResults[$sAttCode]= new CellStatus_SearchIssue();
  328. break;
  329. case 1:
  330. // Do change the external key attribute
  331. $oForeignObj = $oExtObjects->Fetch();
  332. $oTargetObj->Set($sAttCode, $oForeignObj->GetKey());
  333. break;
  334. default:
  335. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-FoundMany', $oExtObjects->Count());
  336. $aResults[$sAttCode]= new CellStatus_Ambiguous($oTargetObj->Get($sAttCode), $oExtObjects->Count(), $oReconFilter->ToOql());
  337. }
  338. }
  339. // Report
  340. if (!array_key_exists($sAttCode, $aResults))
  341. {
  342. $iForeignObj = $oTargetObj->Get($sAttCode);
  343. if (array_key_exists($sAttCode, $oTargetObj->ListChanges()))
  344. {
  345. if ($oTargetObj->IsNew())
  346. {
  347. $aResults[$sAttCode]= new CellStatus_Void($iForeignObj);
  348. }
  349. else
  350. {
  351. $aResults[$sAttCode]= new CellStatus_Modify($iForeignObj, $oTargetObj->GetOriginal($sAttCode));
  352. foreach ($aKeyConfig as $sForeignAttCode => $iCol)
  353. {
  354. // Report the change on reconciliation values as well
  355. $aResults[$iCol] = new CellStatus_Modify($aRowData[$iCol]);
  356. }
  357. }
  358. }
  359. else
  360. {
  361. $aResults[$sAttCode]= new CellStatus_Void($iForeignObj);
  362. }
  363. }
  364. }
  365. // Set the object attributes
  366. //
  367. foreach ($this->m_aAttList as $sAttCode => $iCol)
  368. {
  369. // skip the private key, if any
  370. if ($sAttCode == 'id') continue;
  371. $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  372. $aReasons = array();
  373. $iFlags = $oTargetObj->GetAttributeFlags($sAttCode, $aReasons);
  374. if ( (($iFlags & OPT_ATT_READONLY) == OPT_ATT_READONLY) && ( $oTargetObj->Get($sAttCode) != $aRowData[$iCol]) )
  375. {
  376. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-Readonly', $sAttCode, $oTargetObj->Get($sAttCode), $aRowData[$iCol]);
  377. }
  378. else if ($oAttDef->IsLinkSet() && $oAttDef->IsIndirect())
  379. {
  380. try
  381. {
  382. $oSet = $oAttDef->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  383. $oTargetObj->Set($sAttCode, $oSet);
  384. }
  385. catch(CoreException $e)
  386. {
  387. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-Format', $e->getMessage());
  388. }
  389. }
  390. else
  391. {
  392. $value = $oAttDef->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  393. if (is_null($value) && (strlen($aRowData[$iCol]) > 0))
  394. {
  395. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-NoMatch', $sAttCode);
  396. }
  397. else
  398. {
  399. $res = $oTargetObj->CheckValue($sAttCode, $value);
  400. if ($res === true)
  401. {
  402. $oTargetObj->Set($sAttCode, $value);
  403. }
  404. else
  405. {
  406. // $res is a string with the error description
  407. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-Unknown', $sAttCode, $res);
  408. }
  409. }
  410. }
  411. }
  412. // Reporting on fields
  413. //
  414. $aChangedFields = $oTargetObj->ListChanges();
  415. foreach ($this->m_aAttList as $sAttCode => $iCol)
  416. {
  417. if ($sAttCode == 'id')
  418. {
  419. $aResults[$iCol]= new CellStatus_Void($aRowData[$iCol]);
  420. }
  421. else
  422. {
  423. if ($this->m_bReportHtml)
  424. {
  425. $sCurValue = $oTargetObj->GetAsHTML($sAttCode, $this->m_bLocalizedValues);
  426. $sOrigValue = $oTargetObj->GetOriginalAsHTML($sAttCode, $this->m_bLocalizedValues);
  427. $sInput = htmlentities($aRowData[$iCol], ENT_QUOTES, 'UTF-8');
  428. }
  429. else
  430. {
  431. $sCurValue = $oTargetObj->GetAsCSV($sAttCode, $this->m_sReportCsvSep, $this->m_sReportCsvDelimiter, $this->m_bLocalizedValues);
  432. $sOrigValue = $oTargetObj->GetOriginalAsCSV($sAttCode, $this->m_sReportCsvSep, $this->m_sReportCsvDelimiter, $this->m_bLocalizedValues);
  433. $sInput = $aRowData[$iCol];
  434. }
  435. if (isset($aErrors[$sAttCode]))
  436. {
  437. $aResults[$iCol]= new CellStatus_Issue($aRowData[$iCol], $sOrigValue, $aErrors[$sAttCode]);
  438. }
  439. elseif (array_key_exists($sAttCode, $aChangedFields))
  440. {
  441. if ($oTargetObj->IsNew())
  442. {
  443. $aResults[$iCol]= new CellStatus_Void($sCurValue);
  444. }
  445. else
  446. {
  447. $aResults[$iCol]= new CellStatus_Modify($sCurValue, $sOrigValue);
  448. }
  449. }
  450. else
  451. {
  452. // By default... nothing happens
  453. $aResults[$iCol]= new CellStatus_Void($aRowData[$iCol]);
  454. }
  455. }
  456. }
  457. // Checks
  458. //
  459. $res = $oTargetObj->CheckConsistency();
  460. if ($res !== true)
  461. {
  462. // $res contains the error description
  463. $aErrors["GLOBAL"] = Dict::Format('UI:CSVReport-Row-Issue-Inconsistent', $res);
  464. }
  465. return $aResults;
  466. }
  467. protected function PrepareMissingObject(&$oTargetObj, &$aErrors)
  468. {
  469. $aResults = array();
  470. $aErrors = array();
  471. // External keys
  472. //
  473. foreach($this->m_aExtKeys as $sAttCode => $aKeyConfig)
  474. {
  475. //$oExtKey = MetaModel::GetAttributeDef(get_class($oTargetObj), $sAttCode);
  476. $aResults[$sAttCode]= new CellStatus_Void($oTargetObj->Get($sAttCode));
  477. foreach ($aKeyConfig as $sForeignAttCode => $iCol)
  478. {
  479. $aResults[$iCol] = new CellStatus_Void('?');
  480. }
  481. }
  482. // Update attributes
  483. //
  484. foreach($this->m_aOnDisappear as $sAttCode => $value)
  485. {
  486. if (!MetaModel::IsValidAttCode(get_class($oTargetObj), $sAttCode))
  487. {
  488. throw new BulkChangeException('Invalid attribute code', array('class' => get_class($oTargetObj), 'attcode' => $sAttCode));
  489. }
  490. $oTargetObj->Set($sAttCode, $value);
  491. if (!array_key_exists($sAttCode, $this->m_aAttList))
  492. {
  493. // #@# will be out of the reporting... (counted anyway)
  494. }
  495. }
  496. // Reporting on fields
  497. //
  498. $aChangedFields = $oTargetObj->ListChanges();
  499. foreach ($this->m_aAttList as $sAttCode => $iCol)
  500. {
  501. if ($sAttCode == 'id')
  502. {
  503. $aResults[$iCol]= new CellStatus_Void($oTargetObj->GetKey());
  504. }
  505. if (array_key_exists($sAttCode, $aChangedFields))
  506. {
  507. $aResults[$iCol]= new CellStatus_Modify($oTargetObj->Get($sAttCode), $oTargetObj->GetOriginal($sAttCode));
  508. }
  509. else
  510. {
  511. // By default... nothing happens
  512. $aResults[$iCol]= new CellStatus_Void($oTargetObj->Get($sAttCode));
  513. }
  514. }
  515. // Checks
  516. //
  517. $res = $oTargetObj->CheckConsistency();
  518. if ($res !== true)
  519. {
  520. // $res contains the error description
  521. $aErrors["GLOBAL"] = Dict::Format('UI:CSVReport-Row-Issue-Inconsistent', $res);
  522. }
  523. return $aResults;
  524. }
  525. protected function CreateObject(&$aResult, $iRow, $aRowData, CMDBChange $oChange = null)
  526. {
  527. $oTargetObj = MetaModel::NewObject($this->m_sClass);
  528. $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors);
  529. if (count($aErrors) > 0)
  530. {
  531. $sErrors = implode(', ', $aErrors);
  532. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Attribute'));
  533. return $oTargetObj;
  534. }
  535. // Check that any external key will have a value proposed
  536. $aMissingKeys = array();
  537. foreach (MetaModel::GetExternalKeys($this->m_sClass) as $sExtKeyAttCode => $oExtKey)
  538. {
  539. if (!$oExtKey->IsNullAllowed())
  540. {
  541. if (!array_key_exists($sExtKeyAttCode, $this->m_aExtKeys) && !array_key_exists($sExtKeyAttCode, $this->m_aAttList))
  542. {
  543. $aMissingKeys[] = $oExtKey->GetLabel();
  544. }
  545. }
  546. }
  547. if (count($aMissingKeys) > 0)
  548. {
  549. $sMissingKeys = implode(', ', $aMissingKeys);
  550. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::Format('UI:CSVReport-Row-Issue-MissingExtKey', $sMissingKeys));
  551. return $oTargetObj;
  552. }
  553. // Optionaly record the results
  554. //
  555. if ($oChange)
  556. {
  557. $newID = $oTargetObj->DBInsertTrackedNoReload($oChange);
  558. $aResult[$iRow]["__STATUS__"] = new RowStatus_NewObj($this->m_sClass, $newID);
  559. $aResult[$iRow]["finalclass"] = get_class($oTargetObj);
  560. $aResult[$iRow]["id"] = new CellStatus_Void($newID);
  561. }
  562. else
  563. {
  564. $aResult[$iRow]["__STATUS__"] = new RowStatus_NewObj();
  565. $aResult[$iRow]["finalclass"] = get_class($oTargetObj);
  566. $aResult[$iRow]["id"] = new CellStatus_Void(0);
  567. }
  568. return $oTargetObj;
  569. }
  570. protected function UpdateObject(&$aResult, $iRow, $oTargetObj, $aRowData, CMDBChange $oChange = null)
  571. {
  572. $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors);
  573. // Reporting
  574. //
  575. $aResult[$iRow]["finalclass"] = get_class($oTargetObj);
  576. $aResult[$iRow]["id"] = new CellStatus_Void($oTargetObj->GetKey());
  577. if (count($aErrors) > 0)
  578. {
  579. $sErrors = implode(', ', $aErrors);
  580. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Attribute'));
  581. return;
  582. }
  583. $aChangedFields = $oTargetObj->ListChanges();
  584. if (count($aChangedFields) > 0)
  585. {
  586. $aResult[$iRow]["__STATUS__"] = new RowStatus_Modify(count($aChangedFields));
  587. // Optionaly record the results
  588. //
  589. if ($oChange)
  590. {
  591. try
  592. {
  593. $oTargetObj->DBUpdateTracked($oChange);
  594. }
  595. catch(CoreException $e)
  596. {
  597. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue($e->getMessage());
  598. }
  599. }
  600. }
  601. else
  602. {
  603. $aResult[$iRow]["__STATUS__"] = new RowStatus_NoChange();
  604. }
  605. }
  606. protected function UpdateMissingObject(&$aResult, $iRow, $oTargetObj, CMDBChange $oChange = null)
  607. {
  608. $aResult[$iRow] = $this->PrepareMissingObject($oTargetObj, $aErrors);
  609. // Reporting
  610. //
  611. $aResult[$iRow]["finalclass"] = get_class($oTargetObj);
  612. $aResult[$iRow]["id"] = new CellStatus_Void($oTargetObj->GetKey());
  613. if (count($aErrors) > 0)
  614. {
  615. $sErrors = implode(', ', $aErrors);
  616. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Attribute'));
  617. return;
  618. }
  619. $aChangedFields = $oTargetObj->ListChanges();
  620. if (count($aChangedFields) > 0)
  621. {
  622. $aResult[$iRow]["__STATUS__"] = new RowStatus_Disappeared(count($aChangedFields));
  623. // Optionaly record the results
  624. //
  625. if ($oChange)
  626. {
  627. try
  628. {
  629. $oTargetObj->DBUpdateTracked($oChange);
  630. }
  631. catch(CoreException $e)
  632. {
  633. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue($e->getMessage());
  634. }
  635. }
  636. }
  637. else
  638. {
  639. $aResult[$iRow]["__STATUS__"] = new RowStatus_Disappeared(0);
  640. }
  641. }
  642. public function Process(CMDBChange $oChange = null)
  643. {
  644. // Note: $oChange can be null, in which case the aim is to check what would be done
  645. // Debug...
  646. //
  647. if (false)
  648. {
  649. echo "<pre>\n";
  650. echo "Attributes:\n";
  651. print_r($this->m_aAttList);
  652. echo "ExtKeys:\n";
  653. print_r($this->m_aExtKeys);
  654. echo "Reconciliation:\n";
  655. print_r($this->m_aReconcilKeys);
  656. echo "Synchro scope:\n";
  657. print_r($this->m_sSynchroScope);
  658. echo "Synchro changes:\n";
  659. print_r($this->m_aOnDisappear);
  660. //echo "Data:\n";
  661. //print_r($this->m_aData);
  662. echo "</pre>\n";
  663. exit;
  664. }
  665. $aResult = array();
  666. if (!is_null($this->m_sDateFormat) && (strlen($this->m_sDateFormat) > 0))
  667. {
  668. // Translate dates from the source data
  669. //
  670. foreach ($this->m_aAttList as $sAttCode => $iCol)
  671. {
  672. $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  673. if ($oAttDef instanceof AttributeDateTime)
  674. {
  675. foreach($this->m_aData as $iRow => $aRowData)
  676. {
  677. $sNewDate = utils::StringToTime($this->m_aData[$iRow][$iCol], $this->m_sDateFormat);
  678. if ($sNewDate !== false)
  679. {
  680. // Todo - improve the reporting
  681. $this->m_aData[$iRow][$iCol] = $sNewDate;
  682. }
  683. else
  684. {
  685. // Leave the cell unchanged
  686. $aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
  687. $aResult[$iRow][$sAttCode] = new CellStatus_Issue(null, $this->m_aData[$iRow][$iCol], Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
  688. }
  689. }
  690. }
  691. }
  692. }
  693. // Compute the results
  694. //
  695. if (!is_null($this->m_sSynchroScope))
  696. {
  697. $aVisited = array();
  698. }
  699. foreach($this->m_aData as $iRow => $aRowData)
  700. {
  701. if (isset($aResult[$iRow]["__STATUS__"]))
  702. {
  703. // An issue at the earlier steps - skip the rest
  704. continue;
  705. }
  706. try
  707. {
  708. $oReconciliationFilter = new CMDBSearchFilter($this->m_sClass);
  709. $bSkipQuery = false;
  710. foreach($this->m_aReconcilKeys as $sAttCode)
  711. {
  712. $valuecondition = null;
  713. if (array_key_exists($sAttCode, $this->m_aExtKeys))
  714. {
  715. if ($this->IsNullExternalKeySpec($aRowData, $sAttCode))
  716. {
  717. $oExtKey = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  718. if ($oExtKey->IsNullAllowed())
  719. {
  720. $valuecondition = $oExtKey->GetNullValue();
  721. $aResult[$iRow][$sAttCode] = new CellStatus_Void($oExtKey->GetNullValue());
  722. }
  723. else
  724. {
  725. $aResult[$iRow][$sAttCode] = new CellStatus_NullIssue();
  726. }
  727. }
  728. else
  729. {
  730. // The value has to be found or verified
  731. list($sQuery, $aMatches) = $this->ResolveExternalKey($aRowData, $sAttCode, $aResult[$iRow]);
  732. if (count($aMatches) == 1)
  733. {
  734. $oRemoteObj = reset($aMatches); // first item
  735. $valuecondition = $oRemoteObj->GetKey();
  736. $aResult[$iRow][$sAttCode] = new CellStatus_Void($oRemoteObj->GetKey());
  737. }
  738. elseif (count($aMatches) == 0)
  739. {
  740. $aResult[$iRow][$sAttCode] = new CellStatus_SearchIssue();
  741. }
  742. else
  743. {
  744. $aResult[$iRow][$sAttCode] = new CellStatus_Ambiguous(null, count($aMatches), $sQuery);
  745. }
  746. }
  747. }
  748. else
  749. {
  750. // The value is given in the data row
  751. $iCol = $this->m_aAttList[$sAttCode];
  752. if ($sAttCode == 'id')
  753. {
  754. $valuecondition = $aRowData[$iCol];
  755. }
  756. else
  757. {
  758. $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  759. $valuecondition = $oAttDef->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  760. }
  761. }
  762. if (is_null($valuecondition))
  763. {
  764. $bSkipQuery = true;
  765. }
  766. else
  767. {
  768. $oReconciliationFilter->AddCondition($sAttCode, $valuecondition, '=');
  769. }
  770. }
  771. if ($bSkipQuery)
  772. {
  773. $aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Reconciliation'));
  774. }
  775. else
  776. {
  777. $oReconciliationSet = new CMDBObjectSet($oReconciliationFilter);
  778. switch($oReconciliationSet->Count())
  779. {
  780. case 0:
  781. $oTargetObj = $this->CreateObject($aResult, $iRow, $aRowData, $oChange);
  782. // $aResult[$iRow]["__STATUS__"]=> set in CreateObject
  783. $aVisited[] = $oTargetObj->GetKey();
  784. break;
  785. case 1:
  786. $oTargetObj = $oReconciliationSet->Fetch();
  787. $this->UpdateObject($aResult, $iRow, $oTargetObj, $aRowData, $oChange);
  788. // $aResult[$iRow]["__STATUS__"]=> set in UpdateObject
  789. if (!is_null($this->m_sSynchroScope))
  790. {
  791. $aVisited[] = $oTargetObj->GetKey();
  792. }
  793. break;
  794. default:
  795. // Found several matches, ambiguous
  796. $aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Ambiguous'));
  797. $aResult[$iRow]["id"]= new CellStatus_Ambiguous(0, $oReconciliationSet->Count(), $oReconciliationFilter->ToOql());
  798. $aResult[$iRow]["finalclass"]= 'n/a';
  799. }
  800. }
  801. }
  802. catch (Exception $e)
  803. {
  804. $aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::Format('UI:CSVReport-Row-Issue-Internal', get_class($e), $e->getMessage()));
  805. }
  806. }
  807. if (!is_null($this->m_sSynchroScope))
  808. {
  809. // Compute the delta between the scope and visited objects
  810. $oScopeSearch = DBObjectSearch::FromOQL($this->m_sSynchroScope);
  811. $oScopeSet = new DBObjectSet($oScopeSearch);
  812. while ($oObj = $oScopeSet->Fetch())
  813. {
  814. $iObj = $oObj->GetKey();
  815. if (!in_array($iObj, $aVisited))
  816. {
  817. $iRow++;
  818. $this->UpdateMissingObject($aResult, $iRow, $oObj, $oChange);
  819. }
  820. }
  821. }
  822. // Fill in the blanks - the result matrix is expected to be 100% complete
  823. //
  824. foreach($this->m_aData as $iRow => $aRowData)
  825. {
  826. foreach($this->m_aAttList as $iCol)
  827. {
  828. if (!array_key_exists($iCol, $aResult[$iRow]))
  829. {
  830. $aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]);
  831. }
  832. }
  833. foreach($this->m_aExtKeys as $sAttCode => $aForeignAtts)
  834. {
  835. if (!array_key_exists($sAttCode, $aResult[$iRow]))
  836. {
  837. $aResult[$iRow][$sAttCode] = new CellStatus_Void('n/a');
  838. }
  839. foreach ($aForeignAtts as $sForeignAttCode => $iCol)
  840. {
  841. if (!array_key_exists($iCol, $aResult[$iRow]))
  842. {
  843. // The foreign attribute is one of our reconciliation key
  844. $aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]);
  845. }
  846. }
  847. }
  848. }
  849. return $aResult;
  850. }
  851. /**
  852. * Display the history of bulk imports
  853. */
  854. static function DisplayImportHistory(WebPage $oPage, $bFromAjax = false, $bShowAll = false)
  855. {
  856. $sAjaxDivId = "CSVImportHistory";
  857. if (!$bFromAjax)
  858. {
  859. $oPage->add('<div id="'.$sAjaxDivId.'">');
  860. }
  861. $oPage->p(Dict::S('UI:History:BulkImports+'));
  862. $oBulkChangeSearch = DBObjectSearch::FromOQL("SELECT CMDBChange WHERE userinfo LIKE '%(CSV)'");
  863. $iQueryLimit = $bShowAll ? 0 : MetaModel::GetConfig()->GetMaxDisplayLimit() + 1;
  864. $oBulkChanges = new DBObjectSet($oBulkChangeSearch, array('date' => false), array(), null, $iQueryLimit);
  865. $oAppContext = new ApplicationContext();
  866. $bLimitExceeded = false;
  867. if ($oBulkChanges->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit())
  868. {
  869. $bLimitExceeded = true;
  870. if (!$bShowAll)
  871. {
  872. $iMaxObjects = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit());
  873. $oBulkChanges->SetLimit($iMaxObjects);
  874. }
  875. }
  876. $oBulkChanges->Seek(0);
  877. $aDetails = array();
  878. while ($oChange = $oBulkChanges->Fetch())
  879. {
  880. $sDate = '<a href="csvimport.php?step=10&changeid='.$oChange->GetKey().'&'.$oAppContext->GetForLink().'">'.$oChange->Get('date').'</a>';
  881. $sUser = $oChange->GetUserName();
  882. if (preg_match('/^(.*)\\(CSV\\)$/i', $oChange->Get('userinfo'), $aMatches))
  883. {
  884. $sUser = $aMatches[1];
  885. }
  886. else
  887. {
  888. $sUser = $oChange->Get('userinfo');
  889. }
  890. $oOpSearch = DBObjectSearch::FromOQL("SELECT CMDBChangeOpCreate WHERE change = :change_id");
  891. $oOpSet = new DBObjectSet($oOpSearch, array(), array('change_id' => $oChange->GetKey()));
  892. $iCreated = $oOpSet->Count();
  893. // Get the class from the first item found (assumption: a CSV load is done for a single class)
  894. if ($oCreateOp = $oOpSet->Fetch())
  895. {
  896. $sClass = $oCreateOp->Get('objclass');
  897. }
  898. $oOpSearch = DBObjectSearch::FromOQL("SELECT CMDBChangeOpSetAttribute WHERE change = :change_id");
  899. $oOpSet = new DBObjectSet($oOpSearch, array(), array('change_id' => $oChange->GetKey()));
  900. $aModified = array();
  901. $aAttList = array();
  902. while ($oModified = $oOpSet->Fetch())
  903. {
  904. // Get the class (if not done earlier on object creation)
  905. $sClass = $oModified->Get('objclass');
  906. $iKey = $oModified->Get('objkey');
  907. $sAttCode = $oModified->Get('attcode');
  908. $aAttList[$sClass][$sAttCode] = true;
  909. $aModified["$sClass::$iKey"] = true;
  910. }
  911. $iModified = count($aModified);
  912. // Assumption: there is only one class of objects being loaded
  913. // Then the last class found gives us the class for every object
  914. if ( ($iModified > 0) || ($iCreated > 0))
  915. {
  916. $aDetails[] = array('date' => $sDate, 'user' => $sUser, 'class' => $sClass, 'created' => $iCreated, 'modified' => $iModified);
  917. }
  918. }
  919. $aConfig = array( 'date' => array('label' => Dict::S('UI:History:Date'), 'description' => Dict::S('UI:History:Date+')),
  920. 'user' => array('label' => Dict::S('UI:History:User'), 'description' => Dict::S('UI:History:User+')),
  921. 'class' => array('label' => Dict::S('Core:AttributeClass'), 'description' => Dict::S('Core:AttributeClass+')),
  922. 'created' => array('label' => Dict::S('UI:History:StatsCreations'), 'description' => Dict::S('UI:History:StatsCreations+')),
  923. 'modified' => array('label' => Dict::S('UI:History:StatsModifs'), 'description' => Dict::S('UI:History:StatsModifs+')),
  924. );
  925. if ($bLimitExceeded)
  926. {
  927. if ($bShowAll)
  928. {
  929. // Collapsible list
  930. $oPage->add('<p>'.Dict::Format('UI:CountOfResults', $oBulkChanges->Count()).'&nbsp;&nbsp;<a class="truncated" onclick="OnTruncatedHistoryToggle(false);">'.Dict::S('UI:CollapseList').'</a></p>');
  931. }
  932. else
  933. {
  934. // Truncated list
  935. $iMinDisplayLimit = MetaModel::GetConfig()->GetMinDisplayLimit();
  936. $sCollapsedLabel = Dict::Format('UI:TruncatedResults', $iMinDisplayLimit, $oBulkChanges->Count());
  937. $sLinkLabel = Dict::S('UI:DisplayAll');
  938. $oPage->add('<p>'.$sCollapsedLabel.'&nbsp;&nbsp;<a class="truncated" onclick="OnTruncatedHistoryToggle(true);">'.$sLinkLabel.'</p>');
  939. $oPage->add_ready_script(
  940. <<<EOF
  941. $('#$sAjaxDivId table.listResults').addClass('truncated');
  942. $('#$sAjaxDivId table.listResults tr:last td').addClass('truncated');
  943. EOF
  944. );
  945. $sAppContext = $oAppContext->GetForLink();
  946. $oPage->add_script(
  947. <<<EOF
  948. function OnTruncatedHistoryToggle(bShowAll)
  949. {
  950. $.get(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?{$sAppContext}', {operation: 'displayCSVHistory', showall: bShowAll}, function(data)
  951. {
  952. $('#$sAjaxDivId').html(data);
  953. var table = $('#$sAjaxDivId .listResults');
  954. table.tableHover(); // hover tables
  955. table.tablesorter( { widgets: ['myZebra', 'truncatedList']} ); // sortable and zebra tables
  956. }
  957. );
  958. }
  959. EOF
  960. );
  961. }
  962. }
  963. else
  964. {
  965. // Normal display - full list without any decoration
  966. }
  967. $oPage->table($aConfig, $aDetails);
  968. if (!$bFromAjax)
  969. {
  970. $oPage->add('</div>');
  971. }
  972. }
  973. /**
  974. * Display the details of an import
  975. */
  976. static function DisplayImportHistoryDetails(iTopWebPage $oPage, $iChange)
  977. {
  978. if ($iChange == 0)
  979. {
  980. throw new Exception("Missing parameter changeid");
  981. }
  982. $oChange = MetaModel::GetObject('CMDBChange', $iChange, false);
  983. if (is_null($oChange))
  984. {
  985. throw new Exception("Unknown change: $iChange");
  986. }
  987. $oPage->add("<div><p><h1>".Dict::Format('UI:History:BulkImportDetails', $oChange->Get('date'), $oChange->GetUserName())."</h1></p></div>\n");
  988. // Assumption : change made one single class of objects
  989. $aObjects = array();
  990. $aAttributes = array(); // array of attcode => occurences
  991. $oOpSearch = DBObjectSearch::FromOQL("SELECT CMDBChangeOp WHERE change = :change_id");
  992. $oOpSet = new DBObjectSet($oOpSearch, array(), array('change_id' => $iChange));
  993. while ($oOperation = $oOpSet->Fetch())
  994. {
  995. $sClass = $oOperation->Get('objclass');
  996. $iKey = $oOperation->Get('objkey');
  997. $iObjId = "$sClass::$iKey";
  998. if (!isset($aObjects[$iObjId]))
  999. {
  1000. $aObjects[$iObjId] = array();
  1001. $aObjects[$iObjId]['__class__'] = $sClass;
  1002. $aObjects[$iObjId]['__id__'] = $iKey;
  1003. }
  1004. if (get_class($oOperation) == 'CMDBChangeOpCreate')
  1005. {
  1006. $aObjects[$iObjId]['__created__'] = true;
  1007. }
  1008. elseif ($oOperation instanceof CMDBChangeOpSetAttribute)
  1009. {
  1010. $sAttCode = $oOperation->Get('attcode');
  1011. if (get_class($oOperation) == 'CMDBChangeOpSetAttributeScalar')
  1012. {
  1013. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1014. if ($oAttDef->IsExternalKey())
  1015. {
  1016. $sOldValue = Dict::S('UI:UndefinedObject');
  1017. if ($oOperation->Get('oldvalue') != 0)
  1018. {
  1019. $oOldTarget = MetaModel::GetObject($oAttDef->GetTargetClass(), $oOperation->Get('oldvalue'));
  1020. $sOldValue = $oOldTarget->GetHyperlink();
  1021. }
  1022. $sNewValue = Dict::S('UI:UndefinedObject');
  1023. if ($oOperation->Get('newvalue') != 0)
  1024. {
  1025. $oNewTarget = MetaModel::GetObject($oAttDef->GetTargetClass(), $oOperation->Get('newvalue'));
  1026. $sNewValue = $oNewTarget->GetHyperlink();
  1027. }
  1028. }
  1029. else
  1030. {
  1031. $sOldValue = $oOperation->GetAsHTML('oldvalue');
  1032. $sNewValue = $oOperation->GetAsHTML('newvalue');
  1033. }
  1034. $aObjects[$iObjId][$sAttCode] = $sOldValue.' -&gt; '.$sNewValue;
  1035. }
  1036. else
  1037. {
  1038. $aObjects[$iObjId][$sAttCode] = 'n/a';
  1039. }
  1040. if (isset($aAttributes[$sAttCode]))
  1041. {
  1042. $aAttributes[$sAttCode]++;
  1043. }
  1044. else
  1045. {
  1046. $aAttributes[$sAttCode] = 1;
  1047. }
  1048. }
  1049. }
  1050. $aDetails = array();
  1051. foreach($aObjects as $iUId => $aObjData)
  1052. {
  1053. $aRow = array();
  1054. $oObject = MetaModel::GetObject($aObjData['__class__'], $aObjData['__id__'], false);
  1055. if (is_null($oObject))
  1056. {
  1057. $aRow['object'] = $aObjData['__class__'].'::'.$aObjData['__id__'].' (deleted)';
  1058. }
  1059. else
  1060. {
  1061. $aRow['object'] = $oObject->GetHyperlink();
  1062. }
  1063. if (isset($aObjData['__created__']))
  1064. {
  1065. $aRow['operation'] = Dict::S('Change:ObjectCreated');
  1066. }
  1067. else
  1068. {
  1069. $aRow['operation'] = Dict::S('Change:ObjectModified');
  1070. }
  1071. foreach ($aAttributes as $sAttCode => $iOccurences)
  1072. {
  1073. if (isset($aObjData[$sAttCode]))
  1074. {
  1075. $aRow[$sAttCode] = $aObjData[$sAttCode];
  1076. }
  1077. elseif (!is_null($oObject))
  1078. {
  1079. // This is the current vaslue: $oObject->GetAsHtml($sAttCode)
  1080. // whereas we are displaying the value that was set at the time
  1081. // the object was created
  1082. // This requires addtional coding...let's do that later
  1083. $aRow[$sAttCode] = '';
  1084. }
  1085. else
  1086. {
  1087. $aRow[$sAttCode] = '';
  1088. }
  1089. }
  1090. $aDetails[] = $aRow;
  1091. }
  1092. $aConfig = array();
  1093. $aConfig['object'] = array('label' => MetaModel::GetName($sClass), 'description' => MetaModel::GetClassDescription($sClass));
  1094. $aConfig['operation'] = array('label' => Dict::S('UI:History:Changes'), 'description' => Dict::S('UI:History:Changes+'));
  1095. foreach ($aAttributes as $sAttCode => $iOccurences)
  1096. {
  1097. $aConfig[$sAttCode] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'description' => MetaModel::GetDescription($sClass, $sAttCode));
  1098. }
  1099. $oPage->table($aConfig, $aDetails);
  1100. }
  1101. }
  1102. ?>