Code

Added printer patch
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
index dd7cf2e30bf8b2035252c405160e13a04415fc24..9cccd381a2afd013918ff2dcada07f989a971ad6 100644 (file)
@@ -73,6 +73,7 @@ class printgeneric extends plugin
     }
 
     $this->orig_dn = $this->dn;
+    $ui= get_userinfo();
 
     /* Get printer settings, possibly dn has changed */
     plugin::plugin ($config, $this->dn);
@@ -92,7 +93,6 @@ class printgeneric extends plugin
 
     /* Set base */
     if ($this->dn == "new"){
-      $ui= get_userinfo();
       $this->base= dn2base($ui->dn);
       $this->cn= "";
     } else {
@@ -128,17 +128,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();
-            $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;
+              }
             }
           }
         }
@@ -508,7 +521,11 @@ 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"){
+      $smarty->assign("netconfig", $this->netConfigDNS->execute());
+    } else {
+      $smarty->assign("netconfig", "");
+    }
 
     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
   }
@@ -577,7 +594,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'])){
@@ -596,6 +615,16 @@ class printgeneric extends plugin
     if(($this->BelongsTo == "Printer") && (empty($this->cn))){
       $message[]= "The required field 'Printer name' is not set.";
     }
+
+    if($this->BelongsTo == "Printer"){
+      $ui= get_userinfo();
+      $acl= get_permissions ($dn, $ui->subtreeACL);
+      $acl= get_module_permission($acl, "printer", $this->dn);
+      if (chkacl($acl, "create") != ""){
+        $message[]= _("You have no permissions to create a printer on this 'Base'.");
+      }
+    }
+
     
     /* must: labeledURI */
     if(empty($this->labeledURI)){
@@ -632,6 +661,8 @@ class printgeneric extends plugin
 
     if($this->BelongsTo == "Workstation"){
       $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
+      $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
+      $this->netConfigDNS->macAddress = $mac;
     }
     
     if(!$this->is_account) return;
@@ -679,8 +710,13 @@ class printgeneric extends plugin
     }else{
       $method="http://";
     }
-  
-    $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+
+    /* Only save ppd path, if the path is not empty (no ppd selected )*/ 
+    if(count($this->gotoPrinterPPD)) {
+      $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+    }else{
+      $this->attrs['gotoPrinterPPD'] = array();
+    }
 
     /* Append printer user 
      */
@@ -714,6 +750,14 @@ class printgeneric extends plugin
       $this->attrs['objectClass'][] = "gosaAdministrativeUnitTag";
     }
 
+    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]);
+        }
+      }
+    }
+
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     if ($this->orig_dn == 'new'){
@@ -735,12 +779,16 @@ class printgeneric extends plugin
     }
     show_ldap_error($ldap->get_error(), _("Saving printer failed"));
 
+
     $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(){