Code

removed reload calls
[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     }
65     /* Test Posts */
66     foreach($_POST as $key => $val){
67       // Post for delete
68       if(preg_match("/appl_del.*/",$key)){
69         $s_action = "del";
70         $s_entry  = preg_replace("/appl_".$s_action."_/i","",$key);
71         // Post for edit
72       }elseif(preg_match("/appl_edit_.*/",$key)){
73         $s_action="edit";
74         $s_entry  = preg_replace("/appl_".$s_action."_/i","",$key);
75         // Post for new
76       }elseif(preg_match("/dep_back.*/i",$key)){
77         $s_action="back";
78       }elseif(preg_match("/appl_new.*/",$key)){
79         $s_action="new";
80       }elseif(preg_match("/dep_home.*/i",$key)){
81         $s_action="home";
82       }elseif(preg_match("/dep_root.*/i",$key)){
83         $s_action="root";
84       }
85     }
87     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
88       $s_action ="edit";
89       $s_entry  = $_GET['id'];
90     }
92     $s_entry  = preg_replace("/_.$/","",$s_entry);
94     /* Department changed? */
95     if(isset($_POST['depselect']) && $_POST['depselect']){
96       $appfilter['depselect']= $_POST['depselect'];
97     }
99     /* Homebutton is posted */
100     if($s_action=="home"){
101       $appfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
102       $appfilter['depselect']=(preg_replace("/^[^,]+,/","",$appfilter['depselect']));
103     }
105     if($s_action=="root"){
106       $appfilter['depselect']=($this->config->current['BASE']);
107     }
109     /* If Backbutton is Posted */
110     if($s_action=="back"){
111       $base_back          = preg_replace("/^[^,]+,/","",$appfilter['depselect']);
112       $base_back          = convert_department_dn($base_back);
114       if(isset($this->config->departments[trim($base_back)])){
115         $appfilter['depselect']= $this->config->departments[trim($base_back)];
116       }else{
117         $appfilter['depselect']= $this->config->departments["/"];
118       }
119     }
121     if (isset($_POST['regex'])){
122       $appfilter['regex']= $_POST['regex'];
123     }
124     if (isset($_GET['search'])){
125       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
126       if ($s == "**"){
127         $s= "*";
128       }
129       $appfilter['regex']= $s;
130     }
131     register_global("appfilter", $appfilter);
133     /* Check sorting variable */
134     $this->reload();
135     $smarty= get_smarty();
137     /* Check for exeeded sizelimit */
138     if (($message= check_sizelimit()) != ""){
139       return($message);
140     }
143     /* New application? */
144     if ($s_action=="new"){
146       /* By default we set 'dn' to 'new', all relevant plugins will
147          react on this. */
148       $this->dn= "new";
150       /* Create new usertab object */
151       $this->apptabs= new apptabs($this->config,
152           $this->config->data['TABS']['APPSTABS'], $this->dn);
153       $this->apptabs->set_acl(array(':all'));
154     }
156     /* Cancel dialogs */
157     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
158       del_lock ($this->apptabs->dn);
159       unset ($this->apptabs);
160       $this->apptabs= NULL;
161       unset ($_SESSION['objectinfo']);
162     }
164     /* Finish apps edit is triggered by the tabulator dialog, so
165        the user wants to save edited data. Check and save at this
166        point. */
167     if (isset($_POST['edit_finish'])){
169       /* Check tabs, will feed message array */
170       $this->apptabs->last= $this->apptabs->current;
171       $this->apptabs->save_object();
172       $message= $this->apptabs->check();
174       /* Save, or display error message? */
175       if (count($message) == 0){
177         /* Save data data to ldap */
178         $this->apptabs->save();
179                         gosa_log ("Application object'".$this->dn."' has been saved");
181                         /* Application has been saved successfully, remove lock from
182                            LDAP. */
183                         if ($this->dn != "new"){
184                                 del_lock ($this->dn);
185                         }
187                         /* There's no page reload so we have to read new apps at
188                            this point. */
189                         $this->reload ();
190                         unset ($this->apptabs);
191                         $this->apptabs= NULL;
192                         unset ($_SESSION['objectinfo']);
193                 } else {
194                         /* Ok. There seem to be errors regarding to the tab data,
195                            show message and continue as usual. */
196                         show_errors($message);
197                 }
198         }
200         /* User wants to edit data? */
201         if ($s_action=="edit"){
203                 /* Get 'dn' from posted 'applist', must be unique */
204                 $this->dn= $this->applications[$s_entry]['dn'];
206                 /* Check locking, save current plugin in 'back_plugin', so
207                    the dialog knows where to return. */
208                 if (($user= get_lock($this->dn)) != ""){
209                         return(gen_locked_message ($user, $this->dn));
210                 }
212                 /* Lock the current entry, so everyone will get the
213                    above dialog */
214                 add_lock ($this->dn, $this->ui->dn);
216                 /* Set up the users ACL's for this 'dn' */
217                 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
219                 /* Register apptabs to trigger edit dialog */
220                 $this->apptabs= new apptabs($this->config,
221                                 $this->config->data['TABS']['APPSTABS'], $this->dn);
222                 $this->apptabs->set_acl($acl);
223                 $_SESSION['objectinfo']= $this->dn;
224         }
226         /* Remove user was requested */
227         if ($s_action == "del"){
229                 /* Get 'dn' from posted 'uid' */
230                 $this->dn= $this->applications[$s_entry]['dn'];
232                 /* Load permissions for selected 'dn' and check if
233                    we're allowed to remove this 'dn' */
234                 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
235                 $this->acl= get_module_permission($acl, "application", $this->dn);
236                 if (chkacl($this->acl, "delete") == ""){
238                         /* Check locking, save current plugin in 'back_plugin', so
239                            the dialog knows where to return. */
240                         if (($user= get_lock($this->dn)) != ""){
241                                 return (gen_locked_message ($user, $this->dn));
242                         }
244                         /* Lock the current entry, so nobody will edit it during deletion */
245                         add_lock ($this->dn, $this->ui->dn);
246                         $smarty= get_smarty();
247                         $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), $this->dn));
248                         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
249                 } else {
251                         /* Obviously the user isn't allowed to delete. Show message and
252                            clean session. */
253                         print_red (_("You are not allowed to delete this application!"));
254                 }
255         }
257         /* Confirmation for deletion has been passed. Group should be deleted. */
258         if (isset($_POST['delete_app_confirm'])){
260                 /* Some nice guy may send this as POST, so we've to check
261                    for the permissions again. */
262                 if (chkacl($this->acl, "delete") == ""){
264                         /* Delete request is permitted, perform LDAP action */
265                         $this->apptabs= new apptabs($this->config,
266                                         $this->config->data['TABS']['APPSTABS'], $this->dn);
267                         $this->apptabs->set_acl(array($this->acl));
268                         $this->apptabs->delete ();
269                         gosa_log ("Application object'".$this->dn."' has been removed");
270                         unset ($this->apptabs);
271                         $this->apptabs= NULL;
273                         /* Group list has changed, reload it. */
274                         $this->reload ();
275                 } else {
277                         /* Normally this shouldn't be reached, send some extra
278                            logs to notify the administrator */
279                         print_red (_("You are not allowed to delete this application!"));
280                         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
281                 }
283                 /* Remove lock file after successfull deletion */
284                 del_lock ($this->dn);
285         }
288         /* Delete application canceled? */
289         if (isset($_POST['delete_cancel'])){
290                 del_lock ($this->dn);
291                 unset($_SESSION['objectinfo']);
292         }
294         /* Show tab dialog if object is present */
295         if ($this->apptabs){
296                 $display= $this->apptabs->execute();
298                 /* Don't show buttons if tab dialog requests this */
299                 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
300                         $display.= "<p style=\"text-align:right\">\n";
301                         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
302                         $display.= "&nbsp;\n";
303                         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
304                         $display.= "</p>";
305                 }
306                 return ($display);
307         }
309         /* Show main page */
311         /* Prepare departments */
312         $options= "";
313         foreach ($this->config->idepartments as $key => $value){
314           if ($appfilter['depselect'] == $key){
315             $options.= "<option selected value='$key'>$value</option>";
316           } else {
317             $options.= "<option value='$key'>$value</option>";
318           }
319         }
320         
321         // Managment
322         $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
323           " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
324           " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
325           " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
326           " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
327           " <input type='image' align='middle' src='images/list_new_app.png' alt='"._("new")."' title='"._("Create new application")."' name='appl_new'>&nbsp;".
328           " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
329           _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
330           " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
331           "</div>";
334         $actions = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
335         $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
337         // Defining Links
338         $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
340         // image Buttons
341         $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
342         $userimg  = "<img src='images/select_groups.png' alt='User'    title='%s'>";
344         // Extension images
345         $applimg  = "<img src='images/select_application.png' alt='A'  title='"._("Application")."'>";
347         // Space
348         $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
351         $divlist = new divlist("applicationtabs");
352         $divlist->SetHeader(array(
353               array("string" => ""),
354               array("string" => _("Application name")." / "._("Department")),
355               array("string" => _("Actions")    ,"attach"=>"style='border:none;width:40px;'")
356               ));
359         $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
360         $divlist->SetEntriesPerPage(20);
362         foreach($this->departments as $key=> $val){
364           if(!isset($this->config->departments[trim($key)])){
365             $this->config->departments[trim($key)]="";
366           }
368           $non_empty="";
369           $keys= str_replace("/","\/",$key);
370           foreach($this->config->departments as $keyd=>$vald ){
371             if(preg_match("/".$keys."\/.*/",$keyd)){
372               $non_empty="full";
373             }
374           }
376           $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
377           $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
378           $field3 = array("string" => "&nbsp;","attach"=>"style='text-align:right;border:none'");
380           $divlist->AddEntry(array($field1,$field2,$field3));
381         }
383         foreach($this->applications as $key => $val){
384           $title = "title='dn : ".$val['dn']."'";
386           if(!isset($val['description'][0])){
387             $desc = "";
388           }else{
389             $desc = " - [ ".$val['description'][0]." ]";
390           }
391           $field1 = array("string" => sprintf($applimg,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
392           $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)),"attach"=>$title);
393           $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions),"attach"=>"style='text-align:right;border:none'");
395           $divlist->AddEntry(array($field1,$field2,$field3));
396         }
398         $smarty->assign("applicationshead", $listhead);
399         $smarty->assign("applications", $divlist->DrawList());
400         $smarty->assign("search_image", get_template_path('images/search.png'));
401         $smarty->assign("tree_image", get_template_path('images/tree.png'));
402         $smarty->assign("infoimage", get_template_path('images/info.png'));
403         $smarty->assign("launchimage", get_template_path('images/launch.png'));
404         $smarty->assign("deplist", $this->config->idepartments);
405         $smarty->assign("regex", $appfilter['regex']);
407         /* Extend if we are not using javascript */
408         $smarty->assign("apply", apply_filter());
409         $smarty->assign("alphabet", generate_alphabet());
410         $smarty->assign("hint", print_sizelimit_warning());
412         return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
413   }
416   function reload()
417   {
418         /* Get config */
419         $appfilter= get_global('appfilter');
421         /* Set base for all searches */
422         $base= $appfilter['depselect'];
424         /* Regex filter? */
425         if ($appfilter['regex'] != ""){
426                 $regex= $appfilter['regex'];
427         } else {
428                 $regex= "*";
429         }
431         /* Generate application list */
432         $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)(objectClass=gosaApplication))", TRUE, $base, array("*"), TRUE);
433         $this->applications= array();
434         foreach ($res as $value){
435           $this->applications[]= $value;
436         }
437         reset ($this->applications);
441         /* NEW LIST MANAGMENT
442          * We also need to search for the departments
443          * So we are able to navigate like in konquerer
444          */
445         $base2 = preg_replace("/ou=people,/i","",$base);
447         $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
448             TRUE, $base2, array("ou", "description"), TRUE);
452         $this->departments= array();
453         $tmp = array();
454         foreach ($res3 as $value){
455           $tmp[strtolower($value['dn']).$value['dn']]=$value;
456         }
457         ksort($tmp);
458         foreach($tmp as $value){
459           if($value["description"][0]!=".."){
460             $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
461           }else{
462             $this->departments[$value['dn']]=$value["description"][0];
463           }
464         }
467         /* END NEW LIST MANAGMENT
468          */
470       $tmp=array();
471     foreach($this->applications as $tkey => $val ){
472       $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
473     }
474     ksort($tmp);
475     $this->applications=array();
476     foreach($tmp as $val){
477       $this->applications[]=$val;
478     }
479     reset ($this->applications);
482   }
484   function remove_from_parent()
485   {
486         /* Optionally execute a command after we're done */
487         $this->postremove();
488   }
491   /* Save data to object */
492   function save_object()
493   {
494   }
497   /* Check values */
498   function check()
499   {
500   }
503   /* Save to LDAP */
504   function save()
505   {
506         /* Optionally execute a command after we're done */
507         $this->postcreate();
508   }
510   function adapt_from_template($dn)
511   {
512   }
514   function password_change_needed()
515   {
516   }
518   function show_header($button_text, $text, $disabled= FALSE)
519   {
520   }
522   function remove_lock()
523   {
524         if (isset($this->apptabs->dn)){
525                 del_lock ($this->apptabs->dn);
526         }
527   }
530 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
531 ?>