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