Code

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