Project

General

Profile

Download (60.7 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
require_once('settings.php');
18
require_once('help.php');
19

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

    
29
require_once('classes/footnotemanager.php');
30
require_once('classes/footnote.php');
31
require_once('classes/footnotekey.php');
32
require_once('classes/renderhints.php');
33

    
34
function _add_js_progressbar(){
35
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.progressbar/js/jquery.progressbar.js');
36
}
37

    
38
function _add_js_treeselector(){
39
  //drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
40
  drupal_add_js("
41
    if (Drupal.jsEnabled) {
42
      $(document).ready(function() {
43
          $('#cdm-taxonomictree-selector-form #edit-val').change(function () {
44
              $('#cdm-taxonomictree-selector-form').submit();
45
          });
46

    
47
      });
48
    }", 'inline');
49
}
50

    
51
function _add_js_openlayers_map(){
52

    
53
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
54
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/openlayers_map.js');
55

    
56
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
57

    
58
  $baseLayers = variable_get('baselayers', array());
59
  if(!is_array($baseLayers) || count($baseLayers) == 0){
60
    $baseLayers = array('metacarta_vmap0' => 'Metacarta Vmap0', 'PREFERRED' => 'metacarta_vmap0');
61
  }
62
  $layerNames = '';
63
  foreach($baseLayers as $layerName => $layerLabel){
64
    if($layerName == 'PREFERRED'){
65
      $preferredLayer = $baseLayers['PREFERRED'];
66
    } else {
67
      $layerNames .= ($layerNames ? ', ': '') . "'$layerName'";
68
    }
69
  }
70

    
71
  if( isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb']) ){
72
    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>');
73
    drupal_set_html_head('<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" type="text/javascript"></script>');
74
  }
75

    
76
  drupal_add_js("
77
        if (Drupal.jsEnabled) {
78
          $(document).ready(function() {
79
              $('#openlayers_map').cdm_openlayers_map('"
80
              .getEDITMapServiceURI()."', {
81
                legendPosition: 3,
82
                displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', false) . "',
83
                boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', false) . "',
84
                distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "',
85
                legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "',
86
                showLayerSwitcher: " . (variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE) ? 'true':'false') . ",
87
                baseLayerNames: [".$layerNames."],
88
                defaultBaseLayerName: '".$preferredLayer."',
89
            });
90
          });
91
        }", 'inline');
92

    
93
}
94

    
95
/**
96
 *
97
 * Enter description here ...
98
 * @param unknown_type $width
99
 * @param unknown_type $occurrenceQuery
100
 * @param unknown_type $distributionQuery
101
 * @param unknown_type $legendFormatQuery
102
 * @param unknown_type $map_caption
103
 */
104
function get_image_map($width,  $bounding_box=false, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false ){
105

    
106
  $server = getEDITMapServiceURI();
107

    
108
  if(!$server){
109
    //warning message
110
    drupal_set_message('No \'Geoservice Access Point\' has been set so far. '
111
    . 'Please configure the variable \'Geoservice Access Point\' here '
112
    . l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/geo'), 'warning');
113
    //message to render
114
    return "<p>No geoservice specified</p>";
115
  }
116

    
117
  // additional query parameters as set in the data portal admin section
118
  $labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
119

    
120
  $query_string .= '&image=true&recalculate=false&legend=1&ms=' . $width
121
    . ($bounding_box ? '&bbox=' .  $bounding_box : '')
122
    . ($labels_on ? '&label=' .  $labels_on : '');
123

    
124
  if($map_caption){
125
    $query_string .= '&mlp=3&mc_s=Georgia,15,blue&mc=' . $map_caption;
126
  }
127

    
128
  if (getEDITMapServiceVersionNumber() >= 1.1) {
129

    
130
    // either occurrence or distribution - combined maps will be possible in future
131
    if ($occurrenceQuery){
132

    
133
      //fix $occurrenceQuery
134
      $occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
135
      //$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
136
      $occurrenceQuery .= '&l=tdwg4&as='; // will be replaced below // HACK!!!
137
      $query_string .= "&" .$occurrenceQuery;
138

    
139
    } else if($distributionQuery){
140

    
141
      $query_string .= "&" .$distributionQuery;
142

    
143
    }
144

    
145
    //  apply Plain Image map settings special for version >= 1.1
146
    /*
147
     * example : title=a:Naturalized++non-invasive
148
    * &ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4
149
    * &ms=500&bbox=32,34,35,36&img=true&legend=1&mlp=3
150
    * &mc_s=Georgia,15,blue&mc=&recalculate=false
151
    *
152
    * http://edit.br.fgov.be/edit_wp5/v1/rest_gen.php?
153
    * l=background_gis:b,cyprusdivs&ad=cyprusdivs%3Abdcode%3Aa%3A8%2C4
154
    * &as=a%3A339966%2C%2C0.1%2C|b:0000ff,,
155
    * &bbox=32%2C34%2C35%2C36&img=true&legend=1&mc=&mc_s=Georgia%2C15%2Cblue
156
    * &mlp=3&ms=500&recalculate=false&title=a%3Aindigenous
157
    */
158

    
159
    $map_service_script_name = "rest_gen.php";
160

    
161
    $bgcolor_areaStyleId= "y";
162
    $baselayer_areaStyleId= "z";
163
    $bgcolor_layer='';
164
    $additional_area_styles = array();
165

    
166
    // background color:
167
    if(variable_get('map_bg_color', '')){
168
      $bgcolor_layer = "background_gis:".$bgcolor_areaStyleId;
169
      $additional_area_styles[] = $bgcolor_areaStyleId . ":" . variable_get('map_bg_color', '') . ",,";
170
    }
171

    
172
    //TODO HACK to replace the default base layer which currently is tdwg4 !!! only needed for distribution maps
173
    if(strpos($query_string, "?l=") !== FALSE){
174
      $layer_param_token = "?l=";
175
    } else {
176
      $layer_param_token = "&l=";
177
    }
178
    if(strpos($query_string, "?as=") !== FALSE){
179
      $areystyle_param_token = "?as=";
180
    } else {
181
      $areystyle_param_token = "&as=";
182
    }
183
    if(variable_get('map_base_layer', '')){
184
      $query_string = str_replace($layer_param_token."tdwg4", "$layer_param_token".variable_get('map_base_layer', ''). ":" . $baselayer_areaStyleId, $query_string);
185
    } else {
186
      $query_string = str_replace($layer_param_token."tdwg4", $layer_param_token."tdwg4:".$baselayer_areaStyleId . ",", $query_string);
187
    }
188

    
189
    if($bgcolor_layer){
190
      $query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string);
191
    }
192

    
193
    if(variable_get('map_base_layer_style', '')){
194
      $additional_area_styles[] = $baselayer_areaStyleId . ":" . variable_get('map_base_layer_style', '');
195
    }
196

    
197
    foreach ($additional_area_styles as $as) {
198
      $query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string);
199
    }
200

    
201
  } else {
202
    // pre 1.1. version of map service
203
    if ($occurrenceQuery){
204

    
205
      $map_service_script_name = "point.php";
206

    
207
      //fix $occurrenceQuery
208
      $occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
209
      //$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
210
      $occurrenceQuery .= '&l=v:e_w_0';
211
      $query_string .= "&" .$occurrenceQuery;
212

    
213
    } else if($distributionQuery){
214

    
215
      $query_string .= "&" .$distributionQuery;
216
      $map_service_script_name = "areas.php";
217

    
218
    }
219

    
220
  }
221

    
222
  $mapUri = url("$server/$map_service_script_name?$query_string");
223
  $out = '<img class="distribution_map" src="' . $mapUri . '" alt="Map" />';
224
  // showing map caption
225
  if($map_caption){
226
    $out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; //FIXME: replace <br> by according css style
227
    $out .= '</div>';
228
  }
229

    
230
  return $out;
231

    
232

    
233
}
234

    
235
/**
236
 *
237
 * Enter description here ...
238
 * @param unknown_type $width
239
 * @param unknown_type $occurrenceQuery
240
 * @param unknown_type $distributionQuery
241
 * @param unknown_type $legendFormatQuery
242
 * @param unknown_type $map_caption
243
 */
244
function get_openlayers_map($width, $bounding_box=false, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false ){
245

    
246
  _add_js_openlayers_map();
247

    
248
  $out = '<div id="openlayers">';
249
  $out .= '<div id="openlayers_map" class="smallmap"';
250
  $out .= ' style="width: ' . $width . 'px; height:'.( $width / 2).'px"';
251

    
252
  // additional query parameters as set in the data portal admin section
253
  $labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
254

    
255
  $openlayers_map_query_string .= '&img=false&ms=' . $width
256
    . ($bounding_box ? '&bbox=' .  $bounding_box : '')
257
    . ($labels_on ? '&label=' .  $labels_on : '');
258

    
259
  if($occurrenceQuery){
260
    //fix $occurrenceQuery
261
    $occurrenceQuery .= '&bbox=-180,-90,180,90';
262
    $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
263
    //$occurrenceQuery .= '&l=v:e_w_0';
264
    $occurrenceQuery .= '&legend=0'; //TODO add to cdm service?
265

    
266
    $out .= ' occurrenceQuery="' . $occurrenceQuery . '&' . $openlayers_map_query_string . '"';
267
  }
268

    
269
  if($distributionQuery){
270
    $out .= ' distributionQuery="' . $distributionQuery . '&' . $openlayers_map_query_string . '"';
271
  }
272

    
273
  if($legendFormatQuery){
274
    $out .= ' legendFormatQuery="'.$legendFormatQuery.'"';
275
  }
276

    
277
  $out .= '></div></div>';
278

    
279
  // showing map caption
280
  if($map_caption){
281
    $out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; //FIXME: replace <br> by according css style
282
    $out .= '</div>';
283
  }
284
  return $out;
285
}
286

    
287
/* ====================== hook implementations ====================== */
288

    
289

    
290
/**
291
 * Implementation of hook_perm()
292
 *
293
 * Valid permissions for this module
294
 * @return array An array of valid permissions for the portfolio module
295
 */
296
function cdm_dataportal_perm() {
297
  return array(
298
      'administer cdm_dataportal',
299
      'cdm_dataportal view notes',
300
  //TODO which else permission are required? -> check the WP6 requirements document
301
  );
302
}
303

    
304

    
305
/**
306
 * Implementation of hook_menu()
307
 */
308
function cdm_dataportal_menu($may_cache) {
309
  $items = array();
310

    
311
  cdm_dataportal_menu_admin($may_cache, $items);
312
  cdm_dataportal_menu_help($may_cache, $items);
313

    
314
  if ($may_cache) {
315

    
316
   $items[] = array(
317
      'path' => 'cdm_dataportal/names',
318
      'callback' => 'cdm_dataportal_view_names',
319
      'access' => true,
320
      'type' => MENU_CALLBACK,
321
    );
322
    // optional callback arguments: page
323

    
324
    $items[] = array(
325
      'path' => 'cdm_dataportal/taxon',
326
      'callback' => 'cdm_dataportal_taxon_page_view',
327
      'access' => true,
328
      'type' => MENU_CALLBACK,
329
    // expected callback arguments: uuid
330
    );
331

    
332
    $items[] = array(
333
      'path' => 'cdm_dataportal/name',
334
      'callback' => 'cdm_dataportal_name_page_view',
335
      'access' => true,
336
      'type' => MENU_CALLBACK,
337
    // expected callback arguments: uuid
338
    );
339

    
340
    $items[] = array(
341
      'path' => 'cdm_dataportal/reference',
342
      'callback' => 'cdm_dataportal_view_reference',
343
      'access' => true,
344
      'type' => MENU_CALLBACK,
345
    // expected callback arguments: uuid
346
    );
347

    
348
    $items[] = array(
349
      'path' => 'cdm_dataportal/reference/list',
350
      'callback' => 'cdm_dataportal_view_reference_list',
351
      'access' => true,
352
      'type' => MENU_CALLBACK,
353
    // expected callback arguments: uuid
354
    );
355

    
356
    $items[] = array(
357
      'path' => 'cdm_dataportal/media',
358
      'callback' => 'cdm_dataportal_view_media',
359
      'access' => true,
360
      'type' => MENU_CALLBACK,
361
    // expected callback arguments: uuid, mediarepresentation_uuid, part_uuid or part#
362
    );
363

    
364
    $items[] = array(
365
      'path' => 'cdm_dataportal/polytomousKey',
366
      'callback' => 'cdm_dataportal_view_polytomousKey',
367
      'access' => true,
368
      'type' => MENU_CALLBACK,
369
    // expected callback arguments: polytomousKey->uuid
370
    );
371

    
372
    $items[] = array(
373
      'path' => 'cdm_dataportal/search',
374
      'callback' => 'cdm_dataportal_view_search_advanced',
375
      'access' => true,
376
      'type' => MENU_CALLBACK,
377
    );
378

    
379
    $items[] = array(
380
      'path' => 'cdm_dataportal/search/taxon',
381
      'callback' => 'cdm_dataportal_view_search_taxon',
382
      'access' => true,
383
      'type' => MENU_CALLBACK,
384
    );
385

    
386
    $items[] = array(
387
      'path' => 'cdm/xml2json',
388
      'callback' => 'cdm_view_xml2json',
389
      'access' => true,
390
      'type' => MENU_CALLBACK,
391
    );
392

    
393
  }elseif (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid)) {
394
    //user configuration of cdm_dataportal
395
    $items[] = array('path' => 'user/'.$uid.'/cdm_dataportal',
396
        'title' => t('cdm_dataportal'),
397
        'access' => TRUE,
398
        'callback' => 'drupal_get_form',
399
        'callback arguments' => array('cdm_dataportal_user_form'),
400
        'type' => MENU_LOCAL_TASK,
401
        'weight' => 10,
402
      );
403
  } else {
404
    // may not cache
405
    // --- local tasks for Taxon
406
    $items[] = array(
407
      'path' => 'cdm_dataportal/name/'.arg(2),
408
    //'callback' => 'cdm_dataportal_view_name',
409
      'callback' => 'cdm_dataportal_name_page_view',
410
      'callback arguments' => array(arg(2), arg(3), arg(4)),
411
      'access' => true,
412
      'type' => MENU_CALLBACK,
413
    );
414

    
415
    if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
416

    
417
      $items[] = array(
418
      'path' => 'cdm_dataportal/taxon/'.arg(2),
419
      'title' => theme('cdm_taxonpage_tab', 'General'),
420
      'callback' => 'cdm_dataportal_taxon_page_view',
421
      'access' => true,
422
      'type' => MENU_CALLBACK,
423
      'weight' => 1,
424
      'callback arguments' => array(arg(2), "description")
425
      // expected callback arguments: name_uuid
426
      );
427

    
428
      $items[] = array(
429
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/all',
430
      'title' => theme('cdm_taxonpage_tab', 'General'),
431
      'callback' => 'cdm_dataportal_taxon_page_view',
432
      'access' => true,
433
      'type' => MENU_CALLBACK,
434
      'weight' => 2,
435
      'callback arguments' => array(arg(2), "all")
436
      // expected callback arguments: name_uuid
437
      );
438

    
439
      $items[] = array(
440
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/description',
441
      'title' => theme('cdm_taxonpage_tab', 'General'),
442
      'callback' => 'cdm_dataportal_taxon_page_view',
443
      'access' => true,
444
      'type' => MENU_DEFAULT_LOCAL_TASK,
445
      'weight' => 2,
446
      'callback arguments' => array(arg(2), "description")
447
      // expected callback arguments: name_uuid
448
      );
449

    
450
      $items[] = array(
451
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/synonymy',
452
      'title' => theme('cdm_taxonpage_tab', 'Synonymy'),
453
      'callback' => 'cdm_dataportal_taxon_page_view',
454
      'access' => true,
455
      'type' => MENU_LOCAL_TASK,
456
      'weight' => 4,
457
      'callback arguments' => array(arg(2), "synonymy", arg(4))
458
      // expected callback arguments: name_uuid
459
      );
460
      $items[] = array(
461
      'path' => 'cdm_dataportal/taxon/'.arg(2).'/images',
462
      'title' => theme('cdm_taxonpage_tab', 'Images'),
463
      'callback' => 'cdm_dataportal_taxon_page_view',
464
      'access' => true,
465
      'type' => MENU_LOCAL_TASK,
466
      'weight' => 5,
467
      'callback arguments' => array(arg(2), "images")
468
      // expected callback arguments: name_uuid
469
      );
470

    
471
     $items[] = array(
472
     'path' => 'cdm_dataportal/taxon/'.arg(2).'/specimens',
473
     'title' => theme('cdm_taxonpage_tab', 'Specimens'),
474
     'callback' => 'cdm_dataportal_taxon_page_view',
475
     'access' => true,
476
     'type' => MENU_LOCAL_TASK,
477
     'weight' => 6,
478
     'callback arguments' => array(arg(2), "specimens")
479
     // expected callback arguments: name_uuid
480
     );
481

    
482
     $items[] = array(
483
     'path' => 'cdm_dataportal/taxon/'.arg(2).'/keys',
484
     'title' => theme('cdm_taxonpage_tab', 'Keys'),
485
     'callback' => 'cdm_dataportal_taxon_page_view',
486
     'access' => true,
487
     'type' => MENU_LOCAL_TASK,
488
     'weight' => 6,
489
     'callback arguments' => array(arg(2), "keys")
490
     // expected callback arguments: name_uuid
491
     );
492
    }
493
  }
