Project

General

Profile

Download (58.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
/*
5
 * @file
6
 * cdm_dataportal
7
 *
8
 * Copyright (C) 2007 EDIT
9
 * European Distributed Institute of Taxonomy 
10
 * http://www.e-taxonomy.eu
11
 * 
12
 * The contents of this file are subject to the Mozilla Public License Version 1.1
13
 * See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
14
 */
15

    
16
require_once('node_types.php');
17

    
18
require_once('theme/cdm_dataportal.common.theme');
19
require_once('theme/cdm_dataportal.descriptions.theme');
20
require_once('theme/cdm_dataportal.media.theme');
21
require_once('theme/cdm_dataportal.occurrence.theme');
22
require_once('theme/cdm_dataportal.page.theme');
23
require_once('theme/cdm_dataportal.taxon.theme');
24
require_once('theme/cdm_dataportal.name.theme');
25
require_once('theme/cdm_dataportal.references.theme');
26

    
27
require_once('classes/footnotemanager.php');
28
require_once('classes/footnote.php');
29
require_once('classes/renderhints.php');
30

    
31
define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
32
define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
33
define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
34

    
35
/* gallery variables */
36
$gallery_settings = array(
37
    "cdm_dataportal_show_taxon_thumbnails" => 1,
38
    "cdm_dataportal_show_synonym_thumbnails" => 0,
39
    "cdm_dataportal_show_thumbnail_captions" => 1,
40
    "cdm_dataportal_media_maxextend" => 120,
41
    "cdm_dataportal_media_cols" => 3,
42
    "cdm_dataportal_media_maxRows" => 0);
43
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
44
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
45
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
46
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
47

    
48

    
49

    
50

    
51
function getGallerySettings($gallery_config_form_name){
52
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
53
  	return variable_get($gallery_config_form_name, $default_values);
54
}
55

    
56

    
57

    
58
function _add_js_progressbar(){
59
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.progressbar/js/jquery.progressbar.js');
60
}
61

    
62

    
63
/* ====================== hook implementations ====================== */
64

    
65
/**
66
 * Implementation of hook_help()
67
 *
68
 * Display help and module information
69
 * @param section which section of the site we're displaying help
70
 * @return help text for section
71
 */
72
function cdm_dataportal_help($section='') {
73

    
74
	$out = '';
75
	switch ($section) {
76
		case "admin/modules#description":
77
			$out = t("The dataportal publishes CDM data hosted in a CommunityStore on the web.");
78
			break;
79
	}
80
	return $out;
81
}
82

    
83

    
84
/**
85
 * Implementation of hook_perm()
86
 *
87
 * Valid permissions for this module
88
 * @return array An array of valid permissions for the portfolio module
89
 */
90
function cdm_dataportal_perm() {
91
	return array(
92
    	'administer cdm_dataportal',
93
      'cdm_dataportal view notes',
94
	//TODO which else permission are required? -> check the WP6 requirements document
95
	);
96
}
97

    
98

    
99
/**
100
 * Implementation of hook_menu()
101
 */
102
function cdm_dataportal_menu($may_cache) {
103
	$items = array();
104

    
105
	if ($may_cache) {
106

    
107
		$items[] = array(
108
      'path' => 'admin/settings/cdm_dataportal',
109
      'title' => t('CDM Dataportal'),
110
      'description' => t('Setting for the CDM DataPortal'),
111
      'access' => user_access('administer cdm_dataportal'),
112
      'callback' => 'drupal_get_form',
113
      'callback arguments' => 'cdm_dataportal_settings',
114
      'type' => MENU_NORMAL_ITEM,
115
		);
116

    
117
		$items[] = array(
118
      'path' => 'admin/settings/cdm_dataportal/general',
119
      'title' => t('General'),
120
      'description' => t('Setting for the CDM DataPortal'),
121
      'access' => user_access('administer cdm_dataportal'),
122
      'callback' => 'drupal_get_form',
123
      'callback arguments' => 'cdm_dataportal_settings',
124
      'type' => MENU_LOCAL_TASK,
125
		);
126

    
127
		$items[] = array(
128
      'path' => 'admin/settings/cdm_dataportal/geo',
129
      'title' => t('Geo & Map'),
130
      'description' => t('Geo & Map'),
131
      'access' => user_access('administer cdm_dataportal'),
132
      'callback' => 'drupal_get_form',
133
      'callback arguments' => 'cdm_dataportal_settings_geo',
134
      'type' => MENU_LOCAL_TASK,
135
		);
136

    
137
		$items[] = array(
138
      'path' => 'admin/settings/cdm_dataportal/layout',
139
      'title' => t('Layout'),
140
      'description' => t('Configure and adjust the layout of your DataPortal '),
141
      'access' => user_access('administer cdm_dataportal'),
142
      'callback' => 'drupal_get_form',
143
      'callback arguments' => 'cdm_dataportal_settings_layout',
144
      'type' => MENU_LOCAL_TASK,
145
		);
146

    
147
		$items[] = array(
148
      'path' => 'admin/settings/cdm_dataportal/cachesite',
149
      'title' => t('Cache Site'),
150
      'description' => t('Cache the whole CDM DataPortal site'),
151
      'access' => user_access('administer cdm_dataportal'),
152
      'callback' => 'cdm_dataportal_view_cache_site',
153
      'type' => MENU_LOCAL_TASK,
154
		);
155

    
156
		/*$items[] = array(
157
		 'path' => 'admin/settings/cdm_dataportal/ws',
158
		 'title' => t('Web Service'),
159
		 'description' => t('Setting for the CDM DataPortal'),
160
		 'access' => user_access('administer cdm_dataportal'),
161
		 'callback' => 'drupal_get_form',
162
		 'callback arguments' => 'cdm_dataportal_settings',
163
		 'weight' => 1,
164
		 'type' => MENU_DEFAULT_LOCAL_TASK,
165
		 );*/
166

    
167
		$items[] = array(
168
	    'path' => 'cdm_dataportal/names',
169
	    'callback' => 'cdm_dataportal_view_names',
170
	    'access' => true,
171
	    'type' => MENU_CALLBACK,
172
		);
173
		// optional callback arguments: page
174
			
175
		$items[] = array(
176
      'path' => 'cdm_dataportal/taxon',
177
      'callback' => 'cdm_dataportal_taxon_page_view',
178
      'access' => true,
179
      'type' => MENU_CALLBACK,
180
		// expected callback arguments: uuid
181
		);
182
		
183
		$items[] = array(
184
      'path' => 'cdm_dataportal/name',
185
      'callback' => 'cdm_dataportal_name_page_view',
186
      'access' => true,
187
      'type' => MENU_CALLBACK,
188
    // expected callback arguments: uuid
189
    );
190

    
191
		$items[] = array(
192
      'path' => 'cdm_dataportal/reference',
193
      'callback' => 'cdm_dataportal_view_reference',
194
      'access' => true,
195
      'type' => MENU_CALLBACK,
196
		// expected callback arguments: uuid
197
		);
198

    
199
		$items[] = array(
200
      'path' => 'cdm_dataportal/reference/list',
201
      'callback' => 'cdm_dataportal_view_reference_list',
202
      'access' => true,
203
      'type' => MENU_CALLBACK,
204
		// expected callback arguments: uuid
205
		);
206

    
207
		$items[] = array(
208
      'path' => 'cdm_dataportal/media',
209
      'callback' => 'cdm_dataportal_view_media',
210
      'access' => true,
211
      'type' => MENU_CALLBACK,
212
		// expected callback arguments: uuid, mediarepresentation_uuid, part_uuid or part#
213
		);
214

    
215
		$items[] = array(
216
      'path' => 'cdm_dataportal/search',
217
      'callback' => 'cdm_dataportal_view_search_advanced',
218
      'access' => true,
219
      'type' => MENU_CALLBACK,
220
		);
221

    
222
		$items[] = array(
223
      'path' => 'cdm_dataportal/search/taxon',
224
      'callback' => 'cdm_dataportal_view_search_taxon',
225
      'access' => true,
226
      'type' => MENU_CALLBACK,
227
		);
228
		
229
		$items[] = array(
230
      'path' => 'cdm/xml2json',
231
      'callback' => 'cdm_view_xml2json',
232
      'access' => true,
233
      'type' => MENU_CALLBACK,
234
		);
235

    
236
	} else {
237
		// may not cache
238
		// --- local tasks for Taxon
239
		$items[] = array(
240
      'path' => 'cdm_dataportal/name/'.arg(2),
241
      //'callback' => 'cdm_dataportal_view_name',
242
		  'callback' => 'cdm_dataportal_name_page_view',
243
      'callback arguments' => array(arg(2)),
244
      'access' => true,
245
      'type' => MENU_CALLBACK,
246
    );
247
    
248
		if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
249

    
250
			$items[] = array(
251
      'path' => 'cdm_dataportal/taxon/'.arg(2),
252
      'title' => theme('cdm_taxonpage_tab', 'General'),
253
      'callback' => 'cdm_dataportal_taxon_page_view',
254
      'access' => true,
255
      'type' => MENU_CALLBACK,
256
      'weight' => 1,
257
      'callback arguments' => array(arg(2), "description")
258
			// expected callback arguments: name_uuid
259
			);
260

    
261
			$items[] = array(
262
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/all',
263
      'title' => theme('cdm_taxonpage_tab', 'General'),
264
      'callback' => 'cdm_dataportal_taxon_page_view',
265
      'access' => true,
266
      'type' => MENU_CALLBACK,
267
      'weight' => 2,
268
      'callback arguments' => array(arg(2), "all")
269
			// expected callback arguments: name_uuid
270
			);
271

    
272
			$items[] = array(
273
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/description',
274
      'title' => theme('cdm_taxonpage_tab', 'General'),
275
      'callback' => 'cdm_dataportal_taxon_page_view',
276
      'access' => true,
277
      'type' => MENU_DEFAULT_LOCAL_TASK,
278
      'weight' => 2,
279
      'callback arguments' => array(arg(2), "description")
280
			// expected callback arguments: name_uuid
281
			);
282

    
283
			$items[] = array(
284
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/synonymy',
285
      'title' => theme('cdm_taxonpage_tab', 'Synonymy'),
286
      'callback' => 'cdm_dataportal_taxon_page_view',
287
      'access' => true,
288
      'type' => MENU_LOCAL_TASK,
289
      'weight' => 3,
290
      'callback arguments' => array(arg(2), "synonymy")
291
			// expected callback arguments: name_uuid
292
			);
293

    
294
			$items[] = array(
295
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/images',
296
      'title' => theme('cdm_taxonpage_tab', 'Images'),
297
      'callback' => 'cdm_dataportal_taxon_page_view',
298
      'access' => true,
299
      'type' => MENU_LOCAL_TASK,
300
      'weight' => 4,
301
      'callback arguments' => array(arg(2), "images")
302
			// expected callback arguments: name_uuid
303
			);
304
		}
305
	}
306

    
307
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
308
	//drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
309
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
310

    
311
	return $items;
312

    
313
}
314

    
315
/**
316
 * Implementation of hook_block()
317
 *
318
 * Provides the following blocks:
319
 *  0: list of links useful during development
320
 *
321
 * @param String $op
322
 * @param int $delta
323
 */
