Project

General

Profile

Download (69.5 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/footnotekey.php');
30
require_once('classes/renderhints.php');
31

    
32
define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
33
define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
34
define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
35
define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
36
define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
37

    
38
/* gallery variables */
39
$gallery_settings = array(
40
    "cdm_dataportal_show_taxon_thumbnails" => 1,
41
    "cdm_dataportal_show_synonym_thumbnails" => 0,
42
    "cdm_dataportal_show_thumbnail_captions" => 1,
43
    "cdm_dataportal_media_maxextend" => 120,
44
    "cdm_dataportal_media_cols" => 3,
45
    "cdm_dataportal_media_maxRows" => 1);
46
/**
47
 * default settings for all gallerys
48
 * @var unknown_type
49
 */
50
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
51

    
52
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
53
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
54
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
55
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
56
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
57
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
58
//define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
59
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
60
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
61
define('CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
62
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
63

    
64
function getGallerySettings($gallery_config_form_name){
65
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
66
	return variable_get($gallery_config_form_name, $default_values);
67
}
68

    
69
function _add_js_progressbar(){
70
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.progressbar/js/jquery.progressbar.js');
71
}
72

    
73
function _add_js_treeselector(){
74
	//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
75
	drupal_add_js("
76
		if (Drupal.jsEnabled) {
77
		  $(document).ready(function() {
78
		      $('#cdm-taxonomictree-selector-form #edit-val').change(function () {
79
		          $('#cdm-taxonomictree-selector-form').submit();
80
		      });
81

    
82
		  });
83
		}", 'inline');
84
}
85

    
86

    
87
function get_openlayers_map($width, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false ){
88

    
89
      _add_js_openlayers_map();
90

    
91
      $out = '<div id="openlayers">';
92
      $out .= '<div id="openlayers_map" class="smallmap"';
93
      $out .= ' style="width: ' . $width . 'px; height:'.( $width / 2).'px"';
94
      if($occurrenceQuery){
95

    
96
      	//fix $occurrenceQuery
97
      	$occurrenceQuery .= '&ms=400,350';
98
      	$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
99
      	$occurrenceQuery .= '&legend=0'; //TODO add to cdm service?
100

    
101
      	$out .= ' occurrenceQuery="'.$occurrenceQuery.'"';
102
      }
103
      if($distributionQuery){
104
        $out .= ' distributionQuery="'.$distributionQuery.'"';
105
      }
106
      if($legendFormatQuery){
107
         $out .= ' legendFormatQuery="'.$legendFormatQuery.'"';
108
      }
109
      $out .= '></div></div>';
110

    
111
      // showing map caption
112
      if($map_caption){
113
        $out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; //FIXME: replace <br> by according css style
114
        $out .= '</div>';
115
      }
116
      return $out;
117
}
118

    
119
/* ====================== hook implementations ====================== */
120

    
121
/**
122
 * Implementation of hook_help()
123
 *
124
 * Display help and module information
125
 * @param section which section of the site we're displaying help
126
 * @return help text for section
127
 */
128
function cdm_dataportal_help($section='') {
129

    
130
	$out = '';
131
	switch ($section) {
132
		case "admin/modules#description":
133
			$out = t("The dataportal publishes CDM data hosted in a CommunityStore on the web.");
134
			break;
135
	}
136
	return $out;
137
}
138

    
139

    
140
/**
141
 * Implementation of hook_perm()
142
 *
143
 * Valid permissions for this module
144
 * @return array An array of valid permissions for the portfolio module
145
 */
146
function cdm_dataportal_perm() {
147
	return array(
148
    	'administer cdm_dataportal',
149
      'cdm_dataportal view notes',
150
	//TODO which else permission are required? -> check the WP6 requirements document
151
	);
152
}
153

    
154

    
155
/**
156
 * Implementation of hook_menu()
157
 */
158
function cdm_dataportal_menu($may_cache) {
159
	$items = array();
160

    
161
	if ($may_cache) {
162

    
163
		$items[] = array(
164
      'path' => 'admin/settings/cdm_dataportal',
165
      'title' => t('CDM Dataportal'),
166
      'description' => t('Setting for the CDM DataPortal'),
167
      'access' => user_access('administer cdm_dataportal'),
168
      'callback' => 'drupal_get_form',
169
      'callback arguments' => 'cdm_dataportal_settings',
170
      'type' => MENU_NORMAL_ITEM,
171
		);
172

    
173
		$items[] = array(
174
      'path' => 'admin/settings/cdm_dataportal/general',
175
      'title' => t('General'),
176
      'description' => t('Setting for the CDM DataPortal'),
177
      'access' => user_access('administer cdm_dataportal'),
178
      'callback' => 'drupal_get_form',
179
      'callback arguments' => 'cdm_dataportal_settings',
180
	  'weight' => 0,
181
      'type' => MENU_LOCAL_TASK,
182
		);
183

    
184
		$items[] = array(
185
      'path' => 'admin/settings/cdm_dataportal/geo',
186
      'title' => t('Geo & Map'),
187
      'description' => t('Geo & Map'),
188
      'access' => user_access('administer cdm_dataportal'),
189
      'callback' => 'drupal_get_form',
190
      'callback arguments' => 'cdm_dataportal_settings_geo',
191
	    'weight' => 1,
192
      'type' => MENU_LOCAL_TASK,
193
		);
194

    
195
		$items[] = array(
196
      'path' => 'admin/settings/cdm_dataportal/layout',
197
      'title' => t('Layout'),
198
      'description' => t('Configure and adjust the layout of your DataPortal '),
199
      'access' => user_access('administer cdm_dataportal'),
200
      'callback' => 'drupal_get_form',
201
      'callback arguments' => 'cdm_dataportal_settings_layout',
202
      'weight' => 2,
203
      'type' => MENU_LOCAL_TASK,
204
		);
205

    
206
		$items[] = array(
207
      'path' => 'admin/settings/cdm_dataportal/cachesite',
208
      'title' => t('Cache'),
209
      'description' => t('Cache the whole CDM DataPortal site'),
210
      'access' => user_access('administer cdm_dataportal'),
211
      'callback' => 'cdm_dataportal_view_cache_site',
212
      'weight' => 10,
213
      'type' => MENU_LOCAL_TASK,
214
		);
215

    
216
		/*$items[] = array(
217
		 'path' => 'admin/settings/cdm_dataportal/ws',
218
		 'title' => t('Web Service'),
219
		 'description' => t('Setting for the CDM DataPortal'),
220
		 'access' => user_access('administer cdm_dataportal'),
221
		 'callback' => 'drupal_get_form',
222
		 'callback arguments' => 'cdm_dataportal_settings',
223
		 'weight' => 1,
224
		 'type' => MENU_DEFAULT_LOCAL_TASK,
225
		 );*/
226

    
227
		$items[] = array(
228
	    'path' => 'cdm_dataportal/names',
229
	    'callback' => 'cdm_dataportal_view_names',
230
	    'access' => true,
231
	    'type' => MENU_CALLBACK,
232
		);
233
		// optional callback arguments: page
234

    
235
		$items[] = array(
236
      'path' => 'cdm_dataportal/taxon',
237
      'callback' => 'cdm_dataportal_taxon_page_view',
238
      'access' => true,
239
      'type' => MENU_CALLBACK,
240
		// expected callback arguments: uuid
241
		);
242

    
243
		$items[] = array(
244
      'path' => 'cdm_dataportal/name',
245
      'callback' => 'cdm_dataportal_name_page_view',
246
      'access' => true,
247
      'type' => MENU_CALLBACK,
248
		// expected callback arguments: uuid
249
		);
250

    
251
		$items[] = array(
252
      'path' => 'cdm_dataportal/reference',
253
      'callback' => 'cdm_dataportal_view_reference',
254
      'access' => true,
255
      'type' => MENU_CALLBACK,
256
		// expected callback arguments: uuid
257
		);
258

    
259
		$items[] = array(
260
      'path' => 'cdm_dataportal/reference/list',
261
      'callback' => 'cdm_dataportal_view_reference_list',
262
      'access' => true,
263
      'type' => MENU_CALLBACK,
264
		// expected callback arguments: uuid
265
		);
266

    
267
		$items[] = array(
268
      'path' => 'cdm_dataportal/media',
269
      'callback' => 'cdm_dataportal_view_media',
270
      'access' => true,
271
      'type' => MENU_CALLBACK,
272
		// expected callback arguments: uuid, mediarepresentation_uuid, part_uuid or part#
273
		);
274

    
275
		$items[] = array(
276
      'path' => 'cdm_dataportal/search',
277
      'callback' => 'cdm_dataportal_view_search_advanced',
278
      'access' => true,
279
      'type' => MENU_CALLBACK,
280
		);
281

    
282
		$items[] = array(
283
      'path' => 'cdm_dataportal/search/taxon',
284
      'callback' => 'cdm_dataportal_view_search_taxon',
285
      'access' => true,
286
      'type' => MENU_CALLBACK,
287
		);
288

    
289
		$items[] = array(
290
      'path' => 'cdm/xml2json',
291
      'callback' => 'cdm_view_xml2json',
292
      'access' => true,
293
      'type' => MENU_CALLBACK,
294
		);
295

    
296
	} else {
297
		// may not cache
298
		// --- local tasks for Taxon
299
		$items[] = array(
300
      'path' => 'cdm_dataportal/name/'.arg(2),
301
		//'callback' => 'cdm_dataportal_view_name',
302
		  'callback' => 'cdm_dataportal_name_page_view',
303
      'callback arguments' => array(arg(2), arg(3), arg(4)),
304
      'access' => true,
305
      'type' => MENU_CALLBACK,
306
		);
307

    
308
		if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
309

    
310
			$items[] = array(
311
      'path' => 'cdm_dataportal/taxon/'.arg(2),
312
      'title' => theme('cdm_taxonpage_tab', 'General'),
313
      'callback' => 'cdm_dataportal_taxon_page_view',
314
      'access' => true,
315
      'type' => MENU_CALLBACK,
316
      'weight' => 1,
317
      'callback arguments' => array(arg(2), "description")
318
			// expected callback arguments: name_uuid
319
			);
320

    
321
			$items[] = array(
322
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/all',
323
      'title' => theme('cdm_taxonpage_tab', 'General'),
324
      'callback' => 'cdm_dataportal_taxon_page_view',
325
      'access' => true,
326
      'type' => MENU_CALLBACK,
327
      'weight' => 2,
328
      'callback arguments' => array(arg(2), "all")
329
			// expected callback arguments: name_uuid
330
			);
331

    
332
			$items[] = array(
333
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/description',
334
      'title' => theme('cdm_taxonpage_tab', 'General'),
335
      'callback' => 'cdm_dataportal_taxon_page_view',
336
      'access' => true,
337
      'type' => MENU_DEFAULT_LOCAL_TASK,
338
      'weight' => 2,
339
      'callback arguments' => array(arg(2), "description")
340
			// expected callback arguments: name_uuid
341
			);
342

    
343
			$items[] = array(
344
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/synonymy',
345
      'title' => theme('cdm_taxonpage_tab', 'Synonymy'),
346
      'callback' => 'cdm_dataportal_taxon_page_view',
347
      'access' => true,
348
      'type' => MENU_LOCAL_TASK,
349
      'weight' => 3,
350
      'callback arguments' => array(arg(2), "synonymy")
351
			// expected callback arguments: name_uuid
352
			);
353

    
354
			$items[] = array(
355
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/images',
356
      'title' => theme('cdm_taxonpage_tab', 'Images'),
357
      'callback' => 'cdm_dataportal_taxon_page_view',
358
      'access' => true,
359
      'type' => MENU_LOCAL_TASK,
360
      'weight' => 4,
361
      'callback arguments' => array(arg(2), "images")
362
			// expected callback arguments: name_uuid
363
			);
364
		 $items[] = array(
365
		 'path' => 'cdm_dataportal/taxon/'.arg(2).'/specimens',
366
		 'title' => theme('cdm_taxonpage_tab', 'Specimens'),
367
		 'callback' => 'cdm_dataportal_taxon_page_view',
368
		 'access' => true,
369
		 'type' => MENU_LOCAL_TASK,
370
		 'weight' => 5,
371
		 'callback arguments' => array(arg(2), "specimens")
372
		 // expected callback arguments: name_uuid
373
		 );
374

    
375
		}
376
	}
377

    
378
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
379
	//drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
380
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
381

    
382
	return $items;
383

    
384
}
385

    
386
/**
387
 * Implementation of hook_block()
388
 *
389
 * Provides the following blocks:
390
 *  0: list of links useful during development
391
 *
392
 * @param String $op
393
 * @param int $delta
394
 */
395
function cdm_dataportal_block($op='list', $delta=0) {
396
	// listing of blocks, such as on the admin/block page
397
	if ($op == "list") {
398
		//$block[0]["info"] = t("CDM DataPortal DevLinks");
399
		//		$block[1]["info"] = t("CDM DataPortal Credits");
400
		$block[2]["info"] = t("CDM Search Taxa");
401
		//$block[3]["info"] = t("CDM Filters");
402
		$block[4]["info"] = t("CDM Dataportal Print");
403
		return $block;
404
	}
405
	else if ($op == 'view') {
406
		switch($delta){
407
			//			case 1:
408
			//				$block['subject'] = t('Credits');
409
			//				$block['content'] = theme('cdm_credits');
410
			//				return $block;
411
			case 2:
412
				$block['subject'] = t('Search taxa');
413
				$block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
414
				$block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
415
				return $block;
416
			case 4:
417
				$block['subject'] = t('<none>');
418
				$block['content'] = theme('cdm_print_button');;
419
				return $block;
420
		}
421
	}
422
}
423

    
424

    
425
/**
426
 * Implementation of hook_validate()
427
 *
428
 * @param $element
429
 */
430
function cdm_dataportal_settings_validate($form_id, $form_values){
431

    
432
	if (!str_endsWith($form_values['cdm_webservice_url'], '/')) {
433
		//form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
434
		$form_values['cdm_webservice_url'] .= '/';
435
	}
436

    
437
	if($form_values['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)){
438
		cache_clear_all(NULL, 'cache_cdm_ws');
439
		// better clear secref_cache since i can not be sure if the cache has not be used during this response
440
		cdm_api_secref_cache_clear();
441
	}
442

    
443
}
444

    
445
/*
446
 function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
447
 $_SESSION['cdm'] = null;
448
 if(is_string($cdm_ws_uri_update)){
449
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
450
 }
451
 }
452

    
453
 function cdm_dataportal_session_validate(){
454

    
455
 if(!isset($_SESSION['cdm']['ws_uri'])){
456
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
457
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
458
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
459
 }
460
 }
461
 */
462

    
463
function cdm_dataportal_search_taxon_form($advancedForm = false){
464

    
465
	$preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
466
	$preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
467
	$preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
468
	$preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
469
	$tdwg_level_select =  (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
470
	$selected_areas =  (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
471

    
472
	$url = 'cdm_dataportal/search/taxon';
473
	$form['#method'] = 'get';
474
	$form['#process'] = array('cdm_dataportal_search_process' => array());
475
	$form['#action'] = url($url, NULL, NULL, true);
476

    
477
	$form['query'] = array(
478
    '#delta' => 0,
479
    '#type' => 'textfield',
480
    '#size' => 20,
481
    '#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')),
482
    '#value' => $preset_query,
483
	);
484

    
485
	$form['search'] = array(
486
      '#delta' => 1,
487
      '#tree' => true,
488
	//'#type' => $advancedForm ? 'fieldset': 'hidden',
489
      '#title' => t('Options')
490
	);
491

    
492
	$form['search']['tree'] = array(
493
    '#delta' => -1,
494
    '#type' => 'hidden',
495
    '#value' => get_taxonomictree_uuid_selected()
496
	);
497

    
498

    
499
	// clean URL get forms breaks if we don't give it a 'q'.
500
	if (!(bool)variable_get('clean_url', '0')) {
501
		$form['search']['q'] = array(
502
      '#delta' => -1,
503
      '#type' => 'hidden',
504
      '#value' => $url,
505
      '#name' => 'q',
506
		);
507
	}
508

    
509
	$form['search']['pageSize'] = array(
510
      '#delta' => -1,
511
      '#type' => 'hidden',
512
      '#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
513
	);
514

    
515
	if($advancedForm){
516
		// general search parameters
517
		$form['search']['doTaxa'] = array(
518
      '#delta' => 2,
519
      '#type' => 'checkbox',
520
      '#title' => t('Search for accepted taxa'),
521
      '#value' => $preset_doTaxa
522
		);
523
		$form['search']['doSynonyms'] = array(
524
      '#delta' => 3,
525
      '#type' => 'checkbox',
526
      '#title' => t('Search for synonyms'),
527
      '#value' => $preset_doSynonyms
528
		);
529
		$form['search']['doTaxaByCommonNames'] = array(
530
      '#delta' => 4,
531
      '#type' => 'checkbox',
532
      '#title' => t('Search for common names'),
533
      '#value' => $preset_doTaxaByCommonNames
534
		);
535

    
536
		// Geographic Range
537
		$form['search']['geographic_range'] = array(
538
      '#type' => 'fieldset',
539
      '#delta' => 5,
540
      '#tree' => true,
541
      '#title' => t('Geographic range'),
542
		);
543

    
544
		$form['search']['geographic_range']['tdwg_level_select'] = array(
545
    '#type' => 'radios',
546
    '#title' => t('Select a TDWG distribution level and code'),
547
    '#default_value' => $tdwg_level_select,
548
    '#options' => array(
549
		t('TDWG level-1, i.e. a continent'),
550
		t('TDWG level-2'),
551
		t('TDWG level-3, i.e. a country'),
552
		t('TDWG level-4')
553
		)
554
		);
555
		$tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
556
		$tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
557
		$tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
558
		$tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
559

    
560
		$tdwg_js = '';
561
		foreach($tdwg as $key=>$tdwg_level){
562
			$tdwgOptions = array();
563
			$tdwgOptionsSelected = array();
564
			foreach($tdwg_level as $area){
565
				$representation = $area->representations[0];
566
				$tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
567
				if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
568
					$tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
569
				}
570
			}
571
			asort($tdwgOptions);
572
			$form['search']['geographic_range']['tdwg_level_'.$key] = array(
573
        '#type' => 'select',
574
        '#title'         => t('TDWG level').' '.$key,
575
        '#default_value' => $tdwgOptionsSelected,
576
        '#multiple' => TRUE,
577
        '#options' => $tdwgOptions
578
			);
579
			$tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ?  '.show()' : '.hide()'). ";\n";
580
		}
581

    
582
		drupal_add_js(
583
    "$(document).ready(function(){
584

    
585
      $(\"input[@name='search[geographic_range][tdwg_level_select]']\").change(
586
        function(event){
587
          var selectId = $(\"input[@name='search[geographic_range][tdwg_level_select]']:checked\").val();
588
          var i;
589
          for(i = 0; i < 4; i++){
590
            if(selectId == i){
591
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1) ).parent().fadeIn('slow');
592
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
593
            } else {
594
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).parent().fadeOut('slow');
595
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
596
            }
597
          }
598
        }
599
      );
600

    
601
      $tdwg_js
602
    });",
