Code

updated tempalte
[gosa.git] / plugins / admin / systems / class_glpiAccount.inc
index c10adddd88a516a0c513cec7e02a796ac385b344..411c1ca74438cfff754bb49972a520f66b4b7e36 100644 (file)
@@ -129,7 +129,7 @@ class glpiAccount extends plugin
       $smarty->assign($attr,array());
       $smarty->assign($attr."ACL"," disabled ");
     }
-    foreach(array("type","FK_glpi_enterprise","os","tech_num","comments","contact_num") as $attr){
+    foreach(array("type","FK_glpi_enterprise","os","tech_num","comments","contact_num","AttachmentsDiv") as $attr){
       $smarty->assign($attr,"");
       $smarty->assign($attr."ACL"," disabled ");
     }
@@ -224,6 +224,17 @@ class glpiAccount extends plugin
     
     /* Remove Attachment fro this tab 
      */
+    $once = true;
+    foreach($_POST as $name => $value){
+      if((preg_match("/^delAttachment_/",$name))&&($once)){
+        $once= false;
+        $name = preg_replace("/^delAttachment_/","",$name);
+        $entry = preg_replace("/_.*$/","",$name);
+        if(isset($this->usedAttachments[$entry])){
+          unset($this->usedAttachments[$entry]);
+        }
+      }
+    }
     if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
       foreach($_POST['Attachments'] as $entry){
         if(isset($this->usedAttachments[$entry])){
@@ -267,7 +278,12 @@ class glpiAccount extends plugin
     /* This appends a new system to our sytem types
      */
     if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
-      $this->handle->addSystemType($_POST['type_string']);  
+      $attr = $this->handle->getSystemTypes();
+      if(in_array(trim($_POST['type_string']),$attr)){
+        print_red(_("Adding new sytem type failed, this system type name is already used.")) ;
+      }else{
+        $this->handle->addSystemType(trim($_POST['type_string']));  
+      }
     }
 
     /* Remove selected type from our system types list
@@ -293,7 +309,12 @@ class glpiAccount extends plugin
     /* Rename selected system type to given string
      */
     if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){
-      $this->handle->updateSystemType($_POST['type_string'],$_POST['select_type']);
+      $attr = $this->handle->getSystemTypes();
+      if(in_array(trim($_POST['type_string']),$attr)){
+        print_red(_("Rename failed, this system type name is already used.")) ;
+      }else{
+        $this->handle->updateSystemType($_POST['type_string'],trim($_POST['select_type']));
+      }
     }
 
     /* Someone wants to edit the system types ... 
@@ -323,7 +344,12 @@ class glpiAccount extends plugin
     /* Add new os to the db
      */
     if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))){
-      $this->handle->addOS($_POST['is_string']);  
+      $attr = $this->handle->getOSTypes();
+      if(in_array(trim($_POST['is_string']),$attr)){
+        print_red(_("Adding new operating system failed, specifed name is already used.")) ;
+      }else{
+        $this->handle->addOS(trim($_POST['is_string']));  
+      }
     }
 
     /* Delete selected os from list and db
@@ -344,7 +370,6 @@ class glpiAccount extends plugin
         }
         print_red(sprintf(_("You can't delete this operating system, it is still in use by these system(s) '%s'"),$names));
 
-
       }else{
         $this->handle->removeOS_byID($_POST['select_os']);  
       }
@@ -353,7 +378,12 @@ class glpiAccount extends plugin
     /* Rename selected os to given string
      */
     if((isset($_POST['rename_os']))&&(!empty($_POST['select_os']))&&(!empty($_POST['is_string']))){
-      $this->handle->updateOS($_POST['is_string'],$_POST['select_os']);
+      $attr = $this->handle->getOSTypes();
+      if(in_array(trim($_POST['is_string']),$attr)){
+        print_red(_("Updating operating system failed, specifed name is already used.")) ;
+      }else{
+        $this->handle->updateOS($_POST['is_string'],$_POST['select_os']);
+      }
     }
 
     /* Open dialog to edit os types 
@@ -483,10 +513,10 @@ class glpiAccount extends plugin
     /* Show tab dialog headers */
     if ($this->is_account){
       $display= $this->show_header(_("Remove inventory service"),
-          _("This server has inventory features enabled. You can disable them by clicking below."));
+          _("This device has inventory informations enabled. You can disable them by clicking below."));
     } else {
       $display= $this->show_header(_("Add inventory service"),
-          _("This server has inventory features disabled. You can enable them by clicking below."));
+          _("This device has inventory informations disabled. You can enable them by clicking below."));
       return ($display);
     }
 
@@ -519,9 +549,25 @@ class glpiAccount extends plugin
 
     /* Assign used Attachments
     */
-    $smarty->assign("Attachments",            $this->getUsedAttachments());
-    $smarty->assign("AttachmentKeys",         array_flip($this->getUsedAttachments()));
 
+    $divlist = new divSelectBox("glpiAttachmentsList");
+    $divlist-> SetHeight(130); 
+    $atts = $this->getUsedAttachments(true);
+    $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
+    $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
+    foreach($atts as $id => $attachment){
+      $divlist->AddEntry
+          (
+        array(
+            array("string"=>$attachment['name']),
+            array("string"=>$attachment['mime']),
+            array("string"=>sprintf($downlink,$id,$attachment['filename'])),
+            array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
+             )
+          );
+    }
+
+    $smarty->assign("AttachmentsDiv"          ,$divlist->DrawList());
     /* Handle contact person 
        Assign name ... to smarty, if set
      */ 
@@ -582,6 +628,9 @@ class glpiAccount extends plugin
   /* Save data to object */
   function save_object()
   {
+    if(!isset($_POST['glpi_tpl_posted'])) {
+      return ;
+    }
     plugin::save_object();
     foreach($this->attributes as $attrs){
       if(isset($_POST[$attrs])){
@@ -622,27 +671,29 @@ class glpiAccount extends plugin
       }
       $tmp = $this->handle->getComputerInformations($this->dn);
       $this->handle->addDevicesToComputer($this->usedDevices,$tmp[0]['ID']);
-      $this->handle->addAttachmentsToComputer($this->usedAttachments,$tmp[0]['ID']);
     }
   }
 
   /* Return used attachments */
-  function getUsedAttachments()
+  function getUsedAttachments($divlist = false)
   {
     $atts =$this->handle->getAttachments();
     $ret = array();
     foreach($atts as $entry){
       if(in_array($entry['ID'],$this->usedAttachments)){
+        if($divlist){
+          $ret[$entry['ID']] = $entry;
+        }else{
+          $cm ="";
+          if(isset($entry['comment'])){
+            $cm=" [".$entry['comment']."]";
+          }
+          if(isset($entry['mime'])){
+            $cm.=" -".$entry['mime']."";
+          }
 
-        $cm ="";
-        if(isset($entry['comment'])){
-          $cm=" [".$entry['comment']."]";
+          $ret[$entry['ID']]= $entry['name'].$cm;
         }
-        if(isset($entry['mime'])){
-          $cm.=" -".$entry['mime']."";
-        }
-
-        $ret[$entry['ID']]= $entry['name'].$cm;
       }
     }
     return($ret);