Project

General

Profile

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

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

    
13

    
14
function _add_js_openlayers_map(){
15

    
16
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
17
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/openlayers_map.js');
18

    
19
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
20
  drupal_set_html_head('<script src=http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key='.$gmap_api_key.'" type="text/javascript"></script>');
21
  drupal_set_html_head('<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" type="text/javascript"></script>');
22

    
23
	drupal_add_js("
24
        if (Drupal.jsEnabled) {
25
          $(document).ready(function() {
26
              $('#openlayers_map').cdm_openlayers_map('"
27
              .variable_get('cdm_dataportal_geoservice_access_point', false)."', {
28
                legendPosition: 3,
29
                displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', false) . "',
30
                boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', false) . "',
31
                distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "',
32
                legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "',
33
                showLayerSwitcher: '" . variable_get('cdm_dataportal_geoservice_showLayerSwitcher', true) . "'
34
            });
35
          });
36
        }", 'inline');
37

    
38
}
39

    
40
function theme_cdm_feature_nodesTOC($featureNodes){
41

    
42
	$out .= '<ul>';
43

    
44
	foreach($featureNodes as $node){
45
		// process $descriptionElements with content only
46
		if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0 || count($node->children) > 0){
47

    
48
			$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
49
			// HACK to implement images for taxa, should be removed
50
			if($node->feature->uuid != UUID_IMAGE){
51
				$out .= '<li>'.l(t(theme('cdm_feature_name', $featureRepresentation)), $_GET['q'], array("class"=>"toc"), NULL, generalizeString($featureRepresentation)).'</li>';
52
			}
53
		}
54
	}
55

    
56
	$out .= '</ul>';
57
	return $out;
58
}
59

    
60
function theme_cdm_feature_name($feature_name){
61
	//TODO replace by using translations ?
62
	switch($feature_name){
63
		default: return t(ucfirst($feature_name));
64
	}
65
}
66

    
67
function theme_cdm_featureTrees($mergedTrees, $taxon){
68
	if(!$mergedTrees){
69
		return;
70
	}
71
	foreach($mergedTrees as &$mTree){
72
		//TODO diplay title and reference in case of multiple $mergedTrees -> theme
73
		$out .= theme('cdm_feature_nodes', $mTree->root->children, $taxon);
74
	}
75
	return $out;
76
}
77

    
78

    
79

    
80
function theme_cdm_featureTreeTOCs($mergedTrees){
81

    
82
	if(!$mergedTrees){
83
		return;
84
	}
85
	//FIXME
86
	$out = '<div class="featureTOC">';
87
	$out .= '<h2>' . t('Content') .'</h2>';
88

    
89
	//TODO diplay title and reference in case of multiple $mergedTrees -> theme
90

    
91
	foreach($mergedTrees as &$mTree){
92
		$out .= theme('cdm_feature_nodesTOC', $mTree->root->children);
93
	}
94

    
95
	$out .= '</div>';
96
	return $out;
97
}
98

    
99

    
100

    
101
function theme_cdm_feature_nodes($featureNodes, $taxon){
102

    
103
	RenderHints::pushToRenderStack('feature_nodes');
104
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
105

    
106
	foreach($featureNodes as $node){
107
		// process $descriptionElements with content only
108
		if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0 || count($node->children) > 0){
109
			$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
110
			$block->module = 'cdm_dataportal';
111

    
112
			if($node->feature->uuid != UUID_IMAGE){
113
				$block->delta = generalizeString($featureRepresentation);
114
				$block->subject = theme('cdm_feature_name', $featureRepresentation);
115
				$block->module = "cdm_dataportal-feature";
116
				$block->content = '';
117

    
118
				// Display cdm distribution map TODO this is a HACK to a proper generic implementation?
119
				if($node->feature->uuid == UUID_DISTRIBUTION){
120
					$block->content .= theme('cdm_distribution_map', $taxon);
121
				}
122

    
123
				//get the text for the feature block
124
				//if ($node->feature->titleCache == 'Common Name'){
125
				if ($node->feature->uuid == UUID_COMMON_NAME){
126
					$block->content .= theme('cdm_common_names', $node->descriptionElements);
127
				} else {
128
					$block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
129
				}
130

    
131
				// get media for the feature block
132
				$media_list = cdm_dataportal_media_from_descriptionElements($node->descriptionElements);
133
				$captionElements = array('title', 'rights');
134
				//$block->content .= theme('cdm_media_gallerie', $media_list, "test", 150, 4, false, $captionElements);
135
				$block->content .= theme('cdm_media_gallery', $media_list,
136
				CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
137
				$gallery_settings['cdm_dataportal_media_maxextend'],
138
				$gallery_settings['cdm_dataportal_media_cols'],
139
				$gallery_settings['cdm_dataportal_media_maxRows'],
140
				$captionElements
141
				);
142

    
143
				$block->content .= theme('cdm_footnotes', $node->feature->uuid);
144
				$block->content .= theme('cdm_annotation_footnotes', $node->feature->uuid);
145

    
146
				// set anchor; FIXME put anchor in $block->subject
147
				$out .= '<a name="'.$block->delta.'"></a>';
148
				$out .= theme('block', $block);
149

    
150
			}
151
		}
152
		// theme
153
		if(count($node->children) > 0){
154
			/*
155
			 $out .= '<div class="nested_description_elements">';
156
			 $out .= theme('cdm_feature_nodes', $node->children, $taxon);
157
			 $out .= '</div>';
158
			 */
159
			$text = '';
160
			foreach ($node->children as $child){
161
			 //$out .= theme('cdm_descriptionElementTextData', $child->descriptionElements[0], false);
162
			 if (is_array($child->descriptionElements)){//if condition added to avoid warnings
163
			 	foreach ($child->descriptionElements as $element) {
164
			 		$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
165
			 		$description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
166
			 	}
167
			 	$text .= $description;
168
			 	$description = '';
169
			 }
170
			}
171
			$out .= $text;
172
		}
173

    
174
	}
