diff --git a/plugins/admin/systems/class_printerPPDDialog.inc b/plugins/admin/systems/class_printerPPDDialog.inc
index 11545d4b4c83dc730267b24a0537e938236506d6..a93e91bb4e56ad2a40d99cafcc41e6827d0e57c3 100644 (file)
/* Object Info */
var $cn = "" ; // Used to tag the ppds modified by the printer object,
+ /* 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
+ * to overwrite the current ppd file.
+ */
+ var $add_ppd_later = "";
+ var $add_later_msg_dialog = NULL;
+
function printerPPDDialog (&$config, $dn= NULL, $ppdfile=NULL )
{
plugin::plugin ($config, $dn);
}
}
+ /* Overwrite existing PPD file and select it as currently used for this object */
+ if(is_object($this->add_later_msg_dialog) && ($this->add_later_msg_dialog->is_confirmed()) && $this->add_ppd_later != ""){
+ if($name = $this->AddPPD($this->add_ppd_later,TRUE)){
+ $this->SelectPPD($name);
+ }
+ $this->add_ppd_later = "";
+ $this->add_later_msg_dialog = NULL;
+ }
+
/* 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);
/* This function adds a new ppd file to the list of available ppds.
All required paths and files will be created
$_PathOnHdd e.g. = /tmp/PHP_tmpfile213452 */
- function AddPPD($_PathOnHdd)
+ function AddPPD($_PathOnHdd,$overwrite = FALSE)
{
/* Check if file exists && is readable */
if((!is_file($_PathOnHdd)) || (!is_readable($_PathOnHdd))){
$this->ppdList[$vendor] = array();
}
+ /* Create ppd file and fill in the source contents */
+ $ppdname = $vendor."/".$name.".ppd";
+ $filename = $this->pathToPPD.preg_replace("/[^a-z0-9-_\.\/]/i","_",$ppdname);
+ $filename = $this->pathToPPD.$ppdname;
+ $contents = file_get_contents($_PathOnHdd);
+
+
/* Check if this ppd already exists */
$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.")));
- return;
+ if(!$overwrite){
+ if(!copy($_PathOnHdd,$_PathOnHdd."_back")){
+ print_red(sprintf(_("Can't add new ppd file, the source file '%s' is not accessible."),$_PathOnHdd));
+ }else{
+ $this->add_ppd_later = $_PathOnHdd."_back";
+ $this->add_later_msg_dialog = new msg_dialog(_("Overwrite existing PPD"),
+ _("There is already a ppd file for this kind of printer. Do you want to overwrite it?"),CONFIRM_DIALOG);
+ }
+ return;
+ }
}
}
}
}
- /* Create ppd file and fill in the source contents */
- $ppdname = $vendor."/".$name.".ppd";
- $filename = $this->pathToPPD.$ppdname;
+ /* Open file handle */
$fp = fopen($filename,"w+");
- $contents = file_get_contents($_PathOnHdd);
/* Check file handle & contents */
if(!$fp){
function getPrinterReload()
{
if(is_readable($this->pathToPPD)){
- $tmp = $this->ppdManager->getPrinterList(true);
+ $tmp = @$this->ppdManager->getPrinterList(true);
$this->ppdListHeader = $this->ppdList = array();
/* Save modified ppd */
- function save_ppd(){
+ function save_ppd()
+ {
if($this->ppdManager){
$this->ppdManager->saveProperties($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link'],$this->ppdConfig);
}
print_red(sprintf(_("Removing old ppd file '%s' failed. File does not exists or is not accessible."),$path));
}
}
+
+ function update_ppd_url()
+ {
+ $this->SelectPPD("modified/".$this->selectedPPD['link']);
+ }
function check()
{