324
function cdm_dataportal_block($op='list', $delta=0) {
325
	// listing of blocks, such as on the admin/block page
326
	if ($op == "list") {
327
		//$block[0]["info"] = t("CDM DataPortal DevLinks");
328
		$block[1]["info"] = t("CDM DataPortal Credits");
329
		$block[2]["info"] = t("CDM Search Taxa");
330
		//$block[3]["info"] = t("CDM Filters");
331
		$block[4]["info"] = t("CDM Dataportal Print");
332
		return $block;
333
	}
334
	else if ($op == 'view') {
335
		switch($delta){
336
			case 1:
337
				$block['subject'] = t('Credits');
338
				$block['content'] = theme('cdm_credits');
339
				return $block;
340
			case 2:
341
				$block['subject'] = t('Search Taxa');
342
				$block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
343
				$block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
344
				return $block;
345
			case 4:
346
				$block['subject'] = t('Print this page');
347
				$block['content'] = theme('cdm_print_button');;
348
				return $block;
349
		}
350
	}
351
}
352

    
353

    
354
/**
355
 * Implementation of hook_validate()
356
 *
357
 * @param $element
358
 */
359
function cdm_dataportal_settings_validate($form_id, $form_values){
360

    
361
	if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
362
		form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
363
	}
364

    
365
	$cdm_webservice_url_changed = variable_get('cdm_webservice_url', '') != $form_values['cdm_webservice_url'];
366

    
367
	$cdm_secUuid_default_changed = variable_get('cdm_secUuid_default', '') != $form_values['cdm_secUuid_default'];
368

    
369
	if ($cdm_webservice_url_changed || $cdm_secUuid_default_changed) {
370

    
371
		_cdm_dataportal_set_currentSecUuid($form_values['cdm_secUuid_default']);
372
		// reset all cdm related data stored in the session
373
		// cdm_dataportal_session_clear($form_values['cdm_webservice_url']); // cdm_webservice_url is not further stored here
374
		// clear the cdm webservice cache
375
		cache_clear_all(NULL, 'cache_cdm_ws');
376
		// better clear secref_cache since i can not be sure if the cache has not be used during this response
377
		cdm_api_secref_cache_clear();
378
	}
379
	if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
380
		cache_clear_all(NULL, 'cache_cdm_ws');
381
		// better clear secref_cache since i can not be sure if the cache has not be used during this response
382
		cdm_api_secref_cache_clear();
383
	}
384

    
385
}
386

    
387
/*
388
 function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
389
 $_SESSION['cdm'] = null;
390
 if(is_string($cdm_ws_uri_update)){
391
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
392
 }
393
 }
394

    
395
 function cdm_dataportal_session_validate(){
396

    
397
 if(!isset($_SESSION['cdm']['ws_uri'])){
398
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
399
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
400
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
401
 }
402
 }
403
 */
