Code

- Yeah, we have complete svn build of GOsa, GOto, GOsa-si with svn tags and
[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$$
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   private $headpage = null;
74   private $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("cancelDelete", "cancelEdit");
100     $this->registerAction("remove", "removeEntryRequested");
101     $this->registerAction("removeConfirmed", "removeEntryConfirmed");
103     $this->registerAction("copy",   "copyPasteHandler");
104     $this->registerAction("cut",    "copyPasteHandler");
105     $this->registerAction("paste",  "copyPasteHandler");
107     $this->registerAction("snapshot",    "createSnapshotDialog");
108     $this->registerAction("restore",     "restoreSnapshotDialog");
109     $this->registerAction("saveSnapshot","saveSnapshot");
110     $this->registerAction("restoreSnapshot","restoreSnapshot");
111     $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       }
168       // No bases specified? Try base  
169       if(!count($bases)) $bases[] = $this->headpage->getBase();
171       $this->snapHandler->setSnapshotBases($bases);
172     }
173     
174     // Display list
175     return($this->renderList());
176   }
177   
178   function renderList()
179   {
180     $this->headpage->update();
181     $display = $this->headpage->render();
182     return($this->getHeader().$display);
183   }
185   function getHeadpage()
186   {
187     return($this->headpage);
188   }
190   function getFilter()
191   {
192     return($this->filter);
193   }
195   /*! \brief  Generates the plugin header which is displayed whenever a tab object is 
196    *           opened.
197    */
198   protected function getHeader()
199   {
200     if (get_object_info() != ""){
201       $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
202           "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
203           LDAP::fix(get_object_info()));
204     } else {
205       $display= print_header(get_template_path($this->plIcon),_($this->plDescription));
206     }
207     return($display);
208   }
211   /*! \brief  Generates the footer which is used whenever a tab object is 
212    *           displayed.
213    */
214   protected function _getTabFooter()
215   {
216     // Do not display tab footer for non tab objects 
217     if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
218       return("");
219     }
221     // Check if there is a dialog opened - We don't need any buttons in this case. 
222     if($this->tabObject->by_object[$this->tabObject->current]){
223       $current = $this->tabObject->by_object[$this->tabObject->current];  
224       if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
225         return("");
226       }
227     }
229     // In case an of locked entry, we may have opened a read-only tab.
230     $str = "";
231     if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
232       $str.= "<p style=\"text-align:right\">
233         <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
234         </p>";
235       return($str);
236     }else{
238       // Display ok, (apply) and cancel buttons
239       $str.= "<p style=\"text-align:right\">\n";
240       $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
241       $str.= "&nbsp;\n";
242       if($this->displayApplyBtn){
243         $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
244         $str.= "&nbsp;\n";
245       }
246       $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
247       $str.= "</p>";
248     }
249     return($str);
250   }
253   /*! \brief  Initiates the removal for the given entries
254    *           and displays a confirmation dialog.
255    *      
256    *  @param  String  'action'  The name of the action which was the used as trigger.
257    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
258    *  @param  Array   'all'     A combination of both 'action' and 'target'.
259    */
260   protected function removeEntryRequested($action="",$target=array(),$all=array())
261   {
262     $disallowed = array();
263     $this->dns = array();
265     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
267     // Check permissons for each target 
268     foreach($target as $dn){
269       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
270       if(preg_match("/d/",$acl)){
271         $this->dns[] = $dn;
272       }else{
273         $disallowed[] = $dn;
274       }
275     }
276     if(count($disallowed)){
277       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
278     }
280     // We've at least one entry to delete.
281     if(count($this->dns)){
283       // check locks
284       if ($user= get_multiple_locks($this->dns)){
285         return(gen_locked_message($user,$this->dns));
286       }
288       // Add locks
289       $dns_names = array();
290       foreach($this->dns as $dn){
291         $dns_names[] =LDAP::fix($dn);
292       }
293       add_lock ($this->dns, $this->ui->dn);
295       // Display confirmation dialog.
296       $smarty = get_smarty();
297       $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
298       $smarty->assign("multiple", true);
299       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
300     }
301   }  
304   /*! \brief  Object removal was confirmed, now remove the requested entries. 
305    *      
306    *  @param  String  'action'  The name of the action which was the used as trigger.
307    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
308    *  @param  Array   'all'     A combination of both 'action' and 'target'.
309    */
310   function removeEntryConfirmed($action="",$target=array(),$all=array(),
311       $altTabClass="",$altTabType="",$altAclCategory="")
312   {
313     $tabType = $this->tabType;
314     $tabClass = $this->tabClass;
315     $aclCategory = $this->aclCategory;
316     if(!empty($altTabClass)) $tabClass = $altTabClass;
317     if(!empty($altTabType)) $tabType = $altTabType;
318     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
320     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
322     foreach($this->dns as $key => $dn){
324       // Check permissions, are we allowed to remove this object? 
325       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
326       if(preg_match("/d/",$acl)){
328         // Delete the object
329         $this->dn = $dn;
330         $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
331         $this->tabObject->set_acl_base($this->dn);
332         $this->tabObject->delete ();
333         $this->tabObject->parent = &$this;
335         // Remove the lock for the current object.
336         del_lock($this->dn);        
337       } else {
338         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
339         new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
340       }
341     }
343     // Cleanup
344     $this->remove_lock();
345     $this->closeDialogs();
346   }
349   /*! \brief  Detects actions/events send by the ui
350    *           and the corresponding targets.
351    */
352   function detectPostActions()
353   {
354     if(!is_object($this->headpage)){
355       trigger_error("No valid headpage given....!");
356       return(array());
357     }
358     $action= $this->headpage->getAction();
359     if(isset($_POST['edit_apply']))  $action['action'] = "apply";    
360     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
361     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
362     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
363     if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";   
365     // Detect Snapshot actions
366     if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";   
367     if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";   
368     foreach($_POST as $name => $value){
369       $once =TRUE;
370       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
371         $once = FALSE;
372         $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
373         $action['action'] = "restoreSnapshot";
374         $action['targets'] = array($entry);
375       }
376     }
378     return($action);
379   }
382   /*! \brief  Calls the registered method for a given action/event.
383    */
384   function handleActions($action)
385   {
386     // Start action  
387     if(isset($this->actions[$action['action']])){
388       $func = $this->actions[$action['action']];
389       if(!isset($action['targets']))$action['targets']= array(); 
390       return($this->$func($action['action'],$action['targets'],$action));
391     }
392   } 
395   /*! \brief  Opens the snapshot creation dialog for the given target.
396    *      
397    *  @param  String  'action'  The name of the action which was the used as trigger.
398    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
399    *  @param  Array   'all'     A combination of both 'action' and 'target'.
400    */
401   function createSnapshotDialog($action="",$target=array(),$all=array())
402   {
403     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
405     foreach($target as $entry){
406       if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
407         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
408         $this->dialogObject->aclCategories = array($this->aclCategory);
409         $this->dialogObject->parent = &$this;
411       }else{
412         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
413             ERROR_DIALOG);
414       }
415     }
416   }
419   /*! \brief  Creates a snapshot new entry - This method is called when the somebody
420    *           clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
421    *      
422    *  @param  String  'action'  The name of the action which was the used as trigger.
423    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
424    *  @param  Array   'all'     A combination of both 'action' and 'target'.
425    */
426   function saveSnapshot($action="",$target=array(),$all=array())
427   {
428     $this->dialogObject->save_object();
429     $msgs = $this->dialogObject->check();
430     if(count($msgs)){
431       foreach($msgs as $msg){
432         msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
433       }
434     }else{
435       $this->dn =  $this->dialogObject->dn;
436       $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
437       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
438       $this->closeDialogs();
439     }
440   }
443   /*! \brief  Restores a snapshot object.
444    *          The dn of the snapshot entry has to be given as ['target'] parameter.  
445    *      
446    *  @param  String  'action'  The name of the action which was the used as trigger.
447    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
448    *  @param  Array   'all'     A combination of both 'action' and 'target'.
449    */
450   function restoreSnapshot($action="",$target=array(),$all=array())
451   {
452     $entry = array_pop($target);
453     if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
454       $this->snapHandler->restore_snapshot($entry);
455       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
456       $this->closeDialogs();
457     }else{
458       msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
459           ERROR_DIALOG);
460     }
461   }
464   /*! \brief  Displays the "Restore snapshot dialog" for a given target. 
465    *          If no target is specified, open the restore removed object 
466    *           dialog.
467    *  @param  String  'action'  The name of the action which was the used as trigger.
468    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
469    *  @param  Array   'all'     A combination of both 'action' and 'target'.
470    */
471   function restoreSnapshotDialog($action="",$target=array(),$all=array())
472   {
473     // Set current restore base for snapshot handling.
474     if(is_object($this->snapHandler)){
475       $bases = array();
476       foreach($this->storagePoints as $sp){
477         $bases[] = $sp.$this->headpage->getBase();
478       }
479     }
481     // No bases specified? Try base  
482     if(!count($bases)) $bases[] = $this->headpage->getBase();
484     // No target, open the restore removed object dialog.
485     if(!count($target)){ 
486       $entry = $this->headpage->getBase();
487       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
488         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
489         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
490         $this->dialogObject->set_snapshot_bases($bases);
491         $this->dialogObject->display_all_removed_objects = true;
492         $this->dialogObject->display_restore_dialog = true;
493         $this->dialogObject->parent = &$this;
494       }else{
495         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
496             ERROR_DIALOG);
497       } 
498     }else{
500       // Display the restore points for a given object.
501       $entry = array_pop($target);
502       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
503         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
504         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
505         $this->dialogObject->set_snapshot_bases($bases);
506         $this->dialogObject->display_restore_dialog = true;
507         $this->dialogObject->parent = &$this;
508       }else{
509         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
510             ERROR_DIALOG);
511       } 
512     }
513   }
516   /*! \brief  This method intiates the object creation.
517    *          
518    *  @param  String  'action'  The name of the action which was the used as trigger.
519    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
520    *  @param  Array   'all'     A combination of both 'action' and 'target'.
521    */
522   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
523   {
524     /* To handle mutliple object types overload this method.
525      * ...
526      *   registerAction('newUser', 'newEntry');
527      *   registerAction('newGroup','newEntry');
528      * ... 
529      * 
530      * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
531      * {
532      *   switch($action){
533      *     case 'newUser' : {
534      *       mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
535      *     }
536      *     case 'newGroup' : {
537      *       mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
538      *     }
539      *   }
540      * }
541      **/ 
542     $tabType = $this->tabType;
543     $tabClass = $this->tabClass;
544     $aclCategory = $this->aclCategory;
545     if(!empty($altTabClass)) $tabClass = $altTabClass;
546     if(!empty($altTabType)) $tabType = $altTabType;
547     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
549     // Check locking & lock entry if required 
550     $this->displayApplyBtn = FALSE;
551     $this->dn = "new";
552     $this->is_new = TRUE;
553     $this->is_single_edit = FALSE;
554     $this->is_multiple_edit = FALSE;
556     set_object_info($this->dn);
558     // Open object.
559     if(empty($tabClass) || empty($tabType)){
560       // No tab type defined
561     }else{
562       $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
563       $this->tabObject->set_acl_base($this->headpage->getBase());
564       $this->tabObject->parent = &$this;
565       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
566     }
567   }
570   /*! \brief  This method opens an existing object or a list of existing objects to be edited. 
571    *                  
572    * 
573    *  @param  String  'action'  The name of the action which was the used as trigger.
574    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
575    *  @param  Array   'all'     A combination of both 'action' and 'target'.
576    */
577   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
578   {
579     /* To handle mutliple object types overload this method.
580      * ...
581      *   registerAction('editUser', 'editEntry');
582      *   registerAction('editGroup','editEntry');
583      * ... 
584      * 
585      * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
586      * {
587      *   switch($action){
588      *     case 'editUser' : {
589      *       mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
590      *     }
591      *     case 'editGroup' : {
592      *       mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
593      *     }
594      *   }
595      * }
596      **/
598     // Do not create a new tabObject while there is already one opened,
599     //  the user may have just pressed F5 to reload the page.
600     if(is_object($this->tabObject)){
601       return;
602     }
603  
604     $tabType = $this->tabType;
605     $tabClass = $this->tabClass;
606     $aclCategory = $this->aclCategory;
607     if(!empty($altTabClass)) $tabClass = $altTabClass;
608     if(!empty($altTabType)) $tabType = $altTabType;
609     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
611     // Single edit - we only got one object dn.
612     if(count($target) == 1){
613       $this->displayApplyBtn = TRUE;
614       $this->is_new = FALSE;
615       $this->is_single_edit = TRUE;
616       $this->is_multiple_edit = FALSE;
618       // Get the dn of the object and creates lock
619       $this->dn = array_pop($target);
620       set_object_info($this->dn);
621       $user = get_lock($this->dn);
622       if ($user != ""){
623         return(gen_locked_message ($user, $this->dn,TRUE));
624       }
625       add_lock ($this->dn, $this->ui->dn);
627       // Open object.
628       if(empty($tabClass) || empty($tabType)){
629         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
630       }else{
631         $tab = $tabClass;
632         $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
633         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
634         $this->tabObject->set_acl_base($this->dn);
635         $this->tabObject->parent = &$this;
636       }
637     }else{
639       // We've multiple entries to edit.
640       $this->is_new = FALSE;
641       $this->is_singel_edit = FALSE;
642       $this->is_multiple_edit = TRUE;
644       // Open multiple edit handler.
645       if(empty($tabClass) || empty($tabType)){
646         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
647       }else{
648         $this->dns = $target;
649         $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
650             $this->dns,$this->headpage->getBase(),$aclCategory);
652         // Check for locked entries
653         if ($tmp->entries_locked()){
654           return($tmp->display_lock_message());
655         }
657         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
659         // Now lock entries.
660         $tmp->lock_entries($this->ui->dn);
661         if($tmp->multiple_available()){
662           $this->tabObject = $tmp;
663           set_object_info($this->tabObject->get_object_info());
664         }
665       }
666     }
667   }
670   /*! \brief  Save object modifications and closes dialogs (returns to object listing).
671    *          - Calls '::check' to validate the given input.
672    *          - Calls '::save' to save back object modifications (e.g. to ldap).
673    *          - Calls '::remove_locks' to remove eventually created locks.
674    *          - Calls '::closeDialogs' to return to the object listing.
675    */
676   protected function saveChanges()
677   {
678     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
679       $this->tabObject->save_object();
680       $msgs = $this->tabObject->check();
681       if(count($msgs)){
682         msg_dialog::displayChecks($msgs); 
683         return("");
684       }else{
685         $this->tabObject->save();
686         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
687         $this->remove_lock();
688         $this->closeDialogs();
689       }
690     }elseif($this->dialogObject instanceOf plugin){
691       $this->dialogObject->save_object();
692       $msgs = $this->dialogObject->check();
693       if(count($msgs)){
694         msg_dialog::displayChecks($msgs); 
695         return("");
696       }else{
697         $this->dialogObject->save();
698         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
699         $this->remove_lock();
700         $this->closeDialogs();
701       }
702     }
703   }
706   /*! \brief  Save object modifications and keep dialogs opened. 
707    *          - Calls '::check' to validate the given input.
708    *          - Calls '::save' to save back object modifications (e.g. to ldap).
709    */
710   protected function applyChanges()
711   {
712     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
713       $this->tabObject->save_object();
714       $msgs = $this->tabObject->check();
715       if(count($msgs)){
716         msg_dialog::displayChecks($msgs); 
717         return("");
718       }else{
719         $this->tabObject->save();
720         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
721         $this->tabObject->re_init();
722       }
723     }
724   }
727   /*! \brief  This method closes dialogs
728    *           and cleans up the cached object info and the ui.
729    */
730   protected function closeDialogs()
731   {
732     $this->last_dn = $this->dn;
733     $this->last_dns = $this->dns;
734     $this->last_tabObject = $this->tabObject;
735     $this->last_dialogObject = $this->dialogObject;
736     $this->dn = "";
737     $this->dns = array();
738     $this->tabObject = null;
739     $this->dialogObject = null;
740     set_object_info();
741   }
744   /*! \brief  Editing an object was caneled. 
745    *          Close dialogs/tabs and remove locks.
746    */
747   protected function cancelEdit()
748   {
749     $this->remove_lock();
750     $this->closeDialogs();
751   }
754   /*! \brief  Every click in the list user interface sends an event
755    *           here can we connect those events to a method. 
756    *          eg.  ::registerEvent('new','createUser')
757    *          When the action/event new is send, the method 'createUser' 
758    *           will be called.
759    */
760   function registerAction($action,$target)
761   {
762     $this->actions[$action] = $target;
763   }
766   /*! \brief  Removes ldap object locks created by this class.
767    *          Whenever an object is edited, we create locks to avoid 
768    *           concurrent modifications.
769    *          This locks will automatically removed here.
770    */
771   function remove_lock()
772   {
773     if(!empty($this->dn) && $this->dn != "new"){
774       del_lock($this->dn);
775     }
776     if(count($this->dns)){
777       del_lock($this->dns);
778     }
779   }
782   /*! \brief  This method is used to queue and process copy&paste actions. 
783    *          Allows to copy, cut and paste mutliple entries at once.
784    *  @param  String  'action'  The name of the action which was the used as trigger.
785    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
786    *  @param  Array   'all'     A combination of both 'action' and 'target'.
787    */
788   function copyPasteHandler($action="",$target=array(),$all=array(), 
789       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
790   {
791     // Return without any actions while copy&paste handler is disabled.
792     if(!is_object($this->cpHandler))  return("");
794     $tabType = $this->tabType;
795     $tabClass = $this->tabClass;
796     $aclCategory = $this->aclCategory;
797     $aclPlugin = $this->aclPlugin;
798     if(!empty($altTabClass)) $tabClass = $altTabClass;
799     if(!empty($altTabType)) $tabType = $altTabType;
800     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
801     if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
803     // Save user input
804     $this->cpHandler->save_object();
806     // Add entries to queue 
807     if($action == "copy" || $action == "cut"){
808       $this->cpHandler->cleanup_queue();
809       foreach($target as $dn){
810         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
811           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
812           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
813         }
814         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
815           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
816           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
817         }
818       }
819     }
821     // Initiate pasting
822     if($action == "paste"){
823       $this->cpPastingStarted = TRUE;
824     }
826     // Display any c&p dialogs, eg. object modifications required before pasting.
827     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
828       $this->cpHandler->SetVar("base",$this->headpage->getBase());
829       $data = $this->cpHandler->execute();
830       if(!empty($data)){
831         return($data);
832       }
833     }
835     // Automatically disable pasting process since there is no entry left to paste.
836     if(!$this->cpHandler->entries_queued()){
837       $this->cpPastingStarted = FALSE;
838     }
839     return("");
840   }
843   function setFilter($str) {
844     $this->filter = $str;
845   }
849 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
850 ?>