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