404

    
405
function cdm_dataportal_search_taxon_form($advancedForm = false){
406

    
407
	$preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
408
	$preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
409
	$preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
410
	$preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
411
	$tdwg_level_select =  (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
412
	$selected_areas =  (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
413

    
414
	$url = 'cdm_dataportal/search/taxon';
415
	$form['#method'] = 'get';
416
	$form['#process'] = array('cdm_dataportal_search_process' => array());
417
	$form['#action'] = url($url, NULL, NULL, true);
418

    
419
	$form['query'] = array(
420
    '#delta' => 0,
421
    '#type' => 'textfield',
422
    '#size' => 20,
423
    '#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')),
424
    '#value' => $preset_query,
425
	);
426

    
427
	$form['search'] = array(
428
      '#delta' => 1,
429
      '#tree' => true,
430
	//'#type' => $advancedForm ? 'fieldset': 'hidden',
431
      '#title' => t('Options')
432
	);
433

    
434
	$form['search']['tree'] = array(
435
    '#delta' => -1,
436
    '#type' => 'hidden',
437
    '#value' => variable_get('cdm_taxonomictree_uuid', false)
438
	);
439

    
440

    
441
	// clean URL get forms breaks if we don't give it a 'q'.
442
	if (!(bool)variable_get('clean_url', '0')) {
443
		$form['search']['q'] = array(
444
      '#delta' => -1,
445
      '#type' => 'hidden',
446
      '#value' => $url,
447
      '#name' => 'q',
448
		);
449
	}
450

    
451
	$form['search']['pageSize'] = array(
452
      '#delta' => -1,
453
      '#type' => 'hidden',
454
      '#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
455
	);
456

    
457
	if($advancedForm){
458
		// general search parameters
459
		$form['search']['doTaxa'] = array(
460
      '#delta' => 2,
461
      '#type' => 'checkbox',
462
      '#title' => t('Search for accepted taxa'),
463
      '#value' => $preset_doTaxa
464
		);
465
		$form['search']['doSynonyms'] = array(
466
      '#delta' => 3,
467
      '#type' => 'checkbox',
468
      '#title' => t('Search for synonyms'),
469
      '#value' => $preset_doSynonyms
470
		);
471
		$form['search']['doTaxaByCommonNames'] = array(
472
      '#delta' => 4,
473
      '#type' => 'checkbox',
474
      '#title' => t('Search for common names'),
475
      '#value' => $preset_doTaxaByCommonNames
476
		);
477
			
478
		// Geographic Range
479
		$form['search']['geographic_range'] = array(
480
      '#type' => 'fieldset',
481
      '#delta' => 5,
482
      '#tree' => true,
483
      '#title' => t('Geographic range'),
484
		);
485

    
486
		$form['search']['geographic_range']['tdwg_level_select'] = array(
487
    '#type' => 'radios',
488
    '#title' => t('Select a TDWG distribution level and code'),
489
    '#default_value' => $tdwg_level_select,
490
    '#options' => array(
491
		t('TDWG level-1, i.e. a continent'),
492
		t('TDWG level-2'),
493
		t('TDWG level-3, i.e. a country'),
494
		t('TDWG level-4')
495
		)
496
		);
497
		$tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
498
		$tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
499
		$tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
500
		$tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
501

    
502
		$tdwg_js = '';
503
		foreach($tdwg as $key=>$tdwg_level){
504
			$tdwgOptions = array();
505
			$tdwgOptionsSelected = array();
506
			foreach($tdwg_level as $area){
507
				$representation = $area->representations[0];
508
				$tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
509
				if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
510
					$tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
511
				}
512
			}
513
			asort($tdwgOptions);
514
			$form['search']['geographic_range']['tdwg_level_'.$key] = array(
515
        '#type' => 'select',
516
        '#title'         => t('TDWG level').' '.$key,
517
        '#default_value' => $tdwgOptionsSelected,
518
        '#multiple' => TRUE, 
519
        '#options' => $tdwgOptions
520
			);
521
			$tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ?  '.show()' : '.hide()'). ";\n";
522
		}
523

    
524
		drupal_add_js(
525
    "$(document).ready(function(){
526
    
527
      $(\"input[@name='search[geographic_range][tdwg_level_select]']\").change( 
528
        function(event){
529
          var selectId = $(\"input[@name='search[geographic_range][tdwg_level_select]']:checked\").val();
530
          var i;
531
          for(i = 0; i < 4; i++){
532
            if(selectId == i){
533
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1) ).parent().fadeIn('slow');
534
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
535
            } else {
536
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).parent().fadeOut('slow');
537
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
538
            }
539
          }
540
        }
541
      );
542
      
543
      $tdwg_js
544
    });",
545
    'inline');
546

    
547
	} else {
548
		$form['search']['doTaxa'] = array(
549
      '#delta' => -2,
550
      '#type' => 'hidden',
551
      '#value' => 1
552
		);
553
		$form['search']['doSynonyms'] = array(
554
      '#delta' => -3,
555
      '#type' => 'hidden',
556
      '#value' => 1
557
		);
558
		$form['search']['doTaxaByCommonNames'] = array(
559
      '#delta' => -4,
560
      '#type' => 'hidden',
561
      '#value' => 1
562
		);
563
	}
564

    
565
	$form['submit'] = array(
566
  '#delta' => 9,
567
  '#type' => 'submit',
568
  '#name' => '',
569
  '#value' => t('Search')
570
	);
571

    
572
	return $form;
573
}
574

    
575
function cdm_dataportal_search_taxon_form_advanced(){
576
	return cdm_dataportal_search_taxon_form(true);
577
}
578

    
579
/**
580
 * Implementation #process method call, see form_builder()
581
 * <p>
582
 * Removes Drupal internal form elements from query
583
 * @param $form
584
 * @return unknown_type
585
 */
586
function cdm_dataportal_search_process($form) {
587
	unset($form['form_id']);
588
	unset($form['form_token']);
589
	return $form;
590
}
591

    
592
/**
593
 * Filters $_REQUEST by a list of valid request  parameters and also sets defaults if required.
594
 * returns the processed request parameters submitted by the search form.
595
 */
596
function cdm_dataportal_search_form_request(){
597

    
598

    
599
	$form_params = array();
600
	array_deep_copy($_REQUEST['search'], $form_params);
601
	$form_params['query'] =  trim($_REQUEST['query']);
602

    
603
	// split of  geographic range
604
	if(isset($_REQUEST['search']['geographic_range'])){
605
		$geographicRange = $_REQUEST['search']['geographic_range'];
606
		// remove
607
		unset($form_params['geographic_range']);
608
	}
609

    
610
	// add geographic range
611
	if($geographicRange){
612
		$form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
613
		for($i = 1; $i < 5; $i++){
614
			if(isset($geographicRange['tdwg_level_'.$i])){
615
				$form_params['area'] = $geographicRange['tdwg_level_'.$i];
616
			}
617
		}
618
	}
619

    
620
	// store in session
621
	$_SESSION['cdm']['search'] = $form_params;
622

    
623
	return $form_params;
624
}
625

    
626

    
627
/* UNREACHABLE since action of form directly links to view
628
 function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
629

    
630
 $_SESSION['cdm']['search'] = $form_values;
631
 //return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
632
 return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
633
 //$paramstr = compose_url_prameterstr($form_values);
634
 //return url('/cdm_dataportal/search/taxon/', $paramstr);
635
 }
636
 */
637
/* ====================== menu callback functions ====================== */
638

    
639
/**
640
 * Generate main administration form.
641
 *
642
 * @return
643
 *   An array containing form items to place on the module settings page.
644
 */
645
function cdm_dataportal_settings(){
646

    
647
	$form = cdm_api_settings_form();
648

    
649
	//TODO: settings are still incomplete, compare with trunk/dataportal/inc/config_default.php.inc
650
	$form['cdm_dataportal'] = array(
651
      '#type' => 'fieldset',
652
      '#title' => t('CDM DataPortal'),
653
      '#collapsible' => FALSE,
654
      '#collapsed' => TRUE,
655
	);
656

    
657
	//  $form['cdm_dataportal']['secuuid_widget'] = array(
658
	//    '#type' => 'select_secuuid', // => will be themed by theme_select_secuuid(...)
659
	//    '#title' => t('Default Concept References'),
660
	//    '#description'   => t('The default \'sensu\' reference to start the CDM DataPortal with. Per user choices are possible and may override this value.'),
661
	//    '#varname' => 'cdm_secUuid_default',
662
	//    '#multiple' => false
663
	//  );
664

    
665
	$taxonTrees = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
666
	foreach($taxonTrees as $tree){
667
		$taxonomicTreeOptions[$tree->uuid] = $tree->titleCache;
668
	}
669
	$form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
670
    '#type' => 'select',
671
    '#title'         => t('Available taxonomic views'),
672
    '#default_value' => variable_get('cdm_taxonomictree_uuid', false),
673
    '#options' => $taxonomicTreeOptions,
674
    '#description'   => t('Select a taxonomic view for this webservice.')
675
	);
