Code

Excluded add/remove part in seperate function.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 19 Jul 2006 09:08:22 +0000 (09:08 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 19 Jul 2006 09:08:22 +0000 (09:08 +0000)
User/Group deletion is now possible with multiple users

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@4231 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_printGeneric.inc
plugins/admin/systems/printer.tpl

index 7361720217fe22686595c7a00094a3fd880e9266..026870745045561d315779439ca3aa382b05e50f 100644 (file)
@@ -399,28 +399,28 @@ class printgeneric extends plugin
       }
     }
 
-    /* Member management, delete user / group / admin ..*/
+     /* Member management, delete user / group / admin ..*/
     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
-      if(isset($this->member['AddUser'][$_POST['UserMember']])){
-        unset($this->member['AddUser'][$_POST['UserMember']]);
+      foreach($_POST['UserMember'] as $mem){
+        $this->DelMember('AddUser',$mem);
       }
     }
 
     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
-      if(isset($this->member['AddGroup'][$_POST['UserMember']])){
-        unset($this->member['AddGroup'][$_POST['UserMember']]);
+      foreach($_POST['UserMember'] as $mem){
+        $this->DelMember('AddGroup',$mem);
       }
     }
 
     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
-      if(isset($this->member['AddAdminUser'][$_POST['AdminMember']])){
-        unset($this->member['AddAdminUser'][$_POST['AdminMember']]);
+      foreach($_POST['AdminMember'] as $mem){
+        $this->DelMember('AddAdminUser',$mem);
       }
     }
 
     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
-      if(isset($this->member['AddAdminGroup'][$_POST['AdminMember']])){
-        unset($this->member['AddAdminGroup'][$_POST['AdminMember']]);
+      foreach($_POST['AdminMember'] as $mem){
+        $this->DelMember('AddAdminGroup',$mem);
       }
     }
 
@@ -438,21 +438,13 @@ class printgeneric extends plugin
           print_red($msg);
         }
       }else{
-        $new = $this->dialog->save();
-        $data = $new;
+        $data= $new = $this->dialog->save();
         unset($data['type']);
-
-        if(preg_match("/User/",$new['type'])){
-          $use = "uid";
-        }else{
-          $use = "cn";
-        }
-
         foreach($data as $mem){
-          $this->member[$new['type']][$mem[$use][0]]=$mem;    
+          $this->AddMember($new['type'], $mem['dn']);
         }
         unset($this->dialog);
-        $this->dialog=NULL; 
+        $this->dialog=NULL;
       }
     }
 
@@ -788,6 +780,56 @@ class printgeneric extends plugin
   }
 
 
+  /* Delete member */
+  function DelMember($type,$id)
+  {
+    if(isset($this->member[$type][$id])){
+      unset($this->member[$type][$id]);
+    }
+  }
+
+
+  /* Add given obejct to members */
+  function AddMember($type,$dn)
+  {
+    $types = array("AddUser","AddGroup","AddAdminUser","AddAdminGroup");
+    if(!in_array_ics($type, $types)){
+      print_red(sprintf(_("Illegal printer type while adding '%s' to the list of '%s' printers,"),$dn,$type));
+      return;
+    }
+
+    /* Get name of index attributes */
+    if(preg_match("/user/i",$type)){
+      $var = "uid";
+    }else{
+      $var = "cn";
+    }
+
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($dn);
+    $ldap->cat($dn,array("cn","uid"));
+    if($ldap->count()){
+
+      $attrs = $ldap->fetch();
+
+      /* Check if this uid/cn is already assigned to any permission */
+      foreach($types as $ctype){
+        if($type == $ctype) continue;
+
+        if(in_array($attrs[$var][0],$this->member[$ctype])){
+          print_red(sprintf(_("Can't add '%s' to members it is already used in another category."),$attrs[$var][0]));
+          return;
+        }
+      }
+
+      /* Everything is fine. So add the given object to members */
+      $this->member[$type][$attrs[$var][0]] = $attrs ;
+    }else{
+      print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
+    }
+  }
+
+
 
 }
 
index 808d47f746ec152bcba1a89ff87a20c226810a48..876ae22baf1153f4c942217f9f641d47c43cc73a 100644 (file)
@@ -68,7 +68,7 @@
                                <tr>
                                        <td>
                                                {t}Users which are allowed to use this printer{/t}<br>
-                                               <select size="1" name="UserMember" title="{t}Users{/t}" style="width:100%;height:120px;"  multiple>
+                                               <select size="1" name="UserMember[]" title="{t}Users{/t}" style="width:100%;height:120px;"  multiple>
                                                {html_options options=$UserMembers values=$UserMemberKeys}
                                                </select><br>
                                                        <input type="submit" value="{t}Add user{/t}"  name="AddUser">
@@ -84,7 +84,7 @@
                                <tr>
                                        <td>
                                                {t}Users which are allowed to administrate this printer{/t}<br>
-                                               <select size="1" name="AdminMember" title="{t}Admins{/t}" style="width:100%;height:120px;"  multiple>
+                                               <select size="1" name="AdminMember[]" title="{t}Admins{/t}" style="width:100%;height:120px;"  multiple>
                                                {html_options options=$AdminMembers values=$AdminMemberKeys}
                                                </select><br>
                                                        <input type="submit" value="{t}Add user{/t}"  name="AddAdminUser">