Code

Removed header from management plugin
[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   public $dn = "";  // this is public due to some compatibility problems with class plugin..
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 $aclPlugin = "";        // e.g. generic
50   protected $aclCategory = "";      // e.g. users
51   protected $objectName = "";       // e.g. users
53   // The opened object.
54   protected $tabObject = null;
55   protected $dialogObject = null;
57   // The last opened object.
58   protected $last_tabObject = null;
59   protected $last_dialogObject = null;
61   // Whether to display the apply button or not
62   protected $displayApplyBtn = FALSE;
64   // Whether to display a header or not.
65   protected $skipHeader = false;
67   // Whether to display a footer or not.
68   protected $skipFooter = false;
70   // Copy&Paste handler
71   protected $cpHandler = null;
73   // Indicates that we want to paste objects right now.
74   protected $cpPastingStarted = FALSE;
76   // The Snapshot handler class.
77   protected $snapHandler = null;
79   // The listing handlers
80   private $headpage = null;
81   private $filter = null;
83   // A list of configured actions/events
84   protected $actions = array();
86   // Attributes managed by this plugin, can be used in post events;
87   public $attributes = array(); 
89   function  __construct(&$config,$ui,$plugname, $headpage)
90   {
91     $this->plugname = $plugname;
92     $this->headpage = $headpage;
93     $this->ui = $ui;
94     $this->config = $config;
96     if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
97     if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
99     if(empty($this->plIcon)){
100       $this->plIcon = "plugins/".$plugname."/images/plugin.png";
101     }
103     // Register default actions
104     $this->registerAction("new",    "newEntry");
105     $this->registerAction("edit",   "editEntry");
106     $this->registerAction("apply",  "applyChanges");
107     $this->registerAction("save",   "saveChanges");
108     $this->registerAction("cancel", "cancelEdit");
109     $this->registerAction("cancelDelete", "cancelEdit");
110     $this->registerAction("remove", "removeEntryRequested");
111     $this->registerAction("removeConfirmed", "removeEntryConfirmed");
113     $this->registerAction("copy",   "copyPasteHandler");
114     $this->registerAction("cut",    "copyPasteHandler");
115     $this->registerAction("paste",  "copyPasteHandler");
117     $this->registerAction("snapshot",    "createSnapshotDialog");
118     $this->registerAction("restore",     "restoreSnapshotDialog");
119     $this->registerAction("saveSnapshot","saveSnapshot");
120     $this->registerAction("restoreSnapshot","restoreSnapshot");
121     $this->registerAction("cancelSnapshot","closeDialogs");
122   }
124   /*! \brief  Execute this plugin
125    *          Handle actions/events, locking, snapshots, dialogs, tabs,...
126    */
127   function execute()
128   {
129     // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
130     $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
131     session::set('LOCK_VARS_TO_USE',$vars);
133     /* Display the copy & paste dialog, if it is currently open */
134     $ret = $this->copyPasteHandler("",array());
135     if($ret){
136       return($this->getHeader().$ret);
137     }
139     // Update filter
140     if ($this->filter) {
141       $this->filter->update();
142       session::global_set(get_class($this)."_filter", $this->filter);
143       session::set('autocomplete', $this->filter);
144       if (!$this->filter->isValid()){
145         msg_dialog::display(_("Filter error"), _("The filter is incomplete!"), ERROR_DIALOG);
146       }
147     }
149     // Handle actions (POSTs and GETs)
150     $str = $this->handleActions($this->detectPostActions());
151     if($str) return($this->getHeader().$str);
153     // Open single dialog objects
154     if(is_object($this->dialogObject)){
155       if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object(); 
156       if(method_exists($this->dialogObject,'execute')){
157         $display = $this->dialogObject->execute(); 
158         $display.= $this->_getTabFooter();
159         return($this->getHeader().$display);
160       } 
161     }
163     // Display tab object.
164     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
165 #      $this->tabObject->save_object();
166       $display = $this->tabObject->execute();
167       $display.= $this->_getTabFooter();
168       return($this->getHeader().$display);
169     }
171     // Set current restore base for snapshot handling.
172     if(is_object($this->snapHandler)){
173       $bases = array();
174       foreach($this->storagePoints as $sp){
175         $bases[] = $sp.$this->headpage->getBase();
176       }
178       // No bases specified? Try base  
179       if(!count($bases)) $bases[] = $this->headpage->getBase();
181       $this->snapHandler->setSnapshotBases($bases);
182     }
183     
184     // Display list
185     return($this->renderList());
186   }
187   
188   function renderList()
189   {
190     $this->headpage->update();
191     $display = $this->headpage->render();
192     return($this->getHeader().$display);
193   }
195   function getHeadpage()
196   {
197     return($this->headpage);
198   }
200   function getFilter()
201   {
202     return($this->filter);
203   }
205   /*! \brief  Generates the plugin header which is displayed whenever a tab object is 
206    *           opened.
207    */
208   protected function getHeader()
209   {
210     // We do not display any headers right now.
211     if(1 || $this->skipHeader) return("");
212   }
215   /*! \brief  Generates the footer which is used whenever a tab object is 
216    *           displayed.
217    */
218   protected function _getTabFooter()
219   {
220     // Do not display tab footer for non tab objects 
221     if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
222       return("");
223     }
225     // Check if there is a dialog opened - We don't need any buttons in this case. 
226     if($this->tabObject->by_object[$this->tabObject->current]){
227       $current = $this->tabObject->by_object[$this->tabObject->current];  
228       if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
229         return("");
230       }
231     }
233     // Skip footer if requested;
234     if($this->skipFooter) return("");
236     // In case an of locked entry, we may have opened a read-only tab.
237     $str = "";
238     if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
239       $str.= "<p style=\"text-align:right\">
240         <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
241         </p>";
242       return($str);
243     }else{
245       // Display ok, (apply) and cancel buttons
246       $str.= "<p style=\"text-align:right\">\n";
247       $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
248       $str.= "&nbsp;\n";
249       if($this->displayApplyBtn){
250         $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
251         $str.= "&nbsp;\n";
252       }
253       $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
254       $str.= "</p>";
255     }
256     return($str);
257   }
260   /*! \brief  Initiates the removal for the given entries
261    *           and displays a confirmation dialog.
262    *      
263    *  @param  String  'action'  The name of the action which was the used as trigger.
264    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
265    *  @param  Array   'all'     A combination of both 'action' and 'target'.
266    */
267   protected function removeEntryRequested($action="",$target=array(),$all=array())
268   {
269     $disallowed = array();
270     $this->dns = array();
272     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
274     // Check permissons for each target 
275     foreach($target as $dn){
276       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
277       if(preg_match("/d/",$acl)){
278         $this->dns[] = $dn;
279       }else{
280         $disallowed[] = $dn;
281       }
282     }
283     if(count($disallowed)){
284       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
285     }
287     // We've at least one entry to delete.
288     if(count($this->dns)){
290       // check locks
291       if ($user= get_multiple_locks($this->dns)){
292         return(gen_locked_message($user,$this->dns));
293       }
295       // Add locks
296       $dns_names = array();
297       foreach($this->dns as $dn){
298         $dns_names[] =LDAP::fix($dn);
299       }
300       add_lock ($this->dns, $this->ui->dn);
302       // Display confirmation dialog.
303       $smarty = get_smarty();
304       $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
305       $smarty->assign("multiple", true);
306       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
307     }
308   }  
311   /*! \brief  Object removal was confirmed, now remove the requested entries. 
312    *      
313    *  @param  String  'action'  The name of the action which was the used as trigger.
314    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
315    *  @param  Array   'all'     A combination of both 'action' and 'target'.
316    */
317   function removeEntryConfirmed($action="",$target=array(),$all=array(),
318       $altTabClass="",$altTabType="",$altAclCategory="")
319   {
320     $tabType = $this->tabType;
321     $tabClass = $this->tabClass;
322     $aclCategory = $this->aclCategory;
323     if(!empty($altTabClass)) $tabClass = $altTabClass;
324     if(!empty($altTabType)) $tabType = $altTabType;
325     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
327     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
329     foreach($this->dns as $key => $dn){
331       // Check permissions, are we allowed to remove this object? 
332       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
333       if(preg_match("/d/",$acl)){
335         // Delete the object
336         $this->dn = $dn;
337         $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
338         $this->tabObject->set_acl_base($this->dn);
339         $this->tabObject->parent = &$this;
340         $this->tabObject->delete ();
342         // Remove the lock for the current object.
343         del_lock($this->dn);        
344       } else {
345         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
346         new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
347       }
348     }
350     // Cleanup
351     $this->remove_lock();
352     $this->closeDialogs();
353   }
356   /*! \brief  Detects actions/events send by the ui
357    *           and the corresponding targets.
358    */
359   function detectPostActions()
360   {
361     if(!is_object($this->headpage)){
362       trigger_error("No valid headpage given....!");
363       return(array());
364     }
365     $action= $this->headpage->getAction();
366     if(isset($_POST['edit_apply']))  $action['action'] = "apply";    
367     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
368     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
369     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
370     if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";   
372     // Detect Snapshot actions
373     if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";   
374     if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";   
375     foreach($_POST as $name => $value){
376       $once =TRUE;
377       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
378         $once = FALSE;
379         $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
380         $action['action'] = "restoreSnapshot";
381         $action['targets'] = array($entry);
382       }
383     }
385     return($action);
386   }
389   /*! \brief  Calls the registered method for a given action/event.
390    */
391   function handleActions($action)
392   {
393     // Start action  
394     if(isset($this->actions[$action['action']])){
395       $func = $this->actions[$action['action']];
396       if(!isset($action['targets']))$action['targets']= array(); 
397       return($this->$func($action['action'],$action['targets'],$action));
398     }
399   } 
402   /*! \brief  Opens the snapshot creation dialog for the given target.
403    *      
404    *  @param  String  'action'  The name of the action which was the used as trigger.
405    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
406    *  @param  Array   'all'     A combination of both 'action' and 'target'.
407    */
408   function createSnapshotDialog($action="",$target=array(),$all=array())
409   {
410     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
412     foreach($target as $entry){
413       if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
414         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
415         $this->dialogObject->aclCategories = array($this->aclCategory);
416         $this->dialogObject->parent = &$this;
418       }else{
419         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
420             ERROR_DIALOG);
421       }
422     }
423   }
426   /*! \brief  Creates a snapshot new entry - This method is called when the somebody
427    *           clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
428    *      
429    *  @param  String  'action'  The name of the action which was the used as trigger.
430    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
431    *  @param  Array   'all'     A combination of both 'action' and 'target'.
432    */
433   function saveSnapshot($action="",$target=array(),$all=array())
434   { 
435     if(!is_object($this->dialogObject)) return;
436     $this->dialogObject->save_object();
437     $msgs = $this->dialogObject->check();
438     if(count($msgs)){
439       foreach($msgs as $msg){
440         msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
441       }
442     }else{
443       $this->dn =  $this->dialogObject->dn;
444       $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
445       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
446       $this->closeDialogs();
447     }
448   }
451   /*! \brief  Restores a snapshot object.
452    *          The dn of the snapshot entry has to be given as ['target'] parameter.  
453    *      
454    *  @param  String  'action'  The name of the action which was the used as trigger.
455    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
456    *  @param  Array   'all'     A combination of both 'action' and 'target'.
457    */
458   function restoreSnapshot($action="",$target=array(),$all=array())
459   {
460     $entry = array_pop($target);
461     if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
462       $this->snapHandler->restore_snapshot($entry);
463       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
464       $this->closeDialogs();
465     }else{
466       msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
467           ERROR_DIALOG);
468     }
469   }
472   /*! \brief  Displays the "Restore snapshot dialog" for a given target. 
473    *          If no target is specified, open the restore removed object 
474    *           dialog.
475    *  @param  String  'action'  The name of the action which was the used as trigger.
476    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
477    *  @param  Array   'all'     A combination of both 'action' and 'target'.
478    */
479   function restoreSnapshotDialog($action="",$target=array(),$all=array())
480   {
481     // Set current restore base for snapshot handling.
482     if(is_object($this->snapHandler)){
483       $bases = array();
484       foreach($this->storagePoints as $sp){
485         $bases[] = $sp.$this->headpage->getBase();
486       }
487     }
489     // No bases specified? Try base  
490     if(!count($bases)) $bases[] = $this->headpage->getBase();
492     // No target, open the restore removed object dialog.
493     if(!count($target)){ 
494       $entry = $this->headpage->getBase();
495       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
496         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
497         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
498         $this->dialogObject->set_snapshot_bases($bases);
499         $this->dialogObject->display_all_removed_objects = true;
500         $this->dialogObject->display_restore_dialog = true;
501         $this->dialogObject->parent = &$this;
502       }else{
503         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
504             ERROR_DIALOG);
505       } 
506     }else{
508       // Display the restore points for a given object.
509       $entry = array_pop($target);
510       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
511         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
512         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
513         $this->dialogObject->set_snapshot_bases($bases);
514         $this->dialogObject->display_restore_dialog = true;
515         $this->dialogObject->parent = &$this;
516       }else{
517         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
518             ERROR_DIALOG);
519       } 
520     }
521   }
524   /*! \brief  This method intiates the object creation.
525    *          
526    *  @param  String  'action'  The name of the action which was the used as trigger.
527    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
528    *  @param  Array   'all'     A combination of both 'action' and 'target'.
529    */
530   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
531   {
532     /* To handle mutliple object types overload this method.
533      * ...
534      *   registerAction('newUser', 'newEntry');
535      *   registerAction('newGroup','newEntry');
536      * ... 
537      * 
538      * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
539      * {
540      *   switch($action){
541      *     case 'newUser' : {
542      *       mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
543      *     }
544      *     case 'newGroup' : {
545      *       mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
546      *     }
547      *   }
548      * }
549      **/ 
550     $tabType = $this->tabType;
551     $tabClass = $this->tabClass;
552     $aclCategory = $this->aclCategory;
553     if(!empty($altTabClass)) $tabClass = $altTabClass;
554     if(!empty($altTabType)) $tabType = $altTabType;
555     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
557     // Check locking & lock entry if required 
558     $this->displayApplyBtn = FALSE;
559     $this->dn = "new";
560     $this->is_new = TRUE;
561     $this->is_single_edit = FALSE;
562     $this->is_multiple_edit = FALSE;
564     set_object_info($this->dn);
566     // Open object.
567     if(empty($tabClass) || empty($tabType)){
568       // No tab type defined
569     }else{
570       if (isset($this->config->data['TABS'][$tabType])) {
571         $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
572         $this->tabObject->set_acl_base($this->headpage->getBase());
573         $this->tabObject->parent = &$this;
574         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
575       } else {
576         msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG);
577       }
578     }
579   }
582   /*! \brief  This method opens an existing object or a list of existing objects to be edited. 
583    *                  
584    * 
585    *  @param  String  'action'  The name of the action which was the used as trigger.
586    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
587    *  @param  Array   'all'     A combination of both 'action' and 'target'.
588    */
589   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
590   {
591     /* To handle mutliple object types overload this method.
592      * ...
593      *   registerAction('editUser', 'editEntry');
594      *   registerAction('editGroup','editEntry');
595      * ... 
596      * 
597      * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
598      * {
599      *   switch($action){
600      *     case 'editUser' : {
601      *       mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
602      *     }
603      *     case 'editGroup' : {
604      *       mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
605      *     }
606      *   }
607      * }
608      **/
610     // Do not create a new tabObject while there is already one opened,
611     //  the user may have just pressed F5 to reload the page.
612     if(is_object($this->tabObject)){
613       return;
614     }
615  
616     $tabType = $this->tabType;
617     $tabClass = $this->tabClass;
618     $aclCategory = $this->aclCategory;
619     if(!empty($altTabClass)) $tabClass = $altTabClass;
620     if(!empty($altTabType)) $tabType = $altTabType;
621     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
623     // Single edit - we only got one object dn.
624     if(count($target) == 1){
625       $this->displayApplyBtn = TRUE;
626       $this->is_new = FALSE;
627       $this->is_single_edit = TRUE;
628       $this->is_multiple_edit = FALSE;
630       // Get the dn of the object and creates lock
631       $this->dn = array_pop($target);
632       set_object_info($this->dn);
633       $user = get_lock($this->dn);
634       if ($user != ""){
635         return(gen_locked_message ($user, $this->dn,TRUE));
636       }
637       add_lock ($this->dn, $this->ui->dn);
639       // Open object.
640       if(empty($tabClass) || empty($tabType)){
641         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
642       }else{
643         $tab = $tabClass;
644         $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
645         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
646         $this->tabObject->set_acl_base($this->dn);
647         $this->tabObject->parent = &$this;
648       }
649     }else{
651       // We've multiple entries to edit.
652       $this->is_new = FALSE;
653       $this->is_singel_edit = FALSE;
654       $this->is_multiple_edit = TRUE;
656       // Open multiple edit handler.
657       if(empty($tabClass) || empty($tabType)){
658         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
659       }else{
660         $this->dns = $target;
661         $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
662             $this->dns,$this->headpage->getBase(),$aclCategory);
664         // Check for locked entries
665         if ($tmp->entries_locked()){
666           return($tmp->display_lock_message());
667         }
669         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
671         // Now lock entries.
672         if($tmp->multiple_available()){
673           $tmp->lock_entries($this->ui->dn);
674           $this->tabObject = $tmp;
675           set_object_info($this->tabObject->get_object_info());
676         }
677       }
678     }
679   }
682   /*! \brief  Save object modifications and closes dialogs (returns to object listing).
683    *          - Calls '::check' to validate the given input.
684    *          - Calls '::save' to save back object modifications (e.g. to ldap).
685    *          - Calls '::remove_locks' to remove eventually created locks.
686    *          - Calls '::closeDialogs' to return to the object listing.
687    */
688   protected function saveChanges()
689   {
690     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
691       $this->tabObject->save_object();
692       $msgs = $this->tabObject->check();
693       if(count($msgs)){
694         msg_dialog::displayChecks($msgs); 
695         return("");
696       }else{
697         $this->tabObject->save();
698         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
699         $this->remove_lock();
700         $this->closeDialogs();
701       }
702     }elseif($this->dialogObject instanceOf plugin){
703       $this->dialogObject->save_object();
704       $msgs = $this->dialogObject->check();
705       if(count($msgs)){
706         msg_dialog::displayChecks($msgs); 
707         return("");
708       }else{
709         $this->dialogObject->save();
710         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
711         $this->remove_lock();
712         $this->closeDialogs();
713       }
714     }
715   }
718   /*! \brief  Save object modifications and keep dialogs opened. 
719    *          - Calls '::check' to validate the given input.
720    *          - Calls '::save' to save back object modifications (e.g. to ldap).
721    */
722   protected function applyChanges()
723   {
724     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
725       $this->tabObject->save_object();
726       $msgs = $this->tabObject->check();
727       if(count($msgs)){
728         msg_dialog::displayChecks($msgs); 
729         return("");
730       }else{
731         $this->tabObject->save();
732         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
733         $this->tabObject->re_init();
734       }
735     }
736   }
739   /*! \brief  This method closes dialogs
740    *           and cleans up the cached object info and the ui.
741    */
742   protected function closeDialogs()
743   {
744     $this->last_dn = $this->dn;
745     $this->last_dns = $this->dns;
746     $this->last_tabObject = $this->tabObject;
747     $this->last_dialogObject = $this->dialogObject;
748     $this->dn = "";
749     $this->dns = array();
750     $this->tabObject = null;
751     $this->dialogObject = null;
752     $this->skipFooter = FALSE;
753     set_object_info();
754   }
757   /*! \brief  Editing an object was caneled. 
758    *          Close dialogs/tabs and remove locks.
759    */
760   protected function cancelEdit()
761   {
762     $this->remove_lock();
763     $this->closeDialogs();
764   }
767   /*! \brief  Every click in the list user interface sends an event
768    *           here can we connect those events to a method. 
769    *          eg.  ::registerEvent('new','createUser')
770    *          When the action/event new is send, the method 'createUser' 
771    *           will be called.
772    */
773   function registerAction($action,$target)
774   {
775     $this->actions[$action] = $target;
776   }
779   /*! \brief  Removes ldap object locks created by this class.
780    *          Whenever an object is edited, we create locks to avoid 
781    *           concurrent modifications.
782    *          This locks will automatically removed here.
783    */
784   function remove_lock()
785   {
786     if(!empty($this->dn) && $this->dn != "new"){
787       del_lock($this->dn);
788     }
789     if(count($this->dns)){
790       del_lock($this->dns);
791     }
792   }
795   /*! \brief  This method is used to queue and process copy&paste actions. 
796    *          Allows to copy, cut and paste mutliple entries at once.
797    *  @param  String  'action'  The name of the action which was the used as trigger.
798    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
799    *  @param  Array   'all'     A combination of both 'action' and 'target'.
800    */
801   function copyPasteHandler($action="",$target=array(),$all=array(), 
802       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
803   {
804     // Return without any actions while copy&paste handler is disabled.
805     if(!is_object($this->cpHandler))  return("");
807     $tabType = $this->tabType;
808     $tabClass = $this->tabClass;
809     $aclCategory = $this->aclCategory;
810     $aclPlugin = $this->aclPlugin;
811     if(!empty($altTabClass)) $tabClass = $altTabClass;
812     if(!empty($altTabType)) $tabType = $altTabType;
813     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
814     if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
816     // Save user input
817     $this->cpHandler->save_object();
819     // Add entries to queue 
820     if($action == "copy" || $action == "cut"){
821       $this->cpHandler->cleanup_queue();
822       foreach($target as $dn){
823         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
824           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
825           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
826         }
827         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
828           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
829           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
830         }
831       }
832     }
834     // Initiate pasting
835     if($action == "paste"){
836       $this->cpPastingStarted = TRUE;
837     }
839     // Display any c&p dialogs, eg. object modifications required before pasting.
840     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
841       $this->cpHandler->SetVar("base",$this->headpage->getBase());
842       $data = $this->cpHandler->execute();
843       if(!empty($data)){
844         return($data);
845       }
846     }
848     // Automatically disable pasting process since there is no entry left to paste.
849     if(!$this->cpHandler->entries_queued()){
850       $this->cpPastingStarted = FALSE;
851     }
852     return("");
853   }
856   function setFilter($str) {
857     $this->filter = $str;
858   }
861   function postcreate() {
862     $this->_handlePostEvent('POSTCREATE');
863   }
864   function postmodify(){
865     $this->_handlePostEvent('POSTMODIFY');
866   }
867   function postremove(){
868     $this->_handlePostEvent('POSTREMOVE');
869   }
871   function _handlePostEvent($type)
872   {
874     /* Find postcreate entries for this class */
875     $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
876     if ($command != ""){
878       /* Walk through attribute list */
879       foreach ($this->attributes as $attr){
880         if (!is_array($this->$attr)){
881           $add_attrs[$attr] = $this->$attr;
882         }
883       }
884       $add_attrs['dn']=$this->dn;
886       $tmp = array();
887       foreach($add_attrs as $name => $value){
888         $tmp[$name] =  strlen($name);
889       }
890       arsort($tmp);
892       /* Additional attributes */
893       foreach ($tmp as $name => $len){
894         $value = $add_attrs[$name];
895         $command= str_replace("%$name", "$value", $command);
896       }
898       if (check_command($command)){
899         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
900             $command, "Execute");
901         exec($command,$arr);
902         foreach($arr as $str){
903           @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
904               $command, "Result: ".$str);
905         }
906       } else {
907         $message= msgPool::cmdnotfound($type, get_class($this));
908         msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
909       }
910     }
911   }
913   function is_modal_dialog()
914   {
915     return(is_object($this->tabObject) || is_object($this->dialogObject));
916   }
919 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
920 ?>