Code

Fixed printer add/remove
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 11 Aug 2006 04:10:53 +0000 (04:10 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 11 Aug 2006 04:10:53 +0000 (04:10 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@4471 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_printGeneric.inc
plugins/personal/environment/class_environment.inc

index ea4f24dc973798800917a3e0f062014069f9bd1f..803ea881eee9dc08180f6c7327a1a60c5c332b60 100644 (file)
@@ -814,7 +814,7 @@ class printgeneric extends plugin
     /* Check if there was a printer "dn" given, or the "cn" */
     foreach($this->member[$type] as $key => $printer){
       if($printer['dn'] == $id) {
-        $id = key;
+        $id = $key;
       }
     }
     
index 697f5f85b5a101c22cdbbeb3d7c120c33c657cb4..c86f52d00c80f2884b202355ff7b5f554dea0190 100644 (file)
@@ -73,6 +73,7 @@ class environment extends plugin
   var $objectclasses      = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here 
   var $cn;
   var $OrigCn;
+  var $add_del_printer_member_was_called = false;
 
   function environment ($config, $dn= NULL)
   {
@@ -744,6 +745,7 @@ class environment extends plugin
           if($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
             $this->gotoPrinter[$pname]=$tmp2[$pname];
             $this->gotoPrinter[$pname]['mode']="user";
+            $this->add_del_printer_member_was_called = true;
           }
         }
 
@@ -760,6 +762,7 @@ class environment extends plugin
         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn']);
         if($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->dn)){
           unset($this->gotoPrinter[$pname]);
+          $this->add_del_printer_member_was_called = true;
         }
       }
     }
@@ -960,49 +963,53 @@ class environment extends plugin
      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
      */
-    $types = array( "gotoUserPrinter"       => "AddUser",
-        "gotoGroupPrinter"      => "AddGroup",
-        "gotoUserAdminPrinter"  => "AddAdminUser",
-        "gotoGroupAdminPrinter" => "AddAdminGroup");
-
-    if($this->is_group){
-      $s_suffix = "Group";
-      $useVar   = "cn";
-    }else{
-      $useVar   = "uid";
-      $s_suffix = "User";
-    }
+    
+    if($this->add_del_printer_member_was_called){
 
-    /* Remove old entries */
-    $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
-    while($attr = $ldap->fetch()){
-      $printerObj = NULL;
-      $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
-      $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
-      $printerObj->by_object['printgeneric']->save();
-    }
+      $types = array( "gotoUserPrinter"       => "AddUser",
+          "gotoGroupPrinter"      => "AddGroup",
+          "gotoUserAdminPrinter"  => "AddAdminUser",
+          "gotoGroupAdminPrinter" => "AddAdminGroup");
 
-    $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
-    while($attr = $ldap->fetch()){
-      $printerObj = NULL;
-      $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
-      $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
-      $printerObj->by_object['printgeneric']->save();
-    }
+      if($this->is_group){
+        $s_suffix = "Group";
+        $useVar   = "cn";
+      }else{
+        $useVar   = "uid";
+        $s_suffix = "User";
+      }
 
-    foreach($this->gotoPrinter as $printer){
-      $printerObj = NULL;
-      $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
+      /* Remove old entries */
+      $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
+      while($attr = $ldap->fetch()){
+        $printerObj = NULL;
+        $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
+        $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
+        $printerObj->by_object['printgeneric']->save();
+      }
 
-      if($printer['mode'] == "admin") {
-        $attribute = "goto".$s_suffix."AdminPrinter";
-      }else{
-        $attribute = "goto".$s_suffix."Printer";
+      $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
+      while($attr = $ldap->fetch()){
+        $printerObj = NULL;
+        $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
+        $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
+        $printerObj->by_object['printgeneric']->save();
       }
 
-      $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
-      $printerObj->by_object['printgeneric']->save();
-    }
+      foreach($this->gotoPrinter as $printer){
+        $printerObj = NULL;
+        $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
+
+        if($printer['mode'] == "admin") {
+          $attribute = "goto".$s_suffix."AdminPrinter";
+        }else{
+          $attribute = "goto".$s_suffix."Printer";
+        }
+
+        $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
+        $printerObj->by_object['printgeneric']->save();
+      }
+    }    
 
     /* Prepare HotPlug devices */
     $this->attrs['gotoHotplugDevice'] = array();