Project

General

Profile

Download (46.2 KB) Statistics
| Branch: | Tag: | Revision:
1 9cc1a3e2 Andreas Kohlbecker
<?php
2 e06884e4 Andreas Kohlbecker
// $Id$
3 9cc1a3e2 Andreas Kohlbecker
4 05fe0ad6 Andreas Kohlbecker
/*
5
 * @file
6
 * cdm_dataportal
7 67a4a4c6 Andreas Kohlbecker
 *
8 05fe0ad6 Andreas Kohlbecker
 * Copyright (C) 2007 EDIT
9 67a4a4c6 Andreas Kohlbecker
 * European Distributed Institute of Taxonomy
10 05fe0ad6 Andreas Kohlbecker
 * http://www.e-taxonomy.eu
11 94112bee n.hoffmann
 *
12 05fe0ad6 Andreas Kohlbecker
 */
13
14 8ff851c6 Andreas Kohlbecker
require_once('node_types.php');
15 47a8c0dd Andreas Kohlbecker
require_once('cdm_dataportal.theme.php');
16 9cc1a3e2 Andreas Kohlbecker
17 8ff851c6 Andreas Kohlbecker
18 30c5a6bd Andreas Kohlbecker
define(CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE, 25);
19
20 67a4a4c6 Andreas Kohlbecker
/* ====================== hook implementations ====================== */
21 9cc1a3e2 Andreas Kohlbecker
22
/**
23 bf910101 Andreas Kohlbecker
 * Implementation of hook_help()
24 67a4a4c6 Andreas Kohlbecker
 *
25 9cc1a3e2 Andreas Kohlbecker
 * Display help and module information
26
 * @param section which section of the site we're displaying help
27
 * @return help text for section
28
 */
29
function cdm_dataportal_help($section='') {
30
31 67a4a4c6 Andreas Kohlbecker
  $out = '';
32
  switch ($section) {
33
    case "admin/modules#description":
34
      $out = t("The dataportal publishes CDM data hosted in a CommunityStore on the web.");
35
      break;
36
  }
37
  return $out;
38 9cc1a3e2 Andreas Kohlbecker
}
39
40
41
/**
42 bf910101 Andreas Kohlbecker
 * Implementation of hook_perm()
43 67a4a4c6 Andreas Kohlbecker
 *
44 9cc1a3e2 Andreas Kohlbecker
 * Valid permissions for this module
45
 * @return array An array of valid permissions for the portfolio module
46
 */
47
function cdm_dataportal_perm() {
48 67a4a4c6 Andreas Kohlbecker
  return array(
49 9cc1a3e2 Andreas Kohlbecker
    	'administer cdm_dataportal',
50 ba2bca28 Andreas Kohlbecker
      'cdm_dataportal view notes',
51 67a4a4c6 Andreas Kohlbecker
  //TODO which else permission are required? -> check the WP6 requirements document
52
  );
53 9cc1a3e2 Andreas Kohlbecker
}
54
55
56
/**
57 bf910101 Andreas Kohlbecker
 * Implementation of hook_menu()
58 9cc1a3e2 Andreas Kohlbecker
 */
59
function cdm_dataportal_menu($may_cache) {
60 f5851190 n.hoffmann
  $items = array();
61
  
62 9cc1a3e2 Andreas Kohlbecker
  if ($may_cache) {
63 67a4a4c6 Andreas Kohlbecker
64 9cc1a3e2 Andreas Kohlbecker
    $items[] = array(
65
      'path' => 'admin/settings/cdm_dataportal',
66
      'title' => t('CDM Dataportal'),
67
      'description' => t('Setting for the CDM Dataportal'),
68
      'access' => user_access('administer cdm_dataportal'),
69
      'callback' => 'drupal_get_form',
70
      'callback arguments' => 'cdm_dataportal_settings',
71 a22e3f38 Andreas Kohlbecker
    );
72
    
73 812a9c04 Andreas Kohlbecker
    /*$items[] = array(
74 a22e3f38 Andreas Kohlbecker
      'path' => 'admin/settings/cdm_dataportal/ws',
75
      'title' => t('Web Service'),
76
      'description' => t('Setting for the CDM Dataportal'),
77
      'access' => user_access('administer cdm_dataportal'),
78
      'callback' => 'drupal_get_form',
79
      'callback arguments' => 'cdm_dataportal_settings',
80
      'weight' => 1,
81
      'type' => MENU_DEFAULT_LOCAL_TASK,
82 812a9c04 Andreas Kohlbecker
    );*/
83 a22e3f38 Andreas Kohlbecker
    
84 9cc1a3e2 Andreas Kohlbecker
    $items[] = array(
85
	    'path' => 'cdm_dataportal/names',
86
	    'callback' => 'cdm_dataportal_view_names',
87
	    'access' => true,
88 94112bee n.hoffmann
	    'type' => MENU_CALLBACK,
89 67a4a4c6 Andreas Kohlbecker
    );
90
    // optional callback arguments: page
91 4726aac7 Andreas Kohlbecker
   
92 67a4a4c6 Andreas Kohlbecker
    $items[] = array(
93 4726aac7 Andreas Kohlbecker
      'path' => 'cdm_dataportal/taxon',
94 8ff851c6 Andreas Kohlbecker
      'callback' => 'cdm_dataportal_taxon_page_view',
95 4726aac7 Andreas Kohlbecker
      'access' => true,
96
      'type' => MENU_CALLBACK,
97 0302b693 Andreas Kohlbecker
    // expected callback arguments: uuid
98 4726aac7 Andreas Kohlbecker
    );
99
    
100
    $items[] = array(
101
      'path' => 'cdm_dataportal/reference',
102
      'callback' => 'cdm_dataportal_view_reference',
103
      'access' => true,
104
      'type' => MENU_CALLBACK,
105 0302b693 Andreas Kohlbecker
    // expected callback arguments: uuid
106 67a4a4c6 Andreas Kohlbecker
    );
107 ee99abea Andreas Kohlbecker
    
108 46a52efe Andreas Kohlbecker
    $items[] = array(
109
      'path' => 'cdm_dataportal/reference/list',
110
      'callback' => 'cdm_dataportal_view_reference_list',
111
      'access' => true,
112
      'type' => MENU_CALLBACK,
113 0302b693 Andreas Kohlbecker
    // expected callback arguments: uuid
114 46a52efe Andreas Kohlbecker
    );
115
    
116 2cd9a3d6 Andreas Kohlbecker
    $items[] = array(
117
      'path' => 'cdm_dataportal/media',
118
      'callback' => 'cdm_dataportal_view_media',
119
      'access' => true,
120
      'type' => MENU_CALLBACK,
121 0302b693 Andreas Kohlbecker
    // expected callback arguments: uuid, mediarepresentation_uuid, part_uuid or part#
122 2cd9a3d6 Andreas Kohlbecker
    );
123
    
124 2447830d Andreas Kohlbecker
    $items[] = array(
125
      'path' => 'cdm_dataportal/search',
126
      'callback' => 'cdm_dataportal_view_search_advanced',
127
      'access' => true,
128
      'type' => MENU_CALLBACK,
129
    );
130
    
131 ee99abea Andreas Kohlbecker
    $items[] = array(
132
      'path' => 'cdm_dataportal/search/taxon',
133
      'callback' => 'cdm_dataportal_view_search_taxon',
134
      'access' => true,
135 94112bee n.hoffmann
      'type' => MENU_CALLBACK,
136 f5851190 n.hoffmann
    );
137 ee99abea Andreas Kohlbecker
    
138 67a4a4c6 Andreas Kohlbecker
    $items[] = array(
139 05fe0ad6 Andreas Kohlbecker
      'path' => 'cdm/xml2json',
140
      'callback' => 'cdm_view_xml2json',
141
      'access' => true,
142 94112bee n.hoffmann
      'type' => MENU_CALLBACK,
143 67a4a4c6 Andreas Kohlbecker
    );
144 f5851190 n.hoffmann
    
145
    
146 4726aac7 Andreas Kohlbecker
  } else {
147
    // may not cache
148
        // --- local tasks for Taxon
149
    if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
150
      
151
       $items[] = array(
152
      'path' => 'cdm_dataportal/taxon/'.arg(2),
153 0d127818 Andreas Kohlbecker
      'title' => theme('cdm_taxonpage_tab', 'General'),
154 8ff851c6 Andreas Kohlbecker
      'callback' => 'cdm_dataportal_taxon_page_view',
155 4726aac7 Andreas Kohlbecker
      'access' => true,
156
      'type' => MENU_CALLBACK,
157 3cf0dec2 Andreas Kohlbecker
      'weight' => 1,
158 24b09d7c Andreas Kohlbecker
      'callback arguments' => array(arg(2), "description")
159 4726aac7 Andreas Kohlbecker
      // expected callback arguments: name_uuid
160
      );
161
      
162
      $items[] = array(
163
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/description',
164 0d127818 Andreas Kohlbecker
      'title' => theme('cdm_taxonpage_tab', 'General'),
165 8ff851c6 Andreas Kohlbecker
      'callback' => 'cdm_dataportal_taxon_page_view',
166 4726aac7 Andreas Kohlbecker
      'access' => true,
167
      'type' => MENU_DEFAULT_LOCAL_TASK,
168 3cf0dec2 Andreas Kohlbecker
      'weight' => 2,
169 4726aac7 Andreas Kohlbecker
      'callback arguments' => array(arg(2), "description")
170
      // expected callback arguments: name_uuid
171
      );
172
      
173
      $items[] = array(
174 3cf0dec2 Andreas Kohlbecker
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/synonymy',
175 0d127818 Andreas Kohlbecker
      'title' => theme('cdm_taxonpage_tab', 'Synonymy'),
176 8ff851c6 Andreas Kohlbecker
      'callback' => 'cdm_dataportal_taxon_page_view',
177 4726aac7 Andreas Kohlbecker
      'access' => true,
178
      'type' => MENU_LOCAL_TASK,
179 3cf0dec2 Andreas Kohlbecker
      'weight' => 3,
180
      'callback arguments' => array(arg(2), "synonymy")
181 4726aac7 Andreas Kohlbecker
      // expected callback arguments: name_uuid
182
      );
183
      
184
      $items[] = array(
185 3cf0dec2 Andreas Kohlbecker
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/images',
186 0d127818 Andreas Kohlbecker
      'title' => theme('cdm_taxonpage_tab', 'Images'),
187 8ff851c6 Andreas Kohlbecker
      'callback' => 'cdm_dataportal_taxon_page_view',
188 4726aac7 Andreas Kohlbecker
      'access' => true,
189
      'type' => MENU_LOCAL_TASK,
190 3cf0dec2 Andreas Kohlbecker
      'weight' => 4,
191
      'callback arguments' => array(arg(2), "images")
192 4726aac7 Andreas Kohlbecker
      // expected callback arguments: name_uuid
193
      );
194
    } 
195 f5851190 n.hoffmann
  }