494

    
495
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
496
  //drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
497
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
498

    
499
  return $items;
500

    
501
}
502
/**
503
 * The function generate form for own user cdm dataportal configurations
504
 */
505
function cdm_dataportal_user_form() {
506

    
507
  global $user;
508
    $checkbox_value = 'cdm_dataportal_' .$user->uid . '_default_tab_active';
509

    
510
  $form['check'] = array
511
    (
512
    '#type'            => 'checkbox',
513
    '#title'         => t('Activate user default configuration'),
514
    '#default_value'   => variable_get($checkbox_value, 0),
515
    '#description' => t('Check this if you want configure your own default tab from the below menu.')
516
    );
517

    
518
  $form['cdm_dataportal_user_form'] =  array(
519
      '#type'          => 'select',
520
      '#title'         => t('Default tab to display'),
521
      '#default_value' => get_default_taxon_tab(true),
522
      '#options'       => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
523
      '#description'   => t('<p>Select the default tab to display when visiting a taxon page. Only available if Tabbed Taxon Page is enable.</p>
524
              <strong>Note:</strong> After performing a search and clicking in any synonym, the taxon tab
525
              to be renderized will be the synonymy of the accepted taxon and not the above selected tab.'),
526
  );
527

    
528
  $form['submit'] = array(
529
    '#type' => 'submit',
530
    '#value' => t('Submit')
531
  );
532

    
533
  return $form;
534
}
535

    
536
/**
537
 * The function submit the user cdm dataportal configurations
538
 * @param unknown_type $form
539
 * @param unknown_type $form_values
540
 */
541
function cdm_dataportal_user_form_submit($form, $form_values) {
542
  global $user;
543
  $msg_type = 'status';
544
  $username = $user->name;
545
  $variable_to_use = 'cdm_dataportal_' .$user->uid . '_default_tab';
546

    
547
  //if is the right user the variables are setted
548
  if (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid) && $user->uid==$uid){
549
    $variable = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
550
    variable_set($variable_to_use . '_active', $form_values['check']);
551
    variable_set($variable_to_use, $form_values['cdm_dataportal_user_form']);
552
    if ($form_values['check']){
553
      drupal_set_message('The user default tab will be used for the next taxon site visit.');
554
      drupal_set_message('The user default tab have been changed to: '
555
            . $variable[variable_get($variable_to_use, 0)]
556
            . ' for the user ' . $username, $msg_type);
557
    }else{
558
      drupal_set_message('The user default tab wont be used for the next taxon site, check the box if you want to use the user default configuration.');
559
    }
560
  //problem with the user id => variables wont be saved
561
  }else{
562
    $msg_type = 'warning';
563
    drupal_set_message('Default tab have not been saved due to user id problems', $msg_type);
564
  }
565
}
566

    
567
/**
568
 * Implementation of hook_block()
569
 *
570
 * Provides the following blocks:
571
 *  0: list of links useful during development
572
 *
573
 * @param String $op
574
 * @param int $delta
575
 */
