Code

31573b68f2b1d9a83b110422c069a1e97c41f951
[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       $altTabClass="",$altTabType="",$altAclCategory="")
292   {
293     $tabType = $this->tabType;
294     $tabClass = $this->tabClass;
295     $aclCategory = $this->aclCategory;
296     if(!empty($altTabClass)) $tabClass = $altTabClass;
297     if(!empty($altTabType)) $tabType = $altTabType;
298     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
300     foreach($this->dns as $key => $dn){
302       // Check permissions, are we allowed to remove this object? 
303       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
304       if(preg_match("/d/",$acl)){
306         // Delete the object
307         $this->dn = $dn;
308         $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
309         $this->tabObject->set_acl_base($this->dn);
310         $this->tabObject->delete ();
312         // Remove the lock for the current object.
313         del_lock($this->dn);        
314       } else {
315         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
316         new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
317       }
318     }
320     // Cleanup
321     $this->remove_lock();
322     $this->closeDialogs();
323   }
326   /*! \brief  Detects actions/events send by the ui
327    *           and the corresponding targets.
328    */
329   function detectPostActions()
330   {
331     $action= $this->headpage->getAction();
332     if(isset($_POST['edit_apply']))  $action['action'] = "apply";    
333     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
334     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
335     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
337     // Detect Snapshot actions
338     if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";   
339     if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";   
340     foreach($_POST as $name => $value){
341       $once =TRUE;
342       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
343         $once = FALSE;
344         $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
345         $action['action'] = "restoreSnapshot";
346         $action['targets'] = array($entry);
347       }
348     }
350     return($action);
351   }
354   /*! \brief  Calls the registered method for a given action/event.
355    */
356   function handleActions($action)
357   {
358     // Start action  
359     if(isset($this->actions[$action['action']])){
360       $func = $this->actions[$action['action']];
361       if(!isset($action['targets']))$action['targets']= array(); 
362       return($this->$func($action['action'],$action['targets'],$action));
363     }
364   } 
367   /*! \brief  Opens the snapshot creation dialog for the given target.
368    *      
369    *  @param  String  'action'  The name of the action which was the used as trigger.
370    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
371    *  @param  Array   'all'     A combination of both 'action' and 'target'.
372    */
373   function createSnapshotDialog($action="",$target=array(),$all=array())
374   {
375     foreach($target as $entry){
376       if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
377         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
378         $this->dialogObject->aclCategories = array($this->aclCategory);
380       }else{
381         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
382             ERROR_DIALOG);
383       }
384     }
385   }
388   /*! \brief  Creates a snapshot new entry - This method is called when the somebody
389    *           clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
390    *      
391    *  @param  String  'action'  The name of the action which was the used as trigger.
392    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
393    *  @param  Array   'all'     A combination of both 'action' and 'target'.
394    */
395   function saveSnapsho($action="",$target=array(),$all=array())
396   {
397     $this->dialogObject->save_object();
398     $msgs = $this->dialogObject->check();
399     if(count($msgs)){
400       foreach($msgs as $msg){
401         msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
402       }
403     }else{
404       $this->dn =  $this->dialogObject->dn;
405       $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
406       $this->closeDialogs();
407     }
408   }
411   /*! \brief  Restores a snapshot object.
412    *          The dn of the snapshot entry has to be given as ['target'] parameter.  
413    *      
414    *  @param  String  'action'  The name of the action which was the used as trigger.
415    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
416    *  @param  Array   'all'     A combination of both 'action' and 'target'.
417    */
418   function restoreSnapshot($action="",$target=array(),$all=array())
419   {
420     $entry = array_pop($target);
421     if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
422       $this->snapHandler->restore_snapshot($entry);
423       $this->closeDialogs();
424     }else{
425       msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
426           ERROR_DIALOG);
427     }
428   }
431   /*! \brief  Displays the "Restore snapshot dialog" for a given target. 
432    *          If no target is specified, open the restore removed object 
433    *           dialog.
434    *  @param  String  'action'  The name of the action which was the used as trigger.
435    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
436    *  @param  Array   'all'     A combination of both 'action' and 'target'.
437    */
438   function restoreSnapshotDialog($action="",$target=array(),$all=array())
439   {
440     // Set current restore base for snapshot handling.
441     if(is_object($this->snapHandler)){
442       $bases = array();
443       foreach($this->storagePoints as $sp){
444         $bases[] = $sp.$this->headpage->getBase();
445       }
446     }
448     // No target, open the restore removed object dialog.
449     if(!count($target)){ 
450       $entry = $this->headpage->getBase();
451       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
452         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
453         $this->dialogObject->set_snapshot_bases($bases);
454         $this->dialogObject->display_all_removed_objects = true;
455         $this->dialogObject->display_restore_dialog = true;
456       }else{
457         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
458             ERROR_DIALOG);
459       } 
460     }else{
462       // Display the restore points for a given object.
463       $entry = array_pop($target);
464       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
465         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
466         $this->dialogObject->set_snapshot_bases($bases);
467         $this->dialogObject->display_restore_dialog = true;
468       }else{
469         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
470             ERROR_DIALOG);
471       } 
472     }
473   }
476   /*! \brief  This method intiates the object creation.
477    *          
478    *  @param  String  'action'  The name of the action which was the used as trigger.
479    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
480    *  @param  Array   'all'     A combination of both 'action' and 'target'.
481    */
482   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
483   {
484     /* To handle mutliple object types overload this method.
485      * ...
486      *   registerAction('newUser', 'newEntry');
487      *   registerAction('newGroup','newEntry');
488      * ... 
489      * 
490      * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
491      * {
492      *   switch($action){
493      *     case 'newUser' : {
494      *       mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
495      *     }
496      *     case 'newGroup' : {
497      *       mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
498      *     }
499      *   }
500      * }
501      **/ 
502     $tabType = $this->tabType;
503     $tabClass = $this->tabClass;
504     $aclCategory = $this->aclCategory;
505     if(!empty($altTabClass)) $tabClass = $altTabClass;
506     if(!empty($altTabType)) $tabType = $altTabType;
507     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
509     // Check locking & lock entry if required 
510     $this->displayApplyBtn = FALSE;
511     $this->dn = "new";
512     $this->is_new = TRUE;
513     $this->is_single_edit = FALSE;
514     $this->is_multiple_edit = FALSE;
516     set_object_info($this->dn);
518     // Open object.
519     if(empty($tabClass) || empty($tabType)){
520       // No tab type defined
521     }else{
522       $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
523       $this->tabObject->set_acl_base($this->headpage->getBase());
524     }
525   }
528   /*! \brief  This method opens an existing object or a list of existing objects to be edited. 
529    *                  
530    * 
531    *  @param  String  'action'  The name of the action which was the used as trigger.
532    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
533    *  @param  Array   'all'     A combination of both 'action' and 'target'.
534    */
535   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
536   {
537     /* To handle mutliple object types overload this method.
538      * ...
539      *   registerAction('editUser', 'editEntry');
540      *   registerAction('editGroup','editEntry');
541      * ... 
542      * 
543      * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
544      * {
545      *   switch($action){
546      *     case 'editUser' : {
547      *       mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
548      *     }
549      *     case 'editGroup' : {
550      *       mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
551      *     }
552      *   }
553      * }
554      **/ 
555     $tabType = $this->tabType;
556     $tabClass = $this->tabClass;
557     $aclCategory = $this->aclCategory;
558     if(!empty($altTabClass)) $tabClass = $altTabClass;
559     if(!empty($altTabType)) $tabType = $altTabType;
560     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
562     // Single edit - we only got one object dn.
563     if(count($target) == 1){
564       $this->displayApplyBtn = TRUE;
565       $this->is_new = FALSE;
566       $this->is_single_edit = TRUE;
567       $this->is_multiple_edit = FALSE;
569       // Get the dn of the object and creates lock
570       $this->dn = array_pop($target);
571       set_object_info($this->dn);
572       $user = get_lock($this->dn);
573       if ($user != ""){
574         return(gen_locked_message ($user, $this->dn,TRUE));
575       }
576       add_lock ($this->dn, $this->ui->dn);
578       // Open object.
579       if(empty($tabClass) || empty($tabType)){
580         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
581       }else{
582         $tab = $tabClass;
583         $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
584         $this->tabObject->set_acl_base($this->dn);
585       }
586     }else{
588       // We've multiple entries to edit.
589       $this->is_new = FALSE;
590       $this->is_singel_edit = FALSE;
591       $this->is_multiple_edit = TRUE;
593       // Open multiple edit handler.
594       if(empty($tabClass) || empty($tabType)){
595         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
596       }else{
597         $this->dns = $target;
598         $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
599             $this->dns,$this->headpage->getBase(),$aclCategory);
601         // Check for locked entries
602         if ($tmp->entries_locked()){
603           return($tmp->display_lock_message());
604         }
606         // Now lock entries.
607         $tmp->lock_entries($this->ui->dn);
608         if($tmp->multiple_available()){
609           $this->tabObject = $tmp;
610           set_object_info($this->tabObject->get_object_info());
611         }
612       }
613     }
614   }
617   /*! \brief  Save object modifications and closes dialogs (returns to object listing).
618    *          - Calls '::check' to validate the given input.
619    *          - Calls '::save' to save back object modifications (e.g. to ldap).
620    *          - Calls '::remove_locks' to remove eventually created locks.
621    *          - Calls '::closeDialogs' to return to the object listing.
622    */
623   protected function saveChanges()
624   {
625     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
626       $this->tabObject->save_object();
627       $msgs = $this->tabObject->check();
628       if(count($msgs)){
629         msg_dialog::displayChecks($msgs); 
630         return("");
631       }else{
632         $this->tabObject->save();
633         $this->remove_lock();
634         $this->closeDialogs();
635       }
636     }
637   }
640   /*! \brief  Save object modifications and keep dialogs opened. 
641    *          - Calls '::check' to validate the given input.
642    *          - Calls '::save' to save back object modifications (e.g. to ldap).
643    */
644   protected function applyChanges()
645   {
646     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
647       $this->tabObject->save_object();
648       $msgs = $this->tabObject->check();
649       if(count($msgs)){
650         msg_dialog::displayChecks($msgs); 
651         return("");
652       }else{
653         $this->tabObject->save();
654         $this->tabObject->re_init();
655       }
656     }
657   }
660   /*! \brief  This method closes dialogs
661    *           and cleans up the cached object info and the ui.
662    */
663   protected function closeDialogs()
664   {
665     $this->last_dn = $this->dn;
666     $this->last_dns = $this->dns;
667     $this->last_tabObject = $this->tabObject;
668     $this->last_dialogObject = $this->dialogObject;
669     $this->dn = "";
670     $this->dns = array();
671     $this->tabObject = null;
672     $this->dialogObject = null;
673     set_object_info();
674   }
677   /*! \brief  Editing an object was caneled. 
678    *          Close dialogs/tabs and remove locks.
679    */
680   protected function cancelEdit()
681   {
682     $this->remove_lock();
683     $this->closeDialogs();
684   }
687   /*! \brief  Every click in the list user interface sends an event
688    *           here can we connect those events to a method. 
689    *          eg.  ::registerEvent('new','createUser')
690    *          When the action/event new is send, the method 'createUser' 
691    *           will be called.
692    */
693   function registerAction($action,$target)
694   {
695     $this->actions[$action] = $target;
696   }
699   /*! \brief  Removes ldap object locks created by this class.
700    *          Whenever an object is edited, we create locks to avoid 
701    *           concurrent modifications.
702    *          This locks will automatically removed here.
703    */
704   function remove_lock()
705   {
706     if(!empty($this->dn) && $this->dn != "new"){
707       del_lock($this->dn);
708     }
709     if(count($this->dns)){
710       del_lock($this->dns);
711     }
712   }
715   /*! \brief  This method is used to queue and process copy&paste actions. 
716    *          Allows to copy, cut and paste mutliple entries at once.
717    *  @param  String  'action'  The name of the action which was the used as trigger.
718    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
719    *  @param  Array   'all'     A combination of both 'action' and 'target'.
720    */
721   function copyPasteHandler($action="",$target=array(),$all=array(), 
722       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
723   {
724     // Return without any actions while copy&paste handler is disabled.
725     if(!is_object($this->cpHandler))  return("");
727     $tabType = $this->tabType;
728     $tabClass = $this->tabClass;
729     $aclCategory = $this->aclCategory;
730     $aclPlugin = $this->aclPlugin;
731     if(!empty($altTabClass)) $tabClass = $altTabClass;
732     if(!empty($altTabType)) $tabType = $altTabType;
733     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
734     if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
736     // Save user input
737     $this->cpHandler->save_object();
739     // Add entries to queue 
740     if($action == "copy" || $action == "cut"){
741       $this->cpHandler->cleanup_queue();
742       foreach($target as $dn){
743         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
744           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory);
745         }
746         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
747           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory);
748         }
749       }
750     }
752     // Initiate pasting
753     if($action == "paste"){
754       $this->cpPastingStarted = TRUE;
755     }
757     // Display any c&p dialogs, eg. object modifications required before pasting.
758     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
759       $this->cpHandler->SetVar("base",$this->headpage->getBase());
760       $data = $this->cpHandler->execute();
761       if(!empty($data)){
762         return($data);
763       }
764     }
766     // Automatically disable pasting process since there is no entry left to paste.
767     if(!$this->cpHandler->entries_queued()){
768       $this->cpPastingStarted = FALSE;
769     }
770     return("");
771   }
774   function setFilter($str) {
775     $this->filter = $str;
776   }
780 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
781 ?>