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 $AlreadyAssigned = array();
15 var $regex = "*";
16 var $depselect = "/";
17 var $deplist = "/";
19 function selectPrinterDialog ($config, $dn= NULL,$alreadyused=array() )
20 {
21 $this->AlreadyAssigned = $alreadyused;
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=$this->config->idepartments;
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 /* Call common method to give check the hook */
66 $message= plugin::check();
68 if(empty($_POST['gotoPrinter'])){
69 $message[] = _("Please select a printer or press cancel.");
70 }
71 return $message;
72 }
74 /* Save to LDAP */
75 function save()
76 {
77 return($_POST['gotoPrinter']);
78 }
80 /* This function generates the Printerlist
81 * All printers are returned that match regex and and depselect
82 */
83 function getPrinter($detailed = false)
84 {
85 $a_return=array();
86 $ldap = $this->config->get_ldap_link();
87 $ldap->cd($this->depselect);
89 /* Set tag attribute if we've tagging activated */
90 $tag= "";
91 $ui= get_userinfo();
92 if ($ui->gosaUnitTag != "" && isset($this->config->current['STRICT_UNITS']) &&
93 preg_match('/TRUE/i', $this->config->current['STRICT_UNITS'])){
94 $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
95 }
97 $ldap->search("(&(objectClass=gotoPrinter)$tag(cn=".$this->regex."))",array("*"));
98 while($printer = $ldap->fetch()){
100 if(isset($this->AlreadyAssigned[$printer['cn'][0]])) continue;
102 if($detailed ==true){
103 $a_return[$printer['cn'][0]] = $printer;
104 }else{
105 if(isset($printer['description'][0])){
106 $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];
107 }else{
108 $a_return[$printer['cn'][0]] = $printer['cn'][0];
109 }
110 }
111 }
112 return($a_return);
113 }
114 }
120 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
121 ?>