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'];
27 if(!session::is_set('printerPPDSelectionDialog')){
28 session::set("printerPPDSelectionDialog",array('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";
45 $printerPPDSelectionDialog = session::get('printerPPDSelectionDialog');
46 $regex = $printerPPDSelectionDialog['regex'];
48 if(isset($_GET['search'])){
49 $regex = $_GET['search']."*";
50 }
52 if(isset($_POST['regex'])){
53 $regex= $_POST['regex'];
54 }
56 $regex = str_replace("**","*",$regex);
57 $printerPPDSelectionDialog['regex'] = $regex;
58 session::set('printerPPDSelectionDialog',$printerPPDSelectionDialog);
61 /* Delete requested, check if everything is ok and display confirmation dialog */
62 if(isset($_GET['act']) && $_GET['act'] == "del"){
64 /* Get id and check if id is valid */
65 $id_to_del = base64_decode($_GET['id']);
66 $found = "";
67 foreach($this->list[$this->Vendor] as $key => $data){
68 if($data['link'] == $id_to_del){
69 $found = $key;
70 break;
71 }
72 }
73 if(!empty($found)){
74 $this->current_del_id = $id_to_del;
76 $smarty->assign("warning", sprintf(_("You're about to delete the ppd file '%s' at '%s'."), $found,$id_to_del));
77 return($smarty->fetch(get_template_path('remove_ppd.tpl', TRUE)));
79 }else{
80 print_red(sprintf(_("Could not found specified ppd file '%s'."),$id_to_del));
81 }
82 }
84 /* Deletion confirmed */
85 if(isset($_POST['delete_ppd_confirm']) && !empty($this->current_del_id)){
87 /* check if file is removeable */
88 if(is_writeable($this->current_del_id)){
89 $is_ok = @unlink($this->current_del_id);
91 /* Update ppd list */
92 if($is_ok){
93 foreach($this->list as $vendor => $ppds){
94 foreach($ppds as $ppd => $data){
95 if($data['link'] == $this->current_del_id){
96 unset($this->list[$vendor][$ppd]);
97 }
98 }
99 }
100 }
101 }else{
102 $is_ok = false;
103 }
105 if(!$is_ok){
106 print_red(_("Something went wrong while trying to remove the ppd file from server, possibly we have no write access."));
107 }
108 }
111 /** Added **/
112 $list = array();
113 foreach($this->list as $cat => $ppds){
114 foreach($ppds as $ppd){
115 if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
116 if(is_readable($ppd['link'])){
117 $list[$ppd['link']] = $ppd;
118 }
119 }
120 }
121 }
123 if((isset($_GET['act']))&&($_GET['act']=="open")) {
125 if((!empty($_GET['id'])) && (!isset( $this->header[base64_decode($_GET['id'])]))){
126 print_red(sprintf(_("Selected vendor '%s' does not exists in our list of ppds."),base64_decode($_GET['id'])));
127 $this->Vendor = "";
128 }else{
129 $this->Vendor = base64_decode($_GET['id']);
130 }
131 }
133 $div = new divSelectBox("printerPPDSelectionDialog");
134 $div ->SetHeight(450);
135 $div ->SetSummary(_("Printer ppd selection."));
137 $linkopen = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>
138 <img src='images/folder.png' class='center' border=0> %s
139 </a>";
140 $uselink = "<a href='?plug=".$_GET['plug']."&act=use&id=%s'>%s</a>";
141 $dellink = "<a href='?plug=".$_GET['plug']."&act=del&id=%s'>
142 <img src='images/edittrash.png' alt='"._("delete")."' border=0>
143 </a>";
145 if(empty($this->Vendor)){
146 foreach($this-> header as $key => $entry){
147 $div ->AddEntry (array(
148 array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'")
149 ));
150 }
151 }else{
152 $div ->AddEntry (array(
153 array("string"=>sprintf($linkopen,"",".. ["._("back")."]"),"attach"=>"style='border-right:0px;'")
154 ));
155 foreach($list as $key => $ppd){
156 if(preg_match("/^".$this->Vendor."/",$ppd['ppd'])){
158 if(is_writeable($ppd['link'])){
159 $del_str = sprintf($dellink,base64_encode($key));
160 }else{
161 $del_str = "";
162 }
164 $div ->AddEntry (array(
165 array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd'])),
166 array("string"=>$del_str,"attach"=>"style='border-right:0px;'")
168 ));
169 }
170 }
171 }
173 $smarty->assign("List", $div -> DrawList());
174 $smarty->assign("search_image", get_template_path('images/search.png'));
175 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
176 $smarty->assign("tree_image", get_template_path('images/tree.png'));
177 $smarty->assign("alphabet", generate_alphabet());
178 $smarty->assign("apply", apply_filter());
179 $smarty->assign("regex", $regex);
181 $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__)));
182 return($display);
183 }
185 function save_object()
186 {
187 }
189 function check(){
190 }
192 /* Save to LDAP */
193 function save()
194 {
195 return $this->selectedPPD;
196 }
197 }
198 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
199 ?>