Code

Updated commented code to test new headpage/filters
[gosa.git] / gosa-core / plugins / admin / users / class_userManagement.inc
index e459784b26451d60537dcdfdbe38372d750ffc4d..2b46d6c698595878c3ee46f879b2d1c66905eece 100644 (file)
@@ -23,8 +23,9 @@
 class userManagement extends plugin
 {
   /* Plugin definitions */
-  var $plHeadline= "Users";
-  var $plDescription= "Manage users";
+  var $plHeadline     = "Users";
+  var $plDescription  = "Manage users";
+  var $plIcon         = "plugins/users/images/user.png";
 
   /* Dialog attributes */
   var $usertab              = NULL;
@@ -39,7 +40,9 @@ class userManagement extends plugin
 
   var $start_pasting_copied_objects = FALSE;
   var $msg_dialog= NULL;
-  
+  var $acl_module = array("users");  
+  var $dns    = array();
+
   function userManagement(&$config, $ui)
   {
     /* Save configuration for internal use */
@@ -47,7 +50,7 @@ class userManagement extends plugin
     $this->ui= &$ui;
 
     /* Copy & Paste handler */
-    if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
+    if ($this->config->boolValueIsTrue("main", "copyPaste")){
       $this->CopyPasteHandler= new CopyPasteHandler($this->config);
     }
 
@@ -184,7 +187,7 @@ class userManagement extends plugin
           $type = $events['BY_CLASS'][$event];
           $this->usertab = new $type['CLASS_NAME']($this->config);
           $this->usertab->add_users($uids);
-          $this->usertab->set_type(TRIGGERED_EVENT);
+          $this->usertab->set_type(SCHEDULED_EVENT);
         }
       }
     }
@@ -244,6 +247,7 @@ class userManagement extends plugin
       $acl = $this->ui->get_permissions($dn, "users/password");
       $cacl= $this->ui->get_permissions($dn, "users/user");
 
+      /* Are we allowed to create a new user or to set the password attribute? */
       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
 
         /* Check input and feed errors into 'message' */
@@ -287,18 +291,22 @@ class userManagement extends plugin
         if ($this->usertab){
           if ($this->usertab->password_change_needed()){
             $obj= $this->usertab->by_object['user'];
-            change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
-            if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
-              exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
+            if(!change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage)){
+              return($smarty->fetch(get_template_path('password.tpl', TRUE)));
+            }
+            if ($config->get_cfg_value("passwordHook") != ""){
+              exec($config->get_cfg_value("passwordHook")." ".$username." ".$_POST['new_password'], $resarr);
             }
             new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
             unset($this->usertab);
             $this->usertab= NULL;
           }
         } else {
-          change_password ($this->dn, $_POST['new_password']);
-          if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
-            exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
+          if(!change_password ($this->dn, $_POST['new_password'])){
+            return($smarty->fetch(get_template_path('password.tpl', TRUE)));
+          }
+          if ($config->get_cfg_value("passwordHook") != ""){
+            exec($config->get_cfg_value("passwordHook")." ".$username." ".$_POST['new_password'], $resarr);
           }
           new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
         }
@@ -308,14 +316,14 @@ class userManagement extends plugin
         msg_dialog::display(_("Password change"),_("You have no permission to change this users password!"),WARNING_DIALOG);
       }
       /* Clean session, delete lock */
-      del_lock ($this->dn);
+      $this->remove_lock();
       unset ($this->usertab);
       $this->usertab= NULL;
       $this->lognames= array();;
       $this->sn= "";
       $this->givenName= "";
       $this->uid= "";
-      session::un_set('objectinfo');
+      set_object_info();
     }
 
 
@@ -325,6 +333,16 @@ class userManagement extends plugin
   
     if($s_action == "multiple_password_change"){
       $this->pwd_change_queue = $this->list_get_selected_items();
+      $disallowed = array();
+      foreach($this->pwd_change_queue as $key => $id){
+        if(!preg_match("/w/",$this->ui->get_permissions($this->list[trim($id)]['dn'],"users/password"))){
+          unset($this->pwd_change_queue[$key]);
+          $disallowed[] = $this->list[trim($id)]['dn'];
+        }
+      }
+      if(count($disallowed)){
+        msg_dialog::display(_("Permission"),msgPool::permModify($disallowed),INFO_DIALOG);
+      }
     }    
 
 
@@ -354,10 +372,8 @@ class userManagement extends plugin
 
         /* User is allowed to change passwords, save 'dn' and 'acl' for next
            dialog. */
