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