Code

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