Code

Updated filtering again
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
index 9c594658d4ac0d4e65d1705c7c1580bed7d69c81..d2f3b6beaf826d3b6f86b6043a7c1542441894fe 100644 (file)
@@ -2,11 +2,6 @@
 
 class printgeneric extends plugin
 {
-  /* CLI vars */
-  var $cli_summary      = "Manage terminal base objects";
-  var $cli_description  = "Some longer text\nfor help";
-  var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* Generic terminal attributes */
   var $interfaces     = array();
   var $ignore_account = FALSE;
@@ -18,6 +13,7 @@ class printgeneric extends plugin
   var $description      = "";
   var $labeledURI       = "";
   var $gotoPrinterPPD   = "";
+  var $initial_PPD      = "";
   var $orig_dn          = "";
 
   var $UserMember       ="";
@@ -28,7 +24,6 @@ class printgeneric extends plugin
   var $AdminMembers     =array();
   var $AdminMemberKeys  =array();
 
-  var $gotoUserPrinter ;
   var $PPDdialogToSave  = NULL;
   var $BelongsTo        = "unknown"; //  Specifies if this is a standalone printer, or belongs to a terminal / WS
 
@@ -41,9 +36,15 @@ class printgeneric extends plugin
   var $macAddress       = "";
 
   /* attribute list for save action */
-  var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress");
+  var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress",
+                                "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
   var $objectclasses  = array("top", "gotoPrinter");
 
+    var $gotoUserAdminPrinter;
+  var $gotoGroupAdminPrinter ;
+  var $gotoGroupPrinter;
+  var $gotoUserPrinter ;
+
   function printgeneric ($config, $dn= NULL,$parent = NULL)
   {
     $this->config = $config;
@@ -59,15 +60,16 @@ class printgeneric extends plugin
     }
 
     /* Update dn, to ensure storing as printer instead of WS / terminal */
-    if($this->BelongsTo == "Terminal"){
+    if($this->BelongsTo == "Terminal" || $this->BelongsTo == "TerminalTemplate"){
       $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
     }
 
-    if($this->BelongsTo == "Workstation"){
+    if($this->BelongsTo == "Workstation" || $this->BelongsTo == "WorkstationTemplate"){
       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
     }
 
     $this->orig_dn = $this->dn;
+    $ui= get_userinfo();
 
     /* Get printer settings, possibly dn has changed */
     plugin::plugin ($config, $this->dn);
@@ -77,23 +79,28 @@ class printgeneric extends plugin
 
     /* set orig dn to new if object is new */
     $ldap= $this->config->get_ldap_link();
-    $ldap->cat($this->dn);
+    $ldap->cat($this->dn, array('dn'));
     if(!$ldap->count()){
       $this->orig_dn = "new";
     }
     
     /* create dns object */
     $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
+    $this->netConfigDNS->acl = $this->acl;
 
     /* Set base */
     if ($this->dn == "new"){
-      $ui= get_userinfo();
       $this->base= dn2base($ui->dn);
       $this->cn= "";
     } else {
     
       /* Set base and check if the extracted base exists */
-      $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
+      if(preg_match("/ou=incoming,/",$this->dn)){
+        $this->base= preg_replace("/ou=incoming,/","",dn2base($this->dn));
+      }else{
+        $this->base= preg_replace("/ou=printers,ou=systems,/","",dn2base($this->dn));
+      }
+
       if(!isset($this->config->idepartments[$this->base])){
         print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),$_SESSION['CurrentMainBase']);
         $this->base = $_SESSION['CurrentMainBase'];
@@ -105,6 +112,8 @@ class printgeneric extends plugin
       $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
     }
 
+    $this->initial_PPD = $this->gotoPrinterPPD;
+
     /* Prepare different member types */ 
     foreach(array("AddUser"       =>"gotoUserPrinter",
           "AddGroup"      =>"gotoGroupPrinter",
@@ -118,19 +127,30 @@ class printgeneric extends plugin
         unset($this->attrs[$attr]['count']);
       }
 
+      /* Set tag attribute if we've tagging activated */
+      $tag= "";
+      if ($ui->gosaUnitTag != "" && isset($config->current['STRICT_UNITS']) &&
+          preg_match('/TRUE/i', $config->current['STRICT_UNITS'])){
+        $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
+      }
+
       if(isset($this->attrs[$attr])){
         foreach($this->attrs[$attr] as $mem){
           if(preg_match("/Group/",$type)){
-            $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
-            $entry = $ldap->fetch();
-            if(isset($entry['description'])){
-              $this->member[$type][$entry['cn'][0]]=$entry;
+            $ldap->search("(&(objectClass=posixGroup)$tag(cn=".$mem."))",array("cn","description"));
+            if($ldap->count()){
+              $entry = $ldap->fetch();
+              if(isset($entry['cn'])){
+                $this->member[$type][$entry['cn'][0]]=$entry;
+              }
             }
           }else{
-            $ldap->search("(&(objectClass=person)(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
-            $entry = $ldap->fetch();
-            if(isset($entry['uid'])){
-              $this->member[$type][$entry['uid'][0]]=$entry;
+            $ldap->search("(&(objectClass=person)$tag(objectClass=inetOrgPerson)(uid=".$mem."))",array("cn","uid"));
+            if($ldap->count()){
+              $entry = $ldap->fetch();
+              if(isset($entry['uid'])){
+                $this->member[$type][$entry['uid'][0]]=$entry;
+              }
             }
           }
         }
@@ -201,9 +221,9 @@ class printgeneric extends plugin
 
       /* Detect if this is a valid printer account;
        */
+      //FIXME: do we need to do this? we've already everything we need in $this->attrs...
       $ldap = $this->config->get_ldap_link();
-      $ldap->cd($this->config->current['BASE']);
-      $ldap->cat($this->dn);
+      $ldap->cat($this->dn, array('objectClass'));
 
       if($ldap->count()){
         $attrs = $ldap->fetch();
@@ -219,6 +239,8 @@ class printgeneric extends plugin
 
   function execute()
   {
+    $this->netConfigDNS->acl = $this->acl;
+
     /* Call parent execute */
     plugin::execute();
 
@@ -227,7 +249,7 @@ class printgeneric extends plugin
      */
     if($this->BelongsTo == "unknown"){
       $display= $this->show_header(_("Add printer extension"),
-          _("Could not intialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
+          _("Could not initialize printer tab, parameter parent was missing while construction."),TRUE,TRUE);
       return($display);
     }
 
@@ -262,10 +284,17 @@ class printgeneric extends plugin
       $smarty->assign("StandAlone",false);
     }
 
-    /* Do we need to flip is_account state? */
+
     if (isset($_POST['modify_state'])){
-      $this->is_modified = true;
-      $this->is_account= !$this->is_account;
+
+      /* Only change account state if allowed */
+      if($this->is_account && $this->acl == "#all#"){
+        $this->is_account= !$this->is_account;
+        $this->is_modified = true;
+      }elseif(!$this->is_account && chkacl($this->acl,"create") == ""  && !((empty($this->cn)) && ($this->dn != "new"))){
+        $this->is_account= !$this->is_account;
+        $this->is_modified = true;
+      }
     }
 
     /* Do we represent a valid printer? */
@@ -307,7 +336,7 @@ class printgeneric extends plugin
     /* Base select dialog */
     $once = true;
     foreach($_POST as $name => $value){
-      if(preg_match("/^chooseBase/",$name) && $once){
+      if(preg_match("/^chooseBase/",$name) && $once && chkacl($this->acl,"base")){
         $once = false;
         $this->dialog = new baseSelectDialog($this->config);
         $this->dialog->setCurrentBase($this->base);
@@ -344,30 +373,33 @@ class printgeneric extends plugin
       $smarty->assign("$attr", $this->$attr);
     }
 
-    if(isset($_POST['AddUser'])){
-      $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddUser");
+    $smarty->assign("baseACL", chkacl($this->acl,"base"));
+
+    if(isset($_POST['AddUser']) && chkacl($this->acl,"gotoUserPrinter") == ""){
+      $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddUser");
     }
-    if(isset($_POST['AddGroup'])){
-      $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddGroup");
+    if(isset($_POST['AddGroup']) && chkacl($this->acl,"gotoGroupPrinter") == ""){
+      $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddGroup");
     }
-    if(isset($_POST['AddAdminUser'])){
-      $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminUser");
+    if(isset($_POST['AddAdminUser']) && chkacl($this->acl,"gotoUserAdminPrinter") == ""){
+      $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminUser");
     }
-    if(isset($_POST['AddAdminGroup'])){
-      $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminGroup");
+    if(isset($_POST['AddAdminGroup']) && chkacl($this->acl,"gotoGroupAdminPrinter") == ""){
+      $this->dialog = new selectUserToPrinterDialog($this->config, NULL,"AddAdminGroup");
     }
 
     /* Display ppd configure/select dialog      */
-    if(isset($_POST['EditDriver'])){
+    if(isset($_POST['EditDriver']) && chkacl($this->acl,"gotoPrinterPPD")==""){
       if($this->PPDdialogToSave){
         $this->dialog = $this->PPDdialogToSave;
       }else{
         $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+        $this->dialog->cn= $this->cn;
       }
     }
 
     /* remove ppd */
-    if(isset($_POST['RemoveDriver'])){
+    if(isset($_POST['RemoveDriver']) && chkacl($this->acl,"gotoPrinterPPD")==""){
       $this->gotoPrinterPPD = array();
       $this->PPDdialogToSave = NULL;
     }
@@ -395,27 +427,27 @@ class printgeneric extends plugin
     }
 
     /* 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']]);
+    if((isset($_POST['DelUser']))&&(isset($_POST['UserMember'])) && chkacl($this->acl,"gotoUserPrinter")==""){
+      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']]);
+    if((isset($_POST['DelUser']))&&(isset($_POST['UserMember'])) && chkacl($this->acl,"gotoGroupPrinter")==""){
+      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']]);
+    if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember'])) && chkacl($this->acl,"gotoUserAdminPrinter")==""){
+      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']]);
+    if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember'])) && chkacl($this->acl,"gotoGroupAdminPrinter")==""){
+      foreach($_POST['AdminMember'] as $mem){
+        $this->DelMember('AddAdminGroup',$mem);
       }
     }
 
@@ -433,18 +465,10 @@ 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;    
+        foreach($data as $mem){  
+          $this->AddMember($new['type'], $mem['dn']);    
         }
         unset($this->dialog);
         $this->dialog=NULL; 
@@ -470,15 +494,15 @@ class printgeneric extends plugin
       $ppdManager= new ppdManager($path);
       if(!empty($this->gotoPrinterPPD)){
         if((!file_exists($path.$this->gotoPrinterPPD))){
-          $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$this->gotoPrinterPPD))."</b>";
+          $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$path.$this->gotoPrinterPPD))."</b>";
         }else{
           $smarty->assign("driverInfo", $ppdManager->loadDescription($path.$this->gotoPrinterPPD));
         }
       }else{
-        $smarty->assign("driverInfo", _("not defined"));
+        $smarty->assign("driverInfo", _("Not defined"));
       }
     }else{
-      $smarty->assign("driverInfo",_("can't get ppd informations."));
+      $smarty->assign("driverInfo",_("Can't get ppd informations."));
     }
 
     /* Create user & admin user list */
@@ -506,13 +530,29 @@ class printgeneric extends plugin
     $smarty->assign("AdminMember"    ,$this->AdminMember);
     $smarty->assign("AdminMembers"   ,$adminlist);
     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
-    $smarty->assign("netconfig", $this->netConfigDNS->execute());
+    if($this->BelongsTo == "Printer"){
+      $this->netConfigDNS->cn= $this->cn;
+      $smarty->assign("netconfig", $this->netConfigDNS->execute());
+
+      /* Display sub dialog from network settings */
+      if($this->netConfigDNS->dialog){
+        $this->dialog = TRUE;
+        return($this->netConfigDNS->execute());
+      }else{ 
+        $this->dialog = FALSE;
+      }
+    } else {
+      $smarty->assign("netconfig", "");
+    }
+
 
     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
   }
 
   function remove_from_parent()
   {
+    $this->netConfigDNS->acl = $this->acl;
+
     /* Only remove if there was initially an account */
     if($this->initially_was_account){
 
@@ -528,33 +568,39 @@ class printgeneric extends plugin
 
       /* Check if this dn points to a printer, to avoid deleting something else */
       $ldap= $this->config->get_ldap_link();
-      $ldap->cat($this->dn);
+      $ldap->cat($this->dn, array('dn',"objectClass"));
       if(!$ldap->count()){
-        print_red("Trying to remove printer obejct which isn't a printer. Aborted to avoid data loss.");
+        print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
         return;
       }
 
       /* Check if obejct is a printer */
       $CheckPrinter = $ldap->fetch();
       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
-        print_red("Trying to remove printer obejct which isn't a printer. Aborted to avoid data loss.");
+        print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
         return;
       }
 
       /* Remove account & dns extension */ 
       $this->netConfigDNS->remove_from_parent();
       $ldap->rmdir($this->dn);
-      show_ldap_error($ldap->get_error());
-      $this->handle_post_events("remove");
+      show_ldap_error($ldap->get_error(), _("Removing printer failed"));
+      $this->handle_post_events("remove",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
 
       /* Delete references to object groups */
       $ldap->cd ($this->config->current['BASE']);
-      $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
+      $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
       while ($ldap->fetch()){
         $og= new ogroup($this->config, $ldap->getDN());
         unset($og->member[$this->dn]);
         $og->save ();
       }
+
+      /* Remove previously selected ppd file.*/
+      if(!empty($this->initial_PPD)){
+        $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
+        $tmp->removeModifiedPPD();
+      }
     }
   }
 
@@ -575,7 +621,9 @@ class printgeneric extends plugin
   {
     /* Call common method to give check the hook */
     $message= plugin::check();
-    $message= array_merge($message, $this->netConfigDNS->check());
+    if ($this->BelongsTo == 'printer'){
+      $message= array_merge($message, $this->netConfigDNS->check());
+    }
 
     /* Don't display check messages if this is a template object */
     if(isset($this->parent->by_object['workgeneric'])){
@@ -592,7 +640,27 @@ class printgeneric extends plugin
 
     /* must: cn */
     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
-      $message[]= "The required field 'Printer name' is not set.";
+      $message[]= _("The required field 'Printer name' is not set.");
+    }
+
+    /* must: cn */
+    if(($this->BelongsTo == "Printer") && !is_dns_name($this->cn)){
+      $message[]= _("Invalid character in printer name.");
+    }
+
+    if($this->BelongsTo == "Printer"){
+      $ui= get_userinfo();
+      $acl= get_permissions ($dn, $ui->subtreeACL);
+      $acl= get_module_permission($acl, "printgeneric", $dn);
+      if (chkacl($acl, "create") != ""){
+        $message[]= _("You have no permissions to create a printer on this 'Base'.");
+      }
+    }
+
+    
+    /* must: labeledURI */
+    if(empty($this->labeledURI)){
+      $message[]= "The required field 'Printer URL' is not set.";
     }
     
     /* Check if there is already an entry with this cn*/
@@ -602,6 +670,9 @@ class printgeneric extends plugin
       $ldap->ls("(cn=".$this->cn.")","ou=printers,ou=systems,".$this->base, array("cn"));
       if ($ldap->count() != 0){
         while ($attrs= $ldap->fetch()){
+          if(preg_match("/cn=dhcp,/",$attrs['dn'])){
+            continue;
+          }
           if ($attrs['dn'] != $this->orig_dn){
             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
             break;
@@ -617,6 +688,8 @@ class printgeneric extends plugin
   /* Save to LDAP */
   function save()
   {
+    $this->netConfigDNS->acl = $this->acl;
+
     /* Update dn, to ensure storing as printer instead of WS / terminal
      */
     if($this->BelongsTo == "Terminal"){
@@ -625,6 +698,7 @@ class printgeneric extends plugin
 
     if($this->BelongsTo == "Workstation"){
       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
+      $this->macAddress = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
     }
     
     if(!$this->is_account) return;
@@ -647,6 +721,35 @@ class printgeneric extends plugin
     if($this->PPDdialogToSave){
       $this->PPDdialogToSave->save_ppd();
     }
+    if($this->orig_dn != $this->dn){
+      if(!empty($this->gotoPrinterPPD)) {
+        $this->PPDdialogToSave = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+        $this->PPDdialogToSave->cn = $this->cn;
+        $this->PPDdialogToSave->generateProperties();
+        $this->PPDdialogToSave->update_ppd_url();
+      }
+    }
+
+    /* Remove previously selected ppd file.*/
+    if($this->initial_PPD != $this->gotoPrinterPPD){
+      if(!empty($this->initial_PPD)){
+        $tmp = new printerPPDDialog($this->config, $this->dn,$this->initial_PPD);
+        $tmp->removeModifiedPPD();
+      }
+    }
+
+    if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
+      $method="https://";
+    }else{
+      $method="http://";
+    }
+
+    /* If no ppd is selected, remove this attribute */
+    if(!empty($this->gotoPrinterPPD)) {
+      $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+    }else{
+      $this->gotoPrinterPPD = array();
+    }
 
     $dn= $this->dn;
     plugin::save();
@@ -667,49 +770,68 @@ class printgeneric extends plugin
       $this->attrs= $attrs;
     }
 
-    if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
-      $method="https://";
-    }else{
-      $method="http://";
-    }
-  
-    $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
-
     /* Append printer user 
      */
-    if((isset($this->attrs['gotoUserPrinter'])) && (is_string($this->attrs['gotoUserPrinter']))){
-      $this->attrs['gotoUserPrinter']=array();
-    }
+    $this->attrs['gotoUserPrinter']=array();
     foreach($this->member['AddUser'] as $mem){
       $this->attrs['gotoUserPrinter'][]=$mem['uid'][0];
     }
 
     /* Append printer group 
      */
+    $this->attrs['gotoGroupPrinter'] = array();
     foreach($this->member['AddGroup'] as $mem){
       $this->attrs['gotoGroupPrinter'][]=$mem['cn'][0];
     }
 
     /* Append printer admin user 
      */
+    $this->attrs['gotoUserAdminPrinter'] =array();
     foreach($this->member['AddAdminUser'] as $mem){
       $this->attrs['gotoUserAdminPrinter'][]=$mem['uid'][0];
     }
 
     /* Append printer admin group 
      */
+    $this->attrs['gotoGroupAdminPrinter'] = array();
     foreach($this->member['AddAdminGroup'] as $mem){
       $this->attrs['gotoGroupAdminPrinter'][]=$mem['cn'][0];
     }
 
+    if(($this->gosaUnitTag) && (!in_array_ics("gosaAdministrativeUnitTag",$this->attrs['objectClass']))){
+      $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
+      $this->attrs['gosaUnitTag'] = $this->gosaUnitTag;
+    }
+
+    if($this->orig_dn == 'new'){
+      foreach(array("gotoGroupPrinter","gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter") as $checkVar){
+        if(count($this->attrs[$checkVar])  == 0 || empty($this->attrs[$checkVar])){
+          unset($this->attrs[$checkVar]);
+        }
+      }
+    }
+
+    /* Ensure to create a new object */
+    if(preg_match("/ou=incoming,/",$this->orig_dn)){
+      $this->orig_dn = "new";
+    }
+
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     if ($this->orig_dn == 'new'){
       $ldap->cd($this->config->current['BASE']);
       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
       $ldap->cd($this->dn);
+     
+      /* Remove empty values */ 
+      foreach($this->attrs as $name => $value){
+        if(empty($value)){
+          unset($this->attrs[$name]);
+        }
+      }
+      
       $ldap->add($this->attrs);
-      $this->handle_post_events("add");
+      $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
     } else {
       if ($this->orig_dn != $this->dn){
         $this->move($this->orig_dn, $this->dn);
@@ -719,16 +841,19 @@ class printgeneric extends plugin
       $this->cleanup();
       $ldap->modify ($this->attrs); 
 
-      $this->handle_post_events("modify");
+      $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
     }
-    show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), _("Saving printer failed"));
 
-    $this->netConfigDNS->cn = $this->cn;
-    $this->netConfigDNS->dn = $this->dn;
-    $this->netConfigDNS->save($this->dn);
+    /* Only save dns stuff if we are a standalone printer */
+    if($this->BelongsTo == "Printer"){
+      $this->netConfigDNS->cn = $this->cn;
+      $this->netConfigDNS->dn = $this->dn;
+      $this->netConfigDNS->save($this->dn);
+    }
 
-    /* Optionally execute a command after we're done */
-    $this->postcreate();
+    /* This is a multi object. Handle tagging here... */
+    $this->handle_object_tagging();
   }
 
   function generateList(){
@@ -749,9 +874,54 @@ class printgeneric extends plugin
     }
     return($a_return);
   }
-}
 
+  /* 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();
+      $name = $attrs[$var][0];
+
+      /* Check if this uid/cn is already assigned to any permission */
+      foreach($types as $ctype){
+        if(isset(  $this->member[$ctype][$name])){
+          print_red(sprintf(_("Can't add '%s' to the list of members, it is already used."),$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));
+    }
+  }
+}
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>