Code

Added lock/unlock button to user management list
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 14 Aug 2007 08:28:45 +0000 (08:28 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 14 Aug 2007 08:28:45 +0000 (08:28 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7055 594d385d-05f5-0310-b6e9-bd551577e9d8

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

index b1d5d201ee34d74f7f76b6531be681bc1999395e..c796b1869d86943f08549e7d2fa6375e4b177d56 100644 (file)
@@ -46,7 +46,7 @@ class divListUsers extends MultiSelectWindow
     $this->EnableSaveButton (false);
 
     /* Dynamic action col, depending on snapshot icons */
-    $action_col_size = 104;
+    $action_col_size = 122;
     if($this->parent->snapshotEnabled()){
       $action_col_size += 38;
     }
@@ -163,7 +163,6 @@ class divListUsers extends MultiSelectWindow
       " <input class='center' type='image' src='images/list_submit.png' align='middle' 
       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
 
-  
     /* Multiple options */ 
     $listhead .= "&nbsp;<input class='center' type='image' align='middle' src='images/edittrash.png'
         title='"._("Remove selected user")."' alt='"._("Remove user")."' name='remove_multiple_users'>&nbsp;";
@@ -204,7 +203,7 @@ class divListUsers extends MultiSelectWindow
     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
 
     /* Dynamic action col, depending on snapshot icons */
-    $action_col_size = 104;
+    $action_col_size = 122;
     if($this->parent->snapshotEnabled()){
       $action_col_size += 38;
     }
@@ -251,7 +250,7 @@ class divListUsers extends MultiSelectWindow
   
     // Test Every Entry and generate divlist Array
     foreach($list as $key => $val){
-
+  
       /* Create action icons */
       $action= "";
 
@@ -265,10 +264,30 @@ class divListUsers extends MultiSelectWindow
           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
       }
 
+      /* 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'>";
+      }
+
       /* Generate edit icon */
       $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
         name='user_edit_%KEY%' title='"._("Edit user")."'>";
 
+      /* Add deactivate status if we are allowed to */
+      if (preg_match("/w/",$acl_all)){
+        $action.= $lock_status;
+      }
+
       /* Add Password change icon, if we are able to write users/password */
       if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
         $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
index e9b1904722153f6022453aaa58e232bfa0e7428d..ffc1a34791484fa6377d49dc2ceb9cb1cb01c3d3 100644 (file)
@@ -88,6 +88,7 @@ class userManagement extends plugin
                     "copy_multiple" => "multiple_copy_users",
                     "cut_multiple" => "multiple_cut_users",
                     "copy"      => "^copy",
+                    "toggle_lock_status" => "toggle_lock_status",
                     "cut"       => "^cut") as $act => $name){
 
         if (preg_match("/".$name.".*/", $key)){
@@ -378,6 +379,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."));
+        }
+      }
+    }
+
 
     /********************
       Delete entry requested, display confirm dialog
@@ -832,11 +873,11 @@ class userManagement extends plugin
 
     if ($SubSearch){
       $ListTemp =  get_list($filter, "users", $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, "users", $base, 
-                            array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
+                            array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
     }
     $SortTemp = array();
     $List = array();