bulkchange.class.inc.php 35 KB

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