bulkchange.class.inc.php 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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. $oForeignAtt = MetaModel::GetAttributeDef($oExtKey->GetTargetClass(), $sForeignAttCode);
  311. $value = $oForeignAtt->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  312. $oReconFilter->AddCondition($sForeignAttCode, $value, '=');
  313. $aResults[$iCol] = new CellStatus_Void($aRowData[$iCol]);
  314. }
  315. $oExtObjects = new CMDBObjectSet($oReconFilter);
  316. switch($oExtObjects->Count())
  317. {
  318. case 0:
  319. $aErrors[$sAttCode] = Dict::S('UI:CSVReport-Value-Issue-NotFound');
  320. $aResults[$sAttCode]= new CellStatus_SearchIssue();
  321. break;
  322. case 1:
  323. // Do change the external key attribute
  324. $oForeignObj = $oExtObjects->Fetch();
  325. $oTargetObj->Set($sAttCode, $oForeignObj->GetKey());
  326. break;
  327. default:
  328. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-FoundMany', $oExtObjects->Count());
  329. $aResults[$sAttCode]= new CellStatus_Ambiguous($oTargetObj->Get($sAttCode), $oExtObjects->Count(), $oReconFilter->ToOql());
  330. }
  331. }
  332. // Report
  333. if (!array_key_exists($sAttCode, $aResults))
  334. {
  335. $iForeignObj = $oTargetObj->Get($sAttCode);
  336. if (array_key_exists($sAttCode, $oTargetObj->ListChanges()))
  337. {
  338. if ($oTargetObj->IsNew())
  339. {
  340. $aResults[$sAttCode]= new CellStatus_Void($iForeignObj);
  341. }
  342. else
  343. {
  344. $aResults[$sAttCode]= new CellStatus_Modify($iForeignObj, $oTargetObj->GetOriginal($sAttCode));
  345. foreach ($aKeyConfig as $sForeignAttCode => $iCol)
  346. {
  347. // Report the change on reconciliation values as well
  348. $aResults[$iCol] = new CellStatus_Modify($aRowData[$iCol]);
  349. }
  350. }
  351. }
  352. else
  353. {
  354. $aResults[$sAttCode]= new CellStatus_Void($iForeignObj);
  355. }
  356. }
  357. }
  358. // Set the object attributes
  359. //
  360. foreach ($this->m_aAttList as $sAttCode => $iCol)
  361. {
  362. // skip the private key, if any
  363. if ($sAttCode == 'id') continue;
  364. $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  365. $aReasons = array();
  366. $iFlags = $oTargetObj->GetAttributeFlags($sAttCode, $aReasons);
  367. if ( (($iFlags & OPT_ATT_READONLY) == OPT_ATT_READONLY) && ( $oTargetObj->Get($sAttCode) != $aRowData[$iCol]) )
  368. {
  369. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-Readonly', $sAttCode, $oTargetObj->Get($sAttCode), $aRowData[$iCol]);
  370. }
  371. else if ($oAttDef->IsLinkSet() && $oAttDef->IsIndirect())
  372. {
  373. try
  374. {
  375. $oSet = $oAttDef->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  376. $oTargetObj->Set($sAttCode, $oSet);
  377. }
  378. catch(CoreException $e)
  379. {
  380. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-Format', $e->getMessage());
  381. }
  382. }
  383. else
  384. {
  385. $value = $oAttDef->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  386. if (is_null($value) && (strlen($aRowData[$iCol]) > 0))
  387. {
  388. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-NoMatch', $sAttCode);
  389. }
  390. else
  391. {
  392. $res = $oTargetObj->CheckValue($sAttCode, $value);
  393. if ($res === true)
  394. {
  395. $oTargetObj->Set($sAttCode, $value);
  396. }
  397. else
  398. {
  399. // $res is a string with the error description
  400. $aErrors[$sAttCode] = Dict::Format('UI:CSVReport-Value-Issue-Unknown', $sAttCode, $res);
  401. }
  402. }
  403. }
  404. }
  405. // Reporting on fields
  406. //
  407. $aChangedFields = $oTargetObj->ListChanges();
  408. foreach ($this->m_aAttList as $sAttCode => $iCol)
  409. {
  410. if ($sAttCode == 'id')
  411. {
  412. $aResults[$iCol]= new CellStatus_Void($aRowData[$iCol]);
  413. }
  414. else
  415. {
  416. if ($this->m_bReportHtml)
  417. {
  418. $sCurValue = $oTargetObj->GetAsHTML($sAttCode, $this->m_bLocalizedValues);
  419. $sOrigValue = $oTargetObj->GetOriginalAsHTML($sAttCode, $this->m_bLocalizedValues);
  420. $sInput = htmlentities($aRowData[$iCol], ENT_QUOTES, 'UTF-8');
  421. }
  422. else
  423. {
  424. $sCurValue = $oTargetObj->GetAsCSV($sAttCode, $this->m_sReportCsvSep, $this->m_sReportCsvDelimiter, $this->m_bLocalizedValues);
  425. $sOrigValue = $oTargetObj->GetOriginalAsCSV($sAttCode, $this->m_sReportCsvSep, $this->m_sReportCsvDelimiter, $this->m_bLocalizedValues);
  426. $sInput = $aRowData[$iCol];
  427. }
  428. if (isset($aErrors[$sAttCode]))
  429. {
  430. $aResults[$iCol]= new CellStatus_Issue($aRowData[$iCol], $sOrigValue, $aErrors[$sAttCode]);
  431. }
  432. elseif (array_key_exists($sAttCode, $aChangedFields))
  433. {
  434. if ($oTargetObj->IsNew())
  435. {
  436. $aResults[$iCol]= new CellStatus_Void($sCurValue);
  437. }
  438. else
  439. {
  440. $aResults[$iCol]= new CellStatus_Modify($sCurValue, $sOrigValue);
  441. }
  442. }
  443. else
  444. {
  445. // By default... nothing happens
  446. $aResults[$iCol]= new CellStatus_Void($aRowData[$iCol]);
  447. }
  448. }
  449. }
  450. // Checks
  451. //
  452. $res = $oTargetObj->CheckConsistency();
  453. if ($res !== true)
  454. {
  455. // $res contains the error description
  456. $aErrors["GLOBAL"] = Dict::Format('UI:CSVReport-Row-Issue-Inconsistent', $res);
  457. }
  458. return $aResults;
  459. }
  460. protected function PrepareMissingObject(&$oTargetObj, &$aErrors)
  461. {
  462. $aResults = array();
  463. $aErrors = array();
  464. // External keys
  465. //
  466. foreach($this->m_aExtKeys as $sAttCode => $aKeyConfig)
  467. {
  468. //$oExtKey = MetaModel::GetAttributeDef(get_class($oTargetObj), $sAttCode);
  469. $aResults[$sAttCode]= new CellStatus_Void($oTargetObj->Get($sAttCode));
  470. foreach ($aKeyConfig as $sForeignAttCode => $iCol)
  471. {
  472. $aResults[$iCol] = new CellStatus_Void('?');
  473. }
  474. }
  475. // Update attributes
  476. //
  477. foreach($this->m_aOnDisappear as $sAttCode => $value)
  478. {
  479. if (!MetaModel::IsValidAttCode(get_class($oTargetObj), $sAttCode))
  480. {
  481. throw new BulkChangeException('Invalid attribute code', array('class' => get_class($oTargetObj), 'attcode' => $sAttCode));
  482. }
  483. $oTargetObj->Set($sAttCode, $value);
  484. if (!array_key_exists($sAttCode, $this->m_aAttList))
  485. {
  486. // #@# will be out of the reporting... (counted anyway)
  487. }
  488. }
  489. // Reporting on fields
  490. //
  491. $aChangedFields = $oTargetObj->ListChanges();
  492. foreach ($this->m_aAttList as $sAttCode => $iCol)
  493. {
  494. if ($sAttCode == 'id')
  495. {
  496. $aResults[$iCol]= new CellStatus_Void($oTargetObj->GetKey());
  497. }
  498. if (array_key_exists($sAttCode, $aChangedFields))
  499. {
  500. $aResults[$iCol]= new CellStatus_Modify($oTargetObj->Get($sAttCode), $oTargetObj->GetOriginal($sAttCode));
  501. }
  502. else
  503. {
  504. // By default... nothing happens
  505. $aResults[$iCol]= new CellStatus_Void($oTargetObj->Get($sAttCode));
  506. }
  507. }
  508. // Checks
  509. //
  510. $res = $oTargetObj->CheckConsistency();
  511. if ($res !== true)
  512. {
  513. // $res contains the error description
  514. $aErrors["GLOBAL"] = Dict::Format('UI:CSVReport-Row-Issue-Inconsistent', $res);
  515. }
  516. return $aResults;
  517. }
  518. protected function CreateObject(&$aResult, $iRow, $aRowData, CMDBChange $oChange = null)
  519. {
  520. $oTargetObj = MetaModel::NewObject($this->m_sClass);
  521. $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors);
  522. if (count($aErrors) > 0)
  523. {
  524. $sErrors = implode(', ', $aErrors);
  525. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Attribute'));
  526. return $oTargetObj;
  527. }
  528. // Check that any external key will have a value proposed
  529. $aMissingKeys = array();
  530. foreach (MetaModel::GetExternalKeys($this->m_sClass) as $sExtKeyAttCode => $oExtKey)
  531. {
  532. if (!$oExtKey->IsNullAllowed())
  533. {
  534. if (!array_key_exists($sExtKeyAttCode, $this->m_aExtKeys) && !array_key_exists($sExtKeyAttCode, $this->m_aAttList))
  535. {
  536. $aMissingKeys[] = $oExtKey->GetLabel();
  537. }
  538. }
  539. }
  540. if (count($aMissingKeys) > 0)
  541. {
  542. $sMissingKeys = implode(', ', $aMissingKeys);
  543. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::Format('UI:CSVReport-Row-Issue-MissingExtKey', $sMissingKeys));
  544. return $oTargetObj;
  545. }
  546. // Optionaly record the results
  547. //
  548. if ($oChange)
  549. {
  550. $newID = $oTargetObj->DBInsertTrackedNoReload($oChange);
  551. $aResult[$iRow]["__STATUS__"] = new RowStatus_NewObj($this->m_sClass, $newID);
  552. $aResult[$iRow]["finalclass"] = get_class($oTargetObj);
  553. $aResult[$iRow]["id"] = new CellStatus_Void($newID);
  554. }
  555. else
  556. {
  557. $aResult[$iRow]["__STATUS__"] = new RowStatus_NewObj();
  558. $aResult[$iRow]["finalclass"] = get_class($oTargetObj);
  559. $aResult[$iRow]["id"] = new CellStatus_Void(0);
  560. }
  561. return $oTargetObj;
  562. }
  563. protected function UpdateObject(&$aResult, $iRow, $oTargetObj, $aRowData, CMDBChange $oChange = null)
  564. {
  565. $aResult[$iRow] = $this->PrepareObject($oTargetObj, $aRowData, $aErrors);
  566. // Reporting
  567. //
  568. $aResult[$iRow]["finalclass"] = get_class($oTargetObj);
  569. $aResult[$iRow]["id"] = new CellStatus_Void($oTargetObj->GetKey());
  570. if (count($aErrors) > 0)
  571. {
  572. $sErrors = implode(', ', $aErrors);
  573. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Attribute'));
  574. return;
  575. }
  576. $aChangedFields = $oTargetObj->ListChanges();
  577. if (count($aChangedFields) > 0)
  578. {
  579. $aResult[$iRow]["__STATUS__"] = new RowStatus_Modify(count($aChangedFields));
  580. // Optionaly record the results
  581. //
  582. if ($oChange)
  583. {
  584. try
  585. {
  586. $oTargetObj->DBUpdateTracked($oChange);
  587. }
  588. catch(CoreException $e)
  589. {
  590. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue($e->getMessage());
  591. }
  592. }
  593. }
  594. else
  595. {
  596. $aResult[$iRow]["__STATUS__"] = new RowStatus_NoChange();
  597. }
  598. }
  599. protected function UpdateMissingObject(&$aResult, $iRow, $oTargetObj, CMDBChange $oChange = null)
  600. {
  601. $aResult[$iRow] = $this->PrepareMissingObject($oTargetObj, $aErrors);
  602. // Reporting
  603. //
  604. $aResult[$iRow]["finalclass"] = get_class($oTargetObj);
  605. $aResult[$iRow]["id"] = new CellStatus_Void($oTargetObj->GetKey());
  606. if (count($aErrors) > 0)
  607. {
  608. $sErrors = implode(', ', $aErrors);
  609. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Attribute'));
  610. return;
  611. }
  612. $aChangedFields = $oTargetObj->ListChanges();
  613. if (count($aChangedFields) > 0)
  614. {
  615. $aResult[$iRow]["__STATUS__"] = new RowStatus_Disappeared(count($aChangedFields));
  616. // Optionaly record the results
  617. //
  618. if ($oChange)
  619. {
  620. try
  621. {
  622. $oTargetObj->DBUpdateTracked($oChange);
  623. }
  624. catch(CoreException $e)
  625. {
  626. $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue($e->getMessage());
  627. }
  628. }
  629. }
  630. else
  631. {
  632. $aResult[$iRow]["__STATUS__"] = new RowStatus_Disappeared(0);
  633. }
  634. }
  635. public function Process(CMDBChange $oChange = null)
  636. {
  637. // Note: $oChange can be null, in which case the aim is to check what would be done
  638. // Debug...
  639. //
  640. if (false)
  641. {
  642. echo "<pre>\n";
  643. echo "Attributes:\n";
  644. print_r($this->m_aAttList);
  645. echo "ExtKeys:\n";
  646. print_r($this->m_aExtKeys);
  647. echo "Reconciliation:\n";
  648. print_r($this->m_aReconcilKeys);
  649. echo "Synchro scope:\n";
  650. print_r($this->m_sSynchroScope);
  651. echo "Synchro changes:\n";
  652. print_r($this->m_aOnDisappear);
  653. //echo "Data:\n";
  654. //print_r($this->m_aData);
  655. echo "</pre>\n";
  656. exit;
  657. }
  658. $aResult = array();
  659. if (!is_null($this->m_sDateFormat) && (strlen($this->m_sDateFormat) > 0))
  660. {
  661. // Translate dates from the source data
  662. //
  663. foreach ($this->m_aAttList as $sAttCode => $iCol)
  664. {
  665. $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  666. if ($oAttDef instanceof AttributeDateTime)
  667. {
  668. foreach($this->m_aData as $iRow => $aRowData)
  669. {
  670. $sNewDate = utils::StringToTime($this->m_aData[$iRow][$iCol], $this->m_sDateFormat);
  671. if ($sNewDate !== false)
  672. {
  673. // Todo - improve the reporting
  674. $this->m_aData[$iRow][$iCol] = $sNewDate;
  675. }
  676. else
  677. {
  678. // Leave the cell unchanged
  679. $aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
  680. $aResult[$iRow][$sAttCode] = new CellStatus_Issue(null, $this->m_aData[$iRow][$iCol], Dict::S('UI:CSVReport-Row-Issue-DateFormat'));
  681. }
  682. }
  683. }
  684. }
  685. }
  686. // Compute the results
  687. //
  688. if (!is_null($this->m_sSynchroScope))
  689. {
  690. $aVisited = array();
  691. }
  692. foreach($this->m_aData as $iRow => $aRowData)
  693. {
  694. if (isset($aResult[$iRow]["__STATUS__"]))
  695. {
  696. // An issue at the earlier steps - skip the rest
  697. continue;
  698. }
  699. try
  700. {
  701. $oReconciliationFilter = new CMDBSearchFilter($this->m_sClass);
  702. $bSkipQuery = false;
  703. foreach($this->m_aReconcilKeys as $sAttCode)
  704. {
  705. $valuecondition = null;
  706. if (array_key_exists($sAttCode, $this->m_aExtKeys))
  707. {
  708. if ($this->IsNullExternalKeySpec($aRowData, $sAttCode))
  709. {
  710. $oExtKey = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  711. if ($oExtKey->IsNullAllowed())
  712. {
  713. $valuecondition = $oExtKey->GetNullValue();
  714. $aResult[$iRow][$sAttCode] = new CellStatus_Void($oExtKey->GetNullValue());
  715. }
  716. else
  717. {
  718. $aResult[$iRow][$sAttCode] = new CellStatus_NullIssue();
  719. }
  720. }
  721. else
  722. {
  723. // The value has to be found or verified
  724. list($sQuery, $aMatches) = $this->ResolveExternalKey($aRowData, $sAttCode, $aResult[$iRow]);
  725. if (count($aMatches) == 1)
  726. {
  727. $oRemoteObj = reset($aMatches); // first item
  728. $valuecondition = $oRemoteObj->GetKey();
  729. $aResult[$iRow][$sAttCode] = new CellStatus_Void($oRemoteObj->GetKey());
  730. }
  731. elseif (count($aMatches) == 0)
  732. {
  733. $aResult[$iRow][$sAttCode] = new CellStatus_SearchIssue();
  734. }
  735. else
  736. {
  737. $aResult[$iRow][$sAttCode] = new CellStatus_Ambiguous(null, count($aMatches), $sQuery);
  738. }
  739. }
  740. }
  741. else
  742. {
  743. // The value is given in the data row
  744. $iCol = $this->m_aAttList[$sAttCode];
  745. $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode);
  746. $valuecondition = $oAttDef->MakeValueFromString($aRowData[$iCol], $this->m_bLocalizedValues);
  747. }
  748. if (is_null($valuecondition))
  749. {
  750. $bSkipQuery = true;
  751. }
  752. else
  753. {
  754. $oReconciliationFilter->AddCondition($sAttCode, $valuecondition, '=');
  755. }
  756. }
  757. if ($bSkipQuery)
  758. {
  759. $aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Reconciliation'));
  760. }
  761. else
  762. {
  763. $oReconciliationSet = new CMDBObjectSet($oReconciliationFilter);
  764. switch($oReconciliationSet->Count())
  765. {
  766. case 0:
  767. $oTargetObj = $this->CreateObject($aResult, $iRow, $aRowData, $oChange);
  768. // $aResult[$iRow]["__STATUS__"]=> set in CreateObject
  769. $aVisited[] = $oTargetObj->GetKey();
  770. break;
  771. case 1:
  772. $oTargetObj = $oReconciliationSet->Fetch();
  773. $this->UpdateObject($aResult, $iRow, $oTargetObj, $aRowData, $oChange);
  774. // $aResult[$iRow]["__STATUS__"]=> set in UpdateObject
  775. if (!is_null($this->m_sSynchroScope))
  776. {
  777. $aVisited[] = $oTargetObj->GetKey();
  778. }
  779. break;
  780. default:
  781. // Found several matches, ambiguous
  782. $aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::S('UI:CSVReport-Row-Issue-Ambiguous'));
  783. $aResult[$iRow]["id"]= new CellStatus_Ambiguous(0, $oReconciliationSet->Count(), $oReconciliationFilter->ToOql());
  784. $aResult[$iRow]["finalclass"]= 'n/a';
  785. }
  786. }
  787. }
  788. catch (Exception $e)
  789. {
  790. $aResult[$iRow]["__STATUS__"]= new RowStatus_Issue(Dict::Format('UI:CSVReport-Row-Issue-Internal', get_class($e), $e->getMessage()));
  791. }
  792. }
  793. if (!is_null($this->m_sSynchroScope))
  794. {
  795. // Compute the delta between the scope and visited objects
  796. $oScopeSearch = DBObjectSearch::FromOQL($this->m_sSynchroScope);
  797. $oScopeSet = new DBObjectSet($oScopeSearch);
  798. while ($oObj = $oScopeSet->Fetch())
  799. {
  800. $iObj = $oObj->GetKey();
  801. if (!in_array($iObj, $aVisited))
  802. {
  803. $iRow++;
  804. $this->UpdateMissingObject($aResult, $iRow, $oObj, $oChange);
  805. }
  806. }
  807. }
  808. // Fill in the blanks - the result matrix is expected to be 100% complete
  809. //
  810. foreach($this->m_aData as $iRow => $aRowData)
  811. {
  812. foreach($this->m_aAttList as $iCol)
  813. {
  814. if (!array_key_exists($iCol, $aResult[$iRow]))
  815. {
  816. $aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]);
  817. }
  818. }
  819. foreach($this->m_aExtKeys as $sAttCode => $aForeignAtts)
  820. {
  821. if (!array_key_exists($sAttCode, $aResult[$iRow]))
  822. {
  823. $aResult[$iRow][$sAttCode] = new CellStatus_Void('n/a');
  824. }
  825. foreach ($aForeignAtts as $sForeignAttCode => $iCol)
  826. {
  827. if (!array_key_exists($iCol, $aResult[$iRow]))
  828. {
  829. // The foreign attribute is one of our reconciliation key
  830. $aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]);
  831. }
  832. }
  833. }
  834. }
  835. return $aResult;
  836. }
  837. /**
  838. * Display the history of bulk imports
  839. */
  840. static function DisplayImportHistory(WebPage $oPage, $bFromAjax = false, $bShowAll = false)
  841. {
  842. $sAjaxDivId = "CSVImportHistory";
  843. if (!$bFromAjax)
  844. {
  845. $oPage->add('<div id="'.$sAjaxDivId.'">');
  846. }
  847. $oPage->p(Dict::S('UI:History:BulkImports+'));
  848. $oBulkChangeSearch = DBObjectSearch::FromOQL("SELECT CMDBChange WHERE userinfo LIKE '%(CSV)'");
  849. $iQueryLimit = $bShowAll ? 0 : MetaModel::GetConfig()->GetMaxDisplayLimit() + 1;
  850. $oBulkChanges = new DBObjectSet($oBulkChangeSearch, array('date' => false), array(), null, $iQueryLimit);
  851. $oAppContext = new ApplicationContext();
  852. $bLimitExceeded = false;
  853. if ($oBulkChanges->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit())
  854. {
  855. $bLimitExceeded = true;
  856. if (!$bShowAll)
  857. {
  858. $iMaxObjects = appUserPreferences::GetPref('default_page_size', MetaModel::GetConfig()->GetMinDisplayLimit());
  859. $oBulkChanges->SetLimit($iMaxObjects);
  860. }
  861. }
  862. $oBulkChanges->Seek(0);
  863. $aDetails = array();
  864. while ($oChange = $oBulkChanges->Fetch())
  865. {
  866. $sDate = '<a href="csvimport.php?step=10&changeid='.$oChange->GetKey().'&'.$oAppContext->GetForLink().'">'.$oChange->Get('date').'</a>';
  867. $sUser = $oChange->GetUserName();
  868. if (preg_match('/^(.*)\\(CSV\\)$/i', $oChange->Get('userinfo'), $aMatches))
  869. {
  870. $sUser = $aMatches[1];
  871. }
  872. else
  873. {
  874. $sUser = $oChange->Get('userinfo');
  875. }
  876. $oOpSearch = DBObjectSearch::FromOQL("SELECT CMDBChangeOpCreate WHERE change = :change_id");
  877. $oOpSet = new DBObjectSet($oOpSearch, array(), array('change_id' => $oChange->GetKey()));
  878. $iCreated = $oOpSet->Count();
  879. // Get the class from the first item found (assumption: a CSV load is done for a single class)
  880. if ($oCreateOp = $oOpSet->Fetch())
  881. {
  882. $sClass = $oCreateOp->Get('objclass');
  883. }
  884. $oOpSearch = DBObjectSearch::FromOQL("SELECT CMDBChangeOpSetAttribute WHERE change = :change_id");
  885. $oOpSet = new DBObjectSet($oOpSearch, array(), array('change_id' => $oChange->GetKey()));
  886. $aModified = array();
  887. $aAttList = array();
  888. while ($oModified = $oOpSet->Fetch())
  889. {
  890. // Get the class (if not done earlier on object creation)
  891. $sClass = $oModified->Get('objclass');
  892. $iKey = $oModified->Get('objkey');
  893. $sAttCode = $oModified->Get('attcode');
  894. $aAttList[$sClass][$sAttCode] = true;
  895. $aModified["$sClass::$iKey"] = true;
  896. }
  897. $iModified = count($aModified);
  898. // Assumption: there is only one class of objects being loaded
  899. // Then the last class found gives us the class for every object
  900. if ( ($iModified > 0) || ($iCreated > 0))
  901. {
  902. $aDetails[] = array('date' => $sDate, 'user' => $sUser, 'class' => $sClass, 'created' => $iCreated, 'modified' => $iModified);
  903. }
  904. }
  905. $aConfig = array( 'date' => array('label' => Dict::S('UI:History:Date'), 'description' => Dict::S('UI:History:Date+')),
  906. 'user' => array('label' => Dict::S('UI:History:User'), 'description' => Dict::S('UI:History:User+')),
  907. 'class' => array('label' => Dict::S('Core:AttributeClass'), 'description' => Dict::S('Core:AttributeClass+')),
  908. 'created' => array('label' => Dict::S('UI:History:StatsCreations'), 'description' => Dict::S('UI:History:StatsCreations+')),
  909. 'modified' => array('label' => Dict::S('UI:History:StatsModifs'), 'description' => Dict::S('UI:History:StatsModifs+')),
  910. );
  911. if ($bLimitExceeded)
  912. {
  913. if ($bShowAll)
  914. {
  915. // Collapsible list
  916. $oPage->add('<p>'.Dict::Format('UI:CountOfResults', $oBulkChanges->Count()).'&nbsp;&nbsp;<a class="truncated" onclick="OnTruncatedHistoryToggle(false);">'.Dict::S('UI:CollapseList').'</a></p>');
  917. }
  918. else
  919. {
  920. // Truncated list
  921. $iMinDisplayLimit = MetaModel::GetConfig()->GetMinDisplayLimit();
  922. $sCollapsedLabel = Dict::Format('UI:TruncatedResults', $iMinDisplayLimit, $oBulkChanges->Count());
  923. $sLinkLabel = Dict::S('UI:DisplayAll');
  924. $oPage->add('<p>'.$sCollapsedLabel.'&nbsp;&nbsp;<a class="truncated" onclick="OnTruncatedHistoryToggle(true);">'.$sLinkLabel.'</p>');
  925. $oPage->add_ready_script(
  926. <<<EOF
  927. $('#$sAjaxDivId table.listResults').addClass('truncated');
  928. $('#$sAjaxDivId table.listResults tr:last td').addClass('truncated');
  929. EOF
  930. );
  931. $sAppContext = $oAppContext->GetForLink();
  932. $oPage->add_script(
  933. <<<EOF
  934. function OnTruncatedHistoryToggle(bShowAll)
  935. {
  936. $.get(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?{$sAppContext}', {operation: 'displayCSVHistory', showall: bShowAll}, function(data)
  937. {
  938. $('#$sAjaxDivId').html(data);
  939. var table = $('#$sAjaxDivId .listResults');
  940. table.tableHover(); // hover tables
  941. table.tablesorter( { widgets: ['myZebra', 'truncatedList']} ); // sortable and zebra tables
  942. }
  943. );
  944. }
  945. EOF
  946. );
  947. }
  948. }
  949. else
  950. {
  951. // Normal display - full list without any decoration
  952. }
  953. $oPage->table($aConfig, $aDetails);
  954. if (!$bFromAjax)
  955. {
  956. $oPage->add('</div>');
  957. }
  958. }
  959. /**
  960. * Display the details of an import
  961. */
  962. static function DisplayImportHistoryDetails(iTopWebPage $oPage, $iChange)
  963. {
  964. if ($iChange == 0)
  965. {
  966. throw new Exception("Missing parameter changeid");
  967. }
  968. $oChange = MetaModel::GetObject('CMDBChange', $iChange, false);
  969. if (is_null($oChange))
  970. {
  971. throw new Exception("Unknown change: $iChange");
  972. }
  973. $oPage->add("<div><p><h1>".Dict::Format('UI:History:BulkImportDetails', $oChange->Get('date'), $oChange->GetUserName())."</h1></p></div>\n");
  974. // Assumption : change made one single class of objects
  975. $aObjects = array();
  976. $aAttributes = array(); // array of attcode => occurences
  977. $oOpSearch = DBObjectSearch::FromOQL("SELECT CMDBChangeOp WHERE change = :change_id");
  978. $oOpSet = new DBObjectSet($oOpSearch, array(), array('change_id' => $iChange));
  979. while ($oOperation = $oOpSet->Fetch())
  980. {
  981. $sClass = $oOperation->Get('objclass');
  982. $iKey = $oOperation->Get('objkey');
  983. $iObjId = "$sClass::$iKey";
  984. if (!isset($aObjects[$iObjId]))
  985. {
  986. $aObjects[$iObjId] = array();
  987. $aObjects[$iObjId]['__class__'] = $sClass;
  988. $aObjects[$iObjId]['__id__'] = $iKey;
  989. }
  990. if (get_class($oOperation) == 'CMDBChangeOpCreate')
  991. {
  992. $aObjects[$iObjId]['__created__'] = true;
  993. }
  994. elseif ($oOperation instanceof CMDBChangeOpSetAttribute)
  995. {
  996. $sAttCode = $oOperation->Get('attcode');
  997. if (get_class($oOperation) == 'CMDBChangeOpSetAttributeScalar')
  998. {
  999. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  1000. if ($oAttDef->IsExternalKey())
  1001. {
  1002. $sOldValue = Dict::S('UI:UndefinedObject');
  1003. if ($oOperation->Get('oldvalue') != 0)
  1004. {
  1005. $oOldTarget = MetaModel::GetObject($oAttDef->GetTargetClass(), $oOperation->Get('oldvalue'));
  1006. $sOldValue = $oOldTarget->GetHyperlink();
  1007. }
  1008. $sNewValue = Dict::S('UI:UndefinedObject');
  1009. if ($oOperation->Get('newvalue') != 0)
  1010. {
  1011. $oNewTarget = MetaModel::GetObject($oAttDef->GetTargetClass(), $oOperation->Get('newvalue'));
  1012. $sNewValue = $oNewTarget->GetHyperlink();
  1013. }
  1014. }
  1015. else
  1016. {
  1017. $sOldValue = $oOperation->GetAsHTML('oldvalue');
  1018. $sNewValue = $oOperation->GetAsHTML('newvalue');
  1019. }
  1020. $aObjects[$iObjId][$sAttCode] = $sOldValue.' -&gt; '.$sNewValue;
  1021. }
  1022. else
  1023. {
  1024. $aObjects[$iObjId][$sAttCode] = 'n/a';
  1025. }
  1026. if (isset($aAttributes[$sAttCode]))
  1027. {
  1028. $aAttributes[$sAttCode]++;
  1029. }
  1030. else
  1031. {
  1032. $aAttributes[$sAttCode] = 1;
  1033. }
  1034. }
  1035. }
  1036. $aDetails = array();
  1037. foreach($aObjects as $iUId => $aObjData)
  1038. {
  1039. $aRow = array();
  1040. $oObject = MetaModel::GetObject($aObjData['__class__'], $aObjData['__id__'], false);
  1041. if (is_null($oObject))
  1042. {
  1043. $aRow['object'] = $aObjData['__class__'].'::'.$aObjData['__id__'].' (deleted)';
  1044. }
  1045. else
  1046. {
  1047. $aRow['object'] = $oObject->GetHyperlink();
  1048. }
  1049. if (isset($aObjData['__created__']))
  1050. {
  1051. $aRow['operation'] = Dict::S('Change:ObjectCreated');
  1052. }
  1053. else
  1054. {
  1055. $aRow['operation'] = Dict::S('Change:ObjectModified');
  1056. }
  1057. foreach ($aAttributes as $sAttCode => $iOccurences)
  1058. {
  1059. if (isset($aObjData[$sAttCode]))
  1060. {
  1061. $aRow[$sAttCode] = $aObjData[$sAttCode];
  1062. }
  1063. elseif (!is_null($oObject))
  1064. {
  1065. // This is the current vaslue: $oObject->GetAsHtml($sAttCode)
  1066. // whereas we are displaying the value that was set at the time
  1067. // the object was created
  1068. // This requires addtional coding...let's do that later
  1069. $aRow[$sAttCode] = '';
  1070. }
  1071. else
  1072. {
  1073. $aRow[$sAttCode] = '';
  1074. }
  1075. }
  1076. $aDetails[] = $aRow;
  1077. }
  1078. $aConfig = array();
  1079. $aConfig['object'] = array('label' => MetaModel::GetName($sClass), 'description' => MetaModel::GetClassDescription($sClass));
  1080. $aConfig['operation'] = array('label' => Dict::S('UI:History:Changes'), 'description' => Dict::S('UI:History:Changes+'));
  1081. foreach ($aAttributes as $sAttCode => $iOccurences)
  1082. {
  1083. $aConfig[$sAttCode] = array('label' => MetaModel::GetLabel($sClass, $sAttCode), 'description' => MetaModel::GetDescription($sClass, $sAttCode));
  1084. }
  1085. $oPage->table($aConfig, $aDetails);
  1086. }
  1087. }
  1088. ?>