Code

Updated terminal copy & paste
[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();
13   var $objectclasses        = array("whatever");
15   var $list                 =array();
16   var $header               =array();
17   var $current_del_id       = "";
18   var $Vendor               = "";
20   function printerPPDSelectionDialog ($config, $dn= NULL,$list=false,$headers=false,$ppd=false)
21   {
22     plugin::plugin ($config, $dn);
23     $this->list       = $list;
24     $this->header     = $headers;
25     $this->depselect  = $this->config->current['BASE'];
26     
27     if(!isset($_SESSION['printerPPDSelectionDialog'])){
28       $_SESSION['printerPPDSelectionDialog']['regex'] = "*";
29     }  
31     /* Order the manufacturers index */
32     ksort($this->header);
33   }
35   function execute()
36   {
37         /* Call parent execute */
38         plugin::execute();
40     /* Fill templating stuff */
41     $smarty= get_smarty();
42     $display= "";
43     $s_action = "none";
44   
45     $regex = $_SESSION['printerPPDSelectionDialog']['regex'];
47     if(isset($_GET['search'])){
48       $regex = $_GET['search']."*";
49     }
50   
51     if(isset($_POST['regex'])){
52       $regex= $_POST['regex'];
53     }
54     
55     $regex = str_replace("**","*",$regex);
56     $_SESSION['printerPPDSelectionDialog']['regex'] = $regex;
57  
59     /* Delete requested, check if everything is ok and display confirmation dialog */
60     if(isset($_GET['act']) && $_GET['act'] == "del"){
62       /* Get id and check if id is valid */
63       $id_to_del = base64_decode($_GET['id']);
64       $found = "";
65       foreach($this->list[$this->Vendor] as $key => $data){
66         if($data['link'] == $id_to_del){
67           $found = $key;
68           break;
69         }
70       }
71       if(!empty($found)){
72         $this->current_del_id = $id_to_del;
74         $smarty->assign("warning", sprintf(_("You're about to delete the ppd file '%s' at '%s'."), $found,$id_to_del));
75         return($smarty->fetch(get_template_path('remove_ppd.tpl', TRUE)));
77       }else{
78         print_red(sprintf(_("Could not found specified ppd file '%s'."),$id_to_del));
79       }
80     }
82     /* Deletion confirmed */
83     if(isset($_POST['delete_ppd_confirm']) && !empty($this->current_del_id)){
85       /* check if file is removeable */
86       if(is_writeable($this->current_del_id)){
87         $is_ok = @unlink($this->current_del_id);
89         /* Update ppd list */
90         if($is_ok){
91           foreach($this->list as $vendor => $ppds){
92             foreach($ppds as $ppd => $data){
93               if($data['link'] == $this->current_del_id){
94                 unset($this->list[$vendor][$ppd]);
95               }
96             }
97           }
98         }
99       }else{
100         $is_ok = false;
101       }
103       if(!$is_ok){
104         print_red(_("Something went wrong while trying to remove the ppd file from server, possibly we have no write access."));
105       }
106     }
109     /** Added **/
110     $list = array();
111     foreach($this->list as $cat => $ppds){
112       foreach($ppds as $ppd){
113         if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
114           if(is_readable($ppd['link'])){
115             $list[$ppd['link']] = $ppd;
116           }
117         }
118       }
119     }
120  
121     if((isset($_GET['act']))&&($_GET['act']=="open"))  {
122       
123       if((!empty($_GET['id'])) && (!isset( $this->header[base64_decode($_GET['id'])]))){
124         print_red(sprintf(_("Selected vendor '%s' does not exists in our list of ppds."),base64_decode($_GET['id'])));      
125         $this->Vendor = ""; 
126       }else{
127         $this->Vendor = base64_decode($_GET['id']);
128       }
129     }
131     $div = new divSelectBox("printerPPDSelectionDialog");
132     $div ->SetHeight(450);
133     $div ->SetSummary(_("Printer ppd selection."));
134     
135     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=open&amp;id=%s'>%s</a>";
136     $uselink  = "<a href='?plug=".$_GET['plug']."&amp;act=use&amp;id=%s'>%s</a>";
137     $dellink  = "<a href='?plug=".$_GET['plug']."&amp;act=del&amp;id=%s'><img src='images/edittrash.png' alt='"._("delete")."' border=0></a>"; 
139     if(empty($this->Vendor)){
140       foreach($this-> header as $key => $entry){
141         $div ->AddEntry (array(
142               array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'")
143               ));
144       }
145     }else{
146       $div ->AddEntry (array(
147             array("string"=>sprintf($linkopen,"",".. ["._("back")."]"),"attach"=>"style='border-right:0px;'")
148             ));
149       foreach($list as $key => $ppd){
150         if(preg_match("/^".$this->Vendor."/",$ppd['ppd'])){
152           if(is_writeable($ppd['link'])){
153             $del_str = sprintf($dellink,base64_encode($key));
154           }else{
155             $del_str = "";
156           }
158           $div ->AddEntry (array(
159                                   array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd'])),
160                                   array("string"=>$del_str,"attach"=>"style='border-right:0px;'")
162                 ));
163         }
164       }
165     }
167     $smarty->assign("List",         $div -> DrawList());
168     $smarty->assign("search_image", get_template_path('images/search.png'));
169     $smarty->assign("launchimage",  get_template_path('images/small_filter.png'));
170     $smarty->assign("tree_image",   get_template_path('images/tree.png'));
171     $smarty->assign("alphabet",     generate_alphabet());
172     $smarty->assign("apply",        apply_filter());
173     $smarty->assign("regex",        $regex);
174   
175     $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__)));
176     return($display);
177   }
179   function save_object()
180   {
181   } 
183   function check(){
184   }
186   /* Save to LDAP */
187   function save()
188   {
189     return $this->selectedPPD;
190   }
192 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
193 ?>