From: cajus Date: Thu, 17 Jan 2008 13:34:19 +0000 (+0000) Subject: Moved ppd to goto X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=72aec8fbb33d2cc8abea3764313ed0f30d5733cd;p=gosa.git Moved ppd to goto git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8453 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/plugins/admin/systems/ppd/class_ppdManager.inc b/gosa-core/plugins/admin/systems/ppd/class_ppdManager.inc deleted file mode 100644 index 06996b18e..000000000 --- a/gosa-core/plugins/admin/systems/ppd/class_ppdManager.inc +++ /dev/null @@ -1,356 +0,0 @@ -path= $path; - }else{ - msg_dialog::display(_("PPD manager error"), sprintf(_("The specified path '%s' does not exist."),$path), ERROR_DIALOG); - return (false); - } - } - - - function findPPD($path) - { - $list= array(); - $currentDir= getcwd(); - - $dh = opendir($path); - while(false !== ($file = readdir($dh))){ - - /* Skip well known files */ - if( $file == '.' || $file == '..'){ - continue; - } - - /* Recurse through all "common" directories */ - if(is_dir($path.'/'.$file)){ - $list= array_merge($list, $this->findPPD($path.'/'.$file)); - continue; - } - - /* Check for PPD extension */ - if (preg_match('/\.ppd$/i', $file)){ - $list[]= $path.'/'.$file; - } - } - - closedir($dh); - chdir ($currentDir); - return ($list); - } - - - function updateAttribute($file, $section, $attribute, $value) - { - $fsection= false; - $fattribute= false; - $section= preg_replace('/^\*/', '', $section); - $attribute= preg_replace('/^\*/', '', $attribute); - - $rp= @fopen($file, "r"); - $wp= @fopen("$file.tmp", "w"); - - - - while (!feof($rp)){ - $lines[]= fgets($rp, 1024); - } - - $ret = ""; - $done =false; - foreach($lines as $nr => $line){ - - if (preg_match("/\*OpenGroup:*\s+\**$section\/*/", $line)){ - $fsection= true; - $ret .=$line; - continue; - } - - /* Change model name .. */ - if ((preg_match("/^\*".$attribute.":*\s+/",$line)) && ($attribute == "ModelName")){ - $line= "*$attribute: \"$value\"\n"; - $done =true; - } - - if (($fsection) && ($section != "NO_SECTION")){ - if (preg_match("/^\*CloseGroup:*\s+\**$section\/*/", $line)){ - $fsection= false; - $ret .=$line; - continue; - } - - - if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){ - $fattribute= true; - $ret .= $line; - continue; - } - - if ($fattribute){ - if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){ - $fattribute= false; - $ret .= $line; - continue; - } - - if (preg_match("/^\*Default$attribute:*\s+/", $line)){ - $line= "*Default$attribute: $value\n"; - $done =true; - } - } - }else{ - if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){ - $fattribute= true; - $ret .= $line; - continue; - } - - if ($fattribute){ - if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){ - $fattribute= false; - $ret .= $line; - continue; - } - - if (preg_match("/^\*Default$attribute:*\s+/", $line)){ - $line= "*Default$attribute: $value\n"; - $done =true; - } - } - } - $ret .=$line; - } - - fwrite($wp,$ret); - - fclose($wp); - fclose($rp); - - copy("$file.tmp", "$file"); - unlink("$file.tmp"); - } - - - function saveProperties($ppdFile, $properties) - { - if(!is_readable($ppdFile)){ - msg_dialog::display(_("PPD manager error"), sprintf(_("Specified PPD file '%s' cannot be opened for reading."),$ppdFile), ERROR_DIALOG); - }elseif(!is_writeable(preg_replace("#(^.*/).*$#","\\1",$ppdFile.".tmp"))){ - msg_dialog::display(_("PPD manager error"), sprintf(_("The temporary file '%s' cannot be opened for writing."),$ppdFile.".tmp"), ERROR_DIALOG); - }else{ - foreach ($properties as $name => $section){ - foreach ($section as $attribute => $value){ - if (is_array($value)){ - $this->updateAttribute($ppdFile, $name, $attribute, $value['_default']); - } - } - } - } - } - - function loadProperties($ppdFile) - { - $group= ""; - $option= ""; - $properties= array(); - - $fh= fopen ($ppdFile, 'r'); - while (!feof($fh)) { - - /* Read line */ - $line= fgets($fh, 256); - if (strlen($line) >= 256){ - trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING); - } - - /* Trigger for option groups */ - if (preg_match('/^\*OpenGroup:/i', $line)){ - - /* Sanity checks */ - if ($group != ""){ - trigger_error(_('Nested groups are not supported!'), E_USER_WARNING); - continue; - } - if (in_array($group, $properties)){ - trigger_error(_('Group name not unique!'), E_USER_WARNING); - continue; - } - - // TODO: Symbol values are not supported yet! - if (preg_match('/\^/', $line)){ - trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING); - } - $complete= preg_replace('@^\*OpenGroup:\s+(.*)$@i', '\1', $line); - $complete= trim($complete, '"'); - if (preg_match('@/@', $complete)){ - $group= trim(preg_replace('@^\*OpenGroup:\s+"?([^/]+)/.*$@i', '\1', $line)); - $name = preg_replace('@^\*OpenGroup:\s+"?[^/]+/([^/]+).*$@i', '\1', $line); - } else { - $group= $complete; - $name = $complete; - } - $properties[$group]= array('_name' => $name); - continue; - } - if (preg_match("/^\*CloseGroup:\s+\"?$group\"?/i", $line)){ - $group= ""; - continue; - } - - /* Trigger for options */ - if (preg_match('/^\*OpenUI\s+/i', $line)){ - - /* Sanity check */ - if ($option != ""){ - trigger_error(_('Nested options are not supported!'), E_USER_WARNING); - continue; - } - - // TODO: Symbol values are not supported yet! - if (preg_match('/\^/', $line)){ - trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING); - } - $complete= preg_replace('@^\*OpenUI\s+(.*)$@i', '\1', $line); - $complete= trim($complete, '"'); - if (preg_match('@/@', $complete)){ - $option= trim(preg_replace('@^\*OpenUI\s+([^/]+)/.*$@i', '\1', $line)); - $name = trim(preg_replace('@^\*OpenUI\s+[^/]+/([^/]+).*$@i', '\1', $line)); - } else { - $option= trim($complete); - $name = trim($complete); - } - - /* Extract option type */ - $type= trim(preg_replace('/^[^:]+:\s+/', '', $line)); - $name= preg_replace('/:.*$/', '', $name); - $option= preg_replace('/:.*$/', '', $option); - - // TODO: PickMany is not supported yet! - if (preg_match('/PickMany/i', $type)){ - trigger_error(_('PickMany is not supported yet!'), E_USER_WARNING); - } - if(empty($group)){ - $properties["NO_SECTION"][$option]= array('_name' => $name, '_type' => $type); - }else{ - $properties[$group][$option]= array('_name' => $name, '_type' => $type); - } - continue; - } - /* Show interest for option parsing */ - if ($option != ""){ - - $eoption= preg_replace('@\*@', '', $option); - - /* Close section? */ - if (preg_match("@^\*CloseUI:\s+\*$eoption@i", $line)){ - $option= ""; - continue; - } - - /* Default value? */ - if (preg_match("@^\*Default$eoption:@", $line)){ - $c= preg_replace("@^\*Default$eoption:\s+@", "", $line); - if(empty($group)){ - $properties["NO_SECTION"][$option]['_default']= trim(trim($c, '"')); - }else{ - $properties[$group][$option]['_default']= trim(trim($c, '"')); - } - continue; - } - - /* Possible value? */ - if (preg_match("@^\*$eoption\s+@", $line)){ -#*PageSize Letter/US Letter: "<>setpagedevice" - $c= preg_replace("@^\*$eoption\s+([^/]+).*$@", "$1", $line); - $d= preg_replace("@^\*$eoption\s+[^/]+/([^:]+).*$@", "$1", $line); - if(empty($group)){ - $properties["NO_SECTION"][$option][trim($c)]= trim($d); - }else{ - $properties[$group][$option][trim($c)]= trim($d); - } - continue; - } - } - } - fclose ($fh); - return ($properties); - } - - function loadDescription($ppdFile) - { - $model= ""; - $manufacturer= ""; - - - /* Only parse complete PPD file again, if it was changed */ - $modified = filemtime($ppdFile); - if(isset($this->cachedList[$ppdFile]) && isset($this->timestamps[$ppdFile]) && $modified == $this->timestamps[$ppdFile]){ - return($this->cachedList[$ppdFile]); - } - - /* Remember modified timestamp, to speed up next request */ - $this->timestamps[$ppdFile] = filemtime($ppdFile); - - $fh= fopen ($ppdFile, 'r'); - while ((!feof($fh))&&($fh)) { - - /* Read line */ - $line= fgets($fh, 256); - if (strlen($line) >= 256){ - trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING); - } - - /* Extract interesting informations */ - if (preg_match('/^\*Manufacturer:/i', $line)){ - $manufacturer= preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line); - } - if (preg_match('/^\*ModelName:/i', $line)){ - $model= preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line); - } - - /* Got everything we need? Skip rest for speed reasons... */ - if ($model != '' && $manufacturer != ''){ - break; - } - } - fclose ($fh); - - /* Write out a notice that the PPD file seems to be broken if we can't - extract any usefull informations */ - if ($model == '' || $manufacturer == ''){ - trigger_error(sprintf(_('Parsing PPD file %s failed - no information found.'), $ppdFile), E_USER_WARNING); - } - - return ($manufacturer.' - '.$model); - } - - - function getPrinterList($reload= false) - { - /* Load list of PPD files */ - if (count($this->cachedList) == 0 || $reload){ - $list= $this->findPPD($this->path); - - /* Load descriptive informations to build final printer list */ - $new = array(); - foreach ($list as $ppdFile){ - $new[$ppdFile] = $this->loadDescription($ppdFile); - } - $this->cachedList= $new ; - - } - - return ($this->cachedList); - } - -} - -?> diff --git a/gosa-core/plugins/admin/systems/ppd/class_printerPPDDialog.inc b/gosa-core/plugins/admin/systems/ppd/class_printerPPDDialog.inc deleted file mode 100644 index 49f668180..000000000 --- a/gosa-core/plugins/admin/systems/ppd/class_printerPPDDialog.inc +++ /dev/null @@ -1,547 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account = TRUE; - var $attributes = array("cn"); - var $objectclasses = array("whatever"); - - /* PPD Handling */ - var $selectedPPD = false; // e.g. /vendor/device.ppd - var $ppdManager = false; // new ppdManager; - var $ppdConfig = false; // $this->ppdManager->loadProperties($this->selectedPPD['link']); - var $ppdList = array(); // Contains all Printer models - var $ppdListHeader = array(); // Contains all printer vendors - - /* Paths */ - var $pathToPPD = ""; // Base path, defined in gosa.conf e.g. "/var/spool/ppd/" - var $pathToModified = "modified/"; // used to store the modified ppds - - /* 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); - $this->depselect = $this->config->current['BASE']; - - /* Get PPD path and remove double //, and add trailing / */ - $config = session::get('config'); - if(isset($config->data['MAIN']['PPD_PATH'])){ - $this->pathToPPD = $config->data['MAIN']['PPD_PATH']; - $this->pathToPPD= preg_replace("/\/\//", "/", $this->pathToPPD); - if(!preg_match("/\/$/",$this->pathToPPD)){ - $this->pathToPPD = $this->pathToPPD."/"; - } - }else{ - $this->pathToPPD = ""; - } - - /* It seams that we have an existing PPD path, so go on */ - if(!((!is_dir($this->pathToPPD))||(empty($this->pathToPPD)))){ - - /* Load all available PPD files and sort them into an array */ - $this->ppdManager= new ppdManager($this->pathToPPD); - $this->getPrinterReload (); - - /* The user has already a valid PPD assigned - * Get some informations about this PPD - * and set it as selected. - * The ppdpath ['link'] should be relative from .../ppd/modified/ - * e.g. "/Compaq/Compaq-J1200.ppd" */ - if(($ppdfile!== NULL)&&(strlen($ppdfile)>0)){ - $ppdfile = preg_replace("#".$this->pathToModified."#","",$ppdfile); - if(!file_exists($this->pathToPPD.$this->pathToModified.$ppdfile)){ - print_red(sprintf(_("Can't open '%s', ppd settings resetted."),$ppdfile)); - }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; - } - $this->selectedPPD = $tmp3; - } - } - } - } - - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $display= ""; - $smarty= get_smarty(); - $smarty->assign("ppdString", _("Can't get ppd informations.")); - $smarty->assign("showOptions", ""); - - /* Check these paths */ - $paths = array($this->pathToPPD, $this->pathToPPD.$this->pathToModified); - - /* 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))){ - print_red(sprintf(_("The specified path '%s' which results from PPD_PATH in your gosa.conf is invalid, can't read/write any ppd informations."),$path)); - /* Print out template */ - $display.= $smarty->fetch(get_template_path('printerPPDDialog.tpl', TRUE,dirname(__FILE__))); - return($display); - } - } - - // PPD selection / upload / dialog handling - - /* Is there a new PPD file uploaded ? */ - 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{ - print_red(_("Please specify a valid ppd file.")); - } - } - - /* 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); - } - - /* The selection dialog fpr PPDs is canceled */ - if(isset($_POST['ClosePPDSelection'])){ - unset($this->dialog); - $this->dialog=FALSE; - } - - /* Div Selection */ - if((isset($_GET['act']))&&($_GET['act']=="use")){ - $this->SelectPPD(base64_decode($_GET['id'])); - unset($this->dialog); - $this->dialog=FALSE; - - } - - /* if a dialog is open, print the dialog instead of this class */ - if(is_object($this->dialog)){ - $display = $this->dialog->execute(); - return($display); - } - - // ENDE PPD selection / upload / dialog handling - - /* 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); - } - - - /* Select PPD */ - function SelectPPD($name) - { - /* Replace base path we don't need it here - The path we need looks like this : "/Vendor/ModellName.ppd"; - thats all */ - $name = preg_replace("#".$this->pathToPPD."#","",$name); - - /* Intialise some base vars */ - $AbsoluteSourceName = $this->pathToPPD.$name; - $AbsoluteDestinationPath = $this->pathToPPD.$this->pathToModified; - $Vendor = ""; // Vendor - $Name = ""; // Name - $Modell = ""; // Modell - $PrinterName = ""; // The new name of the printer - $PPDName = ""; - - /* Force reload of config dialog */ - $this->ppdConfig = false; - $this->selectedPPD['link'] = false; - - /* Get PPD informations and set vendor / modell / name */ - if((!file_exists($AbsoluteSourceName)) || (!is_readable($AbsoluteSourceName))){ - print_red(sprintf(_("Can't select PPD file '%s', the file is not readable"),$AbsoluteSourceName)); - 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)); - } - - $PrinterName = $this->cn."-".preg_replace("/[^a-z0-9-_\.]/i","_",$Name); - $PPDName = $Vendor."/".$PrinterName.".ppd"; - - /* Create the vendors path, if it doesn't exists already */ - if(!is_dir($AbsoluteDestinationPath.$Vendor)){ - if(!(@mkdir($AbsoluteDestinationPath.$Vendor))){ - print_red(sprintf(_("Can't create folder '%s' for the uploaded ppd file."),$AbsoluteDestinationPath.$Vendor)); - return(false); - } - } - - /* Create destination file handle */ - $fp = @fopen($AbsoluteDestinationPath.$PPDName,"w+"); - if(!$fp){ - print_red(sprintf(_("Can't create file '%s' to store modifed ppd informations."),$AbsoluteDestinationPath.$PPDName)); - return(false); - } - - $str = file_get_contents($AbsoluteSourceName); - fputs($fp,$str); - @fclose($fp); - - //$this->ppdManager->updateAttribute($filename,"NO_SECTION","ModelName",$printerName); - - $tmp3['link'] =$PPDName; - $this->selectedPPD = $tmp3; - $this->getPrinterReload(); - return($PPDName); - } - - - /* 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,$overwrite = FALSE) - { - /* Check if file exists && is readable */ - if((!is_file($_PathOnHdd)) || (!is_readable($_PathOnHdd))){ - print_red(sprintf(_("Can't add new ppd file, the source file '%s' is not accessible."),$_PathOnHdd)); - return(false); - } - - /* Reload list to detect changes e.g. a file has been deleted */ - $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)); - } - - /* Check if parse was successfull */ - if(empty($name) || empty($vendor)){ - print_red(sprintf(_("The given ppd file '%s' seams to be invalid, can't get any model or vendor informations."),$_PathOnHdd)); - return(false); - } - - /* Prepare list of ppds */ - if(!isset($this->ppdList[$vendor])){ - $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; - 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 the vendors path, if it doesn't exists already */ - if(!is_dir($this->pathToPPD.$vendor)){ - if(!(@mkdir($this->pathToPPD.$vendor))){ - print_red(sprintf(_("Can't create folder '%s' for the uploaded ppd file."),$this->pathToPPD.$vendor)); - return(false); - } - } - - /* Open file handle */ - $fp = fopen($filename,"w+"); - - /* Check file handle & contents */ - if(!$fp){ - print_red(sprintf(_("Can't save file '%s'."),$filename)); - return; - } - if(empty($contents)){ - print_red(_("Uploaded ppd file is empty, can't create new ppd file.")); - return; - } - - /* Fille file with data */ - fputs($fp,$contents); - @fclose($fp); - - /* Our job is done here */ - return($ppdname); - } - - - /* This function reloads the list of available printers/vendors - $this->ppdListHeader - Compaq => 1 - $this->ppdList - Compaq => Compaq IJ1200 => name => Compaq IJ1200 - link => /var/spool/ppd/Compaq/Compaq-J1200.ppd - ppd => Compaq - Co - */ - function getPrinterReload() - { - if(is_readable($this->pathToPPD)){ - $tmp = @$this->ppdManager->getPrinterList(true); - - $this->ppdListHeader = $this->ppdList = array(); - - /* 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; - } - $tmp3['name'] =preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2]); - $tmp3['link'] =$file; - $tmp3['ppd'] =$ppd; - $this->ppdListHeader[$tmp2[0]]++; - $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3; - } - } - } - - - /* Save all options posted from ppd dialog */ - function save_object() - { - if(!((isset($_POST['PPDDisSubmitted'])) && (is_array($this->ppdConfig)))){ - return; - } - - 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'])]; - } - } - } - } - - - /* Save modified ppd */ - function save_ppd() - { - if($this->ppdManager){ - $this->ppdManager->saveProperties($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link'],$this->ppdConfig); - } - } - - - /* Return selected ppd path, if none is selected then false */ - function save() - { - /* return the selected PPD, and in future the selected options too */ - return($this->pathToModified.$this->selectedPPD['link']); - } - - - /* Get Information for a single PPD entry - * This will be shown on top of template - */ - function getPPDInformation() - { - $str = "none"; - if(!empty($this->selectedPPD)){ - $str = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']); - } - return($str) ; - } - - - /* Display all options from the selected ppd file */ - function generateProperties() - { - /* Set Headline */ - $str = ""; - $feed= ""; - - $s_ppd = $this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']; - - /* If ppd exists and is readable */ - if((!empty($this->selectedPPD['link']))&&(file_exists($s_ppd))){ - - /* If there is no initial Configuration, load it */ - if($this->ppdConfig == false){ - $this->ppdConfig = $this->ppdManager->loadProperties($s_ppd); - } - - /* Create a table */ - $str .= "
"; - - /* Input all data to the table */ - foreach($this->ppdConfig as $cat => $obj){ - - /* Add new category */ - $str .= ""; - - /* Add attributes of the current category */ - foreach($obj as $attr => $settings){ - - /* Skip all entries beginning with _ */ - if($attr[0] == "_") continue; - - /* Prepare data */ - $values = array(); - $name = $settings['_name']; - - if (!isset($settings['_default'])){ - $default = ""; - } else { - $default = $settings['_default']; - } - - $type = $settings['_type']; - - /* Add name to table */ - $str .= "\n"; - } - } - $str .= "
$feed"; - if ($feed == ""){ - $feed= "
"; - } - $str .= ""._("Section")." '".$cat."' 
"; - $str .= "
\n"; - $str .= $name."
\n"; - $str .= "
\n"; - - /* Get all values */ - foreach( $settings as $vname => $value){ - if($vname[0] != "_"){ - $values[$vname]= $value; - } - } - - /* 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 .= "\n"; - - }elseif($type == "Boolean"){ - - /* If type is Boolean & no values are given */ - $str .= "\n"; - - }else{ - print_red(sprintf(_("Unsupported ppd type '%s' used for '%s' "),$type,$name)); - } - $str .= "
\n"; - } - return($str); - } - - function removeModifiedPPD() - { - $path = $this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']; - - if(file_exists($path)){ - if(is_writeable($path)){ - if(!@unlink($path)){ - print_red(sprintf(_("Removing old ppd file '%s' failed."),$path)); - } - }else{ - print_red(sprintf(_("Removing old ppd file '%s' failed. File is not accessible."),$path)); - } - }else{ - 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() - { - $message = plugin::check(); - if(empty($this->selectedPPD['link'])){ - $message[] = _("Please select a valid ppd file or use 'Cancel' to go back to printer configuration."); - } - return($message); - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/systems/ppd/class_printerPPDSelectionDialog.inc b/gosa-core/plugins/admin/systems/ppd/class_printerPPDSelectionDialog.inc deleted file mode 100644 index ee5813062..000000000 --- a/gosa-core/plugins/admin/systems/ppd/class_printerPPDSelectionDialog.inc +++ /dev/null @@ -1,199 +0,0 @@ - "Eins ist toll", "zwei" => "Zwei ist noch besser"); - - /* attribute list for save action */ - var $ignore_account = FALSE; - var $attributes = array(); - var $objectclasses = array("whatever"); - - var $list =array(); - var $header =array(); - var $current_del_id = ""; - var $Vendor = ""; - - 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(!session::is_set('printerPPDSelectionDialog')){ - session::set("printerPPDSelectionDialog",array('regex'=> "*")); - } - - /* Order the manufacturers index */ - ksort($this->header); - } - - function execute() - { - /* Call parent execute */ - plugin::execute(); - - /* Fill templating stuff */ - $smarty= get_smarty(); - $display= ""; - $s_action = "none"; - - $printerPPDSelectionDialog = session::get('printerPPDSelectionDialog'); - $regex = $printerPPDSelectionDialog['regex']; - - if(isset($_GET['search'])){ - $regex = $_GET['search']."*"; - } - - if(isset($_POST['regex'])){ - $regex= $_POST['regex']; - } - - $regex = str_replace("**","*",$regex); - $printerPPDSelectionDialog['regex'] = $regex; - session::set('printerPPDSelectionDialog',$printerPPDSelectionDialog); - - - /* 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(!$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'])){ - 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 = " -  %s - "; - $uselink = "%s"; - $dellink = " - "._("delete")." - "; - - 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("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')); - $smarty->assign("alphabet", generate_alphabet()); - $smarty->assign("apply", apply_filter()); - $smarty->assign("regex", $regex); - - $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__))); - return($display); - } - - function save_object() - { - } - - function check(){ - } - - /* Save to LDAP */ - function save() - { - return $this->selectedPPD; - } -} -// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: -?> diff --git a/gosa-core/plugins/admin/systems/ppd/printerPPDDialog.tpl b/gosa-core/plugins/admin/systems/ppd/printerPPDDialog.tpl deleted file mode 100644 index 761d00516..000000000 --- a/gosa-core/plugins/admin/systems/ppd/printerPPDDialog.tpl +++ /dev/null @@ -1,24 +0,0 @@ -

P {t}Printer driver{/t}

- - - - - -
- {t}Model{/t}: {$ppdString}  - - - {t}New driver{/t}  - - -
-{if $showOptions eq 1} -

 

-

L {t}Options{/t}

-{$properties} -{/if} -

- - - -

diff --git a/gosa-core/plugins/admin/systems/ppd/printerPPDSelectionDialog.tpl b/gosa-core/plugins/admin/systems/ppd/printerPPDSelectionDialog.tpl deleted file mode 100644 index b6cad00b8..000000000 --- a/gosa-core/plugins/admin/systems/ppd/printerPPDSelectionDialog.tpl +++ /dev/null @@ -1,48 +0,0 @@ - - - - - -
-
-

- {t}Select objects to add{/t} -

-
-
- {$List} - -
-
-
-

- [F] - {t}Filters{/t} -

-
-
- - {$alphabet} -
- - - - - -
- - - -
- {$apply} - -
-
- -

- -

- diff --git a/gosa-core/plugins/admin/systems/ppd/remove_ppd.tpl b/gosa-core/plugins/admin/systems/ppd/remove_ppd.tpl deleted file mode 100644 index 6d28ba9ec..000000000 --- a/gosa-core/plugins/admin/systems/ppd/remove_ppd.tpl +++ /dev/null @@ -1,15 +0,0 @@ -
- {t}Warning{/t} -
-

- {$warning} -

- -

- {t}The ppd file will be removed from the server and can not be restored.{/t} -

-

- -   - -

diff --git a/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc b/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc new file mode 100644 index 000000000..06996b18e --- /dev/null +++ b/gosa-plugins/goto/admin/systems/ppd/class_ppdManager.inc @@ -0,0 +1,356 @@ +path= $path; + }else{ + msg_dialog::display(_("PPD manager error"), sprintf(_("The specified path '%s' does not exist."),$path), ERROR_DIALOG); + return (false); + } + } + + + function findPPD($path) + { + $list= array(); + $currentDir= getcwd(); + + $dh = opendir($path); + while(false !== ($file = readdir($dh))){ + + /* Skip well known files */ + if( $file == '.' || $file == '..'){ + continue; + } + + /* Recurse through all "common" directories */ + if(is_dir($path.'/'.$file)){ + $list= array_merge($list, $this->findPPD($path.'/'.$file)); + continue; + } + + /* Check for PPD extension */ + if (preg_match('/\.ppd$/i', $file)){ + $list[]= $path.'/'.$file; + } + } + + closedir($dh); + chdir ($currentDir); + return ($list); + } + + + function updateAttribute($file, $section, $attribute, $value) + { + $fsection= false; + $fattribute= false; + $section= preg_replace('/^\*/', '', $section); + $attribute= preg_replace('/^\*/', '', $attribute); + + $rp= @fopen($file, "r"); + $wp= @fopen("$file.tmp", "w"); + + + + while (!feof($rp)){ + $lines[]= fgets($rp, 1024); + } + + $ret = ""; + $done =false; + foreach($lines as $nr => $line){ + + if (preg_match("/\*OpenGroup:*\s+\**$section\/*/", $line)){ + $fsection= true; + $ret .=$line; + continue; + } + + /* Change model name .. */ + if ((preg_match("/^\*".$attribute.":*\s+/",$line)) && ($attribute == "ModelName")){ + $line= "*$attribute: \"$value\"\n"; + $done =true; + } + + if (($fsection) && ($section != "NO_SECTION")){ + if (preg_match("/^\*CloseGroup:*\s+\**$section\/*/", $line)){ + $fsection= false; + $ret .=$line; + continue; + } + + + if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){ + $fattribute= true; + $ret .= $line; + continue; + } + + if ($fattribute){ + if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){ + $fattribute= false; + $ret .= $line; + continue; + } + + if (preg_match("/^\*Default$attribute:*\s+/", $line)){ + $line= "*Default$attribute: $value\n"; + $done =true; + } + } + }else{ + if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){ + $fattribute= true; + $ret .= $line; + continue; + } + + if ($fattribute){ + if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){ + $fattribute= false; + $ret .= $line; + continue; + } + + if (preg_match("/^\*Default$attribute:*\s+/", $line)){ + $line= "*Default$attribute: $value\n"; + $done =true; + } + } + } + $ret .=$line; + } + + fwrite($wp,$ret); + + fclose($wp); + fclose($rp); + + copy("$file.tmp", "$file"); + unlink("$file.tmp"); + } + + + function saveProperties($ppdFile, $properties) + { + if(!is_readable($ppdFile)){ + msg_dialog::display(_("PPD manager error"), sprintf(_("Specified PPD file '%s' cannot be opened for reading."),$ppdFile), ERROR_DIALOG); + }elseif(!is_writeable(preg_replace("#(^.*/).*$#","\\1",$ppdFile.".tmp"))){ + msg_dialog::display(_("PPD manager error"), sprintf(_("The temporary file '%s' cannot be opened for writing."),$ppdFile.".tmp"), ERROR_DIALOG); + }else{ + foreach ($properties as $name => $section){ + foreach ($section as $attribute => $value){ + if (is_array($value)){ + $this->updateAttribute($ppdFile, $name, $attribute, $value['_default']); + } + } + } + } + } + + function loadProperties($ppdFile) + { + $group= ""; + $option= ""; + $properties= array(); + + $fh= fopen ($ppdFile, 'r'); + while (!feof($fh)) { + + /* Read line */ + $line= fgets($fh, 256); + if (strlen($line) >= 256){ + trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING); + } + + /* Trigger for option groups */ + if (preg_match('/^\*OpenGroup:/i', $line)){ + + /* Sanity checks */ + if ($group != ""){ + trigger_error(_('Nested groups are not supported!'), E_USER_WARNING); + continue; + } + if (in_array($group, $properties)){ + trigger_error(_('Group name not unique!'), E_USER_WARNING); + continue; + } + + // TODO: Symbol values are not supported yet! + if (preg_match('/\^/', $line)){ + trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING); + } + $complete= preg_replace('@^\*OpenGroup:\s+(.*)$@i', '\1', $line); + $complete= trim($complete, '"'); + if (preg_match('@/@', $complete)){ + $group= trim(preg_replace('@^\*OpenGroup:\s+"?([^/]+)/.*$@i', '\1', $line)); + $name = preg_replace('@^\*OpenGroup:\s+"?[^/]+/([^/]+).*$@i', '\1', $line); + } else { + $group= $complete; + $name = $complete; + } + $properties[$group]= array('_name' => $name); + continue; + } + if (preg_match("/^\*CloseGroup:\s+\"?$group\"?/i", $line)){ + $group= ""; + continue; + } + + /* Trigger for options */ + if (preg_match('/^\*OpenUI\s+/i', $line)){ + + /* Sanity check */ + if ($option != ""){ + trigger_error(_('Nested options are not supported!'), E_USER_WARNING); + continue; + } + + // TODO: Symbol values are not supported yet! + if (preg_match('/\^/', $line)){ + trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING); + } + $complete= preg_replace('@^\*OpenUI\s+(.*)$@i', '\1', $line); + $complete= trim($complete, '"'); + if (preg_match('@/@', $complete)){ + $option= trim(preg_replace('@^\*OpenUI\s+([^/]+)/.*$@i', '\1', $line)); + $name = trim(preg_replace('@^\*OpenUI\s+[^/]+/([^/]+).*$@i', '\1', $line)); + } else { + $option= trim($complete); + $name = trim($complete); + } + + /* Extract option type */ + $type= trim(preg_replace('/^[^:]+:\s+/', '', $line)); + $name= preg_replace('/:.*$/', '', $name); + $option= preg_replace('/:.*$/', '', $option); + + // TODO: PickMany is not supported yet! + if (preg_match('/PickMany/i', $type)){ + trigger_error(_('PickMany is not supported yet!'), E_USER_WARNING); + } + if(empty($group)){ + $properties["NO_SECTION"][$option]= array('_name' => $name, '_type' => $type); + }else{ + $properties[$group][$option]= array('_name' => $name, '_type' => $type); + } + continue; + } + /* Show interest for option parsing */ + if ($option != ""){ + + $eoption= preg_replace('@\*@', '', $option); + + /* Close section? */ + if (preg_match("@^\*CloseUI:\s+\*$eoption@i", $line)){ + $option= ""; + continue; + } + + /* Default value? */ + if (preg_match("@^\*Default$eoption:@", $line)){ + $c= preg_replace("@^\*Default$eoption:\s+@", "", $line); + if(empty($group)){ + $properties["NO_SECTION"][$option]['_default']= trim(trim($c, '"')); + }else{ + $properties[$group][$option]['_default']= trim(trim($c, '"')); + } + continue; + } + + /* Possible value? */ + if (preg_match("@^\*$eoption\s+@", $line)){ +#*PageSize Letter/US Letter: "<>setpagedevice" + $c= preg_replace("@^\*$eoption\s+([^/]+).*$@", "$1", $line); + $d= preg_replace("@^\*$eoption\s+[^/]+/([^:]+).*$@", "$1", $line); + if(empty($group)){ + $properties["NO_SECTION"][$option][trim($c)]= trim($d); + }else{ + $properties[$group][$option][trim($c)]= trim($d); + } + continue; + } + } + } + fclose ($fh); + return ($properties); + } + + function loadDescription($ppdFile) + { + $model= ""; + $manufacturer= ""; + + + /* Only parse complete PPD file again, if it was changed */ + $modified = filemtime($ppdFile); + if(isset($this->cachedList[$ppdFile]) && isset($this->timestamps[$ppdFile]) && $modified == $this->timestamps[$ppdFile]){ + return($this->cachedList[$ppdFile]); + } + + /* Remember modified timestamp, to speed up next request */ + $this->timestamps[$ppdFile] = filemtime($ppdFile); + + $fh= fopen ($ppdFile, 'r'); + while ((!feof($fh))&&($fh)) { + + /* Read line */ + $line= fgets($fh, 256); + if (strlen($line) >= 256){ + trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING); + } + + /* Extract interesting informations */ + if (preg_match('/^\*Manufacturer:/i', $line)){ + $manufacturer= preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line); + } + if (preg_match('/^\*ModelName:/i', $line)){ + $model= preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line); + } + + /* Got everything we need? Skip rest for speed reasons... */ + if ($model != '' && $manufacturer != ''){ + break; + } + } + fclose ($fh); + + /* Write out a notice that the PPD file seems to be broken if we can't + extract any usefull informations */ + if ($model == '' || $manufacturer == ''){ + trigger_error(sprintf(_('Parsing PPD file %s failed - no information found.'), $ppdFile), E_USER_WARNING); + } + + return ($manufacturer.' - '.$model); + } + + + function getPrinterList($reload= false) + { + /* Load list of PPD files */ + if (count($this->cachedList) == 0 || $reload){ + $list= $this->findPPD($this->path); + + /* Load descriptive informations to build final printer list */ + $new = array(); + foreach ($list as $ppdFile){ + $new[$ppdFile] = $this->loadDescription($ppdFile); + } + $this->cachedList= $new ; + + } + + return ($this->cachedList); + } + +} + +?> diff --git a/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc b/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc new file mode 100644 index 000000000..49f668180 --- /dev/null +++ b/gosa-plugins/goto/admin/systems/ppd/class_printerPPDDialog.inc @@ -0,0 +1,547 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account = TRUE; + var $attributes = array("cn"); + var $objectclasses = array("whatever"); + + /* PPD Handling */ + var $selectedPPD = false; // e.g. /vendor/device.ppd + var $ppdManager = false; // new ppdManager; + var $ppdConfig = false; // $this->ppdManager->loadProperties($this->selectedPPD['link']); + var $ppdList = array(); // Contains all Printer models + var $ppdListHeader = array(); // Contains all printer vendors + + /* Paths */ + var $pathToPPD = ""; // Base path, defined in gosa.conf e.g. "/var/spool/ppd/" + var $pathToModified = "modified/"; // used to store the modified ppds + + /* 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); + $this->depselect = $this->config->current['BASE']; + + /* Get PPD path and remove double //, and add trailing / */ + $config = session::get('config'); + if(isset($config->data['MAIN']['PPD_PATH'])){ + $this->pathToPPD = $config->data['MAIN']['PPD_PATH']; + $this->pathToPPD= preg_replace("/\/\//", "/", $this->pathToPPD); + if(!preg_match("/\/$/",$this->pathToPPD)){ + $this->pathToPPD = $this->pathToPPD."/"; + } + }else{ + $this->pathToPPD = ""; + } + + /* It seams that we have an existing PPD path, so go on */ + if(!((!is_dir($this->pathToPPD))||(empty($this->pathToPPD)))){ + + /* Load all available PPD files and sort them into an array */ + $this->ppdManager= new ppdManager($this->pathToPPD); + $this->getPrinterReload (); + + /* The user has already a valid PPD assigned + * Get some informations about this PPD + * and set it as selected. + * The ppdpath ['link'] should be relative from .../ppd/modified/ + * e.g. "/Compaq/Compaq-J1200.ppd" */ + if(($ppdfile!== NULL)&&(strlen($ppdfile)>0)){ + $ppdfile = preg_replace("#".$this->pathToModified."#","",$ppdfile); + if(!file_exists($this->pathToPPD.$this->pathToModified.$ppdfile)){ + print_red(sprintf(_("Can't open '%s', ppd settings resetted."),$ppdfile)); + }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; + } + $this->selectedPPD = $tmp3; + } + } + } + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $display= ""; + $smarty= get_smarty(); + $smarty->assign("ppdString", _("Can't get ppd informations.")); + $smarty->assign("showOptions", ""); + + /* Check these paths */ + $paths = array($this->pathToPPD, $this->pathToPPD.$this->pathToModified); + + /* 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))){ + print_red(sprintf(_("The specified path '%s' which results from PPD_PATH in your gosa.conf is invalid, can't read/write any ppd informations."),$path)); + /* Print out template */ + $display.= $smarty->fetch(get_template_path('printerPPDDialog.tpl', TRUE,dirname(__FILE__))); + return($display); + } + } + + // PPD selection / upload / dialog handling + + /* Is there a new PPD file uploaded ? */ + 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{ + print_red(_("Please specify a valid ppd file.")); + } + } + + /* 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); + } + + /* The selection dialog fpr PPDs is canceled */ + if(isset($_POST['ClosePPDSelection'])){ + unset($this->dialog); + $this->dialog=FALSE; + } + + /* Div Selection */ + if((isset($_GET['act']))&&($_GET['act']=="use")){ + $this->SelectPPD(base64_decode($_GET['id'])); + unset($this->dialog); + $this->dialog=FALSE; + + } + + /* if a dialog is open, print the dialog instead of this class */ + if(is_object($this->dialog)){ + $display = $this->dialog->execute(); + return($display); + } + + // ENDE PPD selection / upload / dialog handling + + /* 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); + } + + + /* Select PPD */ + function SelectPPD($name) + { + /* Replace base path we don't need it here + The path we need looks like this : "/Vendor/ModellName.ppd"; + thats all */ + $name = preg_replace("#".$this->pathToPPD."#","",$name); + + /* Intialise some base vars */ + $AbsoluteSourceName = $this->pathToPPD.$name; + $AbsoluteDestinationPath = $this->pathToPPD.$this->pathToModified; + $Vendor = ""; // Vendor + $Name = ""; // Name + $Modell = ""; // Modell + $PrinterName = ""; // The new name of the printer + $PPDName = ""; + + /* Force reload of config dialog */ + $this->ppdConfig = false; + $this->selectedPPD['link'] = false; + + /* Get PPD informations and set vendor / modell / name */ + if((!file_exists($AbsoluteSourceName)) || (!is_readable($AbsoluteSourceName))){ + print_red(sprintf(_("Can't select PPD file '%s', the file is not readable"),$AbsoluteSourceName)); + 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)); + } + + $PrinterName = $this->cn."-".preg_replace("/[^a-z0-9-_\.]/i","_",$Name); + $PPDName = $Vendor."/".$PrinterName.".ppd"; + + /* Create the vendors path, if it doesn't exists already */ + if(!is_dir($AbsoluteDestinationPath.$Vendor)){ + if(!(@mkdir($AbsoluteDestinationPath.$Vendor))){ + print_red(sprintf(_("Can't create folder '%s' for the uploaded ppd file."),$AbsoluteDestinationPath.$Vendor)); + return(false); + } + } + + /* Create destination file handle */ + $fp = @fopen($AbsoluteDestinationPath.$PPDName,"w+"); + if(!$fp){ + print_red(sprintf(_("Can't create file '%s' to store modifed ppd informations."),$AbsoluteDestinationPath.$PPDName)); + return(false); + } + + $str = file_get_contents($AbsoluteSourceName); + fputs($fp,$str); + @fclose($fp); + + //$this->ppdManager->updateAttribute($filename,"NO_SECTION","ModelName",$printerName); + + $tmp3['link'] =$PPDName; + $this->selectedPPD = $tmp3; + $this->getPrinterReload(); + return($PPDName); + } + + + /* 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,$overwrite = FALSE) + { + /* Check if file exists && is readable */ + if((!is_file($_PathOnHdd)) || (!is_readable($_PathOnHdd))){ + print_red(sprintf(_("Can't add new ppd file, the source file '%s' is not accessible."),$_PathOnHdd)); + return(false); + } + + /* Reload list to detect changes e.g. a file has been deleted */ + $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)); + } + + /* Check if parse was successfull */ + if(empty($name) || empty($vendor)){ + print_red(sprintf(_("The given ppd file '%s' seams to be invalid, can't get any model or vendor informations."),$_PathOnHdd)); + return(false); + } + + /* Prepare list of ppds */ + if(!isset($this->ppdList[$vendor])){ + $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; + 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 the vendors path, if it doesn't exists already */ + if(!is_dir($this->pathToPPD.$vendor)){ + if(!(@mkdir($this->pathToPPD.$vendor))){ + print_red(sprintf(_("Can't create folder '%s' for the uploaded ppd file."),$this->pathToPPD.$vendor)); + return(false); + } + } + + /* Open file handle */ + $fp = fopen($filename,"w+"); + + /* Check file handle & contents */ + if(!$fp){ + print_red(sprintf(_("Can't save file '%s'."),$filename)); + return; + } + if(empty($contents)){ + print_red(_("Uploaded ppd file is empty, can't create new ppd file.")); + return; + } + + /* Fille file with data */ + fputs($fp,$contents); + @fclose($fp); + + /* Our job is done here */ + return($ppdname); + } + + + /* This function reloads the list of available printers/vendors + $this->ppdListHeader + Compaq => 1 + $this->ppdList + Compaq => Compaq IJ1200 => name => Compaq IJ1200 + link => /var/spool/ppd/Compaq/Compaq-J1200.ppd + ppd => Compaq - Co + */ + function getPrinterReload() + { + if(is_readable($this->pathToPPD)){ + $tmp = @$this->ppdManager->getPrinterList(true); + + $this->ppdListHeader = $this->ppdList = array(); + + /* 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; + } + $tmp3['name'] =preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2]); + $tmp3['link'] =$file; + $tmp3['ppd'] =$ppd; + $this->ppdListHeader[$tmp2[0]]++; + $this->ppdList[$tmp2[0]][preg_replace("/^ -/","",$tmp2[1]." - ".$tmp2[2])]=$tmp3; + } + } + } + + + /* Save all options posted from ppd dialog */ + function save_object() + { + if(!((isset($_POST['PPDDisSubmitted'])) && (is_array($this->ppdConfig)))){ + return; + } + + 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'])]; + } + } + } + } + + + /* Save modified ppd */ + function save_ppd() + { + if($this->ppdManager){ + $this->ppdManager->saveProperties($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link'],$this->ppdConfig); + } + } + + + /* Return selected ppd path, if none is selected then false */ + function save() + { + /* return the selected PPD, and in future the selected options too */ + return($this->pathToModified.$this->selectedPPD['link']); + } + + + /* Get Information for a single PPD entry + * This will be shown on top of template + */ + function getPPDInformation() + { + $str = "none"; + if(!empty($this->selectedPPD)){ + $str = $this->ppdManager->loadDescription($this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']); + } + return($str) ; + } + + + /* Display all options from the selected ppd file */ + function generateProperties() + { + /* Set Headline */ + $str = ""; + $feed= ""; + + $s_ppd = $this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']; + + /* If ppd exists and is readable */ + if((!empty($this->selectedPPD['link']))&&(file_exists($s_ppd))){ + + /* If there is no initial Configuration, load it */ + if($this->ppdConfig == false){ + $this->ppdConfig = $this->ppdManager->loadProperties($s_ppd); + } + + /* Create a table */ + $str .= "
"; + + /* Input all data to the table */ + foreach($this->ppdConfig as $cat => $obj){ + + /* Add new category */ + $str .= ""; + + /* Add attributes of the current category */ + foreach($obj as $attr => $settings){ + + /* Skip all entries beginning with _ */ + if($attr[0] == "_") continue; + + /* Prepare data */ + $values = array(); + $name = $settings['_name']; + + if (!isset($settings['_default'])){ + $default = ""; + } else { + $default = $settings['_default']; + } + + $type = $settings['_type']; + + /* Add name to table */ + $str .= "\n"; + } + } + $str .= "
$feed"; + if ($feed == ""){ + $feed= "
"; + } + $str .= ""._("Section")." '".$cat."' 
"; + $str .= "
\n"; + $str .= $name."
\n"; + $str .= "
\n"; + + /* Get all values */ + foreach( $settings as $vname => $value){ + if($vname[0] != "_"){ + $values[$vname]= $value; + } + } + + /* 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 .= "\n"; + + }elseif($type == "Boolean"){ + + /* If type is Boolean & no values are given */ + $str .= "\n"; + + }else{ + print_red(sprintf(_("Unsupported ppd type '%s' used for '%s' "),$type,$name)); + } + $str .= "
\n"; + } + return($str); + } + + function removeModifiedPPD() + { + $path = $this->pathToPPD.$this->pathToModified.$this->selectedPPD['link']; + + if(file_exists($path)){ + if(is_writeable($path)){ + if(!@unlink($path)){ + print_red(sprintf(_("Removing old ppd file '%s' failed."),$path)); + } + }else{ + print_red(sprintf(_("Removing old ppd file '%s' failed. File is not accessible."),$path)); + } + }else{ + 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() + { + $message = plugin::check(); + if(empty($this->selectedPPD['link'])){ + $message[] = _("Please select a valid ppd file or use 'Cancel' to go back to printer configuration."); + } + return($message); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc b/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc new file mode 100644 index 000000000..ee5813062 --- /dev/null +++ b/gosa-plugins/goto/admin/systems/ppd/class_printerPPDSelectionDialog.inc @@ -0,0 +1,199 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $ignore_account = FALSE; + var $attributes = array(); + var $objectclasses = array("whatever"); + + var $list =array(); + var $header =array(); + var $current_del_id = ""; + var $Vendor = ""; + + 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(!session::is_set('printerPPDSelectionDialog')){ + session::set("printerPPDSelectionDialog",array('regex'=> "*")); + } + + /* Order the manufacturers index */ + ksort($this->header); + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Fill templating stuff */ + $smarty= get_smarty(); + $display= ""; + $s_action = "none"; + + $printerPPDSelectionDialog = session::get('printerPPDSelectionDialog'); + $regex = $printerPPDSelectionDialog['regex']; + + if(isset($_GET['search'])){ + $regex = $_GET['search']."*"; + } + + if(isset($_POST['regex'])){ + $regex= $_POST['regex']; + } + + $regex = str_replace("**","*",$regex); + $printerPPDSelectionDialog['regex'] = $regex; + session::set('printerPPDSelectionDialog',$printerPPDSelectionDialog); + + + /* 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(!$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'])){ + 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 = " +  %s + "; + $uselink = "%s"; + $dellink = " + "._("delete")." + "; + + 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("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')); + $smarty->assign("alphabet", generate_alphabet()); + $smarty->assign("apply", apply_filter()); + $smarty->assign("regex", $regex); + + $display.= $smarty->fetch(get_template_path('printerPPDSelectionDialog.tpl', TRUE,dirname(__FILE__))); + return($display); + } + + function save_object() + { + } + + function check(){ + } + + /* Save to LDAP */ + function save() + { + return $this->selectedPPD; + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/goto/admin/systems/ppd/printerPPDDialog.tpl b/gosa-plugins/goto/admin/systems/ppd/printerPPDDialog.tpl new file mode 100644 index 000000000..761d00516 --- /dev/null +++ b/gosa-plugins/goto/admin/systems/ppd/printerPPDDialog.tpl @@ -0,0 +1,24 @@ +

P {t}Printer driver{/t}

+ + + + + +
+ {t}Model{/t}: {$ppdString}  + + + {t}New driver{/t}  + + +
+{if $showOptions eq 1} +

 

+

L {t}Options{/t}

+{$properties} +{/if} +

+ + + +

diff --git a/gosa-plugins/goto/admin/systems/ppd/printerPPDSelectionDialog.tpl b/gosa-plugins/goto/admin/systems/ppd/printerPPDSelectionDialog.tpl new file mode 100644 index 000000000..b6cad00b8 --- /dev/null +++ b/gosa-plugins/goto/admin/systems/ppd/printerPPDSelectionDialog.tpl @@ -0,0 +1,48 @@ + + + + + +
+
+

+ {t}Select objects to add{/t} +

+
+
+ {$List} + +
+
+
+

+ [F] + {t}Filters{/t} +

+
+
+ + {$alphabet} +
+ + + + + +
+ + + +
+ {$apply} + +
+
+ +

+ +

+ diff --git a/gosa-plugins/goto/admin/systems/ppd/remove_ppd.tpl b/gosa-plugins/goto/admin/systems/ppd/remove_ppd.tpl new file mode 100644 index 000000000..6d28ba9ec --- /dev/null +++ b/gosa-plugins/goto/admin/systems/ppd/remove_ppd.tpl @@ -0,0 +1,15 @@ +
+ {t}Warning{/t} +
+

+ {$warning} +

+ +

+ {t}The ppd file will be removed from the server and can not be restored.{/t} +

+

+ +   + +