175
	RenderHints::popFromRenderStack();
176
	return $out;
177
}
178

    
179

    
180

    
181

    
182
function theme_cdm_descriptionElementArray($elementArray, $feature, $glue = '', $sortArray = false, $enclosingHtml = 'ul'){
183
	$out = '<'.$enclosingHtml.' class="description" id="'.$feature->representation_L10n.'">';
184

    
185
	if($sortArray) sort($elementArray);
186

    
187
	$out .= join($elementArray, $glue);
188

    
189
	$out .= '</'.$enclosingHtml.'>';
190
	return $out;
191
}
192

    
193

    
194
function theme_cdm_descriptionElement_CommonTaxonName($element){
195
	$out = $element->language->representation_L10n . ' (' . $element->area->titleCache . '): ' . $element->name;
196
	return $out;
197
}
198
/**
199
 * TODO: assign a new name to the function? because it is used for the citations
200
 *       textdata elements and not for all text data description elements
201
 * @param $element The description element which contains the text information
202
 * @param $asListElement A boolean which determines whether the citations should
203
 *                       be renderer as a list or not
204
 * @return unknown_type Html to be renderized in drupal
205
 */
206
function theme_cdm_descriptionElementTextData($element, $asListElement, $feature_uuid){
207
	$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
208
	$sourceRefs = '';
209
	$result = array();
210
	$out;
211
	$res_author;
212
	$res_date;
213

    
214
	if(is_array($element->sources)){
215
		foreach($element->sources as $source){
216
			$referenceCitation = theme('cdm_DescriptionElementSource', $source);
217
			if($description && strlen($description) > 0 && $referenceCitation ){
218
				$sourceRefs .= ' ('.$referenceCitation.')' ;
219
			}else if ($referenceCitation){
220
				$sourceRefs = $referenceCitation;
221
			}
222

    
223
			if(strlen($sourceRefs) > 0){
224
				$sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
225
			}
226

    
227
			if ($source->nameUsedInSource->uuid){ //do a link to name page
228
				$name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
229
				path_to_name($source->nameUsedInSource->uuid),
230
				array(), NULL, NULL, FALSE ,TRUE);
231
			}else if (strlen($source->nameUsedInSource->originalNameString) > 0){ //show a text without link
232
				$name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
233
			}
234

    
235
			if ($asListElement){
236
				$out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
237
				//adding ":" if necesary
238
				if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
239
					$out .= ': ';
240
				}
241
				$out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', $element) . '</li>';
242
			}else{
243
				if ($name_used_in_source_link_to_show){
244
					$name_used_in_source_link_to_show = ' (name in source: '. $name_used_in_source_link_to_show . ')';
245
				}
246
				$out = $description . $sourceRefs . $name_used_in_source_link_to_show;
247
			}
248
		}
249
	}
250
	//if no sources, print the description
251
	if(!isset($out)) {
252
		$out = $description;
253
	}
254
	//printing annotations footnotes
255
	//$out .= theme('cdm_annotations_as_footnotekeys', $element);
256
	// add annotations as footnote key
257
	//$out .= theme('cdm_annotations_as_footnotekeys', $element); move above
258
	return $out;
259
}
260

    
261
function theme_cdm_common_names($elements){
262
	$text_data_out = '';
263
	$common_name_out = '';
264
	$separator = ',';
265
	$textData_commonNames = array();
266

    
267
	if (is_array($elements)){
268
		foreach ($elements as $element){
269
			if ($element->class == 'CommonTaxonName'){
270
				//$key = '<b>' . $element->language->representation_L10n . '</b> (' . $element->area->titleCache . ')';
271
				if ($element->language->representation_L10n){
272
					$key = '<b>' . $element->language->representation_L10n . '</b>';
273
					$key .= (strlen($element->area->titleCache)>0) ? ' (' . $element->area->titleCache . ')' : '';
274
				}
275
				$common_names[$key][] = $element;
276
			}else if ($element->class == 'TextData' && $element->feature->uuid == UUID_COMMON_NAME){
277
				$textData_commonNames[] = $element;
278
			}
279
		}
280
	}
281
	//handling common names
282
	if (count($common_names) > 0){
283
		//sorting the a-array based on the area (key)
284
		ksort($common_names);
285
		//creating the output to be render by drupal
286
		foreach ($common_names as $key => $elements){
287
			$rendered_element_list = '';
288
			foreach($elements as $element){
289
				$sourcesFootnoteKeyList = '';
290
				// adding footnotes sources
291
				foreach($element->sources as $source){
292
					if(_is_original_source_type($source)){
293
						$_fkey = FootnoteManager::addNewFootnote(UUID_COMMON_NAME, theme('cdm_DescriptionElementSource', $source, false));
294
						$sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
295
					}
296
				}
297
				if($element->name){
298
				  $rendered_element_list .= (strlen($rendered_element_list) > 0 ? ', ': '') . $element->name . $sourcesFootnoteKeyList;
299
			  }
300
			}
301
			if ($key){
302
			 $common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $key . ': ' . $rendered_element_list;
303
			}else{
304
			  $common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $rendered_element_list;
305
			}
306
		}
307
	}
308
	//handling commons names as text data
309
	foreach($textData_commonNames as $text_data_element){
310
		$text_data_out .= theme('cdm_descriptionElementTextData', $text_data_element, true, $text_data_element->feature->uuid);
311
	}
312
	
313
	$common_name_out = "<div class=common_names_as_common_names> $common_name_out </div>";
314
  $out_array[] = $text_data_out;
315
	$common_name_out_text_data = '<div class=common_names_as_text_data>' . theme('cdm_descriptionElementArray', $out_array, $element->feature) . '</div>';
316
	
317
	return $common_name_out;
318
	//return $common_name_out . theme('cdm_descriptionElementArray', $out_array, $element->feature);
319
	//return "<div class=common_names> $common_name_out $common_name_out_text_data";
320
}
321

    
322
/**
323
 * Theme a list of description elements, usually of a specific feature type
324
 * @param $descriptionElements
325
 * @return unknown_type
326
 */