676

    
677
	//  $form['cdm_dataportal']['DEBUG']= array(
678
	//    '#value' => '<pre>'.print_r($taxonTrees, true).'</pre>'
679
	//  );
680

    
681

    
682
	//------------------ FEATURE TREE --------------------//
683

    
684
	$form['cdm_dataportal']['feature_tree'] = array(
685
    '#type' => 'fieldset',
686
    '#title' => t('Feature Tree'),
687
    '#collapsible' => TRUE,
688
    '#collapsed' => TRUE,
689
	);
690

    
691
	$form['cdm_dataportal']['feature_tree']['cdm_dataportal_featuretree_uuid'] = array(
692
    '#type' => 'select',
693
    '#title'         => t('Available FeatureTrees'),
694
    '#default_value' => variable_get('cdm_dataportal_featuretree_uuid', UUID_DEFAULT_FEATURETREE),
695
	  '#options' => _get_feature_trees(),
696
    '#description'   => t('Select a FeatureTree for this webservice.'
697
    //.' If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
698
	)
699
	);
700

    
701
	return system_settings_form($form);
702
}
703

    
704
/**
705
 * LAYOUT settings
706
 * @return unknown_type
707
 */
708
function cdm_dataportal_settings_layout(){
709

    
710
	$form = array();
711

    
712

    
713
	$form['cdm_taxonname_type'] = array(
714
    '#type' => 'select',
715
    '#title'         => t('Taxon name type'),
716
    '#default_value' => variable_get('cdm_taxonname_type', 'BotanicalName'),
717
    '#options' => array( 'BotanicalName'=>t('BotanicalName'), 'ZoologicalName'=>t('ZoologicalName')),
718
    '#description'   => t('')
719
	);
720

    
721
	$form['cdm_dataportal_nomref_in_title'] = array(
722
    '#type' => 'checkbox',
723
    '#title' => t('Show full nomenclatural reference in title'),
724
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
725
    '#description' => t('Uncheck this, if you want the title of a taxon page consisting of name and author plus publication year only.
726
                        If not checked, the first homotypic taxon is a repetition of the accepted taxon with
727
                        the full nomenclatural reference.')
728
	);
729

    
730
	$form['cdm_dataportal_display_name_relations'] = array(
731
    '#type' => 'checkbox',
732
    '#title' => t('Show name relations of accepted taxa on taxon page'),
733
    '#default_value' => variable_get('cdm_dataportal_display_name_relations', 1),
734
    '#description' => t('')
735
	);
736

    
737
	$form['cdm_dataportal_display_is_accepted_for'] = array(
738
    '#type' => 'checkbox',
739
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
740
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
741
    '#description' => t('')
742
	);
743

    
744
	$form['cdm_dataportal_name_relations_skiptype_basionym'] = array(
745
    '#type' => 'checkbox',
746
    '#title' => t('Exclude the basionym relationship type from the taxon page'),
747
    '#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
748
    '#description' => t('')
749
	);
750

    
751
	$form['cdm_dataportal_taxonpage_tabs'] = array(
752
    '#type' => 'checkbox',
753
    '#title' => t('Tabbed taxon page'),
754
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
755
    '#description' => t('Split the taxon page into individual tabs for description, images, synonymy')
756
	);
757

    
758
	$form['cdm_dataportal_search_items_on_page'] = array(
759
    '#type' => 'textfield',
760
    '#title' => t('Search Page Size'),
761
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
762
    '#description' => t('Number of Names to display per page in search results.')
763
	);
764

    
765
	$form['cdm_dataportal_descriptions_separated'] = array(
766
    '#type' => 'checkbox',
767
    '#title' => t('Separate Descriptions'),
768
    '#default_value' => variable_get('cdm_dataportal_descriptions_separated', 0),
769
    '#description' => t('By default corresponding elements of different descriptions are joined together'
770
    .' into a common section per feature (i.e. type of description).'
771
    .' Check this box to allow displaying all descriptions separately.')
772
    );
773

    
774
    //---- IMAGES ----//
775
    $form['images'] = array(
776
    '#type' => 'fieldset',
777
    '#title' => t('Images'),
778
    '#collapsible' => TRUE,
779
    '#collapsed' => FALSE,
780
    );
781
    $options = cdm_rankVocabulary_as_option();
782
    array_unshift($options, '-- DISABLED --');
783
    $form['images']['image_hide_rank'] =  array(
784
    '#type'          => 'select',
785
    '#title'         => t('Hide Images for Taxa above'),
786
    '#default_value' => variable_get('image_hide_rank', '0'),
787
    '#options'       => $options,
788
    '#description'   => t(''),
789
    );
790
    //show media
791
    $selectShowMedia = array(0 => "Show only taxon media",
792
    1 => "Show taxon and child taxon media");
793
    $form['images']['cdm_dataportal_show_media'] = array(
794
    '#type' => 'select',
795
    '#title' => t('Available media files'),
796
    '#default_value' => variable_get('cdm_dataportal_show_media', false),
797
    '#options' => $selectShowMedia,
798
    '#description'   => t('Select if a taxon should show only his media or also child media.')
799
    );
800

    
801
    // --- SEARCH TAXA GALLERY ---- //
802
    $collapsed = TRUE;
803
    $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
804
    $form_tittle = 'Search Taxa';
805
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
806

    
807
    // --- FEATURE DESCRIPTION GALLERY ---- //
808
    $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
809
    $form_tittle = 'Description elements gallery';
810
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
811

    
812
    // --- MEDIA GALLERY ---- //
813
    $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
814
    $form_tittle = 'Media gallery';
815
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
816

    
817
    return system_settings_form($form);
818
}
819

    
820
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed){
821

    
822
	$form[$form_name] = array(
823
    '#type' => 'fieldset',
824
    '#title' => t($form_tittle),
825
    '#collapsible' => TRUE,
826
    '#collapsed' => $collapsed,
827
    '#tree' => true,
828
	);
829

    
830
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
831
	$gallery_settings = variable_get($form_name, $default_values);
832

    
833
	$form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
834
    '#type' => 'checkbox',
835
    '#title' => t('Show media thumbnails for accepted taxa'),
836
    '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
837
    '#description' => t('')
838
	);
839

    
840
	$form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
841
    '#type' => 'checkbox',
842
    '#title' => t('Show media thumbnails for synonyms'),
843
    '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
844
    '#description' => t('')
845
	);
846

    
847
	//$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
848
	$form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
849
    '#type' => 'checkbox',
850
    '#title' => t('Show captions under thumbnails'),
851
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
852
    '#description' => t('')
853
	);
854

    
855
	$form[$form_name]['cdm_dataportal_media_maxextend'] = array(
856
    '#type' => 'textfield',
857
    '#title' => t('Maximum extend of Images'),
858
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
859
    '#description' => t('In the gallery neither width or height will exceed the maximum extend of images.')
860
	);
861

    
862
	$form[$form_name]['cdm_dataportal_media_cols'] = array(
863
    '#type' => 'textfield',
864
    '#title' => t('Number of columns'),
865
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
866
    '#description' => t('')
867
	);
868

    
869
	$form[$form_name]['cdm_dataportal_media_maxRows'] = array(
870
    '#type' => 'textfield',
871
    '#title' => t('Maximum number of rows'),
872
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
873
    '#description' => t('If you want an unlimited number of rows please set to 0')
874
	);
875

    
876
	return $form;
877
}
878

    
879
/**
880
 * GEOSERVICE and Map settings
881
 * @return unknown_type
882
 */
