Code

39f38da545491afbec35434b55cb3e1abc6b0f82
[gosa.git] / plugins / admin / systems / class_printerPPDSelectionDialog.inc
1 <?php
3 class printerPPDSelectionDialog 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       = FALSE;
12   var $attributes           = array("currentPos","currentSel");
13   var $objectclasses        = array("whatever");
15   var $list                 =array();
16   var $header               =array();
18   var $currentPos           = "";
19   var $currentSel           = -1;
20   var $selectedPPD          = "";
22   function printerPPDSelectionDialog ($config, $dn= NULL,$list=false,$headers=false,$ppd=false)
23   {
24     plugin::plugin ($config, $dn);
25     $this->list       = $list;
26     $this->header     = $headers;
27     $this->depselect  = $this->config->current['BASE'];
28     
29     /* If there is already a ppd file selected, use this as preselected object in our ppds list
30      */
31     if(isset($ppd)){
32       $tmp2 = split("\n",$ppd['ppd']);
33       if(count($tmp2)==2){
34         $this->currentPos = $tmp2[0];
35         $this->currentSel = preg_replace("/^ -/","",$tmp2[1]);
36       }
37     }
38   
39     if(!isset($_SESSION['printerPPDSelectionDialog'])){
40       $_SESSION['printerPPDSelectionDialog']['regex'] = "*";
41     }  
43     /* Order the manufacturers index */
44     ksort($this->header);
45   }
47   function execute()
48   {
49     /* Fill templating stuff */
50     $smarty= get_smarty();
51     $display= "";
52     $s_action = "none";
53   
54     $regex = $_SESSION['printerPPDSelectionDialog']['regex'];
56     if(isset($_GET['search'])){
57       $regex = $_GET['search']."*";
58     }
59   
60     if(isset($_POST['regex'])){
61       $regex= $_POST['regex'];
62     }
63     
64     $regex = str_replace("**","*",$regex);
65     $_SESSION['printerPPDSelectionDialog']['regex'] = $regex;
66   
68     /* if manufacturer is selected and a ppd file 
69      * Set this selected file to our return value.
70      */ 
71     if(isset($this->list[$this->currentPos][$this->currentSel])){
72       $this->selectedPPD = $this->list[$this->currentPos][$this->currentSel];
73     }
75     /** Added **/
76     $list = array();
77     foreach($this->list as $cat => $ppds){
78       foreach($ppds as $ppd){
79         if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
80           $list[$ppd['link']] = $ppd['ppd'];
81         }
82       }
83     }
85     $smarty->assign("objects",      $list);
86     $smarty->assign("objectKeys",   array_flip($list));
87     $smarty->assign("search_image", get_template_path('images/search.png'));
88     $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
89     $smarty->assign("tree_image",   get_template_path('images/tree.png'));
90     $smarty->assign("alphabet",     generate_alphabet());
91     $smarty->assign("apply",        apply_filter());
92     $smarty->assign("regex",        $regex);
93   
94     $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__)));
95     return($display);
96   }
98   function save_object()
99   {
100   } 
102   function check(){
103   }
105   /* Save to LDAP */
106   function save()
107   {
108     return $this->selectedPPD;
109   }
111 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
112 ?>