Code

Added missing class member var
[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   protected $attributes = array(); 
89   function  __construct(&$config,$ui,$plugname, $headpage)
90   {
91     $this->plugname = $plugname;
92     $this->headpage = $headpage;
93     $this->ui = $ui;
94     $this->config = $config;
96     if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
97     if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
99     if(empty($this->plIcon)){
100       $this->plIcon = "plugins/".$plugname."/images/plugin.png";
101     }
103     // Register default actions
104     $this->registerAction("new",    "newEntry");
105     $this->registerAction("edit",   "editEntry");
106     $this->registerAction("apply",  "applyChanges");
107     $this->registerAction("save",   "saveChanges");
108     $this->registerAction("cancel", "cancelEdit");
109     $this->registerAction("cancelDelete", "cancelEdit");
110     $this->registerAction("remove", "removeEntryRequested");
111     $this->registerAction("removeConfirmed", "removeEntryConfirmed");
113     $this->registerAction("copy",   "copyPasteHandler");
114     $this->registerAction("cut",    "copyPasteHandler");
115     $this->registerAction("paste",  "copyPasteHandler");
117     $this->registerAction("snapshot",    "createSnapshotDialog");
118     $this->registerAction("restore",     "restoreSnapshotDialog");
119     $this->registerAction("saveSnapshot","saveSnapshot");
120     $this->registerAction("restoreSnapshot","restoreSnapshot");
121     $this->registerAction("cancelSnapshot","closeDialogs");
122   }
124   /*! \brief  Execute this plugin
125    *          Handle actions/events, locking, snapshots, dialogs, tabs,...
126    */
127   function execute()
128   {
129     // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
130     $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
131     session::set('LOCK_VARS_TO_USE',$vars);
133     /* Display the copy & paste dialog, if it is currently open */
134     $ret = $this->copyPasteHandler("",array());
135     if($ret){
136       return($this->getHeader().$ret);
137     }
139     // Update filter
140     if ($this->filter) {
141       $this->filter->update();
142       session::global_set(get_class($this)."_filter", $this->filter);
143       session::set('autocomplete', $this->filter);
144       if (!$this->filter->isValid()){
145         msg_dialog::display(_("Filter error"), _("The filter is incomplete!"), ERROR_DIALOG);
146       }
147     }
149     // Handle actions (POSTs and GETs)
150     $str = $this->handleActions($this->detectPostActions());
151     if($str) return($this->getHeader().$str);
153     // Open single dialog objects
154     if(is_object($this->dialogObject)){
155       if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object(); 
156       if(method_exists($this->dialogObject,'execute')){
157         $display = $this->dialogObject->execute(); 
158         $display.= $this->_getTabFooter();
159         return($this->getHeader().$display);
160       } 
161     }
163     // Display tab object.
164     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
165 #      $this->tabObject->save_object();
166       $display = $this->tabObject->execute();
167       $display.= $this->_getTabFooter();
168       return($this->getHeader().$display);
169     }
171     // Set current restore base for snapshot handling.
172     if(is_object($this->snapHandler)){
173       $bases = array();
174       foreach($this->storagePoints as $sp){
175         $bases[] = $sp.$this->headpage->getBase();
176       }
178       // No bases specified? Try base  
179       if(!count($bases)) $bases[] = $this->headpage->getBase();
181       $this->snapHandler->setSnapshotBases($bases);
182     }
183     
184     // Display list
185     return($this->renderList());
186   }
187   
188   function renderList()
189   {
190     $this->headpage->update();
191     $display = $this->headpage->render();
192     return($this->getHeader().$display);
193   }
195   function getHeadpage()
196   {
197     return($this->headpage);
198   }
200   function getFilter()
201   {
202     return($this->filter);
203   }
205   /*! \brief  Generates the plugin header which is displayed whenever a tab object is 
206    *           opened.
207    */
208   protected function getHeader()
209   {
210     if($this->skipHeader) return("");
212     if (get_object_info() != ""){
213       $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
214           "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
215           LDAP::fix(get_object_info()));
216     } else {
217       $display= print_header(get_template_path($this->plIcon),_($this->plDescription));
218     }
219     return($display);
220   }
223   /*! \brief  Generates the footer which is used whenever a tab object is 
224    *           displayed.
225    */
226   protected function _getTabFooter()
227   {
228     // Do not display tab footer for non tab objects 
229     if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
230       return("");
231     }
233     // Check if there is a dialog opened - We don't need any buttons in this case. 
234     if($this->tabObject->by_object[$this->tabObject->current]){
235       $current = $this->tabObject->by_object[$this->tabObject->current];  
236       if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
237         return("");
238       }
239     }
241     // Skip footer if requested;
242     if($this->skipFooter) return("");
244     // In case an of locked entry, we may have opened a read-only tab.
245     $str = "";
246     if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
247       $str.= "<p style=\"text-align:right\">
248         <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
249         </p>";
250       return($str);
251     }else{
253       // Display ok, (apply) and cancel buttons
254       $str.= "<p style=\"text-align:right\">\n";
255       $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
256       $str.= "&nbsp;\n";
257       if($this->displayApplyBtn){
258         $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
259         $str.= "&nbsp;\n";
260       }
261       $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
262       $str.= "</p>";
263     }
264     return($str);
265   }
268   /*! \brief  Initiates the removal for the given entries
269    *           and displays a confirmation dialog.
270    *      
271    *  @param  String  'action'  The name of the action which was the used as trigger.
272    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
273    *  @param  Array   'all'     A combination of both 'action' and 'target'.
274    */
275   protected function removeEntryRequested($action="",$target=array(),$all=array())
276   {
277     $disallowed = array();
278     $this->dns = array();
280     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
282     // Check permissons for each target 
283     foreach($target as $dn){
284       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
285       if(preg_match("/d/",$acl)){
286         $this->dns[] = $dn;
287       }else{
288         $disallowed[] = $dn;
289       }
290     }
291     if(count($disallowed)){
292       msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
293     }
295     // We've at least one entry to delete.
296     if(count($this->dns)){
298       // check locks
299       if ($user= get_multiple_locks($this->dns)){
300         return(gen_locked_message($user,$this->dns));
301       }
303       // Add locks
304       $dns_names = array();
305       foreach($this->dns as $dn){
306         $dns_names[] =LDAP::fix($dn);
307       }
308       add_lock ($this->dns, $this->ui->dn);
310       // Display confirmation dialog.
311       $smarty = get_smarty();
312       $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
313       $smarty->assign("multiple", true);
314       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
315     }
316   }  
319   /*! \brief  Object removal was confirmed, now remove the requested entries. 
320    *      
321    *  @param  String  'action'  The name of the action which was the used as trigger.
322    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
323    *  @param  Array   'all'     A combination of both 'action' and 'target'.
324    */
325   function removeEntryConfirmed($action="",$target=array(),$all=array(),
326       $altTabClass="",$altTabType="",$altAclCategory="")
327   {
328     $tabType = $this->tabType;
329     $tabClass = $this->tabClass;
330     $aclCategory = $this->aclCategory;
331     if(!empty($altTabClass)) $tabClass = $altTabClass;
332     if(!empty($altTabType)) $tabType = $altTabType;
333     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
335     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
337     foreach($this->dns as $key => $dn){
339       // Check permissions, are we allowed to remove this object? 
340       $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
341       if(preg_match("/d/",$acl)){
343         // Delete the object
344         $this->dn = $dn;
345         $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
346         $this->tabObject->set_acl_base($this->dn);
347         $this->tabObject->parent = &$this;
348         $this->tabObject->delete ();
350         // Remove the lock for the current object.
351         del_lock($this->dn);        
352       } else {
353         msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
354         new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
355       }
356     }
358     // Cleanup
359     $this->remove_lock();
360     $this->closeDialogs();
361   }
364   /*! \brief  Detects actions/events send by the ui
365    *           and the corresponding targets.
366    */
367   function detectPostActions()
368   {
369     if(!is_object($this->headpage)){
370       trigger_error("No valid headpage given....!");
371       return(array());
372     }
373     $action= $this->headpage->getAction();
374     if(isset($_POST['edit_apply']))  $action['action'] = "apply";    
375     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
376     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
377     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
378     if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";   
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     $this->dialogObject->save_object();
444     $msgs = $this->dialogObject->check();
445     if(count($msgs)){
446       foreach($msgs as $msg){
447         msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
448       }
449     }else{
450       $this->dn =  $this->dialogObject->dn;
451       $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
452       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
453       $this->closeDialogs();
454     }
455   }
458   /*! \brief  Restores a snapshot object.
459    *          The dn of the snapshot entry has to be given as ['target'] parameter.  
460    *      
461    *  @param  String  'action'  The name of the action which was the used as trigger.
462    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
463    *  @param  Array   'all'     A combination of both 'action' and 'target'.
464    */
465   function restoreSnapshot($action="",$target=array(),$all=array())
466   {
467     $entry = array_pop($target);
468     if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
469       $this->snapHandler->restore_snapshot($entry);
470       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
471       $this->closeDialogs();
472     }else{
473       msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
474           ERROR_DIALOG);
475     }
476   }
479   /*! \brief  Displays the "Restore snapshot dialog" for a given target. 
480    *          If no target is specified, open the restore removed object 
481    *           dialog.
482    *  @param  String  'action'  The name of the action which was the used as trigger.
483    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
484    *  @param  Array   'all'     A combination of both 'action' and 'target'.
485    */
486   function restoreSnapshotDialog($action="",$target=array(),$all=array())
487   {
488     // Set current restore base for snapshot handling.
489     if(is_object($this->snapHandler)){
490       $bases = array();
491       foreach($this->storagePoints as $sp){
492         $bases[] = $sp.$this->headpage->getBase();
493       }
494     }
496     // No bases specified? Try base  
497     if(!count($bases)) $bases[] = $this->headpage->getBase();
499     // No target, open the restore removed object dialog.
500     if(!count($target)){ 
501       $entry = $this->headpage->getBase();
502       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
503         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
504         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
505         $this->dialogObject->set_snapshot_bases($bases);
506         $this->dialogObject->display_all_removed_objects = true;
507         $this->dialogObject->display_restore_dialog = true;
508         $this->dialogObject->parent = &$this;
509       }else{
510         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
511             ERROR_DIALOG);
512       } 
513     }else{
515       // Display the restore points for a given object.
516       $entry = array_pop($target);
517       if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
518         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
519         $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
520         $this->dialogObject->set_snapshot_bases($bases);
521         $this->dialogObject->display_restore_dialog = true;
522         $this->dialogObject->parent = &$this;
523       }else{
524         msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
525             ERROR_DIALOG);
526       } 
527     }
528   }
531   /*! \brief  This method intiates the object creation.
532    *          
533    *  @param  String  'action'  The name of the action which was the used as trigger.
534    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
535    *  @param  Array   'all'     A combination of both 'action' and 'target'.
536    */
537   function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
538   {
539     /* To handle mutliple object types overload this method.
540      * ...
541      *   registerAction('newUser', 'newEntry');
542      *   registerAction('newGroup','newEntry');
543      * ... 
544      * 
545      * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
546      * {
547      *   switch($action){
548      *     case 'newUser' : {
549      *       mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
550      *     }
551      *     case 'newGroup' : {
552      *       mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
553      *     }
554      *   }
555      * }
556      **/ 
557     $tabType = $this->tabType;
558     $tabClass = $this->tabClass;
559     $aclCategory = $this->aclCategory;
560     if(!empty($altTabClass)) $tabClass = $altTabClass;
561     if(!empty($altTabType)) $tabType = $altTabType;
562     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
564     // Check locking & lock entry if required 
565     $this->displayApplyBtn = FALSE;
566     $this->dn = "new";
567     $this->is_new = TRUE;
568     $this->is_single_edit = FALSE;
569     $this->is_multiple_edit = FALSE;
571     set_object_info($this->dn);
573     // Open object.
574     if(empty($tabClass) || empty($tabType)){
575       // No tab type defined
576     }else{
577       $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
578       $this->tabObject->set_acl_base($this->headpage->getBase());
579       $this->tabObject->parent = &$this;
580       @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
581     }
582   }
585   /*! \brief  This method opens an existing object or a list of existing objects to be edited. 
586    *                  
587    * 
588    *  @param  String  'action'  The name of the action which was the used as trigger.
589    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
590    *  @param  Array   'all'     A combination of both 'action' and 'target'.
591    */
592   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
593   {
594     /* To handle mutliple object types overload this method.
595      * ...
596      *   registerAction('editUser', 'editEntry');
597      *   registerAction('editGroup','editEntry');
598      * ... 
599      * 
600      * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
601      * {
602      *   switch($action){
603      *     case 'editUser' : {
604      *       mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
605      *     }
606      *     case 'editGroup' : {
607      *       mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
608      *     }
609      *   }
610      * }
611      **/
613     // Do not create a new tabObject while there is already one opened,
614     //  the user may have just pressed F5 to reload the page.
615     if(is_object($this->tabObject)){
616       return;
617     }
618  
619     $tabType = $this->tabType;
620     $tabClass = $this->tabClass;
621     $aclCategory = $this->aclCategory;
622     if(!empty($altTabClass)) $tabClass = $altTabClass;
623     if(!empty($altTabType)) $tabType = $altTabType;
624     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
626     // Single edit - we only got one object dn.
627     if(count($target) == 1){
628       $this->displayApplyBtn = TRUE;
629       $this->is_new = FALSE;
630       $this->is_single_edit = TRUE;
631       $this->is_multiple_edit = FALSE;
633       // Get the dn of the object and creates lock
634       $this->dn = array_pop($target);
635       set_object_info($this->dn);
636       $user = get_lock($this->dn);
637       if ($user != ""){
638         return(gen_locked_message ($user, $this->dn,TRUE));
639       }
640       add_lock ($this->dn, $this->ui->dn);
642       // Open object.
643       if(empty($tabClass) || empty($tabType)){
644         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
645       }else{
646         $tab = $tabClass;
647         $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
648         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
649         $this->tabObject->set_acl_base($this->dn);
650         $this->tabObject->parent = &$this;
651       }
652     }else{
654       // We've multiple entries to edit.
655       $this->is_new = FALSE;
656       $this->is_singel_edit = FALSE;
657       $this->is_multiple_edit = TRUE;
659       // Open multiple edit handler.
660       if(empty($tabClass) || empty($tabType)){
661         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
662       }else{
663         $this->dns = $target;
664         $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
665             $this->dns,$this->headpage->getBase(),$aclCategory);
667         // Check for locked entries
668         if ($tmp->entries_locked()){
669           return($tmp->display_lock_message());
670         }
672         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
674         // Now lock entries.
675         if($tmp->multiple_available()){
676           $tmp->lock_entries($this->ui->dn);
677           $this->tabObject = $tmp;
678           set_object_info($this->tabObject->get_object_info());
679         }
680       }
681     }
682   }
685   /*! \brief  Save object modifications and closes dialogs (returns to object listing).
686    *          - Calls '::check' to validate the given input.
687    *          - Calls '::save' to save back object modifications (e.g. to ldap).
688    *          - Calls '::remove_locks' to remove eventually created locks.
689    *          - Calls '::closeDialogs' to return to the object listing.
690    */
691   protected function saveChanges()
692   {
693     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
694       $this->tabObject->save_object();
695       $msgs = $this->tabObject->check();
696       if(count($msgs)){
697         msg_dialog::displayChecks($msgs); 
698         return("");
699       }else{
700         $this->tabObject->save();
701         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
702         $this->remove_lock();
703         $this->closeDialogs();
704       }
705     }elseif($this->dialogObject instanceOf plugin){
706       $this->dialogObject->save_object();
707       $msgs = $this->dialogObject->check();
708       if(count($msgs)){
709         msg_dialog::displayChecks($msgs); 
710         return("");
711       }else{
712         $this->dialogObject->save();
713         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
714         $this->remove_lock();
715         $this->closeDialogs();
716       }
717     }
718   }
721   /*! \brief  Save object modifications and keep dialogs opened. 
722    *          - Calls '::check' to validate the given input.
723    *          - Calls '::save' to save back object modifications (e.g. to ldap).
724    */
725   protected function applyChanges()
726   {
727     if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
728       $this->tabObject->save_object();
729       $msgs = $this->tabObject->check();
730       if(count($msgs)){
731         msg_dialog::displayChecks($msgs); 
732         return("");
733       }else{
734         $this->tabObject->save();
735         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
736         $this->tabObject->re_init();
737       }
738     }
739   }
742   /*! \brief  This method closes dialogs
743    *           and cleans up the cached object info and the ui.
744    */
745   protected function closeDialogs()
746   {
747     $this->last_dn = $this->dn;
748     $this->last_dns = $this->dns;
749     $this->last_tabObject = $this->tabObject;
750     $this->last_dialogObject = $this->dialogObject;
751     $this->dn = "";
752     $this->dns = array();
753     $this->tabObject = null;
754     $this->dialogObject = null;
755     $this->skipFooter = FALSE;
756     set_object_info();
757   }
760   /*! \brief  Editing an object was caneled. 
761    *          Close dialogs/tabs and remove locks.
762    */
763   protected function cancelEdit()
764   {
765     $this->remove_lock();
766     $this->closeDialogs();
767   }
770   /*! \brief  Every click in the list user interface sends an event
771    *           here can we connect those events to a method. 
772    *          eg.  ::registerEvent('new','createUser')
773    *          When the action/event new is send, the method 'createUser' 
774    *           will be called.
775    */
776   function registerAction($action,$target)
777   {
778     $this->actions[$action] = $target;
779   }
782   /*! \brief  Removes ldap object locks created by this class.
783    *          Whenever an object is edited, we create locks to avoid 
784    *           concurrent modifications.
785    *          This locks will automatically removed here.
786    */
787   function remove_lock()
788   {
789     if(!empty($this->dn) && $this->dn != "new"){
790       del_lock($this->dn);
791     }
792     if(count($this->dns)){
793       del_lock($this->dns);
794     }
795   }
798   /*! \brief  This method is used to queue and process copy&paste actions. 
799    *          Allows to copy, cut and paste mutliple entries at once.
800    *  @param  String  'action'  The name of the action which was the used as trigger.
801    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
802    *  @param  Array   'all'     A combination of both 'action' and 'target'.
803    */
804   function copyPasteHandler($action="",$target=array(),$all=array(), 
805       $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
806   {
807     // Return without any actions while copy&paste handler is disabled.
808     if(!is_object($this->cpHandler))  return("");
810     $tabType = $this->tabType;
811     $tabClass = $this->tabClass;
812     $aclCategory = $this->aclCategory;
813     $aclPlugin = $this->aclPlugin;
814     if(!empty($altTabClass)) $tabClass = $altTabClass;
815     if(!empty($altTabType)) $tabType = $altTabType;
816     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
817     if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
819     // Save user input
820     $this->cpHandler->save_object();
822     // Add entries to queue 
823     if($action == "copy" || $action == "cut"){
824       $this->cpHandler->cleanup_queue();
825       foreach($target as $dn){
826         if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
827           $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
828           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
829         }
830         if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
831           $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
832           @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
833         }
834       }
835     }
837     // Initiate pasting
838     if($action == "paste"){
839       $this->cpPastingStarted = TRUE;
840     }
842     // Display any c&p dialogs, eg. object modifications required before pasting.
843     if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
844       $this->cpHandler->SetVar("base",$this->headpage->getBase());
845       $data = $this->cpHandler->execute();
846       if(!empty($data)){
847         return($data);
848       }
849     }
851     // Automatically disable pasting process since there is no entry left to paste.
852     if(!$this->cpHandler->entries_queued()){
853       $this->cpPastingStarted = FALSE;
854     }
855     return("");
856   }
859   function setFilter($str) {
860     $this->filter = $str;
861   }
864   function postcreate() {
865     $this->_handlePostEvent('POSTCREATE');
866   }
867   function postmodify(){
868     $this->_handlePostEvent('POSTMODIFY');
869   }
870   function postremove(){
871     $this->_handlePostEvent('POSTREMOVE');
872   }
874   function _handlePostEvent($type)
875   {
877     /* Find postcreate entries for this class */
878     $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
879     if ($command != ""){
881       /* Walk through attribute list */
882       foreach ($this->attributes as $attr){
883         if (!is_array($this->$attr)){
884           $add_attrs[$attr] = $this->$attr;
885         }
886       }
887       $add_attrs['dn']=$this->dn;
889       $tmp = array();
890       foreach($add_attrs as $name => $value){
891         $tmp[$name] =  strlen($name);
892       }
893       arsort($tmp);
895       /* Additional attributes */
896       foreach ($tmp as $name => $len){
897         $value = $add_attrs[$name];
898         $command= str_replace("%$name", "$value", $command);
899       }
901       if (check_command($command)){
902         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
903             $command, "Execute");
904         exec($command,$arr);
905         foreach($arr as $str){
906           @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
907               $command, "Result: ".$str);
908         }
909       } else {
910         $message= msgPool::cmdnotfound($type, get_class($this));
911         msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
912       }
913     }
914   }
916   function is_modal_dialog()
917   {
918     return(is_object($this->tabObject) || is_object($this->dialogObject));
919   }
922 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
923 ?>