From 8fe559e5d1fab62ae2abb6512796bda05c309def Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Fri, 31 Aug 2012 14:08:35 +0000 Subject: [PATCH] - Support of iTop 2.0 - Fix for deleting "suggested attachments" SVN:trunk[2164] --- .../itop-attachments/main.attachments.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/datamodel/itop-attachments/main.attachments.php b/datamodel/itop-attachments/main.attachments.php index d51430367..cc6b30730 100644 --- a/datamodel/itop-attachments/main.attachments.php +++ b/datamodel/itop-attachments/main.attachments.php @@ -321,6 +321,37 @@ EOF $sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php/?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents'; $oPage->add('

'.$sFileName.'

  
'); } + + // Suggested attachments are listed here but treated as temporary + $aDefault = utils::ReadParam('default', array(), false, 'raw_data'); + if (array_key_exists('suggested_attachments', $aDefault)) + { + $sSuggestedAttachements = $aDefault['suggested_attachments']; + if (is_array($sSuggestedAttachements)) + { + $sSuggestedAttachements = implode(',', $sSuggestedAttachements); + } + $oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE id IN($sSuggestedAttachements)"); + $oSet = new DBObjectSet($oSearch, array()); + if ($oSet->Count() > 0) + { + while ($oAttachment = $oSet->Fetch()) + { + // Mark the attachments as temporary attachments for the current object/form + $oAttachment->Set('temp_id', $sTempId); + $oAttachment->DBUpdate(); + // Display them + $iAttId = $oAttachment->GetKey(); + $oDoc = $oAttachment->Get('contents'); + $sFileName = $oDoc->GetFileName(); + $sIcon = utils::GetAbsoluteUrlAppRoot().AttachmentPlugIn::GetFileIcon($sFileName); + $sDownloadLink = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php/?operation=download_document&class=Attachment&id='.$iAttId.'&field=contents'; + $oPage->add('

'.$sFileName.'

  
'); + $oPage->add_ready_script("$('#attachment_plugin').trigger('add_attachment', [$iAttId, '".addslashes($sFileName)."']);"); + } + } + } + $oPage->add(''); $oPage->add('
'); $sMaxUpload = $this->GetMaxUpload(); @@ -496,7 +527,7 @@ EOF break; } - return utils::GetAbsoluteUrlModulesRoot()."itop-attachments/icons/$sIcon"; + return 'env-'.utils::GetCurrentEnvironment()."/itop-attachments/icons/$sIcon"; } /////////////////////////////////////////////////////////////////////////