Code

added all alt="" tags to folder /plugins
[gosa.git] / plugins / admin / departments / class_departmentManagement.inc
1 <?php
2 /*
3   This code is part of GOsa (https://gosa.gonicus.de)
4   Copyright (C) 2003  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_department.inc";
22 class departmentManagement extends plugin
23 {
24   /* Definitions */
25   var $plHeadline= "Departments";
26   var $plDescription= "This does something";
28   /* CLI vars */
29   var $cli_summary= "Handling of LDAP subtrees";
30   var $cli_description= "Some longer text\nfor help";
31   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33   /* Headpage attributes */
34   var $last_dep_sorting= "invalid";
35   var $departments= array();
36   var $deptabs= NULL;
38   /* attribute list for save action */
39   var $attributes= array();
40   var $objectclasses= array();
42   function departmentManagement ($config, $ui)
43   {
44         $this->ui= $ui;
45         $this->dn= "";
46         $this->config= $config;
48         /* Get global filter config */
49         if (!is_global("depfilter")){
50                 $base= get_base_from_people($ui->dn);
51                 $depfilter= array("depselect" => $base,
52                                   "regex" => "*");
53                 register_global("depfilter", $depfilter);
54         }
55   }
57   function execute()
58   {
59         /* Reload departments */
60         $this->config->departments= get_departments();
61         $this->config->make_idepartments();
62         $smarty= get_smarty();
64         /* Save data */
65         $depfilter= get_global("depfilter");
66         foreach( array("depselect", "regex") as $type){
67                 if (isset($_POST[$type])){
68                         $depfilter[$type]= $_POST[$type];
69                 }
70         }
71         if (isset($_GET['search'])){
72                 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
73                 if ($s == "**"){
74                         $s= "*";
75                 }
76                 $depfilter['regex']= $s;
77         }
78         register_global("depfilter", $depfilter);
81         /* Create new department? */
82         if (isset($_POST['new_department'])){
83                 $this->acl= array(":all");
84                 $this->dn= "new";
86                 /* Register deptabs to trigger edit dialog */
87                 $this->deptabs= new deptabs($this->config,
88                                 $this->config->data['TABS']['DEPTABS'], $this->dn);
89                 $this->deptabs->set_acl($this->acl);
90         }
92         /* Edit existing department */
93         if ((isset($_POST['select_department']) || (isset($_POST['edit_helper']) && $_POST['edit_helper'] == "1")) && isset($_POST['deplist']) != ""){
94                 $this->dn= $this->config->departments[trim($_POST['deplist'])];
96                 /* Check locking, save current plugin in 'back_plugin', so
97                    the dialog knows where to return. */
98                 if (($user= get_lock($this->dn)) != ""){
99                         return(gen_locked_message ($user, $this->dn));
100                 }
102                 /* Lock the current entry, so everyone will get the
103                    above dialog */
104                 add_lock ($this->dn, $this->ui->dn);
106                 /* Set up the users ACL's for this 'dn' */
107                 $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
109                 /* Register deptabs to trigger edit dialog */
110                 $this->deptabs= new deptabs($this->config,
111                                 $this->config->data['TABS']['DEPTABS'], $this->dn);
112                 $this->deptabs->set_acl($this->acl);
113                 $_SESSION['objectinfo']= $this->dn;
114         }
117         /* Delete requested department */
118         $display= "";
119         if (isset($_POST['delete_department']) && isset($_POST['deplist'])){
120                 $this->dn= $this->config->departments[trim($_POST['deplist'])];
122                 /* Check locking */
123                 if (($user= get_lock($this->dn)) != ""){
124                         $_SESSION['dn']= $this->dn;
125                         return(gen_locked_message($user, $this->dn));
126                 } else {
127                         # Lock this dn for editing
128                         add_lock ($this->dn, $this->ui->dn);
130                         $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
131                         $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
132                         return ($display);
133                 }
134         }
136         /* Finally delete department */
137         if (isset($_POST['delete_department_confirm'])){
138                 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
139                 $acl= get_module_permission($acl, "department", $this->dn);
140                 if (chkacl($acl, "all") == ""){
141                         $this->remove_from_parent();
142                         gosa_log ("Department object'".$this->dn."' has been removed");
143                         $this->reload ();
144                 } else {
145                         print_red (_("You have no permission to remove this department."));
146                 }
147         }
149         /* Finish request */
150        if (isset($_POST['edit_finish'])){
152                 /* Check tabs, will feed message array */
153                 $message= $this->deptabs->check();
155                 /* Save, or display error message? */
156                 if (count($message) == 0){
158                         /* Save user data to ldap */
159                         $this->deptabs->save();
160                         gosa_log ("Department object'".$this->dn."' has been saved");
162                         /* Group has been saved successfully, remove lock from
163                            LDAP. */
164                         if ($this->dn != "new"){
165                                 del_lock ($this->dn);
166                         }
168                         /* There's no page reload so we have to read new users at
169                            this point. */
170                         $this->reload ();
171                         unset ($this->deptabs);
172                         $this->deptabs= NULL;
173                         unset ($_SESSION['objectinfo']);
175                 } else {
176                         /* Ok. There seem to be errors regarding to the tab data,
177                            show message and continue as usual. */
178                         show_errors($message);
179                 }
180         }
183         /* Cancel dialog */
184         if (isset($_POST['edit_cancel']) || isset($_POST['delete_cancel']) ||
185                 isset($_POST['delete_department_confirm']) || isset($_POST['delete_lock'])){
187                 del_lock ($this->dn);
188                 unset($this->depdabs);
189                 $this->deptabs= NULL;
190                 unset ($_SESSION['objectinfo']);
191         }
194         /* Headpage or normal plugin screen? */
195         if ($this->deptabs == NULL){
196                 /* Check sorting variable */
197                 $this->reload();
199                 /* Check for exeeded sizelimit */
200                 if (($message= check_sizelimit()) != ""){
201                         return($message);
202                 }
204                 /* Show main page */
205                 $smarty->assign("departments", $this->departments);
206                 $smarty->assign("search_image", get_template_path('images/search.png'));
207                 $smarty->assign("tree_image", get_template_path('images/tree.png'));
208                 $smarty->assign("infoimage", get_template_path('images/info.png'));
209                 $smarty->assign("launchimage", get_template_path('images/launch.png'));
210                 $smarty->assign("deplist", $this->config->idepartments);
211                 foreach( array("depselect", "regex") as $type){
212                         $smarty->assign("$type", $depfilter[$type]);
213                 }
215                 /* Extend if we are not using javascript */
216                 $smarty->assign("apply", apply_filter());
217                 $smarty->assign("alphabet", generate_alphabet());
218                 $smarty->assign("hint", print_sizelimit_warning());
220                 $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
221                 return($display);
222         }
224         /* Show main page (tabs) */
225         $display= $this->deptabs->execute();
227         $display.= "<p style=\"text-align:right\">\n";
228         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
229         $display.= "&nbsp;\n";
230         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
231         $display.= "</p>";
233         return ($display);
234   }
237   function reload()
238   {
239         /* Get config */
240         $depfilter= get_global('depfilter');
242         /* Set base for all searches */
243         $base= $depfilter['depselect'];
245         /* Regex filter? */
246         if ($depfilter['regex'] != ""){
247                 $regex= $depfilter['regex'];
248         } else {
249                 $regex= "*";
250         }
252         /*Get all gosaDepartments */
253         $res= get_list($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))", TRUE, $base, array("ou", "description"), TRUE);
255         $this->departments= array();
256         foreach ($res as $value){
257                 $title= convert_department_dn($value["dn"]);
258                 $this->departments[$title]= "$title [".$value["description"][0]."]";
259         }
260         natcasesort ($this->departments);
261         reset ($this->departments);
262   }
264   function remove_from_parent()
265   {
266         $ldap= $this->config->get_ldap_link();
267         $ldap->cd ($this->dn);
268         $ldap->recursive_remove();
270         /* Optionally execute a command after we're done */
271         $this->postremove();
273         /* Delete references to object groups */
274         $ldap->cd ($this->config->current['BASE']);
275         $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
276         while ($ldap->fetch()){
277                 $og= new ogroup($this->config, $ldap->getDN());
278                 unset($og->member[$this->dn]);
279                 $og->save ();
280         }
282   }
284   function remove_lock()
285   {
286         if (isset($this->dn)){
287                 del_lock ($this->dn);
288         }
289   }
293 ?>