Code

changed picture 'nothing.png' to 'empty.png', because 'nothing.png' was not present
[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           $smarty       = get_smarty();             // Smarty instance
54           $s_action     = "";                       // Contains the action to proceed
55           $s_entry      = "";                       // The value for s_action
56     $base_back    = "";                       // The Link for Backbutton
58     /* Start for New List Managment */
59     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
60             $s_action="open";
61             $s_entry = base64_decode($_GET['dep_id']);
62             $appfilter['depselect']= "".$this->config->departments[trim($s_entry)];
63             $this->reload();
64     }
66     /* Test Posts */
67     foreach($_POST as $key => $val){
68       // Post for delete
69       if(preg_match("/appl_del.*/",$key)){
70         $s_action = "del";
71         $s_entry  = preg_replace("/appl_".$s_action."_/i","",$key);
72         // Post for edit
73       }elseif(preg_match("/appl_edit_.*/",$key)){
74         $s_action="edit";
75         $s_entry  = preg_replace("/appl_".$s_action."_/i","",$key);
76         // Post for new
77       }elseif(preg_match("/dep_back.*/i",$key)){
78         $s_action="back";
79       }elseif(preg_match("/appl_new.*/",$key)){
80         $s_action="new";
81       }elseif(preg_match("/dep_home.*/i",$key)){
82         $s_action="home";
83       }elseif(preg_match("/dep_root.*/i",$key)){
84         $s_action="root";
85       }
86     }
88     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
89       $s_action ="edit";
90       $s_entry  = $_GET['id'];
91     }
93     $s_entry  = preg_replace("/_.$/","",$s_entry);
95     /* Department changed? */
96     if(isset($_POST['depselect']) && $_POST['depselect']){
97       $appfilter['depselect']= $_POST['depselect'];
98       $this->reload();
99     }
101     /* Homebutton is posted */
102     if($s_action=="home"){
103       $appfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
104       $appfilter['depselect']=(preg_replace("/^[^,]+,/","",$appfilter['depselect']));
105       $this->reload();
106     }
108     if($s_action=="root"){
109       $appfilter['depselect']=($this->config->current['BASE']);
110       $this->reload();
111     }
113     /* If Backbutton is Posted */
114     if($s_action=="back"){
115       $base_back          = preg_replace("/^[^,]+,/","",$appfilter['depselect']);
116       $base_back          = convert_department_dn($base_back);
118       if(isset($this->config->departments[trim($base_back)])){
119         $appfilter['depselect']= $this->config->departments[trim($base_back)];
120       }else{
121         $appfilter['depselect']= $this->config->departments["/"];
122       }
123       $this->reload();
124     }
126     if (isset($_POST['regex'])){
127       $appfilter['regex']= $_POST['regex'];
128     }
129     if (isset($_GET['search'])){
130       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
131       if ($s == "**"){
132         $s= "*";
133       }
134       $appfilter['regex']= $s;
135     }
136     register_global("appfilter", $appfilter);
138     /* Check sorting variable */
139     if (!isset($this->apptabs) &&
140         !isset($_POST['new_app']) &&
141         !isset($_POST['delete_app']) &&
142         !isset($_POST['select_app'])){
143       $this->reload();
144     }
145     $smarty= get_smarty();
147     /* Check for exeeded sizelimit */
148     if (($message= check_sizelimit()) != ""){
149       return($message);
150     }
153     /* New application? */
154     if ($s_action=="new"){
156       /* By default we set 'dn' to 'new', all relevant plugins will
157          react on this. */
158       $this->dn= "new";
160       /* Create new usertab object */
161       $this->apptabs= new apptabs($this->config,
162           $this->config->data['TABS']['APPSTABS'], $this->dn);
163       $this->apptabs->set_acl(array(':all'));
164     }
166     /* Cancel dialogs */
167     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
168       del_lock ($this->apptabs->dn);
169       unset ($this->apptabs);
170       $this->apptabs= NULL;
171       unset ($_SESSION['objectinfo']);
172     }
174     /* Finish apps edit is triggered by the tabulator dialog, so
175        the user wants to save edited data. Check and save at this
176        point. */
177     if (isset($_POST['edit_finish'])){
179       /* Check tabs, will feed message array */
180       $this->apptabs->last= $this->apptabs->current;
181       $this->apptabs->save_object();
182       $message= $this->apptabs->check();
184       /* Save, or display error message? */
185       if (count($message) == 0){
187         /* Save data data to ldap */
188         $this->apptabs->save();
189                         gosa_log ("Application object'".$this->dn."' has been saved");
191                         /* Application has been saved successfully, remove lock from
192                            LDAP. */
193                         if ($this->dn != "new"){
194                                 del_lock ($this->dn);
195                         }
197                         /* There's no page reload so we have to read new apps at
198                            this point. */
199                         $this->reload ();
200                         unset ($this->apptabs);
201                         $this->apptabs= NULL;
202                         unset ($_SESSION['objectinfo']);
203                 } else {
204                         /* Ok. There seem to be errors regarding to the tab data,
205                            show message and continue as usual. */
206                         show_errors($message);
207                 }
208         }
210         /* User wants to edit data? */
211         if ($s_action=="edit"){
213                 /* Get 'dn' from posted 'applist', must be unique */
214                 $this->dn= $this->applications[$s_entry]['dn'];
216                 /* Check locking, save current plugin in 'back_plugin', so
217                    the dialog knows where to return. */
218                 if (($user= get_lock($this->dn)) != ""){
219                         return(gen_locked_message ($user, $this->dn));
220                 }
222                 /* Lock the current entry, so everyone will get the
223                    above dialog */
224                 add_lock ($this->dn, $this->ui->dn);
226                 /* Set up the users ACL's for this 'dn' */
227                 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
229                 /* Register apptabs to trigger edit dialog */
230                 $this->apptabs= new apptabs($this->config,
231                                 $this->config->data['TABS']['APPSTABS'], $this->dn);
232                 $this->apptabs->set_acl($acl);
233                 $_SESSION['objectinfo']= $this->dn;
234         }
236         /* Remove user was requested */
237         if ($s_action == "del"){
239                 /* Get 'dn' from posted 'uid' */
240                 $this->dn= $this->applications[$s_entry]['dn'];
242                 /* Load permissions for selected 'dn' and check if
243                    we're allowed to remove this 'dn' */
244                 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
245                 $this->acl= get_module_permission($acl, "application", $this->dn);
246                 if (chkacl($this->acl, "delete") == ""){
248                         /* Check locking, save current plugin in 'back_plugin', so
249                            the dialog knows where to return. */
250                         if (($user= get_lock($this->dn)) != ""){
251                                 return (gen_locked_message ($user, $this->dn));
252                         }
254                         /* Lock the current entry, so nobody will edit it during deletion */
255                         add_lock ($this->dn, $this->ui->dn);
256                         $smarty= get_smarty();
257                         $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), $this->dn));
258                         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
259                 } else {
261                         /* Obviously the user isn't allowed to delete. Show message and
262                            clean session. */
263                         print_red (_("You are not allowed to delete this application!"));
264                 }
265         }
267         /* Confirmation for deletion has been passed. Group should be deleted. */
268         if (isset($_POST['delete_app_confirm'])){
270                 /* Some nice guy may send this as POST, so we've to check
271                    for the permissions again. */
272                 if (chkacl($this->acl, "delete") == ""){
274                         /* Delete request is permitted, perform LDAP action */
275                         $this->apptabs= new apptabs($this->config,
276                                         $this->config->data['TABS']['APPSTABS'], $this->dn);
277                         $this->apptabs->set_acl(array($this->acl));
278                         $this->apptabs->delete ();
279                         gosa_log ("Application object'".$this->dn."' has been removed");
280                         unset ($this->apptabs);
281                         $this->apptabs= NULL;
283                         /* Group list has changed, reload it. */
284                         $this->reload ();
285                 } else {
287                         /* Normally this shouldn't be reached, send some extra
288                            logs to notify the administrator */
289                         print_red (_("You are not allowed to delete this application!"));
290                         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
291                 }
293                 /* Remove lock file after successfull deletion */
294                 del_lock ($this->dn);
295         }
298         /* Delete application canceled? */
299         if (isset($_POST['delete_cancel'])){
300                 del_lock ($this->dn);
301                 unset($_SESSION['objectinfo']);
302         }
304         /* Show tab dialog if object is present */
305         if ($this->apptabs){
306                 $display= $this->apptabs->execute();
308                 /* Don't show buttons if tab dialog requests this */
309                 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
310                         $display.= "<p style=\"text-align:right\">\n";
311                         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
312                         $display.= "&nbsp;\n";
313                         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
314                         $display.= "</p>";
315                 }
316                 return ($display);
317         }
319         /* Show main page */
321         /* Prepare departments */
322         $options= "";
323         foreach ($this->config->idepartments as $key => $value){
324           if ($appfilter['depselect'] == $key){
325             $options.= "<option selected value='$key'>$value</option>";
326           } else {
327             $options.= "<option value='$key'>$value</option>";
328           }
329         }
330         
331         // Managment
332         $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
333           " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
334           " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
335           " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
336           " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
337           " <input type='image' align='middle' src='images/list_new_app.png' alt='"._("new")."' name='appl_new'>&nbsp;".
338           " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
339           _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
340           " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
341           "</div>";
344         $actions = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
345         $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
347         // Defining Links
348         $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
350         // image Buttons
351         $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
352         $userimg  = "<img src='images/select_groups.png' alt='User'    title='%s'>";
354         // Extension images
355         $applimg  = "<img src='images/select_application.png' alt='A'  title='"._("Application")."'>";
357         // Space
358         $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
361         $divlist = new divlist();
362         $divlist->SetHeader(array(
363               array("string" => ""),
364               array("string" => _("Application name")." / "._("Department")),
365               array("string" => _("Actions")    ,"attach"=>"style='border:none;width:40px;'")
366               ));
369         $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
370         $divlist->SetEntriesPerPage(20);
372         foreach($this->departments as $key=> $val){
374           $field1 = array("string" => "<img src='images/folder.png' alt='department'>");
375           $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
376           $field3 = array("string" => "&nbsp;","attach"=>"style='text-align:right;border:none'");
378           $divlist->AddEntry(array($field1,$field2,$field3));
379         }
381         foreach($this->applications as $key => $val){
382           $title = "title='gid : ".$key." - dn : ".$val['dn']."'";
384           if(!isset($val['description'][0])){
385             $desc = "";
386           }else{
387             $desc = " - [ ".$val['description'][0]." ]";
388           }
389           $field1 = array("string" => sprintf($applimg,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
390           $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)),"attach"=>$title);
391           $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions),"attach"=>"style='text-align:right;border:none'");
393           $divlist->AddEntry(array($field1,$field2,$field3));
394         }
396         $smarty->assign("applicationshead", $listhead);
397         $smarty->assign("applications", $divlist->DrawList());
398         $smarty->assign("search_image", get_template_path('images/search.png'));
399         $smarty->assign("tree_image", get_template_path('images/tree.png'));
400         $smarty->assign("infoimage", get_template_path('images/info.png'));
401         $smarty->assign("launchimage", get_template_path('images/launch.png'));
402         $smarty->assign("deplist", $this->config->idepartments);
403         $smarty->assign("regex", $appfilter['regex']);
405         /* Extend if we are not using javascript */
406         $smarty->assign("apply", apply_filter());
407         $smarty->assign("alphabet", generate_alphabet());
408         $smarty->assign("hint", print_sizelimit_warning());
410         return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
411   }
414   function reload()
415   {
416         /* Get config */
417         $appfilter= get_global('appfilter');
419         /* Set base for all searches */
420         $base= $appfilter['depselect'];
422         /* Regex filter? */
423         if ($appfilter['regex'] != ""){
424                 $regex= $appfilter['regex'];
425         } else {
426                 $regex= "*";
427         }
429         /* Generate application list */
430         $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)(objectClass=gosaApplication))", TRUE, $base, array("*"), TRUE);
431         $this->applications= array();
432         foreach ($res as $value){
433           $this->applications[]= $value;
434         }
435         reset ($this->applications);
439         /* NEW LIST MANAGMENT
440          * We also need to search for the departments
441          * So we are able to navigate like in konquerer
442          */
443         $base2 = preg_replace("/ou=people,/i","",$base);
445         $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
446             TRUE, $base2, array("ou", "description"), TRUE);
448         $this->departments= array();
449         foreach ($res3 as $value){
450           if($value["description"][0]!=".."){
451             $this->departments[$value['dn']]= convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
452           }else{
453             $this->departments[$value['dn']]=$value["description"][0];
454           }
455         }
457         /* END NEW LIST MANAGMENT
458          */
461   }
463   function remove_from_parent()
464   {
465         /* Optionally execute a command after we're done */
466         $this->postremove();
467   }
470   /* Save data to object */
471   function save_object()
472   {
473   }
476   /* Check values */
477   function check()
478   {
479   }
482   /* Save to LDAP */
483   function save()
484   {
485         /* Optionally execute a command after we're done */
486         $this->postcreate();
487   }
489   function adapt_from_template($dn)
490   {
491   }
493   function password_change_needed()
494   {
495   }
497   function show_header($button_text, $text, $disabled= FALSE)
498   {
499   }
501   function remove_lock()
502   {
503         if (isset($this->apptabs->dn)){
504                 del_lock ($this->apptabs->dn);
505         }
506   }
509 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
510 ?>