1 <?php
3 class selectUserToPrinterDialog 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 $regex = "*";
10 var $subtree = FALSE;
11 var $depselect = "/";
12 var $deplist = "/";
14 var $searchObjects = "";
15 var $searchAttrs = "";
16 var $searchAppend = "";
17 var $baseAddition = "";
18 var $type = "";
19 var $search_cat = "";
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 $this->search_cat = "users";
33 ;break;
34 case "AddGroup" :
35 $this->searchObjects = "(objectClass=posixGroup)";
36 $this->searchAttrs = array("cn","description");
37 $this->searchAppend = "cn";
38 $this->baseAddition = get_groups_ou();
39 $this->search_cat = "groups";
40 ;break;
41 case "AddAdminUser" :
42 $this->searchObjects = "(objectClass=gosaAccount)(!(uid=*$))";
43 $this->searchAttrs = array("cn","uid");
44 $this->searchAppend = "uid";
45 $this->baseAddition = get_people_ou();
46 $this->search_cat = "users";
47 ;break;
48 case "AddAdminGroup" :
49 $this->searchObjects = "(objectClass=posixGroup)";
50 $this->searchAttrs = array("cn","description");
51 $this->searchAppend = "cn";
52 $this->baseAddition = get_groups_ou();
53 $this->search_cat = "groups";
54 ;break;
55 }
56 $this->type = $type;
58 }
60 function execute()
61 {
62 /* Call parent execute */
63 plugin::execute();
65 /* Fill templating stuff */
66 $smarty= get_smarty();
67 $display= "";
69 if(isset($_POST['dialogissubmitted'])){
70 $this->regex=$_POST['regexPrinter'];
71 $this->depselect = $_POST['depselectPrinter'];
72 }
73 $this->subtree= isset($_POST['SubSearch']);
75 if((isset($_GET['search']))&&(!empty($_GET['search']))){
76 $this->regex=$_GET['search']."*";
77 $this->regex=preg_replace("/\*\*/","*",$this->regex);
78 }
81 /* Get all departments within this subtree */
82 $base = $this->config->current['BASE'];
83 $deps_res[] = array("dn"=>$this->config->current['BASE']);
84 $deps_res= array_merge($deps_res,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", array("users","groups"), $this->config->current['BASE'],
85 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
87 /* Load possible departments */
88 $ui = get_userinfo();
90 /* Allowed user departments */
91 $udeps = $ui->get_module_departments("users");
93 /* Allowed groups department */
94 $gdeps = $ui->get_module_departments("groups");
96 /* Combine both arrays */
97 $tdeps = array_unique(array_merge($udeps,$gdeps));
99 /* Create usable departments array */
100 $ids = $this->config->idepartments;
101 $deps = array();
102 foreach($deps_res as $dep){
103 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
104 $value = $ids[$dep['dn']];
105 $deps[$dep['dn']] = $value;
106 }
107 }
108 if(!isset($deps[$this->depselect])){
109 $this->depselect = key($deps);
110 }
114 $tmp_printers= $this->getPrinter();
115 natcasesort($tmp_printers);
116 $smarty->assign("regexPrinter" , $this->regex);
117 $smarty->assign("deplistPrinter" , $deps);;//deplist);
118 $smarty->assign("depselectPrinter" , $this->depselect);
119 $smarty->assign("gotoPrinters" , $tmp_printers);
120 $smarty->assign("gotoPrinterKeys" , array_flip($tmp_printers));
121 $smarty->assign("apply" , apply_filter());
122 $smarty->assign("alphabet" , generate_alphabet());
123 $smarty->assign("search_image" , get_template_path('images/search.png'));
124 $smarty->assign("tree_image" , get_template_path('images/tree.png'));
125 $smarty->assign("infoimage" , get_template_path('images/info.png'));
126 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
127 $smarty->assign("deplist" , $deps);
128 $smarty->assign("subtree", $this->subtree?"checked":"");
130 $display.= $smarty->fetch(get_template_path('selectUserToPrinterDialog.tpl', TRUE,dirname(__FILE__)));
131 return($display);
132 }
134 function check(){
135 /* Call common method to give check the hook */
136 $message= plugin::check();
138 if(empty($_POST['gotoPrinter'])){
139 $message[] = _("Please select a printer or press cancel.");
140 }
141 return $message;
142 }
144 /* Save to LDAP */
145 function save()
146 {
147 $a_return['type']=$this->type;
149 foreach($_POST['gotoPrinter'] as $name){
150 $data = $this->getPrinter(true);
151 $a_return[$name]= $data[$name];
152 }
153 return($a_return);
154 }
156 /* This function generates the Printerlist
157 * All printers are returned that match regex and and depselect
158 */
159 function getPrinter($detailed = false)
160 {
161 $a_return=array();
163 $filter = "(&".$this->searchObjects."(cn=".$this->regex."))";
164 $base = $this->baseAddition.$this->depselect;
165 $attrs = $this->searchAttrs;
166 $cat = $this->search_cat;
168 if ($this->subtree){
169 $res= get_list($filter,$cat,$this->depselect,$attrs, GL_SUBSEARCH);
170 } else {
171 $res= get_list($filter,$cat,$base,$attrs);
172 }
173 foreach($res as $printer){
174 if(($detailed ==true)){
175 if(isset($printer[$this->searchAppend])){
176 $a_return[$printer[$this->searchAppend][0]] = $printer;
177 }
178 }else{
179 if(isset($printer[$this->searchAppend])){
180 if(isset($printer['description'][0])){
181 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0]." - ".$printer['description'][0];
182 }else{
183 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0];
184 }
185 }
186 }
187 }
188 return($a_return);
189 }
190 }
192 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
193 ?>