diff --git a/fillpdf.admin.inc b/fillpdf.admin.inc index d54a9f83add42bd05c438984ecb3413137dfd1e5..34900a5718761078485462b0e115b6099b1b4d6a 100644 --- a/fillpdf.admin.inc +++ b/fillpdf.admin.inc @@ -75,19 +75,23 @@ function fillpdf_settings($form, &$form_state) { //TODO: Modify to add check for pdftk installed $js = <<<JS -Drupal.behaviors.fillpdfSettingsCheckboxes = function (context) { - $("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); - }); +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)); @@ -107,20 +111,20 @@ function fillpdf_forms_admin($form, &$form_state) { 'data' => t('Operations'), 'colspan' => '4', )); - while ($pdf_form = db_fetch_object($result)) { + $rows = array(); + foreach ($result as $pdf_form) { $row = array( check_plain($pdf_form->title), - l(t('Edit'), "admin/content/fillpdf/$pdf_form->fid"), - l(t('Delete'), "admin/content/fillpdf/$pdf_form->fid/delete"), - l(t('Export field mappings'), "admin/content/fillpdf/$pdf_form->fid/export"), - l(t('Import field mappings'), "admin/content/fillpdf/$pdf_form->fid/import"), + l(t('Edit'), "admin/structure/fillpdf/$pdf_form->fid"), + l(t('Delete'), "admin/structure/fillpdf/$pdf_form->fid/delete"), + l(t('Export field mappings'), "admin/structure/fillpdf/$pdf_form->fid/export"), + l(t('Import field mappings'), "admin/structure/fillpdf/$pdf_form->fid/import"), ); $rows[] = $row; } $form['existing_forms'] = array( - '#type' => 'markup', - '#value' => theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'fillpdf'))), + '#markup' => theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'fillpdf'))), ); $form['#attributes'] = array('enctype' => "multipart/form-data"); @@ -155,8 +159,8 @@ function fillpdf_forms_admin_validate($form, &$form_state) { } // directory exist or writeable? - $dir = file_directory_path() . "/fillpdf"; - file_prepare_directory($dir, FILE_CREATE_DIRECTORY, 'url'); + $dir = file_build_uri('fillpdf'); + file_prepare_directory($dir, FILE_CREATE_DIRECTORY); } @@ -164,28 +168,37 @@ function fillpdf_forms_admin_validate($form, &$form_state) { * Creates a new Form from the uploaded PDF, including parsed fields */ function fillpdf_forms_admin_submit($form, &$form_state) { - $dir = file_directory_path() . "/fillpdf"; + $dir = file_build_uri('fillpdf'); // $validators not working, so I just checked manually in fillpdf_forms_validate() $validators = array('file_validate_extensions' => array('pdf')); if ($file = file_save_upload('upload_pdf', $validators, $dir, FILE_EXISTS_REPLACE)) { drupal_set_message('<strong>' . $file->filename . '</strong> was successfully uploaded'); - $file->status &= FILE_STATUS_PERMANENT; + $file->status = FILE_STATUS_PERMANENT; $file = file_save($file); + // Does this file already exist in {fillpdf_forms}? If so, don't re-insert it. + $exists = (bool) db_select('fillpdf_forms', 'ff') + ->fields('ff', array('fid')) + ->condition('fid', $file->fid) + ->execute() + ->fetchField(); + if ($exists === FALSE) { + db_insert('fillpdf_forms') + ->fields(array( + 'fid' => $file->fid, + 'title' => $file->filename, + 'url' => $file->uri, + )) + ->execute(); + } + $fid = $file->fid; + fillpdf_parse_pdf($fid); } else { //commented out because even though error if file doesn't upload right, not error if they dont' upload a file (& this is still triggered) drupal_set_message('Error saving file to ' . $dir, 'error'); } - $fid = db_insert('fillpdf_forms') - ->fields(array( - 'fid' => $fid, - 'title' => $file->filename, - 'url' => $file->filepath, - )) - ->execute(); - fillpdf_parse_pdf($fid); - $form_state['redirect'] = "admin/content/fillpdf/$fid"; + $form_state['redirect'] = "admin/structure/fillpdf/$fid"; } @@ -195,7 +208,7 @@ function fillpdf_forms_admin_submit($form, &$form_state) { * Edit existing PDF form */ function fillpdf_form_edit($form, &$form_state, $fid) { - $pdf_form = db_fetch_object(db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))); + $pdf_form = db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))->fetch(); $form['title'] = array( '#type' => 'textfield', @@ -217,17 +230,17 @@ function fillpdf_form_edit($form, &$form_state, $fid) { $form['pdf_info']['submitted_pdf'] = array( '#type' => 'item', '#title' => t('Uploaded PDF'), - '#value' => $pdf_form->url, + '#description' => $pdf_form->url, ); $form['pdf_info']['sample_populate'] = array( '#type' => 'item', '#title' => 'Sample PDF', - '#value' => l("See which fields are which in this PDF", fillpdf_pdf_link($fid, null, null, true)), + '#description' => l("See which fields are which in this PDF", fillpdf_pdf_link($fid, null, null, true)), ); $form['pdf_info']['form_id'] = array( '#type' => 'item', '#title' => 'Form Info', - '#value' => "Form ID: [$fid]. Populate this form with node IDs, such as /fillpdf?fid=$fid&nid=10<br/>", + '#description' => "Form ID: [$fid]. Populate this form with node IDs, such as /fillpdf?fid=$fid&nid=10<br/>", ); @@ -245,23 +258,23 @@ function fillpdf_form_edit($form, &$form_state, $fid) { // @@TODO: order by weight, and add dragable ala http://www.computerminds.co.uk/quick-guide-using-drupal-add-tabledrag-and-enjoying-jquery-drag-and-drop-loveliness $q = db_query('SELECT * FROM {fillpdf_fields} WHERE fid = :fid', array(':fid' => $fid)); $header = array(t('Label'), t('PDF-field key'), t('Value'), array( - 'data' => t('Operations'), - 'colspan' => 2, - )); - while ($field = db_fetch_object($q)) { + 'data' => t('Operations'), + 'colspan' => 2, + )); + $rows = array(); + foreach ($q as $field) { $row = array( check_plain($field->label), //editable check_plain($field->pdf_key), $field->value, //editable, expandable - l(t('Edit'), "admin/content/fillpdf/$fid/edit/{$field->pdf_key}"), - l(t('Delete'), "admin/content/fillpdf/$fid/delete/{$field->pdf_key}"), + l(t('Edit'), "admin/structure/fillpdf/$fid/edit/{$field->pdf_key}"), + l(t('Delete'), "admin/structure/fillpdf/$fid/delete/{$field->pdf_key}"), ); $rows[] = $row; } $form['existing_fields'] = array( - '#type' => 'markup', - '#value' => '<br/><br/>' . theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'fillpdf_fields'))), + '#markup' => '<br/><br/>' . theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'fillpdf_fields'))), ); // $form['tokens_fieldset'] = array( @@ -284,7 +297,7 @@ function fillpdf_form_edit($form, &$form_state, $fid) { */ function fillpdf_form_edit_submit($form, &$form_state) { if ($form_state['values']['op'] == t('Delete')) { - $form_state['redirect'] = "admin/content/fillpdf/{$form['#pdf_form']->fid}/delete"; + $form_state['redirect'] = "admin/structure/fillpdf/{$form['#pdf_form']->fid}/delete"; return; } else { @@ -294,7 +307,7 @@ function fillpdf_form_edit_submit($form, &$form_state) { )) ->condition('fid', $form['#pdf_form']->fid) ->execute(); - $form_state['redirect'] = "admin/content/fillpdf/{$form['#pdf_form']->fid}"; + $form_state['redirect'] = "admin/structure/fillpdf/{$form['#pdf_form']->fid}"; drupal_set_message('Successfully updated form'); //$form_state['nid'] = $node->nid; } @@ -305,17 +318,17 @@ function fillpdf_form_edit_submit($form, &$form_state) { */ function fillpdf_form_delete_confirm($form, &$form_state, $pdf_form) { if (is_numeric(arg(3))) { - $pdf_form = db_fetch_object(db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => arg(3)))); + $pdf_form = db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => arg(3)))->fetch(); } if (!$pdf_form) { drupal_not_found(); - exit; + drupal_exit(); } $form['#pdf_form'] = $pdf_form; return confirm_form($form, t('Are you sure you want to delete the form %title?', array('%title' => $pdf_form->title)), - 'admin/content/fillpdf', + 'admin/structure/fillpdf', t('Deleting a form will delete all the fields you created in it. This action cannot be undone.'), t('Delete'), t('Cancel') ); @@ -332,7 +345,7 @@ function fillpdf_form_delete_confirm_submit($form, &$form_state) { ->condition('fid', $form['#pdf_form']->fid) ->execute(); drupal_set_message('Your form has been deleted.'); - $form_state['redirect'] = 'admin/content/fillpdf'; + $form_state['redirect'] = 'admin/structure/fillpdf'; } /** @@ -344,15 +357,15 @@ function fillpdf_form_delete_confirm_submit($form, &$form_state) { */ function fillpdf_form_export($pdf_form) { if (is_numeric($pdf_form)) { - $fid = db_fetch_object(db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $pdf_form))); + $fid = db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $pdf_form))->fetch(); } if (!$fid) { drupal_not_found(); - exit; + drupal_exit(); } $fields = db_query('SELECT * FROM {fillpdf_fields} WHERE fid = :fid', array(':fid' => $fid->fid)); $export_array = array(); - while ($field = db_fetch_object($fields)) { + foreach ($fields as $field) { $export_array[$field->pdf_key] = array( 'label' => $field->label, 'value' => $field->value, @@ -429,11 +442,11 @@ function fillpdf_form_export_encode($var, $iteration = 0) { */ function fillpdf_form_import_form($form, &$form_state, $pdf_form) { if (is_numeric($pdf_form)) { - $fid = db_fetch_object(db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $pdf_form))); + $fid = db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $pdf_form))->fetch(); } if (!$fid) { drupal_not_found(); - exit; + drupal_exit(); } $form['fid'] = array( '#type' => 'value', @@ -493,7 +506,7 @@ function fillpdf_form_import_form_submit($form, &$form_state) { } } drupal_set_message(t('Successfully imported matching PDF field keys. If any field mappings failed to import, they are listed above.')); - $form_state['redirect'] = "admin/content/fillpdf/{$pdf_form->fid}"; + $form_state['redirect'] = "admin/structure/fillpdf/{$pdf_form->fid}"; } /** @@ -514,11 +527,11 @@ function fillpdf_form_export_decode($string) { */ function fillpdf_field($op, $fid, $pdf_key = NULL) { if (is_numeric($fid)) { - $pdf_form = db_fetch_object(db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))); + $pdf_form = db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))->fetch(); } if (!$pdf_form) { drupal_not_found(); - exit; + drupal_exit(); } if ($op == 'add') { @@ -528,10 +541,10 @@ function fillpdf_field($op, $fid, $pdf_key = NULL) { return fillpdf_form_overview($pdf_form); } else if ($pdf_key) { - $field = db_fetch_object(db_query("SELECT * FROM {fillpdf_fields} WHERE pdf_key = :pdf_key AND fid = :fid", array(':pdf_key' => $pdf_key, ':fid' => $fid))); + $field = db_query("SELECT * FROM {fillpdf_fields} WHERE pdf_key = :pdf_key AND fid = :fid", array(':pdf_key' => $pdf_key, ':fid' => $fid))->fetch(); if (!$field) { drupal_not_found(); - exit; + drupal_exit(); } drupal_set_title($field->label); } @@ -574,9 +587,9 @@ function fillpdf_field_edit($form, &$form_state, $pdf_form, $field) { '#collapsed' => TRUE, '#weight' => 5, ); - // TODO Please change this theme call to use an associative array for the $variables parameter. $form['tokens_fieldset']['tokens'] = array( - '#value' => theme('token_help'), + '#theme' => 'token_tree', + '#token_types' => array('node'), ); $form['submit'] = array( @@ -603,7 +616,8 @@ function fillpdf_field_edit($form, &$form_state, $pdf_form, $field) { * Validate the edited field. */ function fillpdf_field_edit_validate($form, &$form_state) { - if (db_query("SELECT * FROM {fillpdf_fields} WHERE fid = :fid AND pdf_key = :pdf_key", array(':fid' => $form['#pdf_form']->fid, ':pdf_key' => $form_state['values']['pdf_key']))->fetchField()) { + $pdf_form = db_query("SELECT * FROM {fillpdf_fields} WHERE fid = :fid AND pdf_key = :pdf_key", array(':fid' => $form['#pdf_form']->fid, ':pdf_key' => $form_state['values']['pdf_key']))->fetch(); + if ($pdf_form) { if ($form['#pdf_field'] && $form['#pdf_field']->pdf_key == $form_state['values']['pdf_key'] ) { return; } @@ -619,7 +633,7 @@ function fillpdf_field_edit_validate($form, &$form_state) { function fillpdf_field_edit_submit($form, &$form_state) { if ($form['#pdf_field']) { if ($form_state['values']['op'] == t('Delete')) { - $form_state['redirect'] = 'admin/content/fillpdf/' . $form['#pdf_form']->fid . '/delete/' . $form['#pdf_field']->pdf_key; + $form_state['redirect'] = 'admin/structure/fillpdf/' . $form['#pdf_form']->fid . '/delete/' . $form['#pdf_field']->pdf_key; return; } $edit_field = (object) $form_state['values']; @@ -637,7 +651,7 @@ function fillpdf_field_edit_submit($form, &$form_state) { )) ->execute(); } - $form_state['redirect'] = 'admin/content/fillpdf/' . $form['#pdf_form']->fid; + $form_state['redirect'] = 'admin/structure/fillpdf/' . $form['#pdf_form']->fid; } @@ -645,14 +659,14 @@ function fillpdf_field_edit_submit($form, &$form_state) { * Delete form. */ function fillpdf_field_delete_confirm($form, &$form_state, $fid, $pdf_key) { - $pdf_form = db_fetch_object(db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))); + $pdf_form = db_query("SELECT * FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))->fetch(); if ($pdf_key) { - $field = db_fetch_object(db_query("SELECT * FROM {fillpdf_fields} WHERE pdf_key = :pdf_key AND fid = :fid", array(':pdf_key' => $pdf_key, ':fid' => $fid))); + $field = db_query("SELECT * FROM {fillpdf_fields} WHERE pdf_key = :pdf_key AND fid = :fid", array(':pdf_key' => $pdf_key, ':fid' => $fid))->fetch(); } if (!$field) { drupal_not_found(); - exit; + drupal_exit(); } $form['#pdf_field'] = $field; @@ -660,7 +674,7 @@ function fillpdf_field_delete_confirm($form, &$form_state, $fid, $pdf_key) { return confirm_form($form, t('Are you sure you want to delete the field %pdf_key?', array('%pdf_key' => $field->pdf_key)), - 'admin/content/fillpdf/' . $pdf_form->fid, + 'admin/structure/fillpdf/' . $pdf_form->fid, t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } @@ -674,8 +688,8 @@ function fillpdf_field_delete_confirm_submit($form, &$form_state) { ->condition('pdf_key', $form['#pdf_field']->pdf_key) ->execute(); drupal_set_message('Your field has been deleted.'); - //return 'admin/content/fillpdf/'. $form['#pdf_field']->fid; - $form_state['redirect'] = 'admin/content/fillpdf/' . $form['#pdf_field']->fid; + //return 'admin/structure/fillpdf/'. $form['#pdf_field']->fid; + $form_state['redirect'] = 'admin/structure/fillpdf/' . $form['#pdf_field']->fid; } /** diff --git a/fillpdf.info b/fillpdf.info index ea5f9edeab1b18f1ad875ecfc0d97c3a1647858f..d184ead7806e976eb8a0a87a22f4b380d4c3e59e 100644 --- a/fillpdf.info +++ b/fillpdf.info @@ -3,17 +3,4 @@ description = Allows users to populate PDF forms from submitted node data. package = Other core = 7.x -dependencies[] = content dependencies[] = token -; Information added by drupal.org packaging script on 2011-01-04 -version = "6.x-1.x-dev" -core = 7.x -project = "fillpdf" -datestamp = "1294143233" - - -files[] = fillpdf.admin.inc -files[] = fillpdf.install -files[] = fillpdf.module -files[] = webform_tokens.inc -files[] = xfdf.inc diff --git a/fillpdf.install b/fillpdf.install index 3b47cac517a3446d75aeb5e97cdba203b157cb08..3167c43bc532a676dbe86344088576a3fe15e6b8 100644 --- a/fillpdf.install +++ b/fillpdf.install @@ -1,48 +1,79 @@ <?php +/** + * @file + * Install + */ + +/** + * Implements hook_schema(). + */ +function fillpdf_schema() { + $schema = array(); + + $schema['fillpdf_forms'] = array( + 'fields' => array( + 'fid' => array( + 'type' => 'int', + 'length' => 10, + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'title' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + ), + 'url' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + ), + ), + 'primary key' => array('fid'), + ); + + $schema['fillpdf_fields'] = array( + 'fields' => array( + 'fid' => array( + 'type' => 'int', + 'length' => 10, + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'pdf_key' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + ), + 'label' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + ), + 'value' => array( + 'type' => 'text', + 'size' => 'medium', + 'not null' => TRUE, + ), + ), + 'primary key' => array('fid', 'pdf_key'), + ); + + return $schema; +} + +/** + * Implements hook_install(). + */ function fillpdf_install() { - switch ($GLOBALS['db_type']) { - case 'mysqli': - case 'mysql': - db_query("CREATE TABLE if not exists {fillpdf_forms} ( - fid int(10) unsigned NOT NULL, - title varchar(255) NOT NULL, - url varchar(255) NOT NULL, - PRIMARY KEY(fid) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - - db_query("CREATE TABLE if not exists {fillpdf_fields} ( - fid int(10) unsigned NOT NULL, - pdf_key varchar(255) NOT NULL, - label varchar(255) NOT NULL, - value mediumtext NOT NULL, - PRIMARY KEY(fid, pdf_key) - ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;"); - - break; - case 'pgsql': - db_query("CREATE TABLE {fillpdf_forms} ( - fid integer NOT NULL, - title varchar(255) NOT NULL, - url varchar(255) NOT NULL, - PRIMARY KEY(fid) - )"); - - db_query("CREATE TABLE {fillpdf_fields} ( - fid integer NOT NULL, - pdf_key varchar(255) NOT NULL, - label varchar(255) NOT NULL, - value mediumtext NOT NULL, - PRIMARY KEY(fid, pdf_key) - )"); - - default: - break; - } } +/** + * Implements hook_uninstall(). + */ function fillpdf_uninstall() { - db_query("DROP TABLE {fillpdf_forms}"); - db_query("DROP TABLE {fillpdf_fields}"); + } + diff --git a/fillpdf.module b/fillpdf.module index 7a711772479aad205f91473b3cb734ff8e034634..83b16b2ddfb62bd1c4202eabfa012a8acc3ad293 100644 --- a/fillpdf.module +++ b/fillpdf.module @@ -9,7 +9,9 @@ define("DEFAULT_SERVLET_URL", "http://fillpdf-service.com/xmlrpc.php"); module_load_include('inc', 'fillpdf', 'fillpdf.admin'); if (module_exists('webform')) { - module_load_include('inc', 'fillpdf', 'webform_tokens'); + // TODO: Someone wanna convert this to D7 syntax? + // Instructions here: http://drupal.org/documentation/modules/token/update/6/7 + // module_load_include('inc', 'fillpdf', 'webform_tokens'); } /** @@ -21,9 +23,9 @@ function fillpdf_help($path, $arg) { $content = _fillpdf_get_file_contents(drupal_get_path('module', 'fillpdf') . '/README.txt'); $content = '<pre>' . check_plain($content) . '</pre>'; return $content; - case 'admin/content/fillpdf': + case 'admin/structure/fillpdf': if (module_exists('help')) { - return t('See the !link for an explaination on dowloading these forms to PDF', + return t('See the !link for an explanation on dowloading these forms to PDF', array('!link' => l(t('Documentation'), 'admin/help/fillpdf'))); } else { @@ -41,7 +43,7 @@ function fillpdf_menu() { $access = array('administer pdfs'); $items = array(); - // fillpdf&fid=10&nids[]=1&webforms[0][nid]=2&webforms[0][sid]=3 + // fillpdf?fid=10&nids[]=1&webforms[0][nid]=2&webforms[0][sid]=3 $items['fillpdf'] = array( 'page callback' => 'fillpdf_parse_uri', // Can't use access callback. We need the arguments, but they're passed as $GET. Will access-check in fillpdf_merge_pdf @@ -50,42 +52,43 @@ function fillpdf_menu() { ); // ------- Config --------------------------- - $items['admin/config/fillpdf'] = array( + $items['admin/config/media/fillpdf'] = array( 'title' => 'Fill PDF Settings', - 'description' => 'Configure Fill PDF Servelet Information', + 'description' => 'Configure tool to use with Fill PDF', 'page callback' => 'drupal_get_form', 'page arguments' => array('fillpdf_settings'), 'access arguments' => $access, + 'type' => MENU_NORMAL_ITEM, ); // --------- Form ------------------------ - $items['admin/content/fillpdf'] = array( + $items['admin/structure/fillpdf'] = array( 'title' => 'Fill PDF', 'description' => 'Manage your PDFs', 'page callback' => 'drupal_get_form', 'page arguments' => array('fillpdf_forms_admin'), 'access arguments' => $access, ); - $items['admin/content/fillpdf/%'] = array( + $items['admin/structure/fillpdf/%'] = array( 'title' => 'Edit PDF Form', 'page callback' => 'drupal_get_form', 'page arguments' => array('fillpdf_form_edit', 3), 'access arguments' => $access, ); - $items['admin/content/fillpdf/%/delete'] = array( + $items['admin/structure/fillpdf/%/delete'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('fillpdf_form_delete_confirm', 3), 'access arguments' => $access, 'type' => MENU_CALLBACK, ); - $items['admin/content/fillpdf/%/export'] = array( + $items['admin/structure/fillpdf/%/export'] = array( 'title' => t('Export Fill PDF Field Mappings'), 'page callback' => 'fillpdf_form_export', 'page arguments' => array(3), 'access arguments' => $access, 'type' => MENU_CALLBACK, ); - $items['admin/content/fillpdf/%/import'] = array( + $items['admin/structure/fillpdf/%/import'] = array( 'title' => t('Import Fill PDF Field Mappings'), 'page callback' => 'drupal_get_form', 'page arguments' => array('fillpdf_form_import_form', 3), @@ -95,20 +98,20 @@ function fillpdf_menu() { //}else if (is_numeric(arg(4))) { // --------- Fields ------------------------ - $items['admin/content/fillpdf/%/add'] = array( + $items['admin/structure/fillpdf/%/add'] = array( 'title' => 'Add field', 'page callback' => 'fillpdf_field', 'page arguments' => array(4, 3), 'access arguments' => $access, 'type' => MENU_LOCAL_TASK, ); - $items['admin/content/fillpdf/%/edit/%'] = array( + $items['admin/structure/fillpdf/%/edit/%'] = array( 'page callback' => 'fillpdf_field', 'page arguments' => array(4, 3, 5), 'access arguments' => $access, 'type' => MENU_CALLBACK, ); - $items['admin/content/fillpdf/%/delete/%'] = array( + $items['admin/structure/fillpdf/%/delete/%'] = array( 'page callback' => 'drupal_get_form', 'page arguments' => array('fillpdf_field_delete_confirm', 3, 5), 'access arguments' => $access, @@ -147,6 +150,7 @@ function fillpdf_permission() { * @param bool $sample True if you want to populate the form with its own field-names (to get a gist of PDF) */ function fillpdf_pdf_link($fid, $nids = null, $webform_arr = null, $sample = false) { + $nids_uri = $webforms_uri = ""; if (is_array($nids)) { $nids_uri = '&nids[]=' . implode('&nids[]=', $nids); @@ -166,7 +170,7 @@ function fillpdf_pdf_link($fid, $nids = null, $webform_arr = null, $sample = fal } $sample = $sample ? '&sample=true' : ''; - return url('', array('absolute' => true)) . "fillpdf&fid={$fid}{$nids_uri}{$webforms_uri}{$sample}"; + return url('', array('absolute' => true)) . "fillpdf?fid={$fid}{$nids_uri}{$webforms_uri}{$sample}"; } @@ -176,11 +180,22 @@ function fillpdf_pdf_link($fid, $nids = null, $webform_arr = null, $sample = fal * @seealso fillpdf_pdf_link for $_GET params */ function fillpdf_parse_uri() { + // Avoid undefined index warnings, but don't clobber existing values + $_GET += array( + 'nid' => '', + 'nids' => '', + 'webform' => '', + 'webforms' => '', + 'fid' => '', + 'sample' => '' + ); + //this function called multiple times, cut down on DB calls // static $get;if($get)return $get; $sample = $_GET['sample']; // is this just the PDF populated with sample data? $fid = $_GET['fid']; $nids = $webforms = array(); + if ( $_GET['nid'] || $_GET['nids'] ) { $nids = ( $_GET['nid'] ? array($_GET['nid']) : $_GET['nids'] ); } @@ -204,12 +219,12 @@ function fillpdf_merge_pdf($fid, $nids = null, $webform_arr = null, $sample = nu drupal_goto(); } - $fillpdf_info = db_fetch_object(db_query("SELECT title, url FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))); + $fillpdf_info = db_query("SELECT title, url FROM {fillpdf_forms} WHERE fid = :fid", array(':fid' => $fid))->fetch(); // Case 2: Only $fid -- just give them empty pdf if (!empty($nodes) && !empty($webforms) && !is_null($sample)) { $host = url('', array('absolute' => true)); header("Location: " . $host . '/' . $fillpdf_info->url); - exit; + drupal_exit(); } global $user; @@ -247,11 +262,12 @@ function fillpdf_merge_pdf($fid, $nids = null, $webform_arr = null, $sample = nu if (!fillpdf_merge_pdf_access($nodes, $webforms)) { drupal_access_denied(); + drupal_exit(); } $fields = array(); $query = db_query("SELECT * FROM {fillpdf_fields} WHERE fid = :fid", array(':fid' => $fid)); - while ($obj = db_fetch_object($query)) { + foreach ($query as $obj) { // Fill a sample PDF & return if ($sample == 'true') { $fields[$obj->pdf_key] = $obj->pdf_key; @@ -265,7 +281,7 @@ function fillpdf_merge_pdf($fid, $nids = null, $webform_arr = null, $sample = nu // --- node token replacements if (!empty($nodes)) { foreach ($nodes as $node) { - $token = token_replace($obj->value, $type = 'node', $object = $node); + $token = token_replace($obj->value, array('node' => $node)); if ($token) { break; } @@ -353,7 +369,7 @@ function fillpdf_merge_pdf($fid, $nids = null, $webform_arr = null, $sample = nu header('Content-type:application/pdf'); header('Content-disposition:attachment; filename="' . $download_name . '"'); echo $data; - exit; + drupal_exit(); } /** @@ -417,7 +433,7 @@ function fillpdf_execute_merge($method, $fields, $fillpdf, $mode = 'url') { // Generate the file $xfdffile = file_save_data($xfdf, $xfdfname, FILE_EXISTS_RENAME); // Now feed this to pdftk and save the result to a variable - $data = shell_exec('pdftk ' . escapeshellarg($filename) . ' fill_form ' . escapeshellarg($xfdffile) . ' output - flatten drop_xfa'); + $data = shell_exec('pdftk ' . escapeshellarg(drupal_realpath($filename)) . ' fill_form ' . escapeshellarg(drupal_realpath($xfdffile->uri)) . ' output - flatten drop_xfa'); file_delete($xfdffile); if ($mode == 'stream') { file_delete($filename); @@ -440,7 +456,7 @@ function fillpdf_execute_merge($method, $fields, $fillpdf, $mode = 'url') { */ 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>'); + $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); @@ -448,7 +464,7 @@ function fillpdf_parse_pdf($fid) { if ($fillpdf_remote_service) { $result = _fillpdf_xmlrpc_request(DEFAULT_SERVLET_URL, 'parse_pdf_fields', base64_encode($content)); if ($result->error == true) { - drupal_goto("admin/content/fillpdf"); + drupal_goto("admin/structure/fillpdf"); } //after setting error message $fields = $result->data; } @@ -463,7 +479,7 @@ function fillpdf_parse_pdf($fid) { } catch (JavaException $e) { drupal_set_message(java_truncate((string) $e), 'error'); - drupal_goto("admin/content/fillpdf"); //after setting error message + drupal_goto("admin/structure/fillpdf"); //after setting error message } } @@ -480,6 +496,7 @@ function fillpdf_parse_pdf($fid) { $field->fid = $fid; $field->pdf_key = $arr['name']; $field->label = $arr['name']; + $field->value = ''; drupal_write_record('fillpdf_fields', $field); } } @@ -504,7 +521,7 @@ function fillpdf_execute_parse($method, $fillpdf, $mode = 'url') { } // Use exec() to call pdftk (because it will be easier to go line-by-line parsing the output) and pass $content via stdin. Retrieve the fields with dump_data_fields. $output = array(); - exec('pdftk ' . escapeshellarg($filename) . ' dump_data_fields', $output); + exec('pdftk ' . escapeshellarg(drupal_realpath($filename)) . ' dump_data_fields', $output); // Build a simple map of dump_data_fields keys to our own array keys $data_fields_map = array( @@ -535,6 +552,7 @@ function fillpdf_execute_parse($method, $fillpdf, $mode = 'url') { } function _fillpdf_get_file_contents($filepath, $error_goto = null) { + $filepath = drupal_realpath($filepath); if ($error_goto && !(file_exists($filepath))) { drupal_set_message("{$filepath} does not exist. Check your filesystem settings, as well as http://drupal.org/node/764936", 'error'); @@ -548,7 +566,10 @@ function _fillpdf_get_file_contents($filepath, $error_goto = null) { function _fillpdf_xmlrpc_request($url, $method) { $args = func_get_args(); - $result = call_user_func_array('xmlrpc', $args); + array_shift($args); // $url + // Fix up the array for Drupal 7 xmlrpc() function style + $args = array($args[0] => array_slice($args, 1)); + $result = xmlrpc($url, $args); $ret = new stdClass; if (isset($result['error'])) { drupal_set_message($result['error'], 'error'); @@ -573,7 +594,7 @@ function _fillpdf_xmlrpc_request($url, $method) { function fillpdf_get_fields($fid) { $result = db_query('select * from {fillpdf_fields} where fid = %d', $fid); $return = array(); - while ($result_array = db_fetch_array($result)) { + foreach ($result as $result_array) { $return[$result_array['pdf_key']] = array( 'label' => $result_array['label'], 'value' => $result_array['value'], diff --git a/xfdf.inc b/xfdf.inc index d7abdda6b999100f882aa6817eab4334a47af6cc..17fa90e5091135faf9a04715dc66c6ab24f722b9 100644 --- a/xfdf.inc +++ b/xfdf.inc @@ -34,6 +34,7 @@ function escape_string($str) { function print_fields($info) { $fields = array(); + $str = ''; foreach ($info as $field => $val) { $arr = explode('.', $field); $str .= '$fields';