Code

Added some functionalty
[gosa.git] / plugins / admin / systems / class_printerPPDDialog.inc
1 <?php
3 class printerPPDDialog extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary          = "Manage server basic objects";
7   var $cli_description      = "Some longer text\nfor help";
8   var $cli_parameters       = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account       = TRUE;
12   var $attributes           = array();
13   var $objectclasses        = array("whatever");
15   var $ppdList              = array();
16   var $ppdListHeader        = array();
18   var $dialog               = NULL;   
19   var $selectedPPD          = false;
21   var $ppdManager     = false;
22   function printerPPDDialog ($config, $dn= NULL,$ppdfile=NULL )
23   {
24     plugin::plugin ($config, $dn);
25     $this->depselect = $this->config->current['BASE'];
27     /* Load all available PPD files and sort them into an array 
28      */
29     require_once ("class_ppdManager.inc");
30     $this->ppdManager= new ppdManager('/var/spool/ppd/');
31     $tmp = $this->ppdManager->getPrinterList();
33     /* Sort all available files, and create header (Vendor index) */
34     foreach($tmp as $file=>$ppd){
35       $tmp2 = split("\n",$ppd);
36       if(!isset($this->ppdListHeader[$tmp2[0]])){
37         $this->ppdListHeader[$tmp2[0]]=0;
38       }
39       $tmp3['name']   =preg_replace("/^ -/","",$tmp2[1]);
40       $tmp3['link']   =$file;
41       $tmp3['ppd']    =$ppd;
42   
43       $this->ppdListHeader[$tmp2[0]]++;
44       
45       $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1])]=$tmp3;
46     }
48    /* The user has already a valid PPD assigned
49     * Get some informations about this PPD
50     */
51    if(($ppdfile!= NULL)&&(strlen($ppdfile)>0)){
52       $tmp2= split("\n", $this->ppdManager->loadDescription($ppdfile));
53       $tmp3['name']   =preg_replace("/^ -/","",$tmp2[1]);
54       $tmp3['link']   =$ppdfile;
55       $tmp3['ppd']    =$this->ppdManager->loadDescription($ppdfile);
56       $this->selectedPPD = $tmp3;
57    }
59  
60   }
62   function execute()
63   {
64     /* Fill templating stuff */
65     $smarty= get_smarty();
66     $display= "";
69     /* Open a dialog that allow us to select different PPDs
70      */
71     if(isset($_POST['SelectPPD'])){
72       $this->dialog= new printerPPDSelectionDialog($this->config,$this->dn,$this->ppdList,$this->ppdListHeader,$this->selectedPPD);
73     }
75     /* The selection dialog fpr PPDs is canceled
76      */
77     if(isset($_POST['ClosePPDSelection'])){
78       unset($this->dialog);
79       $this->dialog=NULL;
80     }
81   
82     /* A new PPDs was selected in the PPDs selection Dialog
83      * Perform a Check. If everything is fine, use the new PPD.
84      */
85     if(isset($_POST['SavePPDSelection'])){
86       if(count($this->dialog->check())>0){
87         foreach($this->dialog->check() as $msg){
88           print_red($msg);
89         }
90       }else{
91         $this->selectedPPD = $this->dialog->save();
92         unset($this->dialog);
93         $this->dialog=NULL;
94       }
95     }
96   
97     /* if a dialog is open, print the dialog instead of this class
98      */
99     if($this->dialog!=NULL){
100       $display = $this->dialog->execute();
101       return($display);
102     }
104     /* Give smarty the information it needs */
105     $smarty->assign("ppdString" ,$this->getPPDInformation());
106     $smarty->assign("properties",$this->generateProperties());
107   
108     /* Print out template */
109     $display.= $smarty->fetch(get_template_path('printerPPDDialog.tpl', TRUE,dirname(__FILE__)));
110     return($display);
111   }
113   function check(){
114     /* Check the given data
115      */
116     $message=array();
117     return $message;
118   }
120   /* Save to LDAP */
121   function save()
122   {
123     /* return the selected PPD, and in future the selected options too */
124     return($this->selectedPPD['link']);
125   }
127   function getPPDInformation()
128   {
129     /* Get Information for a single PPD entry 
130      * This will be shown on top of template
131      */
132     $str = "none";
133     if(!empty($this->selectedPPD)){
134       $str = $this->selectedPPD['link'];
135       $str = $this->ppdManager->loadDescription($this->selectedPPD['link']);
136     }
137     return($str) ; 
138   }
140   function generateProperties()
141   { 
142     /* In future there will be a schema parser that provide us all settings that can be made in the selected PPD file. 
143      * This function will generate a userfriendly post based form with this informations
144      */
145     return("<table><tr><td>adfasdf</td></tr></table/table>");
146   }
148 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
149 ?>