196
  
197 2189699f Andreas Kohlbecker
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
198 6611904c Andreas Kohlbecker
  //drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
199
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
200 f5851190 n.hoffmann
  
201 9cc1a3e2 Andreas Kohlbecker
  return $items;
202 c0ac3382 Andreas Kohlbecker
  
203 9cc1a3e2 Andreas Kohlbecker
}
204
205 d946105e Andreas Kohlbecker
/**
206
 * Implementation of hook_block()
207 67a4a4c6 Andreas Kohlbecker
 *
208 d946105e Andreas Kohlbecker
 * Provides the following blocks:
209
 *  0: list of links useful during development
210
 *
211
 * @param String $op
212
 * @param int $delta
213
 */
214
function cdm_dataportal_block($op='list', $delta=0) {
215
  // listing of blocks, such as on the admin/block page
216
  if ($op == "list") {
217 8738c560 f.revilla
    //$block[0]["info"] = t("CDM DataPortal DevLinks");
218 67a4a4c6 Andreas Kohlbecker
    $block[1]["info"] = t("CDM DataPortal Credits");
219 ee99abea Andreas Kohlbecker
    $block[2]["info"] = t("CDM Search Taxa");
220 8738c560 f.revilla
    //$block[3]["info"] = t("CDM Filters");
221
    $block[4]["info"] = t("CDM Dataportal Print");
222 d946105e Andreas Kohlbecker
    return $block;
223
  }
224
  else if ($op == 'view') {
225
    switch($delta){
226 67a4a4c6 Andreas Kohlbecker
      case 1:
227
        $block['subject'] = t('Credits');
228 c0ac3382 Andreas Kohlbecker
        $block['content'] = theme('cdm_credits');
229
        return $block;
230 ee99abea Andreas Kohlbecker
      case 2:
231
        $block['subject'] = t('Search Taxa');
232
        $block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
233 8934f97c Andreas Kohlbecker
        $block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
234 ee99abea Andreas Kohlbecker
        return $block;
235 8738c560 f.revilla
      case 4:
236
      	$block['subject'] = t('Print this page');
237
      	$block['content'] = theme('cdm_print_button');;
238
      	return $block;   
239
     }
240 d946105e Andreas Kohlbecker
  }
241
}
242
243 9cc1a3e2 Andreas Kohlbecker
244 47a8c0dd Andreas Kohlbecker
/**
245
 * Implementation of hook_validate()
246
 *
247
 * @param $element
248
 */
249 afbbba9e Andreas Kohlbecker
function cdm_dataportal_settings_validate($form_id, $form_values){
250 812a9c04 Andreas Kohlbecker
  
251 afbbba9e Andreas Kohlbecker
  if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
252 67a4a4c6 Andreas Kohlbecker
    form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
253
  }
254 812a9c04 Andreas Kohlbecker
255
  $cdm_webservice_url_changed = variable_get('cdm_webservice_url', '') != $form_values['cdm_webservice_url'];
256
  
257 24b09d7c Andreas Kohlbecker
  $cdm_secUuid_default_changed = variable_get('cdm_secUuid_default', '') != $form_values['cdm_secUuid_default'];
258
  
259
  if ($cdm_webservice_url_changed || $cdm_secUuid_default_changed) {
260
    
261
    _cdm_dataportal_set_currentSecUuid($form_values['cdm_secUuid_default']);
262 812a9c04 Andreas Kohlbecker
    // reset all cdm related data stored in the session
263 6e1ec3a4 Andreas Kohlbecker
    // cdm_dataportal_session_clear($form_values['cdm_webservice_url']); // cdm_webservice_url is not further stored here
264 fa68c2c5 Andreas Kohlbecker
    // clear the cdm webservice cache
265
    cache_clear_all(NULL, 'cache_cdm_ws');
266 6e1ec3a4 Andreas Kohlbecker
    // better clear secref_cache since i can not be sure if the cache has not be used during this response
267
    cdm_api_secref_cache_clear();
268 812a9c04 Andreas Kohlbecker
  }
269 5d53a642 Andreas Kohlbecker
  if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
270
    cache_clear_all(NULL, 'cache_cdm_ws');
271 6e1ec3a4 Andreas Kohlbecker
    // better clear secref_cache since i can not be sure if the cache has not be used during this response
272
    cdm_api_secref_cache_clear();
273 5d53a642 Andreas Kohlbecker
  }
274 812a9c04 Andreas Kohlbecker
  
