Project

General

Profile

Download (59.1 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" => 1);
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
	  'weight' => 0,
125
      'type' => MENU_LOCAL_TASK,
126
		);
127

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

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

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

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

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

    
195
		$items[] = array(
196
      'path' => 'cdm_dataportal/reference',
197
      'callback' => 'cdm_dataportal_view_reference',
198
      'access' => true,
199
      'type' => MENU_CALLBACK,
200
		// expected callback arguments: uuid
201
		);
202

    
203
		$items[] = array(
204
      'path' => 'cdm_dataportal/reference/list',
205
      'callback' => 'cdm_dataportal_view_reference_list',
206
      'access' => true,
207
      'type' => MENU_CALLBACK,
208
		// expected callback arguments: uuid
209
		);
210

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

    
219
		$items[] = array(
220
      'path' => 'cdm_dataportal/search',
221
      'callback' => 'cdm_dataportal_view_search_advanced',
222
      'access' => true,
223
      'type' => MENU_CALLBACK,
224
		);
225

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

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

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

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

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

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

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

    
311
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
312
	//drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
313
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
314

    
315
	return $items;
316

    
317
}
318

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

    
357

    
358
/**
359
 * Implementation of hook_validate()
360
 *
361
 * @param $element
362
 */
363
function cdm_dataportal_settings_validate($form_id, $form_values){
364

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

    
369
	$cdm_webservice_url_changed = variable_get('cdm_webservice_url', '') != $form_values['cdm_webservice_url'];
370

    
371
	$cdm_secUuid_default_changed = variable_get('cdm_secUuid_default', '') != $form_values['cdm_secUuid_default'];
372

    
373
	if ($cdm_webservice_url_changed || $cdm_secUuid_default_changed) {
374

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

    
389
}
390

    
391
/*
392
 function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
393
 $_SESSION['cdm'] = null;
394
 if(is_string($cdm_ws_uri_update)){
395
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
396
 }
397
 }
398

    
399
 function cdm_dataportal_session_validate(){
400

    
401
 if(!isset($_SESSION['cdm']['ws_uri'])){
402
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
403
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
404
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
405
 }
406
 }
407
 */
408

    
409
function cdm_dataportal_search_taxon_form($advancedForm = false){
410

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

    
418
	$url = 'cdm_dataportal/search/taxon';
419
	$form['#method'] = 'get';
420
	$form['#process'] = array('cdm_dataportal_search_process' => array());
421
	$form['#action'] = url($url, NULL, NULL, true);
422

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

    
431
	$form['search'] = array(
432
      '#delta' => 1,
433
      '#tree' => true,
434
	//'#type' => $advancedForm ? 'fieldset': 'hidden',
435
      '#title' => t('Options')
436
	);
437

    
438
	$form['search']['tree'] = array(
439
    '#delta' => -1,
440
    '#type' => 'hidden',
441
    '#value' => variable_get('cdm_taxonomictree_uuid', false)
442
	);
443

    
444

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

    
455
	$form['search']['pageSize'] = array(
456
      '#delta' => -1,
457
      '#type' => 'hidden',
458
      '#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
459
	);
460

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

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

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

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

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

    
569
	$form['submit'] = array(
570
  '#delta' => 9,
571
  '#type' => 'submit',
572
  '#name' => '',
573
  '#value' => t('Search')
574
	);
575

    
576
	return $form;
577
}
578

    
579
function cdm_dataportal_search_taxon_form_advanced(){
580
	return cdm_dataportal_search_taxon_form(true);
581
}
582

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

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

    
602

    
603
	$form_params = array();
604
	array_deep_copy($_REQUEST['search'], $form_params);
605
	$form_params['query'] =  trim($_REQUEST['query']);
606

    
607
	// split of  geographic range
608
	if(isset($_REQUEST['search']['geographic_range'])){
609
		$geographicRange = $_REQUEST['search']['geographic_range'];
610
		// remove
611
		unset($form_params['geographic_range']);
612
	}
613

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

    
624
	// store in session
625
	$_SESSION['cdm']['search'] = $form_params;
626

    
627
	return $form_params;
628
}
629

    
630

    
631
/* UNREACHABLE since action of form directly links to view
632
 function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
633

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

    
643
/**
644
 * Generate main administration form.
645
 *
646
 * @return
647
 *   An array containing form items to place on the module settings page.
648
 */
