Code

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