-        session::set('objectinfo',$this->dn);
+        set_object_info($this->dn);
         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
-        
-
       } else {
         /* User is not allowed. Show message and cancel. */
         msg_dialog::display(_("Password change"),_("You have no permission to change this users password!"),WARNING_DIALOG);
@@ -370,6 +386,7 @@ class userManagement extends plugin
       Edit existing entry
      ********************/
 
+
     /* User wants to edit data? */
     if (($s_action=="edit") && (!isset($this->usertab->config))){
 
@@ -378,8 +395,9 @@ class userManagement extends plugin
 
       /* Check locking, save current plugin in 'back_plugin', so
          the dialog knows where to return. */
+
       if (($user= get_lock($this->dn)) != ""){
-        return(gen_locked_message ($user, $this->dn));
+        return(gen_locked_message ($user, $this->dn,TRUE));
       }
 
       /* Lock the current entry, so everyone will get the
@@ -395,7 +413,7 @@ class userManagement extends plugin
 
       /* Set ACL and move DN to the headline */
       $this->usertab->set_acl_base($this->dn);
-      session::set('objectinfo',$this->dn);
+      set_object_info($this->dn);
     }
 
 
@@ -419,7 +437,7 @@ class userManagement extends plugin
       if($tmp->multiple_available()){
         $this->usertab = $tmp;
         $this->usertab->set_active_tab($s_tab);
-        session::set('objectinfo',$this->usertab->get_object_info());
+        set_object_info($this->usertab->get_object_info());
       }
     }
 
@@ -431,15 +449,14 @@ class userManagement extends plugin
     /* Reset all relevant data, if we get a _cancel request */
     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
       if (isset($this->usertab)){
-        del_lock ($this->usertab->dn);
-        unset ($this->usertab);
+        $this->remove_lock();
       }
       $this->usertab= NULL;
       $this->lognames= array();;
       $this->sn= "";
       $this->givenName= "";
       $this->uid= "";
-      session::un_set('objectinfo');
+      set_object_info();
     }
 
 
@@ -457,7 +474,7 @@ class userManagement extends plugin
       foreach ($this->config->departments as $key => $value){
     
         /* Get acls from different ou's */
-        $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user")       ; 
+        $acl = $this->ui->get_permissions($value,"users/user")       ; 
  
         /* If creation of a new user is allowed, append this template */
         if (preg_match("/c/",$acl)){
@@ -470,11 +487,11 @@ class userManagement extends plugin
           if ($ldap->count() != 0){
             while ($attrs= $ldap->fetch()){
               $this->templates[$ldap->getDN()]=
-                $attrs['uid'][0]." - ".@LDAP::fix($key);
+                $attrs['uid'][0]." - ".LDAP::fix($key);
+            }
+            if ($s_action != "templatize_multiple"){
+              $this->templates['none']= _("none");
             }
-           if ($s_action != "templatize_multiple"){
-                   $this->templates['none']= _("none");
-           }
           }
         }
       }
@@ -515,22 +532,22 @@ class userManagement extends plugin
 
       /* Template readable? */
       if (preg_match('/r/', $acl)){
-       $template_dn= $_POST['template'];
+        $template_dn= $_POST['template'];
 
         foreach ($this->dns as $dn){
-         $acl = $this->ui->get_permissions($_POST['template'], "users/user");
-         if (preg_match('/w/', $acl)){
-                 $usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
-                 $usertab->adapt_from_template($template_dn, array("sn", "givenName", "uid"));
-                 $usertab->save();
-                 unset ($usertab);
-                 $usertab= NULL;
-         } else {
-                 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to modify object '%s'!"), $dn), ERROR_DIALOG);
+          $acl = $this->ui->get_permissions($_POST['template'], "users/user");
+          if (preg_match('/w/', $acl)){
+            $usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
+            $usertab->adapt_from_template($template_dn, array("sn", "givenName", "uid"));
+            $usertab->save();
+            unset ($usertab);
+            $usertab= NULL;
+          } else {
+            msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to modify object '%s'!"), $dn), ERROR_DIALOG);
           }
         }
       } else {
-       msg_dialog::display(_("Permission error"), _("You have no permission to use this template!"), ERROR_DIALOG);
+        msg_dialog::display(_("Permission error"), _("You have no permission to use this template!"), ERROR_DIALOG);
       }
 
     }
@@ -551,29 +568,43 @@ class userManagement extends plugin
       }
 
       $this->dns = array();