603
    'inline');
604

    
605
	} else {
606
		$form['search']['doTaxa'] = array(
607
	      '#delta' => -2,
608
	      '#type' => 'hidden',
609
	      '#value' => 1
610
		);
611
		$form['search']['doSynonyms'] = array(
612
	      '#delta' => -3,
613
	      '#type' => 'hidden',
614
	      '#value' => 1
615
		);
616
		$form['search']['doTaxaByCommonNames'] = array(
617
	      '#delta' => -4,
618
	      '#type' => 'hidden',
619
	      '#value' => 0
620
		);
621
	}
622

    
623
	$form['submit'] = array(
624
	  '#delta' => 9,
625
	  '#type' => 'submit',
626
	  '#name' => '',
627
	  '#value' => t('Search')
628
	);
629

    
630
	return $form;
631
}
632

    
633
function cdm_dataportal_search_taxon_form_advanced(){
634
	return cdm_dataportal_search_taxon_form(true);
635
}
636

    
637
function cdm_taxonomictree_selector(){
638
	_add_js_treeselector();
639

    
640
	$out = drupal_get_form('cdm_taxonomictree_selector_form');
641

    
642
	return $out;
643
}
644

    
645

    
646
function cdm_taxonomictree_selector_form(){
647

    
648
	$url = url('cdm_api/setvalue/session', null);
649
	$form['#action'] = $url;
650

    
651
	$form['var'] = array(
652
        '#delta' => -3,
653
        '#type' => 'hidden',
654
        '#value' => '[cdm][taxonomictree_uuid]'
655
        );
656

    
657
   $form['destination'] = array(
658
	   '#delta' => -3,
659
	   '#type' => 'hidden',
660
	   '#value' => substr(drupal_get_destination(), strlen('destination='))
661
    );
662

    
663
    $form['val'] = array(
664
      '#type' => 'select',
665
      '#title'         => t('Available classifications'),
666
      '#default_value' => get_taxonomictree_uuid_selected(),
667
      '#options' => cdm_get_taxontrees_as_options()
668
    );
669

    
670
        return $form;
671

    
672
}
673

    
674
/**
675
 * Implementation #process method call, see form_builder()
676
 * <p>
677
 * Removes Drupal internal form elements from query
678
 * @param $form
679
 * @return unknown_type
680
 */
