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(!isset($_SESSION['printerPPDSelectionDialog'])){
28 $_SESSION['printerPPDSelectionDialog']['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 $regex = $_SESSION['printerPPDSelectionDialog']['regex'];
47 if(isset($_GET['search'])){
48 $regex = $_GET['search']."*";
49 }
51 if(isset($_POST['regex'])){
52 $regex= $_POST['regex'];
53 }
55 $regex = str_replace("**","*",$regex);
56 $_SESSION['printerPPDSelectionDialog']['regex'] = $regex;
59 /* Delete requested, check if everything is ok and display confirmation dialog */
60 if(isset($_GET['act']) && $_GET['act'] == "del"){
62 /* Get id and check if id is valid */
63 $id_to_del = base64_decode($_GET['id']);
64 $found = "";
65 foreach($this->list[$this->Vendor] as $key => $data){
66 if($data['link'] == $id_to_del){
67 $found = $key;
68 break;
69 }
70 }
71 if(!empty($found)){
72 $this->current_del_id = $id_to_del;
74 $smarty->assign("warning", sprintf(_("You're about to delete the ppd file '%s' at '%s'."), $found,$id_to_del));
75 return($smarty->fetch(get_template_path('remove_ppd.tpl', TRUE)));
77 }else{
78 print_red(sprintf(_("Could not found specified ppd file '%s'."),$id_to_del));
79 }
80 }
82 /* Deletion confirmed */
83 if(isset($_POST['delete_ppd_confirm']) && !empty($this->current_del_id)){
85 /* check if file is removeable */
86 if(is_writeable($this->current_del_id)){
87 $is_ok = @unlink($this->current_del_id);
89 /* Update ppd list */
90 if($is_ok){
91 foreach($this->list as $vendor => $ppds){
92 foreach($ppds as $ppd => $data){
93 if($data['link'] == $this->current_del_id){
94 unset($this->list[$vendor][$ppd]);
95 }
96 }
97 }
98 }
99 }else{
100 $is_ok = false;
101 }
103 if(!$is_ok){
104 print_red(_("Something went wrong while trying to remove the ppd file from server, possibly we have no write access."));
105 }
106 }
109 /** Added **/
110 $list = array();
111 foreach($this->list as $cat => $ppds){
112 foreach($ppds as $ppd){
113 if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
114 if(is_readable($ppd['link'])){
115 $list[$ppd['link']] = $ppd;
116 }
117 }
118 }
119 }
121 if((isset($_GET['act']))&&($_GET['act']=="open")) {
123 if((!empty($_GET['id'])) && (!isset( $this->header[base64_decode($_GET['id'])]))){
124 print_red(sprintf(_("Selected vendor '%s' does not exists in our list of ppds."),base64_decode($_GET['id'])));
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/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/edittrash.png' alt='"._("delete")."' border=0>
141 </a>";
143 if(empty($this->Vendor)){
144 foreach($this-> header as $key => $entry){
145 $div ->AddEntry (array(
146 array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'")
147 ));
148 }
149 }else{
150 $div ->AddEntry (array(
151 array("string"=>sprintf($linkopen,"",".. ["._("back")."]"),"attach"=>"style='border-right:0px;'")
152 ));
153 foreach($list as $key => $ppd){
154 if(preg_match("/^".$this->Vendor."/",$ppd['ppd'])){
156 if(is_writeable($ppd['link'])){
157 $del_str = sprintf($dellink,base64_encode($key));
158 }else{
159 $del_str = "";
160 }
162 $div ->AddEntry (array(
163 array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd'])),
164 array("string"=>$del_str,"attach"=>"style='border-right:0px;'")
166 ));
167 }
168 }
169 }
171 $smarty->assign("List", $div -> DrawList());
172 $smarty->assign("search_image", get_template_path('images/search.png'));
173 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
174 $smarty->assign("tree_image", get_template_path('images/tree.png'));
175 $smarty->assign("alphabet", generate_alphabet());
176 $smarty->assign("apply", apply_filter());
177 $smarty->assign("regex", $regex);
179 $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__)));
180 return($display);
181 }
183 function save_object()
184 {
185 }
187 function check(){
188 }
190 /* Save to LDAP */
191 function save()
192 {
193 return $this->selectedPPD;
194 }
195 }
196 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
197 ?>