1 <?php
3 class selectPrinterDialog 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 = TRUE;
12 var $attributes = array();
13 var $objectclasses = array("whatever");
14 var $use_existing = false;
15 var $regex = "*";
16 var $depselect = "/";
17 var $deplist = "/";
19 function selectPrinterDialog ($config, $dn= NULL,$use_existing=false )
20 {
21 $this->use_existing = $use_existing;
22 plugin::plugin ($config, $dn);
23 $this->depselect = $this->config->current['BASE'];
24 }
26 function execute()
27 {
28 /* Call parent execute */
29 plugin::execute();
31 /* Fill templating stuff */
32 $smarty= get_smarty();
33 $display= "";
35 if(isset($_POST['dialogissubmitted'])){
36 $this->regex=$_POST['regexPrinter'];
37 $this->depselect = $_POST['depselectPrinter'];
38 }
40 if((isset($_GET['search']))&&(!empty($_GET['search']))){
41 $this->regex=$_GET['search']."*";
42 $this->regex=preg_replace("/\*\*/","*",$this->regex);
43 }
45 $this->deplist=array_flip($this->config->departments);
47 $smarty->assign("regexPrinter" ,$this->regex);
48 $smarty->assign("deplistPrinter" ,$this->deplist);
49 $smarty->assign("depselectPrinter",$this->depselect);
50 $smarty->assign("gotoPrinters",$this->getPrinter());
51 $smarty->assign("gotoPrinterKeys",array_flip($this->getPrinter()));
52 $smarty->assign("apply", apply_filter());
53 $smarty->assign("alphabet", generate_alphabet());
54 $smarty->assign("search_image", get_template_path('images/search.png'));
55 $smarty->assign("tree_image", get_template_path('images/tree.png'));
56 $smarty->assign("infoimage", get_template_path('images/info.png'));
57 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
58 $smarty->assign("deplist", $this->config->idepartments);
60 $display.= $smarty->fetch(get_template_path('selectPrinterDialog.tpl', TRUE,dirname(__FILE__)));
61 return($display);
62 }
64 function check(){
65 $message=array();
66 if(empty($_POST['gotoPrinter'])){
67 $message[] = _("Please select a printer or press cancel.");
68 }
69 return $message;
70 }
72 /* Save to LDAP */
73 function save()
74 {
75 return($_POST['gotoPrinter']);
76 }
78 /* This function generates the Printerlist
79 * All printers are returned that match regex and and depselect
80 */
81 function getPrinter($detailed = false)
82 {
83 $a_return=array();
84 $ldap = $this->config->get_ldap_link();
85 $ldap->cd($this->depselect);
86 $ldap->search("(&(objectClass=gotoPrinter)(cn=".$this->regex."))",array("*"));
87 while($printer = $ldap->fetch()){
88 if($detailed ==true){
89 $a_return[$printer['cn'][0]] = $printer;
90 }else{
91 if(isset($printer['description'][0])){
92 $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];
93 }else{
94 $a_return[$printer['cn'][0]] = $printer['cn'][0];
95 }
96 }
97 }
98 return($a_return);
99 }
100 }
106 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
107 ?>