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 var $CopyPasteHandler ;
36 var $enableCopyPaste = false;
38 function applicationManagement ($config, $ui)
39 {
40 /* Save configuration for internal use */
41 $this->config= $config;
42 $this->ui= $ui;
45 if( (isset($this->config->data['MAIN']['ENABLECOPYPASTE']))
46 &&
47 (preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE'] ))){
48 $this->enableCopyPaste = true;
49 }
53 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
55 /* Get global filter config */
56 if (!is_global("appfilter")){
57 $base= get_base_from_people($ui->dn);
58 $appfilter= array("depselect" => $base,
59 "regex" => "*");
60 register_global("appfilter", $appfilter);
61 }
62 }
64 function execute()
65 {
66 /* Call parent execute */
67 plugin::execute();
69 // print_a($_POST);
70 // print_a($_GET);
71 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/");
73 /* Save data */
74 $appfilter = get_global("appfilter");
75 $smarty = get_smarty(); // Smarty instance
76 $s_action = ""; // Contains the action to proceed
77 $s_entry = ""; // The value for s_action
78 $base_back = ""; // The Link for Backbutton
80 /* Start for New List Managment */
81 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
82 $s_action="open";
83 $s_entry = base64_decode($_GET['dep_id']);
84 $appfilter['depselect']= "".$this->config->departments[trim($s_entry)];
85 }
87 /* Test Posts */
88 foreach($_POST as $key => $val){
89 // Post for delete
90 if(preg_match("/appl_del.*/",$key)){
91 $s_action = "del";
92 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
93 // Post for edit
94 }elseif(preg_match("/appl_edit_.*/",$key)){
95 $s_action="edit";
96 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
97 // Post for new
98 }elseif(preg_match("/^copy_.*/",$key)){
99 $s_action="copy";
100 $s_entry = preg_replace("/^copy_/i","",$key);
101 }elseif(preg_match("/^cut_.*/",$key)){
102 $s_action="cut";
103 $s_entry = preg_replace("/^cut_/i","",$key);
104 // Post for new
105 }elseif(preg_match("/^dep_back.*/i",$key)){
106 $s_action="back";
107 }elseif(preg_match("/^appl_new.*/",$key)){
108 $s_action="new";
109 }elseif(preg_match("/^dep_home.*/i",$key)){
110 $s_action="home";
111 }elseif(preg_match("/^dep_root.*/i",$key)){
112 $s_action="root";
113 }elseif(preg_match("/^editPaste.*/i",$key)){
114 $s_action="editPaste";
115 }
116 }
118 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
119 $s_action ="edit";
120 $s_entry = $_GET['id'];
121 }
123 $s_entry = preg_replace("/_.$/","",$s_entry);
125 /* Department changed? */
126 if(isset($_POST['depselect']) && $_POST['depselect']){
127 $appfilter['depselect']= $_POST['depselect'];
128 }
130 /* Homebutton is posted */
131 if($s_action=="home"){
132 $appfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
133 $appfilter['depselect']=(preg_replace("/^[^,]+,/","",$appfilter['depselect']));
134 }
136 if($s_action=="root"){
137 $appfilter['depselect']=($this->config->current['BASE']);
138 }
140 /* If Backbutton is Posted */
141 if($s_action=="back"){
142 $base_back = preg_replace("/^[^,]+,/","",$appfilter['depselect']);
143 $base_back = convert_department_dn($base_back);
145 if(isset($this->config->departments[trim($base_back)])){
146 $appfilter['depselect']= $this->config->departments[trim($base_back)];
147 }else{
148 $appfilter['depselect']= $this->config->departments["/"];
149 }
150 }
152 if (isset($_POST['regex'])){
153 $appfilter['regex']= $_POST['regex'];
154 }
155 if (isset($_GET['search'])){
156 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
157 if ($s == "**"){
158 $s= "*";
159 }
160 $appfilter['regex']= $s;
161 }
162 register_global("appfilter", $appfilter);
164 /* Check sorting variable */
165 $this->reload();
166 $smarty= get_smarty();
168 /* Check for exeeded sizelimit */
169 if (($message= check_sizelimit()) != ""){
170 return($message);
171 }
174 /* Only perform copy / paste if it is enabled
175 */
176 if($this->enableCopyPaste){
178 /* Paste copied/cutted object in here
179 */
180 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
181 $this->CopyPasteHandler->save_object();
182 $this->CopyPasteHandler->SetVar("base",$appfilter['depselect']);
183 return($this->CopyPasteHandler->execute());
184 }
187 /* Copy current object to CopyHandler
188 */
189 if($s_action == "copy"){
190 $this->CopyPasteHandler->Clear();
191 $dn = $this->applications[$s_entry]['dn'];
192 $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn);
193 $objNew = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], "new");
194 $this->CopyPasteHandler->Copy($obj,$objNew);
195 }
198 /* Copy current object to CopyHandler
199 */
200 if($s_action == "cut"){
201 $this->CopyPasteHandler->Clear();
202 $dn = $this->applications[$s_entry]['dn'];
203 $obj = new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn);
204 $this->CopyPasteHandler->Cut($obj);
205 }
206 }
208 /* New application? */
209 if ($s_action=="new"){
211 /* By default we set 'dn' to 'new', all relevant plugins will
212 react on this. */
213 $this->dn= "new";
215 /* Create new usertab object */
216 $this->apptabs= new apptabs($this->config,
217 $this->config->data['TABS']['APPSTABS'], $this->dn);
218 $this->apptabs->set_acl(array(':all'));
219 }
221 /* Cancel dialogs */
222 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
223 del_lock ($this->apptabs->dn);
224 unset ($this->apptabs);
225 $this->apptabs= NULL;
226 unset ($_SESSION['objectinfo']);
227 }
229 /* Finish apps edit is triggered by the tabulator dialog, so
230 the user wants to save edited data. Check and save at this
231 point. */
232 if ((isset($_POST['edit_finish'])) && (isset($this->apptabs->config))){
234 /* Check tabs, will feed message array */
235 $this->apptabs->last= $this->apptabs->current;
236 $this->apptabs->save_object();
237 $message= $this->apptabs->check();
239 /* Save, or display error message? */
240 if (count($message) == 0){
242 /* Save data data to ldap */
243 $this->apptabs->save();
244 gosa_log ("Application object'".$this->dn."' has been saved");
246 /* Application has been saved successfully, remove lock from
247 LDAP. */
248 if ($this->dn != "new"){
249 del_lock ($this->dn);
250 }
252 /* There's no page reload so we have to read new apps at
253 this point. */
254 $this->reload ();
255 unset ($this->apptabs);
256 $this->apptabs= NULL;
257 unset ($_SESSION['objectinfo']);
258 } else {
259 /* Ok. There seem to be errors regarding to the tab data,
260 show message and continue as usual. */
261 show_errors($message);
262 }
263 }
265 /* User wants to edit data? */
266 if (($s_action=="edit") && (!isset($this->apptabs->config))){
268 /* Get 'dn' from posted 'applist', must be unique */
269 $this->dn= $this->applications[$s_entry]['dn'];
271 /* Check locking, save current plugin in 'back_plugin', so
272 the dialog knows where to return. */
273 if (($user= get_lock($this->dn)) != ""){
274 return(gen_locked_message ($user, $this->dn));
275 }
277 /* Lock the current entry, so everyone will get the
278 above dialog */
279 add_lock ($this->dn, $this->ui->dn);
281 /* Set up the users ACL's for this 'dn' */
282 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
284 /* Register apptabs to trigger edit dialog */
285 $this->apptabs= new apptabs($this->config,
286 $this->config->data['TABS']['APPSTABS'], $this->dn);
287 $this->apptabs->set_acl($acl);
288 $_SESSION['objectinfo']= $this->dn;
289 }
291 /* Remove user was requested */
292 if ($s_action == "del"){
294 /* Get 'dn' from posted 'uid' */
295 $this->dn= $this->applications[$s_entry]['dn'];
297 /* Load permissions for selected 'dn' and check if
298 we're allowed to remove this 'dn' */
299 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
300 $this->acl= get_module_permission($acl, "application", $this->dn);
301 if (chkacl($this->acl, "delete") == ""){
303 /* Check locking, save current plugin in 'back_plugin', so
304 the dialog knows where to return. */
305 if (($user= get_lock($this->dn)) != ""){
306 return (gen_locked_message ($user, $this->dn));
307 }
309 /* Lock the current entry, so nobody will edit it during deletion */
310 add_lock ($this->dn, $this->ui->dn);
311 $smarty= get_smarty();
312 $smarty->assign("intro", sprintf(_("You're about to delete the application '%s'."), LDAP::fix($this->dn)));
313 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
314 } else {
316 /* Obviously the user isn't allowed to delete. Show message and
317 clean session. */
318 print_red (_("You are not allowed to delete this application!"));
319 }
320 }
322 /* Confirmation for deletion has been passed. Group should be deleted. */
323 if (isset($_POST['delete_app_confirm'])){
325 /* Some nice guy may send this as POST, so we've to check
326 for the permissions again. */
327 if (chkacl($this->acl, "delete") == ""){
329 /* Delete request is permitted, perform LDAP action */
330 $this->apptabs= new apptabs($this->config,
331 $this->config->data['TABS']['APPSTABS'], $this->dn);
332 $this->apptabs->set_acl(array($this->acl));
333 $this->apptabs->delete ();
334 gosa_log ("Application object'".$this->dn."' has been removed");
335 unset ($this->apptabs);
336 $this->apptabs= NULL;
338 /* Group list has changed, reload it. */
339 $this->reload ();
340 } else {
342 /* Normally this shouldn't be reached, send some extra
343 logs to notify the administrator */
344 print_red (_("You are not allowed to delete this application!"));
345 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
346 }
348 /* Remove lock file after successfull deletion */
349 del_lock ($this->dn);
350 }
353 /* Delete application canceled? */
354 if (isset($_POST['delete_cancel'])){
355 del_lock ($this->dn);
356 unset($_SESSION['objectinfo']);
357 }
359 /* Show tab dialog if object is present */
360 if (($this->apptabs) && (isset($this->apptabs->config))){
361 $display= $this->apptabs->execute();
363 /* Don't show buttons if tab dialog requests this */
364 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
365 $display.= "<p style=\"text-align:right\">\n";
366 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
367 $display.= " \n";
368 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
369 $display.= "</p>";
370 }
371 return ($display);
372 }
374 /* Show main page */
376 /* Prepare departments */
377 $options= "";
378 foreach ($this->config->idepartments as $key => $value){
379 if ($appfilter['depselect'] == $key){
380 $options.= "<option selected='selected' value='$key'>$value</option>";
381 } else {
382 $options.= "<option value='$key'>$value</option>";
383 }
384 }
386 if($this->enableCopyPaste){
387 $Copy_Paste = " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
389 if($this->CopyPasteHandler->isCurrentObjectPastAble()){
391 if($this->CopyPasteHandler->isCurrentCutted()){
392 $img = "images/cutpaste.png";
393 }else{
394 $img = "images/copypaste.png";
395 }
397 $Copy_Paste .= "<input type='image' name='editPaste' class='center'
398 src='".$img."' alt='"._("Paste")."' title='".$this->CopyPasteHandler->GetCurrentDn()."'> ";
399 }else{
400 $Copy_Paste .= "<img class='center' src='images/cant_editpaste.png' alt='"._("Can't paste")."'> ";
401 }
402 }else{
403 $Copy_Paste ="";
404 }
406 // Managment
407 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
408 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
409 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
410 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
411 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
412 " <input class='center' type='image' align='middle' src='images/list_new_app.png' alt='"._("new")."' title='"._("Create new application")."' name='appl_new'> ".
413 $Copy_Paste.
414 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
415 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
416 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
417 "</div>";
421 if($this->enableCopyPaste){
422 $actions = "<input class='center' type='image'
423 src='images/editdelete.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
424 $actions.= "<input class='center' type='image'
425 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
426 $actions.= "<input class='center' type='image'
427 src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
428 $actions.= "<input class='center' type='image'
429 src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
430 }else{
432 $actions = "<input class='center' type='image'
433 src='images/edit.png' alt='"._("edit")."' name='appl_edit_%KEY%' title='"._("Edit this entry")."'>";
434 $actions.= "<input class='center' type='image'
435 src='images/edittrash.png' alt='"._("delete")."' name='appl_del_%KEY%' title='"._("Delete this entry")."'>";
436 }
439 // Defining Links
440 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
442 // image Buttons
443 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
444 $userimg = "<img class='center' src='images/select_groups.png' alt='User' title='%s'>";
446 // Extension images
447 $applimg = "<img class='center' src='images/select_application.png' alt='A' title='"._("Application")."'>";
449 // Space
450 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
453 $divlist = new divlist("applicationtabs");
454 $divlist->SetHeader(array(
455 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
456 array("string" => _("Application name")." / "._("Department"), "attach" => "style=''"),
457 array("string" => _("Actions"), "attach" => "style='width:80px;border-right:0px;text-align:right;'")
458 ));
461 $divlist->SetSummary(_("This table displays all groups, in the selected tree."));
462 $divlist->SetEntriesPerPage(0);
464 foreach($this->departments as $key=> $val){
466 if(!isset($this->config->departments[trim($key)])){
467 $this->config->departments[trim($key)]="";
468 }
470 $non_empty="";
471 $keys= str_replace("/","\/",$key);
472 foreach($this->config->departments as $keyd=>$vald ){
473 if(preg_match("/".$keys."\/.*/",$keyd)){
474 $non_empty="full";
475 }
476 }
478 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
479 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
480 $field3 = array("string" => " ", "attach" => "style='width:80px;border-right:0px;text-align:right;'");
482 $divlist->AddEntry(array($field1,$field2,$field3));
483 }
485 foreach($this->applications as $key => $val){
486 $title = "title='dn : ".$val['dn']."'";
488 if(!isset($val['description'][0])){
489 $desc = "";
490 }else{
491 $desc = " - [ ".$val['description'][0]." ]";
492 }
493 $field1 = array("string" => sprintf($applimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
494 $field2 = array("string" => sprintf($editlink,$key,($val['cn']['0'].$desc)), "attach" => "style='' ".$title);
495 $field3 = array("string" => preg_replace("/%KEY%/", $key, $actions), "attach" => "style='width:80px;border-right:0px;text-align:right;'");
497 $divlist->AddEntry(array($field1,$field2,$field3));
498 }
500 $smarty->assign("applicationshead", $listhead);
501 $smarty->assign("applications", $divlist->DrawList());
502 $smarty->assign("search_image", get_template_path('images/search.png'));
503 $smarty->assign("tree_image", get_template_path('images/tree.png'));
504 $smarty->assign("infoimage", get_template_path('images/info.png'));
505 $smarty->assign("launchimage", get_template_path('images/launch.png'));
506 $smarty->assign("deplist", $this->config->idepartments);
507 $smarty->assign("regex", $appfilter['regex']);
509 /* Extend if we are not using javascript */
510 $smarty->assign("apply", apply_filter());
511 $smarty->assign("alphabet", generate_alphabet());
512 $smarty->assign("hint", print_sizelimit_warning());
514 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
515 }
518 function reload()
519 {
520 /* Get config */
521 $appfilter= get_global('appfilter');
523 /* Set base for all searches */
524 $base= $appfilter['depselect'];
526 /* Regex filter? */
527 if ($appfilter['regex'] != ""){
528 $regex= $appfilter['regex'];
529 } else {
530 $regex= "*";
531 }
533 /* Generate application list */
534 $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)(objectClass=gosaApplication))", FALSE, "ou=apps,".$base, array("*"), TRUE);
535 $this->applications= array();
536 foreach ($res as $value){
537 $this->applications[]= $value;
538 }
539 reset ($this->applications);
543 /* NEW LIST MANAGMENT
544 * We also need to search for the departments
545 * So we are able to navigate like in konquerer
546 */
547 $peopleOU = get_people_ou();
549 if(empty($peopleOU)){
550 $base2 = $base;
551 }else{
552 $base2 = preg_replace("/".$peopleOU."/i","",$base);
553 }
555 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
556 TRUE, $base2, array("ou", "description"), TRUE);
558 $this->departments= array();
559 $tmp = array();
560 foreach ($res3 as $value){
561 $tmp[strtolower($value['dn']).$value['dn']]=$value;
562 }
563 ksort($tmp);
564 foreach($tmp as $value){
565 if(isset($value["description"][0])){
566 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
567 }else{
568 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);//$value["description"][0];
569 }
570 }
573 /* END NEW LIST MANAGMENT
574 */
576 $tmp=array();
577 foreach($this->applications as $tkey => $val ){
578 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
579 }
580 ksort($tmp);
581 $this->applications=array();
582 foreach($tmp as $val){
583 $this->applications[]=$val;
584 }
585 reset ($this->applications);
588 }
590 function remove_from_parent()
591 {
592 /* Optionally execute a command after we're done */
593 $this->postremove();
594 }
597 /* Save data to object */
598 function save_object()
599 {
600 }
603 /* Check values */
604 function check()
605 {
606 }
609 /* Save to LDAP */
610 function save()
611 {
612 /* Optionally execute a command after we're done */
613 $this->postcreate();
614 }
616 function adapt_from_template($dn)
617 {
618 }
620 function password_change_needed()
621 {
622 }
624 function show_header($button_text, $text, $disabled= FALSE)
625 {
626 }
628 function remove_lock()
629 {
630 if (isset($this->apptabs->dn)){
631 del_lock ($this->apptabs->dn);
632 }
633 }
635 }
636 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
637 ?>