Code

Updated workstation - Startup
[gosa.git] / plugins / admin / systems / class_glpiAttachmentPool.inc
index bddbe307344d16f6f2e706c8beb1d9b7794146f9..b500660298b80ad14dd2502dd6a4c055b6624e63 100644 (file)
@@ -25,7 +25,7 @@ class glpiAttachmentPool extends plugin
 
   var $delAttach= "";
 
-  function glpiAttachmentPool ($config, $dn= NULL,$used=NULL)
+  function glpiAttachmentPool (&$config, $dn= NULL,$used=NULL)
   {
     plugin::plugin ($config, $dn);
     if(!isset($_SESSION['GlpiAttachmentFilter'])){
@@ -33,7 +33,7 @@ class glpiAttachmentPool extends plugin
     }
 
     /* Assign used attributes */
-    if($used != NULL){
+    if($used !== NULL){
       $this->Selected = $used;
     }
   }
@@ -113,6 +113,7 @@ class glpiAttachmentPool extends plugin
 
       }else{
         $this->parent->handle->deleteAttachment($this->delAttach);
+        @unlink(CONFIG_DIR."/glpi/".$this->filename);
         $attach     = $this->parent->handle->getAttachments();
       }
     }
@@ -129,22 +130,26 @@ class glpiAttachmentPool extends plugin
           if($FILE['error']!=0) {
             print_red(_("Upload wasn't successfull."));
           }else{
-            if(!is_dir("/etc/gosa/glpi/")){
-              print_red(_("Missing directory '/etc/gosa/glpi/' to store glpi uploads."));
+            if(!is_dir(CONFIG_DIR."/glpi/")){
+              print_red(sprintf(_("Missing directory '%s/glpi/' to store glpi uploads."),CONFIG_DIR));
             }else{
-              $filen = "/etc/gosa/glpi/".$FILE['name'];
-              $fh = fopen($filen,"w");
-              if(!$fh){
-                print_red(sprintf(_("Can't create file '%s'."),$filen));
+              $filen = CONFIG_DIR."/glpi/".$FILE['name'];
+              if(file_exists($filen)){
+                print_red(_("There is already a file with the same name uploaded."));
               }else{
-                $str = file_get_contents($FILE['tmp_name']);
-                fwrite($fh,$str,strlen($str));
-                fclose($fh);
-                $this->mime     = $FILE['type'];   
-                $this->filename = $FILE['name'];   
-              }
+                $fh = fopen($filen,"w");
+                if(!$fh){
+                  print_red(sprintf(_("Can't create file '%s'."),$filen));
+                }else{
+                  $str = file_get_contents($FILE['tmp_name']);
+                  fwrite($fh,$str,strlen($str));
+                  fclose($fh);
+                  $this->mime     = $FILE['type'];   
+                  $this->filename = $FILE['name'];   
+                }
+              } // File already exists
             }
-          } // Check if any error occured
+          } // Check if any error occurred
         } // check if valid filename was uploaded
       } // ende check if file was uploaded 
     }// upload post
@@ -177,7 +182,7 @@ class glpiAttachmentPool extends plugin
         $smarty->assign($attr,htmlentities(utf8_decode($this->$attr)));
       }
       if(!empty($this->filename)){
-        if(is_readable("/etc/gosa/glpi/".$this->filename)){
+        if(is_readable(CONFIG_DIR."/glpi/".$this->filename)){
           $status =_("File is available.");
         }else{
           $status =_("File is not readable, possibly the file is missing.");
@@ -191,6 +196,7 @@ class glpiAttachmentPool extends plugin
 
     /* Create list with checkboxes to select / deselect some attachents */
     $divlist = new divlist("Attachment");  
+    $divlist->SetPluginMode();
     $divlist->SetHeader(array(
           array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
           array("string" => _("Name")),
@@ -251,7 +257,7 @@ class glpiAttachmentPool extends plugin
 
     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
       "   <input class='center' type='image' 
-      src='images/new.png' align='middle' title='"._("Create new attachment")."' 
+      src='images/fai_new_template.png' align='middle' title='"._("Create new attachment")."' 
       name='new_attach' alt='"._("New Attachment"). "'>&nbsp;".
       "</div>";
 
@@ -321,7 +327,9 @@ class glpiAttachmentPool extends plugin
   /* Simple check */
   function check()
   {
-    $message = array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
+
     if($this->edit){
     
       /* check if given name is already in use */