275 47a8c0dd Andreas Kohlbecker
}
276
277 94112bee n.hoffmann
/*
278 a27e2588 Andreas Kohlbecker
function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
279
  $_SESSION['cdm'] = null;
280
  if(is_string($cdm_ws_uri_update)){
281
    $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
282
  }
283
}
284
285
function cdm_dataportal_session_validate(){
286
287
  if(!isset($_SESSION['cdm']['ws_uri'])){
288
    $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
289
  } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
290
    cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
291
  }
292
}
293 44e02685 Andreas Kohlbecker
*/
294 812a9c04 Andreas Kohlbecker
295 2447830d Andreas Kohlbecker
function cdm_dataportal_search_taxon_form($advancedForm = false){
296
  
297
  $preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
298 fa650011 Andreas Kohlbecker
  $preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
299 abd0ab13 Andreas Kohlbecker
  $preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
300
  $preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
301 8934f97c Andreas Kohlbecker
  $tdwg_level_select =  (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
302 fa650011 Andreas Kohlbecker
  $selected_areas =  (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
303 ee99abea Andreas Kohlbecker
  
304 6611904c Andreas Kohlbecker
  $url = 'cdm_dataportal/search/taxon';
305
  $form['#method'] = 'get';
306
  $form['#process'] = array('cdm_dataportal_search_process' => array());
307
  $form['#action'] = url($url, NULL, NULL, true);
308
  
309 24b09d7c Andreas Kohlbecker
  $form['query'] = array(
310 2447830d Andreas Kohlbecker
    '#delta' => 0,
311 ee99abea Andreas Kohlbecker
    '#type' => 'textfield',
312
    '#size' => 20,
313 304cdf42 Andreas Kohlbecker
    '#attributes' => array('title' => t('Enter the name or part of a name you wish to search for. The asterisk  character * can always be used as wildcard')),
314 2447830d Andreas Kohlbecker
    '#value' => $preset_query,
315 6611904c Andreas Kohlbecker
  );
316
  
317 2447830d Andreas Kohlbecker
  $form['search'] = array(
318
      '#delta' => 1,
319
      '#tree' => true,
320
      //'#type' => $advancedForm ? 'fieldset': 'hidden',
321
      '#title' => t('Options')
322
    );
323 8934f97c Andreas Kohlbecker
    
324 9ee2882b Andreas Kohlbecker
   $form['search']['tree'] = array(
325 8934f97c Andreas Kohlbecker
    '#delta' => -1,
326
    '#type' => 'hidden',
327 9ee2882b Andreas Kohlbecker
    '#value' => variable_get('cdm_taxonomictree_uuid', false)
328 8934f97c Andreas Kohlbecker
  );
329 2447830d Andreas Kohlbecker
  
330 6611904c Andreas Kohlbecker
  
331
  // clean URL get forms breaks if we don't give it a 'q'.
332
  if (!(bool)variable_get('clean_url', '0')) {
333 2447830d Andreas Kohlbecker
    $form['search']['q'] = array(
334
      '#delta' => -1,
335 6611904c Andreas Kohlbecker
      '#type' => 'hidden',
336
      '#value' => $url,
337
      '#name' => 'q',
338
    );
339
  }
340 2447830d Andreas Kohlbecker
  
341
  $form['search']['pageSize'] = array(
342
      '#delta' => -1,
343
      '#type' => 'hidden',
344
      '#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
345
    );
346
347
  if($advancedForm){
348 8934f97c Andreas Kohlbecker
    // general search parameters
349
    $form['search']['doTaxa'] = array(
350 2447830d Andreas Kohlbecker
      '#delta' => 2,
351
      '#type' => 'checkbox',
352
      '#title' => t('Search for accepted taxa'),
353
      '#value' => $preset_doTaxa
354 8934f97c Andreas Kohlbecker
    );
355
    $form['search']['doSynonyms'] = array(
356 2447830d Andreas Kohlbecker
      '#delta' => 3,
357
      '#type' => 'checkbox',
358
      '#title' => t('Search for synonyms'),
359
      '#value' => $preset_doSynonyms
360 8934f97c Andreas Kohlbecker
    );
361
    $form['search']['doTaxaByCommonNames'] = array(
362 2447830d Andreas Kohlbecker
      '#delta' => 4,
363
      '#type' => 'checkbox',
364
      '#title' => t('Search for common names'),
365
      '#value' => $preset_doTaxaByCommonNames
366 8934f97c Andreas Kohlbecker
    );
367
     
368
    // Geographic Range
369
    $form['search']['geographic_range'] = array(
370
      '#type' => 'fieldset',
371
      '#delta' => 5,
372
      '#tree' => true,
373
      '#title' => t('Geographic range'),
374
    );
375
    
376
    $form['search']['geographic_range']['tdwg_level_select'] = array(
377
    '#type' => 'radios',
378 7e29aa4f Andreas Kohlbecker
    '#title' => t('Select a TDWG distribution level and code'),
379 8934f97c Andreas Kohlbecker
    '#default_value' => $tdwg_level_select,
380
    '#options' => array(
381
      t('TDWG level-1, i.e. a continent'),
382
      t('TDWG level-2'),
383
      t('TDWG level-3, i.e. a country'),
384
      t('TDWG level-4')
385
      )     
386
    );
387
    $tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
388
    $tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
389
    $tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
390
    $tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
391
    
392
    $tdwg_js = '';
393
    foreach($tdwg as $key=>$tdwg_level){
394
      $tdwgOptions = array();
395
      $tdwgOptionsSelected = array();
396
      foreach($tdwg_level as $area){
397
        $representation = $area->representations[0];
398
        $tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
399 fa650011 Andreas Kohlbecker
        if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
400
          $tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
401 8934f97c Andreas Kohlbecker
        }
402
      }
403 abd0ab13 Andreas Kohlbecker
      asort($tdwgOptions);
404 8934f97c Andreas Kohlbecker
      $form['search']['geographic_range']['tdwg_level_'.$key] = array(
405
        '#type' => 'select',
406
        '#title'         => t('TDWG level').' '.$key,
407
        '#default_value' => $tdwgOptionsSelected,
408
        '#multiple' => TRUE, 
409
        '#options' => $tdwgOptions
410
      );   
411 abd0ab13 Andreas Kohlbecker
      $tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ?  '.show()' : '.hide()'). ";\n";  
412 8934f97c Andreas Kohlbecker
    }
413
414
    drupal_add_js(
415
    "$(document).ready(function(){
416
    
417
      $(\"input[@name='search[geographic_range][tdwg_level_select]']\").change( 
418
        function(event){
419
          var selectId = $(\"input[@name='search[geographic_range][tdwg_level_select]']:checked\").val();
420
          var i;
421
          for(i = 0; i < 4; i++){
422
            if(selectId == i){
423
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1) ).parent().fadeIn('slow');
424
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
425
            } else {
426
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).parent().fadeOut('slow');
427
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
428
            }
429
          }
430
        }
431
      );
432
      
433
     $tdwg_js
434
    });",
435
    'inline');
436
      
437 2447830d Andreas Kohlbecker
  } else {
438
    $form['search']['doTaxa'] = array(
439
      '#delta' => -2,
440
      '#type' => 'hidden',
441
      '#value' => 1
442
     );
443
      $form['search']['doSynonyms'] = array(
444
      '#delta' => -3,
445
      '#type' => 'hidden',
446
      '#value' => 1
447
     );
448
     $form['search']['doTaxaByCommonNames'] = array(
449
      '#delta' => -4,
450
      '#type' => 'hidden',
451
      '#value' => 1
452
     );
453
  }
454
  
455
   $form['submit'] = array(
456
  '#delta' => 9,
457
  '#type' => 'submit',
458
  '#name' => '',
459
  '#value' => t('Search')
460
  );
461
  
462 ee99abea Andreas Kohlbecker
  return $form;
463
}
464
465 2447830d Andreas Kohlbecker
function cdm_dataportal_search_taxon_form_advanced(){
466
  return cdm_dataportal_search_taxon_form(true);
467
}
468
469 24b09d7c Andreas Kohlbecker
/**
470
 * Implementation #process method call, see form_builder()
471
 * <p>
472
 * Removes Drupal internal form elements from query
473
 * @param $form
474
 * @return unknown_type
475
 */
476 6611904c Andreas Kohlbecker
function cdm_dataportal_search_process($form) {
477
  unset($form['form_id']);
478
  unset($form['form_token']);
479
  return $form;
480
}
481
482
/**
483
 * Filters $_REQUEST by a list of valid request  parameters and also sets defaults if required.
484
 * returns the processed request parameters submitted by the search form.
485
 */
486 24b09d7c Andreas Kohlbecker
function cdm_dataportal_search_form_request(){
487 daba333b Andreas Kohlbecker
488 fa650011 Andreas Kohlbecker
    
489
  $form_params = array();
490
  array_deep_copy($_REQUEST['search'], $form_params);
491
  $form_params['query'] =  trim($_REQUEST['query']);
492
493 8934f97c Andreas Kohlbecker
  // split of  geographic range
494
  if(isset($_REQUEST['search']['geographic_range'])){
495
    $geographicRange = $_REQUEST['search']['geographic_range'];
496 fa650011 Andreas Kohlbecker
    // remove 
497
    unset($form_params['geographic_range']);
498 8934f97c Andreas Kohlbecker
  }
499 24b09d7c Andreas Kohlbecker
  
500 8934f97c Andreas Kohlbecker
  // add geographic range
501
  if($geographicRange){
502
    $form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
503
    for($i = 1; $i < 5; $i++){
504
      if(isset($geographicRange['tdwg_level_'.$i])){
505
        $form_params['area'] = $geographicRange['tdwg_level_'.$i];
506
      }
507
    }
508
  }
509
  
510
  // store in session
511 81df545f Andreas Kohlbecker
  $_SESSION['cdm']['search'] = $form_params;
512 24b09d7c Andreas Kohlbecker
  
513 6611904c Andreas Kohlbecker
  return $form_params;
514
}
515
  
