Code

Added magic_quotes fix for Profile
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
index a9a2bdbebc6735f9e49cd822e6e77d9317608f32..dea5899fdd2f1881f367cf2c323c6eaa12630a83 100644 (file)
@@ -3,13 +3,13 @@
 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");
+  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;
+  var $interfaces     = array();
+  var $ignore_account = FALSE;
 
   /* Needed values and lists */
   var $base             = "";
@@ -26,20 +26,20 @@ class printgeneric extends plugin
   var $UserMember       ="";
   var $UserMembers      =array();
   var $UserMemberKeys   =array();
-
+  
   var $AdminMember      ="";
   var $AdminMembers     =array();
   var $AdminMemberKeys  =array();
 
+  var $is_terminalBased = false; 
   var $member           =array();
-  
   var $strings          = "";
-
   var $type             = "";
   var $dialog           =NULL;
 
   /* attribute list for save action */
-  var $attributes     = array("cn", "description", "l", "labeledURI", "gotoPrinterPPD","macAddress", "ipHostNumber");
+  var $attributes     = array("cn", "description", "l", "labeledURI", "macAddress", "ipHostNumber","gotoPrinterPPD");
   var $objectclasses  = array("top", "gotoPrinter");
 
   function printgeneric ($config, $dn= NULL)
@@ -52,18 +52,21 @@ class printgeneric extends plugin
       $ui= get_userinfo();
       $this->base= dn2base($ui->dn);
       $this->cn= "";
+      $this->is_terminal = true;
     } else {
       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
     }
 
 
     /* In case of gotoWorkstation this tab is calles from workstation plugin
+     * in case of gotoTerminal it is called from a terminal tab
+     * else it is a standalone printer
      */
-    if((in_array("gotoWorkstation",$this->attrs['objectClass']))){
+    if((isset($this->attrs['objectClass']))&&(in_array("gotoWorkstation",$this->attrs['objectClass']))){
       $this->is_terminal = "true";   
       $this->dn   = preg_replace("/ou=workstation/","ou=printer",$this->dn);
       $this->type = "station";
-    }elseif((in_array("gotoTerminal",$this->attrs['objectClass']))){
+    }elseif((isset($this->attrs['objectClass']))&&(in_array("gotoTerminal",$this->attrs['objectClass']))){
       $this->type = "terminal";
       $this->is_terminal = "true";
       $this->dn   = preg_replace("/ou=terminal/","ou=printer",$this->dn);
@@ -72,6 +75,8 @@ class printgeneric extends plugin
       $this->orig_dn= $this->dn;
     }
 
+    /* If it is no standalone printer 
+     */
     if($this->is_terminal){
       // Reload plugin with new dn... (ou=printers instead of ou=terminals)
       plugin::plugin ($this->config, $this->dn);
@@ -118,10 +123,23 @@ class printgeneric extends plugin
         }
       }
     }
