Code

Added a first set of reference changes - nearly untested
[gosa.git] / plugins / admin / systems / class_glpiAccount.inc
index c3015a316e6b9da784bac736b591bc41dfac8efb..76d45fd382c22e02e2362893cf3f5db062cb9306 100644 (file)
@@ -8,75 +8,89 @@ class glpiAccount extends plugin
   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
   /* attribute list for save action */
-  var $ignore_account= TRUE;
+  var $ignore_account= FALSE;
   var $attributes= array("ID","name","contact",
       "tech_num","comments","date_mod","os","location","domain","network","contact_num",
       "model","type","is_template","FK_glpi_enterprise","deleted");
 
-  var $ID                 ;
-  var $name               ="";
-  var $contact            ="";
-  var $contact_num        ="";
-
-  var $tech_num           ="";
-  var $comments           ="";
-
-  var $addUser            ="";
-
-  var $date_mod           ="";
-  var $os                 =0;
-  var $location           =0;
-  var $domain             =0;
-  var $network            =0; 
-
-  var $model              =0;
-  var $type               =0;
-  var $is_template        =0;
-  var $FK_glpi_enterprise =0;
-  var $deleted            ="N";
-
+  var $ID                 ;       // Is set if this entry is edited 
+  var $name               = "";    // This should be the dn of this entry 
+  var $contact            = "";    // Empty
+    
+  var $comments           = "";    // Comment
+  
+  var $contact_num        = "";    // Contact person
+  var $tech_num           = "";    // Technical responsible person
+  
+  var $addUser            = "";    // This is used to remember if a dialog was opened for tech_num or contact_num 
+
+  var $date_mod           = "";    // Modification timestamp
+  var $os                 = 0;     // Operating system
+  var $location           = 0;     // Not used yet
+  var $domain             = 0;     // ? Set to 0
+  var $network            = 0;     // ? Set to 0 
+
+  var $model              = 0;     // ? Can't remember this, it isn't used in GOsa 
+  var $type               = 0;     // System type id
+  var $is_template        = 0;     // Used as template ?
+  var $FK_glpi_enterprise = 0;     // Manufacturer id
+  var $deleted            = "N";   // Deleted entries should have this set to Y
+
+  var $renameTypeDialog   = false;
+  var $renameOSDialog     = false;
+  var $select_type        ;
+  var $view_logged = FALSE;
+  
+  /* Not necessary, cause we use mysql databse */
   var $objectclasses= array("whatever");
 
-  var $initialy_was_account = false;
+  /* Used to remember if this was an account (simply: is this an edited entry) */
+  var $initially_was_account = false;
 
-  var $edit_type    =false;
-  var $edit_os    =false;
+  /* Remember current dialog */
+  var $edit_type            = false;
+  var $edit_os              = false;
 
   var $data;
-  var $handle = NULL;
+  var $handle = NULL;               // Glpi class handle used to query database
 
-  var $cur_dialog = NULL;
+  var $cur_dialog = NULL;           // This contains the sub dialog handle
 
-  var $orig_dn;
-  var $ui;
+  var $orig_dn;                     // To check if dn, has changed 
+  var $ui;                          // Some GOsa specific user informations 
   
-  var $usedDevices      = array();
-  var $usedAttachments  = array();
+  var $usedDevices      = array();  // Which devices are currently selected 
+  var $usedAttachments  = array();  // Used Attachments 
 
   /* Contructor 
      Sets default values and checks if we already have an existing glpi account
    */
-  function glpiAccount ($config, $dn= NULL)
+  function glpiAccount (&$config, $dn= NULL, $parent= NULL)
   {
-    plugin::plugin ($config, $dn);
+    plugin::plugin ($config, $dn, $parent);
     $this->ui= get_userinfo();
 
+    /* Abort class construction, if no db is defined */
     if(!isset($this->config->data['SERVERS']['GLPI'])){
       return;
     }
 
+    // Get informations about databse connection
     $this->data = $this->config->data['SERVERS']['GLPI'];
 
+    // Abort if mysql extension is missing 
     if(!is_callable("mysql_connect")){
       return;
     }
 
+    // Create handle of glpi class, and check if database connection is established 
     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
 
     if(!$this->handle->is_connected){
       return;
     } 
 
+    // If this dn is already used in database, then get all informations for this entry 
     if($this->handle->is_account($this->dn)){
       $this->is_account = true;
       $tmp = ($this->handle->getComputerInformations($this->dn));
@@ -94,11 +108,10 @@ class glpiAccount extends plugin
       $this->is_account = false;
     }
 
-    $this->name = $this->dn;
-    $this->orig_dn = $this->dn;
-    $this->initialy_was_account = $this->is_account;
-
-
+    /* set defaults */
+    $this->name                 = $this->dn;
+    $this->orig_dn              = $this->dn;
+    $this->initially_was_account = $this->is_account;
   }
 
   function execute()
@@ -106,6 +119,11 @@ class glpiAccount extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","all/".get_class($this),$this->dn);
+    }
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
@@ -114,14 +132,17 @@ class glpiAccount extends plugin
         To avoid undefined indexes, if there is an error with the glpi db
      */ 
     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers",
-                  "OSs","TechnicalResponsibles","InstalledDevices","Attachments",
+                  "OSs","TechnicalResponsibles","InstalledDevices","Attachments","AttachmentKeys",
                   "OSKeys","OSs","ManufacturerKeys","InstalledDeviceKeys") as $attr){
       $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 ");
+    }
+
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation) {
+      $smarty->assign($name."ACL",$this->getacl($name));
     }
 
     /* Check if there is a glpi database server defined 
@@ -151,23 +172,41 @@ class glpiAccount extends plugin
       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
     } 
 
-    /*  All check are ok
+    /*  All checks are ok
         Lets handle Posts, templates etc below ...
      */
     
     $users = $this->handle->getUsers();
     $ldap= $this->config->get_ldap_link();
-  
+    /* Check for Trading button Post
+     */
+    if(isset($_POST['Trading'])){
+      print_red(_("This feature is not implemented yet."));
+    }
+
+    /* Check for Software button Post
+     */
+    if(isset($_POST['Software'])){
+      print_red(_("This feature is not implemented yet."));
+    }
+
+    /* Check for Contract button Post
+     */
+    if(isset($_POST['Contracts'])){
+      print_red(_("This feature is not implemented yet."));
+    }
     /* Add Device was requested, open new dialog
      */
