Code

Updated a couple of values
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_printGeneric.inc
index 0b89ef20e84cd1b69bd5e2763d4488cdbdff5026..46aa1f1f8b472dda1934e45113d3b409b57a2fcb 100644 (file)
@@ -15,6 +15,8 @@ class printgeneric extends plugin
   var $gotoPrinterPPD   = "";
   var $initial_PPD      = "";
   var $orig_dn          = "";
+  var $orig_cn          = "";
+  var $orig_base        = "";
 
   var $UserMember       ="";
   var $UserMembers      =array();
@@ -40,7 +42,7 @@ class printgeneric extends plugin
 
   /* attribute list for save action */
   var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","gotoUserPrinter", "macAddress", 
-                              "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter");
+                              "gotoUserAdminPrinter","gotoGroupAdminPrinter","gotoUserPrinter","gotoGroupPrinter","gosaUnitTag");
   var $objectclasses  = array("top", "gotoPrinter");
   var $view_logged    = FALSE;
   var $parent;
@@ -101,7 +103,7 @@ class printgeneric extends plugin
       }
 
       if(!isset($this->config->idepartments[$this->base])){
-        print_red(_("Can't extract a valid base out of object dn, setting base to '%s'."),session::get('CurrentMainBase'));
+        msg_dialog::display(_("Internal error"), sprintf(_("Cannot determine a valid department for this object. Setting base to '%s'!"), session::get('CurrentMainBase')) , WARNING_DIALOG);
         $this->base  = session::get('CurrentMainBase');
       }
     }
@@ -122,14 +124,13 @@ class printgeneric extends plugin
       /* $this->members contains all members */
       $this->member[$type]=array();
 
-      if (isset($this->attrs[$attr]['count'])) {
-        unset($this->attrs[$attr]['count']);
-      }
-
       if(isset($this->attrs[$attr])){
-        foreach($this->attrs[$attr] as $mem){
+        $ldap->cd($this->config->current['BASE']) ;
+        for($i = 0 ;  $i < $this->attrs[$attr]['count']; $i++){
+        
+          $mem = $this->attrs[$attr][$i];
           if(preg_match("/Group/",$type)){
-            $ldap->search("(&(objectClass=posixGroup)(cn=".$mem."))",array("cn","description"));
+            $ldap->search("(&(|(objectClass=posixGroup)(objectClass=gosaGroupOfNames))(cn=".$mem."))",array("cn","description"));
             if($ldap->count()){
               $entry = $ldap->fetch();
               $this->member[$type][$entry['cn'][0]]=$entry;
@@ -144,6 +145,8 @@ class printgeneric extends plugin
         }
       }
     }
+    $this->orig_cn    = $this->cn;
+    $this->orig_base  = $this->base;
   }
 
   function set_acl_base($base)
@@ -310,16 +313,16 @@ class printgeneric extends plugin
 
     /* Do we represent a valid printer? */
     if (!$this->is_account && $this->parent === NULL){
-      $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
-        _("This 'dn' has no printer features.")."</b>";
+      $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
+        msgPool::noValidExtension(_("printer"))."</b>";
       return($display);
     }
 
     /* If this is a WS / Terminal depending printer, display account state button */
     if(!preg_match("/^Printer$/i",$this->BelongsTo)){
-      if((empty($this->cn)) && ($this->dn != "new")){
+      if($this->cn == "" && ($this->dn != "new")){
         $display= $this->show_enable_header(_("Add printer extension"),
-            _("This object has printer extension disabled. You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template"),TRUE,TRUE);
+            msgPool::featuresDisabled(_("printer"))._("You can't enable it while 'cn' is not present in entry. Possibly you are currently creating a new terminal template."),TRUE,TRUE);
         $this->is_account= false;
         return $display;
       }
@@ -327,18 +330,18 @@ class printgeneric extends plugin
       if (($this->is_account)){
         if(preg_match("/^Workstation$/i",$this->BelongsTo)){
           $display= $this->show_disable_header(_("Remove printer extension"),
-              _("This workstation has printer extension enabled.You can disable it by clicking below."));
+              msgPool::featuresEnabled(_("printer")));
         }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){
           $display= $this->show_disable_header(_("Remove printer extension"),
-              _("This terminal has printer extension enabled. You can disable it by clicking below."));
+              msgPool::featuresDisabled(_("printer")));
         }
       }else{
         if(preg_match("/^Workstation$/i",$this->BelongsTo)){
           $display= $this->show_disable_header(_("Add printer extension"),
-              _("This workstation has printer extension disabled. You can enable it by clicking below."));
+              msgPool::featuresEnabled(_("printer")));
         }elseif(preg_match("/^Terminal$/i",$this->BelongsTo)){
           $display= $this->show_enable_header(_("Add printer extension"),
-              _("This terminal has printer extension disabled. You can enable it by clicking below."));
+              msgPool::featuresDisabled(_("printer")));
         }  
         return ($display);
       }
