1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2004 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_ogroups.inc";
22 class ogroupManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Object groups";
26 var $plDescription= "This does something";
28 /* attribute list for save action */
29 var $attributes= array();
30 var $objectclasses= array();
31 var $obtypes= array();
32 var $ogroup;
34 function ogroupManagement ($config, $dn= NULL)
35 {
36 /* Include config object */
37 $this->config= $config;
38 $this->ui= get_userinfo();
40 /* Fill translation array */
41 $this->obtypes= array( "posixAccount" => _("UNIX accounts"),
42 "posixGroup" => _("Groups"),
43 "gosaDepartment" => _("Departments"),
44 "gosaApplication" => _("Applications"),
45 "goServer" => _("Servers"),
46 "gotoTerminal" => _("Thin Clients"),
47 "gotoWorkstation" => _("Workstations"),
48 "goFonHardware" => _("Phone"),
49 "gotoPrinter" => _("Printer"));
50 asort($this->obtypes);
52 /* Get global filter config */
53 if (!is_global("ogroupfilter")){
54 $ui= get_userinfo();
55 $base= get_base_from_people($ui->dn);
56 $ogroupfilter= array( "usergroups" => "checked",
57 "groupgroups" => "checked",
58 "appgroups" => "checked",
59 "depgroups" => "checked",
60 "servergroups" => "checked",
61 "wsgroups" => "checked",
62 "prtgroups" => "checked",
63 "emptygroups" => "checked",
64 "tcgroups" => "checked",
65 "fongroups" => "checked",
66 "depselect" => $base,
67 "regex" => "*");
68 register_global("ogroupfilter", $ogroupfilter);
69 }
70 }
72 function execute()
73 {
74 /* Prepare template */
75 $smarty= get_smarty();
77 /* Save data */
78 if (is_global("ogroupfilter")){
79 $ogroupfilter= get_global("ogroupfilter");
80 } else {
81 $ogroupfilter= array();
82 }
83 foreach( array("depselect", "regex") as $type){
84 if (isset($_POST[$type])){
85 $ogroupfilter[$type]= $_POST[$type];
86 }
87 }
88 if (isset($_POST['depselect'])){
89 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups", "emptygroups",
90 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups") as $type){
92 if (isset($_POST[$type])) {
93 $ogroupfilter[$type]= "checked";
94 } else {
95 $ogroupfilter[$type]= "";
96 }
97 }
98 }
99 if (isset($_GET['search'])){
100 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
101 if ($s == "**"){
102 $s= "*";
103 }
104 $ogroupfilter['regex']= $s;
105 }
106 register_global("ogroupfilter", $ogroupfilter);
108 /* Prepare formular */
109 if (!isset($this->ogroup) &&
110 !isset($_POST['new_group']) &&
111 !isset($_POST['delete_group']) &&
112 !isset($_POST['select_group'])){
113 $this->reload();
114 }
116 /* Check for exeeded sizelimit */
117 if (($message= check_sizelimit()) != ""){
118 return($message);
119 }
121 /* New group? */
122 if (isset($_POST['new_group'])){
124 /* By default we set 'dn' to 'new', all relevant plugins will
125 react on this. */
126 $this->dn= "new";
128 /* Create new usertab object */
129 $this->ogroup= new ogrouptabs($this->config,
130 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
131 $this->ogroup->set_acl(array(':all'));
132 }
134 if (isset($_POST['delete_group']) && isset($_POST['grouplist'])){
136 /* Get 'dn' from posted 'uid' */
137 $this->dn= trim($_POST['grouplist']);
139 /* Load permissions for selected 'dn' and check if
140 we're allowed to remove this 'dn' */
141 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
142 $this->acl= get_module_permission($acl, "ogroup", $this->dn);
143 if (chkacl($this->acl, "delete") == ""){
145 /* Check locking, save current plugin in 'back_plugin', so
146 the dialog knows where to return. */
147 if (($user= get_lock($this->dn)) != ""){
148 return(gen_locked_message ($user, $this->dn));
149 }
151 /* Lock the current entry, so nobody will edit it during deletion */
152 add_lock ($this->dn, $this->ui->dn);
153 $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), $this->dn));
154 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
155 } else {
157 /* Obviously the user isn't allowed to delete. Show message and
158 clean session. */
159 print_red (_("You are not allowed to delete this object group!"));
160 }
161 }
163 /* Confirmation for deletion has been passed. Group should be deleted. */
164 if (isset($_POST['delete_group_confirm'])){
166 /* Some nice guy may send this as POST, so we've to check
167 for the permissions again. */
168 if (chkacl($this->acl, "delete") == ""){
170 /* Delete request is permitted, perform LDAP action */
171 $this->ogroup= new ogrouptabs($this->config,
172 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
173 $this->ogroup->set_acl(array($this->acl));
174 $this->ogroup->delete ();
175 gosa_log ("Object group'".$this->dn."' has been removed");
176 unset ($this->ogroup);
177 $this->ogroup= NULL;
179 /* Group list has changed, reload it. */
180 $this->reload ();
181 } else {
183 /* Normally this shouldn't be reached, send some extra
184 logs to notify the administrator */
185 print_red (_("You are not allowed to delete this object group!"));
186 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
187 }
189 /* Remove lock file after successfull deletion */
190 del_lock ($this->dn);
191 unset($_SESSION['objectinfo']);
192 }
195 /* Delete group canceled? */
196 if (isset($_POST['delete_cancel'])){
197 del_lock ($this->dn);
198 unset($_SESSION['objectinfo']);
199 }
201 if ((isset($_POST['select_group']) || (isset($_POST['edit_helper']) && $_POST['edit_helper'] == "1")) && isset($_POST['grouplist']) && $_POST['grouplist'] != ""){
203 /* Get 'dn' from posted 'uid', must be unique */
204 $this->dn= trim($_POST['grouplist']);
206 /* Check locking, save current plugin in 'back_plugin', so
207 the dialog knows where to return. */
208 if (($user= get_lock($this->dn)) != ""){
209 return(gen_locked_message ($user, $this->dn));
210 }
212 /* Lock the current entry, so everyone will get the
213 above dialog */
214 add_lock ($this->dn, $this->ui->dn);
216 /* Set up the users ACL's for this 'dn' */
217 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
219 /* Register grouptab to trigger edit dialog */
220 $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
221 $this->dn);
222 $this->ogroup->set_acl($acl);
223 $_SESSION['objectinfo']= $this->dn;
224 }
226 /* Finish button has been pressed */
227 if (isset($_POST['edit_finish'])){
229 /* Check tabs, will feed message array */
230 $message= $this->ogroup->check();
232 /* Save, or display error message? */
233 if (count($message) == 0){
235 /* Save user data to ldap */
236 $this->ogroup->save();
237 gosa_log ("Object group'".$this->dn."' has been saved");
239 /* Group has been saved successfully, remove lock from
240 LDAP. */
241 if ($this->dn != "new"){
242 del_lock ($this->dn);
243 }
245 /* There's no page reload so we have to read new users at
246 this point. */
247 $this->reload ();
248 unset ($this->ogroup);
249 $this->ogroup= NULL;
250 unset ($_SESSION['objectinfo']);
252 } else {
253 /* Ok. There seem to be errors regarding to the tab data,
254 show message and continue as usual. */
255 show_errors($message);
256 }
257 }
259 /* Cancel dialogs */
260 if (isset($_POST['edit_cancel'])){
261 del_lock ($this->ogroup->dn);
262 unset ($this->ogroup);
263 $this->ogroup= NULL;
264 unset($_SESSION['objectinfo']);
265 }
267 /* Show dialog if object is present */
268 if ($this->ogroup){
269 $display= $this->ogroup->execute();
271 /* Don't show buttons if tab dialog requests this */
272 if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
273 $display.= "<p style=\"text-align:right\">\n";
274 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
275 $display.= " \n";
276 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
277 $display.= "</p>";
278 }
279 return ($display);
280 }
282 /* Show main page */
283 $smarty->assign("search_image", get_template_path('images/search.png'));
284 $smarty->assign("tree_image", get_template_path('images/tree.png'));
285 $smarty->assign("infoimage", get_template_path('images/info.png'));
286 $smarty->assign("launchimage", get_template_path('images/launch.png'));
287 $smarty->assign("deplist", $this->config->idepartments);
289 $smarty->assign("groups", $this->convert_list($this->grouplist));
291 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups", "emptygroups",
292 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups", "regex", "depselect") as $type){
293 $smarty->assign("$type", $ogroupfilter[$type]);
294 }
296 $smarty->assign("hint", print_sizelimit_warning());
297 $smarty->assign("apply", apply_filter());
298 $smarty->assign("alphabet", generate_alphabet());
299 return ($smarty->fetch (get_template_path('headpage.tpl', TRUE)));
300 }
303 function convert_list($input)
304 {
305 $temp= "";
306 $conv= array( "U" => "select_user.png",
307 "G" => "select_groups.png",
308 "A" => "select_application.png",
309 "D" => "select_department.png",
310 "S" => "select_server.png",
311 "F" => "select_phone.png",
312 "W" => "select_workstation.png",
313 "T" => "select_terminal.png",
314 "P" => "select_printer.png");
316 foreach ($input as $key => $value){
318 /* Assemble picture */
319 $type= $value['type'];
320 if (isset($type[0])){
321 $p1= $conv[$type[0]];
322 } else {
323 $p1= "empty.png";
324 }
325 if (isset($type[1])){
326 $p2= $conv[$type[1]];
327 } else {
328 $p2= "empty.png";
329 }
331 /* Generate output */
332 $temp= "<option value=\"$key\" class=\"select\" style=\"background-image:url('combine.php?image1=$p1&image2=$p2');padding-left:35px;\">".$value['text']."</option>\n".$temp;
333 }
335 return ($temp);
336 }
339 function reload()
340 {
341 /* Get config */
342 $ogroupfilter= get_global('ogroupfilter');
344 /* Set base for all searches */
345 $base= $ogroupfilter['depselect'];
347 /* Regex filter? */
348 if ($ogroupfilter['regex'] != ""){
349 $regex= $ogroupfilter['regex'];
350 } else {
351 $regex= "*";
352 }
354 /* User filter? */
355 $this->grouplist= array();
357 /* Generate grouplist filter */
358 $filter= "";
360 if ($ogroupfilter['usergroups'] == "checked"){
361 $filter.= "(gosaGroupObjects=*U*)";
362 }
363 if ($ogroupfilter['groupgroups'] == "checked"){
364 $filter.= "(gosaGroupObjects=*G*)";
365 }
366 if ($ogroupfilter['appgroups'] == "checked"){
367 $filter.= "(gosaGroupObjects=*A*)";
368 }
369 if ($ogroupfilter['depgroups'] == "checked"){
370 $filter.= "(gosaGroupObjects=*D*)";
371 }
372 if ($ogroupfilter['servergroups'] == "checked"){
373 $filter.= "(gosaGroupObjects=*S*)";
374 }
375 if ($ogroupfilter['wsgroups'] == "checked"){
376 $filter.= "(gosaGroupObjects=*W*)";
377 }
378 if ($ogroupfilter['prtgroups'] == "checked"){
379 $filter.= "(gosaGroupObjects=*P*)";
380 }
381 if ($ogroupfilter['tcgroups'] == "checked"){
382 $filter.= "(gosaGroupObjects=*T*)";
383 }
384 if ($ogroupfilter['fongroups'] == "checked"){
385 $filter.= "(gosaGroupObjects=*F*)";
386 }
387 if ($ogroupfilter['emptygroups'] == "checked"){
388 $filter.= "(gosaGroupObjects=[])";
389 }
391 if ($filter != ""){
392 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames)(|$filter))";
393 } else {
394 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames))";
395 }
396 $res= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("cn", "description", "gosaGroupObjects"), TRUE);
397 foreach ($res as $value){
398 $pictype= preg_replace('/[\[\]]/', '', $value["gosaGroupObjects"][0]);
399 $sortstring= preg_split('//', $pictype, -1, PREG_SPLIT_NO_EMPTY);
400 sort($sortstring);
401 $pictype= implode("", $sortstring);
402 if (isset($value["description"][0])){
403 $this->grouplist[$value["dn"]]= array("text" => $value["cn"][0]." [".
404 $value["description"][0]."]", "type" => $pictype);
405 } else {
406 $this->grouplist[$value["dn"]]= array("text" => $value["cn"][0],
407 "type" => $pictype);
408 }
409 }
410 ksort ($this->grouplist);
411 reset ($this->grouplist);
412 }
414 }
416 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
417 ?>