X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_printerPPDSelectionDialog.inc;h=d1d3329fa5d73f5fc361378502b1f2001765b3cc;hb=5f1f63cbff1a76de561e6e556342179ace8ca24e;hp=b10357b9d056ca6fc703002375cfde08642b1a76;hpb=b7e7d697d736cadae9135d094672c947b35b539f;p=gosa.git diff --git a/plugins/admin/systems/class_printerPPDSelectionDialog.inc b/plugins/admin/systems/class_printerPPDSelectionDialog.inc index b10357b9d..d1d3329fa 100644 --- a/plugins/admin/systems/class_printerPPDSelectionDialog.inc +++ b/plugins/admin/systems/class_printerPPDSelectionDialog.inc @@ -2,22 +2,16 @@ class printerPPDSelectionDialog extends plugin { - /* CLI vars */ - var $cli_summary = "Manage server basic objects"; - var $cli_description = "Some longer text\nfor help"; - var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); - /* attribute list for save action */ var $ignore_account = FALSE; - var $attributes = array("currentPos","currentSel"); + var $attributes = array(); var $objectclasses = array("whatever"); var $list =array(); var $header =array(); - var $currentPos = ""; - var $currentSel = -1; - var $selectedPPD = ""; + var $Vendor = ""; + var $current_del_id = ""; function printerPPDSelectionDialog ($config, $dn= NULL,$list=false,$headers=false,$ppd=false) { @@ -26,113 +20,161 @@ class printerPPDSelectionDialog extends plugin $this->header = $headers; $this->depselect = $this->config->current['BASE']; - /* If there is already a ppd file selected, use this as preselected object in our ppds list - */ - if(isset($ppd)){ - $tmp2 = split("\n",$ppd['ppd']); - $this->currentPos = $tmp2[0]; - $this->currentSel = preg_replace("/^ -/","",$tmp2[1]); - } - + if(!isset($_SESSION['printerPPDSelectionDialog'])){ + $_SESSION['printerPPDSelectionDialog']['regex'] = "*"; + } + /* Order the manufacturers index */ ksort($this->header); } function execute() { + /* Call parent execute */ + plugin::execute(); + /* Fill templating stuff */ $smarty= get_smarty(); $display= ""; $s_action = "none"; - /* Links used to open/select an entry */ - $LINK_openDir = "%s"; - $LINK_useThis = "%s"; + $regex = $_SESSION['printerPPDSelectionDialog']['regex']; - /* Open manufacturer */ - if(isset($_GET['open'])){ - $this->currentPos=base64_decode($_GET['open']); + if(isset($_GET['search'])){ + $regex = $_GET['search']."*"; } - - /* Select ppd */ - if(isset($_GET['use'])){ - $this->currentSel=base64_decode($_GET['use']); + + if(isset($_POST['regex'])){ + $regex= $_POST['regex']; + } + + $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)); + } } - /* if manufacturer is selected and a ppd file - * Set this selected file to our return value. - */ - if(isset($this->list[$this->currentPos][$this->currentSel])){ - $this->selectedPPD = $this->list[$this->currentPos][$this->currentSel]; + /* 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.")); + } } - /* "Back" resets our selection - */ - foreach($_POST as $post => $val){ - if(preg_match("/dep_back/",$post)){ - $s_action = "back"; - $this->currentPos = ""; - $this->currentSel = -1; + /** Added **/ + $list = array(); + foreach($this->list as $cat => $ppds){ + foreach($ppds as $ppd){ + if(preg_match("/^".str_replace("*",".*",$regex)."/i",$ppd['ppd'])){ + if(is_readable($ppd['link'])){ + $list[$ppd['link']] = $ppd; + } + } } } - /* The listhead is shown on top of the list. - * It represents a menu that contains basic option for this dialog/list - */ - $listhead = "