Code

Some changes repository plugin
[gosa.git] / plugins / admin / systems / class_printGeneric.inc
index 36c3588ccdbfbe06bf728e2554fabc6f8aff117a..a8843d920550ae492647e4e60614122cd63d7649 100644 (file)
@@ -32,6 +32,8 @@ class printgeneric extends plugin
   var $AdminMemberKeys  =array();
 
   var $is_terminalBased = false; 
+
+  var $PPDdialogToSave  = NULL;
  
   var $member           =array();
   var $strings          = "";
@@ -57,19 +59,35 @@ class printgeneric extends plugin
       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
     }
 
+    if(isset($this->gotoPrinterPPD)){
+      $this->gotoPrinterPPD = preg_replace("/^http.*ppd\//i","",$this->gotoPrinterPPD);
+    }
 
     /* 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((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";
+      /* Fix for new Workstations */
+      if(preg_match("/ou=incoming/",$this->dn)){    
+        $this->is_terminal = "true";   
+        $this->dn   = preg_replace("/ou=incoming/","ou=printers",$this->dn);
+        $this->type = "station";
+      }else{
+        $this->is_terminal = "true";   
+        $this->dn   = preg_replace("/ou=workstations/","ou=printers",$this->dn);
+        $this->type = "station";
+      }
     }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);
+      if(preg_match("/ou=incoming/",$this->dn)){    
+        $this->is_terminal = "true";   
+        $this->dn   = preg_replace("/ou=incoming/","ou=printers",$this->dn);
+        $this->type = "terminal";
+      }else{
+        $this->type = "terminal";
+        $this->is_terminal = "true";
+        $this->dn   = preg_replace("/ou=terminal/","ou=printers",$this->dn);
+      }
     }else{
       /* Save dn for later references */
       $this->orig_dn= $this->dn;
@@ -92,7 +110,6 @@ class printgeneric extends plugin
       }
     }
 
-   
     /* Prepare different member types 
      */ 
     foreach(array("AddUser"       =>"gotoUserPrinter",
@@ -103,7 +120,9 @@ class printgeneric extends plugin
       /* $this->members contains all members */
       $this->member[$type]=array();
 
-      unset($this->attrs[$attr]['count']);
+      if (isset($this->attrs[$attr]['count'])) {
+        unset($this->attrs[$attr]['count']);
+      }
 
       if(isset($this->attrs[$attr])){
         foreach($this->attrs[$attr] as $mem){
@@ -133,12 +152,19 @@ class printgeneric extends plugin
       }
     }
 
-
-
+    /* 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.
+     */
+    if($this->dn == "new"){
+      $this->is_account = true;
+    }
   }
 
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
 
     $smarty= get_smarty();
     $display="";
@@ -229,22 +255,34 @@ class printgeneric extends plugin
     }
 
     if(isset($_POST['EditDriver'])){
-      $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+      if($this->PPDdialogToSave){
+        $this->dialog = $this->PPDdialogToSave;
+      }else{
+        $this->dialog = new printerPPDDialog($this->config, $this->dn,$this->gotoPrinterPPD);
+      }
     }
 
     if(isset($_POST['PrinterCancel'])){
       unset($this->dialog);
       $this->dialog= NULL;
     }
+    
+    if(isset($_POST['RemoveDriver'])){
+      $this->gotoPrinterPPD = array();
+      $this->PPDdialogToSave = NULL;
+    }
 
     if(isset($_POST['SavePPD'])){
+      $this->dialog->save_object();
       if(count($this->dialog->check())){
         foreach($this->dialog->check() as $msg){
           print_red($msg);
         }
       }else{
         $this->gotoPrinterPPD = array();
+        
         $this->gotoPrinterPPD = $this->dialog->save();
+        $this->PPDdialogToSave = $this->dialog;
         unset($this->dialog);
         $this->dialog=NULL;
       }
@@ -256,6 +294,8 @@ class printgeneric extends plugin
       $this->dialog=NULL;
     }
 
