X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_printerPPDDialog.inc;h=516f95ad0ca8a086ab093dca5d996d459426a1bb;hb=6a798c99f3cd57b6e98610975ac80dcd7e094a90;hp=1b4c5a39633a788f0332102f7eb8e8cfa0cacb11;hpb=b6ee4d1358174708399ca94eb68fde95f06e66c1;p=gosa.git diff --git a/plugins/admin/systems/class_printerPPDDialog.inc b/plugins/admin/systems/class_printerPPDDialog.inc index 1b4c5a396..516f95ad0 100644 --- a/plugins/admin/systems/class_printerPPDDialog.inc +++ b/plugins/admin/systems/class_printerPPDDialog.inc @@ -21,16 +21,61 @@ class printerPPDDialog extends plugin var $ppdManager = false; // new ppdManager; var $ppdConfig = false; // $this->ppdManager->loadProperties($this->selectedPPD['link']); + var $pathToPPD = ""; + function printerPPDDialog ($config, $dn= NULL,$ppdfile=NULL ) { plugin::plugin ($config, $dn); $this->depselect = $this->config->current['BASE']; - /* Load all available PPD files and sort them into an array - */ - require_once ("class_ppdManager.inc"); - $this->ppdManager= new ppdManager('/var/spool/ppd/'); - $tmp = $this->ppdManager->getPrinterList(); + if(isset($_SESSION['config']->data['MAIN']['PPD_PATH'])){ + $this->pathToPPD = $_SESSION['config']->data['MAIN']['PPD_PATH']; + $this->pathToPPD= preg_replace("/\/*$/", "/", $this->pathToPPD); + }else{ + $this->pathToPPD = ""; + } + + if(!((!is_dir($this->pathToPPD))||(empty($this->pathToPPD)))){ + + /* Load all available PPD files and sort them into an array + */ + require_once ("class_ppdManager.inc"); + $this->ppdManager= new ppdManager($this->pathToPPD); + $tmp = $this->ppdManager->getPrinterList(); + + /* Sort all available files, and create header (Vendor index) */ + foreach($tmp as $file=>$ppd){ + $tmp2 = split("\n",$ppd); + if(!isset($this->ppdListHeader[$tmp2[0]])){ + $this->ppdListHeader[$tmp2[0]]=0; + } + $tmp3['name'] =preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2]); + $tmp3['link'] =preg_replace("/".str_replace("/","\/",$this->pathToPPD)."/i","",$file); + $tmp3['ppd'] =$ppd; + $this->ppdListHeader[$tmp2[0]]++; + $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3; + } + + /* The user has already a valid PPD assigned + * Get some informations about this PPD + */ + if(($ppdfile!= NULL)&&(strlen($ppdfile)>0)){ + if(!file_exists($this->pathToPPD.$ppdfile)){ + print_red(sprintf(_("Can't open '%s', ppd settings resetted."),$ppdfile)); + }else{ + $tmp2= split("\n", $this->ppdManager->loadDescription($this->pathToPPD.$ppdfile)); + $tmp3['name'] =preg_replace("/^ -/","",$tmp2[1]); + $tmp3['link'] =$ppdfile; + $tmp3['ppd'] =$this->ppdManager->loadDescription($this->pathToPPD.$ppdfile); + $this->selectedPPD = $tmp3; + } + } + } + } + + function getPrinterReload() + { + $tmp = $this->ppdManager->getPrinterList(true); /* Sort all available files, and create header (Vendor index) */ foreach($tmp as $file=>$ppd){ @@ -45,67 +90,144 @@ class printerPPDDialog extends plugin $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3; } - /* The user has already a valid PPD assigned - * Get some informations about this PPD - */ - if(($ppdfile!= NULL)&&(strlen($ppdfile)>0)){ - $tmp2= split("\n", $this->ppdManager->loadDescription($ppdfile)); - $tmp3['name'] =preg_replace("/^ -/","",$tmp2[1]); - $tmp3['link'] =$ppdfile; - $tmp3['ppd'] =$this->ppdManager->loadDescription($ppdfile); - $this->selectedPPD = $tmp3; - } - - } function execute() { + /* Call parent execute */ + plugin::execute(); + /* Fill templating stuff */ $smarty= get_smarty(); $display= ""; + if((!is_dir($this->pathToPPD))||(empty($this->pathToPPD))){ + print_red(sprintf(_("The specified PPD_PATH='%s' in your gosa.conf is invalid, can't read any ppd informations."),$this->pathToPPD)); + $smarty->assign("ppdString", _("Can't get ppd informations.")); + $smarty->assign("showOptions", ""); + }else{ + + + /* Is there a new PPD file uploaded ? */ + if((isset($_FILES['NewPPDFile']))&&(isset($_POST['SubmitNewPPDFile']))){ + $file = ($_FILES['NewPPDFile']); + if($file['size'] != 0 ){ + $res = @$this->ppdManager->loadDescription($file['tmp_name']); + $name = (trim(preg_replace("/-/","",$res))); + if(!empty($name)){ + $vendor = trim(preg_replace("/-.*$/i","",$res)); + $model = trim(preg_replace("/".$vendor."/","",$name)); + if(!is_dir($this->pathToPPD.$vendor)){ + if(!(@mkdir($this->pathToPPD.$vendor))){ + print_red(sprintf(_("Can't create folder '%s' for the uploaded ppd file."),$vendor)); + } + } - /* Open a dialog that allow us to select different PPDs - */ - if(isset($_POST['SelectPPD'])){ - $this->dialog= new printerPPDSelectionDialog($this->config,$this->dn,$this->ppdList,$this->ppdListHeader,$this->selectedPPD); - } + if(!isset($this->ppdList[$vendor])){ + $this->ppdList[$vendor] = array(); + } - /* The selection dialog fpr PPDs is canceled - */ - if(isset($_POST['ClosePPDSelection'])){ - unset($this->dialog); - $this->dialog=NULL; - } - - /* A new PPDs was selected in the PPDs selection Dialog - * Perform a Check. If everything is fine, use the new PPD. - */ - if(isset($_POST['SavePPDSelection'])){ - if(count($this->dialog->check())>0){ - foreach($this->dialog->check() as $msg){ - print_red($msg); + if(is_dir($this->pathToPPD.$vendor)){ + $found = false; + foreach($this->ppdList[$vendor] as $key => $val){ + if(preg_match("/".$model.".*/i",$key)){ + $found = true; + print_red(sprintf(_("There is already a ppd file for this kind of printer."))); + } + }// Foreach + if(!$found){ + $ppdname = $vendor."/".$vendor."-".preg_replace("/^[^ ]/","",str_replace("-","",$model)).".ppd"; + $filename = $this->pathToPPD.$vendor."/".$vendor."-".preg_replace("/^[^ ]/","",str_replace("-","",$model)).".ppd"; + $fp = @fopen($filename,"w+"); + if(!$fp){ + print_red(sprintf(_("Can't save file '%s'."),$filename)); + }else{ + $str = file_get_contents($file['tmp_name']); + fputs($fp,$str); + @fclose($fp); + + $tmp2= split("\n", $res); + $tmp3['name'] =preg_replace("/^ -/","",$tmp2[1]); + $tmp3['link'] =$ppdname; + $tmp3['ppd'] =$res; + + print_a($tmp3); + + $this->selectedPPD = $tmp3; + $this->getPrinterReload(); + } + } + }// If dir + }else{ + print_red(_("Please specify a valid ppd file.")); + } + }else{ + print_red(_("Please specify a valid ppd file.")); } - }else{ - $this->selectedPPD = $this->dialog->save(); - $this->ppdConfig = false; + + } + + + /* Open a dialog that allow us to select different PPDs + */ + if(isset($_POST['SelectPPD'])){ + $this->dialog= new printerPPDSelectionDialog($this->config,$this->dn,$this->ppdList,$this->ppdListHeader,$this->selectedPPD); + } + + /* The selection dialog fpr PPDs is canceled + */ + if(isset($_POST['ClosePPDSelection'])){ unset($this->dialog); $this->dialog=NULL; } - } - - /* if a dialog is open, print the dialog instead of this class - */ - if($this->dialog!=NULL){ - $display = $this->dialog->execute(); - return($display); - } - /* Give smarty the information it needs */ - $smarty->assign("ppdString" ,$this->getPPDInformation()); - $smarty->assign("properties",$this->generateProperties()); - + /* A new PPDs was selected in the PPDs selection Dialog + * Perform a Check. If everything is fine, use the new PPD. + */ + if(isset($_POST['SavePPDSelection'])){ + if(!isset($_POST['PPDselection'])){ + print_red(_("Please select a valid ppd.")); + }else{ + $this->selectedPPD['link'] = $_POST['PPDselection']; + $this->ppdConfig = false; + unset($this->dialog); + $this->dialog=NULL; + } + } + + /* Div Selection */ + if((isset($_GET['act']))&&($_GET['act']=="use")){ + $hit = false; + foreach($this->ppdList as $vendor => $ppds ){ + foreach($ppds as $name => $ppd){ + if($ppd['link']==$_GET['id']){ + $hit = true; + } + } + } + $this->selectedPPD['link'] = $_GET['id']; + $this->ppdConfig = false; + unset($this->dialog); + $this->dialog=NULL; + } + + /* if a dialog is open, print the dialog instead of this class + */ + if($this->dialog!=NULL){ + $display = $this->dialog->execute(); + return($display); + } + + /* Give smarty the information it needs */ + $smarty->assign("ppdString" ,$this->getPPDInformation()); + $tmp= $this->generateProperties(); + if ($tmp == ""){ + $smarty->assign("showOptions", 0); + } else { + $smarty->assign("showOptions", 1); + $smarty->assign("properties",$this->generateProperties()); + } + } /* Print out template */ $display.= $smarty->fetch(get_template_path('printerPPDDialog.tpl', TRUE,dirname(__FILE__))); return($display); @@ -121,10 +243,12 @@ class printerPPDDialog extends plugin function save_object() { if(isset($_POST['PPDDisSubmitted'])){ - foreach($this->ppdConfig as $cat => $obj){ - foreach($obj as $attr => $attributes){ - if(isset($_POST[base64_encode($attributes['_name'])])){ - $this->ppdConfig[$cat][$attr]['_default'] = $_POST[base64_encode($attributes['_name'])]; + if(is_array($this->ppdConfig)){ + foreach($this->ppdConfig as $cat => $obj){ + foreach($obj as $attr => $attributes){ + if(isset($_POST[base64_encode($attributes['_name'])])){ + $this->ppdConfig[$cat][$attr]['_default'] = $_POST[base64_encode($attributes['_name'])]; + } } } } @@ -132,11 +256,14 @@ class printerPPDDialog extends plugin } + function save_ppd(){ + $this->ppdManager->saveProperties($this->pathToPPD.$this->selectedPPD['link'],$this->ppdConfig); + } + /* Save to LDAP */ function save() { /* return the selected PPD, and in future the selected options too */ - $this->ppdManager->saveProperties($this->selectedPPD['link'],$this->ppdConfig); return($this->selectedPPD['link']); } @@ -147,8 +274,7 @@ class printerPPDDialog extends plugin */ $str = "none"; if(!empty($this->selectedPPD)){ - $str = $this->selectedPPD['link']; - $str = $this->ppdManager->loadDescription($this->selectedPPD['link']); + $str = $this->ppdManager->loadDescription($this->pathToPPD.$this->selectedPPD['link']); } return($str) ; } @@ -158,52 +284,57 @@ class printerPPDDialog extends plugin /* In future there will be a schema parser that provide us all settings that can be made in the selected PPD file. * This function will generate a userfriendly post based form with this informations */ - - $HeadLine = "
"; - $str .= "".$cat." "; + $str .= " | |
$feed";
+ if ($feed == ""){
+ $feed= " "; + } + $str .= ""._("Section")." '".$cat."' "; $str .= " | |
\n"; + $str .= " | |
\n";
$str .= $name." \n"; $str .= " | \n"; - + /* Get all values */ foreach( $settings as $vname => $value){ if($vname[0] != "_"){ - $values[$vname]= $vname; + $values[$vname]= $value; } } @@ -238,7 +369,7 @@ class printerPPDDialog extends plugin $str .= "\n"; }else{ - print_red(sprintf(_("Unsupported PPD type '%s' used for '%s' "),$type,$name)); + print_red(sprintf(_("Unsupported ppd type '%s' used for '%s' "),$type,$name)); } $str .= " |