883
function cdm_dataportal_settings_geo(){
884

    
885
	$form = array();
886

    
887
	$form['cdm_dataportal_map_openlayers'] = array(
888
    '#type' => 'checkbox',
889
    '#title' => t('OpenLayers Viewer'),
890
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
891
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning.')
892
	);
893

    
894
	$form['cdm_dataportal_geoservice_access_point'] = array(
895
    '#type' => 'textfield',
896
    '#title' => t('Geoservice Access Point'),
897
    '#default_value' => variable_get('cdm_dataportal_geoservice_access_point', ''),
898
    '#description' => t('Base URL of the geoservice to be used by this portal')
899
	);
900

    
901
	$form['cdm_dataportal_geoservice_display_width'] = array(
902
    '#type' => 'textfield',
903
    '#title' => t('Geoservice Display Width'),
904
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
905
    '#description' => t('Width of the image generated by geoservice')
906
	);
907

    
908
	$form['cdm_dataportal_geoservice_bounding_box'] = array(
909
    '#type' => 'textfield',
910
    '#title' => t('Fixed Geoservice Bounding Box'),
911
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
912
    '#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.')
913
	);
914

    
915
	//cdm_dataportal_geoservice_labels_on
916
	$form['cdm_dataportal_geoservice_labels_on'] = array(
917
    '#type' => 'checkbox',
918
    '#title' => t('Display Country Labels'),
919
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
920
    '#description' => t('Check this if you like country names to be displayed in the maps. ')
921
	);
922

    
923
	//cdm_dataportal_geoservice_legend_on
924
	$form['cdm_dataportal_geoservice_map_caption'] = array(
925
    '#type' => 'textfield',
926
    '#title' => t('Map Caption'),
927
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
928
    '#description' => t('Define a caption for the map.')
929
	);
930

    
931
	/*
932
	 //cdm_dataportal_geoservice_legend_on
933
	 $form['cdm_dataportal_geoservice_legend_on'] = array(
934
	 '#type' => 'checkbox',
935
	 '#title' => t('Display a map legend'),
936
	 '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
937
	 '#description' => t('Check this if you like a legend to be displayed with the maps. ')
938
	 );
939
	 */
940

    
941
	//cdm_dataportal_geoservice_map_legend
942
	$form['cdm_dataportal_geoservice_map_legend'] = array(
943
      '#type' => 'fieldset',
944
      '#title' => t('Map Legend'),
945
      '#collapsible' => FALSE,
946
      '#collapsed' => TRUE,
947
	);
948

    
949
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
950
    '#type' => 'checkbox',
951
    '#title' => t('Display a map legend'),
952
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
953
    '#description' => t('Check this if you like a legend to be displayed with the maps. ')
954
	);
955

    
956
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
957
    '#type' => 'textfield',
958
    '#title' => t('Font size'),
959
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
960
    '#description' => t('Font size in pixels.')
961
	);
962

    
963
	$fontStyles = array(0 => "plane", 1 => "italic");
964
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
965
    '#type' => 'select',
966
    '#title' => t('Available font styles'),
967
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
968
    '#options' => $fontStyles,
969
    '#description'   => t('Select a font style for the map legend.')
970
	);
971

    
972
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
973
    '#type' => 'textfield',
974
    '#title' => t('Icon width'),
975
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
976
    '#description' => t('Icon width in pixels.')
977
	);
978

    
979
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
980
    '#type' => 'textfield',
981
    '#title' => t('Icon height'),
982
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
983
    '#description' => t('Icon height in pixels.')
984
	);
985

    
986
	/* variable_get('cdm_dataportal_findtaxa_media_maxextend', 120),
987
	 *  $form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
988
	 '#type' => 'select',
989
	 '#title'         => t('Available taxonomic views'),
990
	 '#default_value' => variable_get('cdm_taxonomictree_uuid', false),
991
	 '#options' => $taxonomicTreeOptions,
992
	 '#description'   => t('Select a taxonomic view for this webservice.')
993
	 );
994

    
995
	 $taxonTrees = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
996
	 foreach($taxonTrees as $tree){
997
	 $taxonomicTreeOptions[$tree->uuid] = $tree->titleCache;
998
	 }
999
	 $form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
1000
	 '#type' => 'select',
1001
	 '#title'         => t('Available taxonomic views'),
1002
	 '#default_value' => variable_get('cdm_taxonomictree_uuid', false),
1003
	 '#options' => $taxonomicTreeOptions,
1004
	 '#description'   => t('Select a taxonomic view for this webservice.')
1005
	 );
1006
	 */
1007

    
1008
	return system_settings_form($form);
1009

    
1010
}
1011

    
1012

    
1013
/**
1014
 * @return walk and cache all taxon pages
1015
 */
1016
function cdm_dataportal_view_cache_site(){
1017

    
1018
	_add_js_progressbar();
1019

    
1020
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1021

    
1022
	$out = '';
1023

    
1024
	$request_params = array();
1025
	$request_params['query'] = '%';
1026
	$request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false);
1027
	$request_params['doTaxa'] = 1;
1028
	$request_params['doSynonyms'] = 0;
1029
	$request_params['doTaxaByCommonNames'] = 0;
1030
	$search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1031
	$search_url = uri_uriByProxy($search_url);
1032
	$taxon_page_url = url('cdm_dataportal/taxon/');
1033

    
1034
	$out .= '<form id="cache_site">';
1035
	$out .= '<br /><h4>'
1036
	.t('Cache all taxon pages')
1037
	.'</h4>';
1038
	$out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
1039
	$out .= '<div id="progress"></div>';
1040
	$out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
1041
	$out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
1042
	$out .= '<input type="button" name="start" value="'.t('Start').'"/>';
1043
	$out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
1044
	$out .= '</form>';
1045
	$out .= '</div>';
1046
	//  foreach($taxonPager->records as $taxon){
1047
	//    cdm_dataportal_taxon_view($uuid);
1048
	//  }
1049

    
1050
	return $out;
1051
}
1052

    
1053
/**
1054
 * Implementation of hook_elements().
1055
 */
1056
function cdm_dataportal_elements() {
1057
	$type['select_secuuid'] = array(
1058
    '#input' => TRUE,
1059
    '#process' => array('cdm_dataportal_select_secuuid_expand' => array()),
1060
	//'#validate' => array('cdm_dataportal_select_secuuid_validate' => array()),
1061
	//'#default_value' => array(),
1062
	);
1063
	return $type;
1064
}
1065

    
1066
/*
1067
 *
1068
 */
1069
function cdm_dataportal_select_secuuid_expand($element){
1070

    
1071
	$element['#tree'] = FALSE;
1072

    
1073
	// any value submitted?
1074
	if(isset($element['#post'][$element['#varname']])){
1075
		$selected_values = $element['#post'][$element['#varname']];
1076
	} else {
1077
		// use those store in drupal
1078
		$selected_values = variable_get( $element['#varname'], array());
1079
	}
1080
	if(!is_array($selected_values)){
1081
		$selected_values = array($selected_values);
1082
	}
1083
	$options = array();
1084
	foreach($selected_values as $secUuid){
1085
		$options[$secUuid] = cdm_taxontree_secRefTitle_for($secUuid);
1086
	}
1087

    
1088
	$element[$element['#varname']] =  array(
1089
    '#type' => 'select',
1090
    '#options' => $options,
1091
    '#default_value' => array_values($options),
1092
    '#size' => $element['#multiple'] ? 12 : 2,
1093
    '#multiple' => $element['#multiple'],
1094
	);
1095
	return $element;
1096
}
1097

    
1098

    
1099

    
1100
/**
1101
 * Displays a list of the known taxonomic names. Long lists are split up into multiple pages
1102
 *
1103
 * TODO: parameters are still preliminar
1104
 * @param String $page page number to diplay defaults to page 1
1105
 * @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
1106
 */
