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 if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
110 if(is_readable($ppd['link'])){
111 $list[$ppd['link']] = $ppd;
112 }
113 }
114 }
115 }
117 if((isset($_GET['act']))&&($_GET['act']=="open")) {
119 if((!empty($_GET['id'])) && (!isset( $this->header[base64_decode($_GET['id'])]))){
120 msg_dialog::display(_("PPD error"), sprintf(_("Cannot locate vendor '%s' in available PPDs!"), base64_decode($_GET['id'])), ERROR_DIALOG);
121 $this->Vendor = "";
122 }else{
123 $this->Vendor = base64_decode($_GET['id']);
124 }
125 }
127 $div = new divSelectBox("printerPPDSelectionDialog");
128 $div ->SetHeight(450);
129 $div ->SetSummary(_("Printer ppd selection."));
131 $linkopen = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>
132 <img src='images/folder.png' class='center' border=0> %s
133 </a>";
134 $uselink = "<a href='?plug=".$_GET['plug']."&act=use&id=%s'>%s</a>";
135 $dellink = "<a href='?plug=".$_GET['plug']."&act=del&id=%s'>
136 <img src='images/edittrash.png' alt='"._("delete")."' border=0>
137 </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);
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 }
191 }
192 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
193 ?>