| 1 |
<?php |
<?php |
| 2 |
// $Id: docapi.module,v 1.2.2.8 2008/07/14 07:07:22 bradfordcp Exp $ |
// $Id: docapi.module,v 1.2.2.9 2008/08/20 02:40:58 bradfordcp Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* This module provides an interface for parsing various filetypes |
* This module provides an interface for parsing various filetypes |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
/** |
| 10 |
|
* Implementation of hook_enable(). |
| 11 |
|
*/ |
| 12 |
|
function docapi_enable() { |
| 13 |
|
// Create the upload directory |
| 14 |
|
$path = variable_get('docapi_file_path', file_directory_path() .'/docapi'); |
| 15 |
|
|
| 16 |
|
if (!file_check_directory($path, FILE_CREATE_DIRECTORY)) { |
| 17 |
|
drupal_set_message(t('Could not create the default docapi directory.'), 'error'); |
| 18 |
|
} |
| 19 |
|
else { |
| 20 |
|
drupal_set_message(t('Created the default files directory.')); |
| 21 |
|
} |
| 22 |
|
} |
| 23 |
|
|
| 24 |
/** |
/** |
| 25 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 26 |
*/ |
*/ |
| 48 |
'description' => 'The collection of uploaded documents', |
'description' => 'The collection of uploaded documents', |
| 49 |
'page callback' => 'docapi_library', |
'page callback' => 'docapi_library', |
| 50 |
'page arguments' => array(), |
'page arguments' => array(), |
| 51 |
'access arguments' => array(), |
'access arguments' => array('access document library'), |
| 52 |
); |
); |
| 53 |
|
|
| 54 |
$items['doc/library/import'] = array( |
$items['doc/library/import'] = array( |
| 57 |
'description' => 'Converts a document in the library into a node based on mappings.', |
'description' => 'Converts a document in the library into a node based on mappings.', |
| 58 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 59 |
'page arguments' => array('docapi_library_import_form'), |
'page arguments' => array('docapi_library_import_form'), |
| 60 |
'access arguments' => array(), |
'access arguments' => array('convert documents to node'), |
| 61 |
); |
); |
| 62 |
|
|
| 63 |
$items['doc/library/delete'] = array( |
$items['doc/library/delete'] = array( |
| 66 |
'description' => '', |
'description' => '', |
| 67 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 68 |
'page arguments' => array('docapi_library_remove_confirm_form'), |
'page arguments' => array('docapi_library_remove_confirm_form'), |
| 69 |
'access arguments' => array(), |
'access arguments' => array('delete library documents'), |
| 70 |
); |
); |
| 71 |
|
|
| 72 |
$items['doc/mappings'] = array( |
$items['doc/mappings'] = array( |
| 73 |
'title' => 'Document to Node Mappings', |
'title' => 'Document to Node Maps', |
| 74 |
'description' => 'Lists document to node field relationships', |
'description' => 'Lists document to node field relationships', |
| 75 |
'page callback' => 'docapi_mappings_list', |
'page callback' => 'docapi_mappings_list', |
| 76 |
'page arguments' => array(), |
'page arguments' => array(), |
| 77 |
'access arguments' => array(), |
'access arguments' => array('access document maps'), |
| 78 |
); |
); |
| 79 |
|
|
| 80 |
$items['doc/mappings/add'] = array( |
$items['doc/mappings/add'] = array( |
| 81 |
'title' => 'Create new Mapping', |
'title' => 'Create new Mapping', |
| 82 |
|
'type' => MENU_CALLBACK, |
| 83 |
'description' => 'Creates a new Map between node and document fields', |
'description' => 'Creates a new Map between node and document fields', |
| 84 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 85 |
'page arguments' => array('docapi_mappings_add'), |
'page arguments' => array('docapi_mappings_add'), |
| 86 |
'access arguments' => array(), |
'access arguments' => array('create document maps'), |
| 87 |
|
); |
| 88 |
|
|
| 89 |
|
$items['doc/mappings/remove'] = array( |
| 90 |
|
'title' => 'Remove Mapping', |
| 91 |
|
'type' => MENU_CALLBACK, |
| 92 |
|
'description' => '', |
| 93 |
|
'page callback' => 'drupal_get_form', |
| 94 |
|
'page arguments' => array('docapi_mappings_remove_confirm_form'), |
| 95 |
|
'access arguments' => array('remove document maps'), |
| 96 |
); |
); |
| 97 |
|
|
| 98 |
|
|
| 131 |
function docapi_perm() { |
function docapi_perm() { |
| 132 |
return array( |
return array( |
| 133 |
'import documents to library', |
'import documents to library', |
| 134 |
'create node from document', |
'access document library', |
| 135 |
|
'convert documents to node', |
| 136 |
|
'delete library documents', |
| 137 |
|
'access document maps', |
| 138 |
|
'remove document maps', |
| 139 |
|
'create document maps', |
| 140 |
); |
); |
| 141 |
} |
} |
| 142 |
|
|
| 257 |
$form['docapi_file_settings'] = array( |
$form['docapi_file_settings'] = array( |
| 258 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 259 |
'#title' => t('File Settings'), |
'#title' => t('File Settings'), |
|
'#description' => t('Controls the maximum file size allowed by DocAPI.'), |
|
| 260 |
); |
); |
| 261 |
$form['docapi_file_settings']['docapi_file_path'] = array( |
$form['docapi_file_settings']['docapi_file_path'] = array( |
| 262 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 263 |
'#title' => t('DocAPI file save path'), |
'#title' => t('DocAPI file save path'), |
| 264 |
'#description' => t('The path the location where the imported files will be placed.'), |
'#description' => t('The path the location where the imported files will be placed.'), |
| 265 |
'#default_value' => variable_get('docapi_file_path', file_directory_path() .'/docapi'), |
'#default_value' => variable_get('docapi_file_path', file_directory_path() .'/docapi'), |
| 266 |
); |
); |
|
|
|
|
$form['docapi_plugin_settings'] = array( |
|
|
'#type' => 'fieldset', |
|
|
'#title' => t('Plugin Settings'), |
|
|
'#description' => t(''), |
|
|
); |
|
|
$form['docapi_plugin_settings']['docapi_plugin_autoscan'] = array( |
|
|
'#type' => 'radios', |
|
|
'#title' => t('Auto-scan for plugins'), |
|
|
'#description' => t('If set to yes the plugin will automatically search for new plugins every cron run.'), |
|
|
'#options' => array(t('Yes'), t('No')), |
|
|
'#default_value' => 0, |
|
|
); |
|
| 267 |
|
|
| 268 |
return system_settings_form($form); |
return system_settings_form($form); |
| 269 |
} |
} |
| 272 |
* DocAPI Administration page form validation |
* DocAPI Administration page form validation |
| 273 |
*/ |
*/ |
| 274 |
function docapi_admin_form_validate($form, &$formstate) { |
function docapi_admin_form_validate($form, &$formstate) { |
| 275 |
if (!empty($form['values']['docapi_file_settings']) && !is_dir($form['values']['docapi_file_settings'])) { |
// Check the file directory |
| 276 |
form_set_error('docapi_file_settings', t('Please specify a valid directory. (Note: The directory must exist before setting the value here.)')); |
file_check_directory($form['values']['docapi_file_path'], FILE_CREATE_DIRECTORY, 'docapi_file_path'); |
|
} |
|
| 277 |
} |
} |
| 278 |
|
|
| 279 |
/** |
/** |
| 280 |
* DocAPI Administration page form submission |
* DocAPI Administration page form submission |
| 281 |
*/ |
*/ |
| 282 |
function docapi_admin_form_submit($form, &$form_state) { |
function docapi_admin_form_submit($form, &$form_state) { |
|
// Create the appropriate directories within the path |
|
| 283 |
|
|
| 284 |
} |
} |
| 285 |
|
|
| 349 |
|
|
| 350 |
// Set the path to the tmp file, if a validation error occurs and the user corrects it, they do not need to upload the file again. |
// Set the path to the tmp file, if a validation error occurs and the user corrects it, they do not need to upload the file again. |
| 351 |
if (empty($form_state['values']['docapi_obj_file'])) { |
if (empty($form_state['values']['docapi_obj_file'])) { |
| 352 |
$file = file_save_upload('docapi_file'); |
$file = file_save_upload('docapi_file', array(), variable_get('docapi_file_path', file_directory_path() .'/docapi')); |
| 353 |
form_set_value($form['docapi_obj_file'], $file, $form_state); |
form_set_value($form['docapi_obj_file'], $file, $form_state); |
| 354 |
|
|
| 355 |
} |
} |
| 399 |
|
|
| 400 |
/** |
/** |
| 401 |
* DocAPI Upload document form submission |
* DocAPI Upload document form submission |
|
* |
|
|
* @todo Move the file into the files directory |
|
| 402 |
*/ |
*/ |
| 403 |
function docapi_doc_add_form_submit($form, &$form_state) { |
function docapi_doc_add_form_submit($form, &$form_state) { |
| 404 |
// Begin file processing once it has cleared all of the validation |
// Begin file processing once it has cleared all of the validation |
| 665 |
$fields_cell .= '</ul>'; |
$fields_cell .= '</ul>'; |
| 666 |
$arr_row[] = $fields_cell; |
$arr_row[] = $fields_cell; |
| 667 |
|
|
| 668 |
|
$arr_row[] = l(t('Remove'), 'doc/mappings/remove/'. $row['metadata_map_id']); |
| 669 |
|
|
| 670 |
$arr_rows[] = $arr_row; |
$arr_rows[] = $arr_row; |
| 671 |
} |
} |
| 672 |
|
|
| 673 |
$output .= theme('table', array('Mapping', 'Mimetype', 'Node Type', 'Mappings'), $arr_rows); |
$output .= l('Add', 'doc/mappings/add') .' a new map.'; |
| 674 |
|
$output .= theme('table', array('Mapping', 'Mimetype', 'Node Type', 'Mappings', 'Actions'), $arr_rows); |
| 675 |
|
|
| 676 |
return $output; |
return $output; |
| 677 |
} |
} |
| 1049 |
} |
} |
| 1050 |
|
|
| 1051 |
$form_state['redirect'] = 'doc/mappings'; |
$form_state['redirect'] = 'doc/mappings'; |
| 1052 |
|
} |
| 1053 |
|
|
| 1054 |
|
/** |
| 1055 |
|
* Confirms the removal of a map. |
| 1056 |
|
* |
| 1057 |
|
* @param $matadata_map_id |
| 1058 |
|
* The map to remove |
| 1059 |
|
*/ |
| 1060 |
|
function docapi_mappings_remove_confirm_form($form_state, $metadata_map_id = 0) { |
| 1061 |
|
// Load the filename |
| 1062 |
|
$map_name = ''; |
| 1063 |
|
|
| 1064 |
|
$form = array(); |
| 1065 |
|
|
| 1066 |
|
if ($metadata_map_id != 0) { |
| 1067 |
|
$sql = "SELECT dmm.name |
| 1068 |
|
FROM {docapi_metadata_map} dmm |
| 1069 |
|
WHERE dmm.metadata_map_id = %d"; |
| 1070 |
|
$map_name = db_result(db_query($sql, $metadata_map_id)); |
| 1071 |
|
|
| 1072 |
|
$form['message'] = array( |
| 1073 |
|
'#type' => 'markup', |
| 1074 |
|
'#value' => t('Are you sure you want to remove the map "%map_name"? <br />', array('%map_name' => $map_name)), |
| 1075 |
|
); |
| 1076 |
|
$form['confirm'] = array( |
| 1077 |
|
'#type' => 'submit', |
| 1078 |
|
'#value' => t('Delete'), |
| 1079 |
|
); |
| 1080 |
|
$form['metadata_map_id'] = array( |
| 1081 |
|
'#type' => 'value', |
| 1082 |
|
'#value' => $metadata_map_id, |
| 1083 |
|
); |
| 1084 |
|
|
| 1085 |
|
} |
| 1086 |
|
else { |
| 1087 |
|
drupal_set_message(t('An error has occured, invalid map id supplied.')); |
| 1088 |
|
} |
| 1089 |
|
|
| 1090 |
|
return $form; |
| 1091 |
|
} |
| 1092 |
|
|
| 1093 |
|
/** |
| 1094 |
|
* Removes the document |
| 1095 |
|
*/ |
| 1096 |
|
function docapi_mappings_remove_confirm_form_sumbit($form, &$form_state) { |
| 1097 |
|
$metadata_map_id = $form_state['values']['metadata_map_id']; |
| 1098 |
|
|
| 1099 |
|
// Remove the map and it's mappings |
| 1100 |
|
db_query("DELETE FROM {docapi_metadata_map} WHERE metadata_map_id = %d", $metadata_map_id); |
| 1101 |
|
db_query("DELETE FROM {docapi_metadata_mappings} WHERE metadata_map_id = %d", $metadata_map_id); |
| 1102 |
|
|
| 1103 |
|
$form_state['redirect'] = 'doc/mappings'; |
| 1104 |
} |
} |