Code

Added deactivate user option to divlist in user management
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 14 Aug 2007 08:15:14 +0000 (08:15 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 14 Aug 2007 08:15:14 +0000 (08:15 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7054 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/users/class_divListUsers.inc
plugins/admin/users/class_userManagement.inc

index 2314a077af5408918435fdbf3c4dd9167b422577..2842145d4947e1fe8c031baa9c09d50412673cec 100644 (file)
@@ -49,7 +49,7 @@ class divListUsers extends MultiSelectWindow
     $this->AddHeader(array("string"=>"&nbsp;",          "attach"=>"style='width:20px;'"));
     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:166px;'"));
-    $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:102px;border-right:0px;text-align:right;'"));
+    $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:122px;border-right:0px;text-align:right;'"));
     
     $this->AddCheckBox("ShowTemplates"      ,_("Select to see template pseudo users")               ,_("Show templates")        , false);
     $this->AddCheckBox("ShowFunctionalUsers",_("Select to see users that have only a GOsa object"),_("Show functional users") , true);
@@ -167,7 +167,7 @@ class divListUsers extends MultiSelectWindow
 
     // Test Every Entry and generate divlist Array
     foreach($list as $key => $val){
-
+  
       /* Create action icons */
       $action = "";
 
@@ -175,6 +175,21 @@ class divListUsers extends MultiSelectWindow
       $acl= get_permissions ($dn, $this->ui->subtreeACL);
       $acl= get_module_permission($acl, "user", $dn);
 
+      /* Add deactivate status */
+      $lock_status = "";
+
+      if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
+        if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
+          $lock_status = "<input class='center' type='image' src='images/closedlock.png' 
+            alt='"._("Deactivated")."' name='toggle_lock_status_%KEY%'>";
+        }else{
+          $lock_status = "<input class='center' type='image' src='images/openlock.png' 
+            alt='"._("Active")."' name='toggle_lock_status_%KEY%'>";
+        }
+      }else{
+        $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
+      }
+
       /* Append copy&paste icons if allowed */
       if($acl == "#all#" && $this->parent->CopyPasteHandler){
         $action .= "<input class='center' type='image'
@@ -193,6 +208,11 @@ class divListUsers extends MultiSelectWindow
           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
       }
 
+      /* Add deactivate status if we are allowed to */
+      if (chkacl($acl, "lock_status") == ""){
+        $action.= $lock_status; 
+      }
+
       /* Add delete icon if delete user is allowed */
       if (chkacl($acl, "delete") == ""){
         $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
@@ -254,7 +274,7 @@ class divListUsers extends MultiSelectWindow
       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
       $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
-                      "attach" => "style='width:102px;border-right:0px;    text-align:right;'");
+                      "attach" => "style='width:122px;border-right:0px;    text-align:right;'");
       /* Add to list */
       $add = array($field1,$field2,$field3,$field4);
       $this->AddElement($add);
index fbb89c73d5dd2ff7b40ca30d1b8e5910a959ca77..8b3acec2e18eb9c600de5599433229e236f3a025 100644 (file)
@@ -83,7 +83,8 @@ class userManagement extends plugin
                     "create_user_from_tpl"          => "userfrom_tpl",
                     "change_pw" => "user_chgpw", 
                     "editPaste" => "editPaste",   "copy"      => "copy",
-                    "cut"       => "cut") as $act => $name){
+                    "cut"       => "cut",
+                    "toggle_lock_status" => "toggle_lock_status" ) as $act => $name){
 
         if (preg_match("/".$name.".*/", $key)){
           $s_action= $act;
@@ -133,6 +134,46 @@ class userManagement extends plugin
       }
     }
   
+  
+    /********************
+      Toggle lock status for user
+     ********************/
+  
+    if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
+
+      /* 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.");
+      }else{
+
+        $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']);
+        }else{
+          $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
+        }
+
+        /* Write new status back to ldap */
+        $ldap = $this->config->get_ldap_link();
+        $ldap->cd($val['dn']);
+        $ldap->modify($attrs);
+        if($locked){
+          show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
+        }else{
+          show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
+        }
+      }
+    }
+
 
     /********************
       Edit existing entry 
@@ -719,11 +760,11 @@ class userManagement extends plugin
     $ldap= $this->config->get_ldap_link(TRUE);
     if ($SubSearch){
       $ListTemp =  get_list($filter, $this->ui->subtreeACL, $base,
-                            array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
+                            array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
     } else {
       $base= get_people_ou().$base;
       $ListTemp = get_list($filter, $this->ui->subtreeACL, $base, 
-                            array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
+                            array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
     }
     $SortTemp = array();
     $List = array();