From a989bbfee76a446a04ac0b692bc357fb5a108b27 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 26 Oct 2009 10:01:14 +0000 Subject: [PATCH] Added new (not yet finished) management class git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14629 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_management.inc | 364 +++++++++++++++++++++++++ 1 file changed, 364 insertions(+) create mode 100644 gosa-core/include/class_management.inc diff --git a/gosa-core/include/class_management.inc b/gosa-core/include/class_management.inc new file mode 100644 index 000000000..a8e5813f2 --- /dev/null +++ b/gosa-core/include/class_management.inc @@ -0,0 +1,364 @@ +plugname = $plugname; + $this->headpage = $headpage; + $this->ui = $ui; + $this->config = $config; + + if(empty($this->plIcon)){ + $this->plIcon = "plugins/".$plugname."/images/plugin.png"; + } + } + + function execute() + { + // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog. + $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/'); + session::set('LOCK_VARS_TO_USE',$vars); + + // Handle actions (POSTs and GETs) + $str = $this->detectPostActions(); + if($str) return($this->getHeader().$str); + + // Display tab object. + if($this->tabObject instanceOf tabs){ + $this->tabObject->save_object(); + $display = $this->tabObject->execute(); + $display.= $this->_getTabFooter(); + return($this->getHeader().$display); + } + + $this->headpage->update(); + $display = $this->headpage->render(); + return($this->getHeader().$display); + } + + 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); + } + + + protected function _getTabFooter() + { + if(!$this->tabObject instanceOf tabs){ + return(""); + } + + if($this->tabObject->by_object[$this->tabObject->current]){ + $current = $this->tabObject->by_object[$this->tabObject->current]; + if(is_object($current->dialog)){ + return(""); + } + } + + $str = ""; + if($this->tabObject->read_only == TRUE){ + $str.= "

+ +

"; + return($str); + }else{ + $str.= "

\n"; + $str.= "\n"; + $str.= " \n"; + if($this->displayApplyBtn){ + $str.= "\n"; + $str.= " \n"; + } + $str.= "\n"; + $str.= "

"; + } + return($str); + } + + + protected function removeEntryRequested($action,$entry,$all) + { + $disallowed = array(); + $this->dns = array(); + foreach($entry as $dn){ + $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin); + if(preg_match("/d/",$acl)){ + $this->dns[] = $dn; + }else{ + $disallowed[] = $dn; + } + } + + if(count($disallowed)){ + msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG); + } + + if(count($this->dns)){ + + /* Check locks */ + if ($user= get_multiple_locks($this->dns)){ + return(gen_locked_message($user,$this->dns)); + } + + $dns_names = array(); + foreach($this->dns as $dn){ + $dns_names[] =LDAP::fix($dn); + } + add_lock ($this->dns, $this->ui->dn); + + /* Lock the current entry, so nobody will edit it during deletion */ + $smarty = get_smarty(); + $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName))); + $smarty->assign("multiple", true); + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } + } + + + protected function removeEntryConfirmed() + { + foreach($this->dns as $key => $dn){ + + /* Load permissions for selected 'dn' and check if + we're allowed to remove this 'dn' */ + $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin); + if(preg_match("/d/",$acl)){ + + /* Delete request is permitted, perform LDAP action */ + $this->dn = $dn; + $tab = $this->tabClass; + $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn, $this->aclCategory); + $this->tabObject->set_acl_base($this->dn); + $this->tabObject->delete (); + $this->closeDialogs(); + del_lock($this->dn); + } else { + + /* Normally this shouldn't be reached, send some extra + logs to notify the administrator */ + msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG); + new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion."); + return; + } + } + + $this->closeDialogs(); + $this->remove_lock(); + } + + + function detectPostActions() + { + $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"; + + // Start action + if(isset($this->actions[$action['action']])){ + $func = $this->actions[$action['action']]; + if(!isset($action['targets']))$action['targets']= array(); + return($this->$func($action['action'],$action['targets'],$action)); + } + } + + function newEntry($action,$target,$all) + { + // Check locking & lock entry if required + $this->displayApplyBtn = FALSE; + $this->dn = "new"; + $this->is_new = TRUE; + $this->is_single_edit = FALSE; + $this->is_multiple_edit = FALSE; + + set_object_info($this->dn); + + // Open object. + if(empty($this->tabClass) || empty($this->tabType)){ + // No tab type defined + }else{ + $tab = $this->tabClass; + $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn, $this->aclCategory); + $this->tabObject->set_acl_base($this->headpage->getBase()); + } + } + + function editEntry($action,$target,$all) + { + if(count($target) == 0){ + //nothing + }elseif(count($target) == 1){ + + // Check locking & lock entry if required + $this->displayApplyBtn = TRUE; + + $this->is_new = FALSE; + $this->is_single_edit = TRUE; + $this->is_multiple_edit = FALSE; + + $this->dn = array_pop($target); + set_object_info($this->dn); + $user = get_lock($this->dn); + if ($user != ""){ + return(gen_locked_message ($user, $this->dn,TRUE)); + } + add_lock ($this->dn, $this->ui->dn); + + // Open object. + if(empty($this->tabClass) || empty($this->tabType)){ + // No tab type defined + }else{ + $tab = $this->tabClass; + $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn,$this->aclCategory); + $this->tabObject->set_acl_base($this->dn); + } + }else{ + echo "? Multiple not implemented yet"; + + $this->is_new = FALSE; + $this->is_singel_edit = FALSE; + $this->is_multiple_edit = TRUE; + + } + } + + protected function saveChanges() + { + if($this->tabObject instanceOf tabs){ + $this->tabObject->save_object(); + $msgs = $this->tabObject->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + return(""); + }else{ + $this->tabObject->save(); + $this->closeDialogs(); + $this->remove_lock(); + } + } + } + + protected function applyChanges() + { + if($this->tabObject instanceOf tabs){ + $this->tabObject->save_object(); + $msgs = $this->tabObject->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + return(""); + }else{ + $this->tabObject->save(); + $this->tabObject->re_init(); + } + } + } + + protected function closeDialogs() + { + $this->dn = ""; + $this->dns = array(); + $this->tabObject = null; + set_object_info(); + } + + protected function cancelEdit() + { + $this->closeDialogs(); + $this->remove_lock(); + } + + + + + function registerAction($action,$target) + { + $this->actions[$action] = $target; + } + + function remove_lock() + { + if(!empty($this->dn) && $this->dn != "new"){ + del_lock($this->dn); + } + if(count($this->dns)){ + del_lock($this->dns); + } + } + + + function save_object(){} + function setDescription($str) { + $this->plDescription = $str; + } + function setHeadpage($str) { + $this->headpage = $str; + } + function setFilter($str) { + $this->filter = $str; + } + function setIcon($str) { + $this->plIcon = $str; + } + function setHeadline($str) { + $this->plHeadline = $str; + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> -- 2.30.2