@@ -429,7 +432,7 @@ class printgeneric extends plugin
       $this->dialog->save_object();
       if(count($this->dialog->check())){
         foreach($this->dialog->check() as $msg){
-          print_red($msg);
+          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
         }
       }else{
         $this->gotoPrinterPPD = array();
@@ -476,7 +479,7 @@ class printgeneric extends plugin
       $this->dialog->save_object();
       if(count($this->dialog->check())){
         foreach($this->dialog->check() as $msg){
-          print_red($msg);
+          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
         }
       }else{
         $data= $new = $this->dialog->save();
@@ -498,9 +501,8 @@ class printgeneric extends plugin
 
     /* Parse selected ppd file */
     $config = session::get('config');
-    if((isset($config->data['MAIN']['PPD_PATH']))&&(is_dir($config->data['MAIN']['PPD_PATH']))){
-
-      $path = $config->data['MAIN']['PPD_PATH'];
+    if ($config->get_cfg_value("ppdPath") != ""){
+      $path = $config->get_cfg_value("ppdPath");
       if(!preg_match("/\/$/",$path)){
         $path = $path."/";
       }
@@ -529,9 +531,9 @@ class printgeneric extends plugin
 
     if(!preg_match("/Printer/i",$this->BelongsTo)){
       if(preg_match("/Terminal/i",$this->BelongsTo)){
-        $smarty->assign("desc"    ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
+        $smarty->assign("desc"    ,sprintf(_("This printer belongs to %s. You can't rename this printer."),_("terminal"),"<b>".$this->cn."</b>"));
       }else{
-        $smarty->assign("desc"    ,sprintf(_("This printer belongs to workstation %s. You can't rename this printer."),"<b>".$this->cn."</b>"));
+        $smarty->assign("desc"    ,sprintf(_("This printer belongs to %s. You can't rename this printer."),_("workstation"),"<b>".$this->cn."</b>"));
       }
       $smarty->assign("cnACL"    , $this->getacl("cn",true));
     }else{
@@ -578,14 +580,14 @@ class printgeneric extends plugin
       $ldap= $this->config->get_ldap_link();
       $ldap->cat($this->dn, array('dn',"objectClass"));
       if(!$ldap->count()){
-        print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
+        msg_dialog::display(_("Error"), _("Object is no printer!"), ERROR_DIALOG);
         return;
       }
 
       /* Check if obejct is a printer */
       $CheckPrinter = $ldap->fetch();
       if(!in_array("gotoPrinter",$CheckPrinter['objectClass'])){
-        print_red("Trying to remove printer object which isn't a printer. Aborted to avoid data loss.");
+        msg_dialog::display(_("Error"), _("Object is no printer!"), ERROR_DIALOG);
         return;
       }
 
@@ -664,18 +666,18 @@ class printgeneric extends plugin
     $dn= "cn=".$this->cn.get_ou('printerou').",".$this->base;
 
     /* must: cn */
-    if(($this->BelongsTo == "Printer") && (empty($this->cn))){
-      $message[]= _("The required field 'Printer name' is not set.");
+    if(($this->BelongsTo == "Printer") && $this->cn == ""){
+      $message[]= msgPool::required(_("Name"));
     }
 
     /* must: cn */
     if(($this->BelongsTo == "Printer") && !tests::is_dns_name($this->cn)){
-      $message[]= _("Invalid character in printer name.");
+      $message[]= msgPool::invalid(_("Name"));
     }
 
     /* must: labeledURI */
     if(empty($this->labeledURI)){
-      $message[]= "The required field 'Printer URL' is not set.";
+      $message[]= msgPool::required(_("Printer URL"));
     }
     
     /* Check if there is already an entry with this cn*/
@@ -689,13 +691,21 @@ class printgeneric extends plugin
             continue;
           }
           if ($attrs['dn'] != $this->orig_dn){
-            $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
+            $message[]= msgPool::duplicated(_("Name"));
             break;
           }
         }
       }
     }
 
+    /* Check if we are allowed to create or move this object
+     */
+    if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+      $message[] = msgPool::permCreate();
+    }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+      $message[] = msgPool::permMove();
+    }
+
     return ($message);
   }
 
