Project

General

Profile

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

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

    
16
require_once('node_types.php');
17

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

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

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

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

    
47

    
48

    
49

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

    
55

    
56

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

    
61

    
62
/* ====================== hook implementations ====================== */
63

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

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

    
82

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

    
97

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

    
104
	if ($may_cache) {
105

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
310
	return $items;
311

    
312
}
313

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

    
352

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

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

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

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

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

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

    
384
}
385

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

    
394
 function cdm_dataportal_session_validate(){
395

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

    
404
function cdm_dataportal_search_taxon_form($advancedForm = false){
405

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

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

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

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

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

    
439

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

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

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

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

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

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

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

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

    
571
	return $form;
572
}
573

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

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

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

    
597

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

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

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

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

    
622
	return $form_params;
623
}
624

    
625

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

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

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

    
646
	$form = cdm_api_settings_form();
647

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

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

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

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

    
680

    
681
	//------------------ FEATURE TREE --------------------//
682

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

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

    
700
	return system_settings_form($form);
701
}
702

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

    
709
	$form = array();
710

    
711

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

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

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

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

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

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

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

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

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

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

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

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

    
816
    return system_settings_form($form);
817
}
818

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

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

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

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

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

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

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

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

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

    
875
	return $form;
876
}
877

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

    
884
	$form = array();
885

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1007
	return system_settings_form($form);
1008

    
1009
}
1010

    
1011

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

    
1017
	_add_js_progressbar();
1018

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

    
1021
	$out = '';
1022

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

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

    
1049
	return $out;
1050
}
1051

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

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

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

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

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

    
1097

    
1098

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

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

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

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

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

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

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

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

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

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

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

    
1181
	return $taxonpage;
1182
}
1183

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

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

    
1226
  return $taxon_name_page; 
1227
}
1228

    
1229
function cdm_dataportal_view_search_advanced(){
1230

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

    
1233
	$searchForm = cdm_dataportal_search_taxon_form(true);
1234

    
1235
	return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1236

    
1237
}
1238

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

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

    
1251
	$request_params = cdm_dataportal_search_form_request();
1252
	$taxonPager = cdm_ws_get(CDM_WS_FIND_TAXA, null, queryString($request_params));
1253

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

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

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

    
1306
/* ====================== other functions ====================== */
1307

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

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

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

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

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

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

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

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

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

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

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

    
1426
}
1427

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

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

    
1455
}
1456

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

    
1464
function _cdm_dataportal_acceptedByCurrentView($taxon){
1465

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

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

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

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

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

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

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

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

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

    
1520

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

    
1525
	$template = theme('get_nameRenderTemplate', $renderPath);
1526

    
1527
	if(!is_array($template)){
1528
		switch($renderPath){
1529
			case 'list_of_taxa':
1530
			case  'acceptedFor':
1531
			case 'taxon_page_synonymy':
1532
			case 'typedesignations':
1533
			case 'taxon_page_title':
1534
			case 'na': $template = array(
1535
          'namePart' => array('#uri'=>true),
1536
			//'authorshipPart' => true,
1537
			);
1538
			break;
1539
			case 'nar': $template = array(
1540
          'namePart' => array('#uri'=>true),
1541
			//'authorshipPart' => true,
1542
          'referencePart' => array('#uri'=>true),
1543
          'microreferencePart' => true,
1544
			);
1545
			break;
1546
			default: $template = array(
1547
          'namePart' => array('#uri'=>true),
1548
          'authorshipPart' => true,
1549
          'referencePart' => array('#uri'=>true),
1550
          'microreferencePart' => true,
1551
          'statusPart' => true,
1552
          'descriptionPart' => true
1553
			);
1554
		}
1555
	}
1556

    
1557
	if($nameLink && isset($template['nameAuthorPart']['#uri'])){
1558
		$template['nameAuthorPart']['#uri'] = $nameLink;
1559
	} else{
1560
		unset($template['nameAuthorPart']['#uri']);
1561
	}
1562

    
1563
	if($nameLink && isset($template['namePart']['#uri'])){
1564
		$template['namePart']['#uri'] = $nameLink;
1565
	} else{
1566
		unset($template['namePart']['#uri']);
1567
	}
1568

    
1569
	if($refenceLink && isset($template['referencePart']['#uri'])){
1570
		$template['referencePart']['#uri'] = $refenceLink;
1571
	}else{
1572
		unset($template['referencePart']['#uri']);
1573
	}
1574

    
1575
	return $template;
1576
}
1577

    
1578
function get_partDefinition($taxonNameType){
1579
	//TODO implement admin user interface to allow specify the partdefinitions for any type
1580
	//     preliminar solution: using themes
1581

    
1582
	$partdef = theme('get_partDefinition', $taxonNameType);
1583

    
1584
	if(!is_array($partdef)){
1585
		switch($taxonNameType){
1586
			case 'ZoologicalName': $partdef = array(
1587
        'namePart' => array(
1588
          'name' => true,
1589
			),
1590
        'referencePart' => array(
1591
          'authorTeam' => true
1592
			),
1593
        'microreferencePart' => array(
1594
          'microreference' => true,
1595
			),
1596
        'statusPart' => array(
1597
          'status' => true,
1598
			),
1599
        'descriptionPart' => array(
1600
          'description' => true,
1601
			),
1602
			);
1603
			break;
1604
			case 'BotanicalName': $partdef = array(
1605
        'namePart' => array(
1606
          'name' => true
1607
			),
1608
        'authorTeamPart' => array(
1609
          'authorTeam' => true,   
1610
			),
1611
        'referencePart' => array(
1612
          'reference' => true      
1613
			),
1614
        'microreferencePart' => array(
1615
          'microreference' => true,
1616
			),
1617
        'statusPart' => array(
1618
          'status' => true,
1619
			),
1620
        'descriptionPart' => array(
1621
          'description' => true,
1622
			),
1623
			);
1624
			break;
1625
			default: $partdef = array(
1626
        'namePart' => array(
1627
          'name' => true,
1628
			),
1629
        'authorTeamPart' => array(
1630
          'authorTeam' => true,   
1631
			),
1632
        'referencePart' => array(
1633
          'reference' => true      
1634
			),
1635
        'microreferencePart' => array(
1636
          'microreference' => true,
1637
			),
1638
        'statusPart' => array(
1639
          'status' => true,
1640
			),
1641
        'descriptionPart' => array(
1642
          'description' => true,
1643
			),
1644
			);
1645
		}
1646
	}
1647
	return $partdef;
1648
}
1649

    
1650
/**
1651
 * The function read the metadata info such title or artist of a media file. The
1652
 * function tries at first to get all the info from the file metadata and if it is
1653
 * not avaible look at the media file info stored at the database.
1654
 * @param $media The media file
1655
 * @return array The array with the avilable specified metadata info.
1656
 * TODO rename to read_media_metadata() and move to *.module
1657
 */