+  
+    $ldap->search("(&(cn=".$this->cn.")(|(objectClass=gotoTerminal)(objectClass=gotoWorkstation)))",array("cn","objectClass"));
+    if($attrs = $ldap->fetch()){
+      if(in_array("gotoTerminal",$attrs['objectClass'])){
+        $this->is_terminalBased = "Terminal";
+      }else{
+        $this->is_terminalBased = "Workstation";
+      }
+    }
+
+
+
   }
 
   function execute()
   {
+
     $smarty= get_smarty();
     $display="";
     /* Template management.
@@ -145,23 +163,37 @@ class printgeneric extends plugin
     }
 
     if($this->is_terminal){
-      if ($this->is_account){
-        if($this->type=="station"){
-          $display= $this->show_header(_("Remove printer extension"),
-              _("This workstation has printer extension enabled. You can disable it by clicking below."));
+      if(empty($this->cn)){
+        if(!in_array("gotoPrinter",$this->objectclasses)){
+          $display= $this->show_header(_("Add printer extension"),
+              _("This workstation 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);
+          $this->is_account= false;
+          return $display;
         }else{
-          $display= $this->show_header(_("Remove printer extension"),
-              _("This terminal has printer extension enabled. You can disable it by clicking below."));
+          $smarty->assign("is_terminal","false");
+          $skip = true;
         }
-      }else{
-        if($this->type=="station"){
-          $display= $this->show_header(_("Add printer extension"),
-              _("This workstation has printer extension disabled. You can enable it by clicking below."));
+      }
+
+      if(!isset($skip)){
+        if (($this->is_account)){
+          if($this->type=="station"){
+            $display= $this->show_header(_("Remove printer extension"),
+                _("This workstation has printer extension enabled.You can disable it by clicking below."));
+          }else{
+            $display= $this->show_header(_("Remove printer extension"),
+                _("This terminal has printer extension enabled. You can disable it by clicking below."));
+          }
         }else{
-          $display= $this->show_header(_("Add printer extension"),
-              _("This terminal has printer extension disabled. You can enable it by clicking below."));
-        }  
-        return ($display);
+          if($this->type=="station"){
+            $display= $this->show_header(_("Add printer extension"),
+                _("This workstation has printer extension disabled. You can enable it by clicking below."));
+          }else{
+            $display= $this->show_header(_("Add printer extension"),
+                _("This terminal has printer extension disabled. You can enable it by clicking below."));
+          }  
+          return ($display);
+        }
       }
     }
 
@@ -182,7 +214,7 @@ class printgeneric extends plugin
       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
       $smarty->assign("$attr", $this->$attr);
     }
-    
+
     if(isset($_POST['AddUser'])){
       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddUser");
     }
@@ -196,11 +228,34 @@ class printgeneric extends plugin
       $this->dialog = new selectUserToPrinterDialog($this->config, get_userinfo(),"AddAdminGroup");
     }
 
+    if(isset($_POST['EditDriver'])){
+      $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+    }
+
     if(isset($_POST['PrinterCancel'])){
       unset($this->dialog);
       $this->dialog= NULL;
     }
 
+    if(isset($_POST['SavePPD'])){
+      if(count($this->dialog->check())){
+        foreach($this->dialog->check() as $msg){
+          print_red($msg);
+        }
+      }else{
+        $this->gotoPrinterPPD = array();
+        $this->gotoPrinterPPD = $this->dialog->save();
+        unset($this->dialog);
+        $this->dialog=NULL;
+      }
+
+    }
+
+    if(isset($_POST['ClosePPD'])){
+      unset($this->dialog);
+      $this->dialog=NULL;
+    }
+
     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
       if(isset($this->member['AddUser'][$_POST['UserMember']])){
         unset($this->member['AddUser'][$_POST['UserMember']]);
@@ -257,12 +312,32 @@ class printgeneric extends plugin
 
     /* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
     $smarty->assign("staticAddress", "");
-    $smarty->assign("driverInfo", "Not implemented yet");
+
+
+    require_once ("class_ppdManager.inc");
+    $ppdManager= new ppdManager('/var/spool/ppd/');
+    if(!empty($this->gotoPrinterPPD)){
+      $smarty->assign("driverInfo", $ppdManager->loadDescription($this->gotoPrinterPPD));
+    }else{
+      $smarty->assign("driverInfo", _("Undefined"));
+    }
 
     $list=$this->generateList();
     $userlist   = array_merge($list['AddUser'],$list['AddGroup']);
     $adminlist  = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
 
+    asort($userlist);
+    asort($adminlist);
+    if($this->is_terminalBased){
+      if($this->is_terminalBased == "Terminal"){
+        $smarty->assign("desc"    ,sprintf(_("This printer belongs to terminal %s. You can't rename this printer."),"<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("cnACL"    ," disabled ");
+    }else{
+      $smarty->assign("desc"    ,"");
+    }
     $smarty->assign("UserMember"    ,$this->UserMember);
     $smarty->assign("UserMembers"   ,$userlist);
     $smarty->assign("UserMemberKeys",array_flip($userlist));
@@ -272,7 +347,6 @@ class printgeneric extends plugin
     $smarty->assign("AdminMemberKeys",array_flip($adminlist));
     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
 
-
     return($display.$smarty->fetch (get_template_path('printer.tpl', TRUE)));
   }
 
@@ -345,17 +419,16 @@ class printgeneric extends plugin
   {
     $dn= $this->dn;
     plugin::save();
+    $ldap= $this->config->get_ldap_link();
    
     if((in_array("gotoTerminal",$this->attrs['objectClass']))){
       $this->dn= preg_replace("/ou=terminal/","ou=printer",$this->dn);
     }
+    
     if((in_array("gotoWorkstation",$this->attrs['objectClass']))){
       $this->dn= preg_replace("/ou=workstation/","ou=printer",$this->dn);
     }
 
-    $ldap= $this->config->get_ldap_link();
     /* We are currently editing a Terminal, so we want to save a seperate printer which cn is the terminla cn 
     */
     if($this->is_terminal){
@@ -450,8 +523,6 @@ class printgeneric extends plugin
     }
     return($a_return);
   }
-
-
 }