83c870da17c6137e74b62cee7b90e61a0ccd0623
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 */
21 class applicationManagement extends plugin
22 {
23 /* Definitions */
24 var $plHeadline = "Applications";
25 var $plDescription = "This does something";
27 /* Dialog attributes */
28 var $apptabs = NULL;
29 var $ui = NULL;
30 var $CopyPasteHandler = NULL;
31 var $DivListApplication = NULL;
32 var $applications = array();
33 var $enableReleaseManagement = false;
34 var $start_pasting_copied_objects = FALSE;
36 var $app_base ="";
37 var $app_release ="";
39 function IsReleaseManagementActivated()
40 {
41 /* Check if we should enable the release selection */
42 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
43 if(!empty($tmp)){
44 return(true);
45 }
46 }
49 function applicationManagement (&$config, &$ui)
50 {
51 /* Save configuration for internal use */
52 $this->config = &$config;
53 $this->ui = &$ui;
55 /* Check if copy & paste is activated */
56 if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
57 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
58 }
60 /* Creat dialog object */
61 $this->DivListApplication = new divListApplication($this->config,$this);
63 if($this->IsReleaseManagementActivated()){
64 /* Check if we should enable the release selection */
65 $this->enableReleaseManagement = true;
67 /* Hide SubSearch checkbox */
68 $this->DivListApplication->DisableCheckBox("SubSearch");
69 }
71 /* Set default release */
72 if(!$this->IsReleaseManagementActivated()){
73 $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
74 if(!session::is_set("app_filter")){
75 session::set("app_filter",array("app_base" => $this->app_base));
76 }
77 $app_filter = session::get("app_filter");
78 $this->app_base = $app_filter['app_base'];
79 }else{
80 $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
81 if(!session::is_set("app_filter")){
82 session::set("app_filter",array("app_base" => $this->app_base,"app_release" => $this->app_base));
83 }
84 $app_filter = session::get("app_filter");
85 $this->app_base = $app_filter['app_base'];
86 $this->app_release = $app_filter['app_release'];
87 }
88 $this->app_base = "ou=apps,ou=Direktorium,o=Landeshauptstadt München,c=de";
89 $this->app_release= $this->app_base;
90 }
93 function getReleases()
94 {
95 $ldap = $this->config->get_ldap_link();
96 $ret = array();
97 $base = $this->app_base;
99 $ret[$this->app_base] = "/";
100 $ldap->cd($base);
101 $ldap->search("(&(objectClass=organizationalUnit)(objectClass=FAIbranch))",array("ou"));
102 while($attrs = $ldap->fetch()){
103 $str = str_replace($base,"",$attrs['dn']);
104 $tmp = array_reverse( split("ou=",$str));
105 $str = "";
106 foreach($tmp as $val){
107 $val = trim(preg_replace("/,/","",$val));
108 if(empty($val)) break;
109 $str .= "/".$val;
110 }
111 if(!empty($str)){
112 $ret[$attrs['dn']]= preg_replace("/^\//","",$str);
113 }
114 }
115 asort($ret);
116 return($ret);
117 }
119 function execute()
120 {
121 /* Call parent execute */
122 plugin::execute();
125 /****************
126 Variable init
127 ****************/
129 /* These vars will be stored if you try to open a locked app,
130 to be able to perform your last requests after showing a warning message */
131 session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/","/^item_selected/","/^remove_multiple_applications/"));
133 $smarty = get_smarty(); // Smarty instance
134 $s_action = ""; // Contains the action to proceed
135 $s_entry = ""; // The value for s_action
136 $base_back = ""; // The Link for Backbutton
138 /* Test Posts */
139 foreach($_POST as $key => $val){
140 // Post for delete
141 if(preg_match("/appl_del.*/",$key)){
142 $s_action = "del";
143 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
144 // Post for edit
145 }elseif(preg_match("/appl_edit_.*/",$key)){
146 $s_action="edit";
147 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
148 // Post for new
149 }elseif(preg_match("/^copy_.*/",$key)){
150 $s_action="copy";
151 $s_entry = preg_replace("/^copy_/i","",$key);
152 }elseif(preg_match("/^cut_.*/",$key)){
153 $s_action="cut";
154 $s_entry = preg_replace("/^cut_/i","",$key);
155 // Post for new
156 }elseif(preg_match("/^appl_new.*/",$key)){
157 $s_action="new";
158 }elseif(preg_match("/^remove_multiple_applications/",$key)){
159 $s_action="del_multiple";
160 }elseif(preg_match("/^editPaste.*/i",$key)){
161 $s_action="editPaste";
162 }elseif(preg_match("/^multiple_copy_groups/",$key)){
163 $s_action = "copy_multiple";
164 }elseif(preg_match("/^multiple_cut_groups/",$key)){
165 $s_action = "cut_multiple";
166 }
167 }
169 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
170 $s_action ="edit";
171 $s_entry = $_GET['id'];
172 }
174 $s_entry = preg_replace("/_.$/","",$s_entry);
177 /* handle C&P from layers menu */
178 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
179 $s_action = "copy_multiple";
180 }
181 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
182 $s_action = "cut_multiple";
183 }
184 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
185 $s_action = "editPaste";
186 }
188 /* Create options */
189 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "appl_new"){
190 $s_action = "new";
191 }
193 /* handle remove from layers menu */
194 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
195 $s_action = "del_multiple";
196 }
198 /****************
199 Copy & Paste handling
200 ****************/
202 /* Display the copy & paste dialog, if it is currently open */
203 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
204 if($ret){
205 return($ret);
206 }
208 /****************
209 Create a new app
210 ****************/
212 /* New application? */
213 if ($s_action=="new"){
215 /* By default we set 'dn' to 'new', all relevant plugins will
216 react on this. */
217 $this->dn= "new";
219 /* Create new usertab object */
220 $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
221 $this->apptabs->parent = &$this;
222 $this->apptabs->set_acl_base($this->app_base);
223 }
226 /****************
227 Edit entry canceled
228 ****************/
230 /* Cancel dialogs */
231 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
232 del_lock ($this->apptabs->dn);
233 unset ($this->apptabs);
234 $this->apptabs= NULL;
235 session::un_set('objectinfo');
236 }
239 /****************
240 Edit entry finished
241 ****************/
243 /* Finish apps edit is triggered by the tabulator dialog, so
244 the user wants to save edited data. Check and save at this
245 point. */
246 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply']) ) && (isset($this->apptabs->config))){
248 /* Check tabs, will feed message array */
249 $this->apptabs->last= $this->apptabs->current;
250 $this->apptabs->save_object();
251 $message= $this->apptabs->check();
253 /* Save, or display error message? */
254 if (count($message) == 0){
256 /* Save data data to ldap */
257 $this->apptabs->save();
259 if (!isset($_POST['edit_apply'])){
260 /* Application has been saved successfully, remove lock from
261 LDAP. */
262 if ($this->dn != "new"){
263 del_lock ($this->dn);
264 }
265 unset ($this->apptabs);
266 $this->apptabs= NULL;
267 session::un_set('objectinfo');
268 }
269 } else {
270 /* Ok. There seem to be errors regarding to the tab data,
271 show message and continue as usual. */
272 msg_dialog::displayChecks($message);
273 }
274 }
277 /****************
278 Edit entry
279 ****************/
281 /* User wants to edit data? */
282 if (($s_action=="edit") && (!isset($this->apptabs->config))){
284 /* Get 'dn' from posted 'applist', must be unique */
285 $this->dn= $this->applications[$s_entry]['dn'];
287 /* Check locking, save current plugin in 'back_plugin', so
288 the dialog knows where to return. */
289 if (($user= get_lock($this->dn)) != ""){
290 return(gen_locked_message ($user, $this->dn));
291 }
293 /* Lock the current entry, so everyone will get the
294 above dialog */
295 add_lock ($this->dn, $this->ui->dn);
297 /* Register apptabs to trigger edit dialog */
298 $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
299 $this->apptabs->parent = &$this;
300 $this->apptabs->set_acl_base($this->dn);
301 session::set('objectinfo',$this->dn);
302 }
306 /********************
307 Delete MULTIPLE entries requested, display confirm dialog
308 ********************/
310 if ($s_action=="del_multiple"){
311 $ids = $this->list_get_selected_items();
313 if(count($ids)){
315 foreach($ids as $id){
316 $dn = $this->applications[$id]['dn'];
317 $this->dns[$id] = $dn;
318 }
319 if ($user= get_multiple_locks($this->dns)){
320 return(gen_locked_message($user,$this->dns));
321 }
323 $dns_names[] = array();
324 foreach($this->dns as $dn){
325 add_lock ($dn, $this->ui->dn);
326 $dns_names[] =@LDAP::fix($dn);
327 }
329 /* Lock the current entry, so nobody will edit it during deletion */
330 $smarty->assign("intro", msgPool::deleteInfo($dns_names,_("application")));
331 $smarty->assign("multiple", true);
332 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
333 }
334 }
337 /********************
338 Delete MULTIPLE entries confirmed
339 ********************/
341 /* Confirmation for deletion has been passed. Users should be deleted. */
342 if (isset($_POST['delete_multiple_application_confirm'])){
344 /* Remove user by user and check acls before removeing them */
345 foreach($this->dns as $key => $dn){
347 $ui = get_userinfo();
348 $acl = $ui->get_permissions($dn ,"application/application");
349 if (preg_match('/d/', $acl)){
351 /* Delete request is permitted, perform LDAP action */
352 $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn,"application");
353 $this->apptabs->parent = &$this;
354 $this->apptabs->set_acl_base($dn);
355 $this->apptabs->delete ();
356 unset ($this->apptabs);
357 $this->apptabs= NULL;
359 } else {
360 /* Normally this shouldn't be reached, send some extra
361 logs to notify the administrator */
362 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
363 new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
364 }
365 /* Remove lock file after successfull deletion */
366 del_lock ($dn);
367 unset($this->dns[$key]);
368 }
369 }
372 /********************
373 Delete MULTIPLE entries Canceled
374 ********************/
376 /* Remove lock */
377 if(isset($_POST['delete_multiple_application_cancel'])){
378 foreach($this->dns as $key => $dn){
379 del_lock ($dn);
380 unset($this->dns[$key]);
381 }
382 }
384 /****************
385 Delete app
386 ****************/
388 /* Remove user was requested */
389 if ($s_action == "del"){
391 /* Get 'dn' from posted 'uid' */
392 $this->dn= $this->applications[$s_entry]['dn'];
394 /* Load permissions for selected 'dn' and check if
395 we're allowed to remove this 'dn' */
396 $ui = get_userinfo();
397 $acl = $ui->get_permissions($this->dn ,"application/application");
399 if(preg_match("/d/",$acl)){
400 /* Check locking, save current plugin in 'back_plugin', so
401 the dialog knows where to return. */
402 if (($user= get_lock($this->dn)) != ""){
403 return (gen_locked_message ($user, $this->dn));
404 }
406 /* Lock the current entry, so nobody will edit it during deletion */
407 add_lock ($this->dn, $this->ui->dn);
408 $smarty= get_smarty();
409 $smarty->assign("intro",msgPool::deleteInfo(@LDAP::fix($this->dn),_("application")));
410 $smarty->assign("multiple", false);
411 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
412 } else {
414 /* Obviously the user isn't allowed to delete. Show message and
415 clean session. */
416 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
417 }
418 }
421 /****************
422 Delete app confirmed
423 ****************/
425 /* Confirmation for deletion has been passed. Group should be deleted. */
426 if (isset($_POST['delete_app_confirm'])){
428 /* Some nice guy may send this as POST, so we've to check
429 for the permissions again. */
430 $ui = get_userinfo();
431 $acl = $ui->get_permissions($this->dn ,"application/application");
433 if(preg_match("/d/",$acl)){
435 /* Delete request is permitted, perform LDAP action */
436 $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $this->dn,"application");
437 $this->apptabs->parent = &$this;
438 $this->apptabs->set_acl_base($this->dn);
439 $this->apptabs->delete ();
440 unset ($this->apptabs);
441 $this->apptabs= NULL;
443 } else {
445 /* Normally this shouldn't be reached, send some extra
446 logs to notify the administrator */
447 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
448 new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
449 }
451 /* Remove lock file after successfull deletion */
452 del_lock ($this->dn);
453 }
456 /****************
457 Delete app canceled
458 ****************/
460 /* Delete application canceled? */
461 if (isset($_POST['delete_cancel'])){
462 del_lock ($this->dn);
463 session::un_set('objectinfo');
464 }
466 /* Show tab dialog if object is present */
467 if (($this->apptabs) && (isset($this->apptabs->config))){
468 $display= $this->apptabs->execute();
470 /* Don't show buttons if tab dialog requests this */
471 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
472 $display.= "<p style=\"text-align:right\">\n";
473 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
474 $display.= " \n";
475 if ($this->dn != "new"){
476 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
477 $display.= " \n";
478 }
479 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
480 $display.= "</p>";
481 }
482 return ($display);
483 }
486 /****************
487 Dialog display
488 ****************/
490 /* Check if there is a snapshot dialog open */
491 if($this->IsReleaseManagementActivated()){
492 $base = $this->app_release;
493 }else{
494 $base = $this->app_base;
495 }
496 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
497 return($str);
498 }
500 /* Display dialog with system list */
501 $this->DivListApplication->parent = $this;
502 $this->DivListApplication->execute();
503 if(!$this->IsReleaseManagementActivated()){
504 $this->DivListApplication->AddDepartments($this->DivListApplication->selectedBase,3,1);
505 }
506 $this->reload();
507 $this->DivListApplication->setEntries($this->applications);
508 return($this->DivListApplication->Draw());
509 }
512 /* Return departments, that will be included within snapshot detection */
513 function get_used_snapshot_bases()
514 {
515 if($this->IsReleaseManagementActivated()){
516 return(array($this->app_release));
517 }else{
518 return(array($this->app_base));
519 }
520 }
523 function reload()
524 {
525 $this->applications= array();
527 /* Set base for all searches */
528 $Regex = $this->DivListApplication->Regex;
529 $SubSearch = $this->DivListApplication->SubSearch;
530 $Flags = GL_NONE | GL_SIZELIMIT;
531 $Filter = "(&(cn=".$Regex.")(objectClass=gosaApplication))";
532 $tmp = array();
534 if(!$this->IsReleaseManagementActivated()){
535 $use_base = $this->app_base;
536 }else{
537 $use_base = $this->app_release;
538 }
540 if($SubSearch){
541 $Flags |= GL_SUBSEARCH;
542 }
544 $res= get_list($Filter, "application", $use_base, array("cn","description","dn","objectClass"), $Flags);
545 $tmp2 = array();
546 foreach ($res as $val){
547 $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
548 $tmp2[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']] = strtolower($val['cn'][0]).$val['cn'][0].$val['dn'];
549 }
551 natcasesort($tmp2);
552 $this->applications=array();
553 foreach($tmp2 as $val){
554 $this->applications[]=$tmp[$val];
555 }
556 reset ($this->applications);
557 }
559 function remove_from_parent()
560 {
561 /* Optionally execute a command after we're done */
562 $this->postremove();
563 }
566 function copyPasteHandling_from_queue($s_action,$s_entry)
567 {
568 /* Check if Copy & Paste is disabled */
569 if(!is_object($this->CopyPasteHandler)){
570 return("");
571 }
573 /* Add a single entry to queue */
574 if($s_action == "cut" || $s_action == "copy"){
576 /* Cleanup object queue */
577 $this->CopyPasteHandler->cleanup_queue();
578 $dn = $this->applications[$s_entry]['dn'];
579 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
580 }
583 /* Add entries to queue */
584 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
586 /* Cleanup object queue */
587 $this->CopyPasteHandler->cleanup_queue();
589 /* Add new entries to CP queue */
590 foreach($this->list_get_selected_items() as $id){
591 $dn = $this->applications[$id]['dn'];
593 if($s_action == "copy_multiple"){
594 $this->CopyPasteHandler->add_to_queue($dn,"copy","apptabs","APPSTABS","application");
595 }
596 if($s_action == "cut_multiple"){
597 $this->CopyPasteHandler->add_to_queue($dn,"cut","apptabs","APPSTABS","application");
598 }
599 }
600 }
602 /* Start pasting entries */
603 if($s_action == "editPaste"){
604 $this->start_pasting_copied_objects = TRUE;
605 }
608 /* Return C&P dialog */
609 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
612 /* Get dialog */
613 $this->CopyPasteHandler->SetVar("base",$this->app_base);
614 $this->CopyPasteHandler->SetVar("parent",&$this);
615 $data = $this->CopyPasteHandler->execute();
617 /* Return dialog data */
618 if(!empty($data)){
619 return($data);
620 }
621 }
623 /* Automatically disable status for pasting */
624 if(!$this->CopyPasteHandler->entries_queued()){
625 $this->start_pasting_copied_objects = FALSE;
626 }
627 return("");
628 }
631 function list_get_selected_items()
632 {
633 $ids = array();
634 foreach($_POST as $name => $value){
635 if(preg_match("/^item_selected_[0-9]*$/",$name)){
636 $id = preg_replace("/^item_selected_/","",$name);
637 $ids[$id] = $id;
638 }
639 }
640 return($ids);
641 }
644 /* Save to LDAP */
645 function save()
646 {
647 /* Optionally execute a command after we're done */
648 $this->postcreate();
649 }
651 function remove_lock()
652 {
653 if (isset($this->apptabs->dn)){
654 del_lock ($this->apptabs->dn);
655 }
656 }
658 function save_object()
659 {
660 $this->DivListApplication->save_object();
661 if(is_object($this->CopyPasteHandler)){
662 $this->CopyPasteHandler->save_object();
663 }
665 if($this->IsReleaseManagementActivated() && isset($_POST['app_release'])){
666 $sel_rel = get_post('app_release');
667 $releases = array_flip($this->getReleases());
668 if(isset($releases[$sel_rel])){
669 $this->app_release = $releases[$sel_rel];
670 }
671 }elseif(!$this->IsReleaseManagementActivated()){
672 $this->app_base = get_ou("applicationou").$this->DivListApplication->selectedBase;
673 }
674 }
676 function check() {}
677 function adapt_from_template($dn, $skip= array()) {}
678 function password_change_needed() {}
679 }
680 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
681 ?>