From 1a68537c6b947940a6d55c4e9e358d7095c8197e Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 13 Apr 2010 07:28:26 +0000 Subject: [PATCH] Updated apache plugin -Do not use old style lists git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@17598 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../apache2/class_servApacheEditVhost.inc | 277 ++++-------------- .../apache2/class_servApacheVhost.inc | 76 ++--- 2 files changed, 91 insertions(+), 262 deletions(-) diff --git a/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc b/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc index 1779839e5..96a906456 100644 --- a/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc +++ b/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheEditVhost.inc @@ -73,73 +73,30 @@ class servapacheVhostEdit extends plugin if(!isset($attrs['apacheServerAlias'])) $this->apacheServerAlias = array(); if(!isset($attrs['apacheScriptAlias'])) $this->apacheScriptAlias = array(); } - } - - /* Transports the given Arraykey one position up*/ - function ArrayUp($atr,$attrs) - { - $ret = $attrs; - $pos = $atr ; - $cn = count($attrs); - if(!(($pos == -1)||($pos == 1)||($pos >$cn))){ - $before = array_slice($attrs,0,($pos-2)); - $mitte = array_reverse(array_slice($attrs,($pos-2),2)); - $unten = array_slice($attrs,$pos); - $ret = array(); - $ret = $this->combineArrays($before,$mitte,$unten); - } - return($ret); - } - - /* Transports the given Arraykey one position down*/ - function ArrayDown($atr,$attrs) - { - $ret = $attrs; - $pos = $atr ; - $cn = count($attrs); - if(!(($pos == -1)||($pos == $cn))){ - $before = array_slice($attrs,0,($pos-1)); - $mitte = array_reverse(array_slice($attrs,($pos-1),2)); - $unten = array_slice($attrs,($pos+1)); - $ret = array(); - $ret = $this->combineArrays($before,$mitte,$unten); - } - return($ret); - } - - /* Combine new array */ - function combineArrays($ar0,$ar1,$ar2) - { - $ret = array(); - if(is_array($ar0)) - foreach($ar0 as $ar => $a){ - $ret[]=$a; - } - if(is_array($ar1)) - foreach($ar1 as $ar => $a){ - $ret[]=$a; - } - if(is_array($ar2)) - foreach($ar2 as $ar => $a){ - $ret[]=$a; - } - return($ret); - } - - function getpos($atr,$attrs) - { - $i = 0; - foreach($attrs as $attr => $name) { - $i++; - if($attr == $atr){ - return($i); - } - } - return(-1); + + // Prepare lists + $this->serverList = new sortableListing(array(),array(), TRUE); + $this->serverList->setDeleteable(true); + $this->serverList->setInstantDelete(false); + $this->serverList->setEditable(false); + $this->serverList->setWidth("100%"); + $this->serverList->setHeight("100px"); + $this->serverList->setHeader(array(_("Alias"),_("Directory"))); + $this->serverList->setColspecs(array('*','*','20px')); + $this->serverList->setDefaultSortColumn(0); + + $this->scriptList = new sortableListing(array(),array(), TRUE); + $this->scriptList->setDeleteable(true); + $this->scriptList->setInstantDelete(false); + $this->scriptList->setEditable(false); + $this->scriptList->setWidth("100%"); + $this->scriptList->setHeight("100px"); + $this->scriptList->setColspecs(array('*','*','20px')); + $this->scriptList->setHeader(array(_("Alias"),_("Directory"))); + $this->scriptList->setDefaultSortColumn(0); } - function execute() { /* Call parent execute */ @@ -148,123 +105,27 @@ class servapacheVhostEdit extends plugin /* Fill templating stuff */ $smarty= get_smarty(); + $smarty->assign("usePrototype", "true"); $display= ""; -// Outdated? - -# /* Open Vhost Entry Edit Dialog -# */ -# if(!count($this->VhostObject)){ -# $smarty->assign("AllowVhostEdit" , false); -# }else{ -# $smarty->assign("AllowVhostEdit" , true); -# if(isset($_POST['EditVhostEntries'])){ -# $this->dialog= new apacheVhostEditEntries($this->config,$this->dn,$this->VhostObject); -# } -# } -# -# /* Save Vhost Entry Edit Dialog -# */ -# if(isset($_POST['SaveVhostEntryChanges'])){ -# $this->dialog->save_object(); -# if(count($this->dialog->check())){ -# msg_dialog::displayChecks($this->dialog->check()); -# }else{ -# $this->dialog->save(); -# $this->dialog = false; -# } -# } -# -# /* Cancel Vhost Entrie Edit Dialog -# */ -# if(isset($_POST['CancelVhostEntryChanges'])){ -# $this->dialog = false; -# } -# -# /* Display any type of open dialogs -# */ -# if($this->dialog){ -# $this->dialog->save_object(); -# return($this->dialog->execute()); -# } -# - - /* Check posts - */ - $once =true; - foreach($_POST as $name => $value){ - - /* Move Server Aliases one position up - */ - if((preg_match("/^SAup_/",$name)) && ($once)){ - $once = false; - $id = preg_replace("/^SAup_/","",$name); - $id = preg_replace("/_.*$/","",$id); - $id = postDecode($id); - $this->apacheServerAlias = $this->ArrayUp(($id+1),$this->apacheServerAlias); - } - - /* Move Server Aliases one position down - */ - if((preg_match("/^SAdown_/",$name)) && ($once)){ - $once = false; - - $id = preg_replace("/^SAdown_/","",$name); - $id = preg_replace("/_.*$/","",$id); - $id = postDecode($id); - - $this->apacheServerAlias = $this->ArrayDown(($id+1),$this->apacheServerAlias); - } - - /* Delete a "Server Alias" - */ - if((preg_match("/^SAdel_/",$name)) && ($once)){ - $once = false; - $id = preg_replace("/^SAdel_/","",$name); - $id = preg_replace("/_.*$/","",$id); - $id = postDecode($id); - unset($this->apacheServerAlias[$id]); - $tmp =array(); - foreach($this->apacheServerAlias as $entry){ - $tmp[] = $entry; - } - $this->apacheServerAlias = $tmp; - } - - /* Move "Script Alias" one position up - */ - if((preg_match("/^SCup_/",$name)) && ($once)){ - $once = false; - $id = preg_replace("/^SCup_/","",$name); - $id = preg_replace("/_.*$/","",$id); - $id = postDecode($id); - $this->apacheScriptAlias = $this->ArrayUp(($id+1),$this->apacheScriptAlias); - } - - /* Move "Script Alias" one position down - */ - if((preg_match("/^SCdown_/",$name)) && ($once)){ - $once = false; - $id = preg_replace("/^SCdown_/","",$name); - $id = preg_replace("/_.*$/","",$id); - $id = postDecode($id); - $this->apacheScriptAlias = $this->ArrayDown(($id+1),$this->apacheScriptAlias); - } + $this->serverList->save_object(); + $action = $this->serverList->getAction(); + if($action['action'] == 'delete'){ + $key = $this->serverList->getKey($action['targets'][0]); + unset($this->apacheServerAlias[$key]); + } + if($action['action'] == 'reorder'){ + $this->apacheServerAlias = $this->serverList->getMaintainedData(); + } - /* Remove "Script Alias" - */ - if((preg_match("/^SCdel_/",$name)) && ($once)){ - $once = false; - $id = preg_replace("/^SCdel_/","",$name); - $id = preg_replace("/_.*$/","",$id); - $id = postDecode($id); - unset($this->apacheScriptAlias[$id]); - $tmp =array(); - foreach($this->apacheScriptAlias as $entry){ - $tmp[] = $entry; - } - $this->apacheScriptAlias = $tmp; - } + $this->scriptList->save_object(); + $action = $this->scriptList->getAction(); + if($action['action'] == 'delete'){ + $key = $this->scriptList->getKey($action['targets'][0]); + unset($this->apacheScriptAlias[$key]); + } + if($action['action'] == 'reorder'){ + $this->apacheScriptAlias = $this->scriptList->getMaintainedData(); } /* Add a new "Server Alias" @@ -289,44 +150,25 @@ class servapacheVhostEdit extends plugin $smarty->assign("NotNew", false); - /* Create Server Aliases divlist - */ - $div = new divSelectBox("apacheServerAlias"); - $div->setHeight(120); - $recs = $this->apacheServerAlias; - - $oneup = image('images/lists/sort-up.png','SAup_%s',_("Up"), "top"); - $onedown = image('images/lists/sort-down.png','SAdown_%s',_("Down"), "bottom"); - $onedel = image('images/lists/trash.png','SAdel_%s',_("Delete")); - - foreach($recs as $key => $rec){ - $div ->AddEntry(array( - array("string"=>$rec), - array("string"=>str_replace("%s",postEncode($key),$oneup.$onedown.$onedel), - "attach"=>"style='width:50px;border-right:0px;'") - )); + $this->serverList->setAcl($this->parent->getacl('apacheServerAlias')); + $data = $lData = array(); + foreach($this->apacheServerAlias as $key => $rec){ + $data[$key] = $rec; + $lData[$key]= array('data' => preg_split("/ /",$rec)); } - $smarty->assign("apacheServerAlias", $div->DrawList()); + $this->serverList->setListData($data,$lData); + $this->serverList->update(); + $smarty->assign("apacheServerAlias", $this->serverList->render()); - - /* Create Server Aliases divlist - */ - $div = new DivSelectBox("apacheScriptAlias"); - $div->setHeight(120); - $recs = $this->apacheScriptAlias; - - $oneup = image('images/lists/sort-up.png','SCup_%s',_("Up"), "top"); - $onedown = image('images/lists/sort-down.png','SCdown_%s',_("Down"), "bottom"); - $onedel = image('images/lists/trash.png','SCdel_%s',_("Delete")); - - foreach($recs as $key => $rec){ - $div ->AddEntry(array( - array("string"=>$rec), - array("string"=>str_replace("%s",postEncode($key),$oneup.$onedown.$onedel), - "attach"=>"style='width:50px;border-right:0px;'") - )); + $this->scriptList->setAcl($this->parent->getacl('apacheScriptAlias')); + $data = $lData = array(); + foreach($this->apacheScriptAlias as $key => $rec){ + $data[$key] = $rec; + $lData[$key]= array('data' => preg_split("/ /",$rec)); } - $smarty->assign("apacheScriptAlias", $div->DrawList()); + $this->scriptList->setListData($data,$lData); + $this->scriptList->update(); + $smarty->assign("apacheScriptAlias", $this->scriptList->render()); /* Display template */ $display.= $smarty->fetch(get_template_path('servApacheVhostEdit.tpl', TRUE, dirname(__FILE__))); @@ -445,12 +287,11 @@ class servapacheVhostEdit extends plugin } function acl_is_writeable($attribute,$skip_write = FALSE) - { - if($this->read_only) return(FALSE); - $ui= get_userinfo(); - return preg_match('/w/', $ui->get_permissions($this->acl_base, - $this->acl_category."servapache", $attribute, $skip_write)); + { + return($this->parent->acl_is_writeable($attribute,$skip_write)); } + + } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc b/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc index 9f224f10d..99a1a0681 100644 --- a/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc +++ b/gosa-plugins/apache2/admin/systems/services/apache2/class_servApacheVhost.inc @@ -59,6 +59,18 @@ class servapache extends goService /* Set service name */ $this->DisplayName = _("Apache service"); + + // Prepare lists + $this->vHostList = new sortableListing(); + $this->vHostList->setDeleteable(true); + $this->vHostList->setInstantDelete(false); + $this->vHostList->setEditable(true); + $this->vHostList->setWidth("100%"); + $this->vHostList->setHeight("100px"); + $this->vHostList->setColspecs(array('*','40px')); + $this->vHostList->setHeader(array(_("Name"))); + $this->vHostList->setDefaultSortColumn(0); + } @@ -109,31 +121,16 @@ class servapache extends goService /* Check for edit vhost request */ - $once = false; - foreach( $_POST as $name => $value){ - - /* check all post for edit request - */ - if(preg_match("/^editVhost_/",$name)&& !$once && $this->acl_is_writeable("VirtualHosts")){ - $once =true; - $tmp = preg_replace("/^editVhost_/","",$name); - $tmp = base64_decode(preg_replace("/_.*$/","",$tmp)); - $this->dialog= new servapacheVhostEdit($this->config,$this->dn,$this->Vhosts[$tmp]); + $this->vHostList->save_object(); + $action = $this->vHostList->getAction(); + if($action['action'] == 'delete'){ + $id = $this->vHostList->getKey($action['targets'][0]); + $this->RemoveVhost($id); + } + if($action['action'] == 'edit'){ + $id = $this->vHostList->getKey($action['targets'][0]); + $this->dialog= new servapacheVhostEdit($this->config,$this->dn,$this->Vhosts[$id]); $this->dialog->set_acl_category('server'); - } - - /* check posts for delete vhost - */ - if(preg_match("/^delVhost_/",$name)&&!$once && $this->acl_is_writeable("VirtualHosts")){ - - $once =true; - $tmp = preg_replace("/^delVhost_/","",$name); - $tmp = base64_decode(preg_replace("/_.*$/","",$tmp)); - - /* Initiate deletion - */ - $this->RemoveVhost($tmp); - } } /* Show dialog @@ -144,25 +141,6 @@ class servapache extends goService return($this->dialog->execute()); } - /* Create Listbox with existing Vhosts - */ - $VhostList = new divSelectBox("apacheConfigs"); - $VhostList -> SetHeight(140); - - /* Add entries to divlist - */ - $editImg = - image('images/lists/edit.png','editVhost_%s'). - image('images/lists/trash.png','delVhost_%s'); - - foreach($this->Vhosts as $vhost => $values ){ - $VhostList->AddEntry(array( - array("string" => $vhost), - array("string" => str_replace("%s",postEncode($vhost),$editImg), - "attach" => "style='width:40px;'") - )); - } - /* Assign ACL to smarty */ $info = $this->plInfo(); @@ -170,10 +148,20 @@ class servapache extends goService $smarty->assign($name."ACL",$this->getacl($name)); } + /* Create Listbox with existing Vhosts + */ + $this->vHostList->setAcl($this->getacl('VirtualHosts')); + $data = $lData = array(); + foreach($this->Vhosts as $vhost => $values){ + $data[$vhost]=$values; + $lData[$vhost]=array('data'=>array($vhost)); + } + $this->vHostList->setListData($data,$lData); + $this->vHostList->update(); /* Display template */ - $smarty->assign("VhostList",$VhostList->DrawList()); + $smarty->assign("VhostList",$this->vHostList->render()); $display.= $smarty->fetch(get_template_path('servApacheVhost.tpl', TRUE , dirname(__FILE__))); return($display); } -- 2.30.2