Code

Added logging to some classes
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
index 1a37efb1a2daeed2a5dff030efe1f4de636e5342..9000b008bebf3a644e6f6a9fff24d2bc915f51b3 100644 (file)
@@ -18,6 +18,7 @@ class printgeneric extends plugin
   var $description      = "";
   var $labeledURI       = "";
   var $gotoPrinterPPD   = "";
+  var $initial_PPD      = "";
   var $orig_dn          = "";
 
   var $UserMember       ="";
@@ -117,6 +118,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",
@@ -148,6 +151,10 @@ class printgeneric extends plugin
         }
       }
     }
+    
+    if($this->is_account){
+      @log::log("view","printer/".get_class($this),$this->dn);
+    }
   }
 
   function set_acl_base($base)
@@ -288,14 +295,6 @@ class printgeneric extends plugin
       $smarty->assign($name."ACL", $this->getacl($name));
     }
 
-    /* Create base acls */
-    $baseACL = $this->getacl("base");
-    if(!$this->acl_is_moveable()) {
-      $baseACL = preg_replace("/w/","",$baseACL);
-    }
-    $smarty->assign("baseACL",          $baseACL);
-
-
     $display="";
 
     /* Tell smarty if this is a standalone object or a terminal / WS depending printer */
@@ -371,7 +370,13 @@ class printgeneric extends plugin
           $this->dialog = false;
           $this->baseSelection = false;
         }elseif($this->dialog->isSelected()){
-          $this->base = $this->dialog->isSelected();
+
+          /* A new base was selected, check if it is a valid one */
+          $tmp = $this->get_allowed_bases();
+          if(isset($tmp[$this->dialog->isSelected()])){
+            $this->base = $this->dialog->isSelected();
+          }
+
           $this->dialog= false;
           $this->baseSelection = false;
         }else{
@@ -408,6 +413,7 @@ class printgeneric extends plugin
         $this->dialog = $this->PPDdialogToSave;
       }else{
         $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+        $this->dialog->cn= $this->cn;
       }
     }
 
@@ -585,6 +591,9 @@ class printgeneric extends plugin
       /* Remove account & dns extension */ 
       $this->netConfigDNS->remove_from_parent();
       $ldap->rmdir($this->dn);
+
+      @log::log("remove","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+  
       show_ldap_error($ldap->get_error(), sprintf(_("Removing of system print/generic with dn '%s' failed."),$this->dn));
       $this->handle_post_events("remove");
 
@@ -596,6 +605,12 @@ class printgeneric extends plugin
         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();
+      }
     }
   }
 
@@ -603,27 +618,22 @@ class printgeneric extends plugin
   /* Save data to object */
   function save_object()
   {
+    /* Create a base backup and reset the
+       base directly after calling plugin::save_object();
+       Base will be set seperatly a few lines below */
+    $base_tmp = $this->base;
     plugin::save_object();
-    
+    $this->base = $base_tmp;
+
     if(is_object($this->netConfigDNS)){
       $this->netConfigDNS->save_object();
     }
-
-    /* Save base, since this is no LDAP attribute */
-    if((isset($_POST['base'])) && ($this->acl_is_moveable()) ) {
-      $this->set_acl_base('dummy,'.$_POST['base']);
-      if($this->acl_is_moveable()){
-
-        if(isset($this->config->idepartments[$_POST['base']])){
-          $this->base = $_POST['base'];
-          if ($_POST['base'] != $this->base){
-            $this->is_modified= TRUE;
-          }
-        }
-      }else{
-
-        print_red(sprintf(_("You are not allowed to move this object to '%s'."),LDAP::fix($_POST['base'])));
-        $this->set_acl_base('dummy,'.$this->base);
+    
+    /* Set new base if allowed */
+    $tmp = $this->get_allowed_bases();
+    if(isset($_POST['base'])){
+      if(isset($tmp[$_POST['base']])){
+        $this->base= $_POST['base'];
       }
     }
   }
@@ -655,17 +665,6 @@ class printgeneric extends plugin
       $message[]= "The required field 'Printer name' is not set.";
     }
 
-    /* Set new acl base */
-    if($this->dn == "new") {
-      $this->set_acl_base($this->base);
-    }
-
-    if(preg_match("/printer/i",$this->BelongsTo)){
-      if ($this->orig_dn == "new" && !$this->acl_is_createable()){
-        $message[]= _("You have no permissions to create a group on this 'Base'.");
-      }
-    }
-    
     /* must: labeledURI */
     if(empty($this->labeledURI)){
       $message[]= "The required field 'Printer URL' is not set.";
@@ -724,6 +723,14 @@ class printgeneric extends plugin
       $this->PPDdialogToSave->save_ppd();
     }
 
+    /* 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{
@@ -796,6 +803,11 @@ class printgeneric extends plugin
       }
     }
 
+    /* Ensure to create a new object */
+    if(preg_match("/ou=incoming,/",$this->orig_dn)){
+      $this->orig_dn = "new";
+    }
+
     /* Move object in necessary*/
     if (($this->orig_dn != $this->dn) && ($this->orig_dn != 'new')){
       $this->move($this->orig_dn, $this->dn);
@@ -808,13 +820,23 @@ class printgeneric extends plugin
       $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");
+      @log::log("create","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     } else {
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify ($this->attrs); 
       $this->handle_post_events("modify");
+      @log::log("modify","printer/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }
     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system print/generic with dn '%s' failed."),$this->dn));
 
@@ -860,7 +882,7 @@ class printgeneric extends plugin
           "plDescription" => _("Print generic"),
           "plSelfModify"  => FALSE,
           "plDepends"     => array(),
-          "plPriority"    => 11,
+          "plPriority"    => 4,
           "plSection"     => array("administration"),
           "plCategory"    => array("printer" => array("description"  => _("Printer"),
                                                     "objectClass"  => "gotoPrinter"),"workstation","terminal"),