516
517 81df545f Andreas Kohlbecker
/* UNREACHABLE since action of form directly links to view
518 ee99abea Andreas Kohlbecker
function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
519
  
520
  $_SESSION['cdm']['search'] = $form_values;
521 94112bee n.hoffmann
  //return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
522
  return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
523 cacc1bbf Andreas Kohlbecker
  //$paramstr = compose_url_prameterstr($form_values);
524
  //return url('/cdm_dataportal/search/taxon/', $paramstr);
525 ee99abea Andreas Kohlbecker
}
526 6611904c Andreas Kohlbecker
*/
527 9cc1a3e2 Andreas Kohlbecker
/* ====================== menu callback functions ====================== */
528
529
/**
530
 * Generate main administration form.
531
 *
532
 * @return
533
 *   An array containing form items to place on the module settings page.
534
 */
535
function cdm_dataportal_settings(){
536
537 2e748209 Andreas Kohlbecker
  $form = cdm_api_settings_form();
538 80047c07 Andreas Kohlbecker
539 2e748209 Andreas Kohlbecker
  //TODO: settings are still incomplete, compare with trunk/dataportal/inc/config_default.php.inc
540 6ee322a7 Andreas Kohlbecker
  $form['cdm_dataportal'] = array(
541
      '#type' => 'fieldset',
542
      '#title' => t('CDM DataPortal'),
543
      '#collapsible' => FALSE,
544
      '#collapsed' => TRUE,
545
  );
546 30c5a6bd Andreas Kohlbecker
  
547 2447830d Andreas Kohlbecker
//  $form['cdm_dataportal']['secuuid_widget'] = array(
548
//    '#type' => 'select_secuuid', // => will be themed by theme_select_secuuid(...)
549
//    '#title' => t('Default Concept References'),
550
//    '#description'   => t('The default \'sensu\' reference to start the CDM DataPortal with. Per user choices are possible and may override this value.'),
551
//    '#varname' => 'cdm_secUuid_default',
552
//    '#multiple' => false
553
//  );
554
  
555
  $taxonTrees = cdm_ws_get(CDM_WS_TAXONOMY);
556
  foreach($taxonTrees as $tree){
557
    $taxonomicTreeOptions[$tree->uuid] = $tree->titleCache;  
558
  }
559
  $form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
560
    '#type' => 'select',
561
    '#title'         => t('Available taxonomic views'),
562
    '#default_value' => variable_get('cdm_taxonomictree_uuid', false),
563
    '#options' => $taxonomicTreeOptions,
564
    '#description'   => t('Select a taxonomic view for this webservice.')
565
  );
566 ba2bca28 Andreas Kohlbecker
  
567 ef374f09 Andreas Kohlbecker
//  $form['cdm_dataportal']['DEBUG']= array(
568
//    '#value' => '<pre>'.print_r($taxonTrees, true).'</pre>'
569
//  );
570 94112bee n.hoffmann
  
571 9d98a3c0 n.hoffmann
    
572
  //------------------ FEATURE TREE --------------------//
573
  
574
  $form['cdm_dataportal']['feature_tree'] = array(
575
    '#type' => 'fieldset',
576
    '#title' => t('Feature Tree'),
577
    '#collapsible' => TRUE,
578
    '#collapsed' => TRUE,
579
  );
580
  
581 24b09d7c Andreas Kohlbecker
    $form['cdm_dataportal']['feature_tree']['cdm_dataportal_featuretree_uuid'] = array(
582 94112bee n.hoffmann
    '#type' => 'select',
583 d93dad11 n.hoffmann
    '#title'         => t('Available FeatureTrees'),
584 24b09d7c Andreas Kohlbecker
    '#default_value' => variable_get('cdm_dataportal_featuretree_uuid', false),
585
	  '#options' => _get_feature_trees(),
586
    '#description'   => t('Select a FeatureTree for this webservice.'
587
          //.' If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
588
          )
589 ba2bca28 Andreas Kohlbecker
  );
590 39ceedd6 n.hoffmann
  
591 d93dad11 n.hoffmann
  //------------------ LAYOUT --------------------//
592
  
593 39ceedd6 n.hoffmann
  $form['cdm_dataportal']['layout'] = array(
594
    '#type' => 'fieldset',
595
    '#title' => t('Layout'),
596 9d98a3c0 n.hoffmann
    '#collapsible' => TRUE,
597 39ceedd6 n.hoffmann
    '#collapsed' => TRUE,
598 ff6a8ea7 Andreas Kohlbecker
  );
599
  
600 70fb5e15 Andreas Kohlbecker
  $form['cdm_dataportal']['layout']['cdm_taxonname_type'] = array(
601 ff6a8ea7 Andreas Kohlbecker
    '#type' => 'select',
602
    '#title'         => t('Taxon name type'),
603
    '#default_value' => variable_get('cdm_taxonname_type', 'BotanicalName'),
604
    '#options' => array( 'BotanicalName'=>t('BotanicalName'), 'ZoologicalName'=>t('ZoologicalName')),
605
    '#description'   => t('')
606 39ceedd6 n.hoffmann
  );
607
  
608
  $form['cdm_dataportal']['layout']['cdm_dataportal_nomref_in_title'] = array(
609
    '#type' => 'checkbox',
610 72568f3e Andreas Kohlbecker
    '#title' => t('Hide full nomenclatural reference in title'),
611 39ceedd6 n.hoffmann
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', 1),
612 72568f3e Andreas Kohlbecker
    '#description' => t('Uncheck this, if you want the title of a taxon page consisting of name and author plus publication year only.
613 39ceedd6 n.hoffmann
    					If not checked, the first homotypic taxon is a repetition of the accepted taxon with
614
    					the full nomenclatural reference.')
615
  );
616 d93dad11 n.hoffmann
  
617
  $form['cdm_dataportal']['layout']['cdm_dataportal_display_name_relations'] = array(
618
    '#type' => 'checkbox',
619
    '#title' => t('Show name relations of accepted taxa on taxon page'),
620
    '#default_value' => variable_get('cdm_dataportal_display_name_relations', 1),
621
    '#description' => t('')
622 4726aac7 Andreas Kohlbecker
  );
623
  
624 24b09d7c Andreas Kohlbecker
  $form['cdm_dataportal']['layout']['cdm_dataportal_name_relations_skiptype_basionym'] = array(
625
    '#type' => 'checkbox',
626
    '#title' => t('Exclude the basionym relationship type from the taxon page'),
627
    '#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
628
    '#description' => t('')
629
  );
630
  
631 4726aac7 Andreas Kohlbecker
  $form['cdm_dataportal']['layout']['cdm_dataportal_taxonpage_tabs'] = array(
632
    '#type' => 'checkbox',
633 1c01d44e Andreas Kohlbecker
    '#title' => t('Tabbed taxon page'),
634 4726aac7 Andreas Kohlbecker
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
635 24b09d7c Andreas Kohlbecker
    '#description' => t('Split the taxon page into individual tabs for description, images, synonymy')
636 d93dad11 n.hoffmann
  );
637
  
638
  $form['cdm_dataportal']['layout']['cdm_dataportal_search_items_on_page'] = array(
639
    '#type' => 'textfield',
640
    '#title' => t('Search Page Size'),
641 30c5a6bd Andreas Kohlbecker
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
642 24b09d7c Andreas Kohlbecker
    '#description' => t('Number of Names to display per page in search results.')
643
  );
644
  
645
  $form['cdm_dataportal']['layout']['cdm_dataportal_descriptions_separated'] = array(
646
    '#type' => 'checkbox',
647
    '#title' => t('Separate Desriptions'),
648
    '#default_value' => variable_get('cdm_dataportal_descriptions_separated', 0),
649
    '#description' => t('By default corresponding elements of different descriptions are joined together'
650
                        .' into a common section per feature (i.e. type of description).'
651
                        .' Check this box to allow displaying all descriptions separately.')
652 9fcd1980 Andreas Kohlbecker
  );
653
  
654 70fb5e15 Andreas Kohlbecker
  $options = cdm_rankVocabulary_as_option();
655
  array_unshift($options, '-- DISABLED --');
656
  $form['cdm_dataportal']['layout']['image_hide_rank'] =  array(
657
    '#type'          => 'select',
658
    '#title'         => t('Hide Images for Taxa above'),
659
    '#default_value' => variable_get('image_hide_rank', '0'),
660
    '#options'       => $options,
661
    '#description'   => t(''),
662
  );
663
  
664
  // --- find taxa ---- //
665 784a4314 Andreas Kohlbecker
   $form['cdm_dataportal']['layout']['findtaxa'] = array(
666
    '#type' => 'fieldset',
667
    '#title' => t('Search Taxa'),
668
    '#collapsible' => TRUE,
669
    '#collapsed' => TRUE,
670
  );
671
  
672 9834a411 Andreas Kohlbecker
  //variable_get('', 1);
673
  $form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_show_taxon_thumbnails'] = array(
674 784a4314 Andreas Kohlbecker
    '#type' => 'checkbox',
675 9834a411 Andreas Kohlbecker
    '#title' => t('Show media thumbnails for accepted taxa'),
676
    '#default_value' => variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1),