576
function cdm_dataportal_block($op='list', $delta=0) {
577
  // listing of blocks, such as on the admin/block page
578
  if ($op == "list") {
579
    //$block[0]["info"] = t("CDM DataPortal DevLinks");
580
    //$block[1]["info"] = t("CDM DataPortal Credits");
581
    $block[2]["info"] = t("CDM Search Taxa");
582
    //$block[3]["info"] = t("CDM Filters");
583
    $block[4]["info"] = t("CDM Dataportal Print");
584
    $block["keys"]["info"] = t("CDM identification keys");
585
    return $block;
586
  }
587
  else if ($op == 'view') {
588
    switch($delta){
589
      //			case 1:
590
      //				$block['subject'] = t('Credits');
591
      //				$block['content'] = theme('cdm_credits');
592
      //				return $block;
593
      case 2:
594
        $block['subject'] = t('Search taxa');
595
        $block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
596
        if (variable_get('cdm_dataportal_show_advanced_search', 1)){
597
            $block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
598
        }
599
        return $block;
600
      case 4:
601
        $block['subject'] = t('<none>');
602
        $block['content'] = theme('cdm_print_button');;
603
        return $block;
604
      case "keys":
605
        $block['subject'] = t('Identification Keys');
606
        $block['content'] = theme('cdm_block_IdentificationKeys');
607
        return $block;
608
    }
609
  }
610
}
611

    
612

    
613

    
614
/*
615
 function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
616
 $_SESSION['cdm'] = null;
617
 if(is_string($cdm_ws_uri_update)){
618
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
619
 }
620
 }
621

    
622
 function cdm_dataportal_session_validate(){
623

    
624
 if(!isset($_SESSION['cdm']['ws_uri'])){
625
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
626
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
627
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
628
 }
629
 }
630
 */