681
function cdm_dataportal_search_process($form) {
682
	unset($form['form_id']);
683
	unset($form['form_token']);
684
	return $form;
685
}
686

    
687
/**
688
 * Filters $_REQUEST by a list of valid request  parameters and also sets defaults if required.
689
 * returns the processed request parameters submitted by the search form.
690
 */
691
function cdm_dataportal_search_form_request(){
692

    
693

    
694
	$form_params = array();
695
	array_deep_copy($_REQUEST['search'], $form_params);
696
	$form_params['query'] =  trim($_REQUEST['query']);
697

    
698
	// split of  geographic range
699
	if(isset($_REQUEST['search']['geographic_range'])){
700
		$geographicRange = $_REQUEST['search']['geographic_range'];
701
		// remove
702
		unset($form_params['geographic_range']);
703
	}
704

    
705
	// add geographic range
706
	if($geographicRange){
707
		$form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
708
		for($i = 1; $i < 5; $i++){
709
			if(isset($geographicRange['tdwg_level_'.$i])){
710
				$form_params['area'] = $geographicRange['tdwg_level_'.$i];
711
			}
712
		}
713
	}
714

    
715
	// store in session
716
	$_SESSION['cdm']['search'] = $form_params;
717

    
718
	return $form_params;
719
}
720

    
721

    
722
/* UNREACHABLE since action of form directly links to view
723
 function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
724

    
725
 $_SESSION['cdm']['search'] = $form_values;
726
 //return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
727
 return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
728
 //$paramstr = compose_url_prameterstr($form_values);
729
 //return url('/cdm_dataportal/search/taxon/', $paramstr);
730
 }
731
 */
732
/* ====================== menu callback functions ====================== */
733

    
734
/**
735
 * Generate main administration form.
736
 *
737
 * @return
738
 *   An array containing form items to place on the module settings page.
739
 */
740
function cdm_dataportal_settings(){
741

    
742
	$form = cdm_api_settings_form();
743

    
744

    
745
	return system_settings_form($form);
746
}
747

    
748
function cdm_dataportal_form_alter($form_id, &$form) {
749

    
750
	static $comment_node_disabled =  0;
751
	static $comment_node_read_only =  1;
752
	static $comment_node_read_write =  2;
753

    
754

    
755
	if ($form_id == 'node_type_form'
756
	&& isset($form['identity']['type'])
757
	&& array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
758
	) {
759
		$form['workflow']['comment'] = array(
760
      '#type' => 'radios',
761
      '#title' => t('Default comment setting'),
762
      '#default_value' => variable_get('comment_'. $form['#node_type']->type, $comment_node_disabled),
763
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
764
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
765
		);
766
	}
767
}
768

    
769
/**
770
 * LAYOUT settings
771
 * @return unknown_type
772
 */
773
function cdm_dataportal_settings_layout(){
774

    
775
	$form = array();
776
	/*
777
	 $form['cdm_taxonname_type'] = array(
778
	 '#type' => 'select',
779
	 '#title'         => t('Taxon name type'),
780
	 '#default_value' => variable_get('cdm_taxonname_type', 'BotanicalName'),
781
	 '#options' => array( 'BotanicalName'=>t('BotanicalName'), 'ZoologicalName'=>t('ZoologicalName')),
782
	 '#description'   => t('')
783
	 );
784
	 */
785

    
786
	$form['cdm_dataportal_taxonpage_tabs'] = array(
787
    '#type' => 'checkbox',
788
    '#title' => t('Tabbed taxon page'),
789
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
790
    '#description' => t('Split the taxon page into individual tabs for description, images, synonymy')
791
  );
792

    
793
  //---- footnotes ---//
794
  $form['footnotes'] = array(
795
      '#type' => 'fieldset',
796
      '#title' => t('Footnotes'),
797
      '#collapsible' => TRUE,
798
      '#collapsed' => TRUE,    
799
  );
800
  
801
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
802
      '#type' => 'checkbox',
803
      '#title' => t('Do not show footnotes'),
804
      '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
805
      '#description' => t('Check this if you do not want to show any footnotes')
806
  );
807
  
808
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
809
      '#type' => 'checkbox',
810
      '#title' => t('Do not show annotations footnotes'),
811
      '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
812
      '#description' => t('Check this if you do not want to show annotation footnotes')
813
  );
814
  
815

    
816
	//---- SYNONYMY ----//
817
	$form['synonymy'] = array(
818
      '#type' => 'fieldset',
819
      '#title' => t('Synonymy'),
820
      '#collapsible' => TRUE,
821
      '#collapsed' => TRUE,
822
	);
