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[] = array("dn"=>$this->config->current['BASE']);
89 $deps_res= array_merge($deps_res,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", array("users","groups"), $this->config->current['BASE'],
90 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
92 /* Load possible departments */
93 $ui = get_userinfo();
95 /* Allowed user departments */
96 $udeps = $ui->get_module_departments("users");
98 /* Allowed groups department */
99 $gdeps = $ui->get_module_departments("groups");
101 /* Combine both arrays */
102 $tdeps = array_unique(array_merge($udeps,$gdeps));
104 /* Create usable departments array */
105 $ids = $this->config->idepartments;
106 $deps = array();
107 foreach($deps_res as $dep){
108 if(isset($ids[$dep['dn']]) && in_array_ics($dep['dn'], $tdeps)){
109 $value = $ids[$dep['dn']];
110 $deps[$dep['dn']] = $value;
111 }
112 }
113 if(!isset($deps[$this->depselect])){
114 $this->depselect = key($deps);
115 }
119 $tmp_printers= $this->getPrinter();
120 natcasesort($tmp_printers);
121 $smarty->assign("regexPrinter" , $this->regex);
122 $smarty->assign("deplistPrinter" , $deps);;//deplist);
123 $smarty->assign("depselectPrinter" , $this->depselect);
124 $smarty->assign("gotoPrinters" , $tmp_printers);
125 $smarty->assign("gotoPrinterKeys" , array_flip($tmp_printers));
126 $smarty->assign("apply" , apply_filter());
127 $smarty->assign("alphabet" , generate_alphabet());
128 $smarty->assign("search_image" , get_template_path('images/search.png'));
129 $smarty->assign("tree_image" , get_template_path('images/tree.png'));
130 $smarty->assign("infoimage" , get_template_path('images/info.png'));
131 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
132 $smarty->assign("deplist" , $deps);
133 $smarty->assign("subtree", $this->subtree?"checked":"");
135 $display.= $smarty->fetch(get_template_path('selectUserToPrinterDialog.tpl', TRUE,dirname(__FILE__)));
136 return($display);
137 }
139 function check(){
140 /* Call common method to give check the hook */
141 $message= plugin::check();
143 if(empty($_POST['gotoPrinter'])){
144 $message[] = _("Please select a printer or press cancel.");
145 }
146 return $message;
147 }
149 /* Save to LDAP */
150 function save()
151 {
152 $a_return['type']=$this->type;
154 foreach($_POST['gotoPrinter'] as $name){
155 $data = $this->getPrinter(true);
156 $a_return[$name]= $data[$name];
157 }
158 return($a_return);
159 }
161 /* This function generates the Printerlist
162 * All printers are returned that match regex and and depselect
163 */
164 function getPrinter($detailed = false)
165 {
166 $a_return=array();
168 $filter = "(&".$this->searchObjects."(cn=".$this->regex."))";
169 $base = $this->baseAddition.$this->depselect;
170 $attrs = $this->searchAttrs;
171 $cat = $this->search_cat;
173 if ($this->subtree){
174 $res= get_list($filter,$cat,$this->depselect,$attrs, GL_SUBSEARCH);
175 } else {
176 $res= get_list($filter,$cat,$base,$attrs);
177 }
178 foreach($res as $printer){
179 if(($detailed ==true)){
180 if(isset($printer[$this->searchAppend])){
181 $a_return[$printer[$this->searchAppend][0]] = $printer;
182 }
183 }else{
184 if(isset($printer[$this->searchAppend])){
185 if(isset($printer['description'][0])){
186 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0]." - ".$printer['description'][0];
187 }else{
188 $a_return[$printer[$this->searchAppend][0]] = $printer['cn'][0];
189 }
190 }
191 }
192 }
193 return($a_return);
194 }
195 }
197 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
198 ?>