631

    
632
function cdm_dataportal_search_taxon_form($advancedForm = false){
633

    
634
  $preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
635
  $preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
636
  $preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
637
  $preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
638
  $tdwg_level_select =  (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
639
  $selected_areas =  (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
640

    
641
  $url = 'cdm_dataportal/search/taxon';
642
  $form['#method'] = 'get';
643
  $form['#process'] = array('cdm_dataportal_search_process' => array());
644
  $form['#action'] = url($url, NULL, NULL, true);
645

    
646
  $form['query'] = array(
647
    '#delta' => 0,
648
    '#type' => 'textfield',
649
    '#size' => 20,
650
    '#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')),
651
    '#value' => $preset_query,
652
  );
653

    
654
  $form['search'] = array(
655
      '#delta' => 1,
656
      '#tree' => true,
657
  //'#type' => $advancedForm ? 'fieldset': 'hidden',
658
      '#title' => t('Options')
659
  );
660

    
661
  $form['search']['tree'] = array(
662
    '#delta' => -1,
663
    '#type' => 'hidden',
664
    '#value' => get_taxonomictree_uuid_selected()
665
  );
666

    
667

    
668
  // clean URL get forms breaks if we don't give it a 'q'.
669
  if (!(bool)variable_get('clean_url', '0')) {
670
    $form['search']['q'] = array(
671
      '#delta' => -1,
672
      '#type' => 'hidden',
673
      '#value' => $url,
674
      '#name' => 'q',
675
    );
676
  }
677

    
678
  $form['search']['pageSize'] = array(
679
      '#delta' => -1,
680
      '#type' => 'hidden',
681
      '#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
682
  );
683

    
684
  $form['search']['pageNumber'] = array(
685
      '#delta' => -1,
686
      '#type' => 'hidden',
687
      '#value' => 0
688
  );
689

    
690
  if($advancedForm){
691
    // general search parameters
692
    $form['search']['doTaxa'] = array(
693
      '#delta' => 2,
694
      '#type' => 'checkbox',
695
      '#title' => t('Search for accepted taxa'),
696
      '#value' => $preset_doTaxa
697
    );
698
    $form['search']['doSynonyms'] = array(
699
      '#delta' => 3,
700
      '#type' => 'checkbox',
701
      '#title' => t('Search for synonyms'),
702
      '#value' => $preset_doSynonyms
703
    );
704
    $form['search']['doTaxaByCommonNames'] = array(
705
      '#delta' => 4,
706
      '#type' => 'checkbox',
707
      '#title' => t('Search for common names'),
708
      '#value' => $preset_doTaxaByCommonNames
709
    );
710

    
711
    // Geographic Range
712
    $form['search']['geographic_range'] = array(
713
      '#type' => 'fieldset',
714
      '#delta' => 5,
715
      '#tree' => true,
716
      '#title' => t('Geographic range'),
717
    );
718

    
719
    $form['search']['geographic_range']['tdwg_level_select'] = array(
720
    '#type' => 'radios',
721
    '#title' => t('Select a TDWG distribution level and code'),
722
    '#default_value' => $tdwg_level_select,
723
    '#options' => array(
724
    t('TDWG level-1, i.e. a continent'),
725
    t('TDWG level-2'),
726
    t('TDWG level-3, i.e. a country'),
727
    t('TDWG level-4')
728
    )
729
    );
730
    $tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
731
    $tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
732
    $tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
733
    $tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
734

    
735
    $tdwg_js = '';
736
    foreach($tdwg as $key=>$tdwg_level){
737
      $tdwgOptions = array();
738
      $tdwgOptionsSelected = array();
739
      foreach($tdwg_level as $area){
740
        $representation = $area->representations[0];
741
        $tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
742
        if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
743
          $tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
744
        }
745
      }
746
      asort($tdwgOptions);
747
      $form['search']['geographic_range']['tdwg_level_'.$key] = array(
748
        '#type' => 'select',
749
        '#title'         => t('TDWG level').' '.$key,
750
        '#default_value' => $tdwgOptionsSelected,
751
        '#multiple' => TRUE,
752
        '#options' => $tdwgOptions
753
      );
754
      $tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ?  '.show()' : '.hide()'). ";\n";
755
    }
756

    
757
    drupal_add_js(
758
    "$(document).ready(function(){
759

    
760
      $(\"input[@name='search[geographic_range][tdwg_level_select]']\").change(
761
        function(event){
762
          var selectId = $(\"input[@name='search[geographic_range][tdwg_level_select]']:checked\").val();
763
          var i;
764
          for(i = 0; i < 4; i++){
765
            if(selectId == i){
766
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1) ).parent().fadeIn('slow');
767
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
768
            } else {
769
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).parent().fadeOut('slow');
770
              $('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
771
            }
772
          }
773
        }
774
      );
775

    
776
      $tdwg_js
777
    });",
778
    'inline');
779

    
780
  } else {
781
    $form['search']['doTaxa'] = array(
782
        '#delta' => -2,
783
        '#type' => 'hidden',
784
        '#value' => 1
785
    );
786
    $form['search']['doSynonyms'] = array(
787
        '#delta' => -3,
788
        '#type' => 'hidden',
789
        '#value' => 1
790
    );
791
    $form['search']['doTaxaByCommonNames'] = array(
792
        '#delta' => -4,
793
        '#type' => 'hidden',
794
        '#value' => 0
795
    );
796
  }
797

    
798
  $form['submit'] = array(
799
    '#delta' => 9,
800
    '#type' => 'submit',
801
    '#name' => '',
802
    '#value' => t('Search')
803
  );
804

    
805
  return $form;
806
}
807

    
808
function cdm_dataportal_search_taxon_form_advanced(){
809
  return cdm_dataportal_search_taxon_form(true);
810
}
811

    
812
function cdm_taxonomictree_selector(){
813
  _add_js_treeselector();
814

    
815
  $out = drupal_get_form('cdm_taxonomictree_selector_form');
816

    
817
  return $out;
818
}
819

    
820

    
821
function cdm_taxonomictree_selector_form(){
822

    
823
  $url = url('cdm_api/setvalue/session', null);
824
  $form['#action'] = $url;
825

    
826
  $form['var'] = array(
827
        '#delta' => -3,
828
        '#type' => 'hidden',
829
        '#value' => '[cdm][taxonomictree_uuid]'
830
        );
831

    
832
        $form['destination'] = array(
833
     '#delta' => -3,
834
     '#type' => 'hidden',
835
     '#value' => substr(drupal_get_destination(), strlen('destination='))
836
        );
837

    
838
        $form['val'] = array(
839
      '#type' => 'select',
840
      '#title'         => t('Available classifications'),
841
      '#default_value' => get_taxonomictree_uuid_selected(),
842
      '#options' => cdm_get_taxontrees_as_options()
843
        );
844

    
845
        return $form;
846

    
847
}
848

    
849
/**
850
 * Implementation #process method call, see form_builder()
851
 * <p>
852
 * Removes Drupal internal form elements from query
853
 * @param $form
854
 * @return unknown_type
855
 */
856
function cdm_dataportal_search_process($form) {
857
  unset($form['form_id']);
858
  unset($form['form_token']);
859
  return $form;
860
}
861

    
862
/**
863
 * Filters $_REQUEST by a list of valid request  parameters and also sets defaults if required.
864
 * returns the processed request parameters submitted by the search form.
865
 */
