Code

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