327
function theme_cdm_descriptionElements($descriptionElements, $featureUuid, $taxon_uuid){
328
	$outArray = array();
329
	if(variable_get('distribution_sort', 'NO_SORT')  != 'NO_SORT'){
330
		$glue = '';
331
		$enclosingHtml = 'dl';
332
	} else {
333
		$glue = '';
334
		$enclosingHtml = 'ul';
335
	}
336
	$sortOutArray = false;
337
	$distributionElements = array();
338

    
339
	RenderHints::pushToRenderStack('cdm_descriptionElements');
340
	$common_names = theme('cdm_common_names', $descriptionElements);
341
	if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
342
		foreach($descriptionElements as $descriptionElement){
343
			if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
344
				if($descriptionElement->class == 'Distribution'){
345
					$distributionElements[]= $descriptionElement;
346
				} else if($descriptionElement->class == 'TextData'){
347
					$asListElement = false;
348
					$repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
349

    
350
					if( !array_search($repr, $outArray)){
351
						$outArray[] = $repr;
352
						$glue = '<br/> ';
353
						$sortOutArray = true;
354
						$enclosingHtml = 'p';
355
					}
356
				}
357
			}else if($descriptionElement->class == 'TextData'){
358
				$asListElement = true;
359
				$outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
360
			}else if ($descriptionElement->class == 'CommonTaxonName') {
361
				$outArray[] = theme('cdm_descriptionElement_CommonTaxonName', $descriptionElement);
362
			}else {
363
				$outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
364
			}
365
		}
366
	}
367
	//if feature = NAME USAGE sort the list of sources
368
	//this is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE
369
	if($descriptionElement->feature->uuid == UUID_NAME_USAGE){
370
		sort($outArray);
371
	}
372

    
373
	if(variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT'){
374
		$outArray[] = theme('cdm_description_ordered_distributions2', $taxon_uuid, $distributionElements);
375
	}else{
376
		$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
377
	}
378
	//$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
379
	//$outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
380

    
381
	// take the feature of the last $descriptionElement
382
	$feature = $descriptionElement->feature;
383
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
384

    
385
	RenderHints::popFromRenderStack();
386
	return $out;
387
}
388

    
389
/**
390
 *
391
 * @param unknown_type $descriptionElements
392
 * @return unknown_type
393
 */
394
function theme_cdm_descriptionElementDistribution($descriptionElements){
395
	$out = '';
396
	$separator = ',';
397
	RenderHints::pushToRenderStack('descriptionElementDistribution');
398
	RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
399
	foreach($descriptionElements as $descriptionElement){
400
		// annotations as footnotes
401
		//$annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
402
		$footNoteKeys = cdm_annotations_as_footnotekeys($descriptionElement);
403
		// source references as footnotes
404
		foreach($descriptionElement->sources as $source){
405
			if(_is_original_source_type($source)){
406
				$fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
407
				cdm_add_footnote_to_array($footNoteKeys, $fn_key);// ensure uniqueness of the footnote keys
408
			}
409
		}
410
		// sort and render footnote keys
411
		$footnoteKeyListStr = '';
412
		asort($footNoteKeys);
413
		foreach($footNoteKeys as $footNoteKey){
414
			$footnoteKeyListStr .= theme('cdm_footnote_key', $footNoteKey, ($footnoteKeyListStr ? $separator : ''));
415
		}
416
		$out .= '<span class="descriptionElement descriptionElement-'.$descriptionElement->uuid.'">'.$descriptionElement->area->representation_L10n . $footnoteKeyListStr . ' </span>';
417
	}
418

    
419
	//$out = substr($out, 0, strlen($out)-strlen($separator) );
420

    
421
	RenderHints::popFromRenderStack();
422
	return $out;
423

    
424
}
425

    
426

    
427
function theme_cdm_description_ordered_distributions2($taxon_uuid, $descriptionElements){
428
	//returning null if no description elements
429
	if ($descriptionElements == null){
430
		return '';
431
	}
432
	//initialization some variables
433
	$out = '';
434
	$separator = ',';
435
	RenderHints::pushToRenderStack('descriptionElementDistribution');
436
	RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
437
	//getting all the taxon description for a given taxon
438
	$taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon_uuid);
439
	foreach ($taxonDescriptions as $description){
440
		$descriptions_uuids[] = $description->uuid;
441
	}
442
	//getting the sortered distributions (omiting level ??)
443
	$request_params = array();
