X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_printerPPDSelectionDialog.inc;h=9c36e88e9e38a09e195ee1afc60efa0fcf445f01;hb=d9f1895952e9b02c1b0c398cc5dc09b88178e603;hp=1c949fb99ddf5015a3671e3ec3c9758595d244be;hpb=c59090d7f1094c164c63689262eaadf0a67eba97;p=gosa.git diff --git a/plugins/admin/systems/class_printerPPDSelectionDialog.inc b/plugins/admin/systems/class_printerPPDSelectionDialog.inc index 1c949fb99..9c36e88e9 100644 --- a/plugins/admin/systems/class_printerPPDSelectionDialog.inc +++ b/plugins/admin/systems/class_printerPPDSelectionDialog.inc @@ -16,6 +16,7 @@ class printerPPDSelectionDialog extends plugin var $header =array(); var $Vendor = ""; + var $current_del_id = ""; function printerPPDSelectionDialog ($config, $dn= NULL,$list=false,$headers=false,$ppd=false) { @@ -55,18 +56,76 @@ class printerPPDSelectionDialog extends plugin $regex = str_replace("**","*",$regex); $_SESSION['printerPPDSelectionDialog']['regex'] = $regex; + /* Delete requested, check if everything is ok and display confirmation dialog */ + if(isset($_GET['act']) && $_GET['act'] == "del"){ + + /* Get id and check if id is valid */ + $id_to_del = base64_decode($_GET['id']); + $found = ""; + foreach($this->list[$this->Vendor] as $key => $data){ + if($data['link'] == $id_to_del){ + $found = $key; + break; + } + } + if(!empty($found)){ + $this->current_del_id = $id_to_del; + + $smarty->assign("warning", sprintf(_("You're about to delete the ppd file '%s' at '%s'."), $found,$id_to_del)); + return($smarty->fetch(get_template_path('remove_ppd.tpl', TRUE))); + + }else{ + print_red(sprintf(_("Could not found specified ppd file '%s'."),$id_to_del)); + } + } + + /* Deletion confirmed */ + if(isset($_POST['delete_ppd_confirm']) && !empty($this->current_del_id)){ + + /* check if file is removeable */ + if(is_writeable($this->current_del_id)){ + $is_ok = @unlink($this->current_del_id); + + /* Update ppd list */ + if($is_ok){ + foreach($this->list as $vendor => $ppds){ + foreach($ppds as $ppd => $data){ + if($data['link'] == $this->current_del_id){ + unset($this->list[$vendor][$ppd]); + } + } + } + } + }else{ + $is_ok = false; + } + + if(!$is_ok){ + print_red(_("Something went wrong while trying to remove the ppd file from server, possibly we have no write access.")); + } + } + /** Added **/ $list = array(); foreach($this->list as $cat => $ppds){ foreach($ppds as $ppd){ if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){ - $list[$ppd['link']] = $ppd; + if(is_readable($ppd['link'])){ + $list[$ppd['link']] = $ppd; + } } } } - + + + /* Open vendor folder */ if((isset($_GET['act']))&&($_GET['act']=="open")) { - $this->Vendor = $_GET['id']; + if((!empty($_GET['id'])) && (!isset( $this->header[base64_decode($_GET['id'])]))){ + print_red(sprintf(_("Selected vendor '%s' does not exists in our list of ppds."),base64_decode($_GET['id']))); + $this->Vendor = ""; + }else{ + $this->Vendor = base64_decode($_GET['id']); + } } $div = new divSelectBox("printerPPDSelectionDialog"); @@ -75,12 +134,12 @@ class printerPPDSelectionDialog extends plugin $linkopen = "%s"; $uselink = "%s"; - + $dellink = ""._("delete").""; if(empty($this->Vendor)){ foreach($this-> header as $key => $entry){ $div ->AddEntry (array( - array("string"=>sprintf($linkopen,$key,$key),"attach"=>"style='border-right:0px;'") + array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'") )); } }else{ @@ -89,8 +148,16 @@ class printerPPDSelectionDialog extends plugin )); foreach($list as $key => $ppd){ if(preg_match("/^".$this->Vendor."/",$ppd['ppd'])){ + + if(is_writeable($ppd['link'])){ + $del_str = sprintf($dellink,base64_encode($key)); + }else{ + $del_str = ""; + } + $div ->AddEntry (array( - array("string"=>sprintf($uselink,$key,$ppd['ppd']),"attach"=>"style='border-right:0px;'") + array("string"=>sprintf($uselink,base64_encode($key),$ppd['ppd'])), + array("string"=>$del_str,"attach"=>"style='border-right:0px;'") )); } }