677 784a4314 Andreas Kohlbecker
    '#description' => t('')
678
  );
679
  
680 9834a411 Andreas Kohlbecker
  $form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_show_synonym_thumbnails'] = array(
681 784a4314 Andreas Kohlbecker
    '#type' => 'checkbox',
682 8ff851c6 Andreas Kohlbecker
    '#title' => t('Show media thumbnails for synonyms'),
683 9834a411 Andreas Kohlbecker
    '#default_value' => variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0),
684
    '#description' => t('')
685
  );
686
  
687
  //   $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
688
  $form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_show_thumbnail_captions'] = array(
689
    '#type' => 'checkbox',
690
    '#title' => t('Show captions under thumbnails'),
691
    '#default_value' => variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 1),
692 784a4314 Andreas Kohlbecker
    '#description' => t('')
693
  );
694
  
695
   $form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_media_maxextend'] = array(
696
    '#type' => 'textfield',
697
    '#title' => t('Maximum extend of Images'),
698
    '#default_value' => variable_get('cdm_dataportal_findtaxa_media_maxextend', 120),
699
    '#description' => t('')
700
  );
701
  
702
  $form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_media_cols'] = array(
703
    '#type' => 'textfield',
704
    '#title' => t('Number of columns'),
705
    '#default_value' => variable_get('cdm_dataportal_findtaxa_media_cols', 3),
706
    '#description' => t('')
707
  );
708
  
709
  $form['cdm_dataportal']['layout']['findtaxa']['cdm_dataportal_findtaxa_media_maxRows'] = array(
710
    '#type' => 'textfield',
711
    '#title' => t('Maximum number of rows'),
712
    '#default_value' => variable_get('cdm_dataportal_findtaxa_media_maxRows', 1),
713
    '#description' => t('')
714
  );
715
  
716
  
717 9fcd1980 Andreas Kohlbecker
 
718 e4f58fa1 n.hoffmann
  //---------------- GEOSERVICE ----------------//
719
  
720
  $form['cdm_dataportal']['geoservice'] = array(
721
    '#type' => 'fieldset',
722
    '#title' => t('Geoservice'),
723 9d98a3c0 n.hoffmann
    '#collapsible' => TRUE,
724 e4f58fa1 n.hoffmann
    '#collapsed' => TRUE,
725 784a4314 Andreas Kohlbecker
  );
726
  
727
  $form['cdm_dataportal']['geoservice']['cdm_dataportal_map_openlayers'] = array(
728
    '#type' => 'checkbox',
729
    '#title' => t('OpenLayers Viewer'),
730
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
731
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning.')
732 e4f58fa1 n.hoffmann
  );
733
  
734
  $form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_access_point'] = array(
735
    '#type' => 'textfield',
736
    '#title' => t('Geoservice Access Point'),
737
    '#default_value' => variable_get('cdm_dataportal_geoservice_access_point', ''),
738
    '#description' => t('Base URL of the geoservice to be used by this portal')
739
  );
740
  
741
  $form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_display_width'] = array(
742
    '#type' => 'textfield',
743
    '#title' => t('Geoservice Display Width'),
744
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
745
    '#description' => t('Width of the image generated by geoservice')
746
  );
747
  
748
  $form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_bounding_box'] = array(
749
    '#type' => 'textfield',
750 9d47d187 Andreas Kohlbecker
    '#title' => t('Fixed Geoservice Bounding Box'),
751 e4f58fa1 n.hoffmann
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
752 9d47d187 Andreas Kohlbecker
    '#description' => t('Define urrounding of area to be displayed in maps. Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the distribution area.')
753 9fcd1980 Andreas Kohlbecker
  );
754
  
755
   //cdm_dataportal_geoservice_labels_on
756
  $form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_labels_on'] = array(
757
    '#type' => 'checkbox',
758
    '#title' => t('Display Country Labels'),
759
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
760
    '#description' => t('Check this if you like country names to be displayed in the maps. ')
761 2447830d Andreas Kohlbecker
  );
762
  
763
   //cdm_dataportal_geoservice_legend_on
764
  $form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_legend_on'] = array(
765
    '#type' => 'checkbox',
766
    '#title' => t('Display a map legend'),
767
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
768
    '#description' => t('Check this if you like a legend to be displayed with the maps. ')
769 6499563a f.revilla
  );
770
  
771
   //cdm_dataportal_geoservice_legend_on
772
  $form['cdm_dataportal']['geoservice']['cdm_dataportal_geoservice_map_caption'] = array(
773
    '#type' => 'textfield',
774 0302b693 Andreas Kohlbecker
    '#title' => t('Map Caption'),
775 6499563a f.revilla
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
776 0302b693 Andreas Kohlbecker
    '#description' => t('Define a caption for the map.')
777 e4f58fa1 n.hoffmann
  );
778 a22e3f38 Andreas Kohlbecker
  
779 e38d39d6 Andreas Kohlbecker
  return system_settings_form($form);
780
}
781
782
/**
783
 * Implementation of hook_elements().
784
 */
785
function cdm_dataportal_elements() {
786
  $type['select_secuuid'] = array(
787 94112bee n.hoffmann
    '#input' => TRUE,
788 e38d39d6 Andreas Kohlbecker
    '#process' => array('cdm_dataportal_select_secuuid_expand' => array()),
789
    //'#validate' => array('cdm_dataportal_select_secuuid_validate' => array()),
790
    //'#default_value' => array(),
791 e18349d4 Andreas Kohlbecker
  );
792 e38d39d6 Andreas Kohlbecker
  return $type;
793
}
794
795
/*
796 94112bee n.hoffmann
 *
797 e38d39d6 Andreas Kohlbecker
 */
798
function cdm_dataportal_select_secuuid_expand($element){
799 e18349d4 Andreas Kohlbecker
  
800 e38d39d6 Andreas Kohlbecker
  $element['#tree'] = FALSE;
801
  
802
  // any value submitted?
803
  if(isset($element['#post'][$element['#varname']])){
804
    $selected_values = $element['#post'][$element['#varname']];
805
  } else {
806
    // use those store in drupal
807
    $selected_values = variable_get( $element['#varname'], array());
808
  }
809
  if(!is_array($selected_values)){
810
    $selected_values = array($selected_values);
811
  }
812
  $options = array();
813
  foreach($selected_values as $secUuid){
814 44e02685 Andreas Kohlbecker
    $options[$secUuid] = cdm_taxontree_secRefTitle_for($secUuid);
815 e38d39d6 Andreas Kohlbecker
  }
816 e18349d4 Andreas Kohlbecker
817 e38d39d6 Andreas Kohlbecker
  $element[$element['#varname']] =  array(
818
    '#type' => 'select',
819
    '#options' => $options,
820
    '#default_value' => array_values($options),
821
    '#size' => $element['#multiple'] ? 12 : 2,
822
    '#multiple' => $element['#multiple'],
823
  );
824
  return $element;
825
}
826
827
828
829 9cc1a3e2 Andreas Kohlbecker
/**
830
 * Displays a list of the known taxonomic names. Long lists are split up into multiple pages
831
 *
832 55e5b62d Andreas Kohlbecker
 * TODO: parameters are still preliminar
833 9cc1a3e2 Andreas Kohlbecker
 * @param String $page page number to diplay defaults to page 1
834
 * @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
835
 */
