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 "tcgroups" => "checked",
64 "fongroups" => "checked",
65 "depselect" => $base,
66 "regex" => "*");
67 register_global("ogroupfilter", $ogroupfilter);
68 }
69 }
71 function execute()
72 {
73 /* Prepare template */
74 $smarty= get_smarty();
76 /* Save data */
77 $ogroupfilter= get_global("ogroupfilter");
79 foreach( array("depselect", "regex") as $type){
80 if (isset($_POST[$type])){
81 $ogroupfilter[$type]= $_POST[$type];
82 }
83 }
84 if (isset($_POST['depselect'])){
85 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
86 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups") as $type){
88 if (isset($_POST[$type])) {
89 $ogroupfilter[$type]= "checked";
90 } else {
91 $ogroupfilter[$type]= "";
92 }
93 }
94 }
95 if (isset($_GET['search'])){
96 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
97 if ($s == "**"){
98 $s= "*";
99 }
100 $ogroupfilter['regex']= $s;
101 }
102 register_global("ogroupfilter", $ogroupfilter);
104 /* Prepare formular */
105 if (!isset($this->ogroup) &&
106 !isset($_POST['new_group']) &&
107 !isset($_POST['delete_group']) &&
108 !isset($_POST['select_group'])){
109 $this->reload();
110 }
112 /* Check for exeeded sizelimit */
113 if (($message= check_sizelimit()) != ""){
114 return($message);
115 }
117 /* New group? */
118 if (isset($_POST['new_group'])){
120 /* By default we set 'dn' to 'new', all relevant plugins will
121 react on this. */
122 $this->dn= "new";
124 /* Create new usertab object */
125 $this->ogroup= new ogrouptabs($this->config,
126 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
127 $this->ogroup->set_acl(array(':all'));
128 }
130 if (isset($_POST['delete_group']) && isset($_POST['grouplist'])){
132 /* Get 'dn' from posted 'uid' */
133 $this->dn= trim($_POST['grouplist']);
135 /* Load permissions for selected 'dn' and check if
136 we're allowed to remove this 'dn' */
137 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
138 $this->acl= get_module_permission($acl, "ogroup", $this->dn);
139 if (chkacl($this->acl, "delete") == ""){
141 /* Check locking, save current plugin in 'back_plugin', so
142 the dialog knows where to return. */
143 if (($user= get_lock($this->dn)) != ""){
144 return(gen_locked_message ($user, $this->dn));
145 }
147 /* Lock the current entry, so nobody will edit it during deletion */
148 add_lock ($this->dn, $this->ui->dn);
149 $smarty->assign("info", sprintf(_("You're about to delete the object group '%s'."), $this->dn));
150 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
151 } else {
153 /* Obviously the user isn't allowed to delete. Show message and
154 clean session. */
155 print_red (_("You are not allowed to delete this object group!"));
156 }
157 }
159 /* Confirmation for deletion has been passed. Group should be deleted. */
160 if (isset($_POST['delete_group_confirm'])){
162 /* Some nice guy may send this as POST, so we've to check
163 for the permissions again. */
164 if (chkacl($this->acl, "delete") == ""){
166 /* Delete request is permitted, perform LDAP action */
167 $this->ogroup= new ogrouptabs($this->config,
168 $this->config->data['TABS']['OGROUPTABS'], $this->dn);
169 $this->ogroup->set_acl(array($this->acl));
170 $this->ogroup->delete ();
171 gosa_log ("Object group'".$this->dn."' has been removed");
172 unset ($this->ogroup);
173 $this->ogroup= NULL;
175 /* Group list has changed, reload it. */
176 $this->reload ();
177 } else {
179 /* Normally this shouldn't be reached, send some extra
180 logs to notify the administrator */
181 print_red (_("You are not allowed to delete this object group!"));
182 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
183 }
185 /* Remove lock file after successfull deletion */
186 del_lock ($this->dn);
187 unset($_SESSION['objectinfo']);
188 }
191 /* Delete group canceled? */
192 if (isset($_POST['delete_cancel'])){
193 del_lock ($this->dn);
194 unset($_SESSION['objectinfo']);
195 }
197 if ((isset($_POST['select_group']) || (isset($_POST['edit_helper']) && $_POST['edit_helper'] == "1")) && isset($_POST['grouplist']) && $_POST['grouplist'] != ""){
199 /* Get 'dn' from posted 'uid', must be unique */
200 $this->dn= trim($_POST['grouplist']);
202 /* Check locking, save current plugin in 'back_plugin', so
203 the dialog knows where to return. */
204 if (($user= get_lock($this->dn)) != ""){
205 return(gen_locked_message ($user, $this->dn));
206 }
208 /* Lock the current entry, so everyone will get the
209 above dialog */
210 add_lock ($this->dn, $this->ui->dn);
212 /* Set up the users ACL's for this 'dn' */
213 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
215 /* Register grouptab to trigger edit dialog */
216 $this->ogroup= new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],
217 $this->dn);
218 $this->ogroup->set_acl($acl);
219 $_SESSION['objectinfo']= $this->dn;
220 }
222 /* Finish button has been pressed */
223 if (isset($_POST['edit_finish'])){
225 /* Check tabs, will feed message array */
226 $message= $this->ogroup->check();
228 /* Save, or display error message? */
229 if (count($message) == 0){
231 /* Save user data to ldap */
232 $this->ogroup->save();
233 gosa_log ("Object group'".$this->dn."' has been saved");
235 /* Group has been saved successfully, remove lock from
236 LDAP. */
237 if ($this->dn != "new"){
238 del_lock ($this->dn);
239 }
241 /* There's no page reload so we have to read new users at
242 this point. */
243 $this->reload ();
244 unset ($this->ogroup);
245 $this->ogroup= NULL;
246 unset ($_SESSION['objectinfo']);
248 } else {
249 /* Ok. There seem to be errors regarding to the tab data,
250 show message and continue as usual. */
251 show_errors($message);
252 }
253 }
255 /* Cancel dialogs */
256 if (isset($_POST['edit_cancel'])){
257 del_lock ($this->ogroup->dn);
258 unset ($this->ogroup);
259 $this->ogroup= NULL;
260 unset($_SESSION['objectinfo']);
261 }
263 /* Show dialog if object is present */
264 if ($this->ogroup){
265 $display= $this->ogroup->execute();
267 /* Don't show buttons if tab dialog requests this */
268 if (!$this->ogroup->by_object[$this->ogroup->current]->dialog){
269 $display.= "<p style=\"text-align:right\">\n";
270 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
271 $display.= " \n";
272 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
273 $display.= "</p>";
274 }
275 return ($display);
276 }
278 /* Show main page */
279 $smarty->assign("search_image", get_template_path('images/search.png'));
280 $smarty->assign("tree_image", get_template_path('images/tree.png'));
281 $smarty->assign("infoimage", get_template_path('images/info.png'));
282 $smarty->assign("launchimage", get_template_path('images/launch.png'));
283 $smarty->assign("deplist", $this->config->idepartments);
285 $smarty->assign("groups", $this->convert_list($this->grouplist));
287 foreach( array("usergroups", "groupgroups", "appgroups", "depgroups",
288 "servergroups", "wsgroups", "prtgroups", "tcgroups", "fongroups", "regex", "depselect") as $type){
289 $smarty->assign("$type", $ogroupfilter[$type]);
290 }
292 $smarty->assign("hint", print_sizelimit_warning());
293 $smarty->assign("apply", apply_filter());
294 $smarty->assign("alphabet", generate_alphabet());
295 return ($smarty->fetch (get_template_path('headpage.tpl', TRUE)));
296 }
299 function convert_list($input)
300 {
301 $temp= "";
302 $conv= array( "U" => "select_user.png",
303 "G" => "select_groups.png",
304 "A" => "select_application.png",
305 "D" => "select_department.png",
306 "S" => "select_server.png",
307 "F" => "select_phone.png",
308 "W" => "select_workstation.png",
309 "T" => "select_terminal.png",
310 "P" => "select_printer.png");
312 foreach ($input as $key => $value){
314 /* Assemble picture */
315 $type= $value['type'];
316 if (isset($type[0])){
317 $p1= $conv[$type[0]];
318 } else {
319 $p1= "empty.png";
320 }
321 if (isset($type[1])){
322 $p2= $conv[$type[1]];
323 } else {
324 $p2= "empty.png";
325 }
327 /* Generate output */
328 $temp= "<option value=\"$key\" class=\"select\" style=\"background-image:url('combine.php?image1=$p1&image2=$p2');padding-left:35px;\">".$value['text']."</option>\n".$temp;
329 }
331 return ($temp);
332 }
335 function reload()
336 {
337 /* Get config */
338 $ogroupfilter= get_global('ogroupfilter');
340 /* Set base for all searches */
341 $base= $ogroupfilter['depselect'];
343 /* Regex filter? */
344 if ($ogroupfilter['regex'] != ""){
345 $regex= $ogroupfilter['regex'];
346 } else {
347 $regex= "*";
348 }
350 /* User filter? */
351 $this->grouplist= array();
353 /* Generate grouplist filter */
354 $filter= "";
356 if ($ogroupfilter['usergroups'] == "checked"){
357 $filter.= "(gosaGroupObjects=*U*)";
358 }
359 if ($ogroupfilter['groupgroups'] == "checked"){
360 $filter.= "(gosaGroupObjects=*G*)";
361 }
362 if ($ogroupfilter['appgroups'] == "checked"){
363 $filter.= "(gosaGroupObjects=*A*)";
364 }
365 if ($ogroupfilter['depgroups'] == "checked"){
366 $filter.= "(gosaGroupObjects=*D*)";
367 }
368 if ($ogroupfilter['servergroups'] == "checked"){
369 $filter.= "(gosaGroupObjects=*S*)";
370 }
371 if ($ogroupfilter['wsgroups'] == "checked"){
372 $filter.= "(gosaGroupObjects=*W*)";
373 }
374 if ($ogroupfilter['prtgroups'] == "checked"){
375 $filter.= "(gosaGroupObjects=*P*)";
376 }
377 if ($ogroupfilter['tcgroups'] == "checked"){
378 $filter.= "(gosaGroupObjects=*T*)";
379 }
380 if ($ogroupfilter['fongroups'] == "checked"){
381 $filter.= "(gosaGroupObjects=*F*)";
382 }
384 if ($filter != ""){
385 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames)(|$filter))";
386 } else {
387 $filter= "(&(cn=$regex)(objectClass=gosaGroupOfNames))";
388 }
389 $res= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("cn", "description", "gosaGroupObjects"), TRUE);
390 foreach ($res as $value){
391 $pictype= preg_replace('/[\[\]]/', '', $value["gosaGroupObjects"][0]);
392 $sortstring= preg_split('//', $pictype, -1, PREG_SPLIT_NO_EMPTY);
393 sort($sortstring);
394 $pictype= implode("", $sortstring);
395 if (isset($value["description"][0])){
396 $this->grouplist[$value["dn"]]= array("text" => $value["cn"][0]." [".
397 $value["description"][0]."]", "type" => $pictype);
398 } else {
399 $this->grouplist[$value["dn"]]= array("text" => $value["cn"][0],
400 "type" => $pictype);
401 }
402 }
403 ksort ($this->grouplist);
404 reset ($this->grouplist);
405 }
407 }
409 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
410 ?>