823

    
824
	$form['synonymy']['cdm_dataportal_nomref_in_title'] = array(
825
    '#type' => 'checkbox',
826
    '#title' => t('Show accepted taxon on top of the synonymy'),
827
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
828
    '#description' => t('If checked, the first homotypic taxon is a repetition of the accepted taxon most likely
829
                        with the full nomenclatural reference (depending on the currently chosen theme).')
830
	);
831

    
832
	$form['synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
833
    '#type' => 'checkbox',
834
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when coming from a synonym link.'),
835
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
836
    '#description' => t('Check this if after doing a search and clicking on a synonym you want to see the "accept of" text for the accepted synonym.')
837
	);
838

    
839
	$name_relationships_terms = cdm_ws_get(CDM_WS_TERMVOCABULARY, UUID_NAME_RELATIONSHIP_TYPE);
840
  $name_rel_options = array();
841
  //$name_rel_options['default'] = 'Show all';
842
  foreach ($name_relationships_terms->terms as $element){
843
    $name_rel_options[$element->uuid] = t('Show "' . $element->representation_L10n_abbreviated . '" relationships');
844
  }
845

    
846
	$name_relationships_form['name_relationships_to_show']= array(
847
  '#type' => 'checkboxes',
848
  '#title' => t('Display name relationships'),
849
  '#default_value' => variable_get('name_relationships_to_show', 0),
850
  '#options' => $name_rel_options,
851
  '#description' => t('Select the name relationships you want to show for the accepted taxa.'),
852
  );
853

    
854
  $form['synonymy']['name_relationships'] = $name_relationships_form;
855
/*
856
	$form['synonymy'][CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS] = array(
857
    '#type' => 'checkbox',
858
    '#title' => t('Show name relations of accepted taxa on taxon page'),
859
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT),
860
    //'#description' => t('Check this if you want the synonymy list to show all the name relationships where other names implies the accepted taxa.')
861
	  '#description' => t('Check this if you want the synonymy list to show all the name relationships of accepted taxa.')
862
	);
863
*/
864
	$form['synonymy'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
865
    '#type' => 'checkbox',
866
    '#title' => t('Show taxon relations of accepted taxa on taxon page'),
867
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
868
    '#description' => t('Check this if you want the synonymy list to show the <em>"Misapplied Name for"</em> and <em>"Invalid Designation for"</em> relationships of accepted taxa.')
869
	);
870

    
871
/*
872
	$form['synonymy']['cdm_dataportal_name_relations_skiptype_basionym'] = array(
873
    '#type' => 'checkbox',
874
    '#title' => t('Exclude the basionym relationship type from the taxon page'),
875
    '#default_value' => variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1),
876
    '#description' => t('')
877
	);
878
*/
879

    
880
	/*
881
	 $form['cdm_dataportal_descriptions_separated'] = array(
882
	 '#type' => 'checkbox',
883
	 '#title' => t('Separate Descriptions'),
884
	 '#default_value' => variable_get('cdm_dataportal_descriptions_separated', 0),
885
	 '#description' => t('By default corresponding elements of different descriptions are joined together'
886
	 .' into a common section per feature (i.e. type of description).'
887
	 .' Check this box to allow displaying all descriptions separately.')
888
	 );
889
	 */
890
	//------------------ FEATURE TREE --------------------//
891

    
892
	$form['cdm_dataportal']['taxon_profile'] = array(
893
	    '#type' => 'fieldset',
894
	    '#title' => t('Taxon profile'),
895
	    '#description'   => t('This section covers setting related to the taxon profile tab, also known as the <strong>"General"</strong> tab.'),
896
	    '#collapsible' => TRUE,
897
	    '#collapsed' => TRUE,
898
	);
899

    
900
	$form['cdm_dataportal']['taxon_profile'][CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID] = array(
901
	    '#type' => 'radios',
902
	    '#title'         => t('Taxon profile elements'),
903
	    '#default_value' => variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE),
904
	    '#options' => cdm_get_featureTrees_as_options(TRUE),
905
	    '#description'   => t('Select a FeatureTree to specify the elements to be displayd in the taxon profile.'
906
	    //.' If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
907
	)
908
	);
909

    
910
	$form['cdm_dataportal']['taxon_profile'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
911
	    '#type' => 'radios',
912
	    '#title'         => t('Natural language representation of structured descriptions'),
913
	    '#default_value' => variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, null),
914
	    '#options' => cdm_get_featureTrees_as_options(),
915
	    '#description'   => t('Taxon descriptions can be stored in a highly structured form.'.
916
	      ' The feature tree selected here will be used to generate textual representation in natural language.'
917
	      //.' If there is no applicable FeatureTree you can create a new one using the <a href="">FeatureTreeManager</a>'
918
	)
919
	);
920

    
921
	//---- IMAGES ----//
922
	$form['images'] = array(
923
	    '#type' => 'fieldset',
924
	    '#title' => t('Images'),
925
	    '#collapsible' => TRUE,
926
	    '#collapsed' => TRUE,
927
	);
928
	$options = cdm_rankVocabulary_as_option();
929
	array_unshift($options, '-- DISABLED --');
930
	$form['images']['image_hide_rank'] =  array(
931
	    '#type'          => 'select',
932
	    '#title'         => t('Hide Images for Taxa above'),
933
	    '#default_value' => variable_get('image_hide_rank', '0'),
934
	    '#options'       => $options,
935
	    '#description'   => t(''),
936
	);
937
	//show media
938
	$selectShowMedia = array(0 => "Show only taxon media",
939
	1 => "Show taxon and child taxon media");
940
	$form['images']['cdm_dataportal_show_media'] = array(
941
	    '#type' => 'select',
942
	    '#title' => t('Available media files'),
943
	    '#default_value' => variable_get('cdm_dataportal_show_media', false),
944
	    '#options' => $selectShowMedia,
945
	    '#description'   => t('Select if a taxon should show only his media or also child media.')
946
	);
947
	$selectShowMedia = array(0 => "Show only taxon media",
948
	1 => "Show taxon and child taxon media");
949
	$form['images']['cdm_dataportal_show_default_image'] = array(
950
      '#type' => 'checkbox',
951
      '#title' => t('Show default image'),
952
      '#default_value' => variable_get('cdm_dataportal_show_default_image', false),
953
      '#description'   => t('Select if the taxon profile page should display the default image if no image is available for the chosen taxon.')
954
	);
955

    
956
	//------------------ SEARCH --------------------//
957
  $form['search'] = array(
958
      '#type' => 'fieldset',
959
      '#title' => t('Search'),
960
      '#collapsible' => TRUE,
961
      '#collapsed' => TRUE,
962
  );
963
  $form['search']['cdm_dataportal_search_items_on_page'] = array(
964
    '#type' => 'textfield',
965
    '#title' => t('Search Page Size'),
966
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
967
    '#description' => t('Number of Names to display per page in search results.')
968
  );
969

    
970
	// --- SEARCH TAXA GALLERY ---- //
971
	$items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
972
	$collapsed = TRUE;
973
	$form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
974
	$form_tittle = 'Search Taxa';
975
	$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
976

    
977
	// --- FEATURE DESCRIPTION GALLERY ---- //
978
	$form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
979
	$form_tittle = 'Description elements gallery';
980
	$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
981

    
982
	// --- CDM_DATAPORTAL_SPECIMEN_GALLERY --- //
983
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
984
  $form_tittle = 'Speciment media gallery';
985
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
986

    
987

    
988
	// --- MEDIA GALLERY ---- //
989
	$form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
990
	$form_tittle = 'Media gallery';
991
	$form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
992

    
993
	$form['image_gallery_viewer'] =  array(
994
    '#type'          => 'select',
995
    '#title'         => t('Image Gallery Viewer'),
996
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
997
    '#options' => array(
998
        'default' => t('Standart image gallery'),
999
        'fsi' => t('FSI viewer (requires FSI server!)'),
1000
  ));
1001
	// variable_get("imageviewer", "default")
1002

    
1003
	//-- DISTRIBUTION LAYOUT --//
1004
	$form['distribution_layout'] = array(
1005
        '#title' => t('Distribution layout'),
1006
        '#collapsible' => TRUE,
1007
        '#collapsed' => TRUE,
1008
        '#type' => 'fieldset',
1009
	);
1010

    
1011
	$form['distribution_layout']['distribution_sort'] =  array(
1012
    '#type'          => 'radios',
1013
    '#title'         => t('Sort'),
1014
    '#default_value' => variable_get('distribution_sort', 'NO_SORT'),
1015
    '#options' => array(
1016
				'NO_SORT' => t('Standard (No sort)'),
1017
				'HIDE_TDWG2' => t('Sorted without TDWG Level 2'),
1018
	));
1019

    
1020
	return system_settings_form($form);
1021
}
1022

    
1023
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed){
1024

    
1025
	$form[$form_name] = array(
1026
    '#type' => 'fieldset',
1027
    '#title' => t($form_tittle),
1028
    '#collapsible' => TRUE,
1029
    '#collapsed' => $collapsed,
1030
    '#tree' => true,
1031
	);
1032

    
1033
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1034
	$gallery_settings = variable_get($form_name, $default_values);
1035
	//$test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1036

    
1037
	if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
1038
		/* TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1039
		$form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1040
      '#type' => 'textfield',
1041
      '#title' => t('Search Page Size'),
1042
      '#default_value' => $test,
1043
      '#description' => t('Number of Names to display per page in search results.')
1044
    );
1045
    */
1046
		$form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1047
      '#type' => 'checkbox',
1048
      '#title' => t('Show media thumbnails for accepted taxa'),
1049
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1050
      '#description' => t('')
1051
		);
