Code

Added imagick alternative for icon conversion
[gosa.git] / plugins / admin / applications / class_applicationManagement.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_application.inc";
22 class applicationManagement extends plugin
23 {
24   /* Definitions */
25   var $plHeadline= "Applications";
26   var $plDescription= "This does something";
28   /* Dialog attributes */
29   var $apptabs= NULL;
30   var $applications= array();
31   var $ui= NULL;
32   var $acl= "";
34   function applicationManagement ($config, $ui)
35   {
36         /* Save configuration for internal use */
37         $this->config= $config;
38         $this->ui= $ui;
40         /* Get global filter config */
41         if (!is_global("appfilter")){
42                 $base= get_base_from_people($ui->dn);
43                 $appfilter= array("depselect" => $base,
44                                   "regex" => "*");
45                 register_global("appfilter", $appfilter);
46         }
47   }
49   function execute()
50   {
51         /* Save data */
52         $appfilter= get_global("appfilter");
53         foreach( array("depselect", "regex") as $type){
54                 if (isset($_POST[$type])){
55                         $appfilter[$type]= $_POST[$type];
56                 }
57         }
58         if (isset($_GET['search'])){
59                 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
60                 if ($s == "**"){
61                         $s= "*";
62                 }
63                 $appfilter['regex']= $s;
64         }
65         register_global("appfilter", $appfilter);
67         /* Check sorting variable */
68         if (!isset($this->apptabs) &&
69             !isset($_POST['new_app']) &&
70             !isset($_POST['delete_app']) &&
71             !isset($_POST['select_app'])){
72                 $this->reload();
73         }
74         $smarty= get_smarty();
76         /* Check for exeeded sizelimit */
77         if (($message= check_sizelimit()) != ""){
78                 return($message);
79         }
81         /* New application? */
82         if (isset($_POST['new_app'])){
84                 /* By default we set 'dn' to 'new', all relevant plugins will
85                    react on this. */
86                 $this->dn= "new";
88                 /* Create new usertab object */
89                 $this->apptabs= new apptabs($this->config,
90                                 $this->config->data['TABS']['APPSTABS'], $this->dn);
91                 $this->apptabs->set_acl(array(':all'));
92         }
94         /* Cancel dialogs */
95         if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
96                 del_lock ($this->apptabs->dn);
97                 unset ($this->apptabs);
98                 $this->apptabs= NULL;
99                 unset ($_SESSION['objectinfo']);
100         }
102         /* Finish apps edit is triggered by the tabulator dialog, so
103            the user wants to save edited data. Check and save at this
104            point. */
105         if (isset($_POST['edit_finish'])){
107                 /* Check tabs, will feed message array */
108                 $this->apptabs->last= $this->apptabs->current;
109                 $this->apptabs->save_object();
110                 $message= $this->apptabs->check();
112                 /* Save, or display error message? */
113                 if (count($message) == 0){
115                         /* Save data data to ldap */
116                         $this->apptabs->save();
117                         gosa_log ("Application object'".$this->dn."' has been saved");
119                         /* Application has been saved successfully, remove lock from
120                            LDAP. */
121                         if ($this->dn != "new"){
122                                 del_lock ($this->dn);
123                         }
125                         /* There's no page reload so we have to read new apps at
126                            this point. */
127                         $this->reload ();
128                         unset ($this->apptabs);
129                         $this->apptabs= NULL;
130                         unset ($_SESSION['objectinfo']);
131                 } else {
132                         /* Ok. There seem to be errors regarding to the tab data,
133                            show message and continue as usual. */
134                         show_errors($message);
135                 }
136         }
138         /* User wants to edit data? */
139         if ((isset($_POST['select_app']) || (isset($_POST['edit_helper']) && $_POST['edit_helper'] == "1")) && isset($_POST['applist']) && $_POST['applist'] != ""){
141                 /* Get 'dn' from posted 'applist', must be unique */
142                 $this->dn= trim($_POST['applist']);
144                 /* Check locking, save current plugin in 'back_plugin', so
145                    the dialog knows where to return. */
146                 if (($user= get_lock($this->dn)) != ""){
147                         return(gen_locked_message ($user, $this->dn));
148                 }
150                 /* Lock the current entry, so everyone will get the
151                    above dialog */
152                 add_lock ($this->dn, $this->ui->dn);
154                 /* Set up the users ACL's for this 'dn' */
155                 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
157                 /* Register apptabs to trigger edit dialog */
158                 $this->apptabs= new apptabs($this->config,
159                                 $this->config->data['TABS']['APPSTABS'], $this->dn);
160                 $this->apptabs->set_acl($acl);
161                 $_SESSION['objectinfo']= $this->dn;
162         }
164         /* Remove user was requested */
165         if (isset($_POST['delete_app']) && isset($_POST['applist'])){
167                 /* Get 'dn' from posted 'uid' */
168                 $this->dn= trim($_POST['applist']);
170                 /* Load permissions for selected 'dn' and check if
171                    we're allowed to remove this 'dn' */
172                 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
173                 $this->acl= get_module_permission($acl, "application", $this->dn);
174                 if (chkacl($this->acl, "delete") == ""){
176                         /* Check locking, save current plugin in 'back_plugin', so
177                            the dialog knows where to return. */
178                         if (($user= get_lock($this->dn)) != ""){
179                                 return (gen_locked_message ($user, $this->dn));
180                         }
182                         /* Lock the current entry, so nobody will edit it during deletion */
183                         add_lock ($this->dn, $this->ui->dn);
184                         $smarty= get_smarty();
185                         $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), $this->dn));
186                         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
187                 } else {
189                         /* Obviously the user isn't allowed to delete. Show message and
190                            clean session. */
191                         print_red (_("You are not allowed to delete this application!"));
192                 }
193         }
195         /* Confirmation for deletion has been passed. Group should be deleted. */
196         if (isset($_POST['delete_app_confirm'])){
198                 /* Some nice guy may send this as POST, so we've to check
199                    for the permissions again. */
200                 if (chkacl($this->acl, "delete") == ""){
202                         /* Delete request is permitted, perform LDAP action */
203                         $this->apptabs= new apptabs($this->config,
204                                         $this->config->data['TABS']['APPSTABS'], $this->dn);
205                         $this->apptabs->set_acl(array($this->acl));
206                         $this->apptabs->delete ();
207                         gosa_log ("Application object'".$this->dn."' has been removed");
208                         unset ($this->apptabs);
209                         $this->apptabs= NULL;
211                         /* Group list has changed, reload it. */
212                         $this->reload ();
213                 } else {
215                         /* Normally this shouldn't be reached, send some extra
216                            logs to notify the administrator */
217                         print_red (_("You are not allowed to delete this application!"));
218                         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
219                 }
221                 /* Remove lock file after successfull deletion */
222                 del_lock ($this->dn);
223         }
226         /* Delete application canceled? */
227         if (isset($_POST['delete_cancel'])){
228                 del_lock ($this->dn);
229                 unset($_SESSION['objectinfo']);
230         }
232         /* Show tab dialog if object is present */
233         if ($this->apptabs){
234                 $display= $this->apptabs->execute();
236                 /* Don't show buttons if tab dialog requests this */
237                 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
238                         $display.= "<p style=\"text-align:right\">\n";
239                         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
240                         $display.= "&nbsp;\n";
241                         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
242                         $display.= "</p>";
243                 }
244                 return ($display);
245         }
247         /* Show main page */
248         $smarty->assign("applications", $this->applications);
249         $smarty->assign("search_image", get_template_path('images/search.png'));
250         $smarty->assign("tree_image", get_template_path('images/tree.png'));
251         $smarty->assign("infoimage", get_template_path('images/info.png'));
252         $smarty->assign("launchimage", get_template_path('images/launch.png'));
253         $smarty->assign("deplist", $this->config->idepartments);
254         foreach( array("depselect", "regex") as $type){
255                 $smarty->assign("$type", $appfilter[$type]);
256         }
257         
258         /* Extend if we are not using javascript */
259         $smarty->assign("apply", apply_filter());
260         $smarty->assign("alphabet", generate_alphabet());
261         $smarty->assign("hint", print_sizelimit_warning());
262         
263         return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
264   }
267   function reload()
268   {
269         /* Get config */
270         $appfilter= get_global('appfilter');
272         /* Set base for all searches */
273         $base= $appfilter['depselect'];
275         /* Regex filter? */
276         if ($appfilter['regex'] != ""){
277                 $regex= $appfilter['regex'];
278         } else {
279                 $regex= "*";
280         }
281         
282         /* Generate application list */
283         $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)(objectClass=gosaApplication))", TRUE, $base, array("cn", "description"), TRUE);
284         $this->applications= array();
285         foreach ($res as $value){
286                 $this->applications[$value["dn"]]= $value["cn"][0];
287                 if (isset($value["description"][0])){
288                         $this->applications[$value["dn"]]= $value["cn"][0]." (".
289                                         $value["description"][0].")";
290                 }
291         }
292         natcasesort ($this->applications);
293         reset ($this->applications);
294   }
296   function remove_from_parent()
297   {
298         /* Optionally execute a command after we're done */
299         $this->postremove();
300   }
303   /* Save data to object */
304   function save_object()
305   {
306   }
309   /* Check values */
310   function check()
311   {
312   }
315   /* Save to LDAP */
316   function save()
317   {
318         /* Optionally execute a command after we're done */
319         $this->postcreate();
320   }
322   function adapt_from_template($dn)
323   {
324   }
326   function password_change_needed()
327   {
328   }
330   function show_header($button_text, $text, $disabled= FALSE)
331   {
332   }
334   function remove_lock()
335   {
336         if (isset($this->apptabs->dn)){
337                 del_lock ($this->apptabs->dn);
338         }
339   }
343 ?>