9c36e88e9e38a09e195ee1afc60efa0fcf445f01
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();
18 var $Vendor = "";
19 var $current_del_id = "";
21 function printerPPDSelectionDialog ($config, $dn= NULL,$list=false,$headers=false,$ppd=false)
22 {
23 plugin::plugin ($config, $dn);
24 $this->list = $list;
25 $this->header = $headers;
26 $this->depselect = $this->config->current['BASE'];
28 if(!isset($_SESSION['printerPPDSelectionDialog'])){
29 $_SESSION['printerPPDSelectionDialog']['regex'] = "*";
30 }
32 /* Order the manufacturers index */
33 ksort($this->header);
34 }
36 function execute()
37 {
38 /* Call parent execute */
39 plugin::execute();
41 /* Fill templating stuff */
42 $smarty= get_smarty();
43 $display= "";
44 $s_action = "none";
46 $regex = $_SESSION['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 $_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 }
108 /** Added **/
109 $list = array();
110 foreach($this->list as $cat => $ppds){
111 foreach($ppds as $ppd){
112 if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){
113 if(is_readable($ppd['link'])){
114 $list[$ppd['link']] = $ppd;
115 }
116 }
117 }
118 }
121 /* Open vendor folder */
122 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'>%s</a>";
136 $uselink = "<a href='?plug=".$_GET['plug']."&act=use&id=%s'>%s</a>";
137 $dellink = "<a href='?plug=".$_GET['plug']."&act=del&id=%s'><img src='images/edittrash.png' alt='"._("delete")."' border=0></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;'")
161 ));
162 }
163 }
164 }
166 $smarty->assign("List", $div -> DrawList());
167 $smarty->assign("search_image", get_template_path('images/search.png'));
168 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
169 $smarty->assign("tree_image", get_template_path('images/tree.png'));
170 $smarty->assign("alphabet", generate_alphabet());
171 $smarty->assign("apply", apply_filter());
172 $smarty->assign("regex", $regex);
174 $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__)));
175 return($display);
176 }
178 function save_object()
179 {
180 }
182 function check(){
183 }
185 /* Save to LDAP */
186 function save()
187 {
188 return $this->selectedPPD;
189 }
190 }
191 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
192 ?>