1052

    
1053
		$form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1054
      '#type' => 'checkbox',
1055
      '#title' => t('Show media thumbnails for synonyms'),
1056
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1057
      '#description' => t('')
1058
		);
1059
	}
1060

    
1061
	//$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1062
	$form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1063
    '#type' => 'checkbox',
1064
    '#title' => t('Show captions under thumbnails'),
1065
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1066
    '#description' => t('')
1067
	);
1068

    
1069
	$form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1070
    '#type' => 'textfield',
1071
    '#title' => t('Maximum extend of Images'),
1072
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1073
    '#description' => t('In the gallery neither width or height will exceed the maximum extend of images.')
1074
	);
1075

    
1076
	$form[$form_name]['cdm_dataportal_media_cols'] = array(
1077
    '#type' => 'textfield',
1078
    '#title' => t('Number of columns'),
1079
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1080
    '#description' => t('')
1081
	);
1082

    
1083
	if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
1084
		$form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1085
      '#type' => 'textfield',
1086
      '#title' => t('Maximum number of rows'),
1087
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1088
      '#description' => t('If you want an unlimited number of rows please set to 0')
1089
		);
1090
	}
1091

    
1092
	return $form;
1093
}
1094

    
1095
/**
1096
 * GEOSERVICE and Map settings
1097
 * @return unknown_type
1098
 */
1099
function cdm_dataportal_settings_geo(){
1100

    
1101
	$form = array();
1102

    
1103
	$form['cdm_dataportal_map_openlayers'] = array(
1104
    '#type' => 'checkbox',
1105
    '#title' => t('OpenLayers Viewer'),
1106
    '#default_value' => variable_get('cdm_dataportal_map_openlayers', 1),
1107
    '#description' => t('Display the maps in an interactive viewer which allows zooming and panning.')
1108
	);
1109

    
1110
	$form['cdm_dataportal_geoservice_access_point'] = array(
1111
    '#type' => 'textfield',
1112
    '#title' => t('Geoservice Access Point'),
1113
    '#default_value' => variable_get('cdm_dataportal_geoservice_access_point', ''),
1114
    '#description' => t('Base URL of the geoservice to be used by this portal')
1115
	);
1116

    
1117
	$localhostkey = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
1118
	$gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
1119
	$form['gmap_api_key'] = array(
1120
    '#type' => 'textfield',
1121
    '#title' => t('Gogle Maps API Key'),
1122
    '#default_value' => variable_get('gmap_api_key', $gmap_api_key),
1123
    '#description' => t('Gogle Maps API Key, the key set by default <code>'.$localhostkey.'</code> is a key for the localhost = 127.0.0.1 The key in use is the one above this text.')
1124
  );
1125

    
1126
	//variable_get('gmap_api_key'
1127

    
1128
	$form['cdm_dataportal_geoservice_display_width'] = array(
1129
    '#type' => 'textfield',
1130
    '#title' => t('Geoservice Display Width'),
1131
    '#default_value' => variable_get('cdm_dataportal_geoservice_display_width', 390),
1132
    '#description' => t('Width of the image generated by geoservice')
1133
	);
1134

    
1135
	$form['cdm_dataportal_geoservice_bounding_box'] = array(
1136
    '#type' => 'textfield',
1137
    '#title' => t('Fixed Geoservice Bounding Box'),
1138
    '#default_value' => variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'),
1139
    '#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.')
1140
	);
1141

    
1142
	$form['cdm_dataportal_geoservice_labels_on'] = array(
1143
    '#type' => 'checkbox',
1144
    '#title' => t('Display Country Labels'),
1145
    '#default_value' => variable_get('cdm_dataportal_geoservice_labels_on', FALSE),
1146
    '#description' => t('Check this if you like country names to be displayed in the maps. ')
1147
	);
1148

    
1149
	$form['cdm_dataportal_geoservice_map_caption'] = array(
1150
    '#type' => 'textfield',
1151
    '#title' => t('Map Caption'),
1152
    '#default_value' => variable_get('cdm_dataportal_geoservice_map_caption', ''),
1153
    '#description' => t('Define a caption for the map.')
1154
	);
1155

    
1156
	$form['cdm_dataportal_geoservice_distributionOpacity'] = array(
1157
    '#type' => 'textfield',
1158
    '#title' => t('Distribution Layer Opacity'),
1159
    '#default_value' => variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'),
1160
    '#description' => t('Valid values range from 0.0 to 1.0. You can choose to let the underlying layers shine through if you select a value < 1.0. A value of 1.0 will cause a full opacity of the ditribution layer.')
1161
  );
1162

    
1163
  $form['cdm_dataportal_geoservice_legendOpacity'] = array(
1164
    '#type' => 'textfield',
1165
    '#title' => t('Legend Opacity'),
1166
    '#default_value' => variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'),
1167
    '#description' => t('Valid values range from 0.0 to 1.0. You can choose to let the layers shine through the legend if you select a value < 1.0. A value of 1.0 will cause a full opacity of the legend.')
1168
  );
1169

    
1170
	$form['cdm_dataportal_geoservice_map_legend'] = array(
1171
      '#type' => 'fieldset',
1172
      '#title' => t('Map Legend'),
1173
      '#collapsible' => FALSE,
1174
      '#collapsed' => TRUE,
1175
	);
1176

    
1177
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_on'] = array(
1178
    '#type' => 'checkbox',
1179
    '#title' => t('Display a map legend'),
1180
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_on', TRUE),
1181
    '#description' => t('Check this if you like a legend to be displayed with the maps. ')
1182
	);
1183

    
1184
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_size'] = array(
1185
    '#type' => 'textfield',
1186
    '#title' => t('Font size'),
1187
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_size', 10),
1188
    '#description' => t('Font size in pixels.')
1189
	);
1190

    
1191
	$fontStyles = array(0 => "plane", 1 => "italic");
1192
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_font_style'] = array(
1193
    '#type' => 'select',
1194
    '#title' => t('Available font styles'),
1195
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_font_style', false),
1196
    '#options' => $fontStyles,
1197
    '#description'   => t('Select a font style for the map legend.')
1198
	);
1199

    
1200
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_width'] = array(
1201
    '#type' => 'textfield',
1202
    '#title' => t('Icon width'),
1203
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_width', 35),
1204
    '#description' => t('Icon width in pixels.')
1205
	);
1206

    
1207
	$form['cdm_dataportal_geoservice_map_legend']['cdm_dataportal_geoservice_legend_icon_height'] = array(
1208
    '#type' => 'textfield',
1209
    '#title' => t('Icon height'),
1210
    '#default_value' => variable_get('cdm_dataportal_geoservice_legend_icon_height', 15),
1211
    '#description' => t('Icon height in pixels.')
1212
	);
1213

    
1214
	return system_settings_form($form);
1215
}
1216

    
1217

    
1218
/**
1219
 * @return walk and cache all taxon pages
1220
 */
