import.php 18 KB

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