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