1 <?php
3 class selectPrinterDialog extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account = TRUE;
7 var $attributes = array();
8 var $objectclasses = array("whatever");
9 var $AlreadyAssigned = array();
10 var $regex = "*";
11 var $depselect = "/";
12 var $deplist = "/";
13 var $subtreesearch = FALSE;
15 function selectPrinterDialog ($config, $dn= NULL,$alreadyused=array() )
16 {
17 $this->AlreadyAssigned = $alreadyused;
18 plugin::plugin ($config, $dn);
19 $this->depselect = $this->config->current['BASE'];
20 }
22 function execute()
23 {
24 /* Call parent execute */
25 plugin::execute();
27 /* Fill templating stuff */
28 $smarty= get_smarty();
29 $display= "";
31 if(isset($_POST['dialogissubmitted'])){
32 $this->regex=$_POST['regexPrinter'];
33 $this->depselect = $_POST['depselectPrinter'];
34 }
36 if(isset($_POST['subtrees'])){
37 $this->subtreesearch= TRUE;
38 } else {
39 $this->subtreesearch= FALSE;
40 }
42 if((isset($_GET['search']))&&(!empty($_GET['search']))){
43 $this->regex=$_GET['search']."*";
44 $this->regex=preg_replace("/\*\*/","*",$this->regex);
45 }
47 $this->deplist=$this->config->idepartments;
49 $smarty->assign("regexPrinter" ,$this->regex);
50 $smarty->assign("deplistPrinter" ,$this->deplist);
51 $smarty->assign("depselectPrinter",$this->depselect);
52 $smarty->assign("gotoPrinters",$this->getPrinter());
53 $smarty->assign("gotoPrinterKeys",array_flip($this->getPrinter()));
54 $smarty->assign("apply", apply_filter());
55 $smarty->assign("alphabet", generate_alphabet());
56 $smarty->assign("subtrees", $this->subtreesearch?"checked":"");
57 $smarty->assign("search_image", get_template_path('images/search.png'));
58 $smarty->assign("tree_image", get_template_path('images/tree.png'));
59 $smarty->assign("infoimage", get_template_path('images/info.png'));
60 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
61 $smarty->assign("deplist", $this->config->idepartments);
63 $display.= $smarty->fetch(get_template_path('selectPrinterDialog.tpl', TRUE,dirname(__FILE__)));
64 return($display);
65 }
67 function check(){
68 /* Call common method to give check the hook */
69 $message= plugin::check();
71 if(empty($_POST['gotoPrinter'])){
72 $message[] = _("Please select a printer or press cancel.");
73 }
74 return $message;
75 }
77 /* Save to LDAP */
78 function save()
79 {
80 return($_POST['gotoPrinter']);
81 }
83 /* This function generates the Printerlist
84 * All printers are returned that match regex and and depselect
85 */
86 function getPrinter($detailed = false)
87 {
88 $a_return=array();
89 $ldap = $this->config->get_ldap_link();
91 /* Set tag attribute if we've tagging activated */
92 $tag= "";
93 $ui= get_userinfo();
94 if ($ui->gosaUnitTag != "" && isset($this->config->current['STRICT_UNITS']) &&
95 preg_match('/TRUE/i', $this->config->current['STRICT_UNITS'])){
96 $tag= "(gosaUnitTag=".$ui->gosaUnitTag.")";
97 }
99 if ($this->subtreesearch){
100 $ldap->cd($this->depselect);
101 $ldap->search("(&(objectClass=gotoPrinter)$tag(cn=".$this->regex."))",array("*"));
102 } else {
103 $ldap->cd("ou=printers,ou=systems,".$this->depselect);
104 $ldap->search("(&(objectClass=gotoPrinter)$tag(cn=".$this->regex."))",array("*"));
105 }
106 while($printer = $ldap->fetch()){
108 if(isset($this->AlreadyAssigned[$printer['cn'][0]])) continue;
110 if($detailed ==true){
111 $a_return[$printer['cn'][0]] = $printer;
112 }else{
113 if(isset($printer['description'][0])){
114 $a_return[$printer['cn'][0]] = $printer['cn'][0]." - ".$printer['description'][0];
115 }else{
116 $a_return[$printer['cn'][0]] = $printer['cn'][0];
117 }
118 }
119 }
120 return($a_return);
121 }
122 }
128 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
129 ?>