@@ -718,10 +728,19 @@ class printgeneric extends plugin
       if($this->parent->by_object['workgeneric']->cn == "wdefault"){
         return;
       }
+
+      /* Adapt IP & mac from parent object */
+      $this->netConfigDNS->ipHostNumber = $this->parent->by_object['workgeneric']->netConfigDNS->ipHostNumber;
+      $this->netConfigDNS->macAddress = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
+
     }elseif(isset($this->parent->by_object['termgeneric'])){
       if($this->parent->by_object['termgeneric']->cn == "default"){
         return;
       }
+    
+      /* Adapt IP & mac from parent object */
+      $this->netConfigDNS->ipHostNumber = $this->parent->by_object['termgeneric']->netConfigDNS->ipHostNumber;
+      $this->netConfigDNS->macAddress = $this->parent->by_object['termgeneric']->netConfigDNS->macAddress;
     }
 
     /* If type is still unknown, the initialisation of this printer failed, abort. */
@@ -755,21 +774,30 @@ class printgeneric extends plugin
     }else{
       $method="http://";
     }
+   
+    /* Get servername */
+    $server = $_SERVER['SERVER_NAME'];
+    if(tests::is_ip($server)){  
+      $server_name = gethostbyaddr($server);
+    }else{
+      $server_name = gethostbyaddr(gethostbyname($server));
+    }
 
     /* If no ppd is selected, remove this attribute */
     if(!empty($this->gotoPrinterPPD) && $this->initially_was_account) {
-      $this->gotoPrinterPPD = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->gotoPrinterPPD);
+      $this->gotoPrinterPPD = $method.str_replace("//","/",$server_name."/ppd/".$this->gotoPrinterPPD);
     }else{
       $this->gotoPrinterPPD = array();
     }
 
     $dn= $this->dn;
-    plugin::save();
-    $ldap= $this->config->get_ldap_link();
 
     /* reduce objectClasses to minimun */
     $this->attrs['objectClass']= $this->objectclasses;
 
+    plugin::save();
+    $ldap= $this->config->get_ldap_link();
+
     /* Remove all empty values */
     if ($this->orig_dn == 'new'){
       $attrs= array();
@@ -857,11 +885,11 @@ class printgeneric extends plugin
       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
     }
 
-    if(preg_match("/printer/i",$this->BelongsTo)){
+    #if(preg_match("/printer/i",$this->BelongsTo)){
       $this->netConfigDNS->cn = $this->cn;
       $this->netConfigDNS->dn = $this->dn;
       $this->netConfigDNS->save();
-    }
+    #}
   }
 
   function generateList(){
@@ -920,7 +948,7 @@ class printgeneric extends plugin
     }
   
     if(!$this->acl_is_writeable("gotoUserPrinter")){
-      print_red(sprintf(_("You are not allowed to remove the given object '%s' from the list of members of printer '%s'."),$id,$this->dn));
+      msg_dialog::display(_("Permission error"), msgPool::permDelete(_("printer user"), $id), INFO_DIALOG);
       return(FALSE);
     }
  
@@ -937,12 +965,12 @@ class printgeneric extends plugin
   {
     $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));
+      msg_dialog::display(_("Internal error"), sprintf(_("Illegal member type '%s'!"), $type), ERROR_DIALOG);
       return(FALSE);
     }
 
     if(!$this->acl_is_writeable("gotoUserPrinter")){
-      print_red(sprintf(_("You are not allowed to add the given object '%s' to the list of members of '%s'."),$dn,$this->dn));
+      msg_dialog::display(_("Permission error"), msgPool::permModify(_("printer user"), $this->dn), INFO_DIALOG);
       return(FALSE);
     }
 
@@ -977,7 +1005,7 @@ class printgeneric extends plugin
           }
 
           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]));
+            msg_dialog::display(_("Error"), sprintf(_("'%s' is already used!"), $attrs[$var][0]), ERROR_DIALOG);
             return(FALSE);
           }
         }
@@ -988,7 +1016,7 @@ class printgeneric extends plugin
         print_a($attrs);
       }
     }else{
-      print_red(sprintf(_("Can't add '%s' to list of members, it is not reachable."),$dn));
+      msg_dialog::display(_("Error"), sprintf(_("'%s' does not exist!"), $dn), ERROR_DIALOG);
       return(FALSE);
     }
     return(TRUE);