Skip to content
Snippets Groups Projects
Commit 803a4d32 authored by Liam Morland's avatar Liam Morland Committed by Kevin Kaland
Browse files

Issue #1355018: Improve UX of settings page.

parent 67a960c1
No related branches found
No related tags found
No related merge requests found
......@@ -21,30 +21,44 @@ define('FILLPDF_REPLACEMENTS_DESCRIPTION', t("<p>Tokens, such as those from CCK,
* Settings form for user to place API Key
*/
function fillpdf_settings($form, &$form_state) {
$form['settings_help'] = array(
'#type' => 'markup',
'#value' => t("
This module requires one of several external PDF manipulation tools -- you can:<ul>
<li>Sign up for <a href='http://fillpdf-service.com'>Fillpdf as-a-service</a>, and plug your API key in here; <strong>or</strong>
<li>Deploy locally -- You'll need a VPS or dedicated server so you can deploy PHP/JavaBridge on Tomcat (see README.txt), then select \"Use Local Service\"
<li>Use a local installation of the pdftk program - you'll need a VPS or a dedicated server so you can install pdftk (see README.txt), then select \"Use locally-installed pdftk\"
</ul>
"),
// Assemble service options. Warning messages will be added next as needed.
$options = array(
'pdftk' => t('Use locally-installed pdftk: You will need a VPS or a dedicated server so you can install pdftk (') . l(t('see documentation'), 'admin/help/fillpdf') . t(').'),
'local' => t('Use locally-installed PHP/JavaBridge: You will need a VPS or dedicated server so you can deploy PHP/JavaBridge on Apache Tomcat (') . l(t('see documentation'), 'admin/help/fillpdf') . t(').'),
'remote' => t('Use fillpdf-service.com: Sign up for <a href="http://fillpdf-service.com">Fill PDF as-a-service</a>.'),
);
// Check for JavaBridge.
if (!(file_exists(drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc'))) {
$options['local'] .= '<div class="messages warning">' . t('JavaBridge is not installed locally.') . '</div>';
}
// Check for pdftk.
$output = array();
$status = NULL;
exec('pdftk', $output, $status);
if (in_array($status, array(126, 127))) {
$options['pdftk'] .= '<div class="messages warning">' . t('pdftk is not properly installed.') . '</div>';
}
unset($output);
unset($status);
$form['fillpdf_service'] = array(
'#type' => 'radios',
'#title' => t('PDF-filling service'),
'#description' => t('This module requires the use of one of several external PDF manipulation tools. Choose the service you would like to use.'),
'#default_value' => variable_get('fillpdf_service'),
'#options' => $options,
);
$form['remote'] = array(
'#type' => 'fieldset',
'#title' => t('Use Remote Service'),
);
$form['remote']['fillpdf_remote_service'] = array(
'#type' => 'checkbox',
'#title' => t('Use fillpdf-service.com'),
'#default_value' => variable_get('fillpdf_remote_service', TRUE),
'#title' => t('Configure fillpdf-service.com'),
);
$form['remote']['fillpdf_api_key'] = array(
'#type' => 'textfield',
'#title' => t('API Key'),
'#default_value' => variable_get('fillpdf_api_key', ''),
'#description' => t(''),
'#description' => t('You need to sign up for an API key at <a href="http://fillpdf-service.com">fillpdf-service.com</a>'),
);
$form['remote']['fillpdf_remote_protocol'] = array(
'#type' => 'radios',
......@@ -56,66 +70,7 @@ function fillpdf_settings($form, &$form_state) {
'http' => t('No'),
'https' => t('Yes'),
),
);
if (variable_get('fillpdf_api_key', '') == '') {
$form['remote']['warning'] = array(
'#type' => 'markup',
'#prefix' => "<div class='warning'>",
'#suffix' => "</div>",
'#value' => t("You need to sign up for an API key at <a href='http://fillpdf-service.com'>fillpdf-service.com</a>"),
);
}
$form['local'] = array(
'#type' => 'fieldset',
'#title' => t('Use Local Service'),
);
$form['local']['fillpdf_local_service'] = array(
'#type' => 'checkbox',
'#title' => t('Use locally-installed PHP/JavaBridge'),
'#default_value' => (variable_get('fillpdf_local_service', TRUE)),
);
if (!(file_exists(drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc'))) {
$form['local']['warning'] = array(
'#type' => 'markup',
'#prefix' => "<div class='warning'>",
'#suffix' => "</div>",
'#value' => t("JavaBridge isn't installed locally. See README.txt for setting it up."),
);
}
$form['local_php'] = array(
'#type' => 'fieldset',
'#title' => t('Use Local pdftk'),
);
$form['local_php']['fillpdf_local_php'] = array(
'#type' => 'checkbox',
'#title' => t('Use locally-installed pdftk'),
'#default_value' => (variable_get('fillpdf_local_php', TRUE)),
);
// TODO: Modify to add check for pdftk installed
$js = <<<JS
Drupal.behaviors.fillpdfSettingsCheckboxes = {
attach: function (context) {
(function ($) {
$("input#edit-fillpdf-remote-service").click(function(){
$("input#edit-fillpdf-local-service").attr('checked', false);
$("input#edit-fillpdf-local-php").attr('checked', false);
});
$("input#edit-fillpdf-local-service").change(function(){
$("input#edit-fillpdf-remote-service").attr('checked', false);
$("input#edit-fillpdf-local-php").attr('checked', false);
});
$("input#edit-fillpdf-local-php").change(function(){
$("input#edit-fillpdf-local-service").attr('checked', false);
$("input#edit-fillpdf-remote-service").attr('checked', false);
});
})(jQuery);
}
};
JS;
drupal_add_js($js, array('type' => 'inline', 'scope' => JS_DEFAULT));
return system_settings_form($form);
}
......
......@@ -92,6 +92,10 @@ function fillpdf_uninstall() {
}
/**
* Implements hook_update_N().
*/
/**
* Add field to store destination path for saving PDFs as files.
*/
......@@ -106,3 +110,27 @@ function fillpdf_update_7002() {
db_add_field('fillpdf_forms', 'replacements', array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
db_add_field('fillpdf_fields', 'replacements', array('type' => 'text', 'size' => 'normal', 'not null' => FALSE));
}
/**
* Convert legacy configuration variables to new fillpdf_service variable and delete.
*/
function fillpdf_update_7003() {
$default = FALSE;
global $conf;
foreach (array('fillpdf_remote_service', 'fillpdf_local_service', 'fillpdf_local_php') as $variable_name) {
if (isset($conf[$variable_name])) {
if ($conf[$variable_name]) {
$default = $variable_name;
}
variable_del($variable_name);
}
}
if ($default) {
$variable_name_map = array(
'fillpdf_local_php' => 'pdftk',
'fillpdf_local_service' => 'local',
'fillpdf_remote_service' => 'remote',
);
variable_set('fillpdf_service', $variable_name_map[$default]);
}
}
......@@ -351,38 +351,39 @@ function fillpdf_merge_pdf($fid, $nids = NULL, $webform_arr = NULL, $sample = NU
$output_name = preg_replace('/[^a-zA-Z0-9_]/', '', $fillpdf_info->title) . '.pdf';
$pdf_data = _fillpdf_get_file_contents($fillpdf_info->url, "<front>");
$fillpdf_remote_service = variable_get('fillpdf_remote_service', TRUE);
$fillpdf_local_service = variable_get('fillpdf_local_service', TRUE);
// use fillpdf-service.com's xmlrpc service (must be registered)
if ($fillpdf_remote_service) {
$api_key = variable_get('fillpdf_api_key', '0');
$result = _fillpdf_xmlrpc_request(DEFAULT_SERVLET_URL, 'merge_pdf_enhanced', base64_encode($pdf_data), $fields, $api_key, $flatten);
if ($result->error == TRUE) {
drupal_goto();
} //after setting error message
$data = base64_decode($result->data);
}
// use local php/java bridge (must have Tomcat & JavaBridge installed on VPS or dedicated
elseif ($fillpdf_local_service) {
$require = drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc';
require_once DRUPAL_ROOT . '/' . $require;
try {
$fillpdf = new java('com.ocdevel.FillpdfService', base64_encode($pdf_data), 'bytes');
foreach ($fields as $key => $field) {
$fillpdf->text($key, $field);
switch (variable_get('fillpdf_service')) {
case 'remote': // use fillpdf-service.com's xmlrpc service (must be registered)
$api_key = variable_get('fillpdf_api_key', '0');
$result = _fillpdf_xmlrpc_request(DEFAULT_SERVLET_URL, 'merge_pdf_enhanced', base64_encode($pdf_data), $fields, $api_key, $flatten);
if ($result->error == TRUE) {
drupal_goto();
} // after setting error message
$data = base64_decode($result->data);
break;
case 'local': // use local php/java bridge (must have Tomcat & JavaBridge installed on VPS or dedicated
$require = drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc';
require_once DRUPAL_ROOT . '/' . $require;
try {
$fillpdf = new java('com.ocdevel.FillpdfService', base64_encode($pdf_data), 'bytes');
foreach ($fields as $key => $field) {
$fillpdf->text($key, $field);
}
}
}
catch (JavaException $e) {
drupal_set_message(check_plain(java_truncate((string) $e)), 'error');
drupal_goto(); //after setting error message
}
$data = java_values(base64_decode($fillpdf->toByteArray()));
}
catch (JavaException $e) {
drupal_set_message(check_plain(java_truncate((string) $e)), 'error');
drupal_goto(); // after setting error message
}
$data = java_values(base64_decode($fillpdf->toByteArray()));
break;
// Use PDFTK to merge the two
else {
$data = fillpdf_execute_merge('pdftk', $fields, $fillpdf_info, 'url', $flatten);
case 'pdftk': // Use PDFTK to merge the two
$data = fillpdf_execute_merge('pdftk', $fields, $fillpdf_info, 'url', $flatten);
break;
default:
drupal_set_message(t('Fill PDF is not configured.'), 'error');
drupal_goto();
}
if ($webform_arr) $node = $webform['webform'];
......@@ -529,35 +530,35 @@ function fillpdf_execute_merge($method, $fields, $fillpdf, $mode = 'url', $flatt
function fillpdf_parse_pdf($fid) {
$filename = db_query("SELECT url FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))->fetchField();
$content = _fillpdf_get_file_contents($filename, "<front>");
$fillpdf_remote_service = variable_get('fillpdf_remote_service', TRUE);
$fillpdf_local_service = variable_get('fillpdf_local_service', TRUE);
// use fillpdf-service.com's xmlrpc service (must be registered)
if ($fillpdf_remote_service) {
$result = _fillpdf_xmlrpc_request(DEFAULT_SERVLET_URL, 'parse_pdf_fields', base64_encode($content));
if ($result->error == TRUE) {
drupal_goto("admin/structure/fillpdf");
} //after setting error message
$fields = $result->data;
}
// use local php/java bridge (must have Tomcat & JavaBridge installed on VPS or dedicated
elseif ($fillpdf_local_service) {
$require = drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc';
require_once DRUPAL_ROOT . '/' . $require;
try {
$fillpdf = new java('com.ocdevel.FillpdfService', base64_encode($content), 'bytes');
$fields = java_values($fillpdf->parse());
}
catch (JavaException $e) {
drupal_set_message(check_plain(java_truncate((string) $e)), 'error');
drupal_goto("admin/structure/fillpdf"); //after setting error message
}
}
switch (variable_get('fillpdf_service')) {
case 'remote': // use fillpdf-service.com's xmlrpc service (must be registered)
$result = _fillpdf_xmlrpc_request(DEFAULT_SERVLET_URL, 'parse_pdf_fields', base64_encode($content));
if ($result->error == TRUE) {
drupal_goto('admin/structure/fillpdf');
} // after setting error message
$fields = $result->data;
break;
//use pdftk program (must be installed locally)
else {
$fields = fillpdf_execute_parse('pdftk', $filename);
case 'local': // use local php/java bridge (must have Tomcat & JavaBridge installed on VPS or dedicated
$require = drupal_get_path('module', 'fillpdf') . '/lib/JavaBridge/java/Java.inc';
require_once DRUPAL_ROOT . '/' . $require;
try {
$fillpdf = new java('com.ocdevel.FillpdfService', base64_encode($content), 'bytes');
$fields = java_values($fillpdf->parse());
}
catch (JavaException $e) {
drupal_set_message(check_plain(java_truncate((string) $e)), 'error');
drupal_goto('admin/structure/fillpdf'); // after setting error message
}
break;
case 'pdftk': // use pdftk program (must be installed locally)
$fields = fillpdf_execute_parse('pdftk', $filename);
break;
default:
drupal_set_message(t('Fill PDF is not configured.'), 'error');
drupal_goto('admin/structure/fillpdf');
}
//create fields
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment