Code

Added check to avoid removing of used attachments
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 Jan 2006 07:55:10 +0000 (07:55 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 18 Jan 2006 07:55:10 +0000 (07:55 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2513 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_glpi.inc
plugins/admin/systems/class_glpiAttachmentPool.inc

index 67f02d7aff127bfe14c7dee2532f4a20e2d1094a..fc8dd37f64f254ae84703c3da90d846da9fcbec3 100644 (file)
@@ -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 
      */
index 4c7984cf32800256ee8965cc958b6a8e1462798b..2d96528ec12db25488908fdca6083d8920271392 100644 (file)
@@ -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();