diff --git a/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc b/trunk/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc
index 2f176e75a93eed251cc7bce270434166127c9ae2..955cc21c4e6c1b7359b457aa7bb212342cdb0ab7 100644 (file)
/* Object Info */
var $cn = "" ; // Used to tag the ppds modified by the printer object,
- var $ui;
/* If there is already a ppd file for the same type of printer,
* remember the path to ppd file and display a dialog which allows
plugin::plugin ($config, $dn);
$this->depselect = $this->config->current['BASE'];
- $this->ui = get_userinfo();
-
/* Get PPD path and remove double //, and add trailing / */
$config = session::get('config');
if($config->get_cfg_value("ppdPath") != ""){
if(!file_exists($this->pathToPPD.$this->pathToModified.$ppdfile)){
msg_dialog::display(_("PPD error"), sprintf(_("Cannot open PPD '%s'!"), $ppdfile), ERROR_DIALOG);
}else{
- $res = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$ppdfile);
- if($res){
- $tmp = split("\n",$res);
- $tmp3 = array();
- $tmp3['name'] = trim(preg_replace("/^\-/","",trim($tmp[1])));
- $tmp3['link'] = $ppdfile;
- $tmp3['ppd'] = $res;
+ $ppdDesc = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$ppdfile);
+ if($ppdDesc){
+ $selectedPPD = array();
+ $selectedPPD['name'] = $ppdDesc['name'];
+ $selectedPPD['link'] = $ppdfile;
+ $selectedPPD['ppd'] = $ppdDesc;
}
- $this->selectedPPD = $tmp3;
+ $this->selectedPPD = $selectedPPD;
}
}
}
$smarty->assign("ppdString", _("Can't get ppd informations."));
$smarty->assign("showOptions", "");
$smarty->assign("path_valid", TRUE);
- $smarty->assign("acl",$this->ui->get_permissions($this->dn,"printer/printgeneric","gotoPrinterPPD"));
-
- $acl = $this->ui->get_permissions($this->dn,"printer/printgeneric","gotoPrinterPPD");
if(empty($this->pathToPPD)){
/* If one of our required paths is not available, stop here and display some info */
foreach($paths as $path){
-
+
/* Check if path is write/readable*/
$is_r = @is_readable($path);
if(((!is_dir($path))||(empty($path)) || (!$is_r)) && (!@mkdir($path))){
- msg_dialog::display(_("Configuration error"),
- sprintf(_("Cannot open PPD path '%s' for reading and writing!"), $path), ERROR_DIALOG);
+ msg_dialog::display(_("Configuration error"), sprintf(_("Cannot open PPD path '%s' for reading and writing!"), $path), ERROR_DIALOG);
/* Print out template */
$display.= $smarty->fetch(get_template_path('printerPPDDialog.tpl', TRUE,dirname(__FILE__)));
// PPD selection / upload / dialog handling
/* Is there a new PPD file uploaded ? */
- if(preg_match("/w/",$acl)){
- if((isset($_FILES['NewPPDFile']))&&(isset($_POST['SubmitNewPPDFile']))){
- $file = ($_FILES['NewPPDFile']);
- if($file['size'] != 0 ){
- if($name = $this->AddPPD($file['tmp_name'])){
- $this->SelectPPD($name);
- }
- }else{
- msg_dialog::display(_("PPD error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG);
+ if((isset($_FILES['NewPPDFile']))&&(isset($_POST['SubmitNewPPDFile']))){
+ $file = ($_FILES['NewPPDFile']);
+ if($file['size'] != 0 ){
+ if($name = $this->AddPPD($file['tmp_name'])){
+ $this->SelectPPD($name);
}
+ }else{
+ msg_dialog::display(_("PPD error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG);
}
}
}
/* Open a dialog that allow us to select different PPDs */
- if(preg_match("/w/",$acl)){
- if(isset($_POST['SelectPPD'])){
- $this->dialog= new printerPPDSelectionDialog($this->config,$this->dn,$this->ppdList,$this->ppdListHeader,$this->selectedPPD);
- }
+ 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 */
msg_dialog::display(_("PPD error"), msgPool::cannotReadFile($AbsoluteSourceName), ERROR_DIALOG);
return;
}
- $res = $this->ppdManager->loadDescription($AbsoluteSourceName);
- if($res){
- $tmp = split("\n",$res);
- $Name = trim(preg_replace("/^\-/","",trim($tmp[1])));
- $Vendor = trim($tmp[0]);
- $Model = trim(preg_replace("/".$Vendor."/","",$Name));
+ $ppdDesc = $this->ppdManager->loadDescription($AbsoluteSourceName);
+ if($ppdDesc){
+ $Name = $ppdDesc['name'];
+ $Vendor = $ppdDesc['manufacturer'];
+ $Model = $ppdDesc['model'];
}
$PrinterName = $this->cn."-".preg_replace("/[^a-z0-9-_\.]/i","_",$Name);
$this->getPrinterReload();
/* Get Description from ppd, & parse out some informations */
- $res = @$this->ppdManager->loadDescription($_PathOnHdd);
- if($res){
- $tmp = split("\n",$res);
- $name = @trim(preg_replace("/^\-/","",trim($tmp[1])));
- $vendor = @trim($tmp[0]);
- $model = @trim(preg_replace("/".$vendor."/","",$name));
+ $ppdDesc = @$this->ppdManager->loadDescription($_PathOnHdd);
+ if($ppdDesc){
+ $name = $ppdDesc['name'];
+ $vendor = $ppdDesc['manufacturer'];
+ $model = $ppdDesc['model'];
}
/* Check if parse was successfull */
/* Sort all available files, and create header (Vendor index) */
foreach($tmp as $file=>$ppd){
-
+
if(preg_match("#".$this->pathToModified."#",$file)) continue;
- $tmp2 = split("\n",$ppd);
- if(!isset($this->ppdListHeader[$tmp2[0]])){
- $this->ppdListHeader[$tmp2[0]]=0;
+ if(!isset($this->ppdListHeader[$ppd['manufacturer']])){
+ $this->ppdListHeader[$ppd['manufacturer']]=0;
}
- $tmp3['name'] =preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2]);
+
+ $tmp3['name'] =$ppd['name'];
$tmp3['link'] =$file;
$tmp3['ppd'] =$ppd;
- $this->ppdListHeader[$tmp2[0]]++;
- $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3;
+ $this->ppdListHeader[$ppd['manufacturer']]++;
+ if (isset($this->ppdList[$ppd['manufacturer']][$ppd['name']])) {
+
+ # Printer exists already, add directory/nickname to identify it
+
+ $tmp4 = $this->ppdList[$ppd['manufacturer']][$ppd['name']]['link'];
+
+ # Remove the default path (e.g. /srv/www/ppd) plus a possible debian/ directory
+ $extension = preg_replace("#".$this->pathToPPD."/(debian/)?#", "", $tmp3['link']);
+
+ # Remove all further directories, just keep the first level (e.g. foomatic-rip, hpijs)
+ $extension = preg_replace("#/.*#", "", $extension);
+
+ # Add the nickname as well to distinguish between two drivers for the same model in one directory
+ $extension = $extension." / ".$ppd['nickname'];
+
+ # Generate the updated extension from the original path and nickname, same way as above
+ $updated_nickname = $this->ppdList[$ppd['manufacturer']][$ppd['name']]['ppd']['nickname'];
+ $updated_extension = preg_replace("#".$this->pathToPPD."/(debian/)?#", "", $tmp4);
+ $updated_extension = preg_replace("#/.*#", "", $updated_extension);
+ $updated_extension = $updated_extension." / ".$updated_nickname;
+ $updated_name = $ppd['name']." ($updated_extension)";
+
+ if (!isset($this->ppdList[$ppd['manufacturer']][$updated_name]['name'])) {
+ $old_ppd = array_keys($this->ppdList[$ppd['manufacturer']][$ppd['name']]);
+ # Copy old printer attributes to new name
+ foreach($old_ppd as $entry){
+ $this->ppdList[$ppd['manufacturer']][$updated_name][$entry] = $this->ppdList[$ppd['manufacturer']][$ppd['name']][$entry];
+ }
+
+ # Add old printer under updated name
+ $this->ppdList[$ppd['manufacturer']][$updated_name]['name'] = $updated_name;
+ $this->ppdList[$ppd['manufacturer']][$updated_name]['ppd']['name'] = $ppd['name']." ($updated_extension)";
+ $this->ppdList[$ppd['manufacturer']][$updated_name]['ppd']['model'] = $ppd['model']." ($updated_extension)";
+ }
+
+ # Now generate name/model including extension for new printer
+ $tmp3['ppd']['name'] = $tmp3['name']." ($extension)";
+ $tmp3['ppd']['model'] = $tmp3['ppd']['model']." ($extension)";
+ $tmp3['name'] = $tmp3['name']." ($extension)";
+ $myname = $tmp3['name'];
+ }
+ $this->ppdList[$ppd['manufacturer']][$tmp3['name']]=$tmp3;
+ }
+
+ # Remove all non-nicknamed/directorized printers from list who have a
+ # nicknamed counterpart already, those are dupes.
+ foreach($this->ppdList as $manufacturer => $printers) {
+ foreach($printers as $ppd) {
+ $to_remove = preg_replace("/ \(.*\)$/", "", $ppd['name']);
+ if ($to_remove != $ppd['name'] && isset($this->ppdList[$manufacturer][$to_remove])) {
+ unset($this->ppdList[$manufacturer][$to_remove]);
+ }
+ }
}
}
}
return;
}
- if(preg_match("/w/",$this->ui->get_permissions($this->dn,"printer/printgeneric","gotoPrinterPPD"))){
- 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'])];
- }
+ 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'])];
}
}
}
{
$str = "none";
if(!empty($this->selectedPPD)){
- $str = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']);
+ $ppdDesc = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']);
+ $str = $ppdDesc['name'];
}
return($str) ;
}
-
/* Display all options from the selected ppd file */
function generateProperties()
{
}
}
- $acl ="";
- if(!preg_match("/w/",$this->ui->get_permissions($this->dn,"printer/printgeneric","gotoPrinterPPD"))){
- $acl = "disabled";
- }
-
/* preparing Html output
* Supported types are PickOne/Boolean
*/
/* If type is PickOne, create a select box */
if(($type == "PickOne")||(($type=="Boolean")&&(count($values)>1))){
- $str .= "<select name='".base64_encode($name)."' $acl >\n";
+ $str .= "<select name='".base64_encode($name)."'>\n";
foreach($values as $optionKey => $value){
$selected = "";
if($optionKey == $default){
}elseif($type == "Boolean"){
/* If type is Boolean & no values are given */
- $str .= "<select name='".base64_encode($name)."' $acl>\n";
+ $str .= "<select name='".base64_encode($name)."'>\n";
if($default == "False"){
$str .= "<option value='True' >"._("True")."</option>\n";
$str .= "<option value='False' selected>"._("False")."</option>\n";