866
function cdm_dataportal_search_form_request(){
867

    
868

    
869
  $form_params = array();
870
  array_deep_copy($_REQUEST['search'], $form_params);
871
  $form_params['query'] =  trim($_REQUEST['query']);
872

    
873
  // split of  geographic range
874
  if(isset($_REQUEST['search']['geographic_range'])){
875
    $geographicRange = $_REQUEST['search']['geographic_range'];
876
    // remove
877
    unset($form_params['geographic_range']);
878
  }
879

    
880
  // add geographic range
881
  if($geographicRange){
882
    $form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
883
    for($i = 1; $i < 5; $i++){
884
      if(isset($geographicRange['tdwg_level_'.$i])){
885
        $form_params['area'] = $geographicRange['tdwg_level_'.$i];
886
      }
887
    }
888
  }
889

    
890
  // store in session
891
  $_SESSION['cdm']['search'] = $form_params;
892

    
893
  return $form_params;
894
}
895

    
896

    
897
/* UNREACHABLE since action of form directly links to view
898
 function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
899

    
900
 $_SESSION['cdm']['search'] = $form_values;
901
 //return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
902
 return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
903
 //$paramstr = compose_url_prameterstr($form_values);
904
 //return url('/cdm_dataportal/search/taxon/', $paramstr);
905
 }
906
 */
907
/* ====================== menu callback functions ====================== */
908

    
909

    
910

    
911
function cdm_dataportal_form_alter($form_id, &$form) {
912

    
913
  static $comment_node_disabled =  0;
914
  static $comment_node_read_only =  1;
915
  static $comment_node_read_write =  2;
916

    
917

    
918
  if ($form_id == 'node_type_form'
919
  && isset($form['identity']['type'])
920
  && array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
921
  ) {
922
    $form['workflow']['comment'] = array(
923
      '#type' => 'radios',
924
      '#title' => t('Default comment setting'),
925
      '#default_value' => variable_get('comment_'. $form['#node_type']->type, $comment_node_disabled),
926
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
927
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
928
    );
929
  }
930
}
931

    
932

    
933

    
934
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed, $form_description = ''){
935
//TODO move into settings.php
936
  $form[$form_name] = array(
937
    '#type' => 'fieldset',
938
    '#title' => t($form_tittle),
939
    '#collapsible' => TRUE,
940
    '#collapsed' => $collapsed,
941
    '#tree' => true,
942
  '#description' => t($form_description),
943
  );
944

    
945
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
946
  $gallery_settings = variable_get($form_name, $default_values);
947
  //$test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
948

    
949
  if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
950
    /* TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
951
     $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
952
     '#type' => 'textfield',
953
     '#title' => t('Search Page Size'),
954
     '#default_value' => $test,
955
     '#description' => t('Number of Names to display per page in search results.')
956
     );
957
     */
958
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
959
      '#type' => 'checkbox',
960
      '#title' => t('Show media thumbnails for accepted taxa'),
961
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
962
    );
963

    
964
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
965
      '#type' => 'checkbox',
966
      '#title' => t('Show media thumbnails for synonyms'),
967
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
968
      '#description' => t('')
969
    );
970
  }
971

    
972
  //$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
973
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
974
    '#type' => 'checkbox',
975
    '#title' => t('Show captions under thumbnails'),
976
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
977
    '#description' => t('')
978
  );
979

    
980
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
981
    '#type' => 'textfield',
982
    '#title' => t('Thumbnail size'),
983
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
984
    '#description' => t('Select the size of each individual thumbnail.')
985
  );
986

    
987
  if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
988
     $form[$form_name]['cdm_dataportal_media_cols'] = array(
989
        '#type' => 'textfield',
990
        '#title' => t('Number of columns'),
991
        '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
992
        '#description' => t('Group the thumbnails in columns: select how many columns should the gallery display.')
993
     );
994
  }
995

    
996
  if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
997
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
998
      '#type' => 'textfield',
999
      '#title' => t('Maximum number of rows'),
1000
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1001
      '#description' => t('You can group the thumbnails in rows, select in how many rows should be the thumbnails grouped.<br>
1002
                           <b>Note:</b> If you want an unlimited number of rows please set to 0')
1003
    );
1004
  }
1005

    
1006
  return $form;
1007
}
1008

    
1009

    
1010
/**
1011
 * Displays a list of the known taxonomic names. Long lists are split up into multiple pages
1012
 *
1013
 * TODO: parameters are still preliminar
1014
 * @param String $page page number to diplay defaults to page 1
1015
 * @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
1016
 */
1017
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
1018

    
1019
  $request_params  = array(
1020
    'q' => $beginsWith,
1021
  //'sec' = '',
1022
  //'higherTaxa' => getFiters(),
1023
  // 'matchAnywhere' => false, // default is false
1024
    'page' => $page,
1025
    'onlyAccepted' => $onlyAccepted,
1026
    'pagesize' => 20  /*$_SESSION['cdm']['namelist_pagesize'] */);
1027

    
1028
  $taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
1029
  /*
1030
   * FIXME the filter for accepted names will be a form element, thus this widget
1031
   * should be generated via form api preferably as block
1032
   */
1033
  //$out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1034
  //$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1035
  $out .= theme('cdm_listof_taxa', $taxonPager);
1036
  return $out;
1037
}
1038

    
1039
function cdm_dataportal_view_reference($uuid, $arg2 = null){
1040
  $reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1041
  return theme('cdm_reference_page', $reference);
1042
}
1043

    
1044
function cdm_dataportal_view_reference_list($pageNumber){
1045
  $referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
1046
  return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
1047
}
1048

    
1049
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
1050
  $media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1051
  return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
1052
}
1053

    
1054
function _load_taxonBase(&$taxonBase){
1055
  if(isset($taxonBase->uuid)){
1056
      $taxonBase->name = cdm_ws_get(CDM_WS_TAXON, array($taxonBase->uuid, "name"));
1057
      $taxonBase->name->taggedName = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "taggedName"));
1058
      $taxonBase->name->nomenclaturalReference = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalReference"));
1059
    }
1060
}
1061

    
1062
/**
1063
 * similar to the variable_get() function of Drupal, except of thst this function
1064
 * is able to handle arrays correctly. This function is especially useful
1065
 * when dealing with collections of setting form elemens (#tree = true)
1066
 *
1067
 * @param String $variableKey
1068
 * @param String $defaultValueString a sting as for example derived from a CONSTANT
1069
 * @return mixed, usually an array
1070
 */
1071
function mixed_variable_get($variableKey, $defaultValueString){
1072
    $systemDefaults = unserialize($defaultValueString);
1073
    $storedSettings = variable_get($variableKey, array());
1074
    if(is_array($storedSettings)){
1075
      $settings =  array_merge($systemDefaults, $storedSettings);
1076
    } else {
1077
      $settings = $systemDefaults;
1078
    }
1079
    return $settings;
1080
}
1081

    
1082
/**
1083
 * Loads the subgraph of the given PolytomousKeyNode recursively from the cdm REST service.
1084
 * @param PolytomousKeyNode $polytomousKeyNode passed by reference
1085
 * @return nothing
1086
 */
1087
function _load_polytomousKeySubGraph(&$polytomousKeyNode){
1088

    
1089
  if(!$polytomousKeyNode){
1090
    return;
1091
  }
1092
  if($polytomousKeyNode->class != "PolytomousKeyNode"){
1093
    drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
1094
    return;
1095
  }
1096
  if(!is_uuid($polytomousKeyNode->uuid)){
1097
    drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
1098
    return;
1099
  }
1100

    
1101
  $polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
1102

    
1103
  if(!$polytomousKeyNode){
1104
    //drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
1105
    return;
1106
  }
1107

    
1108
  // load children
1109
  foreach($polytomousKeyNode->children as &$childNode){
1110
    _load_polytomousKeySubGraph($childNode);
1111
  }
1112

    
1113
  // load subkey
1114
  $polytomousKeyNode->subkey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "subkey"));
