diff --git a/plugins/admin/systems/class_printerPPDSelectionDialog.inc b/plugins/admin/systems/class_printerPPDSelectionDialog.inc
index a03209ca45c29aebb0e50ace06da3c78d82ce39b..d4f5d16b8d00603aca0b48f6a7d1f6accf45a581 100644 (file)
/* 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 $current_del_id = "";
+ var $Vendor = "";
- var $currentPos = "";
- var $currentSel = -1;
- var $selectedPPD = "";
-
- function printerPPDSelectionDialog ($config, $dn= NULL,$list=false,$headers=false,$ppd=false)
+ function printerPPDSelectionDialog (&$config, $dn= NULL,$list=false,$headers=false,$ppd=false)
{
plugin::plugin ($config, $dn);
$this->list = $list;
$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)){
- print_a( $ppd);
- $tmp2 = split("\n",$ppd['ppd']);
- if(count($tmp2)==2){
- $this->currentPos = $tmp2[0];
- $this->currentSel = preg_replace("/^ -/","",$tmp2[1]);
- }
- }
-
- */
if(!isset($_SESSION['printerPPDSelectionDialog'])){
$_SESSION['printerPPDSelectionDialog']['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));
+ }
+ }
+
+ /* 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 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];
+ 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['ppd'];
+ if(is_readable($ppd['link'])){
+ $list[$ppd['link']] = $ppd;
+ }
+ }
+ }
+ }
+
+ if((isset($_GET['act']))&&($_GET['act']=="open")) {
+
+ 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");
+ $div ->SetHeight(450);
+ $div ->SetSummary(_("Printer ppd selection."));
+
+ $linkopen = "<a href='?plug=".$_GET['plug']."&act=open&id=%s'>
+ <img src='images/folder.png' class='center' border=0> %s
+ </a>";
+ $uselink = "<a href='?plug=".$_GET['plug']."&act=use&id=%s'>%s</a>";
+ $dellink = "<a href='?plug=".$_GET['plug']."&act=del&id=%s'>
+ <img src='images/edittrash.png' alt='"._("delete")."' border=0>
+ </a>";
+
+ if(empty($this->Vendor)){
+ foreach($this-> header as $key => $entry){
+ $div ->AddEntry (array(
+ array("string"=>sprintf($linkopen,base64_encode($key),$key),"attach"=>"style='border-right:0px;'")
+ ));
+ }
+ }else{
+ $div ->AddEntry (array(
+ array("string"=>sprintf($linkopen,"",".. ["._("back")."]"),"attach"=>"style='border-right:0px;'")
+ ));
+ 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,base64_encode($key),$ppd['ppd'])),
+ array("string"=>$del_str,"attach"=>"style='border-right:0px;'")
+
+ ));
}
}
}
- $smarty->assign("objects", $list);
- $smarty->assign("objectKeys", array_flip($list));
+ $smarty->assign("List", $div -> DrawList());
$smarty->assign("search_image", get_template_path('images/search.png'));
$smarty->assign("launchimage", get_template_path('images/small_filter.png'));
$smarty->assign("tree_image", get_template_path('images/tree.png'));