Code

Fixed image path
[gosa.git] / plugins / admin / systems / class_glpiAttachmentPool.inc
index 4c7984cf32800256ee8965cc958b6a8e1462798b..40a7c3e13bad835e9e00768eb51a9d0bf88046a2 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,24 @@ 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)){
+        $tmp = $this->parent->handle->is_attachmentUsed($this->delAttach);
+        
+        $names = "";
+        foreach($tmp as $name){
+          $names .= ", ".$name;
+        }
+        $names = preg_replace("/^, /","",$names);
+        $names = trim($names);
+        if(count($tmp) == 3){
+          $names .= " ...";
+        }
+        print_red(sprintf(_("You can't delete this attachment, it is still in use by these system(s) '%s'"),$names));
+
+      }else{
+        $this->parent->handle->deleteAttachment($this->delAttach);
+        $attach     = $this->parent->handle->getAttachments();
+      }
     }
 
     /* Someone tries to upload a file */
@@ -136,6 +152,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();
@@ -157,7 +174,7 @@ class glpiAttachmentPool extends plugin
      */
     if($this->edit == true){
       foreach($this->attributes as $attr){
-        $smarty->assign($attr,htmlentities($this->$attr));
+        $smarty->assign($attr,htmlentities(utf8_decode($this->$attr)));
       }
       if(!empty($this->filename)){
         if(is_readable("/etc/gosa/glpi/".$this->filename)){
@@ -306,7 +323,26 @@ class glpiAttachmentPool extends plugin
   {
     $message = array();
     if($this->edit){
+    
+      /* check if given name is already in use */
+      $att = $this->parent->handle->getAttachments();
+      $ok = true;
       $this->name=trim($this->name);
+
+      foreach($att as $val){
+        if(!isset($this->entry['ID'])){
+          if($val['name'] == $this->name){
+            $ok = false;
+          }
+        }else{
+          if(($val['name'] == $this->name)&&($this->entry['ID'] != $val['ID'])){
+            $ok = false;
+          }
+        }
+      }
+      if(!$ok){
+        $message[] = _("This name is already in use.");
+      }
       if(empty($this->name)){
         $message[] = _("Please specify a valid name for this attachment.");
       }