+  
+
     if((isset($_POST['DelUser']))&&(isset($_POST['UserMember']))){
       if(isset($this->member['AddUser'][$_POST['UserMember']])){
         unset($this->member['AddUser'][$_POST['UserMember']]);
@@ -275,7 +315,7 @@ class printgeneric extends plugin
     }
 
     if((isset($_POST['DelAdmin']))&&(isset($_POST['AdminMember']))){
-      if(isset($this->member['AddAdmingroup'][$_POST['AdminMember']])){
+      if(isset($this->member['AddAdminGroup'][$_POST['AdminMember']])){
         unset($this->member['AddAdminGroup'][$_POST['AdminMember']]);
       }
     }
@@ -306,6 +346,7 @@ class printgeneric extends plugin
     }
 
     if($this->dialog != NULL){
+      $this->dialog->save_object();
       $display = $this->dialog->execute();
       return $display;
     }
@@ -315,13 +356,23 @@ class printgeneric extends plugin
 
 
     require_once ("class_ppdManager.inc");
-    $ppdManager= new ppdManager('/var/spool/ppd/');
-    if(!empty($this->gotoPrinterPPD)){
-      $smarty->assign("driverInfo", $ppdManager->loadDescription($this->gotoPrinterPPD));
+
+    if((isset($_SESSION['config']->data['MAIN']['PPD_PATH']))&&(is_dir($_SESSION['config']->data['MAIN']['PPD_PATH']))){
+      $ppdManager= new ppdManager($_SESSION['config']->data['MAIN']['PPD_PATH']);
+      if(!empty($this->gotoPrinterPPD)){
+        if((!file_exists($_SESSION['config']->data['MAIN']['PPD_PATH'].$this->gotoPrinterPPD))){
+          $smarty->assign("driverInfo", "<b>".sprintf(_("Your currently selected PPD file '%s' doesn't exist."),$this->gotoPrinterPPD))."</b>";
+        }else{
+          $smarty->assign("driverInfo", $ppdManager->loadDescription($_SESSION['config']->data['MAIN']['PPD_PATH'].$this->gotoPrinterPPD));
+        }
+      }else{
+        $smarty->assign("driverInfo", _("not defined"));
+      }
     }else{
-      $smarty->assign("driverInfo", _("Undefined"));
+      $smarty->assign("driverInfo",_("can't get ppd informations."));
     }
 
+
     $list=$this->generateList();
     $userlist   = array_merge($list['AddUser'],$list['AddGroup']);
     $adminlist  = array_merge($list['AddAdminUser'],$list['AddAdminGroup']);
@@ -336,7 +387,7 @@ class printgeneric extends plugin
       }
       $smarty->assign("cnACL"    ," disabled ");
     }else{
-      $smarty->assign("desc"    ,_(" "));
+      $smarty->assign("desc"    ,"");
     }
     $smarty->assign("UserMember"    ,$this->UserMember);
     $smarty->assign("UserMembers"   ,$userlist);
@@ -352,6 +403,7 @@ class printgeneric extends plugin
 
   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());
@@ -417,16 +469,23 @@ class printgeneric extends plugin
   /* Save to LDAP */
   function save()
   {
+    if (!$this->is_account){
+      return;
+    }
+  
+    if($this->PPDdialogToSave){
+      $this->PPDdialogToSave->save_ppd();
+    }
     $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);
+      $this->dn= preg_replace("/ou=terminals,/","ou=printers,",$this->dn);
     }
     
     if((in_array("gotoWorkstation",$this->attrs['objectClass']))){
-      $this->dn= preg_replace("/ou=workstation/","ou=printer",$this->dn);
+      $this->dn= preg_replace("/ou=workstations,/","ou=printers,",$this->dn);
     }
 
     /* We are currently editing a Terminal, so we want to save a seperate printer which cn is the terminla cn 
@@ -457,6 +516,16 @@ class printgeneric extends plugin
       $this->attrs= $attrs;
     }
 
+    if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
+      $method="https://";
+    }else{
+      $method="http://";
+    }
+  
+    if(!is_array($this->attrs['gotoPrinterPPD'])) {
+      $this->attrs['gotoPrinterPPD'] = $this->attrs['gotoPrinterPPD'];
+      $this->attrs['gotoPrinterPPD'] = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/ppd/".$this->attrs['gotoPrinterPPD']);
+    }
 
     /* Append printer user 
      */