Code

updated tempalte
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
index fc743ce969414ae6b89fe9511a60c69e73967518..c5717286fdf41c59e55c08d9920e93ebdc680061 100644 (file)
@@ -14,8 +14,6 @@ class printgeneric extends plugin
   /* Needed values and lists */
   var $base             = "";
   var $cn               = "";
-  var $macAddress       = "";
-  var $ipHostNumber     = "";
   var $l                = "";
   var $description      = "";
   var $labeledURI       = "";
@@ -40,14 +38,19 @@ class printgeneric extends plugin
   var $type             = "";
   var $dialog           =NULL;
 
+  var $netConfigDNS;
+
   /* attribute list for save action */
-  var $attributes     = array("cn", "description", "l", "labeledURI", "macAddress", "ipHostNumber","gotoPrinterPPD");
+  var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD");
   var $objectclasses  = array("top", "gotoPrinter");
 
   function printgeneric ($config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
     $ldap= $this->config->get_ldap_link();
+    
+    $this->netConfigDNS = new termDNS($this->config, $this->dn,$this->objectclasses);
+
 
     /* Set base */
     if ($this->dn == "new"){
@@ -86,7 +89,7 @@ class printgeneric extends plugin
       }else{
         $this->type = "terminal";
         $this->is_terminal = "true";
-        $this->dn   = preg_replace("/ou=terminal/","ou=printers",$this->dn);
+        $this->dn   = preg_replace("/ou=terminals/","ou=printers",$this->dn);
       }
     }else{
       /* Save dn for later references */
@@ -152,6 +155,13 @@ class printgeneric extends plugin
       }
     }
 
+    /* This attributes is sometimes written with Uri instead of URI
+       In RFC 2079 it is defined with URI ...
+     */
+    if(isset($this->attrs['labeledUri'])){
+      $this->labeledURI = $this->attrs['labeledUri'][0];
+    }
+
     /* A printer was only saved if the printer belongs to a workstation. 
      * If there was a new single printer created, it was never saved.
      * -This allows new printers to be saved.
@@ -166,6 +176,26 @@ class printgeneric extends plugin
        /* Call parent execute */
        plugin::execute();
 
+    if(isset($this->parent->by_name['workgeneric'])){
+//      echo "workstation";
+      if($this->parent->by_object['workgeneric']->cn == "wdefault"){
+        $display= $this->show_header(_("Add printer extension"),
+            _("This is a workstation template, printer tab is disabled."),TRUE,TRUE);
+        $this->is_account= false;
+        return $display;
+      }
+    }elseif(isset($this->parent->by_name['termgeneric'])){
+      if($this->parent->by_object['termgeneric']->cn == "default"){
+        $display= $this->show_header(_("Add printer extension"),
+            _("This is a terminal template, printer tab is disabled."),TRUE,TRUE);
+        $this->is_account= false;
+        return $display;
+      }
+    }elseif(isset($this->parent->by_name['printgeneric'])){
+//      echo "printer";
+    }
+
+
     $smarty= get_smarty();
     $display="";
     /* Template management.
@@ -351,10 +381,6 @@ class printgeneric extends plugin
       return $display;
     }
 
-    /* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
-    $smarty->assign("staticAddress", "");
-
-
     require_once ("class_ppdManager.inc");
 
     if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
@@ -402,34 +428,40 @@ class printgeneric extends plugin
     $smarty->assign("AdminMember"    ,$this->AdminMember);
     $smarty->assign("AdminMembers"   ,$adminlist);
     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
-    $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
+    $smarty->assign("netconfig", $this->netConfigDNS->execute());
 
     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
   }
 
   function remove_from_parent()
   {
-    $this->dn= preg_replace('/ou=workstations,/', 'ou=printers,', $this->dn);
-    $ldap= $this->config->get_ldap_link();
-    $ldap->rmdir($this->dn);
-    show_ldap_error($ldap->get_error());
-    $this->handle_post_events("remove");
-
-    /* Delete references to object groups */
-    $ldap->cd ($this->config->current['BASE']);
-    $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
-    while ($ldap->fetch()){
-      $og= new ogroup($this->config, $ldap->getDN());
-      unset($og->member[$this->dn]);
-      $og->save ();
+    if($this->initially_was_account){
+      $ldap= $this->config->get_ldap_link();
+      $ldap->cat($this->dn);
+      if(count($ldap->fetch()) ){
+
+        $ldap->rmdir($this->dn);
+        show_ldap_error($ldap->get_error());
+        $this->handle_post_events("remove");
+
+        /* Delete references to object groups */
+        $ldap->cd ($this->config->current['BASE']);
+        $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
+        while ($ldap->fetch()){
+          $og= new ogroup($this->config, $ldap->getDN());
+          unset($og->member[$this->dn]);
+          $og->save ();
+        }
+    
+        $this->netConfigDNS->remove_from_parent();
+      }
     }
   }
-
   /* Save data to object */
   function save_object()
   {
     plugin::save_object();
-
+    $this->netConfigDNS->save_object();
     /* Save base, since this is no LDAP attribute */
     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
       $this->base= $_POST['base'];
@@ -439,7 +471,18 @@ class printgeneric extends plugin
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    $message= $this->netConfigDNS->check();
+
+    if(isset($this->parent->by_name['workgeneric'])){
+      if($this->parent->by_object['workgeneric']->cn == "wdefault"){
+        return $message;
+      }
+    }elseif(isset($this->parent->by_name['termgeneric'])){
+      if($this->parent->by_object['termgeneric']->cn == "default"){
+        return $message;
+      }
+    }
+
     $this->dn= "cn=".$this->cn.",ou=printers,ou=systems,".$this->base;
 
     /* must: cn */
@@ -478,7 +521,16 @@ class printgeneric extends plugin
     if (!$this->is_account){
       return;
     }
-  
+    if(isset($this->parent->by_name['workgeneric'])){
+      if($this->parent->by_object['workgeneric']->cn == "wdefault"){
+        return;
+      }
+    }elseif(isset($this->parent->by_name['termgeneric'])){
+      if($this->parent->by_object['termgeneric']->cn == "default"){
+        return;
+      }
+    }
+
     if($this->PPDdialogToSave){
       $this->PPDdialogToSave->save_ppd();
     }
@@ -576,6 +628,8 @@ class printgeneric extends plugin
     }
     show_ldap_error($ldap->get_error());
 
+    $this->netConfigDNS->save($this->dn);
+
     /* Optionally execute a command after we're done */
     $this->postcreate();
   }