Code

6eababcf81ca6ed95ca0ed05d169e90fe236af0e
[gosa.git] / gosa-core / include / class_management.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id: class_plugin.inc 14584 2009-10-12 14:04:22Z hickert $$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class management
24 {
25   // Public 
26   public $config = null;
27   public $ui     = null;
29   // The plugin description
30   public $plugname      = "unconfigured";
31   public $plIcon        = "unconfigured";
32   public $plDescription = "unconfigured";
33   public $plHeadline    = "unconfigured";
35   // The currently used object(s) (e.g. in edit, removal)
36   protected $dn = "";
37   protected $dns = array();
39   // The last used object(s).
40   protected $last_dn = "";
41   protected $last_dns = array();
43   // The common places the displayed objects are stored in. (e.g. array("ou=groups,",".."))
44   protected $storagePoints = array();
46   // The tab definitions to use for the current object.
47   protected $tabClass = "";         // e.g. usertabs
48   protected $tabType = "";          // e.g. USERTABS
49   protected $aclCategory = "";      // e.g. users
50   protected $objectName = "";       // e.g. users
52   // The opened object.
53   protected $tabObject = null;
54   protected $dialogObject = null;
56   // The last opened object.
57   protected $last_tabObject = null;
58   protected $last_dialogObject = null;
60   // Whether to display the apply button or not
61   protected $displayApplyBtn = "";
63   // Copy&Paste handler
64   protected $cpHandler = null;
66   // Indicates that we want to paste objects right now.
67   protected $cpPastingStarted = FALSE;
69   // The Snapshot handler class.
70   protected $snapHandler = null;
72   // The listing handlers
73   protected $headpage = null;
74   protected $filter = null;
76   // A list of configured actions/events
77   protected $actions = array();
79   function  __construct($config,$ui,$plugname, $headpage)
80   {
81     $this->plugname = $plugname;
82     $this->headpage = $headpage;
83     $this->ui = $ui;
84     $this->config = $config;
86     if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
87     if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
89     if(empty($this->plIcon)){
90       $this->plIcon = "plugins/".$plugname."/images/plugin.png";
91     }
93     // Register default actions
94     $this->registerAction("new",    "newEntry");
95     $this->registerAction("edit",   "editEntry");
96     $this->registerAction("apply",  "applyChanges");
97     $this->registerAction("save",   "saveChanges");
98     $this->registerAction("cancel", "cancelEdit");
99     $this->registerAction("remove", "removeEntryRequested");
100     $this->registerAction("removeConfirmed", "removeEntryConfirmed");
102     $this->registerAction("copy",   "copyPasteHandler");
103     $this->registerAction("cut",    "copyPasteHandler");
104     $this->registerAction("paste",  "copyPasteHandler");
106     $this->registerAction("snapshot",    "createSnapshotDialog");
107     $this->registerAction("restore",     "restoreSnapshotDialog");
108     $this->registerAction("saveSnapshot","saveSnapshot");
109     $this->registerAction("restoreSnapshot","restoreSnapshot");
110     $this->registerAction("cancelSnapshot","closeDialogs");
112   }
114   /*! \brief  Execute this plugin
115    *          Handle actions/events, locking, snapshots, dialogs, tabs,...
116    */
117   function execute()
118   {
119     // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
120     $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
121     session::set('LOCK_VARS_TO_USE',$vars);
123     /* Display the copy & paste dialog, if it is currently open */
124     $ret = $this->copyPasteHandler("",array());
125     if($ret){
126       return($this->getHeader().$ret);
127     }
129     // Update filter
130     if ($this->filter) {
131       $this->filter->update();
132       session::global_set(get_class($this)."_filter", $this->filter);
133       session::set('autocomplete', $this->filter);
134       if (!$this->filter->isValid()){
135         msg_dialog::display(_("Filter error"), _("The filter is incomplete!"), ERROR_DIALOG);
136       }
137     }
139     // Handle actions (POSTs and GETs)
140     $str = $this->handleActions($this->detectPostActions());
141     if($str) return($this->getHeader().$str);
143     // Open single dialog objects
144     if(is_object($this->dialogObject)){
145       if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object(); 
146       if(method_exists($this->dialogObject,'execute')){
147         $display = $this->dialogObject->execute(); 
148         $display.= $this->_getTabFooter();
149         return($this->getHeader().$display);
150       } 
151     }
153     // Display tab object.
154     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
155       $this->tabObject->save_object();
156       $display = $this->tabObject->execute();
157       $display.= $this->_getTabFooter();
158       return($this->getHeader().$display);
159     }
161     // Set current restore base for snapshot handling.
162     if(is_object($this->snapHandler)){
163       $bases = array();
164       foreach($this->storagePoints as $sp){
165         $bases[] = $sp.$this->headpage->getBase();
166       }
167       $this->snapHandler->setSnapshotBases($bases);
168     }
170     $this->headpage->update();
171     $display = $this->headpage->render();
172     return($this->getHeader().$display);
173   }
177   /*! \brief  Generates the plugin header which is displayed whenever a tab object is 
178    *           opened.
179    */
180   protected function getHeader()
181   {
182     if (get_object_info() != ""){
183       $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
184           "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
185           LDAP::fix(get_object_info()));
186     } else {
187       $display= print_header(get_template_path($this->plIcon),_($this->plDescription));
188     }
189     return($display);
190   }
193   /*! \brief  Generates the footer which is used whenever a tab object is 
194    *           displayed.
195    */
196   protected function _getTabFooter()
197   {
198     // Do not display tab footer for non tab objects 
199     if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
200       return("");
201     }
203     // Check if there is a dialog opened - We don't need any buttons in this case. 
204     if($this->tabObject->by_object[$this->tabObject->current]){
205       $current = $this->tabObject->by_object[$this->tabObject->current];  
206       if(is_object($current->dialog)){
207         return("");
208       }
209     }
211     // In case an of locked entry, we may have opened a read-only tab.
212     $str = "";
213     if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
214       $str.= "<p style=\"text-align:right\">
215         <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
216         </p>";
217       return($str);
218     }else{
220       // Display ok, (apply) and cancel buttons
221       $str.= "<p style=\"text-align:right\">\n";
222       $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
223       $str.= "&nbsp;\n";
224       if($this->displayApplyBtn){
225         $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
226         $str.= "&nbsp;\n";
227       }
228       $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
229       $str.= "</p>";
230     }
231     return($str);
232   }
235   /*! \brief  Initiates the removal for the given entries
236    *           and displays a confirmation dialog.
237    *      
238    *  @param  String  'action'  The name of the action which was the used as trigger.
239    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
240    *  @param  Array   'all'     A combination of both 'action' and 'target'.
241    */
242   protected function removeEntryRequested($action,$target,$all)
243   {
244     $disallowed = array();
245     $this->dns = array();
247     // Check permissons for each target 
248     foreach($target as $dn){
249       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
250       if(preg_match("/d/",$acl)){
251         $this->dns[] = $dn;
252       }else{
253         $disallowed[] = $dn;
254       }
255     }
256     if(count($disallowed)){
257       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
258     }
260     // We've at least one entry to delete.
261     if(count($this->dns)){
263       // check locks
264       if ($user= get_multiple_locks($this->dns)){
265         return(gen_locked_message($user,$this->dns));
266       }
268       // Add locks
269       $dns_names = array();
270       foreach($this->dns as $dn){
271         $dns_names[] =LDAP::fix($dn);
272       }
273       add_lock ($this->dns, $this->ui->dn);
275       // Display confirmation dialog.
276       $smarty = get_smarty();
277       $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
278       $smarty->assign("multiple", true);
279       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
280     }
281   }  
284   /*! \brief  Object removal was confirmed, now remove the requested entries. 
285    *      
286    *  @param  String  'action'  The name of the action which was the used as trigger.
287    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
288    *  @param  Array   'all'     A combination of both 'action' and 'target'.
289    */
290   function removeEntryConfirmed($action="",$target=array(),$all=array())
291   {
292     foreach($this->dns as $key => $dn){
294       // Check permissions, are we allowed to remove this object? 
295       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
296       if(preg_match("/d/",$acl)){
298         // Delete the object
299         $this->dn = $dn;
300         $tab = $this->tabClass;
301         $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn, $this->aclCategory);
302         $this->tabObject->set_acl_base($this->dn);
303         $this->tabObject->delete ();
305         // Remove the lock for the current object.
306         del_lock($this->dn);        
307       } else {
308         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
309         new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
310       }
311     }
313     // Cleanup
314     $this->remove_lock();
315     $this->closeDialogs();
316   }
319   /*! \brief  Detects actions/events send by the ui
320    *           and the corresponding targets.
321    */
322   function detectPostActions()
323   {
324     $action= $this->headpage->getAction();
325     if(isset($_POST['edit_apply']))  $action['action'] = "apply";    
326     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
327     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
328     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
330     // Detect Snapshot actions
331     if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";   
332     if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";   
333     foreach($_POST as $name => $value){
334       $once =TRUE;
335       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
336         $once = FALSE;
337         $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
338         $action['action'] = "restoreSnapshot";
339         $action['targets'] = array($entry);
340       }
341     }
343     return($action);
344   }
347   /*! \brief  Calls the registered method for a given action/event.
348    */
349   function handleActions($action)
350   {
351     // Start action  
352     if(isset($this->actions[$action['action']])){
353       $func = $this->actions[$action['action']];
354       if(!isset($action['targets']))$action['targets']= array(); 
355       return($this->$func($action['action'],$action['targets'],$action));
356     }
357   } 
360   /*! \brief  Opens the snapshot creation dialog for the given target.
361    *      
362    *  @param  String  'action'  The name of the action which was the used as trigger.
363    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
364    *  @param  Array   'all'     A combination of both 'action' and 'target'.
365    */
366   function createSnapshotDialog($action="",$target=array(),$all=array())
367   {
368     foreach($target as $entry){
369       if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
370         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
371         $this->dialogObject->aclCategories = array($this->aclCategory);
373       }else{
374         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
375             ERROR_DIALOG);
376       }
377     }
378   }
381   /*! \brief  Creates a snapshot new entry - This method is called when the somebody
382    *           clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
383    *      
384    *  @param  String  'action'  The name of the action which was the used as trigger.
385    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
386    *  @param  Array   'all'     A combination of both 'action' and 'target'.
387    */
388   function saveSnapsho($action="",$target=array(),$all=array())
389   {
390     $this->dialogObject->save_object();
391     $msgs = $this->dialogObject->check();
392     if(count($msgs)){
393       foreach($msgs as $msg){
394         msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
395       }
396     }else{
397       $this->dn =  $this->dialogObject->dn;
398       $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
399       $this->closeDialogs();
400     }
401   }
404   /*! \brief  Restores a snapshot object.
405    *          The dn of the snapshot entry has to be given as ['target'] parameter.  
406    *      
407    *  @param  String  'action'  The name of the action which was the used as trigger.
408    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
409    *  @param  Array   'all'     A combination of both 'action' and 'target'.
410    */
411   function restoreSnapshot($action="",$target=array(),$all=array())
412   {
413     $entry = array_pop($target);
414     if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
415       $this->snapHandler->restore_snapshot($entry);
416       $this->closeDialogs();
417     }else{
418       msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
419           ERROR_DIALOG);
420     }
421   }
424   /*! \brief  Displays the "Restore snapshot dialog" for a given target. 
425    *          If no target is specified, open the restore removed object 
426    *           dialog.
427    *  @param  String  'action'  The name of the action which was the used as trigger.
428    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
429    *  @param  Array   'all'     A combination of both 'action' and 'target'.
430    */
431   function restoreSnapshotDialog($action="",$target=array(),$all=array())
432   {
433     // Set current restore base for snapshot handling.
434     if(is_object($this->snapHandler)){
435       $bases = array();
436       foreach($this->storagePoints as $sp){
437         $bases[] = $sp.$this->headpage->getBase();
438       }
439     }
441     // No target, open the restore removed object dialog.
442     if(!count($target)){ 
443       $entry = $this->headpage->getBase();
444       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
445         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
446         $this->dialogObject->set_snapshot_bases($bases);
447         $this->dialogObject->display_all_removed_objects = true;
448         $this->dialogObject->display_restore_dialog = true;
449       }else{
450         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
451             ERROR_DIALOG);
452       } 
453     }else{
455       // Display the restore points for a given object.
456       $entry = array_pop($target);
457       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
458         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
459         $this->dialogObject->set_snapshot_bases($bases);
460         $this->dialogObject->display_restore_dialog = true;
461       }else{
462         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
463             ERROR_DIALOG);
464       } 
465     }
466   }
469   /*! \brief  This method intiates the object creation.
470    *          
471    *  @param  String  'action'  The name of the action which was the used as trigger.
472    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
473    *  @param  Array   'all'     A combination of both 'action' and 'target'.
474    */
475   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
476   {
477     /* To handle mutliple object types overload this method.
478      * ...
479      *   registerAction('newUser', 'newEntry');
480      *   registerAction('newGroup','newEntry');
481      * ... 
482      * 
483      * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
484      * {
485      *   switch($action){
486      *     case 'newUser' : {
487      *       mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
488      *     }
489      *     case 'newGroup' : {
490      *       mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
491      *     }
492      *   }
493      * }
494      **/ 
495     $tabType = $this->tabType;
496     $tabClass = $this->tabClass;
497     $aclCategory = $this->aclCategory;
498     if(!empty($altTabClass)) $tabClass = $altTabClass;
499     if(!empty($altTabType)) $tabType = $altTabType;
500     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
502     // Check locking & lock entry if required 
503     $this->displayApplyBtn = FALSE;
504     $this->dn = "new";
505     $this->is_new = TRUE;
506     $this->is_single_edit = FALSE;
507     $this->is_multiple_edit = FALSE;
509     set_object_info($this->dn);
511     // Open object.
512     if(empty($tabClass) || empty($tabType)){
513       // No tab type defined
514     }else{
515       $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
516       $this->tabObject->set_acl_base($this->headpage->getBase());
517     }
518   }
521   /*! \brief  This method opens an existing object or a list of existing objects to be edited. 
522    *                  
523    * 
524    *  @param  String  'action'  The name of the action which was the used as trigger.
525    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
526    *  @param  Array   'all'     A combination of both 'action' and 'target'.
527    */
528   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
529   {
530     /* To handle mutliple object types overload this method.
531      * ...
532      *   registerAction('editUser', 'editEntry');
533      *   registerAction('editGroup','editEntry');
534      * ... 
535      * 
536      * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
537      * {
538      *   switch($action){
539      *     case 'editUser' : {
540      *       mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
541      *     }
542      *     case 'editGroup' : {
543      *       mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
544      *     }
545      *   }
546      * }
547      **/ 
548     $tabType = $this->tabType;
549     $tabClass = $this->tabClass;
550     $aclCategory = $this->aclCategory;
551     if(!empty($altTabClass)) $tabClass = $altTabClass;
552     if(!empty($altTabType)) $tabType = $altTabType;
553     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
555     // Single edit - we only got one object dn.
556     if(count($target) == 1){
557       $this->displayApplyBtn = TRUE;
558       $this->is_new = FALSE;
559       $this->is_single_edit = TRUE;
560       $this->is_multiple_edit = FALSE;
562       // Get the dn of the object and creates lock
563       $this->dn = array_pop($target);
564       set_object_info($this->dn);
565       $user = get_lock($this->dn);
566       if ($user != ""){
567         return(gen_locked_message ($user, $this->dn,TRUE));
568       }
569       add_lock ($this->dn, $this->ui->dn);
571       // Open object.
572       if(empty($tabClass) || empty($tabType)){
573         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
574       }else{
575         $tab = $tabClass;
576         $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
577         $this->tabObject->set_acl_base($this->dn);
578       }
579     }else{
581       // We've multiple entries to edit.
582       $this->is_new = FALSE;
583       $this->is_singel_edit = FALSE;
584       $this->is_multiple_edit = TRUE;
586       // Open multiple edit handler.
587       if(empty($tabClass) || empty($tabType)){
588         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
589       }else{
590         $this->dns = $target;
591         $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
592             $this->dns,$this->headpage->getBase(),$aclCategory);
594         // Check for locked entries
595         if ($tmp->entries_locked()){
596           return($tmp->display_lock_message());
597         }
599         // Now lock entries.
600         $tmp->lock_entries($this->ui->dn);
601         if($tmp->multiple_available()){
602           $this->tabObject = $tmp;
603           set_object_info($this->tabObject->get_object_info());
604         }
605       }
606     }
607   }
610   /*! \brief  Save object modifications and closes dialogs (returns to object listing).
611    *          - Calls '::check' to validate the given input.
612    *          - Calls '::save' to save back object modifications (e.g. to ldap).
613    *          - Calls '::remove_locks' to remove eventually created locks.
614    *          - Calls '::closeDialogs' to return to the object listing.
615    */
616   protected function saveChanges()
617   {
618     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
619       $this->tabObject->save_object();
620       $msgs = $this->tabObject->check();
621       if(count($msgs)){
622         msg_dialog::displayChecks($msgs); 
623         return("");
624       }else{
625         $this->tabObject->save();
626         $this->remove_lock();
627         $this->closeDialogs();
628       }
629     }
630   }
633   /*! \brief  Save object modifications and keep dialogs opened. 
634    *          - Calls '::check' to validate the given input.
635    *          - Calls '::save' to save back object modifications (e.g. to ldap).
636    */
637   protected function applyChanges()
638   {
639     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
640       $this->tabObject->save_object();
641       $msgs = $this->tabObject->check();
642       if(count($msgs)){
643         msg_dialog::displayChecks($msgs); 
644         return("");
645       }else{
646         $this->tabObject->save();
647         $this->tabObject->re_init();
648       }
649     }
650   }
653   /*! \brief  This method closes dialogs
654    *           and cleans up the cached object info and the ui.
655    */
656   protected function closeDialogs()
657   {
658     $this->last_dn = $this->dn;
659     $this->last_dns = $this->dns;
660     $this->last_tabObject = $this->tabObject;
661     $this->last_dialogObject = $this->dialogObject;
662     $this->dn = "";
663     $this->dns = array();
664     $this->tabObject = null;
665     $this->dialogObject = null;
666     set_object_info();
667   }
670   /*! \brief  Editing an object was caneled. 
671    *          Close dialogs/tabs and remove locks.
672    */
673   protected function cancelEdit()
674   {
675     $this->remove_lock();
676     $this->closeDialogs();
677   }
680   /*! \brief  Every click in the list user interface sends an event
681    *           here can we connect those events to a method. 
682    *          eg.  ::registerEvent('new','createUser')
683    *          When the action/event new is send, the method 'createUser' 
684    *           will be called.
685    */
686   function registerAction($action,$target)
687   {
688     $this->actions[$action] = $target;
689   }
692   /*! \brief  Removes ldap object locks created by this class.
693    *          Whenever an object is edited, we create locks to avoid 
694    *           concurrent modifications.
695    *          This locks will automatically removed here.
696    */
697   function remove_lock()
698   {
699     if(!empty($this->dn) && $this->dn != "new"){
700       del_lock($this->dn);
701     }
702     if(count($this->dns)){
703       del_lock($this->dns);
704     }
705   }
708   /*! \brief  This method is used to queue and process copy&paste actions. 
709    *          Allows to copy, cut and paste mutliple entries at once.
710    *  @param  String  'action'  The name of the action which was the used as trigger.
711    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
712    *  @param  Array   'all'     A combination of both 'action' and 'target'.
713    */
714   function copyPasteHandler($action="",$target=array(),$all=array(), 
715       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
716   {
717     // Return without any actions while copy&paste handler is disabled.
718     if(!is_object($this->cpHandler))  return("");
720     $tabType = $this->tabType;
721     $tabClass = $this->tabClass;
722     $aclCategory = $this->aclCategory;
723     $aclPlugin = $this->aclPlugin;
724     if(!empty($altTabClass)) $tabClass = $altTabClass;
725     if(!empty($altTabType)) $tabType = $altTabType;
726     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
727     if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
729     // Save user input
730     $this->cpHandler->save_object();
732     // Add entries to queue 
733     if($action == "copy" || $action == "cut"){
734       $this->cpHandler->cleanup_queue();
735       foreach($target as $dn){
736         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
737           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory);
738         }
739         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
740           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory);
741         }
742       }
743     }
745     // Initiate pasting
746     if($action == "paste"){
747       $this->cpPastingStarted = TRUE;
748     }
750     // Display any c&p dialogs, eg. object modifications required before pasting.
751     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
752       $this->cpHandler->SetVar("base",$this->headpage->getBase());
753       $data = $this->cpHandler->execute();
754       if(!empty($data)){
755         return($data);
756       }
757     }
759     // Automatically disable pasting process since there is no entry left to paste.
760     if(!$this->cpHandler->entries_queued()){
761       $this->cpPastingStarted = FALSE;
762     }
763     return("");
764   }
767   function setFilter($str) {
768     $this->filter = $str;
769   }
773 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
774 ?>