-
       if(count($ids)){
+        $disallowed = array();
         foreach($ids as $id){
           $dn = $this->list[$id]['dn'];
-          if (($user= get_lock($dn)) != ""){
-            return(gen_locked_message ($user, $dn));
+          $acl = $this->ui->get_permissions($dn, "users/user"); 
+          if(preg_match("/d/",$acl)){
+            $this->dns[$id] = $dn;
+          }else{
+            $disallowed[] = $dn;
           }
-          $this->dns[$id] = $dn; 
         }
-
-        $dns_names = array();
-        foreach($this->dns as $dn){
-          $dns_names[] = @LDAP::fix($dn);
+        
+        if(count($disallowed)){
+          msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
         }
 
-        /* Lock the current entry, so nobody will edit it during deletion */
-        $info = sprintf(msgPool::deleteInfo($dns_names,_("user")));
+        if(count($this->dns)){
 
-        /* Lock the current entry, so nobody will edit it during deletion */
-        $smarty->assign("info", msgPool::deleteInfo($dns_names));
-        return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+          /* Check locks */
+          if ($user= get_multiple_locks($this->dns)){
+            return(gen_locked_message($user,$this->dns));
+          }
 
+          $dns_names = array();
+          foreach($this->dns as $dn){
+            $dns_names[] = LDAP::fix($dn);
+          }
 
+          add_lock($this->dns, $this->ui->dn);
+
+          /* Lock the current entry, so nobody will edit it during deletion */
+          $info = sprintf(msgPool::deleteInfo($dns_names,_("user")));
+
+          /* Lock the current entry, so nobody will edit it during deletion */
+          $smarty->assign("info", msgPool::deleteInfo($dns_names));
+          return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
+        }
       }
     }
 
@@ -582,30 +613,30 @@ class userManagement extends plugin
       Delete MULTIPLE entries confirmed 
      ********************/
 
-      if(isset($_POST['delete_user_confirm'])){
-        
-        /* Remove user by user and check acls before removeing them */
-        foreach($this->dns as $key => $dn){
+    if(isset($_POST['delete_user_confirm'])){
 
-          $acl = $this->ui->get_permissions($dn, "users/user"); 
-          if (preg_match('/d/', $acl)){
+      /* Remove user by user and check acls before removeing them */
+      foreach($this->dns as $key => $dn){
 
-            /* Delete request is permitted, perform LDAP action */
-            $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
-            $this->usertab->set_acl_base();
-            $this->usertab->delete ();
-            unset ($this->usertab);
-            $this->usertab= NULL;
-          } else {
-            msg_dialog::display(_("Warning"),msgPool::permDelete($dn),WARNING_DIALOG);
-            if(isset($this->ui->uid)){
-              new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
-            }
+        $acl = $this->ui->get_permissions($dn, "users/user"); 
+        if (preg_match('/d/', $acl)){
+
+          /* Delete request is permitted, perform LDAP action */
+          $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
+          $this->usertab->set_acl_base();
+          $this->usertab->delete ();
+          unset ($this->usertab);
+          $this->usertab= NULL;
+        } else {
+          msg_dialog::display(_("Warning"),msgPool::permDelete($dn),WARNING_DIALOG);
+          if(isset($this->ui->uid)){
+            new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
           }
-          /* Remove lock file after successfull deletion */
-          del_lock ($dn);
-          unset($this->dns[$key]);
+        }
       }
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
   
@@ -617,46 +648,46 @@ class userManagement extends plugin
 
       /* Get entry check current status */
       $val = $this->list[$s_entry];
-      $pwd = $val['userPassword'][0];
-
-      if(!preg_match("/^\{[^\}]/",$pwd)){
-        trigger_error("Can not deactivate user which is using clear password encryption.");
+      if (!preg_match("/w/",$this->ui->get_permissions($val['dn'],"users/password"))){
+        msg_dialog::display(_("Account locking"),
+            _("You have no permission to change the lock status for this user!"),WARNING_DIALOG);
       }else{
+        $pwd = $val['userPassword'][0];
+        $method = passwordMethod::get_method($pwd,$val['dn']);
+        $success= false;
+        if($method instanceOf passwordMethod){
+          if($method->is_locked($this->config,$val['dn'])){
+            $success= $method->unlock_account($this->config,$val['dn']);
+          }else{
+            $success= $method->lock_account($this->config,$val['dn']);
+          }
 
-        $locked = false;
-        if(preg_match("/^[^\}]*+\}!/",$pwd)){
-          $locked = true;
-        }
-
-        /* Create ldap array to update status */
-        $attrs = array("userPassword" => $pwd);
-        if($locked){
-          $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
+          /* Check for success */
+          if (!$success){
+            $hn= $method->get_hash_name();
+            if (is_array($hn)){
+              $hn= $hn[0];
+            }
+            msg_dialog::display(_("Account locking"),
+              sprintf(_("Password method '%s' does not support locking. Account has not been locked!"), $hn),WARNING_DIALOG);
+          }
         }else{
-          $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
+          // Can't lock unknown methods.
         }
 
-        /* Write new status back to ldap */
-        $ldap = $this->config->get_ldap_link();
-        $ldap->cd($val['dn']);
-        $ldap->modify($attrs);
-        if (!$ldap->success()){
-          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $val['dn'], 0, get_class()));
-        }
       }
     }
 
-
     /********************
       Delete entry Canceled 
      ********************/
 
     /* Delete user canceled? */
     if (isset($_POST['delete_cancel'])){
-      foreach($this->dns as $key => $dn){
-        del_lock ($dn);
-        unset($this->dns[$key]);
-      }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -694,7 +725,7 @@ class userManagement extends plugin
         if (!isset($_POST['edit_apply'])){
           /* User has been saved successfully, remove lock from LDAP. */
           if ($this->dn != "new"){
-            del_lock ($this->dn);
+            $this->remove_lock();
           }
 
           /* In case of new users, ask for a password, skip this for templates */
@@ -705,7 +736,13 @@ class userManagement extends plugin
 
           unset ($this->usertab);
           $this->usertab= NULL;
-          session::un_set('objectinfo');
+          set_object_info();
+        }else{
+        
+          /* Reinitialize tab */
+          if($this->usertab instanceof tabs){
+            $this->usertab->re_init();
+          }
         }
       } else {
         /* Ok. There seem to be errors regarding to the tab data,
@@ -758,16 +795,12 @@ class userManagement extends plugin
          react on this. */
       $this->dn= "new";
       
-      if (isset($this->config->current['IDGEN'])){
-        $this->got_uid= false;
-      } else {
-        $this->got_uid= true;
-      }
+       $this->got_uid= ($this->config->get_cfg_value("idGenerator") == "");
 
       /* Create new usertab object */
       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
-      $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
+      $this->usertab->set_acl_base($this->DivListUsers->selectedBase);
 
       /* Take care about templates */
       if ($s_action=="new_tpl"){
@@ -825,9 +858,8 @@ class userManagement extends plugin
         msg_dialog::displayChecks($message);
       } else {
         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
-        if (isset($this->config->current['IDGEN']) &&
-            $this->config->current['IDGEN'] != ""){
-          $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
+        if ($this->config->get_cfg_value("idGenerator") != ""){
+          $uids= gen_uids ($this->config->get_cfg_value("idGenerator"), $attributes);
           if (count($uids)){
             $smarty->assign("edit_uid", "false");
             $smarty->assign("uids", $uids);
@@ -870,18 +902,16 @@ class userManagement extends plugin
     /* Finish template preamble */
     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
 
-      /* Might not be filled if IDGEN is unset */
-      $this->sn                 = $_POST['sn'];
-      $this->givenName          = $_POST['givenName'];
-
       /* Move user supplied data to sub plugins */
-      $this->uid                = $_POST['uid'];
-      $this->usertab->uid       = $this->uid;
-      $this->usertab->sn        = $this->sn;
-      $this->usertab->givenName = $this->givenName;
+      foreach(array("uid","sn","givenName") as $attr){
+        $this->$attr = $_POST[$attr];
+        $this->usertab->$attr       = $this->$attr;
+        $this->usertab->by_object['user']->$attr = $this->$attr;
+      }
+
       $template_dn              = $_POST['template'];
-      $this->usertab->adapt_from_template($template_dn);
-      $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
+      $this->usertab->adapt_from_template($template_dn, array("uid","cn","givenName","sn"));
+      $template_base            = preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/')."/", '', $template_dn);
       $this->usertab->by_object['user']->base= $template_base;
     }
    
@@ -912,27 +942,32 @@ class userManagement extends plugin
         }
 
         if(!is_object($dia) && $dia != TRUE){
-          $display.= "<p style=\"text-align:right\">\n";
-          $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
-          $display.= "&nbsp;\n";
-          if ($this->dn != "new"){
-            $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
+          if(($this->usertab instanceOf tabs || $this->usertab instanceOf plugin) && $this->usertab->read_only == TRUE){
+            $display.= "<p style=\"text-align:right\">
+                          <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
+                        </p>";
+          }else{
+            $display.= "<p style=\"text-align:right\">\n";
+            $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
             $display.= "&nbsp;\n";
+            if ($this->dn != "new"){
+              $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
+              $display.= "&nbsp;\n";
+            }
+            $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
+            $display.= "</p>";
           }
-          $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
-          $display.= "</p>";
         }
       return ($display);
     }
     
     /* Check if there is a snapshot dialog open */
     $base = $this->DivListUsers->selectedBase;
-    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
+    if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
       return($str);
     }
   
     /* Return rendered main page */
-        /* Display dialog with system list */
     $this->DivListUsers->parent = $this;
     $this->DivListUsers->execute();
 
@@ -942,10 +977,126 @@ class userManagement extends plugin
     }
     $this->reload();
     $this->DivListUsers->setEntries($this->list);
+
+    # FILTER Test #################################################
+    ## Build filter
+    #$filter = new filter(get_template_path("user-filter.xml", true));
+    #$filter->setObjectStorage(get_people_ou());
+    #$filter->update();
+    #session::set('autocomplete', $filter);
+    #if (!$filter->isValid()){
+    #  msg_dialog::display(_("Filter error"), _("The filter is uncomplete!"), ERROR_DIALOG);
+    #}
+
+    ## Build headpage
+    #$headpage = new listing(get_template_path("user-list.xml", true));
+    #$headpage->registerElementFilter("accountProperties", "userManagement::filterProperties");
+    #$headpage->registerElementFilter("lockLabel", "userManagement::filterLockLabel");
+    #$headpage->registerElementFilter("lockImage", "userManagement::filterLockImage");
+    #$headpage->setFilter($filter);
+
+    ## Needs to be called before update!
+    #$action= $headpage->getAction();
+    #if ($action['action'] != '') {
+    #  echo "List detected action:";
+    #  print_a($action);
+    #}
+
+    ## Refresh for filter
+    #$headpage->update();
+    #
+    #return($headpage->render());
+    ################################################### FILTER Test
+
     return($this->DivListUsers->Draw());
   }
 
 
+  static function filterLockImage($userPassword)
+  {
+    $image= "images/empty.png";
+
+    if(isset($userPassword[0]) && preg_match("/^\{[^\}]/",$userPassword[0])){
+      if(preg_match("/^[^\}]*+\}!/",$userPassword[0])){
+        $image= "images/lists/locked.png";
+      }else{
+        $image= "images/lists/unlocked.png";
+      }
+    }
+
+    return $image;
+  }
+
+
+  static function filterLockLabel($userPassword)
+  {
+    $label= "";
+
+    if(isset($userPassword[0]) && preg_match("/^\{[^\}]/",$userPassword[0])){
+      if(preg_match("/^[^\}]*+\}!/",$userPassword[0])){
+        $label= _("Unlock account");
+      }else{
+        $label= _("Lock account");
+      }
+    }
+
+    return $label;
+  }
+
+
+  static function filterProperties($dn, $row, $class)
+  {
+    $result= "";
+
+    $map= array( "gosaAccount" => array( "image" => "plugins/users/images/select_user.png",
+                                         "plugin" => "user",
+                                         "alt" => _("Generic"),
+                                         "title" => _("Edit generic properties")),
+                 "posixAccount" => array("image" => "images/penguin.png",
+                                         "plugin" => "posixAccount",
+                                         "alt" => _("POSIX"),
+                                         "title" => _("Edit POSIX properties")),
+                 "gosaMailAccount" => array("image" => "images/mailto.png",
+                                         "alt" => _("Mail"),
+                                         "plugin" => "mailAccount",
+                                         "title" => _("Edit mail properties")),
+                 "sambaSamAccount" => array("image" => "plugins/systems/images/select_winstation.png",
+                                         "plugin" => "sambaAccount",
+                                         "alt" => _("Samba"),
+                                         "title" => _("Edit samba properties")),
+                 "apple-user" => array("image" => "plugins/netatalk/images/select_netatalk.png",
+                                         "plugin" => "sambaAccount",
+                                         "alt" => _("Netatalk"),
+                                         "title" => _("Edit netatalk properties")),
+                 "gotoEnvironment" => array("image" => "plugins/users/images/small_environment.png",
+                                         "plugin" => "gotoEnvironment",
+                                         "alt" => _("Environment"),
+                                         "title" => _("Edit environment properties")),
+                 "goFaxAccount" => array("image" => "plugins/users/images/fax_small.png",
+                                         "plugin" => "goFaxAccount",
+                                         "alt" => _("FAX"),
+                                         "title" => _("Edit FAX properties")),
+                 "goFonAccount" => array("image" => "plugins/gofon/images/select_phone.png",
+                                         "plugin" => "goFonAccount",
+                                         "alt" => _("Phone"),
+                                         "title" => _("Edit phone properties")));
+
+    // Walk thru map
+    foreach ($map as $oc => $properties) {
+      if (in_array($oc, $class)) {
+        $result.="<input class='center' type='image' src='".$properties['image']."' ".
+                 "alt='".$properties['alt']."' title='".$properties['title'].
+                 "' name='listing_edit_".$properties['plugin']."_$row' style='padding:1px'>";
+      } else {
+        $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
+      }
+    }
+
+    return $result;
+  }
+
+
+
   /* Return departments, that will be included within snapshot detection */
   function get_used_snapshot_bases()
   {
@@ -971,7 +1122,7 @@ class userManagement extends plugin
 
     /* Setup filter depending on selection */
     $filter="";
-    if ($this->config->current['SAMBAVERSION'] == 3){
+    if ($this->config->get_cfg_value("sambaversion") == 3){
       $samba= "sambaSamAccount";
     } else {
       $samba= "sambaAccount";
@@ -997,7 +1148,9 @@ class userManagement extends plugin
     if ($ShowTemplates){
       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
     } else {
-      $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
+      $filter= "(&(objectClass=gosaAccount)(objectClass=person)".
+        "(objectClass=inetOrgPerson)(objectClass=organizationalPerson)".
+        "(!(objectClass=gosaUserTemplate))(|$filter))";
     }
     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
 
@@ -1014,12 +1167,21 @@ class userManagement extends plugin
     }
     $SortTemp = array();
     $List = array();
+
     foreach($ListTemp as $Key => $Entry){
+    
+      /* Due to the fact that "inetOrgPerson" is derived from "organizationalPerson" and that openldap 
+          doesn't differentiate both classes in search filters, we have to skip entries that do not provide 
+          both classes. (Both classes are required for a valid GOsa user Account.)
+       */
+      if(!in_array("inetOrgPerson",$Entry['objectClass'])|| !in_array("organizationalPerson",$Entry['objectClass'])){
+        continue;
+      }
 
       /* Skip entries that are not located under the people ou (normaly 'ou=people,')
        * Else winstations will be listed too, if you use the subtree flag. 
        */
-      if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
+      if(!preg_match("/".preg_quote(get_people_ou(), '/')."/i",$Entry['dn'])){
         continue;
       }else{
 
@@ -1044,11 +1206,17 @@ class userManagement extends plugin
     }
   }
 
+
   function remove_lock()
   {
     /* Remove user lock if a DN is marked as "currently edited" */
     if (isset($this->usertab->dn)){
       del_lock ($this->usertab->dn);
+    }elseif(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
+      del_lock($this->dn);
+    }
+    if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
+      del_lock($this->dns);
     }
   }
 
@@ -1059,13 +1227,21 @@ class userManagement extends plugin
     if(!is_object($this->CopyPasteHandler)){
       return("");
     }
-
+    
+    $ui = get_userinfo();
+  
     /* Add a single entry to queue */
     if($s_action == "cut" || $s_action == "copy"){
+
       /* Cleanup object queue */
       $this->CopyPasteHandler->cleanup_queue();
       $dn = $this->list[$s_entry]['dn'];
-      $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
+      if($s_action == "copy" && $ui->is_copyable($dn,"users","user")){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
+      }
+      if($s_action == "cut" && $ui->is_cutable($dn,"users","user")){
+        $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
+      }
     }
 
     /* Add entries to queue */
@@ -1078,10 +1254,10 @@ class userManagement extends plugin
       foreach($this->list_get_selected_items() as $id){
         $dn = $this->list[$id]['dn'];
 
-        if($s_action == "copy_multiple"){
+        if($s_action == "copy_multiple" && $ui->is_copyable($dn,"users","user")){
           $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
         }
-        if($s_action == "cut_multiple"){
+        if($s_action == "cut_multiple" && $ui->is_cutable($dn,"users","user")){
           $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
         }
       }
@@ -1096,8 +1272,8 @@ class userManagement extends plugin
     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
    
       /* Get dialog */
-      $data = $this->CopyPasteHandler->execute();
       $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase); 
+      $data = $this->CopyPasteHandler->execute();
 
       /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
       if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){