-    if(isset($_POST['AddDevice'])){
+    if((isset($_POST['AddDevice'])) && ($this->acl_is_writeable("Devices"))){
       $this->dialog =true;
       $this->cur_dialog = new glpiDeviceManagement($this->config,$this->dn,$this->usedDevices);
     }
 
     /* Attachment pool was closed with use
      */
-    if(isset($_POST['UseAttachment'])){
+    if(isset($_POST['UseAttachment']) && ($this->acl_is_writeable("Attachments"))){
       if(count($this->cur_dialog->check())){
         foreach($this->cur_dialog->check() as $msg){
           print_red($msg);
@@ -189,22 +228,35 @@ class glpiAccount extends plugin
 
     /* Open Attachment pool to add/edit Attachments
      */
-    if(isset($_POST['AddAttachment'])){
+    if(isset($_POST['AddAttachment']) && ($this->acl_is_writeable("Attachments"))){
       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
       $this->dialog = true;
     }
     
     /* Remove Attachment fro this tab 
      */
-    if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
-      if(isset($this->usedAttachments[$_POST['Attachments']])){
-        unset($this->usedAttachments[$_POST['Attachments']]);
+    $once = true;
+    foreach($_POST as $name => $value){
+      if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
+        $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'])) && ($this->acl_is_writeable("Attachments"))){
+      foreach($_POST['Attachments'] as $entry){
+        if(isset($this->usedAttachments[$entry])){
+          unset($this->usedAttachments[$entry]);
+        }
       }
     }
 
     /* We have selected some devices and pressed use button 
      */
-    if(isset($_POST['SelectDeviceSave'])){
+    if(isset($_POST['SelectDeviceSave']) && $this->acl_is_writeable("Devices")){
       $this->cur_dialog->save_object();
       $this->usedDevices= ($this->cur_dialog->getSelected());
       $this->cur_dialog = false;
@@ -214,7 +266,7 @@ class glpiAccount extends plugin
 
     /* Aborted Device selction 
      */
-    if(isset($_POST['SelectDeviceCancel'])){
+    if(isset($_POST['SelectDeviceCancel']) && ($this->acl_is_writeable("Devices"))){
       $this->dialog = false;
       $this->cur_dialog = false;
       $this->edit_type=false;
@@ -222,40 +274,90 @@ class glpiAccount extends plugin
 
     /* System type management
      */
-    if(isset($_POST['edit_type'])){
+    if(isset($_POST['edit_type']) && $this->acl_is_writeable("type")){
       $this->dialog = true;
       $this->edit_type=true;
     }
 
     /* This closes the system type editing dialog
      */
-    if(isset($_POST['close_edit_type'])){
+    if(isset($_POST['close_edit_type']) && ($this->acl_is_writeable("type"))){
       $this->edit_type=false;
       $this->dialog = false;
     }
 
+    if(isset($_POST['Rename_Cancel'])){
+      $this->renameTypeDialog = false;
+      $this->renameOSDialog = false;
+    }
+
     /* This appends a new system to our sytem types
      */
-    if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
-      $this->handle->addSystemType($_POST['type_string']);  
+    if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
+      $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
      */
-    if((isset($_POST['del_type']))&&(!empty($_POST['select_type']))){
-      $this->handle->removeSystemType($_POST['select_type']);  
+    if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
+      $tmp = $this->handle->is_systemTypeUsed($_POST['select_type']);
+      if(count($tmp)){
+        $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 system type, it is still in use by these system(s) '%s'"),$names));
+      }else{
+        $this->handle->removeSystemType($_POST['select_type']); 
+      } 
     }
 
     /* 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']);
+    if(isset($_POST['Rename_type_OK'])){
+      $attr = $this->handle->getSystemTypes();
+      if(in_array(trim($_POST['string']),$attr)){
+        print_red(_("Rename failed, this system type name is already used.")) ;
+      }else{
+        $this->renameTypeDialog = false;
+        $this->handle->updateSystemType($_POST['string'],trim($this->select_type));
+      }
     }
+    
+  
+    if((isset($_POST['rename_type'])&&(!empty($_POST['select_type'])))||($this->renameTypeDialog)){
+      if(isset($_POST['select_type'])){
+        $this->select_type = $_POST['select_type'];
+      }
+      $this->renameTypeDialog = true;
+      $tmp = $this->handle->getSystemTypes();
+       
+      $smarty->assign("string",$tmp[$this->select_type]);
+      if(isset($_POST['string'])){
+        $smarty->assign("string",$_POST['string']);
+      }
+      $smarty->assign("Method","rename");
+      $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
+      return($display);
+    }
+
+    
 
     /* Someone wants to edit the system types ... 
        So, lets open a new dialog which provides some buttons to edit the types
      */
     if($this->edit_type){
+      $smarty->assign("Method","edit");
       $smarty->assign("SystemTypes",            $this->handle->getSystemTypes());
       $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
       $display= $smarty->fetch(get_template_path('glpi_edit_type.tpl', TRUE));
@@ -264,7 +366,7 @@ class glpiAccount extends plugin
 
     /* System os management
      */
-    if(isset($_POST['edit_os'])){
+    if(isset($_POST['edit_os']) && $this->acl_is_writeable("os")){
       $this->dialog = true;
       $this->edit_os=true;
     }
@@ -278,42 +380,91 @@ 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']);  
+    if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))  && $this->acl_is_writeable("os")){
+      $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
      */
-    if((isset($_POST['del_os']))&&(!empty($_POST['select_os']))){
-      $this->handle->removeOS_byID($_POST['select_os']);  
+    if((isset($_POST['del_os']))&&(!empty($_POST['select_os']))  && $this->acl_is_writeable("os")){
+      $tmp = $this->handle->is_osUsed($_POST['select_os']);
+  
+      if(count($tmp)){
+
+        $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 operating system, it is still in use by these system(s) '%s'"),$names));
+
+      }else{
+        $this->handle->removeOS_byID($_POST['select_os']);  
+      }
     }
 
     /* 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']);
+    if(isset($_POST['Rename_os_OK'])  && $this->acl_is_writeable("os")){
+      $attr = $this->handle->getOSTypes();
+      if(in_array(trim($_POST['string']),$attr)){
+        print_red(_("Updating operating system failed, specifed name is already used.")) ;
+      }else{
+        $this->handle->updateOS($_POST['string'],$this->select_type);
+        $this->renameOSDialog = false;
+      }
+    }
+    if((isset($_POST['rename_os'])&&(!empty($_POST['select_os'])))||($this->renameOSDialog)){
+      if(isset($_POST['select_os'])){
+        $this->select_type = $_POST['select_os'];
+      }
+      $this->renameOSDialog = true;
+      $tmp = $this->handle->getOSTypes();
+       
+      $smarty->assign("string",$tmp[$this->select_type]);
+      if(isset($_POST['string'])){
+        $smarty->assign("string",$_POST['string']);
+      }
+      $smarty->assign("Method","rename");
+      $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
+      return($display);
     }
 
     /* Open dialog to edit os types 
      */
     if($this->edit_os){
-      $smarty->assign("OSKeys",                 array_flip($this->handle->getOSTypes()));
-      $smarty->assign("OSs",                    $this->handle->getOSTypes());
+      $smarty->assign("Method","edit");
+      $smarty->assign("OSs",            $this->handle->getOSTypes());
+      $smarty->assign("OSKeys",         array_flip($this->handle->getOSTypes()));
       $display= $smarty->fetch(get_template_path('glpi_edit_os.tpl', TRUE));
       return($display);
     }
 
+
+
     /* Show dialog to select a new contact person
      * Select a contact person
      */
-    if(isset($_POST['SelectContactPerson'])){
+    if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
       $this->addUser = "contact";
-      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
+      $this->cur_dialog->set_acl_category(preg_replace("/\//","",$this->acl_category));
+      $this->cur_dialog->set_acl_base($this->dn);
+
     }
 
     /* Open dialog which allows to edit the manufacturers
      */
-    if(isset($_POST['edit_manufacturer'])){
+    if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
       $this->dialog = true;
     }
@@ -327,6 +478,7 @@ class glpiAccount extends plugin
 
     /* Abort user selection
      */
+    $smarty->assign("AbortSelectUser","SelectUserCancel");
     if(isset($_POST['SelectUserCancel'])){
       $this->dialog = false;
       $this->addUser ="";
@@ -335,13 +487,19 @@ class glpiAccount extends plugin
 
     /* Selecte technical responsible person
      */
-    if(isset($_POST['SelectTechPerson'])){
+    if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
       $this->addUser ="tech";
-      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
+      $this->cur_dialog->set_acl_category(preg_replace("/\//","",$this->acl_category));
+      $this->cur_dialog->set_acl_base($this->dn);
     }
 
     /* Technical responsible person selected*/
-    if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")){
+    if(isset($_GET['act'])&&($_GET['act']=="user_tech_num")&&(strlen($_GET['id']) > 100)){
+      print_red(sprintf(_("Could not add the given user, the users dn is too long, only 100 characters are allowed here.")));
+
+    }elseif(isset($_GET['act'])&&($_GET['act']=="user_tech_num") && strlen($_GET['id'])){
+
 
       /* Get posted id */
       $id = base64_decode($_GET['id']);
@@ -350,7 +508,8 @@ class glpiAccount extends plugin
       if(!in_array($id,$users)){
 
         /* If this user doesn't exists in glpi db, we must create him */
-        $atr = $ldap->fetch($ldap->cat($id));
+        $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
+        $atr = $ldap->fetch();
         $tmp = array();
         $use = array( "cn"              =>"name",
             "mail"            =>"email",
@@ -399,36 +558,33 @@ class glpiAccount extends plugin
     /* Assign smarty defaults */ 
     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers","OSs","TechnicalResponsibles","InstalledDevices","Attachments") as $attr){
       $smarty->assign($attr,array());
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
 
     /* Assign some vars to smarty 
      */
-    foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num") as $attr){
+    foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num","Attachments","InstalledDevices") as $attr){
       $smarty->assign($attr,"");
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
 
     /* Do we need to flip is_account state? */
-    if (isset($_POST['modify_state'])){
-      $this->is_account= !$this->is_account;
+    if(isset($_POST['modify_state'])){
+      if($this->is_account && $this->acl_is_removeable()){
+        $this->is_account= FALSE;
+      }elseif(!$this->is_account && $this->acl_is_createable()){
+        $this->is_account= TRUE;
+      }
     }
 
     /* 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."));
+      $display= $this->show_disable_header(_("Remove inventory"),
+          _("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."));
+      $display= $this->show_enable_header(_("Add inventory"),
+          _("This device has inventory informations disabled. You can enable them by clicking below."));
       return ($display);
     }
 
-    /* Assign ACLs to smarty*/
-    foreach($this->attributes as $attr){
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
-    }
-
     /* Assign system types 
      */
     $smarty->assign("SystemTypeKeys",         array_flip($this->handle->getSystemTypes()));
@@ -453,14 +609,31 @@ 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
      */ 
     if(isset($users[$this->contact_num])){
-      $tr = $ldap->fetch($ldap->cat($users[$this->contact_num]));
+      $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
+      $tr = $ldap->fetch();
       $str = "";
       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
@@ -474,7 +647,8 @@ class glpiAccount extends plugin
        Assign name ... to smarty, if set
      */ 
     if(isset($users[$this->tech_num])){
-      $tr = $ldap->fetch($ldap->cat($users[$this->tech_num]));
+      $tr = $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
+      $tr = $ldap->fetch();
       $str = "";
       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
@@ -491,13 +665,32 @@ class glpiAccount extends plugin
 
   function remove_from_parent()
   {
+    /* Cancel if there's nothing to do here */
+    if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
+      return;
+    }
+    if(function_exists("mysql_pconnect")){
+      $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
+      if($this->initially_was_account){
+        $this->handle->removeComputerInformations($this->dn); 
+        new log("remove","undefined/".get_class($this),$this->dn);
+      }
+    }else{
+      print_red(_("Can't remove glpi account, while mysql extension is missing."));
+      new log("remove","undefined/".get_class($this),$this->dn,array(),_("Can't remove glpi account, while mysql extension is missing."));
+    }
+  
   }
 
   function getDevices(){
     $ret = array();
     foreach($this->usedDevices as $type => $entries){
       foreach($entries as $ent){
-        $ret[] = $ent['designation']." [".$type."]";
+        if(isset($ent['designation'])){
+          $ret[] = $ent['designation']." [".$type."]";
+        }else{
+          $ret[] = $ent['name']." [".$type."]";
+        }
       }
     }
     return($ret); 
@@ -507,19 +700,18 @@ class glpiAccount extends plugin
   /* Save data to object */
   function save_object()
   {
-    plugin::save_object();
-    foreach($this->attributes as $attrs){
-      if(isset($_POST[$attrs])){
-        $this->$attrs = $_POST[$attrs];
-      }
+    if(!isset($_POST['glpi_tpl_posted'])) {
+      return ;
     }
+    plugin::save_object();
   }
 
 
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     //    if($this->TechnicalResponsible == ""){
     //      $message[] = _("Please select a technical responsible person for this entry.");
@@ -528,6 +720,7 @@ class glpiAccount extends plugin
     return ($message);
   }
 
+
   /* Save to LDAP */
   function save()
   {
@@ -540,37 +733,71 @@ class glpiAccount extends plugin
       $attrs['name'] = $this->dn;
       unset($attrs['ID']);
       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
-      if($this->initialy_was_account&&$this->is_account){
-        $this->handle->updateComputerInformations($attrs,$this->dn);
+
+      /* check if we have to update, add */
+      if($this->initially_was_account&&$this->is_account){
+        $this->handle->updateComputerInformations($attrs,$this->orig_dn);
+        new log("modify","undefined/".get_class($this),$this->dn);
       }elseif($this->is_account){
         $this->handle->addComputerInformations($attrs,$this->dn);
+        new log("create","undefined/".get_class($this),$this->dn);
       }
       $tmp = $this->handle->getComputerInformations($this->dn);
       $this->handle->addDevicesToComputer($this->usedDevices,$tmp[0]['ID']);
-      $this->handle->addAttachmentsToComputer($this->usedAttachments,$tmp[0]['ID']);
     }
   }
 
-  function getUsedAttachments()
+
+  /* Return used attachments */
+  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);
   }
+
+   /* Return plugin informations for acl handling */
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Glpi"),
+          "plDescription" => _("Inventory extension"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 20,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("workstation","terminal","component","server","phone") ,
+          "plProvidedAcls"=> array(
+          
+            "tech_num"            => _("Technical responsible"),
+            "comments"            => _("Comment"),
+            "os"                  => _("Operating system"),
+            "location"            => _("Location"),
+            "contact_num"         => _("Contact person"),
+            "model"               => _("Model"),
+            "type"                => _("Type"),
+            "FK_glpi_enterprise"  => _("Manufacturer"),
+            "Attachments"         => _("Attachments"),
+            "Devices"             => _("Peripheral devices"))
+          ));
+  }
   
 
 }