diff --git a/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc b/gosa-plugins/goto-ng/admin/newConfigManagement/class_newConfigManagement.inc
index bf29fc9e9fb2541d033195379ddf098938d0fd97..3f1dac3867245ebf8e9d56e12492f74b9311455e 100644 (file)
var $cfgTypeMap = NULL;
var $cfgItemMap = NULL;
+ var $addableContainerItems = array();
+ var $currentObject = NULL;
+
+
/*! \brief Initialize the plugin and finally update the data model.
*/
function __construct($config, $dn)
// Walk through each entry and then try to add it to the model
foreach($sLen as $unused => $itemPath){
+ // Do not add the root element '/'
+ if($itemPath == "/") continue;
+
$type = $res[$itemPath];
// Root installation objects do not have a name, so we use 'root' here.
- $targetPath = trim($path."/root/".$itemPath);
+ $targetPath = trim($path."/".$itemPath);
// Remove trailing and duplicated slashes
$targetPath = rtrim($targetPath, '/');
*/
function setCurrentContainer($cont)
{
-
$this->selectedContainer = $cont;
// Update list of items within the selected container.
return;
}
$this->installationMethods = $res;
+
if(!count($this->installationMethods)){
$this->errorMessage = _("No selectable install methods returned!");
msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
foreach($this->installationMethods as $method => $items){
foreach($items['items'] as $itemName => $item){
$this->cfgItemMap[$itemName] = $method;
+
+ // This enables us to create the first level of config items when
+ // a release is selected.
+ if($item['name'] == "/"){
+ $this->installationMethods[$method]['items']['Release'] =
+ &$this->installationMethods[$method]['items'][$itemName];
+ }
}
}
}
{
}
+ function removeEntry($ids)
+ {
+ $item = $this->dataModel->getItemById($ids[0]);
+ $release = preg_replace("/^.*\//","",$item['values']['__release']);
+ $path = $item['values']['__path'];
+ $rpc = $this->config->getRpcHandle();
+ $rpc->removeConfigItem($release, $path);
+
+ if(!$rpc->success()){
+ msg_dialog::display(_("Error"), sprintf(_("Failed to remove: %s"), $rpc->get_error()),ERROR_DIALOG);
+ return(NULL);
+ }
+ }
function editEntry($ids)
{
$this->setInstallMethod($method);
$this->TemplateEngine->setValues($item['type'],$item['values']['itemValues']);
$this->listing->setDialogObject($this->TemplateEngine);
+ $this->currentObject = $item;
+ }
+ }
+
+ function newEntry($type)
+ {
+ $method = $this->cfgItemMap[$type];
+ $this->setInstallMethod($method);
+ $this->TemplateEngine->setValues($type,array());
+ $this->listing->setDialogObject($this->TemplateEngine);
+ $this->currentObject = NULL;
+ }
+
+
+ function getItemPath($fullPath)
+ {
+ $fPath = $fullPath.'/';
+ while(preg_match("/\//", $fPath)){
+ $fPath = preg_replace("/\/[^\/]*$/","", $fPath);
+ $item = $this->dataModel->getItemByPath($fPath);
+ if(isset($this->cfgItemMap[$item['type']])){
+ return(preg_replace("/".preg_quote($item['parentPath'],'/')."/", "", $fullPath));
+ }
}
+ return(NULL);
}
+ function getReleasePath($fullPath)
+ {
+ $fullPath.='/';
+ while(preg_match("/\//", $fullPath)){
+ $fullPath = preg_replace("/\/[^\/]*$/","", $fullPath);
+ $item = $this->dataModel->getItemByPath($fullPath);
+ if($item['type'] == 'Release'){
+ return($fullPath);
+ }
+ }
+ return(NULL);
+ }
+
+ function saveItemChanges()
+ {
+ $item = $this->currentObject;
+
+ // Null means a new object has to be added.
+ if($item == NULL){
+
+ // Save template engine modifications
+ $this->TemplateEngine->save_object();
+ $release = preg_replace("/^.*\//","", $this->getReleasePath($this->selectedContainer));
+ $type = $this->TemplateEngine->getItemType();
+
+ // Collect modified values
+ $values = array();
+ foreach($this->TemplateEngine->getWidgets() as $w){
+ $values[$w->getName()] = $w->getValue();
+ }
+
+ // Create the elements target path
+ $path = $this->getItemPath($this->selectedContainer)."/".$values['name'];
+
+ // Add the new item
+ $rpc = $this->config->getRpcHandle();
+ $res = $rpc->setConfigItem($release, $path, $type, $values);
+ if(!$rpc->success()){
+ msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG);
+ return(NULL);
+ }else{
+
+ // We've successfully added the item, now add it to the tree.
+ $this->dataModel->addItem($type, $this->selectedContainer, $values['name'],
+ array(
+ '__editable' => TRUE,
+ '__removeable' => TRUE,
+ '__path' => $path,
+ '__release' => $this->getReleasePath($this->selectedContainer)
+ ), '-' );
+
+ // Finally - close the dialog.
+ $this->listing->clearDialogObject();
+ }
+ }else{
+ // Collect modified values.
+ $this->TemplateEngine->save_object();
+ $values = array();
+ foreach($this->TemplateEngine->getWidgets() as $w){
+ $values[$w->getName()] = $w->getValue();
+ }
+
+ // Get the items release & path info
+ $release = preg_replace("/^.*\//","",$item['values']['__release']);
+ $path = $item['values']['__path'];
+
+ // Write the modifications back to the server.
+ $rpc = $this->config->getRpcHandle();
+ $res = $rpc->setConfigItem($release, $path, $item['type'], $values);
+ if(!$rpc->success()){
+ msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions: %s"), $rpc->get_error()),ERROR_DIALOG);
+ return(NULL);
+ }else{
+
+ // Update the data model
+ $item['values']['itemValues'] = $values;
+ $this->dataModel->setItemValues($item['path'], $item['values']);
+ $this->listing->clearDialogObject();
+ }
+ }
+ }
}
+
+
?>