1 |
37c1f19c
|
l.morris
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* menu callback
|
5 |
|
|
*/
|
6 |
|
|
function dwca_export_deliver_archive(){
|
7 |
|
|
if(file_exists('public://dwca.zip')){
|
8 |
|
|
file_transfer('public://dwca.zip', array(
|
9 |
|
|
'Content-Type' => 'application/zip'
|
10 |
|
|
));
|
11 |
|
|
}else{
|
12 |
|
|
drupal_set_message('The Darwincore Arhive for this site has not yet been created');
|
13 |
|
|
drupal_goto('/');
|
14 |
|
|
}
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
/**
|
18 |
|
|
* Form function, called by drupal_get_form()
|
19 |
|
|
* in dwca_export_menu().
|
20 |
|
|
*/
|
21 |
|
|
function dwca_export_config_form($form, &$form_state){
|
22 |
|
|
global $base_url;
|
23 |
|
|
$form['dwca_export_info'] = array(
|
24 |
|
|
'#markup' => '<p>For general information on the DarwinCore Archive format please refer to ' . l('GBIF - Standards and Tools - Darwin Core Archives', 'http://www.gbif.org/informatics/standards-and-tools/publishing-data/data-standards/darwin-core-archives/') . '</p>'
|
25 |
|
|
);
|
26 |
|
|
$form['dwca_export_execute'] = array(
|
27 |
|
|
'#markup' => '<p>The DarwinCore Archive export can be downloaded from ' . l(url('dwca.zip', array(
|
28 |
|
|
'absolute' => TRUE
|
29 |
|
|
)), 'dwca.zip') . '</p>'
|
30 |
|
|
);
|
31 |
|
|
$form['dwca_export_view_mapping'] = dwca_export_select_view_form();
|
32 |
|
|
$form['#submit'][] = 'dwca_export_config_form_submit';
|
33 |
|
|
return system_settings_form($form);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
function dwca_export_select_view_form(){
|
37 |
|
|
$views = array(
|
38 |
|
|
'#type' => 'fieldset',
|
39 |
|
|
'#title' => t('View to file mapping')
|
40 |
|
|
); //'#tree' => TRUE,
|
41 |
|
|
foreach(variable_get(FILE_MAP, 'dwca_export_archive_descriptor_file_map') as $dwca_filename => $view_data){
|
42 |
|
|
if($dwca_filename == 'description'){
|
43 |
|
|
$views[$dwca_filename] = array(
|
44 |
|
|
'#type' => 'fieldset',
|
45 |
|
|
'#title' => t('DESCRIPTIVE DATA TYPES'),
|
46 |
|
|
'#weight' => 3,
|
47 |
|
|
'#collapsible' => TRUE,
|
48 |
|
|
'#collapsed' => TRUE,
|
49 |
|
|
//'#prefix' => '<table>',
|
50 |
|
|
//'#suffix' => '</table>',
|
51 |
|
|
'#tree' => TRUE
|
52 |
|
|
);
|
53 |
|
|
foreach($view_data as $dwca_filename_inner => $view_data_inner){
|
54 |
|
|
$views[$dwca_filename][$dwca_filename_inner] = array(
|
55 |
|
|
'#type' => 'textfield',
|
56 |
|
|
'#title' => t($dwca_filename . '_' . $dwca_filename_inner),
|
57 |
|
|
'#default_value' => $view_data_inner['view_name'],
|
58 |
|
|
'#size' => 60,
|
59 |
|
|
'#description' => t('specify view for ' . $dwca_filename_inner)
|
60 |
|
|
); //'#prefix' => '<tr>',
|
61 |
|
|
//'#suffix' => '</tr>',
|
62 |
|
|
//TODO: Change collaped discription form to table, layout using <td> and <tr> e.g. try 3 description types per row
|
63 |
|
|
}
|
64 |
|
|
}else{
|
65 |
|
|
$views[$dwca_filename] = array(
|
66 |
|
|
'#type' => 'textfield',
|
67 |
|
|
'#title' => t($dwca_filename),
|
68 |
|
|
'#default_value' => $view_data['view_name'],
|
69 |
|
|
'#size' => 60,
|
70 |
|
|
'#description' => t('specify view for ' . $dwca_filename)
|
71 |
|
|
);
|
72 |
|
|
}
|
73 |
|
|
}
|
74 |
|
|
return $views;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
/**
|
78 |
|
|
* Submit function for the above form.
|
79 |
|
|
*/
|
80 |
|
|
function dwca_export_config_form_submit($form, &$form_state){
|
81 |
|
|
$variables = $form_state['input'];
|
82 |
|
|
$save_variables = '';
|
83 |
|
|
$dwca_export_archive_descriptor_file_map = variable_get(FILE_MAP);
|
84 |
|
|
foreach($variables as $key => $value){
|
85 |
|
|
if(array_key_exists($key, $dwca_export_archive_descriptor_file_map)){
|
86 |
|
|
$dwca_export_archive_descriptor_file_map[$key]['view_name'] = $value;
|
87 |
|
|
//$save_variables .= '<p>' . $key . ' ' . $value . '</p>';
|
88 |
|
|
}else{
|
89 |
|
|
$description_key = 'description';
|
90 |
|
|
if(array_key_exists($description_key, $dwca_export_archive_descriptor_file_map)){
|
91 |
|
|
//get the inner array containing the different description data types
|
92 |
|
|
$description_map = $dwca_export_archive_descriptor_file_map[$description_key];
|
93 |
|
|
if(array_key_exists($key, $description_map)){
|
94 |
|
|
$dwca_export_archive_descriptor_file_map[$description_key][$key]['view_name'] = $value;
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
variable_del(FILE_MAP);
|
100 |
|
|
variable_set(FILE_MAP, $dwca_export_archive_descriptor_file_map);
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/**
|
104 |
|
|
* Validate function for the above form.
|
105 |
|
|
*
|
106 |
|
|
* Reports an error if view name entered by the user does not exist in the
|
107 |
|
|
* database.
|
108 |
|
|
*/
|
109 |
|
|
function dwca_export_config_form_validate($form, &$form_state){
|
110 |
|
|
$variables = $form_state['input'];
|
111 |
|
|
$dwca_export_archive_descriptor_file_map = variable_get(FILE_MAP);
|
112 |
|
|
$view_names = array();
|
113 |
|
|
$missing_view_names = '';
|
114 |
|
|
$missing_view = false;
|
115 |
|
|
foreach($variables as $key => $value){
|
116 |
|
|
//TODO: Check whether the views for the inner array cotaining all the description views exist
|
117 |
|
|
if(array_key_exists($key, $dwca_export_archive_descriptor_file_map)){
|
118 |
|
|
$view = views_get_view($value);
|
119 |
|
|
// check whether there is a view named with this value
|
120 |
|
|
if(!$view){
|
121 |
|
|
$view_names[] = $value;
|
122 |
|
|
$missing_view_names .= $value . ', ';
|
123 |
|
|
$missing_view = true;
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
if($missing_view){
|
128 |
|
|
form_set_error('', t('VIEW(S) ' . $missing_view_names . ' NOT FOUND. Please input another view name.'));
|
129 |
|
|
}
|
130 |
|
|
}
|