649
function cdm_dataportal_settings(){
650

    
651
	$form = cdm_api_settings_form();
652

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

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

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

    
681
	//  $form['cdm_dataportal']['DEBUG']= array(
682
	//    '#value' => '<pre>'.print_r($taxonTrees, true).'</pre>'
683
	//  );
684

    
685

    
686
	//------------------ FEATURE TREE --------------------//
687

    
688
	$form['cdm_dataportal']['feature_tree'] = array(
689
    '#type' => 'fieldset',
690
    '#title' => t('Feature Tree'),
691
    '#collapsible' => TRUE,
692
    '#collapsed' => TRUE,
693
	);
694

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

    
705
	return system_settings_form($form);
706
}
707

    
708
/**
709
 * LAYOUT settings
710
 * @return unknown_type
711
 */
712
function cdm_dataportal_settings_layout(){
713

    
714
	$form = array();
715

    
716

    
717
	$form['cdm_taxonname_type'] = array(
718
    '#type' => 'select',
719
    '#title'         => t('Taxon name type'),
720
    '#default_value' => variable_get('cdm_taxonname_type', 'BotanicalName'),
721
    '#options' => array( 'BotanicalName'=>t('BotanicalName'), 'ZoologicalName'=>t('ZoologicalName')),
722
    '#description'   => t('')
723
	);
724

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

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

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

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

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

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

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

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

    
805
    // --- SEARCH TAXA GALLERY ---- //
806
    $collapsed = TRUE;
807
    $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
808
    $form_tittle = 'Search Taxa';
809
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
810

    
811
    // --- FEATURE DESCRIPTION GALLERY ---- //
812
    $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
813
    $form_tittle = 'Description elements gallery';
814
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
815

    
816
    // --- MEDIA GALLERY ---- //
817
    $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
818
    $form_tittle = 'Media gallery';
819
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
820

    
821
    return system_settings_form($form);
822
}
823

    
824
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed){
825

    
826
	$form[$form_name] = array(
827
    '#type' => 'fieldset',
828
    '#title' => t($form_tittle),
829
    '#collapsible' => TRUE,
830
    '#collapsed' => $collapsed,
831
    '#tree' => true,
832
	);
833

    
834
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
835
	$gallery_settings = variable_get($form_name, $default_values);
836

    
837
  if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
838
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
839
      '#type' => 'checkbox',
840
      '#title' => t('Show media thumbnails for accepted taxa'),
841
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
842
      '#description' => t('')
843
    );
844

    
845
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
846
      '#type' => 'checkbox',
847
      '#title' => t('Show media thumbnails for synonyms'),
848
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
849
      '#description' => t('')
850
    );
851
  }
852
  
853
	//$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
854
	$form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
855
    '#type' => 'checkbox',
856
    '#title' => t('Show captions under thumbnails'),
857
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
858
    '#description' => t('')
859
	);
860

    
861
	$form[$form_name]['cdm_dataportal_media_maxextend'] = array(
862
    '#type' => 'textfield',
863
    '#title' => t('Maximum extend of Images'),
864
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
865
    '#description' => t('In the gallery neither width or height will exceed the maximum extend of images.')
866
	);
867

    
868
	$form[$form_name]['cdm_dataportal_media_cols'] = array(
869
    '#type' => 'textfield',
870
    '#title' => t('Number of columns'),
871
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
872
    '#description' => t('')
873
	);
874

    
875
  if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
876
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
877
      '#type' => 'textfield',
878
      '#title' => t('Maximum number of rows'),
879
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
880
      '#description' => t('If you want an unlimited number of rows please set to 0')
881
    );
882
  }
883

    
884
	return $form;
885
}
886

    
887
/**
888
 * GEOSERVICE and Map settings
889
 * @return unknown_type
890
 */
891
function cdm_dataportal_settings_geo(){
892

    
893
	$form = array();
894

    
895
	$form['cdm_dataportal_map_openlayers'] = array(
896
    '#type' => 'checkbox',
897
    '#title' => t('OpenLayers Viewer'),
898
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
899
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning.')
900
	);
901

    
902
	$form['cdm_dataportal_geoservice_access_point'] = array(
903
    '#type' => 'textfield',
904
    '#title' => t('Geoservice Access Point'),
905
    '#default_value' => variable_get('cdm_dataportal_geoservice_access_point', ''),
906
    '#description' => t('Base URL of the geoservice to be used by this portal')
907
	);
908

    
909
	$form['cdm_dataportal_geoservice_display_width'] = array(
910
    '#type' => 'textfield',
911
    '#title' => t('Geoservice Display Width'),
912
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
913
    '#description' => t('Width of the image generated by geoservice')
914
	);
915

    
916
	$form['cdm_dataportal_geoservice_bounding_box'] = array(
917
    '#type' => 'textfield',
918
    '#title' => t('Fixed Geoservice Bounding Box'),
919
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
920
    '#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.')
921
	);