1658
function cdm_read_media_metadata($media){
1659

    
1660
	$metadata_caption = array('title' => '',           //media_metadata and media
1661
                              'artist' => '',          //media_metadata and media
1662
                              'rights',                //media_metadata and media
1663
                              'location',              //media_metadata
1664
                              'filename' => '',        //media
1665
                              'mediacreated' => '',    //media
1666
                              'description' => '');    //media
1667

    
1668
	//getting the media metadata
1669
	$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
1670

    
1671
	//title
1672
	//if ($media_metadata->Headline) {
1673
	if ($media_metadata->ObjectName) {
1674
		$metadata_caption['title'] = $media_metadata->ObjectName;
1675
		//	} else if ($media->titleCache){
1676
		//		$metadata_caption['title'] = $media_metadata->ObjectName;
1677
	} else if ($media->titleCache){
1678
		$metadata_caption['title'] = $media->titleCache;
1679
		if ($media->description_L10n)
1680
		$metadata_caption['title'] .= ' - ' . $media->description_L10n;
1681
	}else{ //if there is no title on the db and metadata get file title
1682
    $aux = $media->representations[0]->parts[0]->uri;
1683
    $aux = explode("/", $aux);
1684
    $aux = end($aux);
1685
		$metadata_caption['title'] = $aux;		
1686
	}
1687

    
1688
	//artist
1689
	if ($media_metadata->Artist){
1690
	 $metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
1691
	}
1692
	elseif ($media->artist->titleCache){
1693
	 $metadata_caption['artist'] = $media->artist->titleCache;
1694
	}
1695
	
1696
	//copyright
1697
	$metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
1698
                                      'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
1699
	if ($media_metadata->Copyright)
1700
	$metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
1701
	elseif ($media->rights){
1702
		foreach($media->rights as $right){
1703
			switch($right->term->uuid){
1704
				case UUID_RIGHTS_LICENCE:
1705
					$metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
1706
					$metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
1707
					$metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
1708
					$metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
1709
					break;
1710
				case UUID_RIGHTS_COPYRIGHT:
1711
					$metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
1712
					break;
1713
			}
1714
		}
1715
	}
1716
	else
1717
	$metadata_caption['rights']['agentNames'][] = '';
1718

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

    
1722
	//location
1723
	$metadata_caption['location'] = array();
1724
	$metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
1725
	$metadata_caption['location']['city'] = $media_metadata->City;
1726
	$metadata_caption['location']['province'] = $media_metadata->Province;
1727
	$metadata_caption['location']['country'] = $media_metadata->Country;
1728

    
1729
	//filename
1730
	if(isset($media->representations[0]->parts[0]->uri)){
1731
		$fileUri = $media->representations[0]->parts[0]->uri;
1732
		$filename = substr($fileUri, strrpos($fileUri, "/")+1);
1733
		$metadata_caption['filename'] = $filename;
1734
	}
1735
	else{
1736
	 $metadata_caption['filename'] = '';
1737
	}
1738
	/*
1739
	 //creation date
1740
	 if($media_metadata["Modify Date"])
1741
	 $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
1742
	 else
1743
	 $metadata_caption['mediacreated'] = $media->created;
1744
	 */
1745
	//returned value
1746
	return $metadata_caption;
1747
}
1748

    
1749
/**
1750
 * This function collects all the media from a list of description elements
1751
 * and return them as an Array.
1752
 *
1753
 * @param $descriptionElementes The description elements
1754
 * @return Array The output with all the media
1755
 */
1756
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
1757
	//variables
1758
	$outArrayOfMedia = array(); //return value
1759
	//implementation
1760
	foreach($descriptionElements as $descriptionElement){
1761
		foreach($descriptionElement->media as $media){
1762
			if(isset($media)){
1763
			 $outArrayOfMedia[] = $media;
1764
			}
1765
	 }
1766
	}
1767
	return $outArrayOfMedia;
1768
}
1769

    
1770

    
(5-5/9)