836 afbbba9e Andreas Kohlbecker
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
837 67a4a4c6 Andreas Kohlbecker
838 ee99abea Andreas Kohlbecker
  $request_params  = array(
839 94112bee n.hoffmann
    'q' => $beginsWith,
840 ee99abea Andreas Kohlbecker
         //'sec' = '',
841
         //'higherTaxa' => getFiters(),
842
          // 'matchAnywhere' => false, // default is false
843 94112bee n.hoffmann
    'page' => $page,
844
    'onlyAccepted' => $onlyAccepted,
845 ee99abea Andreas Kohlbecker
    'pagesize' => 20  /*$_SESSION['cdm']['namelist_pagesize'] */);
846
  
847 30c5a6bd Andreas Kohlbecker
  $taxonPager = cdm_ws_find(CDM_WS_FIND_TAXA, $request_params);
848 67a4a4c6 Andreas Kohlbecker
  /*
849
   * FIXME the filter for accepted names will be a form element, thus this widget
850
   * should be generated via form api preferably as block
851
   */
852
  //$out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
853
  //$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
854 30c5a6bd Andreas Kohlbecker
  $out .= theme('cdm_listof_taxa', $taxonPager);
855 67a4a4c6 Andreas Kohlbecker
  return $out;
856 9cc1a3e2 Andreas Kohlbecker
}
857
858 4726aac7 Andreas Kohlbecker
function cdm_dataportal_view_reference($uuid, $arg2 = null){
859 30c5a6bd Andreas Kohlbecker
    $reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
860
    return theme('cdm_reference_page', $reference);
861 4726aac7 Andreas Kohlbecker
}
862
863 46a52efe Andreas Kohlbecker
function cdm_dataportal_view_reference_list($pageNumber){
864 30c5a6bd Andreas Kohlbecker
    $referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
865 46a52efe Andreas Kohlbecker
    return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
866
}
867
868 b09e63fd Andreas Kohlbecker
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
869 5424c3b5 f.revilla
   	$media = cdm_ws_get(CDM_WS_MEDIA, $mediaUuid);
870 b09e63fd Andreas Kohlbecker
   return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
871 2cd9a3d6 Andreas Kohlbecker
}
872
873 9cc1a3e2 Andreas Kohlbecker
/**
874
 * The taxon page gives detailed information on a taxon, it shows:
875
 *  - Taxon name
876 67a4a4c6 Andreas Kohlbecker
 *  - Full list of synonyms homotypic synonyms on top, followed by the
877
 *    heterotypic and finally followed by misapplied names.
878 afbbba9e Andreas Kohlbecker
 *    The list is ordered historically.
879 8ff851c6 Andreas Kohlbecker
 *  - All description associated with the taxon.
880 9cc1a3e2 Andreas Kohlbecker
 *
881 8ff851c6 Andreas Kohlbecker
 * @param $uuid
882
 * @param $chapter name of the part to display,
883
 *         valid values are: 'description', 'images', 'synonymy', 'all'
884
 * @return unknown_type
885 9cc1a3e2 Andreas Kohlbecker
 */
886 8ff851c6 Andreas Kohlbecker
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all'){
887 53a13220 Andreas Kohlbecker
  
888
    // display the page for the taxon defined by $uuid
889 8ff851c6 Andreas Kohlbecker
    $taxonpage = cdm_dataportal_taxon_view($uuid, $chapter); 
890
    return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
891
}
892
893
/**
894
 * @param $uuid
895
 * @param $chapter name of the part to display,
896
 *         valid values are: 'description', 'images', 'synonymy', 'all'
897
 * @return unknown_type
898
 */
899
function cdm_dataportal_taxon_view($uuid, $chapter = 'all'){
900
  
901 30c5a6bd Andreas Kohlbecker
    $taxon = cdm_ws_get(CDM_WS_TAXON, $uuid);
902
    if(!$taxon){
903 a27e2588 Andreas Kohlbecker
      drupal_set_title(t('Taxon does not exist'));
904 94112bee n.hoffmann
      return false;
905 a27e2588 Andreas Kohlbecker
    }
906 30c5a6bd Andreas Kohlbecker
    _cdm_dataportal_set_currentSecUuid($taxon->sec->uuid);
907 72568f3e Andreas Kohlbecker
    
908 8ff851c6 Andreas Kohlbecker
    $taxonpage->title = theme('cdm_taxon_page_title', $taxon);
909
    $taxonpage->content = theme('cdm_taxon_page_general', $taxon, $chapter);
910
911
    return $taxonpage;
912 53a13220 Andreas Kohlbecker
}
913 67a4a4c6 Andreas Kohlbecker
914 8ff851c6 Andreas Kohlbecker
915 2447830d Andreas Kohlbecker
function cdm_dataportal_view_search_advanced(){
916
  
917
  drupal_set_title(t('Advanced Search'));
918
  
919
  $searchForm = cdm_dataportal_search_taxon_form(true);
920
    
921
  return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
922
  
923
}
924
925 ee99abea Andreas Kohlbecker
/**
926 94112bee n.hoffmann
 *
927 ee99abea Andreas Kohlbecker
 * future extensions to meet palmweb mockup requirements:
928
 *  - habitat
929
 *  - uses
930
 *  - conservation status
931
 *  - locality / tdwg region
932
 */
933 24b09d7c Andreas Kohlbecker
function cdm_dataportal_view_search_taxon(){
934
  
935 64c1bd2d n.hoffmann
  $_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
936 daba333b Andreas Kohlbecker
937 6611904c Andreas Kohlbecker
  $request_params = cdm_dataportal_search_form_request();
938 8934f97c Andreas Kohlbecker
  $taxonPager = cdm_ws_get(CDM_WS_FIND_TAXA, null, queryString($request_params));
939 24b09d7c Andreas Kohlbecker
  
940 daba333b Andreas Kohlbecker
  $search_params = $_REQUEST;
941
  unset($search_params['q']);
942
  return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
943 ee99abea Andreas Kohlbecker
}
944
945 05fe0ad6 Andreas Kohlbecker
function cdm_view_xml2json(){
946
  $file = arg(2);
947
  $datastr = get_content(variable_get('cdm_webservice_url', '').$file);
948
  return  xml2json::transformXmlStringToJson($datastr);
949 fa97cd20 Andreas Kohlbecker
}
950
951 47a8c0dd Andreas Kohlbecker
/* ====================== other functions ====================== */
952
953 ec0c70d2 Andreas Kohlbecker
/**
954
 * Enter description here...
955
 *
956
 * @param String $uuid the UUID of the taxon
957
 * @return the URL
958
 */
959 24b09d7c Andreas Kohlbecker
function path_to_taxon($uuid){
960
  if(!$uuid) return false;
961 ec0c70d2 Andreas Kohlbecker
  return 'cdm_dataportal/taxon/'.$uuid;
962 ad497c90 Andreas Kohlbecker
}
963
964 24b09d7c Andreas Kohlbecker
function path_to_reference($uuid){
965
  if(!$uuid) return false;
966
  return 'cdm_dataportal/reference/'.$uuid;
967
}
968
969 b09e63fd Andreas Kohlbecker
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
970 2cd9a3d6 Andreas Kohlbecker
  if(!$uuid) return false;
971 b09e63fd Andreas Kohlbecker
  $out = 'cdm_dataportal/media/'.$uuid;
972
  if($representaion_uuid){
973
    $out .= '/'.$representaion_uuid;
974
    if($partId !== false){
975
      $out .= '/'.$partId;
976
    }
977
  }
978
  return $out;
979 2cd9a3d6 Andreas Kohlbecker
}
980
981 70fb5e15 Andreas Kohlbecker
/**
982
 * Compares thisRank with thatRank.
983
 * Returns a negative integer, zero, or a positive integer 
984
 * as the of thisRank is higher than, equal to, or lower than thatRank.
985
 * e.g: 
986
 * <ul>
987
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
988
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
989
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
990
 * </ul>
991
 * <p>
992
 * This compare logic of the underlying webservice is the
993
 * <b>inverse logic</b> of the the one implemented in 
994
 * java.lang.Comparable#compareTo(java.lang.Object)
995
 * @param $thisRankUuid
996
 * @param $thatRankUuid
997
 * @return  a negative integer, zero, or a positive integer 
998
 * as the thisRank is lower than, equal to, or higher than thatRank 
999
 */