922

    
923
	//cdm_dataportal_geoservice_labels_on
924
	$form['cdm_dataportal_geoservice_labels_on'] = array(
925
    '#type' => 'checkbox',
926
    '#title' => t('Display Country Labels'),
927
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
928
    '#description' => t('Check this if you like country names to be displayed in the maps. ')
929
	);
930

    
931
	//cdm_dataportal_geoservice_legend_on
932
	$form['cdm_dataportal_geoservice_map_caption'] = array(
933
    '#type' => 'textfield',
934
    '#title' => t('Map Caption'),
935
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
936
    '#description' => t('Define a caption for the map.')
937
	);
938

    
939
	/*
940
	 //cdm_dataportal_geoservice_legend_on
941
	 $form['cdm_dataportal_geoservice_legend_on'] = array(
942
	 '#type' => 'checkbox',
943
	 '#title' => t('Display a map legend'),
944
	 '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
945
	 '#description' => t('Check this if you like a legend to be displayed with the maps. ')
946
	 );
947
	 */
948

    
949
	//cdm_dataportal_geoservice_map_legend
950
	$form['cdm_dataportal_geoservice_map_legend'] = array(
951
      '#type' => 'fieldset',
952
      '#title' => t('Map Legend'),
953
      '#collapsible' => FALSE,
954
      '#collapsed' => TRUE,
955
	);
956

    
957
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
958
    '#type' => 'checkbox',
959
    '#title' => t('Display a map legend'),
960
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
961
    '#description' => t('Check this if you like a legend to be displayed with the maps. ')
962
	);
963

    
964
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
965
    '#type' => 'textfield',
966
    '#title' => t('Font size'),
967
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
968
    '#description' => t('Font size in pixels.')
969
	);
970

    
971
	$fontStyles = array(0 => "plane", 1 => "italic");
972
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
973
    '#type' => 'select',
974
    '#title' => t('Available font styles'),
975
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
976
    '#options' => $fontStyles,
977
    '#description'   => t('Select a font style for the map legend.')
978
	);
979

    
980
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
981
    '#type' => 'textfield',
982
    '#title' => t('Icon width'),
983
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
984
    '#description' => t('Icon width in pixels.')
985
	);
986

    
987
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
988
    '#type' => 'textfield',
989
    '#title' => t('Icon height'),
990
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
991
    '#description' => t('Icon height in pixels.')
992
	);
993

    
994
	/* variable_get('cdm_dataportal_findtaxa_media_maxextend', 120),
995
	 *  $form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
996
	 '#type' => 'select',
997
	 '#title'         => t('Available taxonomic views'),
998
	 '#default_value' => variable_get('cdm_taxonomictree_uuid', false),
999
	 '#options' => $taxonomicTreeOptions,
1000
	 '#description'   => t('Select a taxonomic view for this webservice.')
1001
	 );
1002

    
1003
	 $taxonTrees = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
1004
	 foreach($taxonTrees as $tree){
1005
	 $taxonomicTreeOptions[$tree->uuid] = $tree->titleCache;
1006
	 }
1007
	 $form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
1008
	 '#type' => 'select',
1009
	 '#title'         => t('Available taxonomic views'),
1010
	 '#default_value' => variable_get('cdm_taxonomictree_uuid', false),
1011
	 '#options' => $taxonomicTreeOptions,
1012
	 '#description'   => t('Select a taxonomic view for this webservice.')
1013
	 );
1014
	 */
1015

    
1016
	return system_settings_form($form);
1017

    
1018
}
1019

    
1020

    
1021
/**
1022
 * @return walk and cache all taxon pages
1023
 */
1024
function cdm_dataportal_view_cache_site(){
1025

    
1026
	_add_js_progressbar();
1027

    
1028
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1029

    
1030
	$out = '';
1031

    
1032
	$request_params = array();
1033
	$request_params['query'] = '%';
1034
	$request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false);
