浏览代码

- Support of iTop 2.0
- Fix for deleting "suggested attachments"

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2164 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 12 年之前
父节点
当前提交
cf93e9cf0b
共有 1 个文件被更改,包括 32 次插入1 次删除
  1. 32 1
      datamodel/itop-attachments/main.attachments.php

+ 32 - 1
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('<div class="attachment" id="attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/>&nbsp;<input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="$(\'#attachment_'.$iAttId.'\').remove();"/>&nbsp;</div>');
 			}
+			
+			// 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('<div class="attachment" id="display_attachment_'.$iAttId.'"><a href="'.$sDownloadLink.'"><img src="'.$sIcon.'"><br/>'.$sFileName.'<input type="hidden" name="attachments[]" value="'.$iAttId.'"/></a><br/>&nbsp;<input id="btn_remove_'.$iAttId.'" type="button" class="btn_hidden" value="Delete" onClick="RemoveNewAttachment('.$iAttId.');"/>&nbsp;</div>');
+						$oPage->add_ready_script("$('#attachment_plugin').trigger('add_attachment', [$iAttId, '".addslashes($sFileName)."']);");
+					}
+				}
+			}
+			
 			$oPage->add('</span>');			
 			$oPage->add('<div style="clear:both"></div>');			
 			$sMaxUpload = $this->GetMaxUpload();
@@ -496,7 +527,7 @@ EOF
 			break;
 		}
 		
-		return utils::GetAbsoluteUrlModulesRoot()."itop-attachments/icons/$sIcon";
+		return 'env-'.utils::GetCurrentEnvironment()."/itop-attachments/icons/$sIcon";
 	}
 	
 	/////////////////////////////////////////////////////////////////////////