import.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Import web service
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. //
  25. // Known limitations
  26. // - reconciliation is made on the first column
  27. //
  28. // Known issues
  29. // - ALMOST impossible to troubleshoot when an externl key has a wrong value
  30. // - no character escaping in the xml output (yes !?!?!)
  31. // - not outputing xml when a wrong input is given (class, attribute names)
  32. //
  33. require_once('../application/application.inc.php');
  34. require_once('../application/webpage.class.inc.php');
  35. require_once('../application/csvpage.class.inc.php');
  36. require_once('../application/clipage.class.inc.php');
  37. require_once('../application/startup.inc.php');
  38. class BulkLoadException extends Exception
  39. {
  40. }
  41. $aPageParams = array
  42. (
  43. 'auth_user' => array
  44. (
  45. 'mandatory' => true,
  46. 'modes' => 'cli',
  47. 'default' => null,
  48. 'description' => 'login (must have enough rights to create objects of the given class)',
  49. ),
  50. 'auth_pwd' => array
  51. (
  52. 'mandatory' => true,
  53. 'modes' => 'cli',
  54. 'default' => null,
  55. 'description' => 'password',
  56. ),
  57. 'class' => array
  58. (
  59. 'mandatory' => true,
  60. 'modes' => 'http,cli',
  61. 'default' => null,
  62. 'description' => 'class of loaded objects',
  63. ),
  64. 'csvdata' => array
  65. (
  66. 'mandatory' => true,
  67. 'modes' => 'http',
  68. 'default' => null,
  69. 'description' => 'data',
  70. ),
  71. 'csvfile' => array
  72. (
  73. 'mandatory' => true,
  74. 'modes' => 'cli',
  75. 'default' => '',
  76. 'description' => 'local data file, replaces csvdata if specified',
  77. ),
  78. 'charset' => array
  79. (
  80. 'mandatory' => false,
  81. 'modes' => 'http,cli',
  82. 'default' => 'UTF-8',
  83. 'description' => 'Character set encoding of the CSV data: UTF-8, ISO-8859-1, WINDOWS-1251, WINDOWS-1252, ISO-8859-15',
  84. ),
  85. 'separator' => array
  86. (
  87. 'mandatory' => false,
  88. 'modes' => 'http,cli',
  89. 'default' => ';',
  90. 'description' => 'column separator in CSV data',
  91. ),
  92. 'qualifier' => array
  93. (
  94. 'mandatory' => false,
  95. 'modes' => 'http,cli',
  96. 'default' => '"',
  97. 'description' => 'test qualifier in CSV data',
  98. ),
  99. 'output' => array
  100. (
  101. 'mandatory' => false,
  102. 'modes' => 'http,cli',
  103. 'default' => 'summary',
  104. 'description' => '[retcode] to return the count of lines in error, [summary] to return a concise report, [details] to get a detailed report (each line listed)',
  105. ),
  106. /*
  107. 'reportlevel' => array
  108. (
  109. 'mandatory' => false,
  110. 'modes' => 'http,cli',
  111. 'default' => 'errors|warnings|created|changed|unchanged',
  112. 'description' => 'combination of flags to limit the detailed output',
  113. ),
  114. */
  115. 'reconciliationkeys' => array
  116. (
  117. 'mandatory' => false,
  118. 'modes' => 'http,cli',
  119. 'default' => '',
  120. 'description' => 'name of the columns used to identify existing objects and update them, or create a new one',
  121. ),
  122. 'simulate' => array
  123. (
  124. 'mandatory' => false,
  125. 'modes' => 'http,cli',
  126. 'default' => '0',
  127. 'description' => 'If set to 1, then the load will not be executed, but the expected report will be produced',
  128. ),
  129. 'comment' => array
  130. (
  131. 'mandatory' => false,
  132. 'modes' => 'http,cli',
  133. 'default' => '',
  134. 'description' => 'Comment to be added into the change log',
  135. ),
  136. );
  137. function UsageAndExit($oP)
  138. {
  139. global $aPageParams;
  140. $bModeCLI = utils::IsModeCLI();
  141. $oP->p("USAGE:\n");
  142. foreach($aPageParams as $sParam => $aParamData)
  143. {
  144. $aModes = explode(',', $aParamData['modes']);
  145. if ($bModeCLI)
  146. {
  147. if (in_array('cli', $aModes))
  148. {
  149. $sDesc = $aParamData['description'].', '.($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to ['.$aParamData['default'].']');
  150. $oP->p("$sParam = $sDesc");
  151. }
  152. }
  153. else
  154. {
  155. if (in_array('http', $aModes))
  156. {
  157. $sDesc = $aParamData['description'].', '.($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to ['.$aParamData['default'].']');
  158. $oP->p("$sParam = $sDesc");
  159. }
  160. }
  161. }
  162. $oP->output();
  163. exit;
  164. }
  165. function ReadParam($oP, $sParam)
  166. {
  167. global $aPageParams;
  168. assert(isset($aPageParams[$sParam]));
  169. assert(!$aPageParams[$sParam]['mandatory']);
  170. $sValue = utils::ReadParam($sParam, $aPageParams[$sParam]['default'], true /* Allow CLI */);
  171. return trim($sValue);
  172. }
  173. function ReadMandatoryParam($oP, $sParam)
  174. {
  175. global $aPageParams;
  176. assert(isset($aPageParams[$sParam]));
  177. assert($aPageParams[$sParam]['mandatory']);
  178. $sValue = utils::ReadParam($sParam, null, true /* Allow CLI */);
  179. if (is_null($sValue))
  180. {
  181. $oP->p("ERROR: Missing argument '$sParam'\n");
  182. UsageAndExit($oP);
  183. }
  184. return trim($sValue);
  185. }
  186. /////////////////////////////////
  187. // Main program
  188. if (utils::IsModeCLI())
  189. {
  190. $oP = new CLIPage("iTop - Bulk import");
  191. // Next steps:
  192. // specific arguments: 'csvfile'
  193. //
  194. $sAuthUser = ReadMandatoryParam($oP, 'auth_user');
  195. $sAuthPwd = ReadMandatoryParam($oP, 'auth_pwd');
  196. $sCsvFile = ReadMandatoryParam($oP, 'csvfile');
  197. if (UserRights::CheckCredentials($sAuthUser, $sAuthPwd))
  198. {
  199. UserRights::Login($sAuthUser); // Login & set the user's language
  200. }
  201. else
  202. {
  203. $oP->p("Access restricted or wrong credentials ('$sAuthUser')");
  204. exit;
  205. }
  206. if (!is_readable($sCsvFile))
  207. {
  208. $oP->p("Input file could not be found or could not be read: '$sCsvFile'");
  209. exit;
  210. }
  211. $sCSVData = file_get_contents($sCsvFile);
  212. }
  213. else
  214. {
  215. $_SESSION['login_mode'] = 'basic';
  216. require_once('../application/loginwebpage.class.inc.php');
  217. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  218. $oP = new CSVPage("iTop - Bulk import");
  219. $sCSVData = utils::ReadPostedParam('csvdata');
  220. }
  221. try
  222. {
  223. //////////////////////////////////////////////////
  224. //
  225. // Read parameters
  226. //
  227. $sClass = ReadMandatoryParam($oP, 'class');
  228. $sSep = ReadParam($oP, 'separator');
  229. $sQualifier = ReadParam($oP, 'qualifier');
  230. $sCharSet = ReadParam($oP, 'charset');
  231. $sOutput = ReadParam($oP, 'output');
  232. // $sReportLevel = ReadParam($oP, 'reportlevel');
  233. $sReconcKeys = ReadParam($oP, 'reconciliationkeys');
  234. $sSimulate = ReadParam($oP, 'simulate');
  235. $sComment = ReadParam($oP, 'comment');
  236. //////////////////////////////////////////////////
  237. //
  238. // Check parameters format/consistency
  239. //
  240. if (!MetaModel::IsValidClass($sClass))
  241. {
  242. throw new BulkLoadException("Unknown class: '$sClass'");
  243. }
  244. if (strlen($sSep) > 1)
  245. {
  246. throw new BulkLoadException("Separator is limited to one character, found '$sSep'");
  247. }
  248. if (strlen($sQualifier) > 1)
  249. {
  250. throw new BulkLoadException("Text qualifier is limited to one character, found '$sQualifier'");
  251. }
  252. if (!in_array($sOutput, array('retcode', 'summary', 'details')))
  253. {
  254. throw new BulkLoadException("Unknown output format: '$sOutput'");
  255. }
  256. /*
  257. $aReportLevels = explode('|', $sReportLevel);
  258. foreach($aReportLevels as $sLevel)
  259. {
  260. if (!in_array($sLevel, explode('|', 'errors|warnings|created|changed|unchanged')))
  261. {
  262. throw new BulkLoadException("Unknown level in reporting level: '$sLevel'");
  263. }
  264. }
  265. */
  266. if ($sSimulate == '1')
  267. {
  268. $bSimulate = true;
  269. }
  270. else
  271. {
  272. $bSimulate = false;
  273. }
  274. //////////////////////////////////////////////////
  275. //
  276. // Security
  277. //
  278. if (!UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY))
  279. {
  280. throw new SecurityException(Dict::Format('UI:Error:BulkModifyNotAllowedOn_Class', $sClass));
  281. }
  282. //////////////////////////////////////////////////
  283. //
  284. // Parse first line, check attributes, analyse the request
  285. //
  286. if ($sCharSet == 'UTF-8')
  287. {
  288. $sUTF8Data = $sCSVData;
  289. }
  290. else
  291. {
  292. $sUTF8Data = iconv($sCharSet, 'UTF-8//IGNORE//TRANSLIT', $sCSVData);
  293. }
  294. $oCSVParser = new CSVParser($sUTF8Data, $sSep, $sQualifier);
  295. // Limitation: as the attribute list is in the first line, we can not match external key by a third-party attribute
  296. $aRawFieldList = $oCSVParser->ListFields();
  297. $iColCount = count($aRawFieldList);
  298. $aAttList = array();
  299. $aExtKeys = array();
  300. foreach($aRawFieldList as $iFieldId => $sFieldName)
  301. {
  302. $aMatches = array();
  303. if (preg_match('/^(.+)\*$/', $sFieldName, $aMatches))
  304. {
  305. // Ignore any trailing "star" (*) that simply indicates a mandatory field
  306. $sFieldName = $aMatches[1];
  307. }
  308. if (preg_match('/^(.*)->(.*)$/', trim($sFieldName), $aMatches))
  309. {
  310. // The column has been specified as "extkey->attcode"
  311. //
  312. $sExtKeyAttCode = $aMatches[1];
  313. $sRemoteAttCode = $aMatches[2];
  314. if (!MetaModel::IsValidAttCode($sClass, $sExtKeyAttCode))
  315. {
  316. throw new BulkLoadException("Unknown attribute '$sExtKeyAttCode' (class: '$sClass')");
  317. }
  318. $oAtt = MetaModel::GetAttributeDef($sClass, $sExtKeyAttCode);
  319. if (!$oAtt->IsExternalKey())
  320. {
  321. throw new BulkLoadException("Not an external key '$sExtKeyAttCode' (class: '$sClass')");
  322. }
  323. $sTargetClass = $oAtt->GetTargetClass();
  324. if (!MetaModel::IsValidAttCode($sTargetClass, $sRemoteAttCode))
  325. {
  326. throw new BulkLoadException("Unknown attribute '$sRemoteAttCode' (key: '$sExtKeyAttCode', class: '$sTargetClass')");
  327. }
  328. $aExtKeys[$sExtKeyAttCode][$sRemoteAttCode] = $iFieldId;
  329. }
  330. else
  331. {
  332. // The column has been specified as "attcode"
  333. //
  334. if (!MetaModel::IsValidAttCode($sClass, $sFieldName))
  335. {
  336. throw new BulkLoadException("Unknown attribute '$sFieldName' (class: '$sClass')");
  337. }
  338. $oAtt = MetaModel::GetAttributeDef($sClass, $sFieldName);
  339. if ($oAtt->IsExternalKey())
  340. {
  341. $aExtKeys[$sFieldName]['id'] = $iFieldId;
  342. $aAttList[$sFieldName] = $iFieldId;
  343. }
  344. elseif ($oAtt->IsExternalField())
  345. {
  346. $sExtKeyAttCode = $oAtt->GetKeyAttCode();
  347. $sRemoteAttCode = $oAtt->GetExtAttCode();
  348. $aExtKeys[$sExtKeyAttCode][$sRemoteAttCode] = $iFieldId;
  349. }
  350. else
  351. {
  352. $aAttList[$sFieldName] = $iFieldId;
  353. }
  354. }
  355. }
  356. // Make sure there are some reconciliation keys
  357. //
  358. if (empty($sReconcKeys))
  359. {
  360. $aReconcSpec = array();
  361. // Base reconciliation scheme on the default one
  362. // The reconciliation attributes not present in the data will be ignored
  363. foreach(MetaModel::GetReconcKeys($sClass) as $sReconcKeyAttCode)
  364. {
  365. if (in_array($sReconcKeyAttCode, $aRawFieldList))
  366. {
  367. $aReconcSpec[] = $sReconcKeyAttCode;
  368. }
  369. }
  370. if (count($aReconcSpec) == 0)
  371. {
  372. throw new BulkLoadException("No reconciliation scheme could be defined, please add a column corresponding to one defined reconciliation key (class: '$sClass', reconciliation:".implode(',', MetaModel::GetReconcKeys($sClass)).")");
  373. }
  374. $sReconcKeys = implode(',', $aReconcSpec);
  375. }
  376. // Interpret the list of reconciliation keys
  377. //
  378. $aFinalReconcilKeys = array();
  379. $aReconcilKeysReport = array();
  380. foreach (explode(',', $sReconcKeys) as $sReconcKey)
  381. {
  382. $sReconcKey = trim($sReconcKey);
  383. if (empty($sReconcKey)) continue; // skip empty spec
  384. if (!in_array($sReconcKey, $aRawFieldList))
  385. {
  386. throw new BulkLoadException("Reconciliation keys not found in the input columns '$sReconcKey' (class: '$sClass')");
  387. }
  388. if (preg_match('/^(.*)->(.*)$/', trim($sReconcKey), $aMatches))
  389. {
  390. // The column has been specified as "extkey->attcode"
  391. //
  392. $sExtKeyAttCode = $aMatches[1];
  393. $sRemoteAttCode = $aMatches[2];
  394. $aFinalReconcilKeys[] = $sExtKeyAttCode;
  395. $aReconcilKeysReport[$sExtKeyAttCode][] = $sRemoteAttCode;
  396. }
  397. else
  398. {
  399. if (!MetaModel::IsValidAttCode($sClass, $sReconcKey))
  400. {
  401. // Safety net: should never happen, but...
  402. throw new BulkLoadException("Unknown reconciliation attribute '$sReconcKey' (class: '$sClass')");
  403. }
  404. $oAtt = MetaModel::GetAttributeDef($sClass, $sReconcKey);
  405. if ($oAtt->IsExternalKey())
  406. {
  407. $aFinalReconcilKeys[] = $sReconcKey;
  408. $aReconcilKeysReport[$sReconcKey][] = 'id';
  409. }
  410. elseif ($oAtt->IsExternalField())
  411. {
  412. $sReconcAttCode = $oAtt->GetKeyAttCode();
  413. $sReconcKeyReport = "$sReconcAttCode ($sReconcKey)";
  414. $aFinalReconcilKeys[] = $sReconcAttCode;
  415. $aReconcilKeysReport[$sReconcAttCode][] = $sReconcKeyReport;
  416. }
  417. else
  418. {
  419. $aFinalReconcilKeys[] = $sReconcKey;
  420. $aReconcilKeysReport[$sReconcKey] = array();
  421. }
  422. }
  423. }
  424. //////////////////////////////////////////////////
  425. //
  426. // Go for parsing and interpretation
  427. //
  428. $aData = $oCSVParser->ToArray();
  429. $iLineCount = count($aData);
  430. $oBulk = new BulkChange(
  431. $sClass,
  432. $aData,
  433. $aAttList,
  434. $aExtKeys,
  435. $aFinalReconcilKeys
  436. );
  437. if ($bSimulate)
  438. {
  439. $oMyChange = null;
  440. }
  441. else
  442. {
  443. $oMyChange = MetaModel::NewObject("CMDBChange");
  444. $oMyChange->Set("date", time());
  445. if (UserRights::IsImpersonated())
  446. {
  447. $sUserString = Dict::Format('UI:Archive_User_OnBehalfOf_User', UserRights::GetRealUser(), UserRights::GetUser());
  448. }
  449. else
  450. {
  451. $sUserString = UserRights::GetUser();
  452. }
  453. if (strlen($sComment) > 0)
  454. {
  455. $sMoreInfo = 'Web Service (CSV) - '.$sComment;
  456. }
  457. else
  458. {
  459. $sMoreInfo = 'Web Service (CSV)';
  460. }
  461. $oMyChange->Set("userinfo", $sUserString.', '.$sMoreInfo);
  462. $iChangeId = $oMyChange->DBInsert();
  463. }
  464. $aRes = $oBulk->Process($oMyChange);
  465. //////////////////////////////////////////////////
  466. //
  467. // Compute statistics
  468. //
  469. $iCountErrors = 0;
  470. $iCountWarnings = 0;
  471. $iCountCreations = 0;
  472. $iCountUpdates = 0;
  473. $iCountUnchanged = 0;
  474. foreach($aRes as $iRow => $aRowData)
  475. {
  476. $bWritten = false;
  477. $oStatus = $aRowData["__STATUS__"];
  478. switch(get_class($oStatus))
  479. {
  480. case 'RowStatus_NoChange':
  481. $iCountUnchanged++;
  482. break;
  483. case 'RowStatus_Modify':
  484. $iCountUpdates++;
  485. $bWritten = true;
  486. break;
  487. case 'RowStatus_NewObj':
  488. $iCountCreations++;
  489. $bWritten = true;
  490. break;
  491. case 'RowStatus_Issue':
  492. $iCountErrors++;
  493. break;
  494. }
  495. if ($bWritten)
  496. {
  497. // Something has been done, still there may be some issues to report
  498. foreach($aRowData as $key => $value)
  499. {
  500. if (!is_object($value)) continue;
  501. switch (get_class($value))
  502. {
  503. case 'CellStatus_Void':
  504. case 'CellStatus_Modify':
  505. break;
  506. case 'CellStatus_Issue':
  507. case 'CellStatus_SearchIssue':
  508. case 'CellStatus_NullIssue':
  509. case 'CellStatus_Ambiguous':
  510. $iCountWarnings++;
  511. break;
  512. }
  513. }
  514. }
  515. }
  516. //////////////////////////////////////////////////
  517. //
  518. // Summary of settings and results
  519. //
  520. if ($sOutput == 'retcode')
  521. {
  522. $oP->add($iCountErrors);
  523. }
  524. if (($sOutput == "summary") || ($sOutput == 'details'))
  525. {
  526. $aReconciliationReport = array();
  527. foreach($aReconcilKeysReport as $sKey => $aKeyDetails)
  528. {
  529. if (count($aKeyDetails) > 0)
  530. {
  531. $aReconciliationReport[] = $sKey.' ('.implode(',', $aKeyDetails).')';
  532. }
  533. else
  534. {
  535. $aReconciliationReport[] = $sKey;
  536. }
  537. }
  538. $oP->add_comment("Class: ".$sClass);
  539. $oP->add_comment("Separator: ".$sSep);
  540. $oP->add_comment("Qualifier: ".$sQualifier);
  541. $oP->add_comment("Charset Encoding:".$sCharSet);
  542. $oP->add_comment("Data Size: ".strlen($sCSVData));
  543. $oP->add_comment("Data Lines: ".$iLineCount);
  544. $oP->add_comment("Columns: ".implode(', ', $aRawFieldList));
  545. $oP->add_comment("Reconciliation Keys: ".implode(', ', $aReconciliationReport));
  546. $oP->add_comment("Output format: ".$sOutput);
  547. // $oP->add_comment("Report level: ".$sReportLevel);
  548. $oP->add_comment("Simulate: ".($bSimulate ? '1' : '0'));
  549. $oP->add_comment("Change tracking comment: ".$sComment);
  550. $oP->add_comment("Issues: ".$iCountErrors);
  551. $oP->add_comment("Warnings: ".$iCountWarnings);
  552. $oP->add_comment("Created: ".$iCountCreations);
  553. $oP->add_comment("Updated: ".$iCountUpdates);
  554. $oP->add_comment("Unchanged: ".$iCountUnchanged);
  555. }
  556. if ($sOutput == 'details')
  557. {
  558. // Setup result presentation
  559. //
  560. $aDisplayConfig = array();
  561. $aDisplayConfig["__LINE__"] = array("label"=>"Line", "description"=>"");
  562. $aDisplayConfig["__STATUS__"] = array("label"=>"Status", "description"=>"");
  563. $aDisplayConfig["__OBJECT_CLASS__"] = array("label"=>"Object Class", "description"=>"");
  564. $aDisplayConfig["__OBJECT_ID__"] = array("label"=>"Object Id", "description"=>"");
  565. foreach($aExtKeys as $sExtKeyAttCode => $aRemoteAtt)
  566. {
  567. $sLabel = MetaModel::GetAttributeDef($sClass, $sExtKeyAttCode)->GetLabel();
  568. $aDisplayConfig["$sExtKeyAttCode"] = array("label"=>$sExtKeyAttCode, "description"=>$sLabel." - ext key");
  569. }
  570. foreach($aFinalReconcilKeys as $iCol => $sAttCode)
  571. {
  572. // $sLabel = MetaModel::GetAttributeDef($sClass, $sAttCode)->GetLabel();
  573. // $aDisplayConfig["$iCol"] = array("label"=>"$sLabel", "description"=>"");
  574. }
  575. foreach ($aAttList as $sAttCode => $iCol)
  576. {
  577. $sLabel = MetaModel::GetAttributeDef($sClass, $sAttCode)->GetLabel();
  578. $aDisplayConfig["$iCol"] = array("label"=>$sAttCode, "description"=>$sLabel);
  579. }
  580. $aResultDisp = array(); // to be displayed
  581. foreach($aRes as $iRow => $aRowData)
  582. {
  583. $aRowDisp = array();
  584. $aRowDisp["__LINE__"] = $iRow;
  585. if (is_object($aRowData["__STATUS__"]))
  586. {
  587. $aRowDisp["__STATUS__"] = $aRowData["__STATUS__"]->GetDescription();
  588. }
  589. else
  590. {
  591. $aRowDisp["__STATUS__"] = "*No status available*";
  592. }
  593. if (isset($aRowData["finalclass"]) && isset($aRowData["id"]))
  594. {
  595. $aRowDisp["__OBJECT_CLASS__"] = $aRowData["finalclass"];
  596. $aRowDisp["__OBJECT_ID__"] = $aRowData["id"]->GetValue();
  597. }
  598. else
  599. {
  600. $aRowDisp["__OBJECT_CLASS__"] = "n/a";
  601. $aRowDisp["__OBJECT_ID__"] = "n/a";
  602. }
  603. foreach($aRowData as $key => $value)
  604. {
  605. $sKey = (string) $key;
  606. if ($sKey == '__STATUS__') continue;
  607. if ($sKey == 'finalclass') continue;
  608. if ($sKey == 'id') continue;
  609. if (is_object($value))
  610. {
  611. $aRowDisp["$sKey"] = $value->GetValue().$value->GetDescription();
  612. }
  613. else
  614. {
  615. $aRowDisp["$sKey"] = $value;
  616. }
  617. }
  618. $aResultDisp[$iRow] = $aRowDisp;
  619. }
  620. $oP->table($aDisplayConfig, $aResultDisp);
  621. }
  622. }
  623. catch(BulkLoadException $e)
  624. {
  625. $oP->add_comment($e->getMessage());
  626. }
  627. catch(SecurityException $e)
  628. {
  629. $oP->add_comment($e->getMessage());
  630. }
  631. catch(Exception $e)
  632. {
  633. $oP->add_comment((string)$e);
  634. }
  635. $oP->output();
  636. ?>