1221
function cdm_dataportal_view_cache_site(){
1222

    
1223
	_add_js_progressbar();
1224

    
1225
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cache_all_taxa.js');
1226

    
1227
	$out = '';
1228

    
1229
	$request_params = array();
1230
	$request_params['query'] = '%';
1231
	$request_params['tree'] = variable_get('cdm_taxonomictree_uuid', false); //cache only the dafault classification
1232
	$request_params['doTaxa'] = 1;
1233
	$request_params['doSynonyms'] = 0;
1234
	$request_params['doTaxaByCommonNames'] = 0;
1235
	$search_url = cdm_compose_url(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1236
	$search_url = uri_uriByProxy($search_url);
1237
	$taxon_page_url = url('cdm_dataportal/taxon/');
1238

    
1239
	$out .= '<form id="cache_site">';
1240
	$out .= '<br /><h4>'.t('Cache all taxon pages').'</h4>';
1241
	$out .= 'Before  running the cache bot you have to empty the cache manually:<ul>'
1242
	.'<li>Navigate to "Site Configuration -> General"</li>'
1243
	.'<li>Uncheck "Enable Caching" checkbox</li>'
1244
	.'<li>Check "Enable Caching" checkbox</li>'
1245
	.'</ul>';
1246
	$out .= '<div>'.t('This caching process may take long time and could cause heavy load on your server').'</div>';
1247
	$out .= '<div id="progress"></div>';
1248
	$out .= '<input type="hidden" name="searchTaxaUrl" value="'.$search_url.'"/>';
1249
	$out .= '<input type="hidden" name="taxonPageUrl" value="'.$taxon_page_url.'"/>';
1250
	$out .= '<input type="button" name="start" value="'.t('Start').'"/>';
1251
	$out .= '<input type="button" name="stop" value="'.t('Stop').'"/>';
1252
	$out .= '</form>';
1253
	$out .= '</div>';
1254
	//  foreach($taxonPager->records as $taxon){
1255
	//    cdm_dataportal_taxon_view($uuid);
1256
	//  }
1257

    
1258
	return $out;
1259
}
1260

    
1261
/**
1262
 * Implementation of hook_elements().
1263
 */
1264
function cdm_dataportal_elements() {
1265
	$type['select_secuuid'] = array(
1266
    '#input' => TRUE,
1267
    '#process' => array('cdm_dataportal_select_secuuid_expand' => array()),
1268
	//'#validate' => array('cdm_dataportal_select_secuuid_validate' => array()),
1269
	//'#default_value' => array(),
1270
	);
1271
	return $type;
1272
}
1273

    
1274
/*
1275
 *
1276
 */
1277
function cdm_dataportal_select_secuuid_expand($element){
1278

    
1279
	$element['#tree'] = FALSE;
1280

    
1281
	// any value submitted?
1282
	if(isset($element['#post'][$element['#varname']])){
1283
		$selected_values = $element['#post'][$element['#varname']];
1284
	} else {
1285
		// use those store in drupal
1286
		$selected_values = variable_get( $element['#varname'], array());
1287
	}
1288
	if(!is_array($selected_values)){
1289
		$selected_values = array($selected_values);
1290
	}
1291
	$options = array();
1292
	foreach($selected_values as $secUuid){
1293
		$options[$secUuid] = cdm_taxontree_secRefTitle_for($secUuid);
1294
	}
1295

    
1296
	$element[$element['#varname']] =  array(
1297
    '#type' => 'select',
1298
    '#options' => $options,
1299
    '#default_value' => array_values($options),
1300
    '#size' => $element['#multiple'] ? 12 : 2,
1301
    '#multiple' => $element['#multiple'],
1302
	);
1303
	return $element;
1304
}
1305

    
1306

    
1307

    
1308
/**
1309
 * Displays a list of the known taxonomic names. Long lists are split up into multiple pages
1310
 *
1311
 * TODO: parameters are still preliminar
1312
 * @param String $page page number to diplay defaults to page 1
1313
 * @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
1314
 */
1315
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
1316

    
1317
	$request_params  = array(
1318
    'q' => $beginsWith,
1319
	//'sec' = '',
1320
	//'higherTaxa' => getFiters(),
1321
	// 'matchAnywhere' => false, // default is false
1322
    'page' => $page,
1323
    'onlyAccepted' => $onlyAccepted,
1324
    'pagesize' => 20  /*$_SESSION['cdm']['namelist_pagesize'] */);
1325

    
1326
	$taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
1327
	/*
1328
	 * FIXME the filter for accepted names will be a form element, thus this widget
1329
	 * should be generated via form api preferably as block
1330
	 */
1331
	//$out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1332
	//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1333
	$out .= theme('cdm_listof_taxa', $taxonPager);
1334
	return $out;
1335
}
1336

    
1337
function cdm_dataportal_view_reference($uuid, $arg2 = null){
1338
	$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1339
	return theme('cdm_reference_page', $reference);
1340
}
1341

    
1342
function cdm_dataportal_view_reference_list($pageNumber){
1343
	$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
1344
	return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
1345
}
1346

    
1347
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
1348
	$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1349
	return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
1350
}
1351

    
1352
/**
1353
 * The taxon page gives detailed information on a taxon, it shows:
1354
 *  - Taxon name
1355
 *  - Full list of synonyms homotypic synonyms on top, followed by the
1356
 *    heterotypic and finally followed by misapplied names.
1357
 *    The list is ordered historically.
1358
 *  - All description associated with the taxon.
1359
 *
1360
 * @param $uuid
1361
 * @param $chapter name of the part to display,
1362
 *         valid values are: 'description', 'images', 'synonymy', 'specimens', 'all'
1363
 * @return unknown_type
1364
 */
1365
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all'){
1366
	// display the page for the taxon defined by $uuid
1367
	set_last_taxon_page_tab(arg(3));
1368
	$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
1369
	return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
1370
}
1371

    
1372
/**
1373
 * @param $uuid
1374
 * @param $chapter name of the part to display,
1375
 *         valid values are: 'description', 'images', 'synonymy', 'all'
1376
 * @return unknown_type
1377
 */
1378
function cdm_dataportal_taxon_view($uuid, $chapter = 'all'){
1379

    
1380
	$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1381
	if(!$taxon){
1382
		drupal_set_title(t('Taxon does not exist'));
1383
		return false;
1384
	}
1385
	$taxonpage->title = theme('cdm_taxon_page_title', $taxon);
1386

    
1387
	// check if the taxon id contained in the currently selected tree
1388
	$taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $uuid);
1389
	$taxon_in_current_tree = false;
1390
	foreach($taxon_nodes as $node){
1391
		if(get_taxonomictree_uuid_selected() == $node->taxonomicTree->uuid){
1392
			$taxon_in_current_tree = true;
1393
			break;
1394
		}
1395
	}
1396
	if(!$taxon_in_current_tree){
1397
		if(count($taxon_nodes) == 0){
1398
			drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained any classification.'
1399
			,'warning');
1400
		} else {
1401
			$trees = '';
1402
			foreach($taxon_nodes as $node){
1403
				$trees .= ($trees?', ':'').'<strong>'.$node->taxonomicTree->titleCache.'</strong>';
1404

    
1405
			}
1406
			drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained in the currently chosen classification, but in '
1407
			.(count($taxon_nodes) > 1? ' one of these: ' : ' this one: ') . $trees
1408
			, 'warning');
1409
		}
1410
	}
1411

    
1412
	// render the taxon page
1413
	$taxonpage->content = theme('cdm_taxon_page_general', $taxon, $chapter);
1414

    
1415
	return $taxonpage;
1416
}
1417

    
1418
/**
1419
 * The function returns a name page as a drupal node ready to be renderized by drupal.
1420
 * The node page show the taxon name title and the list of taxon related with such taxon
1421
 * name on the tree already in used.
1422
 * @param $taxon_name_uuid A taxon name uuid
1423
 * @return The formatted name page as node
1424
 */
1425
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
1426
	$taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
1427
	return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
1428
}
1429

    
1430
/**
1431
 * The function genates a object ready to be transformated to a node
1432
 * in order to show as a drupal node
1433
 * @param $taxon_name_uuid
1434
 * @return the object with the page content and title
1435
 */
1436
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
1437
	//getting the full taxonname object from the server
1438
	$taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1439
	if(!$taxon_name){
1440
		drupal_set_title(t('Taxon name does not exist'));
1441
		return false;
1442
	}
1443
	//searching for all the taxa connected with the taxon name on the tree in used
1444
	$name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1445
	$request_params = array();
1446
	$request_params['query'] = $name_cache;
1447
	$request_params['tree'] = get_taxonomictree_uuid_selected();
1448
	$request_params['doTaxa'] = 1;
1449
	$request_params['doSynonyms'] = 1;
1450
	$request_params['doTaxaByCommonNames'] = 0;
1451
	$request_params['matchMode'] = "EXACT";
1452
	$taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1453

    
1454
	//removing the name where we come from and
1455
	foreach($taxon_pager->records as $k=>&$taxon){
1456
		if($taxon->uuid == $taxon_to_hide_uuid){
1457
			unset($taxon_pager->records[$k]);
1458
		}
1459
	}
1460
	//show the taxa list or go to the singular taxon
1461
	if (sizeof($taxon_pager->records) == 1){ //sigle taxon case
1462
		reset($taxon_pager->records);
1463
		$first_key = key($taxon_pager->records);
1464
		if($taxon_pager->records[$first_key]->class != "Taxon"){
1465
			$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, $taxon_pager->records[$first_key]->uuid);
1466
			if($synonym_uuid){
1467
				drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
1468
			}else{
1469
				drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid);
1470
			}
1471
		}else{
1472
			if($synonym_uuid){
1473
				drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid . '/synonymy',
1474
                      'highlite=' . $synonym_uuid);
1475
			}else{
1476
				drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid);
1477
			}
1478
			//drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid);
1479
		}
1480
	}else{ //more than one taxa case
1481
		$taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
1482
		if($taxon_pager->records){
1483
			$taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
1484
		}else{
1485
			$taxon_name_page->content = 'This name has no taxa';
1486
		}
1487
		return $taxon_name_page;
1488
	}
1489
}
1490

    
1491
function cdm_dataportal_view_search_advanced(){
1492

    
1493
	drupal_set_title(t('Advanced search'));
1494

    
1495
	$searchForm = cdm_dataportal_search_taxon_form(true);
1496

    
1497
	return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1498

    
1499
}
1500

    
1501
/**
1502
 *
1503
 * future extensions to meet palmweb mockup requirements:
1504
 *  - habitat
1505
 *  - uses
1506
 *  - conservation status
1507
 *  - locality / tdwg region
1508
 */