1107
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
1108

    
1109
	$request_params  = array(
1110
    'q' => $beginsWith,
1111
	//'sec' = '',
1112
	//'higherTaxa' => getFiters(),
1113
	// 'matchAnywhere' => false, // default is false
1114
    'page' => $page,
1115
    'onlyAccepted' => $onlyAccepted,
1116
    'pagesize' => 20  /*$_SESSION['cdm']['namelist_pagesize'] */);
1117

    
1118
	$taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
1119
	/*
1120
	 * FIXME the filter for accepted names will be a form element, thus this widget
1121
	 * should be generated via form api preferably as block
1122
	 */
1123
	//$out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1124
	//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1125
	$out .= theme('cdm_listof_taxa', $taxonPager);
1126
	return $out;
1127
}
1128

    
1129
function cdm_dataportal_view_reference($uuid, $arg2 = null){
1130
	$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1131
	return theme('cdm_reference_page', $reference);
1132
}
1133

    
1134
function cdm_dataportal_view_reference_list($pageNumber){
1135
	$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
1136
	return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
1137
}
1138

    
1139
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
1140
	$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1141
	return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
1142
}
1143

    
1144
/**
1145
 * The taxon page gives detailed information on a taxon, it shows:
1146
 *  - Taxon name
1147
 *  - Full list of synonyms homotypic synonyms on top, followed by the
1148
 *    heterotypic and finally followed by misapplied names.
1149
 *    The list is ordered historically.
1150
 *  - All description associated with the taxon.
1151
 *
1152
 * @param $uuid
1153
 * @param $chapter name of the part to display,
1154
 *         valid values are: 'description', 'images', 'synonymy', 'all'
1155
 * @return unknown_type
1156
 */
1157
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all'){
1158

    
1159
	// display the page for the taxon defined by $uuid
1160
	$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
1161
	return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
1162
}
1163

    
1164
/**
1165
 * @param $uuid
1166
 * @param $chapter name of the part to display,
1167
 *         valid values are: 'description', 'images', 'synonymy', 'all'
1168
 * @return unknown_type
1169
 */
1170
function cdm_dataportal_taxon_view($uuid, $chapter = 'all'){
1171

    
1172
	$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1173
	if(!$taxon){
1174
		drupal_set_title(t('Taxon does not exist'));
1175
		return false;
1176
	}
1177
	_cdm_dataportal_set_currentSecUuid($taxon->sec->uuid);
1178

    
1179
	$taxonpage->title = theme('cdm_taxon_page_title', $taxon);
1180
	$taxonpage->content = theme('cdm_taxon_page_general', $taxon, $chapter);
1181

    
1182
	return $taxonpage;
1183
}
1184

    
1185
/**
1186
 * The function returns a name page as a drupal node ready to be renderized by drupal.
1187
 * The node page show the taxon name title and the list of taxon related with such taxon 
1188
 * name on the tree already in used. 
1189
 * @param $taxon_name_uuid A taxon name uuid
1190
 * @return The formatted name page as node
1191
 */
1192
function cdm_dataportal_name_page_view($taxon_name_uuid){
1193
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid);
1194
  return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
1195
}
1196

    
1197
/**
1198
 * The function genates a object ready to be transformated to a node 
1199
 * in order to show as a drupal node
1200
 * @param $taxon_name_uuid
1201
 * @return the object with the page content and title  
1202
 */
1203
function cdm_dataportal_name_view($taxon_name_uuid){
1204
	//getting the full taxonname object from the server  
1205
  $taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1206
  if(!$taxon_name){
1207
    drupal_set_title(t('Taxon name does not exist'));
1208
    return false;
1209
  }
1210
  //searching for all the taxon connected with the taxon name on the tree in used
1211
  $name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1212
  $request_params = array();
1213
  $request_params['query'] = $name_cache;
1214
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false);
1215
  $request_params['doTaxa'] = 1;
1216
  $request_params['doSynonyms'] = 1;
1217
  $request_params['doTaxaByCommonNames'] = 0;
1218
  $request_params['matchMode'] = "EXACT";
1219
  $taxon_pager = cdm_ws_get(CDM_WS_FIND_TAXA, null, queryString($request_params));
1220
  
1221
  //_cdm_dataportal_set_currentSecUuid($taxon->sec->uuid);
1222
  
1223
  //generating the returned object
1224
  $taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
1225
  $taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
1226

    
1227
  return $taxon_name_page; 
1228
}
1229

    
1230
function cdm_dataportal_view_search_advanced(){
1231

    
1232
	drupal_set_title(t('Advanced Search'));
1233

    
1234
	$searchForm = cdm_dataportal_search_taxon_form(true);
1235

    
1236
	return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1237

    
1238
}
1239

    
1240
/**
1241
 *
1242
 * future extensions to meet palmweb mockup requirements:
1243
 *  - habitat
1244
 *  - uses
1245
 *  - conservation status
1246
 *  - locality / tdwg region
1247
 */
1248
function cdm_dataportal_view_search_taxon(){
1249

    
1250
	$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
1251

    
1252
	$request_params = cdm_dataportal_search_form_request();
1253
	$taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1254

    
1255
	$search_params = $_REQUEST;
1256
	unset($search_params['q']);
1257
	return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
1258
}
1259

    
1260
///**
1261
// * 
1262
// * @return unknown_type
1263
// */
1264
//function cdm_dataportal_view_name($taxon_name_uuid){
1265
//
1266
//	$taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1267
//	/*
1268
//	$name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1269
//	$records = array();
1270
//	foreach ($taxon_name->taxonBases as $taxon_base){
1271
//		$taxon = cdm_ws_get(CDM_WS_TAXON, array($taxon_base->uuid));
1272
//		$records[] = $taxon;
1273
//	}
1274
//	
1275
//	$out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1276
//	$out .= theme_cdm_list_of_taxa($records, false);
1277
//	*/
1278
//	
1279
//	$request_params = array();
1280
//  $request_params['query'] = $name_cache;
1281
//  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false);
1282
//  $request_params['doTaxa'] = 1;
1283
//  $request_params['doSynonyms'] = 1;
1284
//  $request_params['doTaxaByCommonNames'] = 0;
1285
//  //$request_params['matchMode'] = "EXACT";
1286
//  
1287
//  $taxon_pager = cdm_ws_get(CDM_WS_FIND_TAXA, null, queryString($request_params));
1288
//  //var_dump($taxon_pager->records);
1289
//  //$out = theme_cdm_taxonname_page_title($taxon_name);
1290
//  $out = theme_cdm_list_of_taxa($taxon_pager->records, false);
1291
//  
1292
///*
1293
//  $out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1294
//  $out .= "Taxon name uuid: " . $taxon_name_uuid  . "<br/>";
1295
//  $out .= "Taxon name records: "  . "<br/>" . $records_names_out; 
1296
//*/
1297
//  //$out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1298
//	return $out;
1299
//}
1300

    
1301
function cdm_view_xml2json(){
1302
	$file = arg(2);
1303
	$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
1304
	return  xml2json::transformXmlStringToJson($datastr);
1305
}
1306

    
1307
/* ====================== other functions ====================== */
1308

    
1309
/**
1310
 * Enter description here...
1311
 *
1312
 * @param String $uuid the UUID of the taxon
1313
 * @return the URL
1314
 */
1315
function path_to_taxon($uuid){
1316
	if(!$uuid) return false;
1317
	return 'cdm_dataportal/taxon/'.$uuid;
1318
}
1319

    
1320
function path_to_reference($uuid){
1321
	if(!$uuid) return false;
1322
	return 'cdm_dataportal/reference/'.$uuid;
1323
}
1324

    
1325
function path_to_name($name_uuid){
1326
	$res = false;
1327
	if($name_uuid){
1328
	 $res = 'cdm_dataportal/name/'.$name_uuid;
1329
	}
1330
  return $res;
1331
}
1332

    
1333
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
1334
	if(!$uuid) return false;
