ajax.render.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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. * Handles various ajax requests
  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. require_once('../approot.inc.php');
  25. require_once(APPROOT.'/application/application.inc.php');
  26. require_once(APPROOT.'/application/webpage.class.inc.php');
  27. require_once(APPROOT.'/application/ajaxwebpage.class.inc.php');
  28. require_once(APPROOT.'/application/wizardhelper.class.inc.php');
  29. require_once(APPROOT.'/application/ui.linkswidget.class.inc.php');
  30. require_once(APPROOT.'/application/ui.extkeywidget.class.inc.php');
  31. try
  32. {
  33. require_once(APPROOT.'/application/startup.inc.php');
  34. require_once(APPROOT.'/application/user.preferences.class.inc.php');
  35. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  36. LoginWebPage::DoLogin(false /* bMustBeAdmin */, true /* IsAllowedToPortalUsers */); // Check user rights and prompt if needed
  37. $oPage = new ajax_page("");
  38. $oPage->no_cache();
  39. $operation = utils::ReadParam('operation', '');
  40. $sFilter = stripslashes(utils::ReadParam('filter', ''));
  41. $sEncoding = utils::ReadParam('encoding', 'serialize');
  42. $sClass = utils::ReadParam('class', 'MissingAjaxParam');
  43. $sStyle = utils::ReadParam('style', 'list');
  44. switch($operation)
  45. {
  46. case 'pagination':
  47. $sExtraParams = stripslashes(utils::ReadParam('extra_param', ''));
  48. $aExtraParams = array();
  49. if (!empty($sExtraParams))
  50. {
  51. $aExtraParams = json_decode(str_replace("'", '"', $sExtraParams), true /* associative array */);
  52. }
  53. if ($sEncoding == 'oql')
  54. {
  55. $oFilter = CMDBSearchFilter::FromOQL($sFilter);
  56. }
  57. else
  58. {
  59. $oFilter = CMDBSearchFilter::unserialize($sFilter);
  60. }
  61. $iStart = utils::ReadParam('start',0);
  62. $iEnd = utils::ReadParam('end',1);
  63. $iSortCol = utils::ReadParam('sort_col',null);
  64. $sSelectMode = utils::ReadParam('select_mode', '');
  65. $bDisplayKey = utils::ReadParam('display_key', 'true') == 'true';
  66. $aList = utils::ReadParam('display_list', array());
  67. $sClassName = $oFilter->GetClass();
  68. //$aList = cmdbAbstractObject::FlattenZList(MetaModel::GetZListItems($sClassName, 'list'));
  69. // Filter the list to removed linked set since we are not able to display them here
  70. $aOrderBy = array();
  71. $aConfig = array();
  72. $iSortIndex = 0;
  73. if ($sSelectMode != '')
  74. {
  75. $aConfig['form::select'] = array();
  76. $iSortIndex++; // Take into account the extra (non-sortable) column for the checkbox/radio button.
  77. }
  78. if ($bDisplayKey)
  79. {
  80. $aConfig['key'] = array();
  81. if ($iSortIndex == $iSortCol)
  82. {
  83. $aOrderBy['friendlyname'] = (utils::ReadParam('sort_order', 'asc') == 'asc');
  84. }
  85. $iSortIndex++;
  86. }
  87. foreach($aList as $sAttCode)
  88. {
  89. $aConfig[$sAttCode] = array();
  90. }
  91. foreach($aList as $index => $sAttCode)
  92. {
  93. $oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
  94. if ($oAttDef instanceof AttributeLinkedSet)
  95. {
  96. // Removed from the display list
  97. unset($aList[$index]);
  98. }
  99. if ($iSortCol == $iSortIndex)
  100. {
  101. if ($oAttDef->IsExternalKey())
  102. {
  103. $sSortCol = $sAttCode.'_friendlyname';
  104. }
  105. else
  106. {
  107. $sSortCol = $sAttCode;
  108. }
  109. $aOrderBy[$sSortCol] = (utils::ReadParam('sort_order', 'asc') == 'asc');
  110. }
  111. $iSortIndex++;
  112. }
  113. // Load only the requested columns
  114. $oSet = new DBObjectSet($oFilter, $aOrderBy, $aExtraParams, null, $iEnd-$iStart, $iStart);
  115. $sClassAlias = $oSet->GetFilter()->GetClassAlias();
  116. $oSet->OptimizeColumnLoad(array($sClassAlias => $aList));
  117. while($oObj = $oSet->Fetch())
  118. {
  119. $aRow = array();
  120. $sDisabled = '';
  121. switch ($sSelectMode)
  122. {
  123. case 'single':
  124. $aRow['form::select'] = "<input type=\"radio\" $sDisabled name=\"selectObject\" value=\"".$oObj->GetKey()."\"></input>";
  125. break;
  126. case 'multiple':
  127. $aRow['form::select'] = "<input type=\"checkBox\" $sDisabled name=\"selectObject[]\" value=\"".$oObj->GetKey()."\"></input>";
  128. break;
  129. }
  130. if ($bDisplayKey)
  131. {
  132. $aRow['key'] = $oObj->GetHyperLink();
  133. }
  134. $sHilightClass = $oObj->GetHilightClass();
  135. if ($sHilightClass != '')
  136. {
  137. $aRow['@class'] = $sHilightClass;
  138. }
  139. foreach($aList as $sAttCode)
  140. {
  141. $aRow[$sAttCode] = $oObj->GetAsHTML($sAttCode);
  142. }
  143. $sRow = $oPage->GetTableRow($aRow, $aConfig);
  144. $oPage->add($sRow);
  145. }
  146. break;
  147. // ui.linkswidget
  148. case 'searchObjectsToAdd':
  149. $sRemoteClass = utils::ReadParam('sRemoteClass', '');
  150. $sAttCode = utils::ReadParam('sAttCode', '');
  151. $iInputId = utils::ReadParam('iInputId', '');
  152. $sSuffix = utils::ReadParam('sSuffix', '');
  153. $bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
  154. $aAlreadyLinked = utils::ReadParam('aAlreadyLinked', array());
  155. $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
  156. $oWidget->SearchObjectsToAdd($oPage, $sRemoteClass, $aAlreadyLinked);
  157. break;
  158. ////////////////////////////////////////////////////////////
  159. // ui.extkeywidget
  160. case 'searchObjectsToSelect':
  161. $sTargetClass = utils::ReadParam('sTargetClass', '');
  162. $iInputId = utils::ReadParam('iInputId', '');
  163. $sRemoteClass = utils::ReadParam('sRemoteClass', '');
  164. $sFilter = utils::ReadParam('sFilter');
  165. $sJson = utils::ReadParam('json', '');
  166. if (!empty($sJson))
  167. {
  168. $oWizardHelper = WizardHelper::FromJSON($sJson);
  169. $oObj = $oWizardHelper->GetTargetObject();
  170. }
  171. else
  172. {
  173. // Search form: no current object
  174. $oObj = null;
  175. }
  176. $oWidget = new UIExtKeyWidget($sTargetClass, $iInputId);
  177. $oWidget->SearchObjectsToSelect($oPage, $sFilter, $sRemoteClass, $oObj);
  178. break;
  179. // ui.extkeywidget: autocomplete
  180. case 'ac_extkey':
  181. $sTargetClass = utils::ReadParam('sTargetClass', '');
  182. $iInputId = utils::ReadParam('iInputId', '');
  183. $sFilter = utils::ReadParam('sFilter');
  184. $sJson = utils::ReadParam('json', '');
  185. $sContains = utils::ReadParam('q', '');
  186. if (!empty($sJson))
  187. {
  188. $oWizardHelper = WizardHelper::FromJSON($sJson);
  189. $oObj = $oWizardHelper->GetTargetObject();
  190. }
  191. else
  192. {
  193. // Search form: no current object
  194. $oObj = null;
  195. }
  196. $oWidget = new UIExtKeyWidget($sTargetClass, $iInputId);
  197. $oWidget->AutoComplete($oPage, $sFilter, $oObj, $sContains);
  198. break;
  199. // ui.extkeywidget
  200. case 'objectSearchForm':
  201. $sTargetClass = utils::ReadParam('sTargetClass', '');
  202. $iInputId = utils::ReadParam('iInputId', '');
  203. $sTitle = utils::ReadParam('sTitle');
  204. $oWidget = new UIExtKeyWidget($sTargetClass, $iInputId);
  205. $oWidget->GetSearchDialog($oPage, $sTitle);
  206. break;
  207. // ui.extkeywidget
  208. case 'objectCreationForm':
  209. $sTargetClass = utils::ReadParam('sTargetClass', '');
  210. $iInputId = utils::ReadParam('iInputId', '');
  211. $oWidget = new UIExtKeyWidget($sTargetClass, $iInputId);
  212. $oWidget->GetObjectCreationForm($oPage);
  213. break;
  214. // ui.extkeywidget
  215. case 'doCreateObject':
  216. $sTargetClass = utils::ReadParam('sTargetClass', '');
  217. $iInputId = utils::ReadParam('iInputId', '');
  218. $sFormPrefix = utils::ReadParam('sFormPrefix', '');
  219. $oWidget = new UIExtKeyWidget($sTargetClass, $iInputId);
  220. $aResult = $oWidget->DoCreateObject($oPage);
  221. echo json_encode($aResult);
  222. break;
  223. // ui.extkeywidget
  224. case 'getObjectName':
  225. $sTargetClass = utils::ReadParam('sTargetClass', '');
  226. $iInputId = utils::ReadParam('iInputId', '');
  227. $iObjectId = utils::ReadParam('iObjectId', '');
  228. $oWidget = new UIExtKeyWidget($sTargetClass, $iInputId);
  229. $sName = $oWidget->GetObjectName($iObjectId);
  230. echo json_encode(array('name' => $sName));
  231. break;
  232. // ui.extkeywidget
  233. case 'displayHierarchy':
  234. $sTargetClass = utils::ReadParam('sTargetClass', '');
  235. $sInputId = utils::ReadParam('sInputId', '');
  236. $sFilter = utils::ReadParam('sFilter');
  237. $sJson = utils::ReadParam('json', '');
  238. $currValue = utils::ReadParam('value', '');
  239. if (!empty($sJson))
  240. {
  241. $oWizardHelper = WizardHelper::FromJSON($sJson);
  242. $oObj = $oWizardHelper->GetTargetObject();
  243. }
  244. else
  245. {
  246. // Search form: no current object
  247. $oObj = null;
  248. }
  249. $oWidget = new UIExtKeyWidget($sTargetClass, $sInputId);
  250. $oWidget->DisplayHierarchy($oPage, $sFilter, $currValue);
  251. break;
  252. ////////////////////////////////////////////////////
  253. // ui.linkswidget
  254. case 'doAddObjects':
  255. $sAttCode = utils::ReadParam('sAttCode', '');
  256. $iInputId = utils::ReadParam('iInputId', '');
  257. $sSuffix = utils::ReadParam('sSuffix', '');
  258. $sRemoteClass = utils::ReadParam('sRemoteClass', $sClass);
  259. $bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
  260. $oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
  261. if ($sFilter != '')
  262. {
  263. $oFullSetFilter = DBObjectSearch::unserialize($sFilter);
  264. }
  265. else
  266. {
  267. $oFullSetFilter = new DBObjectSearch($sRemoteClass);
  268. }
  269. $oWidget->DoAddObjects($oPage, $oFullSetFilter);
  270. break;
  271. case 'wizard_helper_preview':
  272. $sJson = utils::ReadParam('json_obj', '');
  273. $oWizardHelper = WizardHelper::FromJSON($sJson);
  274. $oObj = $oWizardHelper->GetTargetObject();
  275. $oObj->DisplayBareProperties($oPage);
  276. break;
  277. case 'wizard_helper':
  278. $sJson = utils::ReadParam('json_obj', '');
  279. $oWizardHelper = WizardHelper::FromJSON($sJson);
  280. $oObj = $oWizardHelper->GetTargetObject();
  281. $sClass = $oWizardHelper->GetTargetClass();
  282. foreach($oWizardHelper->GetFieldsForDefaultValue() as $sAttCode)
  283. {
  284. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  285. $defaultValue = $oAttDef->GetDefaultValue();
  286. $oWizardHelper->SetDefaultValue($sAttCode, $defaultValue);
  287. $oObj->Set($sAttCode, $defaultValue);
  288. }
  289. $sFormPrefix = $oWizardHelper->GetFormPrefix();
  290. foreach($oWizardHelper->GetFieldsForAllowedValues() as $sAttCode)
  291. {
  292. $sId = $oWizardHelper->GetIdForField($sAttCode);
  293. if ($sId != '')
  294. {
  295. // It may happen that the field we'd like to update does not
  296. // exist in the form. For example, if the field should be hidden/read-only
  297. // in the current state of the object
  298. $value = $oObj->Get($sAttCode);
  299. $displayValue = $oObj->GetEditValue($sAttCode);
  300. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  301. $iFlags = MetaModel::GetAttributeFlags($sClass, $oObj->GetState(), $sAttCode);
  302. $sHTMLValue = cmdbAbstractObject::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value, $displayValue, $sId, '', $iFlags, array('this' => $oObj, 'formPrefix' => $sFormPrefix));
  303. // Make sure that we immediatly validate the field when we reload it
  304. $oPage->add_ready_script("$('#$sId').trigger('validate');");
  305. $oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
  306. }
  307. }
  308. $oPage->add_script("oWizardHelper{$sFormPrefix}.m_oData=".$oWizardHelper->ToJSON().";\noWizardHelper{$sFormPrefix}.UpdateFields();\n");
  309. break;
  310. // DisplayBlock
  311. case 'ajax':
  312. if ($sFilter != "")
  313. {
  314. $sExtraParams = stripslashes(utils::ReadParam('extra_params', ''));
  315. $aExtraParams = array();
  316. if (!empty($sExtraParams))
  317. {
  318. $aExtraParams = json_decode(str_replace("'", '"', $sExtraParams), true /* associative array */);
  319. }
  320. if ($sEncoding == 'oql')
  321. {
  322. $oFilter = CMDBSearchFilter::FromOQL($sFilter);
  323. }
  324. else
  325. {
  326. $oFilter = CMDBSearchFilter::unserialize($sFilter);
  327. }
  328. $oDisplayBlock = new DisplayBlock($oFilter, $sStyle, false);
  329. $aExtraParams['display_limit'] = true;
  330. $aExtraParams['truncated'] = true;
  331. $oDisplayBlock->RenderContent($oPage, $aExtraParams);
  332. }
  333. else
  334. {
  335. $oPage->p("Invalid query (empty filter).");
  336. }
  337. break;
  338. case 'displayCSVHistory':
  339. $bShowAll = (utils::ReadParam('showall', 'false') == 'true');
  340. BulkChange::DisplayImportHistory($oPage, true, $bShowAll);
  341. break;
  342. case 'details':
  343. $key = utils::ReadParam('id', 0);
  344. $oFilter = new DBObjectSearch($sClass);
  345. $oFilter->AddCondition('id', $key, '=');
  346. $oDisplayBlock = new DisplayBlock($oFilter, 'details', false);
  347. $oDisplayBlock->RenderContent($oPage);
  348. break;
  349. case 'pie_chart':
  350. $sGroupBy = utils::ReadParam('group_by', '');
  351. if ($sFilter != '')
  352. {
  353. if ($sEncoding == 'oql')
  354. {
  355. $oFilter = CMDBSearchFilter::FromOQL($sFilter);
  356. }
  357. else
  358. {
  359. $oFilter = CMDBSearchFilter::unserialize($sFilter);
  360. }
  361. $oDisplayBlock = new DisplayBlock($oFilter, 'pie_chart_ajax', false);
  362. $oDisplayBlock->RenderContent($oPage, array('group_by' => $sGroupBy));
  363. }
  364. else
  365. {
  366. $oPage->add("<chart>\n<chart_type>3d pie</chart_type><!-- empty filter '$sFilter' --></chart>\n.");
  367. }
  368. break;
  369. case 'open_flash_chart':
  370. $aParams = utils::ReadParam('params', array());
  371. if ($sFilter != '')
  372. {
  373. $oFilter = CMDBSearchFilter::unserialize($sFilter);
  374. $oDisplayBlock = new DisplayBlock($oFilter, 'open_flash_chart_ajax', false);
  375. $oDisplayBlock->RenderContent($oPage, $aParams);
  376. }
  377. else
  378. {
  379. $oPage->add("<chart>\n<chart_type>3d pie</chart_type><!-- empty filter '$sFilter' --></chart>\n.");
  380. }
  381. break;
  382. case 'modal_details':
  383. $key = utils::ReadParam('id', 0);
  384. $oFilter = new DBObjectSearch($sClass);
  385. $oFilter->AddCondition('id', $key, '=');
  386. $oPage->Add("<p style=\"width:100%; margin-top:-5px;padding:3px; background-color:#33f; color:#fff;\">Object Details</p>\n");
  387. $oDisplayBlock = new DisplayBlock($oFilter, 'details', false);
  388. $oDisplayBlock->RenderContent($oPage);
  389. $oPage->Add("<input type=\"button\" class=\"jqmClose\" value=\" Close \" />\n");
  390. break;
  391. case 'link':
  392. $sClass = utils::ReadParam('sclass', 'logInfra');
  393. $sAttCode = utils::ReadParam('attCode', 'name');
  394. //$sOrg = utils::ReadParam('org_id', '');
  395. $sName = utils::ReadParam('q', '');
  396. $iMaxCount = utils::ReadParam('max', 30);
  397. $iCount = 0;
  398. $oFilter = new DBObjectSearch($sClass);
  399. $oFilter->AddCondition($sAttCode, $sName, 'Begins with');
  400. //$oFilter->AddCondition('org_id', $sOrg, '=');
  401. $oSet = new CMDBObjectSet($oFilter, array($sAttCode => true));
  402. while( ($iCount < $iMaxCount) && ($oObj = $oSet->fetch()) )
  403. {
  404. $oPage->add($oObj->GetAsHTML($sAttCode)."|".$oObj->GetKey()."\n");
  405. $iCount++;
  406. }
  407. break;
  408. case 'create':
  409. case 'create_menu':
  410. $sClass = utils::ReadParam('class', '');
  411. $sFilter = utils::ReadParam('filter', '');
  412. menuNode::DisplayCreationForm($oPage, $sClass, $sFilter);
  413. break;
  414. case 'combo_options':
  415. $oFilter = CMDBSearchFilter::FromOQL($sFilter);
  416. $oSet = new CMDBObjectSet($oFilter);
  417. while( $oObj = $oSet->fetch())
  418. {
  419. $oPage->add('<option title="Here is more information..." value="'.$oObj->GetKey().'">'.$oObj->GetName().'</option>');
  420. }
  421. break;
  422. case 'display_document':
  423. $id = utils::ReadParam('id', '');
  424. $sField = utils::ReadParam('field', '');
  425. if (!empty($sClass) && !empty($id) && !empty($sField))
  426. {
  427. DownloadDocument($oPage, $sClass, $id, $sField, 'inline');
  428. }
  429. break;
  430. case 'download_document':
  431. $id = utils::ReadParam('id', '');
  432. $sField = utils::ReadParam('field', '');
  433. if (!empty($sClass) && !empty($id) && !empty($sField))
  434. {
  435. DownloadDocument($oPage, $sClass, $id, $sField, 'attachement');
  436. }
  437. break;
  438. case 'search_form':
  439. $sClass = utils::ReadParam('className', '');
  440. $sRootClass = utils::ReadParam('baseClass', '');
  441. $currentId = utils::ReadParam('currentId', '');
  442. $sAction = utils::ReadParam('action', '');
  443. $oFilter = new DBObjectSearch($sClass);
  444. $oSet = new CMDBObjectSet($oFilter);
  445. $sHtml = cmdbAbstractObject::GetSearchForm($oPage, $oSet, array('currentId' => $currentId, 'baseClass' => $sRootClass, 'action' => $sAction));
  446. $oPage->add($sHtml);
  447. break;
  448. case 'set_pref':
  449. $sCode = utils::ReadPostedParam('code', '');
  450. $sValue = utils::ReadPostedParam('value', '');
  451. appUserPreferences::SetPref($sCode, $sValue);
  452. break;
  453. case 'erase_all_pref':
  454. // Can be useful in case a user got some corrupted prefs...
  455. appUserPreferences::ClearPreferences();
  456. break;
  457. case 'on_form_cancel':
  458. // Called when a creation/modification form is cancelled by the end-user
  459. // Let's take this opportunity to inform the plug-ins so that they can perform some cleanup
  460. $iTransactionId = utils::ReadParam('transaction_id', 0);
  461. $sTempId = session_id().'_'.$iTransactionId;
  462. foreach (MetaModel::EnumPlugins('iApplicationObjectExtension') as $oExtensionInstance)
  463. {
  464. $oExtensionInstance->OnFormCancel($sTempId);
  465. }
  466. break;
  467. default:
  468. $oPage->p("Invalid query.");
  469. }
  470. $oPage->output();
  471. }
  472. catch (Exception $e)
  473. {
  474. echo $e->GetMessage();
  475. IssueLog::Error($e->getMessage());
  476. }
  477. /**
  478. * Downloads a document to the browser, either as 'inline' or 'attachment'
  479. *
  480. * @param WebPage $oPage The web page for the output
  481. * @param string $sClass Class name of the object
  482. * @param mixed $id Identifier of the object
  483. * @param string $sAttCode Name of the attribute containing the document to download
  484. * @param string $sContentDisposition Either 'inline' or 'attachment'
  485. * @return none
  486. */
  487. function DownloadDocument(WebPage $oPage, $sClass, $id, $sAttCode, $sContentDisposition = 'attachement')
  488. {
  489. try
  490. {
  491. $oObj = MetaModel::GetObject($sClass, $id);
  492. if (is_object($oObj))
  493. {
  494. $oDocument = $oObj->Get($sAttCode);
  495. if (is_object($oDocument))
  496. {
  497. $oPage->add_header('Content-type: '.$oDocument->GetMimeType());
  498. $oPage->add_header('Content-Disposition: '.$sContentDisposition.'; filename="'.$oDocument->GetFileName().'"');
  499. $oPage->add($oDocument->GetData());
  500. }
  501. }
  502. }
  503. catch(Exception $e)
  504. {
  505. $oPage->p($e->getMessage());
  506. }
  507. }
  508. ?>