1115

    
1116
  // load taxon
1117
  $polytomousKeyNode->taxon = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "taxon"));
1118
  _load_taxonBase($polytomousKeyNode->taxon);
1119
  return;
1120
}
1121

    
1122
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid){
1123
  $polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
1124

    
1125
  $sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "sources"));
1126
  if(is_array($sourcePager->records)){
1127
    $polytomousKey->sources =  $sourcePager->records;
1128
    //$polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "sources"));
1129
  }
1130

    
1131
  $annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "annotations"));
1132
  if(is_array($annotationPager->records)){
1133
    $polytomousKey->annotations = $annotationPager->records;
1134
  }
1135

    
1136
  _load_polytomousKeySubGraph($polytomousKey->root);
1137
  return theme('cdm_polytomousKey_page', $polytomousKey);
1138
}
1139

    
1140
/**
1141
 * The taxon page gives detailed information on a taxon, it shows:
1142
 *  - Taxon name
1143
 *  - Full list of synonyms homotypic synonyms on top, followed by the
1144
 *    heterotypic and finally followed by misapplied names.
1145
 *    The list is ordered historically.
1146
 *  - All description associated with the taxon.
1147
 *
1148
 * @param $uuid
1149
 * @param $chapter name of the part to display,
1150
 *         valid values are: 'description', 'images', 'synonymy', 'specimens', 'all'
1151
 * @return unknown_type
1152
 */
1153
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all', $synonym_uuid = null){
1154
  // display the page for the taxon defined by $uuid
1155
  set_last_taxon_page_tab(arg(3));
1156
  $taxonpage = cdm_dataportal_taxon_view($uuid, $chapter, $synonym_uuid);
1157
  return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
1158
}
1159

    
1160
/**
1161
 * @param $uuid
1162
 * @param $chapter name of the part to display,
1163
 *         valid values are: 'description', 'images', 'synonymy', 'all'
1164
 * @return unknown_type
1165
 */
1166
function cdm_dataportal_taxon_view($uuid, $chapter = 'all', $synonym_uuid = null){
1167
  $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1168
  if(!$taxon){
1169
    drupal_set_title(t('Taxon does not exist'));
1170
    return false;
1171
  }
1172

    
1173
  $taxonpage->title = theme('cdm_taxon_page_title', $taxon, $uuid, $synonym_uuid);
1174

    
1175
  // check if the taxon id contained in the currently selected tree
1176
  $taxon_in_current_tree = taxon_in_current_tree($uuid);
1177
  $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $uuid);
1178
  if(!$taxon_in_current_tree){
1179
    if(count($taxon_nodes) == 0){
1180
      drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained any classification.'
1181
      ,'warning');
1182
    } else {
1183
      $trees = '';
1184
      foreach($taxon_nodes as $node){
1185
        $trees .= ($trees?', ':'').'<strong>'.$node->classification->titleCache.'</strong>';
1186

    
1187
      }
1188
      drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained in the currently chosen classification, but in '
1189
      .(count($taxon_nodes) > 1? ' one of these: ' : ' this one: ') . $trees
1190
      , 'warning');
1191
    }
1192
  }
1193

    
1194
  // render the taxon page
1195
  $taxonpage->content = theme('cdm_taxon_page', $taxon, $chapter);
1196

    
1197
  return $taxonpage;
1198
}
1199

    
1200
/**
1201
 * The function returns a name page as a drupal node ready to be renderized by drupal.
1202
 * The node page show the taxon name title and the list of taxon related with such taxon
1203
 * name on the tree already in used.
1204
 * @param $taxon_name_uuid A taxon name uuid
1205
 * @return The formatted name page as node
1206
 */
1207
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
1208
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
1209
  return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
1210
}
1211

    
1212
/**
1213
 * The function genates a object ready to be transformated to a node
1214
 * in order to show as a drupal node
1215
 * @param $taxon_name_uuid
1216
 * @return the object with the page content and title
1217
 */
1218
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
1219
  //getting the full taxonname object from the server
1220
  $taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1221
  if(!$taxon_name){
1222
    drupal_set_title(t('Taxon name does not exist'));
1223
    return false;
1224
  }
1225
  //searching for all the taxa connected with the taxon name on the tree in used
1226
  $name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1227
  $request_params = array();
1228
  $request_params['query'] = $name_cache;
1229
  $request_params['tree'] = get_taxonomictree_uuid_selected();
1230
  $request_params['doTaxa'] = 1;
1231
  $request_params['doSynonyms'] = 1;
1232
  $request_params['doTaxaByCommonNames'] = 0;
1233
  $request_params['matchMode'] = "EXACT";
1234
  $taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1235

    
1236
  //removing the name where we come from and
1237
  foreach($taxon_pager->records as $k=>&$taxon){
1238
    if($taxon->uuid == $taxon_to_hide_uuid){
1239
      unset($taxon_pager->records[$k]);
1240
    }
1241
  }
1242
  //show the taxa list or go to the singular taxon
1243
  if (sizeof($taxon_pager->records) == 1){ //sigle taxon case
1244
    reset($taxon_pager->records);
1245
    $singleTaxon = $taxon_pager->records[0];
1246
    if($singleTaxon->class != "Taxon"){
1247
      // it is a Synonym -> look for the accepted
1248
      $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid, get_taxonomictree_uuid_selected()));
1249
      if($synonym_uuid){
1250
        drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
1251
      }else {
1252
        drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $singleTaxon->uuid);
1253
      }
1254
    }else{
1255
      // it is an accepted taxon
1256
      if($synonym_uuid){
1257
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
1258
      }else{
1259
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid);
1260
      }
1261
    }
1262
  }else{ //more than one taxa case
1263
    $taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
1264
    if($taxon_pager->records){
1265
      $taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
1266
    }else{
1267
      $taxon_name_page->content = 'This name has no taxa';
1268
    }
1269
    return $taxon_name_page;
1270
  }
1271
}
1272

    
1273
function cdm_dataportal_view_search_advanced(){
1274

    
1275
  drupal_set_title(t('Advanced search'));
1276

    
1277
  $searchForm = cdm_dataportal_search_taxon_form(true);
1278

    
1279
  return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1280

    
1281
}
1282

    
1283
/**
1284
 *
1285
 * future extensions to meet palmweb mockup requirements:
1286
 *  - habitat
1287
 *  - uses
1288
 *  - conservation status
1289
 *  - locality / tdwg region
1290
 */
1291
function cdm_dataportal_view_search_taxon(){
1292

    
1293
  $_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
1294

    
1295
  $request_params = cdm_dataportal_search_form_request();
1296
  $taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
1297

    
1298
  $search_params = $_REQUEST;
1299
  unset($search_params['q']);
1300
  return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
1301
}
1302

    
1303

    
1304
function cdm_view_xml2json(){
1305
  $file = arg(2);
1306
  $datastr = get_content(variable_get('cdm_webservice_url', '').$file);
1307
  return  xml2json::transformXmlStringToJson($datastr);
1308
}
1309

    
1310
/* ====================== other functions ====================== */
1311

    
1312

    
1313
/**
1314
 * Creates a URL to the taxon page specified by the $uuid parameter.
1315
 * The URL will be prepended with a path element to a specific taxon page tab.
1316
 *
1317
 * This tab is either taken from the CDM_DATAPORTAL_DEFAULT_TAXON_TAB which can
1318
 * be set globally in the administrative settings or individually in the user
1319
 * profile. If the CDM_DATAPORTAL_DEFAULT_TAXON_TAB value is set to LAST_VISITED_TAB
1320
 * the last portal will stay on this last tab.
1321
 *
1322
 * A third option is offerered by the $page_tab parameter which allows overwriting this
1323
 * internal mechanism by a specific value.
1324
 *
1325
 * @param String $uuid the UUID of the taxon
1326
 * @param String $page_tab overwriting the preset mechanism by defining specific valuefor the taxon page tab.
1327
 *
1328
 * @return the URL
1329
 */