1335
	$out = 'cdm_dataportal/media/'.$uuid;
1336
	if($representaion_uuid){
1337
		$out .= '/'.$representaion_uuid;
1338
		if($partId !== false){
1339
			$out .= '/'.$partId;
1340
		}
1341
	}
1342
	return $out;
1343
}
1344

    
1345
/**
1346
 * Compares thisRank with thatRank.
1347
 * Returns a negative integer, zero, or a positive integer
1348
 * as the of thisRank is higher than, equal to, or lower than thatRank.
1349
 * e.g:
1350
 * <ul>
1351
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
1352
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
1353
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
1354
 * </ul>
1355
 * <p>
1356
 * This compare logic of the underlying webservice is the
1357
 * <b>inverse logic</b> of the the one implemented in
1358
 * java.lang.Comparable#compareTo(java.lang.Object)
1359
 * @param $thisRankUuid
1360
 * @param $thatRankUuid
1361
 * @return  a negative integer, zero, or a positive integer
1362
 * as the thisRank is lower than, equal to, or higher than thatRank
1363
 */
1364
function rank_compare($thisRankUuid, $thatRankUuid){
1365
	$result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
1366
	return $result->Integer;
1367
}
1368

    
1369
function uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null){
1370
	$acceptedPath = path_to_taxon($acceptedUuid);
1371
	return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid);
1372
}
1373

    
1374
/**
1375
 * Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
1376
 * If the taggename if empty the fullname will be returned.
1377
 *
1378
 * @param unknown_type $Name or TreeNode
1379
 * @return string
1380
 */
1381
function cdm_dataportal_shortname_of($name){
1382

    
1383
	$nameStr = '';
1384
	// get all tagged text tokens of the scientific name
1385
	foreach($name->taggedTitle as $tagtxt){
1386
		if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
1387
			$nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
1388
		}
1389
	}
1390
	$nameStr = trim($nameStr);
1391
	if($nameStr){
1392
		// do not return short names for these
1393
		if($nameStr == 'Incertae sedis' || $nameStr ==  'Nomina excludenda'){
1394
			return $nameStr;
1395
		}
1396
		if($pos = stripos($nameStr, ' ')){
1397
			return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos);
1398
		} else {
1399
			return $nameStr;
1400
		}
1401
	} else {
1402
		return $name->titleCache;
1403
	}
1404
}
1405

    
1406
/**
1407
 * TODO Add Comments. I don't get what
1408
 *
1409
 * @param UUID $secUuid
1410
 */
1411
function _cdm_dataportal_set_currentSecUuid($secUuid){
1412

    
1413
	// do not save in session but in database
1414

    
1415
	if(is_array($secUuid)){
1416
		$secUuid = $secUuid[0];
1417
	}
1418
	if(!$secUuid){
1419
		variable_set('cdm_currentSecRef', null);
1420
	} else {
1421
		$secRef = cdm_ws_get(CDM_WS_REFERENCE, $secUuid);
1422
		if(isset($secRef)){
1423
			variable_set('cdm_currentSecRef', (array)($secRef));
1424
		}
1425
	}
1426

    
1427
}
1428

    
1429
/**
1430
 * TODO
1431
 * This will not work with multiple instances of the dataportal running
1432
 * under the same host as there is only one session for all instances.
1433
 * In case you switch instances with the same client, you will definitely
1434
 * run into trouble.
1435
 * Also this is not handling multiple secs.
1436
 *
1437
 *
1438
 * returns the current secRef array.
1439
 * If the according session variable is not jet set the default
1440
 * as configured in the setting is used otherwise null.
1441
 *
1442
 * currentSecRef['uuid']
1443
 * currentSecRef[....
1444
 *
1445
 * @return array
1446
 */
1447
function _cdm_dataportal_currentSecRef_array(){
1448

    
1449
	// do not look in session but in database
1450
	if( variable_get('cdm_currentSecRef', null) == null){
1451
		$secUuid = variable_get('cdm_secUuid_default', null);
1452
		_cdm_dataportal_set_currentSecUuid($secUuid);
1453
	}
1454
	return variable_get('cdm_currentSecRef', null);
1455

    
1456
}
1457

    
1458
/**
1459
 * Check if a taxon is accepted by the current taxonomic tree
1460
 *
1461
 * @param Taxon $taxon
1462
 * @return true if $taxon is accepted, false otherwise
1463
 */
1464

    
1465
function _cdm_dataportal_acceptedByCurrentView($taxon){
1466

    
1467
	//$current_secref = _cdm_dataportal_currentSecRef_array();
1468
	$defaultTreeUuid = variable_get('cdm_taxonomictree_uuid', false);
1469
	if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){
1470
		foreach($taxon->taxonNodes as $node){
1471
			if($node->taxonomicTree == $defaultTreeUuid) {
1472
				return true;
1473
			}
1474
		}
1475
	}
1476
	return false;
1477
}
1478

    
1479
/**@Deprecated
1480
 *
1481
 */
1482
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
1483
	$pstr = '';
1484
	foreach($parameters as $key=>$value){
1485
		if(is_array($value)){
1486

    
1487
		} else {
1488
			$pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
1489
		}
1490
	}
1491
	return $pstr;
1492
}
1493

    
1494
function _get_feature_trees(){
1495
	$feature_trees = array();
1496

    
1497
	// set tree that contains all features
1498
	$feature_trees[UUID_DEFAULT_FEATURETREE] = t('Default Featuretree (contains all features)');
1499

    
1500
	// get features from database
1501
	$persisted_trees = cdm_ws_get(CDM_WS_FEATURETREES);
1502
	if(is_array($persisted_trees)){
1503
		foreach($persisted_trees as $featureTree){
1504

    
1505
			// do not add the DEFAULT_FEATURETREE again
1506
			if($featureTree->uuid == UUID_DEFAULT_FEATURETREE){
1507
				continue;
1508
			}
1509
			$featureLabels = array();
1510
			foreach ($featureTree->root->children as $featureNode){
1511
				$featureLabels[] = $featureNode->feature->representation_L10n;
1512
			}
1513

    
1514
			$feature_trees[$featureTree->uuid] = implode(", ", $featureLabels);
1515

    
1516
		}
1517
	}
1518
	return $feature_trees;
1519
}
1520

    
1521

    
1522
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
1523
	//TODO implement admin user interface to replace swicth statement
1524
	//     preliminar solution: using themes
1525

    
1526
	$template = null;
1527
	// find best matching default RenderTemplate in theme
1528
	//echo "<br/><br/>".$renderPath;
1529
	while(!is_array($template) && strlen($renderPath) > 0){
1530
	   $template = theme('get_nameRenderTemplate', $renderPath);
1531
	   $renderPath = substr($renderPath, 0, strrpos($renderPath, '.'));
1532
//	   if(!is_array($template)){
1533
//	       echo "<br/>->".$renderPath;
1534
//	   }
1535
	}
1536
	
1537
	// otherwise get default RenderTemplate from theme 
1538
	if(!is_array($template)){
1539
	   $template = theme('get_nameRenderTemplate', '#DEFAULT');
1540
	}
1541
	// otherwise get system default RenderTemplate
1542
	if(!is_array($template)){
1543
		switch($renderPath){
1544
			case 'list_of_taxa':
1545
			case  'acceptedFor':
1546
			case 'taxon_page_synonymy':
1547
			case 'typedesignations':
1548
			case 'taxon_page_title':
1549
			case 'na': $template = array(
1550
			        'namePart' => array('#uri'=>true),
1551
			        //'authorshipPart' => true,
1552
				);
1553
				break;
1554
			case 'nar': $template = array(
1555
		          	'namePart' => array('#uri'=>true),
1556
					 //'authorshipPart' => true,
1557
		          	'referencePart' => array('#uri'=>true),
1558
		          	'microreferencePart' => true,
1559
				);
1560
				break;
1561
			default: $template = array(
1562
          'namePart' => array('#uri'=>true),
1563
          'authorshipPart' => true,
1564
          'referencePart' => array('#uri'=>true),
1565
          'microreferencePart' => true,
1566
          'statusPart' => true,
1567
          'descriptionPart' => true
1568
			);
1569
		}
1570
	}