1035
	$request_params['doTaxa'] = 1;
1036
	$request_params['doSynonyms'] = 0;
1037
	$request_params['doTaxaByCommonNames'] = 0;
1038
	$search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1039
	$search_url = uri_uriByProxy($search_url);
1040
	$taxon_page_url = url('cdm_dataportal/taxon/');
1041

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

    
1058
	return $out;
1059
}
1060

    
1061
/**
1062
 * Implementation of hook_elements().
1063
 */
1064
function cdm_dataportal_elements() {
1065
	$type['select_secuuid'] = array(
1066
    '#input' => TRUE,
1067
    '#process' => array('cdm_dataportal_select_secuuid_expand' => array()),
1068
	//'#validate' => array('cdm_dataportal_select_secuuid_validate' => array()),
1069
	//'#default_value' => array(),
1070
	);
1071
	return $type;
1072
}
1073

    
1074
/*
1075
 *
1076
 */
1077
function cdm_dataportal_select_secuuid_expand($element){
1078

    
1079
	$element['#tree'] = FALSE;
1080

    
1081
	// any value submitted?
1082
	if(isset($element['#post'][$element['#varname']])){
1083
		$selected_values = $element['#post'][$element['#varname']];
1084
	} else {
1085
		// use those store in drupal
1086
		$selected_values = variable_get( $element['#varname'], array());
1087
	}
1088
	if(!is_array($selected_values)){
1089
		$selected_values = array($selected_values);
1090
	}
1091
	$options = array();
1092
	foreach($selected_values as $secUuid){
1093
		$options[$secUuid] = cdm_taxontree_secRefTitle_for($secUuid);
1094
	}
1095

    
1096
	$element[$element['#varname']] =  array(
1097
    '#type' => 'select',
1098
    '#options' => $options,
1099
    '#default_value' => array_values($options),
1100
    '#size' => $element['#multiple'] ? 12 : 2,
1101
    '#multiple' => $element['#multiple'],
1102
	);
1103
	return $element;
1104
}
1105

    
1106

    
1107

    
1108
/**
1109
 * Displays a list of the known taxonomic names. Long lists are split up into multiple pages
1110
 *
1111
 * TODO: parameters are still preliminar
1112
 * @param String $page page number to diplay defaults to page 1
1113
 * @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
1114
 */
1115
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
1116

    
1117
	$request_params  = array(
1118
    'q' => $beginsWith,
1119
	//'sec' = '',
1120
	//'higherTaxa' => getFiters(),
1121
	// 'matchAnywhere' => false, // default is false
1122
    'page' => $page,
1123
    'onlyAccepted' => $onlyAccepted,
1124
    'pagesize' => 20  /*$_SESSION['cdm']['namelist_pagesize'] */);
1125

    
1126
	$taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
1127
	/*
1128
	 * FIXME the filter for accepted names will be a form element, thus this widget
1129
	 * should be generated via form api preferably as block
1130
	 */
1131
	//$out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1132
	//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1133
	$out .= theme('cdm_listof_taxa', $taxonPager);
1134
	return $out;
1135
}
1136

    
1137
function cdm_dataportal_view_reference($uuid, $arg2 = null){
1138
	$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1139
	return theme('cdm_reference_page', $reference);
1140
}
1141

    
1142
function cdm_dataportal_view_reference_list($pageNumber){
1143
	$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
1144
	return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
1145
}
1146

    
1147
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
1148
	$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1149
	return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
1150
}
1151

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

    
1167
	// display the page for the taxon defined by $uuid
1168
	$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
1169
	return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
1170
}
1171

    
1172
/**
1173
 * @param $uuid
1174
 * @param $chapter name of the part to display,
1175
 *         valid values are: 'description', 'images', 'synonymy', 'all'
1176
 * @return unknown_type
1177
 */
1178
function cdm_dataportal_taxon_view($uuid, $chapter = 'all'){
1179

    
1180
	$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1181
	if(!$taxon){
1182
		drupal_set_title(t('Taxon does not exist'));
1183
		return false;
1184
	}
1185
	_cdm_dataportal_set_currentSecUuid($taxon->sec->uuid);
1186

    
1187
	$taxonpage->title = theme('cdm_taxon_page_title', $taxon);
1188
	$taxonpage->content = theme('cdm_taxon_page_general', $taxon, $chapter);
1189

    
1190
	return $taxonpage;
1191
}
1192

    
1193
/**
1194
 * The function returns a name page as a drupal node ready to be renderized by drupal.
1195
 * The node page show the taxon name title and the list of taxon related with such taxon 
1196
 * name on the tree already in used. 
1197
 * @param $taxon_name_uuid A taxon name uuid
1198
 * @return The formatted name page as node
1199
 */
