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