1571

    
1572
	if($nameLink && isset($template['nameAuthorPart']['#uri'])){
1573
		$template['nameAuthorPart']['#uri'] = $nameLink;
1574
	} else{
1575
		unset($template['nameAuthorPart']['#uri']);
1576
	}
1577

    
1578
	if($nameLink && isset($template['namePart']['#uri'])){
1579
		$template['namePart']['#uri'] = $nameLink;
1580
	} else{
1581
		unset($template['namePart']['#uri']);
1582
	}
1583

    
1584
	if($refenceLink && isset($template['referencePart']['#uri'])){
1585
		$template['referencePart']['#uri'] = $refenceLink;
1586
	}else{
1587
		unset($template['referencePart']['#uri']);
1588
	}
1589

    
1590
	return $template;
1591
}
1592

    
1593
function get_partDefinition($taxonNameType){
1594
	//TODO implement admin user interface to allow specify the partdefinitions for any type
1595
	//     preliminar solution: using themes
1596

    
1597
	$partdef = theme('get_partDefinition', $taxonNameType);
1598

    
1599
	if(!is_array($partdef)){
1600
		switch($taxonNameType){
1601
			case 'ZoologicalName': $partdef = array(
1602
        'namePart' => array(
1603
          'name' => true,
1604
			),
1605
        'referencePart' => array(
1606
          'authorTeam' => true
1607
			),
1608
        'microreferencePart' => array(
1609
          'microreference' => true,
1610
			),
1611
        'statusPart' => array(
1612
          'status' => true,
1613
			),
1614
        'descriptionPart' => array(
1615
          'description' => true,
1616
			),
1617
			);
1618
			break;
1619
			case 'BotanicalName': $partdef = array(
1620
        'namePart' => array(
1621
          'name' => true
1622
			),
1623
        'authorTeamPart' => array(
1624
          'authorTeam' => true,   
1625
			),
1626
        'referencePart' => array(
1627
          'reference' => true      
1628
			),
1629
        'microreferencePart' => array(
1630
          'microreference' => true,
1631
			),
1632
        'statusPart' => array(
1633
          'status' => true,
1634
			),
1635
        'descriptionPart' => array(
1636
          'description' => true,
1637
			),
1638
			);
1639
			break;
1640
			default: $partdef = array(
1641
        'namePart' => array(
1642
          'name' => true,
1643
			),
1644
        'authorTeamPart' => array(
1645
          'authorTeam' => true,   
1646
			),
1647
        'referencePart' => array(
1648
          'reference' => true      
1649
			),
1650
        'microreferencePart' => array(
1651
          'microreference' => true,
1652
			),
1653
        'statusPart' => array(
1654
          'status' => true,
1655
			),
1656
        'descriptionPart' => array(
1657
          'description' => true,
1658
			),
1659
			);
1660
		}
1661
	}
1662
	return $partdef;
1663
}
1664

    
1665
/**
1666
 * The function read the metadata info such title or artist of a media file. The
1667
 * function tries at first to get all the info from the file metadata and if it is
1668
 * not avaible look at the media file info stored at the database.
1669
 * @param $media The media file
1670
 * @return array The array with the avilable specified metadata info.
1671
 * TODO rename to read_media_metadata() and move to *.module
1672
 */
1673
function cdm_read_media_metadata($media){
1674

    
1675
	$metadata_caption = array('title' => '',           //media_metadata and media
1676
                              'artist' => '',          //media_metadata and media
1677
                              'rights',                //media_metadata and media
1678
                              'location',              //media_metadata
1679
                              'filename' => '',        //media
1680
                              'mediacreated' => '',    //media
1681
                              'description' => '');    //media
1682

    
1683
	//getting the media metadata
1684
	$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
1685

    
1686
	//title
1687
	//if ($media_metadata->Headline) {
1688
	if ($media_metadata->ObjectName) {
1689
		$metadata_caption['title'] = $media_metadata->ObjectName;
1690
		//	} else if ($media->titleCache){
1691
		//		$metadata_caption['title'] = $media_metadata->ObjectName;
1692
	} else if ($media->titleCache){
1693
		$metadata_caption['title'] = $media->titleCache;
1694
		if ($media->description_L10n)
1695
		$metadata_caption['title'] .= ' - ' . $media->description_L10n;
1696
	}else{ //if there is no title on the db and metadata get file title
1697
    $aux = $media->representations[0]->parts[0]->uri;
1698
    $aux = explode("/", $aux);
1699
    $aux = end($aux);
1700
		$metadata_caption['title'] = $aux;		
1701
	}
1702

    
1703
	//artist
1704
	if ($media_metadata->Artist){
1705
	 $metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
1706
	}
1707
	elseif ($media->artist->titleCache){
1708
	 $metadata_caption['artist'] = $media->artist->titleCache;
1709
	}
1710
	
1711
	//copyright
1712
	$metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
1713
                                      'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
1714
	if ($media_metadata->Copyright)
1715
	$metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
1716
	elseif ($media->rights){
1717
		foreach($media->rights as $right){
1718
			switch($right->term->uuid){
1719
				case UUID_RIGHTS_LICENCE:
1720
					$metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
1721
					$metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
1722
					$metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
1723
					$metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
1724
					break;
1725
				case UUID_RIGHTS_COPYRIGHT:
1726
					$metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
1727
					break;
1728
			}
1729
		}
1730
	}
1731
	else
1732
	$metadata_caption['rights']['agentNames'][] = '';
1733

    
1734
	//filling the description (though there is no description in the db???)
1735
	//$metadata_caption['description'] = $media->description_L10n;
1736

    
1737
	//location
1738
	$metadata_caption['location'] = array();
1739
	$metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
1740
	$metadata_caption['location']['city'] = $media_metadata->City;
1741
	$metadata_caption['location']['province'] = $media_metadata->Province;
1742
	$metadata_caption['location']['country'] = $media_metadata->Country;
1743

    
1744
	//filename
1745
	if(isset($media->representations[0]->parts[0]->uri)){
1746
		$fileUri = $media->representations[0]->parts[0]->uri;
1747
		$filename = substr($fileUri, strrpos($fileUri, "/")+1);
1748
		$metadata_caption['filename'] = $filename;
1749
	}
1750
	else{
1751
	 $metadata_caption['filename'] = '';
1752
	}
1753
	/*
1754
	 //creation date
1755
	 if($media_metadata["Modify Date"])
1756
	 $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
1757
	 else
1758
	 $metadata_caption['mediacreated'] = $media->created;
1759
	 */
1760
	//returned value
1761
	return $metadata_caption;
1762
}
1763

    
1764
/**
1765
 * This function collects all the media from a list of description elements
1766
 * and return them as an Array.
1767
 *
1768
 * @param $descriptionElementes The description elements
1769
 * @return Array The output with all the media
1770
 */
1771
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
1772
	//variables
1773
	$outArrayOfMedia = array(); //return value
1774
	//implementation
1775
	foreach($descriptionElements as $descriptionElement){
1776
		foreach($descriptionElement->media as $media){
1777
			if(isset($media)){
1778
			 $outArrayOfMedia[] = $media;
1779
			}
1780
	 }
1781
	}
1782
	return $outArrayOfMedia;
1783
}
1784

    
1785

    
(5-5/9)