444
	$request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
445
	$ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',',$descriptions_uuids), queryString($request_params));
446
	$ordered_areas = $ordered_areas->rootElement->children;
447

    
448
	//printing the distributions
449
	foreach ($ordered_areas as $element_level1){
450
		//level1
451
		if ($element_level1->data){
452
			$out .= '<dt>' . $element_level1->data->area->representation_L10n . ':</dt> ';
453
		}
454
		$out .= '<dd>';
455

    
456
		//level3
457
		foreach ($element_level1->children as $element_level3){
458
			if ($element_level3->data){
459
				$text_l3 = $element_level3->data->area->representation_L10n;
460
			}
461
			$fnKeysLevel3Str = '';
462
			$fnKeysLevel3 = cdm_annotations_as_footnotekeys($element_level3->data);
463
			foreach($element_level3->data->sources as $source){
464
				if(_is_original_source_type($source)){
465
					$fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
466
					cdm_add_footnote_to_array($fnKeysLevel3, $fn_key3);
467
				}
468
			}
469
			//level4
470
			$l4_regions = array();
471
			foreach ($element_level3->children as $element_level4){
472
				if ($element_level4->data){
473
					$text_l4 = $element_level4->data->area->representation_L10n;
474
					$l4_regions[$element_level3->data->area->representation_L10n] = '';
475
					$fnKeysLevel4Str = '';
476
					$fnKeysLevel4 = cdm_annotations_as_footnotekeys($element_level4->data);
477
					foreach($element_level4->data->sources as $source){
478
						if(_is_original_source_type($source)){
479
							$fn_key4 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
480
							cdm_add_footnote_to_array($fnKeysLevel4, $fn_key4);
481
						}
482
					}
483
					$l4_regions[$text_l4] = $fnKeysLevel4;
484
				}
485
			}//level4
486
			//managing level3 and level4 for generating the right output
487
			foreach ($fnKeysLevel3 as $key3){
488
				foreach ($l4_regions as $key4 => $value4){
489
					cdm_add_footnote_to_array($l4_regions[$key4], $key3);
490
				}
491
			}
492
			if ($element_level3->numberOfChildren == 1 &&
493
			 $text_l3 == $element_level3->children[0]->data->area->representation_L10n){
494
				//var_dump($element_level3->children[0]->data->area->representation_L10n);
495
				$fnStr = '';
496
				$region = array_pop($l4_regions);
497
				foreach($region as $key){
498
					$fnStr .= theme('cdm_footnote_key', $key, ($fnStr ? $separator : ''));
499
				}
500
				$out .= "$text_l3 $fnStr; ";
501
			}else{
502
				$fnKeysLevel3Str = '';
503
				foreach($fnKeysLevel3 as $key){
504
					$fnKeysLevel3Str .= theme('cdm_footnote_key', $key, ($fnKeysLevel3Str ? $separator : ''));
505
				}
506
				$text_l4_aux = '';
507
				foreach ($l4_regions as $key => $value){
508
					$fnKeysLevel4Str = '';
509
					if (is_array($l4_regions[$key])) {
510
						foreach ($l4_regions[$key] as $fnkey){//warning why?
511
							$fnKeysLevel4Str .= theme('cdm_footnote_key', $fnkey, ($fnKeysLevel4Str ? $separator : ''));
512
						}
513
					}
514
					if ($key != $text_l3 || sizeof($l4_regions > 1)){
515
						$text_l4_aux .= "$key $fnKeysLevel4Str, ";
516
					}
517
				}
518
				$text_l4_aux = substr($text_l4_aux, 0, -2);
519
				if (strlen($text_l4_aux) > 0){
520
					$out .= "$text_l3 $fnKeysLevel3Str ( $text_l4_aux ); ";
521
				}else{
522
					$out .= "$text_l3 $fnKeysLevel3Str; ";
523
				}
524

    
525
			}
526
		}//level3
527
		$out = substr($out, 0, -2);
528
		$out .= '.</dd>';
529
	}//level1
530

    
531
	RenderHints::popFromRenderStack();
532
	return $out;
533
}
534

    
535

    
536
function theme_cdm_description_ordered_distributions($taxon_uuid, $descriptionElements){
537

    
538
	if ($descriptionElements == null){
539
		return '';
540
	}
541
	$out = '';
542
	$separator = ',';
543
	RenderHints::pushToRenderStack('descriptionElementDistribution');
544
	RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
545

    
546
	//getting all the taxon description for a given taxon
547
	$taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon_uuid);
548
	foreach ($taxonDescriptions as $description){
549
		$descriptions_uuids[] = $description->uuid;
550
	}
551
	//getting the sortered distributions (omiting level ??)
552
	$request_params = array();
553
	$request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
554
	//$ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_AREAS_TREE, join(',',$descriptions_uuids), queryString($request_params));
555
	$ordered_areas2 = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, join(',',$descriptions_uuids), queryString($request_params));
556
	$ordered_areas2 = $ordered_areas2->rootElement->children;
557

    
558
	//printing the distributions
559
	foreach ($ordered_areas2 as $element_l1){//level 1
560
		if ($element_l1->data){
561
			$out .= '<dt>' . $element_l1->data->area->representation_L10n . ':</dt> ';
562
		}
563
		$out .= '<dd>';
564

    
565
		foreach ($element_l1->children as $element_l3){//level 3
566
			$out_l4 = '';
567
			if ($element_l3->data){
568
				$l3 = $element_l3->data->area->representation_L10n;
569
			}
570
			if (sizeof($element_l3->children) == 0){
571
				$footnoteKeyListStr2 = '';
572
				$footNoteKeys2 = cdm_annotations_as_footnotekeys($element_l3->data);
573
				$superFootNoteKeys = array();
574
				foreach($element_l3->data->sources as $source){
575
					if(_is_original_source_type($source)){
576
						//$footNoteKeys2[] = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
577
						$fn_key3 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
578
						cdm_add_footnote_to_array($footNoteKeys2, $fn_key3);
579
						cdm_add_footnote_to_array($superFootNoteKeys, $fn_key3);
580
					}
581
				}
582
				foreach($footNoteKeys2 as $key){
583
					$footnoteKeyListStr2 .= theme('cdm_footnote_key', $key, ($footnoteKeyListStr2 ? $separator : ''));
584
				}
585
				//$out_l4 .= $l3 . $footnoteKeyListStr2 . ', ';
586
				$out_l4 .= $l3 . ', ';
587
			}
588
			$l4_aux = array();
589
			foreach ($element_l3->children as $element_l4){//level 4
590
				if ($element_l4->data){
591
					$l4 = $element_l4->data->area->representation_L10n;
592
					if (strlen($l4) > 0){
593
						//$out_l4 .= $l4;
594
						$footnoteKeyListStr = '';
595
						$footNoteKeys = cdm_annotations_as_footnotekeys($element_l4->data);
596
						if(isset($element_l4->data->sources)){
597
							foreach($element_l4->data->sources as $source){
598
								if(_is_original_source_type($source)){
599
									//$footNoteKeys[] = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
600
									$fn_key4 = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
601
									cdm_add_footnote_to_array($footNoteKeys, $fn_key4);
602
									cdm_add_footnote_to_array($superFootNoteKeys, $fn_key4);
603
								}
604
							}
605
						}
606
						foreach($footNoteKeys as $key){
607
							$footnoteKeyListStr .= theme('cdm_footnote_key', $key, ($footnoteKeyListStr ? $separator : ''));
608
						}
609
						$out_l4 .= $l4 . $footnoteKeyListStr .', ';
610
						$l4_aux[] = $l4 ;
611

    
612
					}
613
				}
614
			}
615
			$out_l4 = substr($out_l4, 0, -2);
616
			/*
617
			 $pieces1 = explode(", ", $out_l4); //var_dump($pieces1[0]);
618
			 $pieces2 =  explode('<span class="footnote-key', $pieces1[0]);
619
			 if (((sizeof($pieces1) == 1) && substr_count($pieces2[0], $l3) > 0) || strlen($out_l4)<2){
620
			 $out .= $out_l4 . $footnoteKeyListStr2 . '; ';
621
			 }else{
622
			 $out .= $l3 . $footnoteKeyListStr2 . ' (' . $out_l4 . '); ';
623
			 }
624
			 */
625
			$superfootnoteKeyListStr = '';
626
			foreach($superFootNoteKeys as $key){
627
				$superfootnoteKeyListStr .= theme('cdm_footnote_key', $key, ($superfootnoteKeyListStr ? $separator : ''));
628
			}		$superfootnoteKeyListStr = '';
629
			if (empty($l4_aux)){
630
				$out .= $out_l4 . '; ';      var_dump("caso1) $l3:$l4");
631
			}elseif ( (sizeof($l4_aux) == 1) && $l4_aux[0] == $l3 || empty($l4_aux)){
632
				$out .= $l4 . $superfootnoteKeyListStr . '; ';     var_dump("caso2) $l3:$l4");
633
				//$out .= $l4 . '; ';
634
			}else{
635
				$out .= $l3 . $footnoteKeyListStr2 . ' (' . $out_l4 . '); ';    var_dump("caso3) $l3:$l4");
636
				//$out .= $l3 . ' (' . $out_l4 . '); ';
637
			}
638

    
639

    
640

    
641
		}
642
		$out = substr($out, 0, -2);
643
		$out .= '.</dd>';
644
	}
645
	RenderHints::popFromRenderStack();
646
	return $out;
647

    
648
	//ignoring the root element because is garbage
649
	/*
650
	 $ordered_areas = $ordered_areas->rootElement->children;
651
	 $out = '';
652

    
653
	 foreach ($ordered_areas as $element_l1){//level 1
654
	 if ($element_l1->data){
655
	 //$result[] = $element_l1->data->titleCache;
656
	 $out .= '<b>' . $element_l1->data->titleCache . ':</b> ';
657
	 }
658
	 foreach ($element_l1->children as $element_l2){//level 2
659
	 $out_l3 = '';
660
	 if ($element_l2->data){
661
	 //$result[][] = $element_l2->data->titleCache;
662
	 //$out .= $element_l2->data->titleCache . '[';
663
	 }
664
	 foreach ($element_l2->children as $element_l3){//level 3
665
	 $out_l4 = '';
666
	 if ($element_l3->data){
667
	 //$result[][][] = $element_l3->data->titleCache;
668
	 $out .= $element_l3->data->titleCache;
669

    
670
	 $l3 = $element_l3->data->titleCache;
671
	 }
672
	 foreach ($element_l3->children as $element_l4){//level 4
673
	 if ($element_l4->data){
674
	 //$result[][][][] = $element_14->data->titleCache;
675
	 $l4 = $element_l4->data->titleCache;
676
	 if (sizeof($l4) != 0 && $l4 != $l3){
677
	 $out_l4 .= $l4 . ', ';
678
	 }
679
	 }
680
	 }
681
	 $out_l4 = substr($out_l4, 0, -2);
682
	 if($out_l4){
683
	 $out .= ' (' . $out_l4 . '); ';
684
	 }else{
685
	 $out .= '; ';
686
	 }
687
	 }
688
	 }
689
	 $out = substr($out, 0, -2);
690
	 $out .= '<br>';
691
	 }
692
	 */
693
}
694

    
695

    
696
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
697

    
698
	if(isset($descriptionElementSource->citation)){
699
		$out = theme('cdm_reference', $descriptionElementSource->citation, $descriptionElementSource->citationMicroReference, $doLink);
700
	}
701
	return $out;
702
}
703

    
704

    
705
/*
706
 function theme_cdm_descriptionElementDistribution($descriptionElements){
707

    
708
 $out = '';
709
 $separator = ',';
710
 RenderHints::pushToRenderStack('descriptionElementDistribution');
711
 RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
712
 foreach($descriptionElements as $descriptionElement){
713
 // annotations as footnotes
714
 $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
715
 // source references as footnotes
716
 $sourcesFootnoteKeyList = '';
717
 foreach($descriptionElement->sources as $source){
718
 if(_is_original_source_type($source)){
719
 $_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_DescriptionElementSource', $source, false));
720
 $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : ''));
721
 }
722
 }
723
 if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
724
 $annotationFootnoteKeys .= $separator;
725
 }
726
 $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList . ' ';
727
 }
728

    
729
 $out = substr($out, 0, strlen($out)-strlen($separator) );
730

    
731
 RenderHints::popFromRenderStack();
732
 return $out;
733

    
734
 }
735
 */
736

    
737

    
738
/**
739
 * TODO
740
 * Quick-and-dirty solution to show distribution service to exemplar groups
741
 *
742
 * @param unknown_type $featureTo
743
 * @return unknown
744
 */
745
function theme_cdm_distribution_map($taxon){
746

    
747
	$server = variable_get('cdm_dataportal_geoservice_access_point', false);
748

    
749
	if(!$server){
750
		//warning message
751
		drupal_set_message('No \'Geoservice Access Point\' has been set so far. '
752
		. 'Please configure the variable \'Geoservice Access Point\' here '
753
		. l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/geo'), 'warning');
754
		//message to render
755
		return "<p>No geoservice specified</p>";
756
	}else{
757
		$fontStyles = array(0 => "plane", 1 => "italic");
758

    
759
		$map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
760
		$query_string = $map_data_parameters->String;
761
		if(!$query_string){
762
			// the $query_string is empty if there are no distribution areas defined
763
			return ;
764
		}
765

    
766
		$query_string = str_replace('%3A', ":", $query_string);
767

    
768
		$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
769
		$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
770
		$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
771

    
772
		$query_string .= ($display_width ? '&img=false&ms=' . $display_width: '').
773
		($bounding_box ? '&bbox=' .  $bounding_box : '')
774
		. ($labels_on ? '&labels=' .  $labels_on : '');
775

    
776
		if(variable_get('cdm_dataportal_map_openlayers', 1)){
777

    
778
			/* =========== display distributions using the openlayers map viewer =========== */
779

    
780
			$legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
781
			$legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
782
			$legend_url_font_style = $fontStyles[$legend_url_font_style];
783
			$legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
784
			$legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
785

    
786
			//$legendQueryStr  = $geoserver_uri . "/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1&format=image".urlencode('/')."png&TRANSPARENT=TRUE";
787
			$legendFormatQueryStr  = "format=image".urlencode('/')."png&TRANSPARENT=TRUE";
788
			$legendFormatQueryStr .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
789
			$legendFormatQueryStr .="layer=topp".urlencode(':')."tdwg_level_4&LEGEND_OPTIONS=forceLabels".urlencode(':')."on;fontStyle".urlencode(':').$legend_url_font_style.";fontSize".urlencode(':').$legend_url_font_size."&SLD=".urlencode($sldLegend);
790

    
791
			$out = get_openlayers_map(
792
			$display_width,
793
			null,
794
			$query_string,
795
			$legendFormatQueryStr,
796
			variable_get('cdm_dataportal_geoservice_map_caption', '')
797
			);
798

    
799
		} else {
800
			// simple image
801
			$mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
802

    
803
			$query_string .= ($display_width ? '&img=true&ms=' . $display_width: '')
804
			.'&img=true&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=false';
805

    
806
			$mapUri = url($server. '/areas.php?' .$map_data_parameters->String, $query_string);
807
			$out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
808
		}
809
		/*
810
		 // add a simple legend
811
		 if(variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
812
		 $legenddata = array(
813
		 'native' => "4daf4a",
814
		 'native_doubtfully_native' => "377eb8",
815
		 'cultivated' => "984ea3",
816
		 'introduced' => "ff7f00",
817
		 'introduced adventitious' => "ffff33",
818
		 'introduced cultivated' => "a65628",
819
		 'introduced naturalized' => "f781bf"
820
		 );
821

    
822
		 $out .= '<div class="distribution_map_legend">';
823
		 foreach($legenddata as $term => $color){
824
		 $out .= '<img style="width: 3em; height: 1em; background-color: #'.$color.'" src="'.
825
		 drupal_get_path('module', 'cdm_dataportal').'/images/clear.gif" />'.t($term).' ';
826
		 }
827
		 $out .= '</div>';
828

    
829
		 }
830
		 */
831
		return $out;
832
	}
833
}
(2-2/8)