1509
function cdm_dataportal_view_search_taxon(){
1510

    
1511
	$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
1512

    
1513
	$request_params = cdm_dataportal_search_form_request();
1514
	$taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1515

    
1516
	$search_params = $_REQUEST;
1517
	unset($search_params['q']);
1518
	return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
1519
}
1520

    
1521

    
1522
function cdm_view_xml2json(){
1523
	$file = arg(2);
1524
	$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
1525
	return  xml2json::transformXmlStringToJson($datastr);
1526
}
1527

    
1528
/* ====================== other functions ====================== */
1529

    
1530
/**
1531
 * Enter description here...
1532
 *
1533
 * @param String $uuid the UUID of the taxon
1534
 * @return the URL
1535
 */
1536
function path_to_taxon($uuid){
1537
	if(!$uuid) return false;
1538
	if(get_last_taxon_page_tab()){
1539
		return 'cdm_dataportal/taxon/'.$uuid . '/' . get_last_taxon_page_tab();
1540
	} else {
1541
		 return 'cdm_dataportal/taxon/'.$uuid ;
1542
	}
1543
}
1544

    
1545
function path_to_reference($uuid){
1546
	if(!$uuid) return false;
1547
	return 'cdm_dataportal/reference/'.$uuid;
1548
}
1549

    
1550
function path_to_name($name_uuid){
1551
	$res = false;
1552
	if($name_uuid){
1553
	 $res = 'cdm_dataportal/name/'.$name_uuid;
1554
	}
1555
	return $res;
1556
}
1557

    
1558
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
1559
	if(!$uuid) return false;
1560
	$out = 'cdm_dataportal/media/'.$uuid;
1561
	if($representaion_uuid){
1562
		$out .= '/'.$representaion_uuid;
1563
		if($partId !== false){
1564
			$out .= '/'.$partId;
1565
		}
1566
	}
1567
	return $out;
1568
}
1569

    
1570
/**
1571
 * Compares thisRank with thatRank.
1572
 * Returns a negative integer, zero, or a positive integer
1573
 * as the of thisRank is higher than, equal to, or lower than thatRank.
1574
 * e.g:
1575
 * <ul>
1576
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
1577
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
1578
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
1579
 * </ul>
1580
 * <p>
1581
 * This compare logic of the underlying webservice is the
1582
 * <b>inverse logic</b> of the the one implemented in
1583
 * java.lang.Comparable#compareTo(java.lang.Object)
1584
 * @param $thisRankUuid
1585
 * @param $thatRankUuid
1586
 * @return  a negative integer, zero, or a positive integer
1587
 * as the thisRank is lower than, equal to, or higher than thatRank
1588
 */
1589
function rank_compare($thisRankUuid, $thatRankUuid){
1590
	$result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
1591
	return $result->Integer;
1592
}
1593

    
1594
function uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null){
1595
	$acceptedPath = path_to_taxon($acceptedUuid);
1596
	return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid, $synonymUuid);
1597
}
1598

    
1599
/**
1600
 * Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
1601
 * If the taggename if empty the fullname will be returned.
1602
 *
1603
 * @param unknown_type $Name or TreeNode
1604
 * @return string
1605
 */
1606
function cdm_dataportal_shortname_of($name){
1607

    
1608
	$nameStr = '';
1609
	// get all tagged text tokens of the scientific name
1610
	foreach($name->taggedTitle as $tagtxt){
1611
		if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
1612
			$nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
1613
		}
1614
	}
1615
	$nameStr = trim($nameStr);
1616
	/*
1617
	 if (stristr(strtolower($nameStr), 'incertae sedis') !== FALSE ||
1618
	 stristr(strtolower($nameStr), 'nomina excludenda') !== FALSE){
1619
	 var_dump($nameStr);
1620
	 }
1621
	 */
1622
	if($nameStr){
1623
		// do not return short names for these
1624
		//if(strtolower($nameStr) == 'incertae sedis' || $nameStr ==  'nomina excludenda'){
1625
		if (stristr(strtolower($nameStr), 'incertae sedis') !== FALSE ||
1626
		stristr(strtolower($nameStr), 'nomina excludenda') !== FALSE){
1627
			return $nameStr;
1628
		}
1629
		if($pos = stripos($nameStr, ' ')){
1630
			return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos);
1631
		} else {
1632
			return $nameStr;
1633
		}
1634
	} else {
1635
		return $name->titleCache;
1636
	}
1637
}
1638

    
1639

    
1640
/**
1641
 * Check if a taxon is accepted by the current taxonomic tree
1642
 *
1643
 * @param Taxon $taxon
1644
 * @return true if $taxon is accepted, false otherwise
1645
 */
1646

    
1647
function _cdm_dataportal_acceptedByCurrentView($taxon){
1648

    
1649
	$defaultTreeUuid = get_taxonomictree_uuid_selected();
1650
	if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){
1651
		foreach($taxon->taxonNodes as $node){
1652
			if($node->taxonomicTree == $defaultTreeUuid) {
1653
				return true;
1654
			}
1655
		}
1656
	}
1657
	return false;
1658
}
1659

    
1660
/**@Deprecated
1661
 *
1662
 */
1663
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
1664
	$pstr = '';
1665
	foreach($parameters as $key=>$value){
1666
		if(is_array($value)){
1667

    
1668
		} else {
1669
			$pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
1670
		}
1671
	}
1672
	return $pstr;
1673
}
1674

    
1675
/**
1676
 * workaround for missing original source type, idNamespace is always set in these cases
1677
 * @param unknown_type $source
1678
 * @return unknown_type
1679
 */
1680
function _is_original_source_type($source){
1681
	return !$source->idNamespace && strlen($source->idNamespace) == 0;
1682
}
1683

    
1684

    
1685
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
1686
	//TODO implement admin user interface to replace switch statement
1687
	//     preliminar solution: using themes
1688

    
1689
	$template = null;
1690
	// find best matching default RenderTemplate in theme
1691
	//echo "<br/><br/>RENDER PATH:  ".$renderPath;
1692
	//var_dump('RENDER PATH: ' . $renderPath);
1693
	while(!is_array($template) && strlen($renderPath) > 0){
1694
		$template = theme('get_nameRenderTemplate', $renderPath);
1695
		$renderPath = substr($renderPath, 0, strrpos($renderPath, '.'));
1696
		//	   if(!is_array($template)){
1697
		//	       echo "<br/>->".$renderPath;
1698
		//	   }
1699
	}
1700

    
1701
	// otherwise get default RenderTemplate from theme
1702
	if(!is_array($template)){
1703
		$template = theme('get_nameRenderTemplate', '#DEFAULT');
1704
	}
1705
	// otherwise get system default RenderTemplate
1706
	if(!is_array($template)){
1707
		switch($renderPath){
1708
			case 'list_of_taxa':
1709
			case  'acceptedFor':
1710
			case 'taxon_page_synonymy':
1711
			case 'typedesignations':
1712
			case 'taxon_page_title':
1713
			case 'na': $template = array(
1714
			        'namePart' => array('#uri'=>true),
1715
			//'authorshipPart' => true,
1716
			);
1717
			break;
1718
			case 'nar': $template = array(
1719
		          	'namePart' => array('#uri'=>true),
1720
			//'authorshipPart' => true,
1721
		          	'referencePart' => array('#uri'=>true),
1722
		          	'microreferencePart' => true,
1723
			);
1724
			break;
1725
			default: $template = array(
1726
          'namePart' => array('#uri'=>true),
1727
          'authorshipPart' => true,
1728
          'referencePart' => array('#uri'=>true),
1729
          'microreferencePart' => true,
1730
          'statusPart' => true,
1731
          'descriptionPart' => true
1732
			);
1733
		}
1734
	}
1735

    
1736
	if($nameLink && isset($template['nameAuthorPart']['#uri'])){
1737
		$template['nameAuthorPart']['#uri'] = $nameLink;
1738
	} else{
1739
		unset($template['nameAuthorPart']['#uri']);
1740
	}
1741

    
1742
	if($nameLink && isset($template['namePart']['#uri'])){
1743
		$template['namePart']['#uri'] = $nameLink;
1744
	} else{
1745
		unset($template['namePart']['#uri']);
1746
	}
1747

    
1748
	if($refenceLink && isset($template['referencePart']['#uri'])){
1749
		$template['referencePart']['#uri'] = $refenceLink;
1750
	}else{
1751
		unset($template['referencePart']['#uri']);
1752
	}
1753

    
1754
	return $template;
