Code

Removed old stuff
[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");
123     $this->registerAction("config-filter","editFilter");
124   }
126   /*! \brief  Execute this plugin
127    *          Handle actions/events, locking, snapshots, dialogs, tabs,...
128    */
129   function execute()
130   {
131     // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
132     $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
133     session::set('LOCK_VARS_TO_USE',$vars);
135     pathNavigator::registerPlugin($this);
137     /* Display the copy & paste dialog, if it is currently open */
138     $ret = $this->copyPasteHandler("",array());
139     if($ret){
140       return($this->getHeader().$ret);
141     }
143     // Update filter
144     if ($this->filter) {
145       $this->filter->update();
146       session::global_set(get_class($this)."_filter", $this->filter);
147       session::set('autocomplete', $this->filter);
148     }
150     // Handle actions (POSTs and GETs)
151     $str = $this->handleActions($this->detectPostActions());
152     if($str) return($this->getHeader().$str);
154     // Open single dialog objects
155     if(is_object($this->dialogObject)){
156       if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object(); 
157       if(method_exists($this->dialogObject,'execute')){
158         $display = $this->dialogObject->execute(); 
159         $display.= $this->_getTabFooter();
160         return($this->getHeader().$display);
161       } 
162     }
164     // Display tab object.
165     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
166 #      $this->tabObject->save_object();
167       $display = $this->tabObject->execute();
168       $display.= $this->_getTabFooter();
169       return($this->getHeader().$display);
170     }
172     // Set current restore base for snapshot handling.
173     if(is_object($this->snapHandler)){
174       $bases = array();
175       foreach($this->storagePoints as $sp){
176         $bases[] = $sp.$this->headpage->getBase();
177       }
179       // No bases specified? Try base  
180       if(!count($bases)) $bases[] = $this->headpage->getBase();
182       $this->snapHandler->setSnapshotBases($bases);
183     }
184   
185     // Display list
186     return($this->renderList());
187   }
188  
189   function editFilter()
190   {
191     $this->dialogObject = new userFilter($this->config,$this->getHeadpage());
192   }
193  
194   function renderList()
195   {
196     $this->headpage->update();
197     $display = $this->headpage->render();
198     return($this->getHeader().$display);
199   }
201   function getHeadpage()
202   {
203     return($this->headpage);
204   }
206   function getFilter()
207   {
208     return($this->filter);
209   }
211   /*! \brief  Generates the plugin header which is displayed whenever a tab object is 
212    *           opened.
213    */
214   protected function getHeader()
215   {
216     // We do not display any headers right now.
217     if(1 || $this->skipHeader) return("");
218   }
221   /*! \brief  Generates the footer which is used whenever a tab object is 
222    *           displayed.
223    */
224   protected function _getTabFooter()
225   {
226     // Do not display tab footer for non tab objects 
227     if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
228       return("");
229     }
231     // Check if there is a dialog opened - We don't need any buttons in this case. 
232     if($this->tabObject->by_object[$this->tabObject->current]){
233       $current = $this->tabObject->by_object[$this->tabObject->current];  
234       if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
235         return("");
236       }
237     }
239     // Skip footer if requested;
240     if($this->skipFooter) return("");
242     // In case an of locked entry, we may have opened a read-only tab.
243     $str = "";
244     if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
245       $str.= "<p style=\"text-align:right\">
246         <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
247         </p>";
248       return($str);
249     }else{
251       // Display ok, (apply) and cancel buttons
252       $str.= "<p style=\"text-align:right\">\n";
253       $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
254       $str.= "&nbsp;\n";
255       if($this->displayApplyBtn){
256         $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
257         $str.= "&nbsp;\n";
258       }
259       $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
260       $str.= "</p>";
261     }
262     return($str);
263   }
266   /*! \brief  Initiates the removal for the given entries
267    *           and displays a confirmation dialog.
268    *      
269    *  @param  String  'action'  The name of the action which was the used as trigger.
270    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
271    *  @param  Array   'all'     A combination of both 'action' and 'target'.
272    */
273   protected function removeEntryRequested($action="",$target=array(),$all=array())
274   {
275     $disallowed = array();
276     $this->dns = array();
278     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
280     // Check permissons for each target 
281     foreach($target as $dn){
282       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
283       if(preg_match("/d/",$acl)){
284         $this->dns[] = $dn;
285       }else{
286         $disallowed[] = $dn;
287       }
288     }
289     if(count($disallowed)){
290       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
291     }
293     // We've at least one entry to delete.
294     if(count($this->dns)){
296       // check locks
297       if ($user= get_multiple_locks($this->dns)){
298         return(gen_locked_message($user,$this->dns));
299       }
301       // Add locks
302       $dns_names = array();
303       foreach($this->dns as $dn){
304         $dns_names[] =LDAP::fix($dn);
305       }
306       add_lock ($this->dns, $this->ui->dn);
308       // Display confirmation dialog.
309       $smarty = get_smarty();
310       $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
311       $smarty->assign("multiple", true);
312       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
313     }
314   }  
317   /*! \brief  Object removal was confirmed, now remove the requested entries. 
318    *      
319    *  @param  String  'action'  The name of the action which was the used as trigger.
320    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
321    *  @param  Array   'all'     A combination of both 'action' and 'target'.
322    */
323   function removeEntryConfirmed($action="",$target=array(),$all=array(),
324       $altTabClass="",$altTabType="",$altAclCategory="")
325   {
326     $tabType = $this->tabType;
327     $tabClass = $this->tabClass;
328     $aclCategory = $this->aclCategory;
329     if(!empty($altTabClass)) $tabClass = $altTabClass;
330     if(!empty($altTabType)) $tabType = $altTabType;
331     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
333     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
335     foreach($this->dns as $key => $dn){
337       // Check permissions, are we allowed to remove this object? 
338       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
339       if(preg_match("/d/",$acl)){
341         // Delete the object
342         $this->dn = $dn;
343         $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
344         $this->tabObject->set_acl_base($this->dn);
345         $this->tabObject->parent = &$this;
346         $this->tabObject->delete ();
348         // Remove the lock for the current object.
349         del_lock($this->dn);        
350       } else {
351         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
352         new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
353       }
354     }
356     // Cleanup
357     $this->remove_lock();
358     $this->closeDialogs();
359   }
362   /*! \brief  Detects actions/events send by the ui
363    *           and the corresponding targets.
364    */
365   function detectPostActions()
366   {
367     if(!is_object($this->headpage)){
368       trigger_error("No valid headpage given....!");
369       return(array());
370     }
371     $action= $this->headpage->getAction();
372     if(isset($_POST['edit_apply']))  $action['action'] = "apply";    
373     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
374     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
375     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
376     if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";   
377     if(isset($_POST['saveFilter'])) $action['action'] = "save";   
378     if(isset($_POST['cancelFilter'])) $action['action'] = "cancel";   
380     // Detect Snapshot actions
381     if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";   
382     if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";   
383     foreach($_POST as $name => $value){
384       $once =TRUE;
385       if(preg_match("/^RestoreSnapShot_/",$name) && $once){
386         $once = FALSE;
387         $entry = base64_decode(preg_replace("/^RestoreSnapShot_([^_]*)_[xy]$/i","\\1",$name));
388         $action['action'] = "restoreSnapshot";
389         $action['targets'] = array($entry);
390       }
391     }
393     return($action);
394   }
397   /*! \brief  Calls the registered method for a given action/event.
398    */
399   function handleActions($action)
400   {
401     // Start action  
402     if(isset($this->actions[$action['action']])){
403       $func = $this->actions[$action['action']];
404       if(!isset($action['targets']))$action['targets']= array(); 
405       return($this->$func($action['action'],$action['targets'],$action));
406     }
407   } 
410   /*! \brief  Opens the snapshot creation dialog for the given target.
411    *      
412    *  @param  String  'action'  The name of the action which was the used as trigger.
413    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
414    *  @param  Array   'all'     A combination of both 'action' and 'target'.
415    */
416   function createSnapshotDialog($action="",$target=array(),$all=array())
417   {
418     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
420     foreach($target as $entry){
421       if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
422         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
423         $this->dialogObject->aclCategories = array($this->aclCategory);
424         $this->dialogObject->parent = &$this;
426       }else{
427         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
428             ERROR_DIALOG);
429       }
430     }
431   }
434   /*! \brief  Creates a snapshot new entry - This method is called when the somebody
435    *           clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
436    *      
437    *  @param  String  'action'  The name of the action which was the used as trigger.
438    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
439    *  @param  Array   'all'     A combination of both 'action' and 'target'.
440    */
441   function saveSnapshot($action="",$target=array(),$all=array())
442   { 
443     if(!is_object($this->dialogObject)) return;
444     $this->dialogObject->save_object();
445     $msgs = $this->dialogObject->check();
446     if(count($msgs)){
447       foreach($msgs as $msg){
448         msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
449       }
450     }else{
451       $this->dn =  $this->dialogObject->dn;
452       $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
453       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
454       $this->closeDialogs();
455     }
456   }
459   /*! \brief  Restores a snapshot object.
460    *          The dn of the snapshot entry has to be given as ['target'] parameter.  
461    *      
462    *  @param  String  'action'  The name of the action which was the used as trigger.
463    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
464    *  @param  Array   'all'     A combination of both 'action' and 'target'.
465    */
466   function restoreSnapshot($action="",$target=array(),$all=array())
467   {
468     $entry = array_pop($target);
469     if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
470       $this->snapHandler->restore_snapshot($entry);
471       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
472       $this->closeDialogs();
473     }else{
474       msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
475           ERROR_DIALOG);
476     }
477   }
480   /*! \brief  Displays the "Restore snapshot dialog" for a given target. 
481    *          If no target is specified, open the restore removed object 
482    *           dialog.
483    *  @param  String  'action'  The name of the action which was the used as trigger.
484    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
485    *  @param  Array   'all'     A combination of both 'action' and 'target'.
486    */
487   function restoreSnapshotDialog($action="",$target=array(),$all=array())
488   {
489     // Set current restore base for snapshot handling.
490     if(is_object($this->snapHandler)){
491       $bases = array();
492       foreach($this->storagePoints as $sp){
493         $bases[] = $sp.$this->headpage->getBase();
494       }
495     }
497     // No bases specified? Try base  
498     if(!count($bases)) $bases[] = $this->headpage->getBase();
500     // No target, open the restore removed object dialog.
501     if(!count($target)){ 
502       $entry = $this->headpage->getBase();
503       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
504         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
505         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
506         $this->dialogObject->set_snapshot_bases($bases);
507         $this->dialogObject->display_all_removed_objects = true;
508         $this->dialogObject->display_restore_dialog = true;
509         $this->dialogObject->parent = &$this;
510       }else{
511         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
512             ERROR_DIALOG);
513       } 
514     }else{
516       // Display the restore points for a given object.
517       $entry = array_pop($target);
518       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
519         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
520         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
521         $this->dialogObject->set_snapshot_bases($bases);
522         $this->dialogObject->display_restore_dialog = true;
523         $this->dialogObject->parent = &$this;
524       }else{
525         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
526             ERROR_DIALOG);
527       } 
528     }
529   }
532   /*! \brief  This method intiates the object creation.
533    *          
534    *  @param  String  'action'  The name of the action which was the used as trigger.
535    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
536    *  @param  Array   'all'     A combination of both 'action' and 'target'.
537    */
538   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
539   {
540     /* To handle mutliple object types overload this method.
541      * ...
542      *   registerAction('newUser', 'newEntry');
543      *   registerAction('newGroup','newEntry');
544      * ... 
545      * 
546      * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
547      * {
548      *   switch($action){
549      *     case 'newUser' : {
550      *       mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
551      *     }
552      *     case 'newGroup' : {
553      *       mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
554      *     }
555      *   }
556      * }
557      **/ 
558     $tabType = $this->tabType;
559     $tabClass = $this->tabClass;
560     $aclCategory = $this->aclCategory;
561     if(!empty($altTabClass)) $tabClass = $altTabClass;
562     if(!empty($altTabType)) $tabType = $altTabType;
563     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
565     // Check locking & lock entry if required 
566     $this->displayApplyBtn = FALSE;
567     $this->dn = "new";
568     $this->is_new = TRUE;
569     $this->is_single_edit = FALSE;
570     $this->is_multiple_edit = FALSE;
572     set_object_info($this->dn);
574     // Open object.
575     if(empty($tabClass) || empty($tabType)){
576       // No tab type defined
577     }else{
578       if (isset($this->config->data['TABS'][$tabType])) {
579         $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
580         $this->tabObject->set_acl_base($this->headpage->getBase());
581         $this->tabObject->parent = &$this;
582         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
583       } else {
584         msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG);
585       }
586     }
587   }
590   /*! \brief  This method opens an existing object or a list of existing objects to be edited. 
591    *                  
592    * 
593    *  @param  String  'action'  The name of the action which was the used as trigger.
594    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
595    *  @param  Array   'all'     A combination of both 'action' and 'target'.
596    */
597   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
598   {
599     /* To handle mutliple object types overload this method.
600      * ...
601      *   registerAction('editUser', 'editEntry');
602      *   registerAction('editGroup','editEntry');
603      * ... 
604      * 
605      * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
606      * {
607      *   switch($action){
608      *     case 'editUser' : {
609      *       mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
610      *     }
611      *     case 'editGroup' : {
612      *       mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
613      *     }
614      *   }
615      * }
616      **/
618     // Do not create a new tabObject while there is already one opened,
619     //  the user may have just pressed F5 to reload the page.
620     if(is_object($this->tabObject)){
621       return;
622     }
623  
624     $tabType = $this->tabType;
625     $tabClass = $this->tabClass;
626     $aclCategory = $this->aclCategory;
627     if(!empty($altTabClass)) $tabClass = $altTabClass;
628     if(!empty($altTabType)) $tabType = $altTabType;
629     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
631     // Single edit - we only got one object dn.
632     if(count($target) == 1){
633       $this->displayApplyBtn = TRUE;
634       $this->is_new = FALSE;
635       $this->is_single_edit = TRUE;
636       $this->is_multiple_edit = FALSE;
638       // Get the dn of the object and creates lock
639       $this->dn = array_pop($target);
640       set_object_info($this->dn);
641       $user = get_lock($this->dn);
642       if ($user != ""){
643         return(gen_locked_message ($user, $this->dn,TRUE));
644       }
645       add_lock ($this->dn, $this->ui->dn);
647       // Open object.
648       if(empty($tabClass) || empty($tabType)){
649         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
650       }else{
651         $tab = $tabClass;
652         $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
653         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
654         $this->tabObject->set_acl_base($this->dn);
655         $this->tabObject->parent = &$this;
656       }
657     }else{
659       // We've multiple entries to edit.
660       $this->is_new = FALSE;
661       $this->is_singel_edit = FALSE;
662       $this->is_multiple_edit = TRUE;
664       // Open multiple edit handler.
665       if(empty($tabClass) || empty($tabType)){
666         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
667       }else{
668         $this->dns = $target;
669         $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
670             $this->dns,$this->headpage->getBase(),$aclCategory);
672         // Check for locked entries
673         if ($tmp->entries_locked()){
674           return($tmp->display_lock_message());
675         }
677         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
679         // Now lock entries.
680         if($tmp->multiple_available()){
681           $tmp->lock_entries($this->ui->dn);
682           $this->tabObject = $tmp;
683           set_object_info($this->tabObject->get_object_info());
684         }
685       }
686     }
687   }
690   /*! \brief  Save object modifications and closes dialogs (returns to object listing).
691    *          - Calls '::check' to validate the given input.
692    *          - Calls '::save' to save back object modifications (e.g. to ldap).
693    *          - Calls '::remove_locks' to remove eventually created locks.
694    *          - Calls '::closeDialogs' to return to the object listing.
695    */
696   protected function saveChanges()
697   {
698     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
699       $this->tabObject->save_object();
700       $msgs = $this->tabObject->check();
701       if(count($msgs)){
702         msg_dialog::displayChecks($msgs); 
703         return("");
704       }else{
705         $this->tabObject->save();
706         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
707         $this->remove_lock();
708         $this->closeDialogs();
709       }
710     }elseif($this->dialogObject instanceOf plugin){
711       $this->dialogObject->save_object();
712       $msgs = $this->dialogObject->check();
713       if(count($msgs)){
714         msg_dialog::displayChecks($msgs); 
715         return("");
716       }else{
717         $this->dialogObject->save();
718         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
719         $this->remove_lock();
720         $this->closeDialogs();
721       }
722     }
723   }
726   /*! \brief  Save object modifications and keep dialogs opened. 
727    *          - Calls '::check' to validate the given input.
728    *          - Calls '::save' to save back object modifications (e.g. to ldap).
729    */
730   protected function applyChanges()
731   {
732     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
733       $this->tabObject->save_object();
734       $msgs = $this->tabObject->check();
735       if(count($msgs)){
736         msg_dialog::displayChecks($msgs); 
737         return("");
738       }else{
739         $this->tabObject->save();
740         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
741         $this->tabObject->re_init();
742       }
743     }
744   }
747   /*! \brief  This method closes dialogs
748    *           and cleans up the cached object info and the ui.
749    */
750   protected function closeDialogs()
751   {
752     $this->last_dn = $this->dn;
753     $this->last_dns = $this->dns;
754     $this->last_tabObject = $this->tabObject;
755     $this->last_dialogObject = $this->dialogObject;
756     $this->dn = "";
757     $this->dns = array();
758     $this->tabObject = null;
759     $this->dialogObject = null;
760     $this->skipFooter = FALSE;
761     set_object_info();
762   }
765   /*! \brief  Editing an object was caneled. 
766    *          Close dialogs/tabs and remove locks.
767    */
768   protected function cancelEdit()
769   {
770     $this->remove_lock();
771     $this->closeDialogs();
772   }
775   /*! \brief  Every click in the list user interface sends an event
776    *           here can we connect those events to a method. 
777    *          eg.  ::registerEvent('new','createUser')
778    *          When the action/event new is send, the method 'createUser' 
779    *           will be called.
780    */
781   function registerAction($action,$target)
782   {
783     $this->actions[$action] = $target;
784   }
787   /*! \brief  Removes ldap object locks created by this class.
788    *          Whenever an object is edited, we create locks to avoid 
789    *           concurrent modifications.
790    *          This locks will automatically removed here.
791    */
792   function remove_lock()
793   {
794     if(!empty($this->dn) && $this->dn != "new"){
795       del_lock($this->dn);
796     }
797     if(count($this->dns)){
798       del_lock($this->dns);
799     }
800   }
803   /*! \brief  This method is used to queue and process copy&paste actions. 
804    *          Allows to copy, cut and paste mutliple entries at once.
805    *  @param  String  'action'  The name of the action which was the used as trigger.
806    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
807    *  @param  Array   'all'     A combination of both 'action' and 'target'.
808    */
809   function copyPasteHandler($action="",$target=array(),$all=array(), 
810       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
811   {
812     // Return without any actions while copy&paste handler is disabled.
813     if(!is_object($this->cpHandler))  return("");
815     $tabType = $this->tabType;
816     $tabClass = $this->tabClass;
817     $aclCategory = $this->aclCategory;
818     $aclPlugin = $this->aclPlugin;
819     if(!empty($altTabClass)) $tabClass = $altTabClass;
820     if(!empty($altTabType)) $tabType = $altTabType;
821     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
822     if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
824     // Save user input
825     $this->cpHandler->save_object();
827     // Add entries to queue 
828     if($action == "copy" || $action == "cut"){
829       $this->cpHandler->cleanup_queue();
830       foreach($target as $dn){
831         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
832           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
833           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
834         }
835         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
836           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
837           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
838         }
839       }
840     }
842     // Initiate pasting
843     if($action == "paste"){
844       $this->cpPastingStarted = TRUE;
845     }
847     // Display any c&p dialogs, eg. object modifications required before pasting.
848     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
849       $this->cpHandler->SetVar("base",$this->headpage->getBase());
850       $data = $this->cpHandler->execute();
851       if(!empty($data)){
852         return($data);
853       }
854     }
856     // Automatically disable pasting process since there is no entry left to paste.
857     if(!$this->cpHandler->entries_queued()){
858       $this->cpPastingStarted = FALSE;
859     }
860     return("");
861   }
864   function setFilter($str) {
865     $this->filter = $str;
866   }
869   function postcreate() {
870     $this->_handlePostEvent('POSTCREATE');
871   }
872   function postmodify(){
873     $this->_handlePostEvent('POSTMODIFY');
874   }
875   function postremove(){
876     $this->_handlePostEvent('POSTREMOVE');
877   }
879   function _handlePostEvent($type)
880   {
882     /* Find postcreate entries for this class */
883     $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
884     if ($command != ""){
886       /* Walk through attribute list */
887       foreach ($this->attributes as $attr){
888         if (!is_array($this->$attr)){
889           $add_attrs[$attr] = $this->$attr;
890         }
891       }
892       $add_attrs['dn']=$this->dn;
894       $tmp = array();
895       foreach($add_attrs as $name => $value){
896         $tmp[$name] =  strlen($name);
897       }
898       arsort($tmp);
900       /* Additional attributes */
901       foreach ($tmp as $name => $len){
902         $value = $add_attrs[$name];
903         $command= str_replace("%$name", "$value", $command);
904       }
906       if (check_command($command)){
907         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
908             $command, "Execute");
909         exec($command,$arr);
910         foreach($arr as $str){
911           @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
912               $command, "Result: ".$str);
913         }
914       } else {
915         $message= msgPool::cmdnotfound($type, get_class($this));
916         msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
917       }
918     }
919   }
921   function is_modal_dialog()
922   {
923     return(is_object($this->tabObject) || is_object($this->dialogObject));
924   }
927   /*! \brief    Forward command execution request
928    *             to the correct method.
929    */
930   function handle_post_events($mode, $addAttrs= array())
931   {
932     if(!in_array($mode, array('add','remove','modify'))){
933       trigger_error(sprintf("Invalid post event type given '%s'! Valid types are [add,modify,remove].", $mode));
934       return;
935     }
936     switch ($mode){
937       case "add":
938         plugin::callHook($this,"POSTCREATE", $addAttrs);
939       break;
941       case "modify":
942         plugin::callHook($this,"POSTMODIFY", $addAttrs);
943       break;
945       case "remove":
946         plugin::callHook($this,"POSTREMOVE", $addAttrs);
947       break;
948     }
949   }
952 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
953 ?>