1 <?php
3 class selectUserToPrinterDialog extends plugin
4 {
6 /* attribute list for save action */
7 var $ignore_account = TRUE;
8 var $attributes = array();
9 var $objectclasses = array("whatever");
10 var $regex = "*";
11 var $depselect = "/";
12 var $deplist = "/";
14 var $searchObjects = "";
15 var $searchAttrs = "";
16 var $searchAppend = "";
17 var $baseAddition = "";
18 var $type = "";
20 function selectUserToPrinterDialog ($config, $dn= NULL,$type=false )
21 {
22 plugin::plugin ($config, $dn);
23 $this->depselect = $this->config->current['BASE'];
25 switch($type){
26 case "AddUser" :
27 $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
28 $this->searchAttrs = array("cn","uid");
29 $this->searchAppend = "uid";
30 $this->baseAddition = get_people_ou();
31 ;break;
32 case "AddGroup" :
33 $this->searchObjects = "(objectClass=posixGroup)";
34 $this->searchAttrs = array("cn","description");
35 $this->searchAppend = "cn";
36 $this->baseAddition = get_groups_ou();
37 ;break;
38 case "AddAdminUser" :
39 $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
40 $this->searchAttrs = array("cn","uid");
41 $this->searchAppend = "uid";
42 $this->baseAddition = get_people_ou();
43 ;break;
44 case "AddAdminGroup" :
45 $this->searchObjects = "(objectClass=posixGroup)";
46 $this->searchAttrs = array("cn","description");
47 $this->searchAppend = "cn";
48 $this->baseAddition = get_groups_ou();
49 ;break;
50 }
51 $this->type = $type;
53 }
55 function execute()
56 {
57 /* Call parent execute */
58 plugin::execute();
60 /* Fill templating stuff */
61 $smarty= get_smarty();
62 $display= "";
64 if(isset($_POST['dialogissubmitted'])){
65 $this->regex=$_POST['regexPrinter'];
66 $this->depselect = $_POST['depselectPrinter'];
67 }
69 if((isset($_GET['search']))&&(!empty($_GET['search']))){
70 $this->regex=$_GET['search']."*";
71 $this->regex=preg_replace("/\*\*/","*",$this->regex);
72 }
74 $tmp_printers= $this->getPrinter();
75 natcasesort($tmp_printers);
76 $smarty->assign("regexPrinter" , $this->regex);
77 $smarty->assign("deplistPrinter" , $this->config->idepartments);//deplist);
78 $smarty->assign("depselectPrinter" , $this->depselect);
79 $smarty->assign("gotoPrinters" , $tmp_printers);
80 $smarty->assign("gotoPrinterKeys" , array_flip($tmp_printers));
81 $smarty->assign("apply" , apply_filter());
82 $smarty->assign("alphabet" , generate_alphabet());
83 $smarty->assign("search_image" , get_template_path('images/search.png'));
84 $smarty->assign("tree_image" , get_template_path('images/tree.png'));
85 $smarty->assign("infoimage" , get_template_path('images/info.png'));
86 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
87 $smarty->assign("deplist" , $this->config->idepartments);
89 $display.= $smarty->fetch(get_template_path('selectUserToPrinterDialog.tpl', TRUE,dirname(__FILE__)));
90 return($display);
91 }
93 function check(){
94 /* Call common method to give check the hook */
95 $message= plugin::check();
97 if(empty($_POST['gotoPrinter'])){
98 $message[] = _("Please select a printer or press cancel.");
99 }
100 return $message;
101 }
103 /* Save to LDAP */
104 function save()
105 {
106 $a_return['type']=$this->type;
108 foreach($_POST['gotoPrinter'] as $name){
109 $data = $this->getPrinter(true);
110 $a_return[$name]= $data[$name];
111 }
112 return($a_return);
113 }
115 /* This function generates the Printerlist
116 * All printers are returned that match regex and and depselect
117 */
118 function getPrinter($detailed = false)
119 {
120 $a_return=array();
121 $ldap = $this->config->get_ldap_link();
122 $ldap->cd($this->depselect);
123 #$ldap->search("(&".$this->searchObjects."(cn=".$this->regex."))", $this->depselect, $this->searchAttrs);
124 $ldap->ls("(&".$this->searchObjects."(cn=".$this->regex."))", $this->baseAddition.$this->depselect, $this->searchAttrs);
125 while($printer = $ldap->fetch()){
126 if(($detailed ==true)){
127 if(isset($printer[$this->searchAppend])){
128 $a_return[$printer[$this->searchAppend][0]] = $printer;
129 }
130 }else{
131 if(isset($printer[$this->searchAppend])){
132 if(isset($printer['description'][0])){
133 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0]." - ".$printer['description'][0];
134 }else{
135 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0];
136 }
137 }
138 }
139 }
140 return($a_return);
141 }
142 }
144 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
145 ?>