1330
function path_to_taxon($uuid, $page_tab = false){
1331

    
1332
  $tab = get_default_taxon_tab();
1333
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
1334

    
1335
  if(!$uuid) return false;
1336

    
1337
  if($page_tab){
1338
    return 'cdm_dataportal/taxon/'.$uuid . '/' . $page_tab;
1339
  } else if (!$tab){
1340
    return 'cdm_dataportal/taxon/'.$uuid;
1341
  }else if(get_last_taxon_page_tab() &&  $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]){
1342
    return 'cdm_dataportal/taxon/'.$uuid . '/' . get_last_taxon_page_tab();
1343
  } else {
1344
    return 'cdm_dataportal/taxon/'.$uuid . '/' . strtolower($tab);
1345
  }
1346
}
1347

    
1348
function uri_to_synonym($synonymUuid, $acceptedUuid){
1349
  $acceptedPath = path_to_taxon($acceptedUuid, "synonymy");
1350
  return url($acceptedPath, 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid, $synonymUuid);
1351
}
1352

    
1353
function path_to_key($keyType, $keyUuid){
1354
  if(!$keyUuid || !$keyType) return false;
1355
  $keyType{0} = strtolower($keyType{0});
1356
  return "cdm_dataportal/".$keyType."/$keyUuid";
1357
}
1358

    
1359
function path_to_reference($uuid){
1360
  if(!$uuid) return false;
1361
  return 'cdm_dataportal/reference/'.$uuid;
1362
}
1363

    
1364
function path_to_name($name_uuid){
1365
  $res = false;
1366
  if($name_uuid){
1367
   $res = 'cdm_dataportal/name/'.$name_uuid;
1368
  }
1369
  return $res;
1370
}
1371

    
1372
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
1373
  if(!$uuid) return false;
1374
  $out = 'cdm_dataportal/media/'.$uuid;
1375
  if($representaion_uuid){
1376
    $out .= '/'.$representaion_uuid;
1377
    if($partId !== false){
1378
      $out .= '/'.$partId;
1379
    }
1380
  }
1381
  return $out;
1382
}
1383

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

    
1408
/**
1409
 * Composes an HTML element class attribute value composed of
1410
 * the shortname of the cdm class and the uuid of the entity.
1411
 * This class attribute should be used whereever an cdm-entity is rendered.
1412
 *
1413
 * These according class selectors in css must be escaped, eg:
1414
 *    .cdm\:TextData
1415
 *
1416
 * @param $cdmEntity
1417
 */
1418
function html_class_atttibute_ref($cdmEntity){
1419

    
1420
  if(is_cdm_entity($cdmEntity)) {
1421
    return "cdm:".$cdmEntity->class." uuid:".$cdmEntity->uuid;
1422
  }
1423
}
1424

    
1425

    
1426
/**
1427
 * Preprocess the taggedName to normalize newly introduced tagtypes like hybridSign, separator, .. more?
1428
 *
1429
 * @param unknown_type $taggedTextList
1430
 */
1431
function normalize_TaggedName(&$taggedTextList){
1432

    
1433
    if(is_array($taggedTextList)) {
1434

    
1435
      // first pass: rename
1436
      for($i = 0; $i < count($taggedTextList); $i++){
1437

    
1438
        if($taggedTextList[$i]->type == "hybridSign"){
1439
          $taggedTextList[$i]->type = "name";
1440
        }
1441

    
1442
      }
1443

    
1444
      // second pass: resolve separators
1445
      $taggedNameListNew = array();
1446
      for($i = 0; $i < count($taggedTextList); $i++){
1447

    
1448
        if($i + 1 < count($taggedTextList) && $taggedTextList[$i + 1]->type == "separator" ) {
1449

    
1450
          if($taggedTextList[$i]->type == $taggedTextList[$i + 2]->type){
1451
            $taggedName = $taggedTextList[$i];
1452
            $taggedName->text = $taggedName->text . $taggedTextList[$i + 1]->text . $taggedTextList[$i + 2]->text;
1453
            $taggedNameListNew[] = $taggedName;
1454
            ++$i;
1455
            ++$i;
1456
          }
1457
        } else {
1458
          $taggedNameListNew[] = $taggedTextList[$i];
1459
        }
1460
	  }
1461
	   $taggedTextList = $taggedNameListNew;
1462
    }
1463
}
1464

    
1465
/**
1466
 * Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
1467
 * If the taggename if empty the fullname will be returned.
1468
 *
1469
 * @param unknown_type $Name or TreeNode
1470
 * @return string
1471
 */
1472
function cdm_dataportal_shortname_of($name){
1473
  $nameStr = '';
1474

    
1475
  normalize_TaggedName($name->taggedTitle);
1476

    
1477
  // get all tagged text tokens of the scientific name
1478
  foreach($name->taggedTitle as $tagtxt){
1479
    if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
1480
      $nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
1481
    }
1482
  }
1483
  $nameStr = trim($nameStr);
1484
  if($nameStr){
1485
    // do not return short names for these
1486
    //if (stristr(strtolower($nameStr), 'incertae sedis') !== FALSE ||
1487
    //	stristr(strtolower($nameStr), 'nomina excludenda') !== FALSE) {
1488
    if ($name->unplaced || $name->excluded){
1489
      return $nameStr;
1490
    }
1491
    if($pos = stripos($nameStr, ' ')){
1492
      return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos);
1493
    } else {
1494
      return $nameStr;
1495
    }
1496
  } else {
1497
    return $name->titleCache;
1498
  }
1499
}
1500

    
1501

    
1502
/**
1503
 * Check if a taxon is accepted by the current taxonomic tree
1504
 *
1505
 * @param Taxon $taxon
1506
 * @return true if $taxon is accepted, false otherwise
1507
 */
1508

    
1509
function _cdm_dataportal_acceptedByCurrentView($taxon){
1510

    
1511
  $defaultTreeUuid = get_taxonomictree_uuid_selected();
1512
  if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){
1513
    foreach($taxon->taxonNodes as $node){
1514
      if($node->classification == $defaultTreeUuid) {
1515
        return true;
1516
      }
1517
    }
1518
  }
1519
  return false;
1520
}
1521

    
1522
/**@Deprecated
1523
 *
1524
 */
1525
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
1526
  $pstr = '';
1527
  foreach($parameters as $key=>$value){
1528
    if(is_array($value)){
1529

    
1530
    } else {
1531
      $pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
1532
    }
1533
  }
1534
  return $pstr;
1535
}
1536

    
1537
/**
1538
 * workaround for missing original source type, idNamespace is always set in these cases
1539
 * @param unknown_type $source
1540
 * @return unknown_type
1541
 */
1542
function _is_original_source_type($source){
1543
  return !$source->idNamespace && strlen($source->idNamespace) == 0;
1544
}
1545

    
1546
function _is_invers_taxonRelationship($taxonRelationship, $focusedTaxon){
1547
  return $taxonRelationship->toTaxon->uuid == $focusedTaxon->uuid;
1548
}
1549

    
1550

    
1551

    
1552
/**
1553
 * The function read the metadata info such title or artist of a media file. The
1554
 * function tries at first to get all the info from the file metadata and if it is
1555
 * not avaible look at the media file info stored at the database.
1556
 * @param $media The media file
1557
 * @return array The array with the avilable specified metadata info.
1558
 * TODO rename to read_media_metadata() and move to *.module
1559
 */