1000
function rank_compare($thisRankUuid, $thatRankUuid){
1001
    $result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
1002
    return $result->Integer;
1003
}
1004
1005 24b09d7c Andreas Kohlbecker
function uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null){
1006
   $acceptedPath = path_to_taxon($acceptedUuid);
1007
   return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid);
1008
}
1009
1010 ec0c70d2 Andreas Kohlbecker
/**
1011
 * Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
1012
 * If the taggename if empty the fullname will be returned.
1013
 *
1014 30c5a6bd Andreas Kohlbecker
 * @param unknown_type $Name or TreeNode
1015 67a4a4c6 Andreas Kohlbecker
 * @return string
1016 ec0c70d2 Andreas Kohlbecker
 */
1017 30c5a6bd Andreas Kohlbecker
function cdm_dataportal_shortname_of($name){
1018 67a4a4c6 Andreas Kohlbecker
1019 30c5a6bd Andreas Kohlbecker
  $nameStr = '';
1020 fa68c2c5 Andreas Kohlbecker
  // get all tagged text tokens of the scientific name
1021 30c5a6bd Andreas Kohlbecker
  foreach($name->taggedTitle as $tagtxt){
1022 fa68c2c5 Andreas Kohlbecker
      if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
1023 30c5a6bd Andreas Kohlbecker
        $nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
1024 fa68c2c5 Andreas Kohlbecker
      }
1025
  }
1026 30c5a6bd Andreas Kohlbecker
  $nameStr = trim($nameStr);
1027
  if($nameStr){
1028 bd4696a1 n.hoffmann
    // do not return short names for these
1029 30c5a6bd Andreas Kohlbecker
    if($nameStr == 'Incertae sedis' || $nameStr ==  'Nomina excludenda'){
1030
      return $nameStr;
1031 bd4696a1 n.hoffmann
    }
1032 30c5a6bd Andreas Kohlbecker
    if($pos = stripos($nameStr, ' ')){
1033
      return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos);
1034 ec0c70d2 Andreas Kohlbecker
    } else {
1035 30c5a6bd Andreas Kohlbecker
      return $nameStr;
1036 ec0c70d2 Andreas Kohlbecker
    }
1037
  } else {
1038 30c5a6bd Andreas Kohlbecker
    return $name->titleCache;
1039 ec0c70d2 Andreas Kohlbecker
  }
1040
}
1041 47a8c0dd Andreas Kohlbecker
1042 af7422cb n.hoffmann
/**
1043
 * TODO Add Comments. I don't get what
1044
 *
1045 44e02685 Andreas Kohlbecker
 * @param UUID $secUuid
1046 67a4a4c6 Andreas Kohlbecker
 */
1047 27c1d8ec Andreas Kohlbecker
function _cdm_dataportal_set_currentSecUuid($secUuid){
1048 5ab248ac Andreas Kohlbecker
 
1049 0d127818 Andreas Kohlbecker
  // do not save in session but in database
1050 af7422cb n.hoffmann
  
1051
  if(is_array($secUuid)){
1052
    $secUuid = $secUuid[0];
1053
  }
1054
  if(!$secUuid){
1055
    variable_set('cdm_currentSecRef', null);
1056
  } else {
1057 30c5a6bd Andreas Kohlbecker
    $secRef = cdm_ws_get(CDM_WS_REFERENCE, $secUuid);
1058 24b09d7c Andreas Kohlbecker
    if(isset($secRef)){
1059
      variable_set('cdm_currentSecRef', (array)($secRef));
1060 af7422cb n.hoffmann
    }
1061
  }
1062
  
1063 27c1d8ec Andreas Kohlbecker
}
1064
1065 af7422cb n.hoffmann
/**
1066
 * TODO
1067
 * This will not work with multiple instances of the dataportal running
1068
 * under the same host as there is only one session for all instances.
1069
 * In case you switch instances with the same client, you will definitely
1070
 * run into trouble.
1071
 * Also this is not handling multiple secs.
1072
 *
1073
 *
1074 24b09d7c Andreas Kohlbecker
 * returns the current secRef array.
1075 27c1d8ec Andreas Kohlbecker
 * If the according session variable is not jet set the default
1076 812a9c04 Andreas Kohlbecker
 * as configured in the setting is used otherwise null.
1077 94112bee n.hoffmann
 *
1078 f5b3d74e Andreas Kohlbecker
 * currentSecRef['uuid']
1079
 * currentSecRef[....
1080 27c1d8ec Andreas Kohlbecker
 *
1081
 * @return array
1082
 */
1083 1dbc28d9 Andreas Kohlbecker
function _cdm_dataportal_currentSecRef_array(){
1084 24b09d7c Andreas Kohlbecker
1085 3cf0dec2 Andreas Kohlbecker
  // do not look in session but in database
1086 24b09d7c Andreas Kohlbecker
  if( variable_get('cdm_currentSecRef', null) == null){
1087 af7422cb n.hoffmann
     $secUuid = variable_get('cdm_secUuid_default', null);
1088
     _cdm_dataportal_set_currentSecUuid($secUuid);
1089
  }
1090
  return variable_get('cdm_currentSecRef', null);
1091
  
1092 67a4a4c6 Andreas Kohlbecker
}
1093 d93dad11 n.hoffmann
1094
/**
1095 9ee2882b Andreas Kohlbecker
 * Check if a taxon is accepted by the current taxonomic tree
1096 d93dad11 n.hoffmann
 *
1097 9ee2882b Andreas Kohlbecker
 * @param Taxon $taxon
1098
 * @return true if $taxon is accepted, false otherwise
1099 d93dad11 n.hoffmann
 */
1100 9ee2882b Andreas Kohlbecker
1101 30c5a6bd Andreas Kohlbecker
function _cdm_dataportal_acceptedByCurrentView($taxon){
1102 81df545f Andreas Kohlbecker
  
1103 9ee2882b Andreas Kohlbecker
  //$current_secref = _cdm_dataportal_currentSecRef_array();
1104
  $defaultTreeUuid = variable_get('cdm_taxonomictree_uuid', false);
1105
  if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){
1106
    foreach($taxon->taxonNodes as $node){
1107
      if($node->taxonomicTree == $defaultTreeUuid) {
1108
        return true;
1109
      }
1110
    }
1111
  }
1112
  return false;
1113 81df545f Andreas Kohlbecker
}
1114 44e02685 Andreas Kohlbecker
1115 daba333b Andreas Kohlbecker
/**@Deprecated
1116
 * 
1117
 */
1118
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
1119 cacc1bbf Andreas Kohlbecker
  $pstr = '';
1120
  foreach($parameters as $key=>$value){
1121 daba333b Andreas Kohlbecker
    if(is_array($value)){
1122
      
1123
    } else {
1124
       $pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);    
1125
    }
1126 cacc1bbf Andreas Kohlbecker
  }
1127
  return $pstr;
1128 d93dad11 n.hoffmann
}
1129
1130
function _get_feature_trees(){
1131
   $feature_trees = array();
1132
   
1133
   // set tree that contains all features
1134
   $feature_trees['0'] = 'No FeatureTree';
1135
   
1136 30c5a6bd Andreas Kohlbecker
   // get features from database
1137 24b09d7c Andreas Kohlbecker
   $persisted_trees = cdm_ws_get(CDM_WS_FEATURETREES);
1138 d93dad11 n.hoffmann
   if(is_array($persisted_trees)){
1139
     foreach($persisted_trees as $featureTree){
1140
       
1141
       $featureLabels = array();
1142 24b09d7c Andreas Kohlbecker
       foreach ($featureTree->root->children as $featureNode){
1143 30c5a6bd Andreas Kohlbecker
         $featureLabels[] = $featureNode->feature->representation_L10n;
1144 d93dad11 n.hoffmann
       }
1145
       
1146
       $feature_trees[$featureTree->uuid] = implode(", ", $featureLabels);
1147
       
1148
     }
1149
   }
1150
   return $feature_trees;
1151 cacc1bbf Andreas Kohlbecker
}
1152 6f4dd14a Andreas Kohlbecker
1153 24b09d7c Andreas Kohlbecker
1154
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
1155
  //TODO implement admin user interface to replace swicth statement 
1156
  //     preliminar solution: using themes 
