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