1560
function cdm_read_media_metadata($media){
1561

    
1562
  $metadata_caption = array('title' => '',           //media_metadata and media
1563
                              'artist' => '',          //media_metadata and media
1564
                              'rights',                //media_metadata and media
1565
                              'location',              //media_metadata
1566
                              'filename' => '',        //media
1567
                              'mediacreated' => '',    //media
1568
                              'description' => '');    //media
1569

    
1570
  //getting the media metadata
1571
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
1572
  $media_metadata_aux = (array) $media_metadata;
1573

    
1574
  //filename
1575
  if(isset($media->representations[0]->parts[0]->uri)){
1576
    $fileUri = $media->representations[0]->parts[0]->uri;
1577
    $filename = substr($fileUri, strrpos($fileUri, "/")+1);
1578
    $metadata_caption['filename'] = $filename;
1579
  }
1580
  else{
1581
      $metadata_caption['filename'] = '';
1582
  }
1583

    
1584
  //title
1585
  if ($media_metadata->ObjectName) {
1586
    $metadata_caption['title'] = $media_metadata->ObjectName;
1587
  } else if ($media_metadata_aux['Object Name']){
1588
    $metadata_caption['title'] = $media_metadata_aux['Object Name'];
1589
  } else if ($media->title_L10n){
1590
    $metadata_caption['title'] = $media->title_L10n;
1591
  } else if ($media->titleCache){
1592
    $metadata_caption['title'] = $media->titleCache;
1593
  }
1594

    
1595
  // append description to title
1596
  if ($media->description_L10n) {
1597
    $metadata_caption['title'] .= '<span class="media-description">' . $media->description_L10n . '<span>';
1598
  }
1599

    
1600
  //artist
1601
  if ($media_metadata->Artist){
1602
   $metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
1603
  }
1604
  elseif ($media->artist->titleCache){
1605
   $metadata_caption['artist'] = $media->artist->titleCache;
1606
  }
1607

    
1608
  //copyright
1609
  $metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
1610
                                      'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
1611
  if ($media_metadata->Copyright)
1612
  $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
1613
  elseif ($media->rights){
1614
    foreach($media->rights as $right){
1615
      switch($right->term->uuid){
1616
        case UUID_RIGHTS_LICENCE:
1617
          $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
1618
          $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
1619
          $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
1620
          $metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
1621
          break;
1622
        case UUID_RIGHTS_COPYRIGHT:
1623
          $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
1624
          break;
1625
      }
1626
    }
1627
  } else {
1628
    $metadata_caption['rights']['agentNames'][] = '';
1629
  }
1630

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

    
1634
  //location
1635
  $metadata_caption['location'] = array();
1636
  $metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
1637
  $metadata_caption['location']['city'] = $media_metadata->City;
1638
  $metadata_caption['location']['province'] = $media_metadata->Province;
1639
  $metadata_caption['location']['country'] = $media_metadata->Country;
1640

    
1641
  /*
1642
   //creation date
1643
   if($media_metadata["Modify Date"])
1644
   $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
1645
   else
1646
   $metadata_caption['mediacreated'] = $media->created;
1647
   */
1648
  //returned value
1649
  return $metadata_caption;
1650
}
1651

    
1652
/**
1653
 * This function collects all the media from a list of description elements
1654
 * and return them as an Array.
1655
 *
1656
 * @param $descriptionElementes The description elements
1657
 * @return Array The output with all the media
1658
 */
1659
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
1660
  //variables
1661
  $outArrayOfMedia = array(); //return value
1662
  //implementation
1663
  if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
1664
    foreach($descriptionElements as $descriptionElement){
1665
      if(is_array($descriptionElement->media)){
1666
        foreach($descriptionElement->media as $media){
1667
          if(is_object($media)){
1668
            $outArrayOfMedia[] = $media;
1669
          }
1670
        }
1671
      }
1672
    }
1673
  }
1674
  return $outArrayOfMedia;
1675
}
1676

    
1677
/**
1678
 *
1679
 * @param - $cdmBase_list @param $cdmBase_list an array of CdmBase instances or a single instance
1680
 * @param - $footnote_list_key
1681
 */
1682
function cdm_annotations_as_footnotekeys($cdmBase_list, $footnote_list_key = null){
1683
  static $annotations_types_filter;
1684

    
1685
  if(!$annotations_types_filter) {
1686
    unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT);
1687
  }
1688

    
1689
  $footNoteKeys = array();
1690

    
1691
  //is argument cdmBase an array?
1692
  if (!is_array($cdmBase_list)){
1693
    $cdmBase_array = array();
1694
    $cdmBase_array[] = $cdmBase_list;
1695
  }else{
1696
    $cdmBase_array = $cdmBase_list;
1697
  }
1698

    
1699
  //getting the key for the footnotemanager
1700
  if( $footnote_list_key ){
1701
    $footnoteListKey = $footnote_list_key;
1702
  }else{
1703
    $footnoteListKey = RenderHints::getFootnoteListKey() . '-annotations';
1704
  }
1705

    
1706
  //adding the footnotes keys
1707
  $annotations_types_filter = unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT);
1708
  foreach($cdmBase_array as $cdmBase_element){
1709
    $annotations = cdm_ws_getAnnotationsFor($cdmBase_element, variable_get('annotations_types_as_footnotes', $annotations_types_filter));
1710
    if(is_array($annotations)){
1711
      foreach($annotations as $annotation){
1712
          $footNoteKeys[] = FootnoteManager::addNewFootnote($footnoteListKey, $annotation->text);
1713
      }
1714
    }
1715
  }
1716

    
1717
  return $footNoteKeys;
1718
}
1719

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

    
1722
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
1723

    
1724
  $cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
1725
  $out .= '<'. $enclosingtags[0]. ' class="dynabox"><a href="'.$content_url.'" class="label" alt="'.t($link_alt_text).'">'.$label.'</a>';
1726
  $out .= '<'. $enclosingtags[1]. ' class="dynabox_content" title="'.$cdm_proxy_url.'"><'. $enclosingtags[0]. '><img class="loading" src="'.drupal_get_path('module', 'cdm_dataportal').'/images/loading_circle_grey_16.gif" style="display:none;"></'. $enclosingtags[0]. '></'. $enclosingtags[1]. '>';
1727
  $out .= '</'. $enclosingtags[0]. '>';
1728
  return $out;
1729
}
1730

    
1731
/**
1732
 * returns true if the given $featureNode or any of its subordinate nodes contains
1733
 * at least one non empty TextData or at leas one DescriptionElement of an other type.
1734
 *
1735
 * @param unknown_type $featureNode A heature node as produced by the function _mergeFeatureTreeDescriptions()
1736
 */
1737
function hasFeatureNodeDescriptionElements($featureNode) {
1738

    
1739
  if(is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) {
1740
    foreach ($featureNode->descriptionElements as $descriptionElement) {
1741
      if($descriptionElement->class != "TextData" || $descriptionElement->multilanguageText_L10n->text){
1742
        return true;
1743
      }
1744
    }
1745
  } else if(is_array($featureNode->children)) {
1746
    foreach ($featureNode->children as $child) {
1747
      if(hasFeatureNodeDescriptionElements($child)){
1748
        return true;
1749
      }
1750
    }
1751
  }
1752
  return false;
1753
}
1754

    
(6-6/12)