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'];
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";
40 $printerPPDSelectionDialog = session::get('printerPPDSelectionDialog');
41 $regex = $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 $printerPPDSelectionDialog['regex'] = $regex;
53 session::set('printerPPDSelectionDialog',$printerPPDSelectionDialog);
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(msgPool::deleteInfo($found)));
72 return($smarty->fetch(get_template_path('remove_ppd.tpl', TRUE)));
74 }else{
75 msg_dialog::display(_("PPD error"), msgPool::fileDoesNotExist($id_to_del), ERROR_DIALOG);
76 }
77 }
79 /* Deletion confirmed */
80 if(isset($_POST['delete_ppd_confirm']) && !empty($this->current_del_id)){
82 /* check if file is removeable */
83 $is_ok = false;
84 if(is_writeable($this->current_del_id)){
85 $is_ok = @unlink($this->current_del_id);
87 /* Update ppd list */
88 if($is_ok){
89 foreach($this->list as $vendor => $ppds){
90 foreach($ppds as $ppd => $data){
91 if($data['link'] == $this->current_del_id){
92 unset($this->list[$vendor][$ppd]);
93 }
94 }
95 }
96 }
97 }
99 if(!$is_ok){
100 msg_dialog::display(_("PPD error"), msgPool::cannotDeleteFile($this->current_del_id), ERROR_DIALOG);
101 }
102 }
105 /** Added **/
106 $list = array();
107 foreach($this->list as $cat => $ppds){
108 foreach($ppds as $ppd){
109 $name = $ppd['ppd']['name'];
110 if(preg_match("/^".str_replace("*",".*",$regex)."/i",$name)){
111 if(is_readable($ppd['link'])){
112 $list[$ppd['link']] = $ppd;
113 }
114 }
115 }
116 }
118 /* Sort the list alphabetically */
119 asort($list);
121 if((isset($_GET['act']))&&($_GET['act']=="open")) {
123 if((!empty($_GET['id'])) && (!isset( $this->header[base64_decode($_GET['id'])]))){
124 msg_dialog::display(_("PPD error"), sprintf(_("Cannot locate vendor '%s' in available PPDs!"), base64_decode($_GET['id'])), ERROR_DIALOG);
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."));
135 $linkopen = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>
136 <img src='images/lists/folder.png' class='center' border=0> %s
137 </a>";
138 $uselink = "<a href='?plug=".$_GET['plug']."&act=use&id=%s'>%s</a>";
139 $dellink = "<a href='?plug=".$_GET['plug']."&act=del&id=%s'>
140 <img src='images/lists/trash.png' alt='"._("delete")."' border=0>
141 </a>";
143 if(empty($this->Vendor)){
144 foreach($this-> header as $key => $entry){
145 $div ->AddEntry (array(
147 array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'")
148 ));
149 }
150 }else{
151 $div ->AddEntry (array(
152 array("string"=>sprintf($linkopen,"",".. ["._("back")."]"),"attach"=>"style='border-right:0px;'")
153 ));
154 foreach($list as $key => $ppd){
155 $name = $ppd['ppd']['name'];
156 if(preg_match("/^".$this->Vendor."/", $name)){
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),$name)),
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/lists/search.png'));
175 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
176 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.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 ?>