Code

Added additional filter
[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");
111   }
113   /*! \brief  Execute this plugin
114    *          Handle actions/events, locking, snapshots, dialogs, tabs,...
115    */
116   function execute()
117   {
118     // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
119     $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
120     session::set('LOCK_VARS_TO_USE',$vars);
122     /* Display the copy & paste dialog, if it is currently open */
123     $ret = $this->copyPasteHandler("",array());
124     if($ret){
125       return($this->getHeader().$ret);
126     }
128     // Update filter
129     if ($this->filter) {
130       $this->filter->update();
131       session::global_set(get_class($this)."_filter", $this->filter);
132       session::set('autocomplete', $this->filter);
133       if (!$this->filter->isValid()){
134         msg_dialog::display(_("Filter error"), _("The filter is incomplete!"), ERROR_DIALOG);
135       }
136     }
138     // Handle actions (POSTs and GETs)
139     $str = $this->handleActions($this->detectPostActions());
140     if($str) return($this->getHeader().$str);
142     // Open single dialog objects
143     if(is_object($this->dialogObject)){
144       if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object(); 
145       if(method_exists($this->dialogObject,'execute')){
146         $display = $this->dialogObject->execute(); 
147         $display.= $this->_getTabFooter();
148         return($this->getHeader().$display);
149       } 
150     }
152     // Display tab object.
153     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
154       $this->tabObject->save_object();
155       $display = $this->tabObject->execute();
156       $display.= $this->_getTabFooter();
157       return($this->getHeader().$display);
158     }
160     // Set current restore base for snapshot handling.
161     if(is_object($this->snapHandler)){
162       $bases = array();
163       foreach($this->storagePoints as $sp){
164         $bases[] = $sp.$this->headpage->getBase();
165       }
166       $this->snapHandler->setSnapshotBases($bases);
167     }
169     $this->headpage->update();
170     $display = $this->headpage->render();
171     return($this->getHeader().$display);
172   }
176   /*! \brief  Generates the plugin header which is displayed whenever a tab object is 
177    *           opened.
178    */
179   protected function getHeader()
180   {
181     if (get_object_info() != ""){
182       $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
183           "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
184           LDAP::fix(get_object_info()));
185     } else {
186       $display= print_header(get_template_path($this->plIcon),_($this->plDescription));
187     }
188     return($display);
189   }
192   /*! \brief  Generates the footer which is used whenever a tab object is 
193    *           displayed.
194    */
195   protected function _getTabFooter()
196   {
197     // Do not display tab footer for non tab objects 
198     if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
199       return("");
200     }
202     // Check if there is a dialog opened - We don't need any buttons in this case. 
203     if($this->tabObject->by_object[$this->tabObject->current]){
204       $current = $this->tabObject->by_object[$this->tabObject->current];  
205       if(is_object($current->dialog)){
206         return("");
207       }
208     }
210     // In case an of locked entry, we may have opened a read-only tab.
211     $str = "";
212     if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
213       $str.= "<p style=\"text-align:right\">
214         <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
215         </p>";
216       return($str);
217     }else{
219       // Display ok, (apply) and cancel buttons
220       $str.= "<p style=\"text-align:right\">\n";
221       $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
222       $str.= "&nbsp;\n";
223       if($this->displayApplyBtn){
224         $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
225         $str.= "&nbsp;\n";
226       }
227       $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
228       $str.= "</p>";
229     }
230     return($str);
231   }
234   /*! \brief  Initiates the removal for the given entries
235    *           and displays a confirmation dialog.
236    *      
237    *  @param  String  'action'  The name of the action which was the used as trigger.
238    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
239    *  @param  Array   'all'     A combination of both 'action' and 'target'.
240    */
241   protected function removeEntryRequested($action="",$target=array(),$all=array())
242   {
243     $disallowed = array();
244     $this->dns = array();
246     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
248     // Check permissons for each target 
249     foreach($target as $dn){
250       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
251       if(preg_match("/d/",$acl)){
252         $this->dns[] = $dn;
253       }else{
254         $disallowed[] = $dn;
255       }
256     }
257     if(count($disallowed)){
258       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
259     }
261     // We've at least one entry to delete.
262     if(count($this->dns)){
264       // check locks
265       if ($user= get_multiple_locks($this->dns)){
266         return(gen_locked_message($user,$this->dns));
267       }
269       // Add locks
270       $dns_names = array();
271       foreach($this->dns as $dn){
272         $dns_names[] =LDAP::fix($dn);
273       }
274       add_lock ($this->dns, $this->ui->dn);
276       // Display confirmation dialog.
277       $smarty = get_smarty();
278       $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
279       $smarty->assign("multiple", true);
280       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
281     }
282   }  
285   /*! \brief  Object removal was confirmed, now remove the requested entries. 
286    *      
287    *  @param  String  'action'  The name of the action which was the used as trigger.
288    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
289    *  @param  Array   'all'     A combination of both 'action' and 'target'.
290    */
291   function removeEntryConfirmed($action="",$target=array(),$all=array(),
292       $altTabClass="",$altTabType="",$altAclCategory="")
293   {
294     $tabType = $this->tabType;
295     $tabClass = $this->tabClass;
296     $aclCategory = $this->aclCategory;
297     if(!empty($altTabClass)) $tabClass = $altTabClass;
298     if(!empty($altTabType)) $tabType = $altTabType;
299     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
301     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
303     foreach($this->dns as $key => $dn){
305       // Check permissions, are we allowed to remove this object? 
306       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
307       if(preg_match("/d/",$acl)){
309         // Delete the object
310         $this->dn = $dn;
311         $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
312         $this->tabObject->set_acl_base($this->dn);
313         $this->tabObject->delete ();
315         // Remove the lock for the current object.
316         del_lock($this->dn);        
317       } else {
318         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
319         new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
320       }
321     }
323     // Cleanup
324     $this->remove_lock();
325     $this->closeDialogs();
326   }
329   /*! \brief  Detects actions/events send by the ui
330    *           and the corresponding targets.
331    */
332   function detectPostActions()
333   {
334     $action= $this->headpage->getAction();
335     if(isset($_POST['edit_apply']))  $action['action'] = "apply";    
336     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
337     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
338     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
340     // Detect Snapshot actions
341     if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";   
342     if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";   
343     foreach($_POST as $name => $value){
344       $once =TRUE;
345       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
346         $once = FALSE;
347         $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
348         $action['action'] = "restoreSnapshot";
349         $action['targets'] = array($entry);
350       }
351     }
353     return($action);
354   }
357   /*! \brief  Calls the registered method for a given action/event.
358    */
359   function handleActions($action)
360   {
361     // Start action  
362     if(isset($this->actions[$action['action']])){
363       $func = $this->actions[$action['action']];
364       if(!isset($action['targets']))$action['targets']= array(); 
365       return($this->$func($action['action'],$action['targets'],$action));
366     }
367   } 
370   /*! \brief  Opens the snapshot creation dialog for the given target.
371    *      
372    *  @param  String  'action'  The name of the action which was the used as trigger.
373    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
374    *  @param  Array   'all'     A combination of both 'action' and 'target'.
375    */
376   function createSnapshotDialog($action="",$target=array(),$all=array())
377   {
378     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
380     foreach($target as $entry){
381       if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
382         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
383         $this->dialogObject->aclCategories = array($this->aclCategory);
385       }else{
386         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
387             ERROR_DIALOG);
388       }
389     }
390   }
393   /*! \brief  Creates a snapshot new entry - This method is called when the somebody
394    *           clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
395    *      
396    *  @param  String  'action'  The name of the action which was the used as trigger.
397    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
398    *  @param  Array   'all'     A combination of both 'action' and 'target'.
399    */
400   function saveSnapshot($action="",$target=array(),$all=array())
401   {
402     $this->dialogObject->save_object();
403     $msgs = $this->dialogObject->check();
404     if(count($msgs)){
405       foreach($msgs as $msg){
406         msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
407       }
408     }else{
409       $this->dn =  $this->dialogObject->dn;
410       $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
411       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
412       $this->closeDialogs();
413     }
414   }
417   /*! \brief  Restores a snapshot object.
418    *          The dn of the snapshot entry has to be given as ['target'] parameter.  
419    *      
420    *  @param  String  'action'  The name of the action which was the used as trigger.
421    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
422    *  @param  Array   'all'     A combination of both 'action' and 'target'.
423    */
424   function restoreSnapshot($action="",$target=array(),$all=array())
425   {
426     $entry = array_pop($target);
427     if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
428       $this->snapHandler->restore_snapshot($entry);
429       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
430       $this->closeDialogs();
431     }else{
432       msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
433           ERROR_DIALOG);
434     }
435   }
438   /*! \brief  Displays the "Restore snapshot dialog" for a given target. 
439    *          If no target is specified, open the restore removed object 
440    *           dialog.
441    *  @param  String  'action'  The name of the action which was the used as trigger.
442    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
443    *  @param  Array   'all'     A combination of both 'action' and 'target'.
444    */
445   function restoreSnapshotDialog($action="",$target=array(),$all=array())
446   {
447     // Set current restore base for snapshot handling.
448     if(is_object($this->snapHandler)){
449       $bases = array();
450       foreach($this->storagePoints as $sp){
451         $bases[] = $sp.$this->headpage->getBase();
452       }
453     }
455     // No target, open the restore removed object dialog.
456     if(!count($target)){ 
457       $entry = $this->headpage->getBase();
458       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
459         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
460         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
461         $this->dialogObject->set_snapshot_bases($bases);
462         $this->dialogObject->display_all_removed_objects = true;
463         $this->dialogObject->display_restore_dialog = true;
464       }else{
465         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
466             ERROR_DIALOG);
467       } 
468     }else{
470       // Display the restore points for a given object.
471       $entry = array_pop($target);
472       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
473         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
474         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
475         $this->dialogObject->set_snapshot_bases($bases);
476         $this->dialogObject->display_restore_dialog = true;
477       }else{
478         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
479             ERROR_DIALOG);
480       } 
481     }
482   }
485   /*! \brief  This method intiates the object creation.
486    *          
487    *  @param  String  'action'  The name of the action which was the used as trigger.
488    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
489    *  @param  Array   'all'     A combination of both 'action' and 'target'.
490    */
491   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
492   {
493     /* To handle mutliple object types overload this method.
494      * ...
495      *   registerAction('newUser', 'newEntry');
496      *   registerAction('newGroup','newEntry');
497      * ... 
498      * 
499      * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
500      * {
501      *   switch($action){
502      *     case 'newUser' : {
503      *       mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
504      *     }
505      *     case 'newGroup' : {
506      *       mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
507      *     }
508      *   }
509      * }
510      **/ 
511     $tabType = $this->tabType;
512     $tabClass = $this->tabClass;
513     $aclCategory = $this->aclCategory;
514     if(!empty($altTabClass)) $tabClass = $altTabClass;
515     if(!empty($altTabType)) $tabType = $altTabType;
516     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
518     // Check locking & lock entry if required 
519     $this->displayApplyBtn = FALSE;
520     $this->dn = "new";
521     $this->is_new = TRUE;
522     $this->is_single_edit = FALSE;
523     $this->is_multiple_edit = FALSE;
525     set_object_info($this->dn);
527     // Open object.
528     if(empty($tabClass) || empty($tabType)){
529       // No tab type defined
530     }else{
531       $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
532       $this->tabObject->set_acl_base($this->headpage->getBase());
533       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
534     }
535   }
538   /*! \brief  This method opens an existing object or a list of existing objects to be edited. 
539    *                  
540    * 
541    *  @param  String  'action'  The name of the action which was the used as trigger.
542    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
543    *  @param  Array   'all'     A combination of both 'action' and 'target'.
544    */
545   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
546   {
547     /* To handle mutliple object types overload this method.
548      * ...
549      *   registerAction('editUser', 'editEntry');
550      *   registerAction('editGroup','editEntry');
551      * ... 
552      * 
553      * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
554      * {
555      *   switch($action){
556      *     case 'editUser' : {
557      *       mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
558      *     }
559      *     case 'editGroup' : {
560      *       mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
561      *     }
562      *   }
563      * }
564      **/ 
565     $tabType = $this->tabType;
566     $tabClass = $this->tabClass;
567     $aclCategory = $this->aclCategory;
568     if(!empty($altTabClass)) $tabClass = $altTabClass;
569     if(!empty($altTabType)) $tabType = $altTabType;
570     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
572     // Single edit - we only got one object dn.
573     if(count($target) == 1){
574       $this->displayApplyBtn = TRUE;
575       $this->is_new = FALSE;
576       $this->is_single_edit = TRUE;
577       $this->is_multiple_edit = FALSE;
579       // Get the dn of the object and creates lock
580       $this->dn = array_pop($target);
581       set_object_info($this->dn);
582       $user = get_lock($this->dn);
583       if ($user != ""){
584         return(gen_locked_message ($user, $this->dn,TRUE));
585       }
586       add_lock ($this->dn, $this->ui->dn);
588       // Open object.
589       if(empty($tabClass) || empty($tabType)){
590         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
591       }else{
592         $tab = $tabClass;
593         $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
594         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
595         $this->tabObject->set_acl_base($this->dn);
596       }
597     }else{
599       // We've multiple entries to edit.
600       $this->is_new = FALSE;
601       $this->is_singel_edit = FALSE;
602       $this->is_multiple_edit = TRUE;
604       // Open multiple edit handler.
605       if(empty($tabClass) || empty($tabType)){
606         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
607       }else{
608         $this->dns = $target;
609         $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
610             $this->dns,$this->headpage->getBase(),$aclCategory);
612         // Check for locked entries
613         if ($tmp->entries_locked()){
614           return($tmp->display_lock_message());
615         }
617         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
619         // Now lock entries.
620         $tmp->lock_entries($this->ui->dn);
621         if($tmp->multiple_available()){
622           $this->tabObject = $tmp;
623           set_object_info($this->tabObject->get_object_info());
624         }
625       }
626     }
627   }
630   /*! \brief  Save object modifications and closes dialogs (returns to object listing).
631    *          - Calls '::check' to validate the given input.
632    *          - Calls '::save' to save back object modifications (e.g. to ldap).
633    *          - Calls '::remove_locks' to remove eventually created locks.
634    *          - Calls '::closeDialogs' to return to the object listing.
635    */
636   protected function saveChanges()
637   {
638     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
639       $this->tabObject->save_object();
640       $msgs = $this->tabObject->check();
641       if(count($msgs)){
642         msg_dialog::displayChecks($msgs); 
643         return("");
644       }else{
645         $this->tabObject->save();
646         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
647         $this->remove_lock();
648         $this->closeDialogs();
649       }
650     }
651   }
654   /*! \brief  Save object modifications and keep dialogs opened. 
655    *          - Calls '::check' to validate the given input.
656    *          - Calls '::save' to save back object modifications (e.g. to ldap).
657    */
658   protected function applyChanges()
659   {
660     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
661       $this->tabObject->save_object();
662       $msgs = $this->tabObject->check();
663       if(count($msgs)){
664         msg_dialog::displayChecks($msgs); 
665         return("");
666       }else{
667         $this->tabObject->save();
668         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
669         $this->tabObject->re_init();
670       }
671     }
672   }
675   /*! \brief  This method closes dialogs
676    *           and cleans up the cached object info and the ui.
677    */
678   protected function closeDialogs()
679   {
680     $this->last_dn = $this->dn;
681     $this->last_dns = $this->dns;
682     $this->last_tabObject = $this->tabObject;
683     $this->last_dialogObject = $this->dialogObject;
684     $this->dn = "";
685     $this->dns = array();
686     $this->tabObject = null;
687     $this->dialogObject = null;
688     set_object_info();
689   }
692   /*! \brief  Editing an object was caneled. 
693    *          Close dialogs/tabs and remove locks.
694    */
695   protected function cancelEdit()
696   {
697     $this->remove_lock();
698     $this->closeDialogs();
699   }
702   /*! \brief  Every click in the list user interface sends an event
703    *           here can we connect those events to a method. 
704    *          eg.  ::registerEvent('new','createUser')
705    *          When the action/event new is send, the method 'createUser' 
706    *           will be called.
707    */
708   function registerAction($action,$target)
709   {
710     $this->actions[$action] = $target;
711   }
714   /*! \brief  Removes ldap object locks created by this class.
715    *          Whenever an object is edited, we create locks to avoid 
716    *           concurrent modifications.
717    *          This locks will automatically removed here.
718    */
719   function remove_lock()
720   {
721     if(!empty($this->dn) && $this->dn != "new"){
722       del_lock($this->dn);
723     }
724     if(count($this->dns)){
725       del_lock($this->dns);
726     }
727   }
730   /*! \brief  This method is used to queue and process copy&paste actions. 
731    *          Allows to copy, cut and paste mutliple entries at once.
732    *  @param  String  'action'  The name of the action which was the used as trigger.
733    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
734    *  @param  Array   'all'     A combination of both 'action' and 'target'.
735    */
736   function copyPasteHandler($action="",$target=array(),$all=array(), 
737       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
738   {
739     // Return without any actions while copy&paste handler is disabled.
740     if(!is_object($this->cpHandler))  return("");
742     $tabType = $this->tabType;
743     $tabClass = $this->tabClass;
744     $aclCategory = $this->aclCategory;
745     $aclPlugin = $this->aclPlugin;
746     if(!empty($altTabClass)) $tabClass = $altTabClass;
747     if(!empty($altTabType)) $tabType = $altTabType;
748     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
749     if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
751     // Save user input
752     $this->cpHandler->save_object();
754     // Add entries to queue 
755     if($action == "copy" || $action == "cut"){
756       $this->cpHandler->cleanup_queue();
757       foreach($target as $dn){
758         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
759           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory);
760           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
761         }
762         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
763           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory);
764           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
765         }
766       }
767     }
769     // Initiate pasting
770     if($action == "paste"){
771       $this->cpPastingStarted = TRUE;
772     }
774     // Display any c&p dialogs, eg. object modifications required before pasting.
775     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
776       $this->cpHandler->SetVar("base",$this->headpage->getBase());
777       $data = $this->cpHandler->execute();
778       if(!empty($data)){
779         return($data);
780       }
781     }
783     // Automatically disable pasting process since there is no entry left to paste.
784     if(!$this->cpHandler->entries_queued()){
785       $this->cpPastingStarted = FALSE;
786     }
787     return("");
788   }
791   function setFilter($str) {
792     $this->filter = $str;
793   }
797 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
798 ?>