1755
}
1756

    
1757
function get_partDefinition($taxonNameType){
1758
	//TODO implement admin user interface to allow specify the partdefinitions for any type
1759
	//     preliminar solution: using themes
1760

    
1761
	$partdef = theme('get_partDefinition', $taxonNameType);
1762

    
1763
	if(!is_array($partdef)){
1764
		switch($taxonNameType){
1765
			case 'ZoologicalName': $partdef = array(
1766
        'namePart' => array(
1767
          'name' => true,
1768
			),
1769
        'referencePart' => array(
1770
          'authorTeam' => true
1771
			),
1772
        'microreferencePart' => array(
1773
          'microreference' => true,
1774
			),
1775
        'statusPart' => array(
1776
          'status' => true,
1777
			),
1778
        'descriptionPart' => array(
1779
          'description' => true,
1780
			),
1781
			);
1782
			break;
1783
			case 'BotanicalName': $partdef = array(
1784
        'namePart' => array(
1785
          'name' => true
1786
			),
1787
        'authorTeamPart' => array(
1788
          'authorTeam' => true,
1789
			),
1790
        'referencePart' => array(
1791
          'reference' => true
1792
			),
1793
        'microreferencePart' => array(
1794
          'microreference' => true,
1795
			),
1796
        'statusPart' => array(
1797
          'status' => true,
1798
			),
1799
        'descriptionPart' => array(
1800
          'description' => true,
1801
			),
1802
			);
1803
			break;
1804
			default: $partdef = array(
1805
        'namePart' => array(
1806
          'name' => true,
1807
			),
1808
        'authorTeamPart' => array(
1809
          'authorTeam' => true,
1810
			),
1811
        'referencePart' => array(
1812
          'reference' => true
1813
			),
1814
        'microreferencePart' => array(
1815
          'microreference' => true,
1816
			),
1817
        'statusPart' => array(
1818
          'status' => true,
1819
			),
1820
        'descriptionPart' => array(
1821
          'description' => true,
1822
			),
1823
			);
1824
		}
1825
	}
1826
	return $partdef;
1827
}
1828

    
1829
/**
1830
 * The function read the metadata info such title or artist of a media file. The
1831
 * function tries at first to get all the info from the file metadata and if it is
1832
 * not avaible look at the media file info stored at the database.
1833
 * @param $media The media file
1834
 * @return array The array with the avilable specified metadata info.
1835
 * TODO rename to read_media_metadata() and move to *.module
1836
 */
1837
function cdm_read_media_metadata($media){
1838

    
1839
	$metadata_caption = array('title' => '',           //media_metadata and media
1840
                              'artist' => '',          //media_metadata and media
1841
                              'rights',                //media_metadata and media
1842
                              'location',              //media_metadata
1843
                              'filename' => '',        //media
1844
                              'mediacreated' => '',    //media
1845
                              'description' => '');    //media
1846

    
1847
	//getting the media metadata
1848
	$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
1849

    
1850
	//title
1851
	//if ($media_metadata->Headline) {
1852
	if ($media_metadata->ObjectName) {
1853
		$metadata_caption['title'] = $media_metadata->ObjectName;
1854
		//	} else if ($media->titleCache){
1855
		//		$metadata_caption['title'] = $media_metadata->ObjectName;
1856
	} else if ($media->titleCache){
1857
		$metadata_caption['title'] = $media->titleCache;
1858
		if ($media->description_L10n)
1859
		$metadata_caption['title'] .= ' - ' . $media->description_L10n;
1860
	}else{ //if there is no title on the db and metadata get file title
1861
		$aux = $media->representations[0]->parts[0]->uri;
1862
		$aux = explode("/", $aux);
1863
		$aux = end($aux);
1864
		$metadata_caption['title'] = $aux;
1865
	}
1866

    
1867
	//artist
1868
	if ($media_metadata->Artist){
1869
	 $metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
1870
	}
1871
	elseif ($media->artist->titleCache){
1872
	 $metadata_caption['artist'] = $media->artist->titleCache;
1873
	}
1874

    
1875
	//copyright
1876
	$metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
1877
                                      'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
1878
	if ($media_metadata->Copyright)
1879
	$metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
1880
	elseif ($media->rights){
1881
		foreach($media->rights as $right){
1882
			switch($right->term->uuid){
1883
				case UUID_RIGHTS_LICENCE:
1884
					$metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
1885
					$metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
1886
					$metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
1887
					$metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
1888
					break;
1889
				case UUID_RIGHTS_COPYRIGHT:
1890
					$metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
1891
					break;
1892
			}
1893
		}
1894
	}
1895
	else
1896
	$metadata_caption['rights']['agentNames'][] = '';
1897

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

    
1901
	//location
1902
	$metadata_caption['location'] = array();
1903
	$metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
1904
	$metadata_caption['location']['city'] = $media_metadata->City;
1905
	$metadata_caption['location']['province'] = $media_metadata->Province;
1906
	$metadata_caption['location']['country'] = $media_metadata->Country;
1907

    
1908
	//filename
1909
	if(isset($media->representations[0]->parts[0]->uri)){
1910
		$fileUri = $media->representations[0]->parts[0]->uri;
1911
		$filename = substr($fileUri, strrpos($fileUri, "/")+1);
1912
		$metadata_caption['filename'] = $filename;
1913
	}
1914
	else{
1915
	 $metadata_caption['filename'] = '';
1916
	}
1917
	/*
1918
	 //creation date
1919
	 if($media_metadata["Modify Date"])
1920
	 $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
1921
	 else
1922
	 $metadata_caption['mediacreated'] = $media->created;
1923
	 */
1924
	//returned value
1925
	return $metadata_caption;
1926
}
1927

    
1928
/**
1929
 * This function collects all the media from a list of description elements
1930
 * and return them as an Array.
1931
 *
1932
 * @param $descriptionElementes The description elements
1933
 * @return Array The output with all the media
1934
 */
1935
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
1936
	//variables
1937
	$outArrayOfMedia = array(); //return value
1938
	//implementation
1939
	if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
1940
		foreach($descriptionElements as $descriptionElement){
1941
			if(is_array($descriptionElement->media)){
1942
				foreach($descriptionElement->media as $media){
1943
					if(isset($media)){
1944
						$outArrayOfMedia[] = $media;
1945
					}
1946
				}
1947
			}
1948
		}
1949
	}
1950
	return $outArrayOfMedia;
1951
}
1952

    
1953
function cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key = array()){
1954
	$footNoteKeys = array();
1955
	//is argument cdmBase an array?
1956
	if (!is_array($cdmBase)){
1957
		$cdmBase_array = array();
1958
		$cdmBase_array[] = $cdmBase;
1959
	}else{
1960
		$cdmBase_array = $cdmBase;
1961
	}
1962
	//getting the key for the footnotemanager
1963
	if((bool) $footnote_list_key){
1964
		$footnoteListKey = $footnote_list_key;
1965
	}else{
1966
		$footnoteListKey = RenderHints::getFootnoteListKey() . '-annotations';
1967
	}
1968
	//adding the footnotes keys
1969
	foreach($cdmBase_array as $cdmBase_element){
1970
		$annotationUrl = cdm_compose_annotations_url($cdmBase_element);
1971
		if($annotationUrl){
1972
			$annotationPager = cdm_ws_get($annotationUrl, null, null, null, true);
1973
			if($annotationPager->count > 0){
1974
				foreach($annotationPager->records as $annotation){
1975
					$footNoteKeys[] = FootnoteManager::addNewFootnote($footnoteListKey, $annotation->text);
1976
				}
1977
			}
1978
		}
1979
	}
1980
	return $footNoteKeys;
1981
	/*
1982
	 $footNoteKeys = array();
1983
	 $footnoteListKey = RenderHints::getFootnoteListKey() . '-annotations';
1984
	 $annotationUrl = cdm_compose_annotations_url($cdmBase);
1985
	 if($annotationUrl){
1986
		$annotationPager = cdm_ws_get($annotationUrl, null, null, null, true);
1987
		if($annotationPager->count > 0){
1988
		foreach($annotationPager->records as $annotation){
1989
		$footNoteKeys[] = FootnoteManager::addNewFootnote($footnoteListKey, $annotation->text);
1990
		}
1991
		}
1992
		}
1993
		return $footNoteKeys;
1994
		*/
1995
}
1996

    
1997
function cdm_dynabox($label, $content_url, $theme, $link_alt_text, $enclosingtags = array('li', 'ul')){
1998

    
1999
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
2000

    
2001
  $cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
2002
  $out .= '<'. $enclosingtags[0]. ' class="dynabox"><span class="label" alt="'.t($link_alt_text).'">'.$label.'</span>';
2003
  $out .= '<'. $enclosingtags[1]. ' class="dynabox_content" title="'.$cdm_proxy_url.'"><'. $enclosingtags[0]. '><img class="loading" src="'.drupal_get_path('module', 'cdm_dataportal').'/images/loading_circle_grey_16.gif" style="display:none;"></'. $enclosingtags[0]. '></'. $enclosingtags[1]. '>';
2004
  $out .= '</'. $enclosingtags[0]. '>';
2005
  return $out;
2006
}
2007

    
(6-6/9)