14f51165fda4b65cc474f6d9d29e82c3a7a26ea9
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 return(false);
47 }
50 function applicationManagement (&$config, &$ui)
51 {
52 /* Save configuration for internal use */
53 $this->config = &$config;
54 $this->ui = &$ui;
56 /* Check if copy & paste is activated */
57 if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
58 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
59 }
61 /* Creat dialog object */
62 $this->DivListApplication = new divListApplication($this->config,$this);
64 if($this->IsReleaseManagementActivated()){
65 /* Check if we should enable the release selection */
66 $this->enableReleaseManagement = true;
68 /* Hide SubSearch checkbox */
69 $this->DivListApplication->DisableCheckBox("SubSearch");
70 }
72 /* Set default release */
73 if(!$this->IsReleaseManagementActivated()){
74 $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
75 if(!session::is_set("app_filter")){
76 session::set("app_filter",array("app_base" => $this->app_base));
77 }
78 $app_filter = session::get("app_filter");
79 $this->app_base = $app_filter['app_base'];
80 }else{
81 $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
82 if(!session::is_set("app_filter")){
83 session::set("app_filter",array("app_base" => $this->app_base,"app_release" => $this->app_base));
84 }
85 $app_filter = session::get("app_filter");
86 $this->app_base = $app_filter['app_base'];
87 $this->app_release = $app_filter['app_release'];
88 }
89 $this->app_base = "ou=apps,o=Landeshauptstadt München,c=de";
90 $this->app_release= $this->app_base;
91 }
94 function getReleases()
95 {
96 $ldap = $this->config->get_ldap_link();
97 $ret = array();
98 $base = $this->app_base;
100 $ret[$this->app_base] = "/";
101 $ldap->cd($base);
102 $ldap->search("(&(objectClass=organizationalUnit)(objectClass=FAIbranch))",array("ou"));
103 while($attrs = $ldap->fetch()){
104 $str = str_replace($base,"",$attrs['dn']);
105 $tmp = array_reverse( split("ou=",$str));
106 $str = "";
107 foreach($tmp as $val){
108 $val = trim(preg_replace("/,/","",$val));
109 if(empty($val)) break;
110 $str .= "/".$val;
111 }
112 if(!empty($str)){
113 $ret[$attrs['dn']]= preg_replace("/^\//","",$str);
114 }
115 }
116 asort($ret);
117 return($ret);
118 }
120 function execute()
121 {
122 /* Call parent execute */
123 plugin::execute();
126 /****************
127 Variable init
128 ****************/
130 /* These vars will be stored if you try to open a locked app,
131 to be able to perform your last requests after showing a warning message */
132 session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/","/^item_selected/","/^remove_multiple_applications/"));
134 $smarty = get_smarty(); // Smarty instance
135 $s_action = ""; // Contains the action to proceed
136 $s_entry = ""; // The value for s_action
137 $base_back = ""; // The Link for Backbutton
139 /* Test Posts */
140 foreach($_POST as $key => $val){
141 // Post for delete
142 if(preg_match("/appl_del.*/",$key)){
143 $s_action = "del";
144 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
145 // Post for edit
146 }elseif(preg_match("/appl_edit_.*/",$key)){
147 $s_action="edit";
148 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
149 // Post for new
150 }elseif(preg_match("/^copy_.*/",$key)){
151 $s_action="copy";
152 $s_entry = preg_replace("/^copy_/i","",$key);
153 }elseif(preg_match("/^cut_.*/",$key)){
154 $s_action="cut";
155 $s_entry = preg_replace("/^cut_/i","",$key);
156 // Post for new
157 }elseif(preg_match("/^appl_new.*/",$key)){
158 $s_action="new";
159 }elseif(preg_match("/^remove_multiple_applications/",$key)){
160 $s_action="del_multiple";
161 }elseif(preg_match("/^editPaste.*/i",$key)){
162 $s_action="editPaste";
163 }elseif(preg_match("/^multiple_copy_groups/",$key)){
164 $s_action = "copy_multiple";
165 }elseif(preg_match("/^multiple_cut_groups/",$key)){
166 $s_action = "cut_multiple";
167 }
168 }
170 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
171 $s_action ="edit";
172 $s_entry = $_GET['id'];
173 }
175 $s_entry = preg_replace("/_.$/","",$s_entry);
178 /* handle C&P from layers menu */
179 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
180 $s_action = "copy_multiple";
181 }
182 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
183 $s_action = "cut_multiple";
184 }
185 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
186 $s_action = "editPaste";
187 }
189 /* Create options */
190 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "appl_new"){
191 $s_action = "new";
192 }
194 /* handle remove from layers menu */
195 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
196 $s_action = "del_multiple";
197 }
199 /****************
200 Copy & Paste handling
201 ****************/
203 /* Display the copy & paste dialog, if it is currently open */
204 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
205 if($ret){
206 return($ret);
207 }
209 /****************
210 Create a new app
211 ****************/
213 /* New application? */
214 if ($s_action=="new"){
216 /* By default we set 'dn' to 'new', all relevant plugins will
217 react on this. */
218 $this->dn= "new";
220 /* Create new usertab object */
221 $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
222 $this->apptabs->parent = &$this;
223 $this->apptabs->set_acl_base($this->app_base);
224 }
227 /****************
228 Edit entry canceled
229 ****************/
231 /* Cancel dialogs */
232 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
233 del_lock ($this->apptabs->dn);
234 unset ($this->apptabs);
235 $this->apptabs= NULL;
236 session::un_set('objectinfo');
237 }
240 /****************
241 Edit entry finished
242 ****************/
244 /* Finish apps edit is triggered by the tabulator dialog, so
245 the user wants to save edited data. Check and save at this
246 point. */
247 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply']) ) && (isset($this->apptabs->config))){
249 /* Check tabs, will feed message array */
250 $this->apptabs->last= $this->apptabs->current;
251 $this->apptabs->save_object();
252 $message= $this->apptabs->check();
254 /* Save, or display error message? */
255 if (count($message) == 0){
257 /* Save data data to ldap */
258 $this->apptabs->save();
260 if (!isset($_POST['edit_apply'])){
261 /* Application has been saved successfully, remove lock from
262 LDAP. */
263 if ($this->dn != "new"){
264 del_lock ($this->dn);
265 }
266 unset ($this->apptabs);
267 $this->apptabs= NULL;
268 session::un_set('objectinfo');
269 }
270 } else {
271 /* Ok. There seem to be errors regarding to the tab data,
272 show message and continue as usual. */
273 msg_dialog::displayChecks($message);
274 }
275 }
278 /****************
279 Edit entry
280 ****************/
282 /* User wants to edit data? */
283 if (($s_action=="edit") && (!isset($this->apptabs->config))){
285 /* Get 'dn' from posted 'applist', must be unique */
286 $this->dn= $this->applications[$s_entry]['dn'];
288 /* Check locking, save current plugin in 'back_plugin', so
289 the dialog knows where to return. */
290 if (($user= get_lock($this->dn)) != ""){
291 return(gen_locked_message ($user, $this->dn));
292 }
294 /* Lock the current entry, so everyone will get the
295 above dialog */
296 add_lock ($this->dn, $this->ui->dn);
298 /* Register apptabs to trigger edit dialog */
299 $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
300 $this->apptabs->parent = &$this;
301 $this->apptabs->set_acl_base($this->dn);
302 session::set('objectinfo',$this->dn);
303 }
307 /********************
308 Delete MULTIPLE entries requested, display confirm dialog
309 ********************/
311 if ($s_action=="del_multiple"){
312 $ids = $this->list_get_selected_items();
314 if(count($ids)){
316 foreach($ids as $id){
317 $dn = $this->applications[$id]['dn'];
318 $this->dns[$id] = $dn;
319 }
320 if ($user= get_multiple_locks($this->dns)){
321 return(gen_locked_message($user,$this->dns));
322 }
324 $dns_names[] = array();
325 foreach($this->dns as $dn){
326 add_lock ($dn, $this->ui->dn);
327 $dns_names[] =@LDAP::fix($dn);
328 }
330 /* Lock the current entry, so nobody will edit it during deletion */
331 $smarty->assign("intro", msgPool::deleteInfo($dns_names,_("application")));
332 $smarty->assign("multiple", true);
333 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
334 }
335 }
338 /********************
339 Delete MULTIPLE entries confirmed
340 ********************/
342 /* Confirmation for deletion has been passed. Users should be deleted. */
343 if (isset($_POST['delete_multiple_application_confirm'])){
345 /* Remove user by user and check acls before removeing them */
346 foreach($this->dns as $key => $dn){
348 $ui = get_userinfo();
349 $acl = $ui->get_permissions($dn ,"application/application");
350 if (preg_match('/d/', $acl)){
352 /* Delete request is permitted, perform LDAP action */
353 $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn,"application");
354 $this->apptabs->parent = &$this;
355 $this->apptabs->set_acl_base($dn);
356 $this->apptabs->delete ();
357 unset ($this->apptabs);
358 $this->apptabs= NULL;
360 } else {
361 /* Normally this shouldn't be reached, send some extra
362 logs to notify the administrator */
363 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
364 new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
365 }
366 /* Remove lock file after successfull deletion */
367 del_lock ($dn);
368 unset($this->dns[$key]);
369 }
370 }
373 /********************
374 Delete MULTIPLE entries Canceled
375 ********************/
377 /* Remove lock */
378 if(isset($_POST['delete_multiple_application_cancel'])){
379 foreach($this->dns as $key => $dn){
380 del_lock ($dn);
381 unset($this->dns[$key]);
382 }
383 }
385 /****************
386 Delete app
387 ****************/
389 /* Remove user was requested */
390 if ($s_action == "del"){
392 /* Get 'dn' from posted 'uid' */
393 $this->dn= $this->applications[$s_entry]['dn'];
395 /* Load permissions for selected 'dn' and check if
396 we're allowed to remove this 'dn' */
397 $ui = get_userinfo();
398 $acl = $ui->get_permissions($this->dn ,"application/application");
400 if(preg_match("/d/",$acl)){
401 /* Check locking, save current plugin in 'back_plugin', so
402 the dialog knows where to return. */
403 if (($user= get_lock($this->dn)) != ""){
404 return (gen_locked_message ($user, $this->dn));
405 }
407 /* Lock the current entry, so nobody will edit it during deletion */
408 add_lock ($this->dn, $this->ui->dn);
409 $smarty= get_smarty();
410 $smarty->assign("intro",msgPool::deleteInfo(@LDAP::fix($this->dn),_("application")));
411 $smarty->assign("multiple", false);
412 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
413 } else {
415 /* Obviously the user isn't allowed to delete. Show message and
416 clean session. */
417 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
418 }
419 }
422 /****************
423 Delete app confirmed
424 ****************/
426 /* Confirmation for deletion has been passed. Group should be deleted. */
427 if (isset($_POST['delete_app_confirm'])){
429 /* Some nice guy may send this as POST, so we've to check
430 for the permissions again. */
431 $ui = get_userinfo();
432 $acl = $ui->get_permissions($this->dn ,"application/application");
434 if(preg_match("/d/",$acl)){
436 /* Delete request is permitted, perform LDAP action */
437 $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $this->dn,"application");
438 $this->apptabs->parent = &$this;
439 $this->apptabs->set_acl_base($this->dn);
440 $this->apptabs->delete ();
441 unset ($this->apptabs);
442 $this->apptabs= NULL;
444 } else {
446 /* Normally this shouldn't be reached, send some extra
447 logs to notify the administrator */
448 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
449 new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
450 }
452 /* Remove lock file after successfull deletion */
453 del_lock ($this->dn);
454 }
457 /****************
458 Delete app canceled
459 ****************/
461 /* Delete application canceled? */
462 if (isset($_POST['delete_cancel'])){
463 del_lock ($this->dn);
464 session::un_set('objectinfo');
465 }
467 /* Show tab dialog if object is present */
468 if (($this->apptabs) && (isset($this->apptabs->config))){
469 $display= $this->apptabs->execute();
471 /* Don't show buttons if tab dialog requests this */
472 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
473 $display.= "<p style=\"text-align:right\">\n";
474 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
475 $display.= " \n";
476 if ($this->dn != "new"){
477 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
478 $display.= " \n";
479 }
480 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
481 $display.= "</p>";
482 }
483 return ($display);
484 }
487 /****************
488 Dialog display
489 ****************/
491 /* Check if there is a snapshot dialog open */
492 if($this->IsReleaseManagementActivated()){
493 $base = $this->app_release;
494 }else{
495 $base = $this->app_base;
496 }
497 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
498 return($str);
499 }
501 /* Display dialog with system list */
502 $this->DivListApplication->parent = $this;
503 $this->DivListApplication->execute();
504 if(!$this->IsReleaseManagementActivated()){
505 $this->DivListApplication->AddDepartments($this->DivListApplication->selectedBase,3,1);
506 }
507 $this->reload();
508 $this->DivListApplication->setEntries($this->applications);
509 return($this->DivListApplication->Draw());
510 }
513 /* Return departments, that will be included within snapshot detection */
514 function get_used_snapshot_bases()
515 {
516 if($this->IsReleaseManagementActivated()){
517 return(array($this->app_release));
518 }else{
519 return(array($this->app_base));
520 }
521 }
524 function reload()
525 {
526 $this->applications= array();
528 /* Set base for all searches */
529 $Regex = $this->DivListApplication->Regex;
530 $SubSearch = $this->DivListApplication->SubSearch;
531 $Flags = GL_NONE | GL_SIZELIMIT;
532 $Filter = "(&(cn=".$Regex.")(objectClass=gosaApplication))";
533 $tmp = array();
535 if(!$this->IsReleaseManagementActivated()){
536 $use_base = $this->app_base;
537 if($SubSearch){
538 $use_base = preg_replace("/^".normalizePreg(get_ou("applicationou"))."/","",$use_base);
539 }
540 }else{
541 $use_base = $this->app_release;
542 $SubSearch= FALSE;
543 }
545 if($SubSearch){
546 $res= get_sub_list($Filter, "application",get_ou("applicationou"), $use_base, array("cn","description","dn","objectClass"), $Flags);
547 }else{
548 $res= get_list($Filter, "application",$use_base, array("cn","description","dn","objectClass"), $Flags);
549 }
550 $tmp2 = array();
551 foreach ($res as $val){
552 $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
553 $tmp2[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']] = strtolower($val['cn'][0]).$val['cn'][0].$val['dn'];
554 }
556 natcasesort($tmp2);
557 $this->applications=array();
558 foreach($tmp2 as $val){
559 $this->applications[]=$tmp[$val];
560 }
561 reset ($this->applications);
562 }
564 function remove_from_parent()
565 {
566 /* Optionally execute a command after we're done */
567 $this->postremove();
568 }
571 function copyPasteHandling_from_queue($s_action,$s_entry)
572 {
573 /* Check if Copy & Paste is disabled */
574 if(!is_object($this->CopyPasteHandler)){
575 return("");
576 }
578 /* Add a single entry to queue */
579 if($s_action == "cut" || $s_action == "copy"){
581 /* Cleanup object queue */
582 $this->CopyPasteHandler->cleanup_queue();
583 $dn = $this->applications[$s_entry]['dn'];
584 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
585 }
588 /* Add entries to queue */
589 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
591 /* Cleanup object queue */
592 $this->CopyPasteHandler->cleanup_queue();
594 /* Add new entries to CP queue */
595 foreach($this->list_get_selected_items() as $id){
596 $dn = $this->applications[$id]['dn'];
598 if($s_action == "copy_multiple"){
599 $this->CopyPasteHandler->add_to_queue($dn,"copy","apptabs","APPSTABS","application");
600 }
601 if($s_action == "cut_multiple"){
602 $this->CopyPasteHandler->add_to_queue($dn,"cut","apptabs","APPSTABS","application");
603 }
604 }
605 }
607 /* Start pasting entries */
608 if($s_action == "editPaste"){
609 $this->start_pasting_copied_objects = TRUE;
610 }
613 /* Return C&P dialog */
614 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
617 /* Get dialog */
618 $this->CopyPasteHandler->SetVar("base",$this->app_base);
619 $this->CopyPasteHandler->SetVar("parent",&$this);
620 $data = $this->CopyPasteHandler->execute();
622 /* Return dialog data */
623 if(!empty($data)){
624 return($data);
625 }
626 }
628 /* Automatically disable status for pasting */
629 if(!$this->CopyPasteHandler->entries_queued()){
630 $this->start_pasting_copied_objects = FALSE;
631 }
632 return("");
633 }
636 function list_get_selected_items()
637 {
638 $ids = array();
639 foreach($_POST as $name => $value){
640 if(preg_match("/^item_selected_[0-9]*$/",$name)){
641 $id = preg_replace("/^item_selected_/","",$name);
642 $ids[$id] = $id;
643 }
644 }
645 return($ids);
646 }
649 /* Save to LDAP */
650 function save()
651 {
652 /* Optionally execute a command after we're done */
653 $this->postcreate();
654 }
656 function remove_lock()
657 {
658 if (isset($this->apptabs->dn)){
659 del_lock ($this->apptabs->dn);
660 }
661 }
663 function save_object()
664 {
665 $this->DivListApplication->save_object();
666 if(is_object($this->CopyPasteHandler)){
667 $this->CopyPasteHandler->save_object();
668 }
670 if($this->IsReleaseManagementActivated() && isset($_POST['app_release'])){
671 $sel_rel = get_post('app_release');
672 $releases = array_flip($this->getReleases());
673 if(isset($releases[$sel_rel])){
674 $this->app_release = $releases[$sel_rel];
675 }
676 }elseif(!$this->IsReleaseManagementActivated()){
677 $this->app_base = get_ou("applicationou").$this->DivListApplication->selectedBase;
678 }
679 }
681 function check() {}
682 function adapt_from_template($dn, $skip= array()) {}
683 function password_change_needed() {}
684 }
685 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
686 ?>