1157
  
1158
  $template = theme('get_nameRenderTemplate', $renderPath);
1159
  
1160
  if(!is_array($template)){
1161
    switch($renderPath){
1162
      case 'list_of_taxa':
1163
      case  'acceptedFor':
1164
      case 'taxon_page_synonymy':
1165
      case 'typedesignations':
1166
      case 'taxon_page_title':
1167
      case 'na': $template = array(
1168 8a60c8fc Andreas Kohlbecker
          'namePart' => array('#uri'=>true),
1169 24b09d7c Andreas Kohlbecker
          //'authorshipPart' => true,
1170
        );
1171
        break;
1172
      case 'nar': $template = array(
1173 8a60c8fc Andreas Kohlbecker
          'namePart' => array('#uri'=>true),
1174 24b09d7c Andreas Kohlbecker
          //'authorshipPart' => true,
1175 8a60c8fc Andreas Kohlbecker
          'referencePart' => array('#uri'=>true),
1176 24b09d7c Andreas Kohlbecker
          'microreferencePart' => true,
1177
        );
1178
        break;
1179
      default: $template = array(
1180 8a60c8fc Andreas Kohlbecker
          'namePart' => array('#uri'=>true),
1181 24b09d7c Andreas Kohlbecker
          'authorshipPart' => true,
1182 8a60c8fc Andreas Kohlbecker
          'referencePart' => array('#uri'=>true),
1183 24b09d7c Andreas Kohlbecker
          'microreferencePart' => true,
1184
          'statusPart' => true,
1185
          'descriptionPart' => true
1186
        );
1187
    }
1188
  }
1189 70fb5e15 Andreas Kohlbecker
  
1190
  if($nameLink && isset($template['nameAuthorPart']['#uri'])){
1191
    $template['nameAuthorPart']['#uri'] = $nameLink;
1192
  } else{
1193
    unset($template['nameAuthorPart']['#uri']);
1194
  }
1195
  
1196 8a60c8fc Andreas Kohlbecker
  if($nameLink && isset($template['namePart']['#uri'])){
1197
    $template['namePart']['#uri'] = $nameLink;
1198
  } else{
1199
    unset($template['namePart']['#uri']);
1200 24b09d7c Andreas Kohlbecker
  }
1201 70fb5e15 Andreas Kohlbecker
  
1202 8a60c8fc Andreas Kohlbecker
  if($refenceLink && isset($template['referencePart']['#uri'])){
1203
    $template['referencePart']['#uri'] = $refenceLink;
1204
  }else{
1205
    unset($template['referencePart']['#uri']);
1206 24b09d7c Andreas Kohlbecker
  }
1207 70fb5e15 Andreas Kohlbecker
  
1208 24b09d7c Andreas Kohlbecker
  return $template;
1209
}
1210
1211
function get_partDefinition($taxonNameType){
1212
  //TODO implement admin user interface to allow specify the partdefinitions for any type
1213
  //     preliminar solution: using themes 
1214
  
1215
  $partdef = theme('get_partDefinition', $taxonNameType);
1216
  
1217
  if(!is_array($partdef)){  
1218
    switch($taxonNameType){
1219
      case 'ZoologicalName': $partdef = array(
1220
        'namePart' => array(
1221
          'name' => true,
1222
        ),
1223
        'referencePart' => array(
1224
          'authorTeam' => true
1225
        ),
1226
        'microreferencePart' => array(
1227
          'microreference' => true,
1228
        ),
1229
        'statusPart' => array(
1230
          'status' => true,
1231
        ),
1232
        'descriptionPart' => array(
1233
          'description' => true,
1234
        ),
1235
      );
1236
      break;
1237
      case 'BotanicalName': $partdef = array(
1238
        'namePart' => array(
1239
          'name' => true
1240
        ),
1241
        'authorTeamPart' => array(
1242
          'authorTeam' => true,   
1243
        ),
1244
        'referencePart' => array(
1245
          'reference' => true      
1246
        ),
1247
        'microreferencePart' => array(
1248
          'microreference' => true,
1249
        ),
1250
        'statusPart' => array(
1251
          'status' => true,
1252
        ),
1253
        'descriptionPart' => array(
1254
          'description' => true,
1255
        ),
1256
      );
1257
      break;
1258
      default: $partdef = array(
1259
        'namePart' => array(
1260
          'name' => true,
1261
        ),
1262
        'authorTeamPart' => array(
1263
          'authorTeam' => true,   
1264
        ),
1265
        'referencePart' => array(
1266
          'reference' => true      
1267
        ),
1268
        'microreferencePart' => array(
1269
          'microreference' => true,
1270
        ),
1271
        'statusPart' => array(
1272
          'status' => true,
1273
        ),
1274
        'descriptionPart' => array(
1275
          'description' => true,
1276
        ),
1277
      );
1278
    }
1279
  }
1280
  return $partdef;
1281
}
1282 46edbba8 f.revilla
1283
/**
1284
 * 
1285
 * @param $media
1286
 * @param $priority
1287
 * @return unknown_type
1288
 * TODO rename to read_media_metadata() and move to *.module
1289
 */
1290
function cdm_read_media_metadata($media, $priority = 1){
1291
1292
    $metadata_caption = array('title' => '', 
1293
                              'artist' => '', 
1294
                              'rights', 
1295
                              'location', 
1296
                              'filename' => '', 
1297
                              'mediacreated' => '', 
1298
                              'description' => '');
1299
1300
    //getting the media metadata
1301
    $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
1302
1303
    //filling the title, artist, copyright depending on the priority 1=>files 2=>CDM
1304
    switch($priority){
1305
        case 1:
1306
            //filling the title
1307
            if ($media_metadata->Headline)
1308
            $metadata_caption['title'] = $media_metadata->Headline;
1309
            elseif ($media->titleCache){
1310
                $metadata_caption['title'] = $media->titleCache;
1311
                if ($media->description_L10n)
1312
                $metadata_caption['title'] .= ' - ' . $media->description_L10n;
1313
            }
1314
            
1315
            //filling the artist
1316
            if ($media_metadata->Artist)
1317
                 $metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
1318
            elseif ($media->artist->titleCache)
1319
                 $metadata_caption['artist'] = $media->artist->titleCache;
1320
    
1321
            //filling out with the copyright info
1322
            $metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
1323
                                                'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
1324
            if ($media_metadata->Copyright)
1325
                 $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
1326
            elseif ($media->rights){
1327
                foreach($media->rights as $right){
1328
                    switch($right->term->uuid){
1329
                        case UUID_RIGHTS_LICENCE:
1330
                            $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
1331
                            $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
1332
                            $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
1333
                            $metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
1334
                            break;
1335
                        case UUID_RIGHTS_COPYRIGHT:
1336
                            $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
1337
                            break;
1338
                    }
1339
                }
1340
            }
1341
            else
1342
            $metadata_caption['rights']['agentNames'][] = '';
1343
1344
            break;
1345
1346
        case 2:
1347
            //filling the title
1348
            if ($media->titleCache){
1349
                $metadata_caption['title'] = $media->titleCache;
1350
                if ($media->description_L10n)
1351
                $metadata_caption['title'] .= ' - ' . $media->description_L10n;
1352
            }
1353
            elseif ($media_metadata->Headline)
1354
                $metadata_caption['title'] = $media_metadata->Headline;
1355
            break;
1356
    }
1357
    //filling the description (though there is no description in the db???)
1358
    $metadata_caption['description'] = $media->description_L10n;
1359
1360
    //filling the location
1361
    $metadata_caption['location'] = array();
1362
    $metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
1363
    $metadata_caption['location']['city'] = $media_metadata->City;
1364
    $metadata_caption['location']['province'] = $media_metadata->Province;
1365
    $metadata_caption['location']['country'] = $media_metadata->Country;
1366
1367
1368
    //filling the filename
1369
    if(isset($media->representations[0]->parts[0]->uri)){
1370
        $fileUri = $media->representations[0]->parts[0]->uri;
1371
        $filename = substr($fileUri, strrpos($fileUri, "/")+1);
1372
        $metadata_caption['filename'] = $filename;
1373
    }
1374
    else
1375
    $metadata_caption['filename'] = '';
1376
    
1377
    //filling the creation date
1378
    $metadata_caption['mediacreated'] = $media->created;
1379
1380
    //returned value
1381
    return $metadata_caption;
1382
}