1200
function cdm_dataportal_name_page_view($taxon_name_uuid){
1201
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid);
1202
  return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
1203
}
1204

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

    
1239
  return $taxon_name_page; 
1240
}
1241

    
1242
function cdm_dataportal_view_search_advanced(){
1243

    
1244
	drupal_set_title(t('Advanced Search'));
1245

    
1246
	$searchForm = cdm_dataportal_search_taxon_form(true);
1247

    
1248
	return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1249

    
1250
}
1251

    
1252
/**
1253
 *
1254
 * future extensions to meet palmweb mockup requirements:
1255
 *  - habitat
1256
 *  - uses
1257
 *  - conservation status
1258
 *  - locality / tdwg region
1259
 */
1260
function cdm_dataportal_view_search_taxon(){
1261

    
1262
	$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
1263

    
1264
	$request_params = cdm_dataportal_search_form_request();
1265
	$taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1266

    
1267
	$search_params = $_REQUEST;
1268
	unset($search_params['q']);
1269
	return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
1270
}
1271

    
1272
///**
1273
// * 
1274
// * @return unknown_type
1275
// */
1276
//function cdm_dataportal_view_name($taxon_name_uuid){
1277
//
1278
//	$taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1279
//	/*
1280
//	$name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1281
//	$records = array();
1282
//	foreach ($taxon_name->taxonBases as $taxon_base){
1283
//		$taxon = cdm_ws_get(CDM_WS_TAXON, array($taxon_base->uuid));
1284
//		$records[] = $taxon;
1285
//	}
1286
//	
1287
//	$out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1288
//	$out .= theme_cdm_list_of_taxa($records, false);
1289
//	*/
1290
//	
1291
//	$request_params = array();
1292
//  $request_params['query'] = $name_cache;
1293
//  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false);
1294
//  $request_params['doTaxa'] = 1;
1295
//  $request_params['doSynonyms'] = 1;
1296
//  $request_params['doTaxaByCommonNames'] = 0;
1297
//  //$request_params['matchMode'] = "EXACT";
1298
//  
1299
//  $taxon_pager = cdm_ws_get(CDM_WS_FIND_TAXA, null, queryString($request_params));
1300
//  //var_dump($taxon_pager->records);
1301
//  //$out = theme_cdm_taxonname_page_title($taxon_name);
1302
//  $out = theme_cdm_list_of_taxa($taxon_pager->records, false);
1303
//  
1304
///*
1305
//  $out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1306
//  $out .= "Taxon name uuid: " . $taxon_name_uuid  . "<br/>";
1307
//  $out .= "Taxon name records: "  . "<br/>" . $records_names_out; 
1308
//*/
1309
//  //$out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1310
//	return $out;
1311
//}
1312

    
1313
function cdm_view_xml2json(){
1314
	$file = arg(2);
1315
	$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
1316
	return  xml2json::transformXmlStringToJson($datastr);
1317
}
1318

    
1319
/* ====================== other functions ====================== */
1320

    
1321
/**
1322
 * Enter description here...
1323
 *
1324
 * @param String $uuid the UUID of the taxon
1325
 * @return the URL
1326
 */
1327
function path_to_taxon($uuid){
1328
	if(!$uuid) return false;
1329
	return 'cdm_dataportal/taxon/'.$uuid;
1330
}
1331

    
1332
function path_to_reference($uuid){
1333
	if(!$uuid) return false;
1334
	return 'cdm_dataportal/reference/'.$uuid;
1335
}
1336

    
1337
function path_to_name($name_uuid){
1338
	$res = false;
1339
	if($name_uuid){
1340
	 $res = 'cdm_dataportal/name/'.$name_uuid;
1341
	}
1342
  return $res;
1343
}
1344

    
1345
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
1346
	if(!$uuid) return false;
1347
	$out = 'cdm_dataportal/media/'.$uuid;
1348
	if($representaion_uuid){
1349
		$out .= '/'.$representaion_uuid;
1350
		if($partId !== false){
1351
			$out .= '/'.$partId;
1352
		}
1353
	}
1354
	return $out;
1355
}
1356

    
1357
/**
1358
 * Compares thisRank with thatRank.
1359
 * Returns a negative integer, zero, or a positive integer
1360
 * as the of thisRank is higher than, equal to, or lower than thatRank.
1361
 * e.g:
1362
 * <ul>
1363
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
1364
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
1365
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
1366
 * </ul>
1367
 * <p>
1368
 * This compare logic of the underlying webservice is the
1369
 * <b>inverse logic</b> of the the one implemented in
1370
 * java.lang.Comparable#compareTo(java.lang.Object)
1371
 * @param $thisRankUuid
1372
 * @param $thatRankUuid
1373
 * @return  a negative integer, zero, or a positive integer
1374
 * as the thisRank is lower than, equal to, or higher than thatRank
1375
 */
1376
function rank_compare($thisRankUuid, $thatRankUuid){
1377
	$result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
1378
	return $result->Integer;
1379
}
1380

    
1381
function uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null){
1382
	$acceptedPath = path_to_taxon($acceptedUuid);
1383
	return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid);
1384
}
1385

    
1386
/**
1387
 * Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
1388
 * If the taggename if empty the fullname will be returned.
1389
 *
1390
 * @param unknown_type $Name or TreeNode
1391
 * @return string
1392
 */
1393
function cdm_dataportal_shortname_of($name){
1394

    
1395
	$nameStr = '';
1396
	// get all tagged text tokens of the scientific name
1397
	foreach($name->taggedTitle as $tagtxt){
1398
		if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
1399
			$nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
1400
		}
1401
	}
1402
	$nameStr = trim($nameStr);
1403
	if($nameStr){
1404
		// do not return short names for these
1405
		if($nameStr == 'Incertae sedis' || $nameStr ==  'Nomina excludenda'){
1406
			return $nameStr;
1407
		}
1408
		if($pos = stripos($nameStr, ' ')){
1409
			return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos);
1410
		} else {
1411
			return $nameStr;
1412
		}
1413
	} else {
1414
		return $name->titleCache;
1415
	}
1416
}
1417

    
1418
/**
1419
 * TODO Add Comments. I don't get what
1420
 *
1421
 * @param UUID $secUuid
1422
 */
1423
function _cdm_dataportal_set_currentSecUuid($secUuid){
1424

    
1425
	// do not save in session but in database
1426

    
1427
	if(is_array($secUuid)){
1428
		$secUuid = $secUuid[0];
1429
	}
1430
	if(!$secUuid){
1431
		variable_set('cdm_currentSecRef', null);
1432
	} else {
1433
		$secRef = cdm_ws_get(CDM_WS_REFERENCE, $secUuid);
1434
		if(isset($secRef)){
1435
			variable_set('cdm_currentSecRef', (array)($secRef));
1436
		}
1437
	}
1438

    
1439
}
1440

    
1441
/**
1442
 * TODO
1443
 * This will not work with multiple instances of the dataportal running
1444
 * under the same host as there is only one session for all instances.
1445
 * In case you switch instances with the same client, you will definitely
1446
 * run into trouble.
1447
 * Also this is not handling multiple secs.
1448
 *
1449
 *
1450
 * returns the current secRef array.
1451
 * If the according session variable is not jet set the default
1452
 * as configured in the setting is used otherwise null.
1453
 *
1454
 * currentSecRef['uuid']
1455
 * currentSecRef[....
1456
 *
1457
 * @return array
1458
 */
1459
function _cdm_dataportal_currentSecRef_array(){
1460

    
1461
	// do not look in session but in database
1462
	if( variable_get('cdm_currentSecRef', null) == null){
1463
		$secUuid = variable_get('cdm_secUuid_default', null);
1464
		_cdm_dataportal_set_currentSecUuid($secUuid);
1465
	}
1466
	return variable_get('cdm_currentSecRef', null);
1467

    
1468
}
1469

    
1470
/**
1471
 * Check if a taxon is accepted by the current taxonomic tree
1472
 *
1473
 * @param Taxon $taxon
1474
 * @return true if $taxon is accepted, false otherwise
1475
 */
1476

    
1477
function _cdm_dataportal_acceptedByCurrentView($taxon){
1478

    
1479
	//$current_secref = _cdm_dataportal_currentSecRef_array();
1480
	$defaultTreeUuid = variable_get('cdm_taxonomictree_uuid', false);
1481
	if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){
1482
		foreach($taxon->taxonNodes as $node){
1483
			if($node->taxonomicTree == $defaultTreeUuid) {
1484
				return true;
1485
			}
1486
		}
1487
	}
1488
	return false;
1489
}
1490

    
1491
/**@Deprecated
1492
 *
1493
 */
1494
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
1495
	$pstr = '';
1496
	foreach($parameters as $key=>$value){
1497
		if(is_array($value)){
1498

    
1499
		} else {
1500
			$pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
1501
		}
1502
	}
1503
	return $pstr;
1504
}
1505

    
1506
function _get_feature_trees(){
1507
	$feature_trees = array();
1508

    
1509
	// set tree that contains all features
1510
	$feature_trees[UUID_DEFAULT_FEATURETREE] = t('Default Featuretree (contains all features)');
1511

    
1512
	// get features from database
1513
	$persisted_trees = cdm_ws_get(CDM_WS_FEATURETREES);
1514
	if(is_array($persisted_trees)){
1515
		foreach($persisted_trees as $featureTree){
1516

    
1517
			// do not add the DEFAULT_FEATURETREE again
1518
			if($featureTree->uuid == UUID_DEFAULT_FEATURETREE){
1519
				continue;
1520
			}
1521
			$featureLabels = array();
1522
			foreach ($featureTree->root->children as $featureNode){
1523
				$featureLabels[] = $featureNode->feature->representation_L10n;
1524
			}
1525

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

    
1528
		}
1529
	}
1530
	return $feature_trees;
1531
}
1532

    
1533

    
1534
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
1535
	//TODO implement admin user interface to replace swicth statement
1536
	//     preliminar solution: using themes
1537

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

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

    
1590
	if($nameLink && isset($template['namePart']['#uri'])){
1591
		$template['namePart']['#uri'] = $nameLink;
1592
	} else{
1593
		unset($template['namePart']['#uri']);
1594
	}
1595

    
1596
	if($refenceLink && isset($template['referencePart']['#uri'])){
1597
		$template['referencePart']['#uri'] = $refenceLink;
1598
	}else{
1599
		unset($template['referencePart']['#uri']);
1600
	}
1601

    
1602
	return $template;
1603
}
1604

    
1605
function get_partDefinition($taxonNameType){
1606
	//TODO implement admin user interface to allow specify the partdefinitions for any type
1607
	//     preliminar solution: using themes
1608

    
1609
	$partdef = theme('get_partDefinition', $taxonNameType);
1610

    
1611
	if(!is_array($partdef)){
1612
		switch($taxonNameType){
1613
			case 'ZoologicalName': $partdef = array(
1614
        'namePart' => array(
1615
          'name' => true,
1616
			),
1617
        'referencePart' => array(
1618
          'authorTeam' => true
1619
			),
1620
        'microreferencePart' => array(
1621
          'microreference' => true,
1622
			),
1623
        'statusPart' => array(
1624
          'status' => true,
1625
			),
1626
        'descriptionPart' => array(
1627
          'description' => true,
1628
			),
1629
			);
1630
			break;
1631
			case 'BotanicalName': $partdef = array(
1632
        'namePart' => array(
1633
          'name' => true
1634
			),
1635
        'authorTeamPart' => array(
1636
          'authorTeam' => true,   
1637
			),
1638
        'referencePart' => array(
1639
          'reference' => true      
1640
			),
1641
        'microreferencePart' => array(
1642
          'microreference' => true,
1643
			),
1644
        'statusPart' => array(
1645
          'status' => true,
1646
			),
1647
        'descriptionPart' => array(
1648
          'description' => true,
1649
			),
1650
			);
1651
			break;
1652
			default: $partdef = array(
1653
        'namePart' => array(
1654
          'name' => true,
1655
			),
1656
        'authorTeamPart' => array(
1657
          'authorTeam' => true,   
1658
			),
1659
        'referencePart' => array(
1660
          'reference' => true      
1661
			),
1662
        'microreferencePart' => array(
1663
          'microreference' => true,
1664
			),
1665
        'statusPart' => array(
1666
          'status' => true,
1667
			),
1668
        'descriptionPart' => array(
1669
          'description' => true,
1670
			),
1671
			);
1672
		}
1673
	}
1674
	return $partdef;
1675
}
1676

    
1677
/**
1678
 * The function read the metadata info such title or artist of a media file. The
1679
 * function tries at first to get all the info from the file metadata and if it is
1680
 * not avaible look at the media file info stored at the database.
1681
 * @param $media The media file
1682
 * @return array The array with the avilable specified metadata info.
1683
 * TODO rename to read_media_metadata() and move to *.module
1684
 */
1685
function cdm_read_media_metadata($media){
1686

    
1687
	$metadata_caption = array('title' => '',           //media_metadata and media
1688
                              'artist' => '',          //media_metadata and media
1689
                              'rights',                //media_metadata and media
1690
                              'location',              //media_metadata
1691
                              'filename' => '',        //media
1692
                              'mediacreated' => '',    //media
1693
                              'description' => '');    //media
1694

    
1695
	//getting the media metadata
1696
	$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
1697

    
1698
	//title
1699
	//if ($media_metadata->Headline) {
1700
	if ($media_metadata->ObjectName) {
1701
		$metadata_caption['title'] = $media_metadata->ObjectName;
1702
		//	} else if ($media->titleCache){
1703
		//		$metadata_caption['title'] = $media_metadata->ObjectName;
1704
	} else if ($media->titleCache){
1705
		$metadata_caption['title'] = $media->titleCache;
1706
		if ($media->description_L10n)
1707
		$metadata_caption['title'] .= ' - ' . $media->description_L10n;
1708
	}else{ //if there is no title on the db and metadata get file title
1709
    $aux = $media->representations[0]->parts[0]->uri;
1710
    $aux = explode("/", $aux);
1711
    $aux = end($aux);
1712
		$metadata_caption['title'] = $aux;		
1713
	}
1714

    
1715
	//artist
1716
	if ($media_metadata->Artist){
1717
	 $metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
1718
	}
1719
	elseif ($media->artist->titleCache){
1720
	 $metadata_caption['artist'] = $media->artist->titleCache;
1721
	}
1722
	
1723
	//copyright
1724
	$metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
1725
                                      'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
1726
	if ($media_metadata->Copyright)
1727
	$metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
1728
	elseif ($media->rights){
1729
		foreach($media->rights as $right){
1730
			switch($right->term->uuid){
1731
				case UUID_RIGHTS_LICENCE:
1732
					$metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
1733
					$metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
1734
					$metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
1735
					$metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
1736
					break;
1737
				case UUID_RIGHTS_COPYRIGHT:
1738
					$metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
1739
					break;
1740
			}
1741
		}
1742
	}
1743
	else
1744
	$metadata_caption['rights']['agentNames'][] = '';
1745

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

    
1749
	//location
1750
	$metadata_caption['location'] = array();
1751
	$metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
1752
	$metadata_caption['location']['city'] = $media_metadata->City;
1753
	$metadata_caption['location']['province'] = $media_metadata->Province;
1754
	$metadata_caption['location']['country'] = $media_metadata->Country;
1755

    
1756
	//filename
1757
	if(isset($media->representations[0]->parts[0]->uri)){
1758
		$fileUri = $media->representations[0]->parts[0]->uri;
1759
		$filename = substr($fileUri, strrpos($fileUri, "/")+1);
1760
		$metadata_caption['filename'] = $filename;
1761
	}
1762
	else{
1763
	 $metadata_caption['filename'] = '';
1764
	}
1765
	/*
1766
	 //creation date
1767
	 if($media_metadata["Modify Date"])
1768
	 $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
1769
	 else
1770
	 $metadata_caption['mediacreated'] = $media->created;
1771
	 */
1772
	//returned value
1773
	return $metadata_caption;
1774
}
1775

    
1776
/**
1777
 * This function collects all the media from a list of description elements
1778
 * and return them as an Array.
1779
 *
1780
 * @param $descriptionElementes The description elements
1781
 * @return Array The output with all the media
1782
 */
1783
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
1784
	//variables
1785
	$outArrayOfMedia = array(); //return value
1786
	//implementation
1787
	foreach($descriptionElements as $descriptionElement){
1788
		foreach($descriptionElement->media as $media){
1789
			if(isset($media)){
1790
			 $outArrayOfMedia[] = $media;
1791
			}
1792
	 }
1793
	}
1794
	return $outArrayOfMedia;
1795
}
1796

    
1797

    
(5-5/9)