X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_management.inc;h=aec1431f5efcb9cd5049287b743f9c22b8769bec;hb=319592def57490e70cbf3d2a8ac2acfb4adcaa20;hp=6a4675e50651be9edbe13e081c4f40d0815524d3;hpb=402a95a272290c036a41d37ef61f792df419c344;p=gosa.git diff --git a/gosa-core/include/class_management.inc b/gosa-core/include/class_management.inc index 6a4675e50..aec1431f5 100644 --- a/gosa-core/include/class_management.inc +++ b/gosa-core/include/class_management.inc @@ -3,7 +3,7 @@ * This code is part of GOsa (http://www.gosa-project.org) * Copyright (C) 2003-2008 GONICUS GmbH * - * ID: $$Id: class_plugin.inc 14584 2009-10-12 14:04:22Z hickert $$ + * ID: $$Id$$ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ class management public $plHeadline = "unconfigured"; // The currently used object(s) (e.g. in edit, removal) - protected $dn = ""; + public $dn = ""; // this is public due to some compatibility problems with class plugin.. protected $dns = array(); // The last used object(s). @@ -46,6 +46,7 @@ class management // The tab definitions to use for the current object. protected $tabClass = ""; // e.g. usertabs protected $tabType = ""; // e.g. USERTABS + protected $aclPlugin = ""; // e.g. generic protected $aclCategory = ""; // e.g. users protected $objectName = ""; // e.g. users @@ -58,7 +59,13 @@ class management protected $last_dialogObject = null; // Whether to display the apply button or not - protected $displayApplyBtn = ""; + protected $displayApplyBtn = FALSE; + + // Whether to display a header or not. + protected $skipHeader = false; + + // Whether to display a footer or not. + protected $skipFooter = false; // Copy&Paste handler protected $cpHandler = null; @@ -70,13 +77,16 @@ class management protected $snapHandler = null; // The listing handlers - protected $headpage = null; - protected $filter = null; + private $headpage = null; + private $filter = null; // A list of configured actions/events protected $actions = array(); - function __construct($config,$ui,$plugname, $headpage) + // Attributes managed by this plugin, can be used in post events; + public $attributes = array(); + + function __construct(&$config,$ui,$plugname, $headpage) { $this->plugname = $plugname; $this->headpage = $headpage; @@ -131,9 +141,6 @@ class management $this->filter->update(); session::global_set(get_class($this)."_filter", $this->filter); session::set('autocomplete', $this->filter); - if (!$this->filter->isValid()){ - msg_dialog::display(_("Filter error"), _("The filter is incomplete!"), ERROR_DIALOG); - } } // Handle actions (POSTs and GETs) @@ -152,7 +159,7 @@ class management // Display tab object. if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){ - $this->tabObject->save_object(); +# $this->tabObject->save_object(); $display = $this->tabObject->execute(); $display.= $this->_getTabFooter(); return($this->getHeader().$display); @@ -164,29 +171,51 @@ class management foreach($this->storagePoints as $sp){ $bases[] = $sp.$this->headpage->getBase(); } + + // No bases specified? Try base + if(!count($bases)) $bases[] = $this->headpage->getBase(); + $this->snapHandler->setSnapshotBases($bases); } - + + // Dummy filter editor + $dummy = ""; + $this->registerAction("editFilter", "editFilter"); + + // Display list + return($dummy.$this->renderList()); + } + + function editFilter() + { + $headpage = $this->getHeadpage(); + $this->dialogObject = new filterEditor($this->config,$headpage->categories); + } + + function renderList() + { $this->headpage->update(); $display = $this->headpage->render(); return($this->getHeader().$display); } + function getHeadpage() + { + return($this->headpage); + } + function getFilter() + { + return($this->filter); + } /*! \brief Generates the plugin header which is displayed whenever a tab object is * opened. */ protected function getHeader() { - if (get_object_info() != ""){ - $display= print_header(get_template_path($this->plIcon),_($this->plDescription), - "\"\"". - LDAP::fix(get_object_info())); - } else { - $display= print_header(get_template_path($this->plIcon),_($this->plDescription)); - } - return($display); + // We do not display any headers right now. + if(1 || $this->skipHeader) return(""); } @@ -208,6 +237,9 @@ class management } } + // Skip footer if requested; + if($this->skipFooter) return(""); + // In case an of locked entry, we may have opened a read-only tab. $str = ""; if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){ @@ -309,10 +341,10 @@ class management // Delete the object $this->dn = $dn; - $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory); + $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true); $this->tabObject->set_acl_base($this->dn); - $this->tabObject->delete (); $this->tabObject->parent = &$this; + $this->tabObject->delete (); // Remove the lock for the current object. del_lock($this->dn); @@ -333,12 +365,19 @@ class management */ function detectPostActions() { + if(!is_object($this->headpage)){ + trigger_error("No valid headpage given....!"); + return(array()); + } $action= $this->headpage->getAction(); if(isset($_POST['edit_apply'])) $action['action'] = "apply"; if(isset($_POST['edit_finish'])) $action['action'] = "save"; if(isset($_POST['edit_cancel'])) $action['action'] = "cancel"; if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed"; if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete"; + if(isset($_POST['editFilter'])) $action['action'] = "editFilter"; + if(isset($_POST['saveFilter'])) $action['action'] = "save"; + if(isset($_POST['cancelFilter'])) $action['action'] = "cancel"; // Detect Snapshot actions if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot"; @@ -402,7 +441,8 @@ class management * @param Array 'all' A combination of both 'action' and 'target'. */ function saveSnapshot($action="",$target=array(),$all=array()) - { + { + if(!is_object($this->dialogObject)) return; $this->dialogObject->save_object(); $msgs = $this->dialogObject->check(); if(count($msgs)){ @@ -456,6 +496,9 @@ class management } } + // No bases specified? Try base + if(!count($bases)) $bases[] = $this->headpage->getBase(); + // No target, open the restore removed object dialog. if(!count($target)){ $entry = $this->headpage->getBase(); @@ -534,10 +577,14 @@ class management if(empty($tabClass) || empty($tabType)){ // No tab type defined }else{ - $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory); - $this->tabObject->set_acl_base($this->headpage->getBase()); - $this->tabObject->parent = &$this; - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!"); + if (isset($this->config->data['TABS'][$tabType])) { + $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory); + $this->tabObject->set_acl_base($this->headpage->getBase()); + $this->tabObject->parent = &$this; + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!"); + } else { + msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG); + } } } @@ -568,7 +615,14 @@ class management * } * } * } - **/ + **/ + + // Do not create a new tabObject while there is already one opened, + // the user may have just pressed F5 to reload the page. + if(is_object($this->tabObject)){ + return; + } + $tabType = $this->tabType; $tabClass = $this->tabClass; $aclCategory = $this->aclCategory; @@ -625,8 +679,8 @@ class management @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!"); // Now lock entries. - $tmp->lock_entries($this->ui->dn); if($tmp->multiple_available()){ + $tmp->lock_entries($this->ui->dn); $this->tabObject = $tmp; set_object_info($this->tabObject->get_object_info()); } @@ -655,6 +709,18 @@ class management $this->remove_lock(); $this->closeDialogs(); } + }elseif($this->dialogObject instanceOf plugin){ + $this->dialogObject->save_object(); + $msgs = $this->dialogObject->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + return(""); + }else{ + $this->dialogObject->save(); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!"); + $this->remove_lock(); + $this->closeDialogs(); + } } } @@ -693,6 +759,7 @@ class management $this->dns = array(); $this->tabObject = null; $this->dialogObject = null; + $this->skipFooter = FALSE; set_object_info(); } @@ -764,11 +831,11 @@ class management $this->cpHandler->cleanup_queue(); foreach($target as $dn){ if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){ - $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory); + $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this); @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!"); } if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){ - $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory); + $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this); @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!"); } } @@ -800,6 +867,88 @@ class management $this->filter = $str; } + + function postcreate() { + $this->_handlePostEvent('POSTCREATE'); + } + function postmodify(){ + $this->_handlePostEvent('POSTMODIFY'); + } + function postremove(){ + $this->_handlePostEvent('POSTREMOVE'); + } + + function _handlePostEvent($type) + { + + /* Find postcreate entries for this class */ + $command= $this->config->search(get_class($this), $type,array('menu', 'tabs')); + if ($command != ""){ + + /* Walk through attribute list */ + foreach ($this->attributes as $attr){ + if (!is_array($this->$attr)){ + $add_attrs[$attr] = $this->$attr; + } + } + $add_attrs['dn']=$this->dn; + + $tmp = array(); + foreach($add_attrs as $name => $value){ + $tmp[$name] = strlen($name); + } + arsort($tmp); + + /* Additional attributes */ + foreach ($tmp as $name => $len){ + $value = $add_attrs[$name]; + $command= str_replace("%$name", "$value", $command); + } + + if (check_command($command)){ + @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, + $command, "Execute"); + exec($command,$arr); + foreach($arr as $str){ + @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, + $command, "Result: ".$str); + } + } else { + $message= msgPool::cmdnotfound($type, get_class($this)); + msg_dialog::display(_("Error"), $message, ERROR_DIALOG); + } + } + } + + function is_modal_dialog() + { + return(is_object($this->tabObject) || is_object($this->dialogObject)); + } + + + /*! \brief Forward command execution request + * to the correct method. + */ + function handle_post_events($mode, $addAttrs= array()) + { + if(!in_array($mode, array('add','remove','modify'))){ + trigger_error(sprintf("Invalid post event type given '%s'! Valid types are [add,modify,remove].", $mode)); + return; + } + switch ($mode){ + case "add": + plugin::callHook($this,"POSTCREATE", $addAttrs); + break; + + case "modify": + plugin::callHook($this,"POSTMODIFY", $addAttrs); + break; + + case "remove": + plugin::callHook($this,"POSTREMOVE", $addAttrs); + break; + } + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: