Project

General

Profile

Download (60.2 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
		$form_values['cdm_webservice_url'] .= '/';
368
	}
369

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

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

    
388
}
389

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

    
398
 function cdm_dataportal_session_validate(){
399

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

    
408
function cdm_dataportal_search_taxon_form($advancedForm = false){
409

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

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

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

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

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

    
443

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

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

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

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

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

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

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

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

    
575
	return $form;
576
}
577

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

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

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

    
601

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

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

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

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

    
626
	return $form_params;
627
}
628

    
629

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

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

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

    
650
	$form = cdm_api_settings_form();
651

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

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

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

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

    
684

    
685
	//------------------ FEATURE TREE --------------------//
686

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

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

    
704
	return system_settings_form($form);
705
}
706

    
707
function cdm_dataportal_form_alter($form_id, &$form) {
708
    
709
static $comment_node_disabled =  0;
710
static $comment_node_read_only =  1;
711
static $comment_node_read_write =  2;
712
   
713
    
714
  if ($form_id == 'node_type_form' 
715
    && isset($form['identity']['type']) 
716
    && array_key_exists($form['#node_type']->type, cdm_dataportal_get_nodetypes()) 
717
    ) {
718
    $form['workflow']['comment'] = array(
719
      '#type' => 'radios',
720
      '#title' => t('Default comment setting'),
721
      '#default_value' => variable_get('comment_'. $form['#node_type']->type, $comment_node_disabled),
722
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
723
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
724
    );
725
  }
726
}
727

    
728
/**
729
 * LAYOUT settings
730
 * @return unknown_type
731
 */
732
function cdm_dataportal_settings_layout(){
733

    
734
	$form = array();
735

    
736

    
737
	$form['cdm_taxonname_type'] = array(
738
    '#type' => 'select',
739
    '#title'         => t('Taxon name type'),
740
    '#default_value' => variable_get('cdm_taxonname_type', 'BotanicalName'),
741
    '#options' => array( 'BotanicalName'=>t('BotanicalName'), 'ZoologicalName'=>t('ZoologicalName')),
742
    '#description'   => t('')
743
	);
744

    
745
	$form['cdm_dataportal_nomref_in_title'] = array(
746
    '#type' => 'checkbox',
747
    '#title' => t('Show full nomenclatural reference in title'),
748
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
749
    '#description' => t('Uncheck this, if you want the title of a taxon page consisting of name and author plus publication year only.
750
                        If not checked, the first homotypic taxon is a repetition of the accepted taxon with
751
                        the full nomenclatural reference.')
752
	);
753

    
754
	$form['cdm_dataportal_display_name_relations'] = array(
755
    '#type' => 'checkbox',
756
    '#title' => t('Show name relations of accepted taxa on taxon page'),
757
    '#default_value' => variable_get('cdm_dataportal_display_name_relations', 1),
758
    '#description' => t('')
759
	);
760

    
761
	$form['cdm_dataportal_display_is_accepted_for'] = array(
762
    '#type' => 'checkbox',
763
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
764
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
765
    '#description' => t('')
766
	);
767

    
768
	$form['cdm_dataportal_name_relations_skiptype_basionym'] = array(
769
    '#type' => 'checkbox',
770
    '#title' => t('Exclude the basionym relationship type from the taxon page'),
771
    '#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
772
    '#description' => t('')
773
	);
774

    
775
	$form['cdm_dataportal_taxonpage_tabs'] = array(
776
    '#type' => 'checkbox',
777
    '#title' => t('Tabbed taxon page'),
778
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
779
    '#description' => t('Split the taxon page into individual tabs for description, images, synonymy')
780
	);
781

    
782
	$form['cdm_dataportal_search_items_on_page'] = array(
783
    '#type' => 'textfield',
784
    '#title' => t('Search Page Size'),
785
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
786
    '#description' => t('Number of Names to display per page in search results.')
787
	);
788

    
789
	$form['cdm_dataportal_descriptions_separated'] = array(
790
    '#type' => 'checkbox',
791
    '#title' => t('Separate Descriptions'),
792
    '#default_value' => variable_get('cdm_dataportal_descriptions_separated', 0),
793
    '#description' => t('By default corresponding elements of different descriptions are joined together'
794
    .' into a common section per feature (i.e. type of description).'
795
    .' Check this box to allow displaying all descriptions separately.')
796
    );
797

    
798
    //---- IMAGES ----//
799
    $form['images'] = array(
800
    '#type' => 'fieldset',
801
    '#title' => t('Images'),
802
    '#collapsible' => TRUE,
803
    '#collapsed' => FALSE,
804
    );
805
    $options = cdm_rankVocabulary_as_option();
806
    array_unshift($options, '-- DISABLED --');
807
    $form['images']['image_hide_rank'] =  array(
808
    '#type'          => 'select',
809
    '#title'         => t('Hide Images for Taxa above'),
810
    '#default_value' => variable_get('image_hide_rank', '0'),
811
    '#options'       => $options,
812
    '#description'   => t(''),
813
    );
814
    //show media
815
    $selectShowMedia = array(0 => "Show only taxon media",
816
    1 => "Show taxon and child taxon media");
817
    $form['images']['cdm_dataportal_show_media'] = array(
818
    '#type' => 'select',
819
    '#title' => t('Available media files'),
820
    '#default_value' => variable_get('cdm_dataportal_show_media', false),
821
    '#options' => $selectShowMedia,
822
    '#description'   => t('Select if a taxon should show only his media or also child media.')
823
    );
824

    
825
    // --- SEARCH TAXA GALLERY ---- //
826
    $collapsed = TRUE;
827
    $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
828
    $form_tittle = 'Search Taxa';
829
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
830

    
831
    // --- FEATURE DESCRIPTION GALLERY ---- //
832
    $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
833
    $form_tittle = 'Description elements gallery';
834
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
835

    
836
    // --- MEDIA GALLERY ---- //
837
    $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
838
    $form_tittle = 'Media gallery';
839
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
840

    
841
    return system_settings_form($form);
842
}
843

    
844
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed){
845

    
846
	$form[$form_name] = array(
847
    '#type' => 'fieldset',
848
    '#title' => t($form_tittle),
849
    '#collapsible' => TRUE,
850
    '#collapsed' => $collapsed,
851
    '#tree' => true,
852
	);
853

    
854
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
855
	$gallery_settings = variable_get($form_name, $default_values);
856

    
857
  if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
858
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
859
      '#type' => 'checkbox',
860
      '#title' => t('Show media thumbnails for accepted taxa'),
861
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
862
      '#description' => t('')
863
    );
864

    
865
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
866
      '#type' => 'checkbox',
867
      '#title' => t('Show media thumbnails for synonyms'),
868
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
869
      '#description' => t('')
870
    );
871
  }
872
  
873
	//$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
874
	$form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
875
    '#type' => 'checkbox',
876
    '#title' => t('Show captions under thumbnails'),
877
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
878
    '#description' => t('')
879
	);
880

    
881
	$form[$form_name]['cdm_dataportal_media_maxextend'] = array(
882
    '#type' => 'textfield',
883
    '#title' => t('Maximum extend of Images'),
884
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
885
    '#description' => t('In the gallery neither width or height will exceed the maximum extend of images.')
886
	);
887

    
888
	$form[$form_name]['cdm_dataportal_media_cols'] = array(
889
    '#type' => 'textfield',
890
    '#title' => t('Number of columns'),
891
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
892
    '#description' => t('')
893
	);
894

    
895
  if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
896
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
897
      '#type' => 'textfield',
898
      '#title' => t('Maximum number of rows'),
899
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
900
      '#description' => t('If you want an unlimited number of rows please set to 0')
901
    );
902
  }
903

    
904
	return $form;
905
}
906

    
907
/**
908
 * GEOSERVICE and Map settings
909
 * @return unknown_type
910
 */
911
function cdm_dataportal_settings_geo(){
912

    
913
	$form = array();
914

    
915
	$form['cdm_dataportal_map_openlayers'] = array(
916
    '#type' => 'checkbox',
917
    '#title' => t('OpenLayers Viewer'),
918
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
919
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning.')
920
	);
921

    
922
	$form['cdm_dataportal_geoservice_access_point'] = array(
923
    '#type' => 'textfield',
924
    '#title' => t('Geoservice Access Point'),
925
    '#default_value' => variable_get('cdm_dataportal_geoservice_access_point', ''),
926
    '#description' => t('Base URL of the geoservice to be used by this portal')
927
	);
928

    
929
	$form['cdm_dataportal_geoservice_display_width'] = array(
930
    '#type' => 'textfield',
931
    '#title' => t('Geoservice Display Width'),
932
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
933
    '#description' => t('Width of the image generated by geoservice')
934
	);
935

    
936
	$form['cdm_dataportal_geoservice_bounding_box'] = array(
937
    '#type' => 'textfield',
938
    '#title' => t('Fixed Geoservice Bounding Box'),
939
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
940
    '#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.')
941
	);
942

    
943
	//cdm_dataportal_geoservice_labels_on
944
	$form['cdm_dataportal_geoservice_labels_on'] = array(
945
    '#type' => 'checkbox',
946
    '#title' => t('Display Country Labels'),
947
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
948
    '#description' => t('Check this if you like country names to be displayed in the maps. ')
949
	);
950

    
951
	//cdm_dataportal_geoservice_legend_on
952
	$form['cdm_dataportal_geoservice_map_caption'] = array(
953
    '#type' => 'textfield',
954
    '#title' => t('Map Caption'),
955
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
956
    '#description' => t('Define a caption for the map.')
957
	);
958

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

    
969
	//cdm_dataportal_geoservice_map_legend
970
	$form['cdm_dataportal_geoservice_map_legend'] = array(
971
      '#type' => 'fieldset',
972
      '#title' => t('Map Legend'),
973
      '#collapsible' => FALSE,
974
      '#collapsed' => TRUE,
975
	);
976

    
977
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
978
    '#type' => 'checkbox',
979
    '#title' => t('Display a map legend'),
980
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
981
    '#description' => t('Check this if you like a legend to be displayed with the maps. ')
982
	);
983

    
984
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
985
    '#type' => 'textfield',
986
    '#title' => t('Font size'),
987
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
988
    '#description' => t('Font size in pixels.')
989
	);
990

    
991
	$fontStyles = array(0 => "plane", 1 => "italic");
992
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
993
    '#type' => 'select',
994
    '#title' => t('Available font styles'),
995
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
996
    '#options' => $fontStyles,
997
    '#description'   => t('Select a font style for the map legend.')
998
	);
999

    
1000
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1001
    '#type' => 'textfield',
1002
    '#title' => t('Icon width'),
1003
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1004
    '#description' => t('Icon width in pixels.')
1005
	);
1006

    
1007
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1008
    '#type' => 'textfield',
1009
    '#title' => t('Icon height'),
1010
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1011
    '#description' => t('Icon height in pixels.')
1012
	);
1013

    
1014
	/* variable_get('cdm_dataportal_findtaxa_media_maxextend', 120),
1015
	 *  $form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
1016
	 '#type' => 'select',
1017
	 '#title'         => t('Available taxonomic views'),
1018
	 '#default_value' => variable_get('cdm_taxonomictree_uuid', false),
1019
	 '#options' => $taxonomicTreeOptions,
1020
	 '#description'   => t('Select a taxonomic view for this webservice.')
1021
	 );
1022

    
1023
	 $taxonTrees = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
1024
	 foreach($taxonTrees as $tree){
1025
	 $taxonomicTreeOptions[$tree->uuid] = $tree->titleCache;
1026
	 }
1027
	 $form['cdm_dataportal']['cdm_taxonomictree_uuid'] = array(
1028
	 '#type' => 'select',
1029
	 '#title'         => t('Available taxonomic views'),
1030
	 '#default_value' => variable_get('cdm_taxonomictree_uuid', false),
1031
	 '#options' => $taxonomicTreeOptions,
1032
	 '#description'   => t('Select a taxonomic view for this webservice.')
1033
	 );
1034
	 */
1035

    
1036
	return system_settings_form($form);
1037

    
1038
}
1039

    
1040

    
1041
/**
1042
 * @return walk and cache all taxon pages
1043
 */
1044
function cdm_dataportal_view_cache_site(){
1045

    
1046
	_add_js_progressbar();
1047

    
1048
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1049

    
1050
	$out = '';
1051

    
1052
	$request_params = array();
1053
	$request_params['query'] = '%';
1054
	$request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false);
1055
	$request_params['doTaxa'] = 1;
1056
	$request_params['doSynonyms'] = 0;
1057
	$request_params['doTaxaByCommonNames'] = 0;
1058
	$search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1059
	$search_url = uri_uriByProxy($search_url);
1060
	$taxon_page_url = url('cdm_dataportal/taxon/');
1061

    
1062
	$out .= '<form id="cache_site">';
1063
	$out .= '<br /><h4>'.t('Cache all taxon pages').'</h4>';
1064
	$out .= 'Before  running the cache bot you have to empty the cache manually:<ul>' 
1065
            .'<li>Navigate to "Site Configuration -> General"</li>'
1066
            .'<li>Uncheck "Enable Caching" checkbox</li>'
1067
            .'<li>Check "Enable Caching" checkbox</li>'
1068
	        .'</ul>';
1069
	$out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
1070
	$out .= '<div id="progress"></div>';
1071
	$out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
1072
	$out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
1073
	$out .= '<input type="button" name="start" value="'.t('Start').'"/>';
1074
	$out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
1075
	$out .= '</form>';
1076
	$out .= '</div>';
1077
	//  foreach($taxonPager->records as $taxon){
1078
	//    cdm_dataportal_taxon_view($uuid);
1079
	//  }
1080

    
1081
	return $out;
1082
}
1083

    
1084
/**
1085
 * Implementation of hook_elements().
1086
 */
1087
function cdm_dataportal_elements() {
1088
	$type['select_secuuid'] = array(
1089
    '#input' => TRUE,
1090
    '#process' => array('cdm_dataportal_select_secuuid_expand' => array()),
1091
	//'#validate' => array('cdm_dataportal_select_secuuid_validate' => array()),
1092
	//'#default_value' => array(),
1093
	);
1094
	return $type;
1095
}
1096

    
1097
/*
1098
 *
1099
 */
1100
function cdm_dataportal_select_secuuid_expand($element){
1101

    
1102
	$element['#tree'] = FALSE;
1103

    
1104
	// any value submitted?
1105
	if(isset($element['#post'][$element['#varname']])){
1106
		$selected_values = $element['#post'][$element['#varname']];
1107
	} else {
1108
		// use those store in drupal
1109
		$selected_values = variable_get( $element['#varname'], array());
1110
	}
1111
	if(!is_array($selected_values)){
1112
		$selected_values = array($selected_values);
1113
	}
1114
	$options = array();
1115
	foreach($selected_values as $secUuid){
1116
		$options[$secUuid] = cdm_taxontree_secRefTitle_for($secUuid);
1117
	}
1118

    
1119
	$element[$element['#varname']] =  array(
1120
    '#type' => 'select',
1121
    '#options' => $options,
1122
    '#default_value' => array_values($options),
1123
    '#size' => $element['#multiple'] ? 12 : 2,
1124
    '#multiple' => $element['#multiple'],
1125
	);
1126
	return $element;
1127
}
1128

    
1129

    
1130

    
1131
/**
1132
 * Displays a list of the known taxonomic names. Long lists are split up into multiple pages
1133
 *
1134
 * TODO: parameters are still preliminar
1135
 * @param String $page page number to diplay defaults to page 1
1136
 * @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
1137
 */
1138
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
1139

    
1140
	$request_params  = array(
1141
    'q' => $beginsWith,
1142
	//'sec' = '',
1143
	//'higherTaxa' => getFiters(),
1144
	// 'matchAnywhere' => false, // default is false
1145
    'page' => $page,
1146
    'onlyAccepted' => $onlyAccepted,
1147
    'pagesize' => 20  /*$_SESSION['cdm']['namelist_pagesize'] */);
1148

    
1149
	$taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
1150
	/*
1151
	 * FIXME the filter for accepted names will be a form element, thus this widget
1152
	 * should be generated via form api preferably as block
1153
	 */
1154
	//$out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1155
	//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1156
	$out .= theme('cdm_listof_taxa', $taxonPager);
1157
	return $out;
1158
}
1159

    
1160
function cdm_dataportal_view_reference($uuid, $arg2 = null){
1161
	$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1162
	return theme('cdm_reference_page', $reference);
1163
}
1164

    
1165
function cdm_dataportal_view_reference_list($pageNumber){
1166
	$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
1167
	return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
1168
}
1169

    
1170
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
1171
	$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1172
	return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
1173
}
1174

    
1175
/**
1176
 * The taxon page gives detailed information on a taxon, it shows:
1177
 *  - Taxon name
1178
 *  - Full list of synonyms homotypic synonyms on top, followed by the
1179
 *    heterotypic and finally followed by misapplied names.
1180
 *    The list is ordered historically.
1181
 *  - All description associated with the taxon.
1182
 *
1183
 * @param $uuid
1184
 * @param $chapter name of the part to display,
1185
 *         valid values are: 'description', 'images', 'synonymy', 'all'
1186
 * @return unknown_type
1187
 */
1188
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all'){
1189

    
1190
	// display the page for the taxon defined by $uuid
1191
	$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
1192
	return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
1193
}
1194

    
1195
/**
1196
 * @param $uuid
1197
 * @param $chapter name of the part to display,
1198
 *         valid values are: 'description', 'images', 'synonymy', 'all'
1199
 * @return unknown_type
1200
 */
1201
function cdm_dataportal_taxon_view($uuid, $chapter = 'all'){
1202

    
1203
	$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1204
	if(!$taxon){
1205
		drupal_set_title(t('Taxon does not exist'));
1206
		return false;
1207
	}
1208
	//FIXME remove _cdm_dataportal_set_currentSecUuid($taxon->sec->uuid);
1209

    
1210
	$taxonpage->title = theme('cdm_taxon_page_title', $taxon);
1211
	$taxonpage->content = theme('cdm_taxon_page_general', $taxon, $chapter);
1212

    
1213
	return $taxonpage;
1214
}
1215

    
1216
/**
1217
 * The function returns a name page as a drupal node ready to be renderized by drupal.
1218
 * The node page show the taxon name title and the list of taxon related with such taxon 
1219
 * name on the tree already in used. 
1220
 * @param $taxon_name_uuid A taxon name uuid
1221
 * @return The formatted name page as node
1222
 */
1223
function cdm_dataportal_name_page_view($taxon_name_uuid){
1224
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid);
1225
  return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
1226
}
1227

    
1228
/**
1229
 * The function genates a object ready to be transformated to a node 
1230
 * in order to show as a drupal node
1231
 * @param $taxon_name_uuid
1232
 * @return the object with the page content and title  
1233
 */
1234
function cdm_dataportal_name_view($taxon_name_uuid){
1235
	//getting the full taxonname object from the server  
1236
  $taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1237
  if(!$taxon_name){
1238
    drupal_set_title(t('Taxon name does not exist'));
1239
    return false;
1240
  }
1241
  //searching for all the taxon connected with the taxon name on the tree in used
1242
  $name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1243
  $request_params = array();
1244
  $request_params['query'] = $name_cache;
1245
  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false);
1246
  $request_params['doTaxa'] = 1;
1247
  $request_params['doSynonyms'] = 1;
1248
  $request_params['doTaxaByCommonNames'] = 0;
1249
  $request_params['matchMode'] = "EXACT";
1250
  $taxon_pager = cdm_ws_get(CDM_WS_FIND_TAXA, null, queryString($request_params));
1251
  
1252
  //_cdm_dataportal_set_currentSecUuid($taxon->sec->uuid);
1253
  
1254
  //generating the returned object
1255
  $taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
1256
  if($taxon_pager->records){
1257
    $taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
1258
  }else{
1259
    $taxon_name_page->content = 'This name has no taxa';
1260
  }
1261

    
1262
  return $taxon_name_page; 
1263
}
1264

    
1265
function cdm_dataportal_view_search_advanced(){
1266

    
1267
	drupal_set_title(t('Advanced Search'));
1268

    
1269
	$searchForm = cdm_dataportal_search_taxon_form(true);
1270

    
1271
	return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1272

    
1273
}
1274

    
1275
/**
1276
 *
1277
 * future extensions to meet palmweb mockup requirements:
1278
 *  - habitat
1279
 *  - uses
1280
 *  - conservation status
1281
 *  - locality / tdwg region
1282
 */
1283
function cdm_dataportal_view_search_taxon(){
1284

    
1285
	$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
1286

    
1287
	$request_params = cdm_dataportal_search_form_request();
1288
	$taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1289

    
1290
	$search_params = $_REQUEST;
1291
	unset($search_params['q']);
1292
	return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
1293
}
1294

    
1295
///**
1296
// * 
1297
// * @return unknown_type
1298
// */
1299
//function cdm_dataportal_view_name($taxon_name_uuid){
1300
//
1301
//	$taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1302
//	/*
1303
//	$name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1304
//	$records = array();
1305
//	foreach ($taxon_name->taxonBases as $taxon_base){
1306
//		$taxon = cdm_ws_get(CDM_WS_TAXON, array($taxon_base->uuid));
1307
//		$records[] = $taxon;
1308
//	}
1309
//	
1310
//	$out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1311
//	$out .= theme_cdm_list_of_taxa($records, false);
1312
//	*/
1313
//	
1314
//	$request_params = array();
1315
//  $request_params['query'] = $name_cache;
1316
//  $request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false);
1317
//  $request_params['doTaxa'] = 1;
1318
//  $request_params['doSynonyms'] = 1;
1319
//  $request_params['doTaxaByCommonNames'] = 0;
1320
//  //$request_params['matchMode'] = "EXACT";
1321
//  
1322
//  $taxon_pager = cdm_ws_get(CDM_WS_FIND_TAXA, null, queryString($request_params));
1323
//  //var_dump($taxon_pager->records);
1324
//  //$out = theme_cdm_taxonname_page_title($taxon_name);
1325
//  $out = theme_cdm_list_of_taxa($taxon_pager->records, false);
1326
//  
1327
///*
1328
//  $out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1329
//  $out .= "Taxon name uuid: " . $taxon_name_uuid  . "<br/>";
1330
//  $out .= "Taxon name records: "  . "<br/>" . $records_names_out; 
1331
//*/
1332
//  //$out  = "Taxon name: " . $taxon_name->titleCache . "<br/>";
1333
//	return $out;
1334
//}
1335

    
1336
function cdm_view_xml2json(){
1337
	$file = arg(2);
1338
	$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
1339
	return  xml2json::transformXmlStringToJson($datastr);
1340
}
1341

    
1342
/* ====================== other functions ====================== */
1343

    
1344
/**
1345
 * Enter description here...
1346
 *
1347
 * @param String $uuid the UUID of the taxon
1348
 * @return the URL
1349
 */
1350
function path_to_taxon($uuid){
1351
	if(!$uuid) return false;
1352
	return 'cdm_dataportal/taxon/'.$uuid;
1353
}
1354

    
1355
function path_to_reference($uuid){
1356
	if(!$uuid) return false;
1357
	return 'cdm_dataportal/reference/'.$uuid;
1358
}
1359

    
1360
function path_to_name($name_uuid){
1361
	$res = false;
1362
	if($name_uuid){
1363
	 $res = 'cdm_dataportal/name/'.$name_uuid;
1364
	}
1365
  return $res;
1366
}
1367

    
1368
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
1369
	if(!$uuid) return false;
1370
	$out = 'cdm_dataportal/media/'.$uuid;
1371
	if($representaion_uuid){
1372
		$out .= '/'.$representaion_uuid;
1373
		if($partId !== false){
1374
			$out .= '/'.$partId;
1375
		}
1376
	}
1377
	return $out;
1378
}
1379

    
1380
/**
1381
 * Compares thisRank with thatRank.
1382
 * Returns a negative integer, zero, or a positive integer
1383
 * as the of thisRank is higher than, equal to, or lower than thatRank.
1384
 * e.g:
1385
 * <ul>
1386
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
1387
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
1388
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
1389
 * </ul>
1390
 * <p>
1391
 * This compare logic of the underlying webservice is the
1392
 * <b>inverse logic</b> of the the one implemented in
1393
 * java.lang.Comparable#compareTo(java.lang.Object)
1394
 * @param $thisRankUuid
1395
 * @param $thatRankUuid
1396
 * @return  a negative integer, zero, or a positive integer
1397
 * as the thisRank is lower than, equal to, or higher than thatRank
1398
 */
1399
function rank_compare($thisRankUuid, $thatRankUuid){
1400
	$result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
1401
	return $result->Integer;
1402
}
1403

    
1404
function uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null){
1405
	$acceptedPath = path_to_taxon($acceptedUuid);
1406
	return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid);
1407
}
1408

    
1409
/**
1410
 * Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
1411
 * If the taggename if empty the fullname will be returned.
1412
 *
1413
 * @param unknown_type $Name or TreeNode
1414
 * @return string
1415
 */
1416
function cdm_dataportal_shortname_of($name){
1417

    
1418
	$nameStr = '';
1419
	// get all tagged text tokens of the scientific name
1420
	foreach($name->taggedTitle as $tagtxt){
1421
		if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
1422
			$nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
1423
		}
1424
	}
1425
	$nameStr = trim($nameStr);
1426
	if($nameStr){
1427
		// do not return short names for these
1428
		if($nameStr == 'Incertae sedis' || $nameStr ==  'Nomina excludenda'){
1429
			return $nameStr;
1430
		}
1431
		if($pos = stripos($nameStr, ' ')){
1432
			return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos);
1433
		} else {
1434
			return $nameStr;
1435
		}
1436
	} else {
1437
		return $name->titleCache;
1438
	}
1439
}
1440

    
1441
/**
1442
 * TODO Add Comments. I don't get what
1443
 *
1444
 * @param UUID $secUuid
1445
 */
1446
function _cdm_dataportal_set_currentSecUuid($secUuid){
1447

    
1448
	// do not save in session but in database
1449

    
1450
	if(is_array($secUuid)){
1451
		$secUuid = $secUuid[0];
1452
	}
1453
	if(!$secUuid){
1454
		variable_set('cdm_currentSecRef', null);
1455
	} else {
1456
		$secRef = cdm_ws_get(CDM_WS_REFERENCE, $secUuid);
1457
		if(isset($secRef)){
1458
			variable_set('cdm_currentSecRef', (array)($secRef));
1459
		}
1460
	}
1461

    
1462
}
1463

    
1464
/**
1465
 * TODO
1466
 * This will not work with multiple instances of the dataportal running
1467
 * under the same host as there is only one session for all instances.
1468
 * In case you switch instances with the same client, you will definitely
1469
 * run into trouble.
1470
 * Also this is not handling multiple secs.
1471
 *
1472
 *
1473
 * returns the current secRef array.
1474
 * If the according session variable is not jet set the default
1475
 * as configured in the setting is used otherwise null.
1476
 *
1477
 * currentSecRef['uuid']
1478
 * currentSecRef[....
1479
 *
1480
 * @return array
1481
 */
1482
//FIXME function _cdm_dataportal_currentSecRef_array(){
1483
//
1484
//	// do not look in session but in database
1485
//	if( variable_get('cdm_currentSecRef', null) == null){
1486
//		$secUuid = variable_get('cdm_secUuid_default', null);
1487
//		_cdm_dataportal_set_currentSecUuid($secUuid);
1488
//	}
1489
//	return variable_get('cdm_currentSecRef', null);
1490
//
1491
//}
1492

    
1493
/**
1494
 * Check if a taxon is accepted by the current taxonomic tree
1495
 *
1496
 * @param Taxon $taxon
1497
 * @return true if $taxon is accepted, false otherwise
1498
 */
1499

    
1500
function _cdm_dataportal_acceptedByCurrentView($taxon){
1501

    
1502
	//FIXME $current_secref = _cdm_dataportal_currentSecRef_array();
1503
	$defaultTreeUuid = variable_get('cdm_taxonomictree_uuid', false);
1504
	if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){
1505
		foreach($taxon->taxonNodes as $node){
1506
			if($node->taxonomicTree == $defaultTreeUuid) {
1507
				return true;
1508
			}
1509
		}
1510
	}
1511
	return false;
1512
}
1513

    
1514
/**@Deprecated
1515
 *
1516
 */
1517
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
1518
	$pstr = '';
1519
	foreach($parameters as $key=>$value){
1520
		if(is_array($value)){
1521

    
1522
		} else {
1523
			$pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
1524
		}
1525
	}
1526
	return $pstr;
1527
}
1528

    
1529
function _get_feature_trees(){
1530
	$feature_trees = array();
1531

    
1532
	// set tree that contains all features
1533
	$feature_trees[UUID_DEFAULT_FEATURETREE] = t('Default Featuretree (contains all features)');
1534

    
1535
	// get features from database
1536
	$persisted_trees = cdm_ws_get(CDM_WS_FEATURETREES);
1537
	if(is_array($persisted_trees)){
1538
		foreach($persisted_trees as $featureTree){
1539

    
1540
			// do not add the DEFAULT_FEATURETREE again
1541
			if($featureTree->uuid == UUID_DEFAULT_FEATURETREE){
1542
				continue;
1543
			}
1544
			$featureLabels = array();
1545
			foreach ($featureTree->root->children as $featureNode){
1546
				$featureLabels[] = $featureNode->feature->representation_L10n;
1547
			}
1548

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

    
1551
		}
1552
	}
1553
	return $feature_trees;
1554
}
1555

    
1556

    
1557
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
1558
	//TODO implement admin user interface to replace swicth statement
1559
	//     preliminar solution: using themes
1560

    
1561
	$template = null;
1562
	// find best matching default RenderTemplate in theme
1563
	//echo "<br/><br/>RENDER PATH:  ".$renderPath;
1564
	//var_dump('RENDER PATH: ' . $renderPath);
1565
	while(!is_array($template) && strlen($renderPath) > 0){
1566
	   $template = theme('get_nameRenderTemplate', $renderPath);
1567
	   $renderPath = substr($renderPath, 0, strrpos($renderPath, '.'));
1568
//	   if(!is_array($template)){
1569
//	       echo "<br/>->".$renderPath;
1570
//	   }
1571
	}
1572
	
1573
	// otherwise get default RenderTemplate from theme 
1574
	if(!is_array($template)){
1575
	   $template = theme('get_nameRenderTemplate', '#DEFAULT');
1576
	}
1577
	// otherwise get system default RenderTemplate
1578
	if(!is_array($template)){
1579
		switch($renderPath){
1580
			case 'list_of_taxa':
1581
			case  'acceptedFor':
1582
			case 'taxon_page_synonymy':
1583
			case 'typedesignations':
1584
			case 'taxon_page_title':
1585
			case 'na': $template = array(
1586
			        'namePart' => array('#uri'=>true),
1587
			        //'authorshipPart' => true,
1588
				);
1589
				break;
1590
			case 'nar': $template = array(
1591
		          	'namePart' => array('#uri'=>true),
1592
					 //'authorshipPart' => true,
1593
		          	'referencePart' => array('#uri'=>true),
1594
		          	'microreferencePart' => true,
1595
				);
1596
				break;
1597
			default: $template = array(
1598
          'namePart' => array('#uri'=>true),
1599
          'authorshipPart' => true,
1600
          'referencePart' => array('#uri'=>true),
1601
          'microreferencePart' => true,
1602
          'statusPart' => true,
1603
          'descriptionPart' => true
1604
			);
1605
		}
1606
	}
1607

    
1608
	if($nameLink && isset($template['nameAuthorPart']['#uri'])){
1609
		$template['nameAuthorPart']['#uri'] = $nameLink;
1610
	} else{
1611
		unset($template['nameAuthorPart']['#uri']);
1612
	}
1613

    
1614
	if($nameLink && isset($template['namePart']['#uri'])){
1615
		$template['namePart']['#uri'] = $nameLink;
1616
	} else{
1617
		unset($template['namePart']['#uri']);
1618
	}
1619

    
1620
	if($refenceLink && isset($template['referencePart']['#uri'])){
1621
		$template['referencePart']['#uri'] = $refenceLink;
1622
	}else{
1623
		unset($template['referencePart']['#uri']);
1624
	}
1625
	
1626
	return $template;
1627
}
1628

    
1629
function get_partDefinition($taxonNameType){
1630
	//TODO implement admin user interface to allow specify the partdefinitions for any type
1631
	//     preliminar solution: using themes
1632

    
1633
	$partdef = theme('get_partDefinition', $taxonNameType);
1634

    
1635
	if(!is_array($partdef)){
1636
		switch($taxonNameType){
1637
			case 'ZoologicalName': $partdef = array(
1638
        'namePart' => array(
1639
          'name' => true,
1640
			),
1641
        'referencePart' => array(
1642
          'authorTeam' => true
1643
			),
1644
        'microreferencePart' => array(
1645
          'microreference' => true,
1646
			),
1647
        'statusPart' => array(
1648
          'status' => true,
1649
			),
1650
        'descriptionPart' => array(
1651
          'description' => true,
1652
			),
1653
			);
1654
			break;
1655
			case 'BotanicalName': $partdef = array(
1656
        'namePart' => array(
1657
          'name' => true
1658
			),
1659
        'authorTeamPart' => array(
1660
          'authorTeam' => true,   
1661
			),
1662
        'referencePart' => array(
1663
          'reference' => true      
1664
			),
1665
        'microreferencePart' => array(
1666
          'microreference' => true,
1667
			),
1668
        'statusPart' => array(
1669
          'status' => true,
1670
			),
1671
        'descriptionPart' => array(
1672
          'description' => true,
1673
			),
1674
			);
1675
			break;
1676
			default: $partdef = array(
1677
        'namePart' => array(
1678
          'name' => true,
1679
			),
1680
        'authorTeamPart' => array(
1681
          'authorTeam' => true,   
1682
			),
1683
        'referencePart' => array(
1684
          'reference' => true      
1685
			),
1686
        'microreferencePart' => array(
1687
          'microreference' => true,
1688
			),
1689
        'statusPart' => array(
1690
          'status' => true,
1691
			),
1692
        'descriptionPart' => array(
1693
          'description' => true,
1694
			),
1695
			);
1696
		}
1697
	}
1698
	return $partdef;
1699
}
1700

    
1701
/**
1702
 * The function read the metadata info such title or artist of a media file. The
1703
 * function tries at first to get all the info from the file metadata and if it is
1704
 * not avaible look at the media file info stored at the database.
1705
 * @param $media The media file
1706
 * @return array The array with the avilable specified metadata info.
1707
 * TODO rename to read_media_metadata() and move to *.module
1708
 */
1709
function cdm_read_media_metadata($media){
1710

    
1711
	$metadata_caption = array('title' => '',           //media_metadata and media
1712
                              'artist' => '',          //media_metadata and media
1713
                              'rights',                //media_metadata and media
1714
                              'location',              //media_metadata
1715
                              'filename' => '',        //media
1716
                              'mediacreated' => '',    //media
1717
                              'description' => '');    //media
1718

    
1719
	//getting the media metadata
1720
	$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
1721

    
1722
	//title
1723
	//if ($media_metadata->Headline) {
1724
	if ($media_metadata->ObjectName) {
1725
		$metadata_caption['title'] = $media_metadata->ObjectName;
1726
		//	} else if ($media->titleCache){
1727
		//		$metadata_caption['title'] = $media_metadata->ObjectName;
1728
	} else if ($media->titleCache){
1729
		$metadata_caption['title'] = $media->titleCache;
1730
		if ($media->description_L10n)
1731
		$metadata_caption['title'] .= ' - ' . $media->description_L10n;
1732
	}else{ //if there is no title on the db and metadata get file title
1733
    $aux = $media->representations[0]->parts[0]->uri;
1734
    $aux = explode("/", $aux);
1735
    $aux = end($aux);
1736
		$metadata_caption['title'] = $aux;		
1737
	}
1738

    
1739
	//artist
1740
	if ($media_metadata->Artist){
1741
	 $metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
1742
	}
1743
	elseif ($media->artist->titleCache){
1744
	 $metadata_caption['artist'] = $media->artist->titleCache;
1745
	}
1746
	
1747
	//copyright
1748
	$metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
1749
                                      'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
1750
	if ($media_metadata->Copyright)
1751
	$metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
1752
	elseif ($media->rights){
1753
		foreach($media->rights as $right){
1754
			switch($right->term->uuid){
1755
				case UUID_RIGHTS_LICENCE:
1756
					$metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
1757
					$metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
1758
					$metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
1759
					$metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
1760
					break;
1761
				case UUID_RIGHTS_COPYRIGHT:
1762
					$metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
1763
					break;
1764
			}
1765
		}
1766
	}
1767
	else
1768
	$metadata_caption['rights']['agentNames'][] = '';
1769

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

    
1773
	//location
1774
	$metadata_caption['location'] = array();
1775
	$metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
1776
	$metadata_caption['location']['city'] = $media_metadata->City;
1777
	$metadata_caption['location']['province'] = $media_metadata->Province;
1778
	$metadata_caption['location']['country'] = $media_metadata->Country;
1779

    
1780
	//filename
1781
	if(isset($media->representations[0]->parts[0]->uri)){
1782
		$fileUri = $media->representations[0]->parts[0]->uri;
1783
		$filename = substr($fileUri, strrpos($fileUri, "/")+1);
1784
		$metadata_caption['filename'] = $filename;
1785
	}
1786
	else{
1787
	 $metadata_caption['filename'] = '';
1788
	}
1789
	/*
1790
	 //creation date
1791
	 if($media_metadata["Modify Date"])
1792
	 $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
1793
	 else
1794
	 $metadata_caption['mediacreated'] = $media->created;
1795
	 */
1796
	//returned value
1797
	return $metadata_caption;
1798
}
1799

    
1800
/**
1801
 * This function collects all the media from a list of description elements
1802
 * and return them as an Array.
1803
 *
1804
 * @param $descriptionElementes The description elements
1805
 * @return Array The output with all the media
1806
 */
1807
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
1808
	//variables
1809
	$outArrayOfMedia = array(); //return value
1810
	//implementation
1811
	foreach($descriptionElements as $descriptionElement){
1812
		foreach($descriptionElement->media as $media){
1813
			if(isset($media)){
1814
			 $outArrayOfMedia[] = $media;
1815
			}
1816
	 }
1817
	}
1818
	return $outArrayOfMedia;
1819
}
1820

    
1821

    
(6-6/10)