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 149dc8608b377ece7d070b905b882666bf0ed878..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") != ""){
$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 */
$tmp3['link'] =$file;
$tmp3['ppd'] =$ppd;
$this->ppdListHeader[$ppd['manufacturer']]++;
- $this->ppdList[$ppd['manufacturer']][$ppd['name']]=$tmp3;
+ 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'])];
}
}
}
}
}
- $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";