From 3e5bedf8b8ad76dd3989306d22f3b93cb6ebee4d Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 18 Jan 2006 07:55:10 +0000 Subject: [PATCH] Added check to avoid removing of used attachments git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2513 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_glpi.inc | 24 +++++++++++++++++-- .../systems/class_glpiAttachmentPool.inc | 13 ++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/class_glpi.inc b/include/class_glpi.inc index 67f02d7af..fc8dd37f6 100644 --- a/include/class_glpi.inc +++ b/include/class_glpi.inc @@ -896,9 +896,15 @@ class glpiDB{ function getAttachments() { + $ret = array(); if($this->is_connected){ $qry = "SELECT * FROM glpi_docs WHERE name!='';"; - $ret = $this->query($qry); + $re = $this->query($qry); + + foreach($re as $entry){ + $ret[$entry['ID']]=$entry; + } + return($ret); }else{ echo "not connected"; @@ -936,7 +942,6 @@ class glpiDB{ $values = preg_replace("/, $/","",$values); $namen = preg_replace("/, $/","",$namen); $str .= "(".$namen.") VALUES (".$values.");"; - print $str; }else{ $str = "UPDATE glpi_docs SET "; foreach($tmp as $name => $value){ @@ -958,6 +963,21 @@ class glpiDB{ } } + + /* Check if given attachment id is used in any Device + ( - avoid removing of used attachments) + */ + function is_attachmentUsed($id) + { + if($this->is_connected){ + $qry = "SELECT * FROM glpi_doc_device WHERE FK_doc =".$id." LIMIT 1; "; + return(count($this->query($qry))); + }else{ + echo "not connected"; + return(false); + } + } + /* Monitor handling */ diff --git a/plugins/admin/systems/class_glpiAttachmentPool.inc b/plugins/admin/systems/class_glpiAttachmentPool.inc index 4c7984cf3..2d96528ec 100644 --- a/plugins/admin/systems/class_glpiAttachmentPool.inc +++ b/plugins/admin/systems/class_glpiAttachmentPool.inc @@ -9,13 +9,13 @@ class glpiAttachmentPool extends plugin /* attribute list for save action */ var $ignore_account = TRUE; - var $attributes = array("name","comment","mime","filename"); + var $attributes = array("name","comment","mime","filename","date_mod"); var $objectclasses = array("whatever"); var $parent; var $edit = false; var $entry = false; - + var $date_mod =""; var $name =""; var $comment =""; var $mime =""; @@ -97,8 +97,12 @@ class glpiAttachmentPool extends plugin } if((isset($_POST['delete_glpi_confirm']))&&(isset($attach[$this->delAttach]))){ - $this->parent->handle->deleteAttachment($this->delAttach); - $attach = $this->parent->handle->getAttachments(); + if($this->parent->handle->is_attachmentUsed($this->delAttach)){ + print_red(_("Can't delete this attachment, it is still in use.")); + }else{ + $this->parent->handle->deleteAttachment($this->delAttach); + $attach = $this->parent->handle->getAttachments(); + } } /* Someone tries to upload a file */ @@ -136,6 +140,7 @@ class glpiAttachmentPool extends plugin /* save attachment*/ if(($this->edit == true)&&(isset($_POST['SaveAttachment']))){ if(count($this->check())==0){ + $this->date_mod = date("Y-m-d H:i:s"); $this->save_entry(); $this->edit= false; $this->entry = array(); -- 2.30.2