Project

General

Profile

Download (152 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6

    
7

    
8
  // TODO Genus UUID.
9

    
10
  define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
11
  define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
12
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
13
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
14

    
15
  define('NO_SORT', -1);
16
  define('SORT_HIERARCHICAL', 9);
17

    
18
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
19

    
20
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
21
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
22

    
23
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
24
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
25
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
26
  define('CDM_DATAPORTAL_TAXON_AUTO_SUGGEST', 0);
27
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
28
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
29
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
30
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
31
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
32

    
33
  /* annotationTypeKeys */
34
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
35
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
36
    $annotationTypeKeys = array_flip($annotationTypeKeys);
37

    
38
    // Technical annotation are off by default.
39
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
40
    $annotationTypeKeys = array_flip($annotationTypeKeys);
41
    // Additional value for the NULL case.
42
    $annotationTypeKeys[] = 'NULL_VALUE';
43
  }
44
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
45

    
46
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
47
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
48
    'enabled' => 0,
49
    'key_format' => 'ALPHA'
50
  )));
51

    
52
  /* taxonRelationshipTypes */
53
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
54

    
55

    
56
  /* ---- MAP SETTING CONSTANTS ---- */
57
  /**
58
   * @var array of URIs eg. http://edit.africamuseum.be"
59
   *   An options array
60
   */
61
  define('EDIT_MAPSERVER_URI', serialize(
62
      array(
63
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
64
      )
65
    )
66
  );
67
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
68
  /**
69
   * @var array of versions eg. "v1.2"
70
   *   An options array
71
   */
72
  define('EDIT_MAPSERVER_VERSION', serialize(
73
      array(
74
//        'v1' => 'v1' ,           // no longer recommended
75
//        'v1.1' => 'v1.1',        // no longer recommended
76
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
77
        'v1.2' => 'v1.2',
78
        'v1.3_dev' => 'v1.3_dev (not recommended)',
79
        'v1.4_dev' => 'v1.4_dev (experimental features)'
80
      )
81
    )
82
  );
83
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
84
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
85

    
86
    // --- Taxon profile settings --- /
87
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
88
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
89
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
90
      array(
91
          'show' => 0,
92
          'maxextend' => 184,
93
          'media_uri_query' => '',
94
          'custom_placeholder_enabled' => 1,
95
          'custom_placeholder_image_on' => 0,
96
          'custom_placeholder_image_fid' => ''
97
      )
98
    )
99
  );
100

    
101

    
102
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
103

    
104
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
105
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
106
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
107
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
108
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
109

    
110
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
111
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
112
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
113
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
114

    
115
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
116
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
117

    
118
/**
119
 * Returns the array of implemented taxon page tabs.
120
 * The array has fixed integer keys which must not be changed.
121
 */
122
function get_taxon_tabs_list() {
123
  $opts = array(
124
    0 => 'General',
125
    1 => 'Synonymy',
126
    2 => 'Images',
127
    3 => 'Specimens',
128
    4 => 'Keys',
129
    5 => 'Experts',
130
  );
131
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
132
    // skip the Synonymy if it is shown in  the general tab
133
    unset($opts[1]);
134
  }
135
  return $opts;
136
}
137

    
138
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
139
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
140
  array(
141
    'general' => '-3',
142
    'synonymy' => '-2',
143
    'images' => '0',
144
    'specimens' => '1',
145
    'keys' => '3',
146
    'experts' => '5',
147
    )
148
));
149

    
150

    
151
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
152
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
153
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
154
  array(
155
    'general' => null,
156
    'synonymy' => null,
157
    'images' => null,
158
    'specimens' => null,
159
    'keys' => null,
160
    'experts' => null,
161
  )
162
));
163

    
164
$taxon_tab_options = get_taxon_tabs_list();
165
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
166

    
167
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
168

    
169
/**
170
 * @todo document this function.
171
 */
172
function get_taxon_options_list() {
173
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
174
  foreach ($taxon_tab_options as $key => $value) {
175
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
176
  }
177
  return $taxon_tab_options;
178

    
179
}
180

    
181
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
182
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
183
    array(
184
      'ZoologicalName' => array(
185
        'namePart' => array('name' => TRUE),
186
        'nameAuthorPart' => array('name' => TRUE),
187
        'referencePart' => array('authors' => TRUE),
188
        'microreferencePart' => array('microreference' => TRUE),
189
        'secReferencePart' => array('secReference' => TRUE,),
190
        'statusPart' => array('status' => TRUE),
191
        'descriptionPart' => array('description' => TRUE),
192
      ),
193
      'BotanicalName'=> array(
194
        'namePart' => array('name' => TRUE),
195
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
196
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
197
        'secReferencePart' => array('secReference' => TRUE,),
198
        'referenceYearPart' => array('reference.year' => TRUE),
199
        'statusPart' => array('status' => TRUE),
200
        'descriptionPart' => array('description' => TRUE),
201
      ),
202
     '#DEFAULT' => array(
203
        'namePart' => array(
204
            'name' => TRUE
205
        ),
206
        'nameAuthorPart' => array(
207
            'name' => TRUE,
208
            'authors' => TRUE
209
        ),
210
       'referencePart' => array(
211
         'reference' => TRUE
212
        ),
213
       'secReferencePart' => array(
214
         'secReference' => TRUE,
215
       ),
216
       'microreferencePart' => array(
217
          'microreference' => TRUE,
218
        ),
219
       'statusPart' => array(
220
          'status' => TRUE,
221
        ),
222
       'descriptionPart' => array(
223
          'description' => TRUE,
224
        ),
225
      )
226
    )
227
  )
228
);
229
define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
230
    array(
231
      'ZoologicalName' => array(
232
        'namePart' => array('name' => TRUE),
233
        'nameAuthorPart' => array('name' => TRUE),
234
        'referencePart' => array('authors' => TRUE),
235
        'microreferencePart' => array('microreference' => TRUE),
236
        'statusPart' => array('status' => TRUE),
237
        'descriptionPart' => array('description' => TRUE),
238
      ),
239
      'BotanicalName'=> array(
240
        'namePart' => array('name' => TRUE),
241
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
242
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
243
        'referenceYearPart' => array('reference.year' => TRUE),
244
        'statusPart' => array('status' => TRUE),
245
        'descriptionPart' => array('description' => TRUE),
246
      ),
247
      '#DEFAULT' => array(
248
        'namePart' => array(
249
          'name' => TRUE
250
        ),
251
        'nameAuthorPart' => array(
252
          'name' => TRUE,
253
          'authors' => TRUE
254
        ),
255
        'referencePart' => array(
256
          'reference' => TRUE
257
        ),
258
        'microreferencePart' => array(
259
          'microreference' => TRUE,
260
        ),
261
        'statusPart' => array(
262
          'status' => TRUE,
263
        ),
264
        'descriptionPart' => array(
265
          'description' => TRUE,
266
        ),
267
      )
268
    )
269
  )
270
  );
271

    
272
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
273
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
274
  array (
275
    'taxon_page_title,polytomousKey'=> array(
276
        'namePart' => array('#uri' => TRUE),
277
      ),
278
    'not_in_current_classification' => array(
279
     'nameAuthorPart' => TRUE,
280
     'referencePart' => TRUE,
281
     'statusPart' => TRUE,
282
     'secReferencePart' => TRUE,
283
    ),
284
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
285
      'nameAuthorPart' => array('#uri' => TRUE),
286
      'referencePart' => TRUE,
287
      'descriptionPart' => TRUE,
288
      'statusPart' => TRUE,
289
    ),
290
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
291
      'nameAuthorPart' => array('#uri' => TRUE),
292
      'referencePart' => TRUE,
293
      'descriptionPart' => TRUE,
294
      'statusPart' => TRUE,
295
      'secReferencePart' => TRUE,
296
    ),
297
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
298
      'nameAuthorPart' => array('#uri' => TRUE),
299
      'referencePart' => TRUE,
300
      'descriptionPart' => TRUE,
301
      'statusPart' => TRUE,
302
      /* no sec ref in this case, misapplied names are
303
       * de-duplicated and the sec ref is shown as footnote */
304
    ),
305
    'homonym'=> array(
306
        'nameAuthorPart' => array('#uri' => TRUE),
307
        'referenceYearPart' => TRUE,
308
        'statusPart' => TRUE,
309
    ),
310
    'acceptedFor,typedesignations,list_of_taxa' => array(
311
        'nameAuthorPart' => array('#uri' => TRUE),
312
        'referencePart' => TRUE,
313
      ),
314
    '#DEFAULT' => array(
315
        'nameAuthorPart' => array('#uri' => TRUE),
316
        'referencePart' => TRUE,
317
     )
318
  )
319
));
320
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
321
  array (
322
    'taxon_page_title,polytomousKey'=> array(
323
      'namePart' => array('#uri' => TRUE),
324
    ),
325
    'taxon_page_synonymy,related_taxon'=> array(
326
      'nameAuthorPart' => array('#uri' => TRUE),
327
      'referencePart' => TRUE,
328
      'statusPart' => TRUE,
329
      'descriptionPart' => TRUE,
330
    ),
331
    'homonym'=> array(
332
      'nameAuthorPart' => array('#uri' => TRUE),
333
      'referenceYearPart' => TRUE,
334
    ),
335
    'acceptedFor,typedesignations,list_of_taxa' => array(
336
      'nameAuthorPart' => array('#uri' => TRUE),
337
      'referencePart' => TRUE,
338
    ),
339
    '#DEFAULT' => array(
340
      'nameAuthorPart' => array('#uri' => TRUE),
341
      'referencePart' => TRUE,
342
    )
343
  )
344
));
345

    
346
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
347
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
348
    // to unset a default enntry set the value to 0
349
    array(
350
      'doTaxa'=>'doTaxa',
351
      'doSynonyms' => 'doSynonyms',
352
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
353
      'doMisappliedNames' => 'doMisappliedNames'
354
    )
355
  )
356
);
357

    
358
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
359

    
360
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
361
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
362

    
363
/* Gallery variables. */
364
$gallery_settings = array(
365
    "cdm_dataportal_show_taxon_thumbnails" => 1,
366
    "cdm_dataportal_show_synonym_thumbnails" => 0,
367
    "cdm_dataportal_show_thumbnail_captions" => 1,
368
    "cdm_dataportal_media_maxextend" => 120,
369
    "cdm_dataportal_media_cols" => 3,
370
    "cdm_dataportal_media_maxRows" => 1,
371
);
372

    
373
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
374
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
375
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
376
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
377
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
378
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
379
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
380
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
381
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
382
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
383
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
384

    
385
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
386
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
387
  'media_representation_details_enabled' => 0
388
)));
389

    
390
/**
391
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
392
 * the snonymy.
393
 *
394
 * @var string
395
 */
396
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
397

    
398
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
399
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
400
    array(
401
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
402
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
403
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
404
    )
405
  )
406
);
407

    
408
/**
409
 * The drupal variable for the configuration of the information aggregation along
410
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
411
 *    - direct: the uuids of the taxon relationship types to take into account in invers
412
 *      direction.
413
 *    - invers: the uuids of the taxon relationship types to take into account in direct
414
 *      direction.
415
 *
416
 * @var String
417
 */
418
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
419
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
420
    array(
421
        'direct'=>array(),
422
        'invers'=>array()
423
     )
424
   ));
425
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
426
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
427
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
428

    
429
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
430
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
431
      array(
432
      'filter_rules' => array(
433
        'statusOrderPreference' => 0,
434
        'subAreaPreference' => 0,
435
      ),
436
      'hiddenAreaMarkerType' => array()
437
     )
438
));
439

    
440
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
441
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
442
  "level_0" => array(
443
    'label_suffix' => ':',
444
    'status_glue' => '',
445
    'item_glue' => ' ',
446
    'item_group_prefix' => '',
447
    'item_group_postfix' => ''
448
  ),
449
  "level_1" => array(
450
    'label_suffix' => '',
451
    'status_glue' => '‒ ', // '&#8210; '
452
    'item_glue' => '; ',
453
    'item_group_prefix' => ', ',
454
    'item_group_postfix' => ''
455
  ),
456
  "level_2" => array(
457
    'label_suffix' => '',
458
    'status_glue' => '‒ ', // '&#8210; '
459
    'item_glue' => ', ',
460
    'item_group_prefix' => ' (',
461
    'item_group_postfix' => ')'
462
  )
463
)));
464

    
465
/**
466
 * Constant for the drupal variable key distribution_map_visibility
467
 *
468
 * possible values:
469
 *  - never
470
 *  - automatic
471
 *  - always
472
 */
473
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
474
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
475

    
476
/**
477
 * Constant for the drupal variable key specimen_map_visibility
478
 *
479
 * possible values:
480
 *  - never
481
 *  - automatic
482
 *  - always
483
 */
484
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
485
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
486

    
487
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
488
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
489
    array(
490
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
491
        'includeOccurrences' => 0,
492
        'includeTaxonNameDescriptions' => 0
493
     )
494
  ));
495

    
496
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
497
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
498
  // needs to be merged with user setting by drupal_array_merge_deep()
499
  // 'width' => 512, // optimum size for OSM layers is 512
500
  // 'height' => 512 / 2, // optimum size for OSM layers 256
501
  'aspect_ratio' => 2,
502
  'bbox' => '', // empty to allow automatic zooming to extend
503
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
504
  'show_labels' => FALSE,
505
  'caption' => '',
506
  'distribution_opacity' => '0.5',
507
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
508
  'image_map' => array(
509
    'base_layer' => '', // none, formerly this was cyprusdivs
510
    'bg_color' => '1874CD',
511
    'layer_style' => 'ffffff,606060,,',
512
  ),
513
  'openlayers' => array(
514
    'base_layers' =>  array(
515
      // A layer MUST NOT BE SET in the defaults,
516
      // otherwise it can not be overidden by the user settings:
517
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
518
      // it is sufficient to define the preferred layer,
519
      // since it will automatically be enabled:
520
      'PREFERRED' => 'mapproxy_vmap0'),
521
    'custom_wms_base_layer' => array(
522
      'name' => NULL,
523
      'url' => NULL,
524
      'params' =>  NULL,
525
      'projection' => NULL,
526
      'proj4js_def' => NULL,
527
      'max_extent' => NULL,
528
      'units' => NULL,
529
      'untiled' => FALSE
530
    ),
531
    'wms_overlay_layer' => array(
532
      'name' => NULL,
533
      'url' => NULL,
534
      'params' =>  NULL,
535
      'untiled' => FALSE
536
    ),
537
    'show_layer_switcher' => TRUE,
538
    'display_outside_max_extent' => FALSE,
539
    'google_maps_api_key' => NULL,
540
  ),
541
  'legend' => array(
542
    'show' => TRUE,
543
    'opacity' => '0.5',
544
    'font_size' => 10,
545
    'font_style' => FALSE,
546
    'icon_width' => 35,
547
    'icon_height' => 15
548
  )
549
)));
550

    
551
/**
552
 * Merges the named array variable with the array of defaults.
553
 *
554
 * IMPORTANT: The array keys must be strings. When the keys are integers
555
 * the merging will not take place for these entities. Number keyed entities
556
 * are just appended to the result array.
557
 *
558
 * @param string $variable_name
559
 *     The variable name
560
 * @param string | array $default
561
 *     The array containing the default values either as array or serialized as string.
562
 *     Unserialization is cared for if necessary
563
 * @return array
564
 *     The merged array as returned by drupal_array_merge_deep()
565
 *
566
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
567
 * TODO force $default being an array
568
 */
569
function get_array_variable_merged($variable_name, $default){
570

    
571
    // unserialize if nessecary
572
    if(!is_array($default)){
573
      $default = unserialize($default);
574
    }
575
    $variable = variable_get($variable_name, array());
576
    $result = drupal_array_merge_deep($default, $variable);
577
    return $result;
578
}
579

    
580
/**
581
 * @todo document this function.
582
 */
583
function getGallerySettings($gallery_config_form_name) {
584
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
585
}
586

    
587
/**
588
 * Returns the string representation of the default tab.
589
 *
590
 * @param bool $returnTabIndex
591
 *   Defaults to FALSE, if set true this function will return the index number
592
 *   of the default tab. (used to supply default values to form elements).
593
 */
594
function get_default_taxon_tab($returnTabIndex = FALSE) {
595

    
596
  global $user;
597
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
598
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
599
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
600
  // Get the user value if the used has chosen to overwrite the system settings.
601
  $user_tab_on = variable_get($user_tab_active, FALSE);
602
  if ($user_tab_on) {
603
    $user_value = variable_get($user_tab, 0);
604
    $index_value = $user_value;
605
    // Get the system value.
606
  }
607
  else {
608
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
609
    $index_value = $system_value;
610
  }
611

    
612
  // Return the index value or the string representation.
613
  if ($returnTabIndex) {
614
    return $index_value;
615
  }
616
  else {
617
    return ($values[$index_value]);
618
  }
619
}
620

    
621
/**
622
 * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
623
 *
624
 * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
625
 * one or more fields these fields are taken from the default. That is the specific settings are always merges
626
 * with the default.
627
 *
628
 * Note: These settings only apply to feature blocks which do not have a special rendering
629
 * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
630
 * 'special' element of the settings
631
 *
632
 * @param $feature_uuid
633
 *   The uuid string representation of the feature to return the settings for
634
 *
635
 * @return array
636
 *  an associative array of settings, with the following fields:
637
 *    - as_list: string
638
 *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
639
 *        possible values are:
640
 *          div: not as list,
641
 *          ul: as bullet list,
642
 *          ol: as numbered list,
643
 *          dl: as definition list
644
 *        The tag used for the inner element, thus depends on the value of this field. The
645
 *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
646
 *    - link_to_reference: boolean,
647
 *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
648
 *    - link_to_name_used_in_source": boolean
649
 *        whether to show name in source information as link which will point to the according name page
650
 *    - sources_as_content (boolean)
651
 *        TRUE (int: 1):
652
 *          1. If element is of the CDM type TextData and the text is not empty the source references will be
653
 *             appended in brackets like "text (source references)". If the original source has name in source
654
 *             information it will be appended to the citation string,
655
 *             like : "(citation, as name in source; citation, as name in source)"
656
 *          2. if the text of the TextData is empty, the original source citations are the only content
657
 *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
658
 *             prepended to the citation string like: "name in source: citation"
659
 *        FALSE (int: 0):
660
 *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
661
 *          citations are the only content, the resulting feature block content would only consist of footnotes.
662
 *          In this case the display of the respective feature block is suppressed.
663
 *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
664
 *               in future however they will in this case be shown in a separate references section for each
665
 *               feature block.
666
 *    - sources_as_content_to_bibliography  (boolean)
667
 *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
668
 *        in the bibliography.
669
 *    - sort_elements
670
 *        whether and how to sort the elements
671
 *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
672
 *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
673
 *        TODO option to exclude levels, put in special?,
674
 *        TODO make use of this setting in compose_feature_block_wrap_elements())
675
 *    - element_tag
676
 *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
677
 *        possible values are span | div. the proper inner tag name can be retrieved by the function
678
 *        cdm_feature_block_element_tag_name()
679
 *    - special: array()
680
 *        an array with further settings, this field can be used for special
681
 *        settings for specialized rendering like for distributions
682
 *  }
683
 *
684
 */
685
function get_feature_block_settings($feature_uuid = 'DEFAULT') {
686
  // the default must conform to the default parameter values of
687
  // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
688
  // compose_description_element_text_data() : asListElement = NULL
689

    
690
  // see #3257 (implement means to define the features to show up in the taxonprofile and in the specimen descriptions)
691

    
692
  // ---- DEFAULTS settings
693

    
694
  // only needed as final option, when the settings are not having a default
695
  $default = array(
696
    'DEFAULT' => array(
697
      'as_list' => 'div',
698
      'link_to_reference' => 0,
699
      'link_to_name_used_in_source' => 1,
700
      'sources_as_content' => 0,
701
      'sources_as_content_to_bibliography' => 0,
702
      'sort_elements' => NO_SORT,
703
      'glue' => '',
704
      'element_tag' => NULL
705
    ),
706
    // settings for pseudo feature bibliography
707
    // only hard coded here
708
    'BIBLIOGRAPHY' => array(
709
      'as_list' => 'div',
710
      'link_to_reference' => 0,
711
      'link_to_name_used_in_source' => 1,
712
      'sources_as_content' => 0,
713
      'sources_as_content_to_bibliography' => 0,
714
      'sort_elements' => NO_SORT,
715
      'glue' => '',
716
      'element_tag' => NULL
717
    )
718
  );
719

    
720
  // will be used as preset in the settings
721
  $other_themes_default = array(
722
    'DEFAULT' => array(
723
      'as_list' => 'div',
724
      'link_to_reference' => 0,
725
      'link_to_name_used_in_source' => 1,
726
      'sources_as_content' => 0,
727
      'sources_as_content_to_bibliography' => 0,
728
      'sort_elements' => NO_SORT,
729
      'glue' => '',
730
      'element_tag' => NULL
731
    ),
732
    UUID_CITATION => array(
733
      'as_list' => 'div',
734
      'link_to_reference' => 0,
735
      'link_to_name_used_in_source' => 0,
736
      'sources_as_content' => 1,
737
      'sources_as_content_to_bibliography' => 0,
738
      'sort_elements' => SORT_ASC,
739
      'glue' => '',
740
      'element_tag' => 'div'
741
    ),
742
    UUID_DISTRIBUTION => array(
743
      'as_list' => 'div', // currently ignored
744
      'link_to_reference' => 0,
745
      'link_to_name_used_in_source' => 0,
746
      'sources_as_content' => 0,
747
      'sources_as_content_to_bibliography' => 0,
748
      'sort_elements' => NO_SORT, // will cause ...
749
      'glue' => '',
750
      'element_tag' => 'div',
751
      'special' => array()
752
    ),
753
    UUID_COMMON_NAME => array(
754
      'as_list' => 'div',
755
      'link_to_reference' => 0,
756
      'link_to_name_used_in_source' => 1,
757
      'sources_as_content' => 0,
758
      'sources_as_content_to_bibliography' => 0,
759
      'sort_elements' => NO_SORT,
760
      'glue' => '',
761
      'element_tag' => 'span'
762
    ),
763
  );
764

    
765
  // ---- Special DEFAULTS for existing portals
766
  // TODO:
767
  // this can be removed once the feature block
768
  // settings have been deployed for the first time to these portals
769

    
770
  $cichorieae_default = array(
771
    'DEFAULT' => array(
772
      'as_list' => 'div',
773
      'link_to_reference' => 1,
774
      'link_to_name_used_in_source' => 1,
775
      'sources_as_content' => 1,
776
      'sources_as_content_to_bibliography' => 0,
777
      'sort_elements' => NO_SORT,
778
      'glue' => '',
779
      'element_tag' => 'div'
780
    ),
781
    UUID_CITATION => array(
782
      'as_list' => 'div',
783
      'link_to_reference' => 0,
784
      'link_to_name_used_in_source' => 0,
785
      'sources_as_content' => 1,
786
      'sources_as_content_to_bibliography' => 0,
787
      'sort_elements' => SORT_ASC,
788
      'glue' => '',
789
      'element_tag' => 'div'
790
    ),
791
    UUID_CHROMOSOMES_NUMBERS => array(
792
      'as_list' => 'ul',
793
      'link_to_reference' => 1,
794
      'link_to_name_used_in_source' => 1,
795
      'sources_as_content' => 1,
796
      'sources_as_content_to_bibliography' => 0,
797
      'sort_elements' => NO_SORT,
798
      'glue' => '',
799
      'element_tag' => 'div'
800
    ),
801
    UUID_CHROMOSOMES => array(
802
      'as_list' => 'ul',
803
      'link_to_reference' => 0,
804
      'link_to_name_used_in_source' => 1,
805
      'sources_as_content' => 1,
806
      'sources_as_content_to_bibliography' => 0,
807
      'sort_elements' => NO_SORT,
808
      'glue' => '',
809
      'element_tag' => 'div'
810
    ),
811
    UUID_COMMON_NAME => array(
812
      'as_list' => 'div',
813
      'link_to_reference' => 0,
814
      'link_to_name_used_in_source' => 1,
815
      'sources_as_content' => 0,
816
      'sources_as_content_to_bibliography' => 0,
817
      'sort_elements' => NO_SORT,
818
      'glue' => '',
819
      'element_tag' => 'span'
820
    ),
821
  );
822

    
823
  $palmweb_default = array(
824
    'DEFAULT' => array(
825
      'as_list' => 'ul',
826
      'link_to_reference' => 1,
827
      'link_to_name_used_in_source' => 1,
828
      'sources_as_content' => 1,
829
      'sources_as_content_to_bibliography' => 1,
830
      'sort_elements' => NO_SORT,
831
      'glue' => '',
832
      'element_tag' => NULL
833
    ),
834
    UUID_CITATION => array(
835
      'as_list' => 'ul',
836
      'link_to_reference' => 1,
837
      'link_to_name_used_in_source' => 1,
838
      'sources_as_content' => 0,
839
      'sources_as_content_to_bibliography' => 1,
840
      'sort_elements' => SORT_ASC,
841
      'glue' => '',
842
      'element_tag' => 'div'
843
    ),
844
    UUID_DISTRIBUTION => array(
845
      'as_list' => 'div', // currently ignored
846
      'link_to_reference' => 1,
847
      'link_to_name_used_in_source' => 1,
848
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
849
      'sources_as_content_to_bibliography' => 1,
850
      'sort_elements' => NO_SORT, // will cause ...
851
      'glue' => ', ',
852
      'element_tag' => 'span',
853
      'special' => array()
854
    ),
855
  );
856

    
857
  $cyprus_default = $cichorieae_default;
858
  $cyprus_default[UUID_DISTRIBUTION] = array(
859
    'as_list' => 'div', // currently ignored
860
    'link_to_reference' => 0,
861
    'link_to_name_used_in_source' => 0,
862
    'sources_as_content' => 0,
863
    'sources_as_content_to_bibliography' => 0,
864
    'sort_elements' => NO_SORT, // will cause ...
865
    'glue' => ' ',
866
    'element_tag' => 'div',
867
    'special' => array()
868
  );
869

    
870
  $default_theme = variable_get('theme_default', NULL);
871

    
872
  switch ($default_theme) {
873
    case 'garland_cichorieae':
874
      $settings_for_theme = $cichorieae_default;
875
      break;
876
    case 'cyprus':
877
      // cyprus: no longer used in production,
878
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
879
      $settings_for_theme = $cyprus_default;
880
      break;
881
    case 'flore_afrique_centrale':
882
    case 'flora_malesiana':
883
    case 'flore_gabon':
884
      $settings_for_theme = $cichorieae_default;
885
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
886
      break;
887
    case 'palmweb_2':
888
      $settings_for_theme = $palmweb_default;
889
      break;
890
    default:
891
      $settings_for_theme = $other_themes_default;
892
  }
893
  // add pseudo feature settings
894
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
895

    
896
  // ---- END of DEFAULTS
897

    
898
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
899

    
900
  $feature_block_setting = null;
901

    
902
  if (isset($saved_settings[$feature_uuid])) {
903
    $feature_block_setting = $saved_settings[$feature_uuid];
904
  }
905
  else if (isset($settings_for_theme[$feature_uuid])) {
906
    $feature_block_setting = $settings_for_theme[$feature_uuid];
907
  }
908
  else if (isset($settings_for_theme['DEFAULT'])) {
909
    $feature_block_setting = $settings_for_theme['DEFAULT'];
910
  }
911

    
912
  // now merge the default and specific settings
913
  $settings_to_merge = array($default['DEFAULT']);
914
  if(is_array($saved_settings)){
915
    $settings_to_merge[] = $saved_settings['DEFAULT'];
916
  }
917
  if(isset($feature_block_setting)){
918
    $settings_to_merge[] = $feature_block_setting;
919
  }
920
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
921

    
922
  return $feature_block_setting;
923
}
924

    
925
/**
926
 * returns the current setting for the original source bibliography
927
 *
928
 * Caches internally
929
 *
930
 * @return array
931
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
932
 *   - 'enabled': 1|0
933
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
934
 */
935
function get_bibliography_settings($clear_cache = false){
936
  static $bibliography_settings = null;
937
  if(!$bibliography_settings || $clear_cache){
938
    $bibliography_settings = get_array_variable_merged(
939
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
940
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
941
    );
942
  }
943
  return $bibliography_settings;
944
}
945

    
946
/**
947
 * @todo Please document this function.
948
 * @see http://drupal.org/node/1354
949
 */
950
function cdm_dataportal_menu_admin(&$items) {
951
  // Display section on admin/config page.
952
  $items['admin/config/cdm_dataportal'] = array(
953
    'title' => 'CDM Dataportal',
954
    'description' => 'Settings for the CDM DataPortal.',
955
    'position' => 'right',
956
    'weight' => 10,
957
    'page callback' => 'system_admin_menu_block_page',
958
    'access arguments' => array('administer cdm_dataportal'),
959
    'file' => 'system.admin.inc',
960
    'file path' => drupal_get_path('module', 'system'),
961
  );
962
  $items['admin/config/cdm_dataportal/settings'] = array(
963
    'title' => 'Settings',
964
    'description' => 'Settings for the CDM DataPortal.',
965
    'weight' => 0,
966
    'page callback' => 'drupal_get_form',
967
    'page arguments' => array('cdm_settings_general'),
968
    'access arguments' => array('administer cdm_dataportal'),
969
    'type' => MENU_NORMAL_ITEM,
970
  );
971
  $items['admin/config/cdm_dataportal/settings/general'] = array(
972
    'title' => 'General',
973
    'description' => 'General',
974
    'weight' => 0,
975
    'page callback' => 'drupal_get_form',
976
    'page arguments' => array('cdm_settings_general'),
977
    'access arguments' => array('administer cdm_dataportal'),
978
    'type' => MENU_DEFAULT_LOCAL_TASK,
979
  );
980

    
981
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
982
    'title' => 'Cache',
983
    'description' => 'Cache',
984
    'access arguments' => array('administer cdm_dataportal'),
985
    'page callback' => 'drupal_get_form',
986
    'page arguments' => array('cdm_settings_cache'),
987
    'weight' => 10,
988
    'type' => MENU_LOCAL_TASK,
989
  );
990

    
991
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
992
    'title' => 'Geo & Map',
993
    'description' => 'Geo & Map',
994
    'access arguments' => array('administer cdm_dataportal'),
995
    'page callback' => 'drupal_get_form',
996
    'page arguments' => array('cdm_settings_geo'),
997
    'weight' => 1,
998
    'type' => MENU_LOCAL_TASK,
999
  );
1000

    
1001
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1002
    'title' => 'Layout',
1003
    'description' => 'Configure and adjust the layout of your DataPortal ',
1004
    'access arguments' => array('administer cdm_dataportal'),
1005
    'page callback' => 'drupal_get_form',
1006
    'page arguments' => array('cdm_settings_layout'),
1007
    'weight' => 2,
1008
    'type' => MENU_LOCAL_TASK,
1009
  );
1010

    
1011
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1012
    'title' => 'Taxon',
1013
    'description' => 'Configure and adjust the layout of your DataPortal ',
1014
    'access arguments' => array('administer cdm_dataportal'),
1015
    'page callback' => 'drupal_get_form',
1016
    'page arguments' => array('cdm_settings_layout_taxon'),
1017
    'weight' => 1,
1018
    'type' => MENU_LOCAL_TASK,
1019
  );
1020
  /*
1021
  $items[] = array(
1022
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1023
  'title' => t('Synonymy'),
1024
  'description' => t('Configure and adjust the layout of your DataPortal '),
1025
  'access' => user_access('administer cdm_dataportal'),
1026
  'callback' => 'drupal_get_form',
1027
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1028
  'weight' => 1,
1029
  'type' => MENU_LOCAL_TASK,
1030
  );
1031

    
1032
  $items[] = array(
1033
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1034
  'title' => t('Specimens'),
1035
  'description' => t('Configure and adjust the layout of your DataPortal '),
1036
  'access' => user_access('administer cdm_dataportal'),
1037
  'callback' => 'drupal_get_form',
1038
  'callback arguments' => array('cdm_settings_layout_specimens'),
1039
  'weight' => 1,
1040
  'type' => MENU_LOCAL_TASK,
1041
  );
1042
  */
1043
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1044
    'title' => 'Search',
1045
    'description' => 'Configure and adjust the layout of your DataPortal ',
1046
    'access arguments' => array('administer cdm_dataportal'),
1047
    'page callback' => 'drupal_get_form',
1048
    'page arguments' => array('cdm_settings_layout_search'),
1049
    'weight' => 2,
1050
    'type' => MENU_LOCAL_TASK,
1051
  );
1052

    
1053
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1054
    'title' => 'Media',
1055
    'description' => 'Configure and adjust the layout of your DataPortal ',
1056
    'access arguments' => array('administer cdm_dataportal'),
1057
    'page callback' => 'drupal_get_form',
1058
    'page arguments' => array('cdm_settings_layout_media'),
1059
    'weight' => 3,
1060
    'type' => MENU_LOCAL_TASK,
1061
  );
1062

    
1063
}
1064

    
1065
/**
1066
 * @todo document this function.
1067
 */
1068
function cdm_help_general_cache() {
1069
  $form = array();
1070
  $form['cache_help'] = array(
1071
    '#type' => 'fieldset',
1072
    '#title' => t('Help'),
1073
    '#collapsible' => TRUE,
1074
    '#collapsed' => TRUE,
1075
  );
1076
  $form['cache_help']['test'] = array('#value' => t('probando'));
1077
  return drupal_render($form);
1078
  $res = array();
1079
  $res['default'] = drupal_render($help);
1080
  return $res;
1081
}
1082

    
1083
/**
1084
 * Configures the settings form for the CDM-API module.
1085
 *
1086
 * @return array
1087
 *   Drupal settings form.
1088
 */
1089
function cdm_settings_general() {
1090

    
1091
  $form['cdm_webservice'] = array(
1092
    '#type' => 'fieldset',
1093
    '#title' => t('CDM Server'),
1094
    '#collapsible' => FALSE,
1095
    '#collapsed' => FALSE,
1096
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1097
        CDM data base to the web via RESTful web services and thus is the source of the data
1098
        to be displayed by a CDM DataPotal.'),
1099
  );
1100

    
1101
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1102
    '#type' => 'textfield',
1103
    '#title' => t('CDM web service URL') . ':',
1104
    '#description' => t('This is the URL to the CDM-Server exposing your data
1105
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1106
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1107
  );
1108

    
1109
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1110
    '#type' => 'markup',
1111
    '#markup' => '<b>Debug CDM Web Service:</b> Debugging web services is possible via the ' . l('CDM web service debug block', 'admin/structure/block/manage/cdm_api/cdm_ws_debug/configure')
1112
      . ' visible only for administrators',
1113
  );
1114

    
1115
  $form['cdm_webservice']['freetext_index'] = array(
1116
    '#type' => 'fieldset',
1117
    '#title' => t('Freetext index'),
1118
    '#collapsible' => FALSE,
1119
    '#collapsed' => FALSE,
1120
  );
1121

    
1122
  // Check the cdmserver port number and display a waring if it is not port 80
1123
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1124
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1125
    $form['cdm_webservice']['freetext_index']['message'] = array(
1126
      '#markup' => "<div class=\"description\">"
1127
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1128
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1129
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1130
          array('!port' => $portNumberMatch[1][0])
1131
        )
1132
      . "</div>",
1133
    );
1134
  };
1135

    
1136
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1137
  $trigger_link_options = array(
1138
    'attributes' => array(
1139
      'class' => 'index-trigger'
1140
    ),
1141
  );
1142
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1143
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1144
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1145
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1146
      ))
1147
    . '<div id="index-progress"></div></div>',
1148
  );
1149

    
1150
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1151
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1152
    '#type' => 'textfield',
1153
    '#title' => t('Login'),
1154
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1155
  );
1156
  drupal_add_js('
1157
        jQuery(document).ready(function() {
1158
             jQuery("#edit-cdm-login").change(function (e) {
1159
                var login = jQuery(e.target).val();
1160
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1161
                   var url = jQuery(this).attr("href");
1162
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1163
                   jQuery(this).attr("href", url);
1164
                });
1165
            });
1166
        });
1167
      ',
1168
    array(
1169
      'type' => 'inline',
1170
      'scope' => 'footer'
1171
    )
1172
  );
1173
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1174

    
1175
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1176
        '#type' => 'checkbox',
1177
        '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
1178
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1179
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1180
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1181
    );
1182

    
1183
  $form['cdm_webservice']['proxy'] = array(
1184
    '#type' => 'fieldset',
1185
    '#title' => t('Proxy'),
1186
    '#collapsible' => TRUE,
1187
    '#collapsed' => TRUE,
1188
  );
1189

    
1190
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1191
    '#type' => 'textfield',
1192
    '#title' => t('Proxy URL') . ':',
1193
    '#description' => t('If this proxy url is set the cdm api tries
1194
    to connect the web service over the given proxy server.
1195
    Otherwise proxy usage is deactivated.'),
1196
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1197
  );
1198

    
1199
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1200
    '#type' => 'textfield',
1201
    '#title' => t('Proxy port') . ':',
1202
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1203
  );
1204

    
1205
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1206
    '#type' => 'textfield',
1207
    '#title' => t('Login') . ':',
1208
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1209
  );
1210

    
1211
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1212
    '#type' => 'textfield',
1213
    '#title' => t('Password') . ':',
1214
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1215
  );
1216

    
1217
  // TODO: settings are still incomplete, compare with
1218
  // trunk/dataportal/inc/config_default.php.inc.
1219
  $form['taxon_tree'] = array(
1220
    '#type' => 'fieldset',
1221
    '#title' => t('Taxon Tree'),
1222
    '#collapsible' => FALSE,
1223
    '#collapsed' => TRUE,
1224
    '#description' => t('<p>When you explore your collection, you can navigate
1225
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1226
      able to navigate through your collection the
1227
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1228
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1229
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1230
      </a></p>'),
1231
  );
1232

    
1233
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1234
    '#type' => 'select',
1235
    '#title' => t('Default classification') . ':',
1236
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1237
    '#options' => cdm_get_taxontrees_as_options(),
1238
    '#description' => t('The default taxa classification to be used in the whole portal. 
1239
      This affects most obviously the classification browser and the search in case is is restricted 
1240
      to a specific classification. See also <i>Included Classifications</i> below.'),
1241
  );
1242

    
1243
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1244
    '#type' => 'select',
1245
    '#title' => t('Rank of highest displayed taxon') . ':',
1246
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1247
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1248
    '#options' => cdm_rankVocabulary_as_option(),
1249
    '#description' => t('This is the rank of the highest displayed taxon in the
1250
      <em>taxon tree</em>. You can select here which rank should be at the top
1251
      level of the tree structure.'),
1252
  );
1253

    
1254
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1255
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1256
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1257
      '#type' => 'checkboxes',
1258
      '#title' => t('Included Classifications') . ':',
1259
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1260
      '#options' => cdm_get_taxontrees_as_options(),
1261
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1262
  );
1263

    
1264
  $form['distribution'] = array(
1265
      '#type' => 'fieldset',
1266
      '#title' => t('Distributions'),
1267
      '#collapsible' => FALSE,
1268
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1269
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1270
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1271
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1272
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1273
          '<p>
1274
          </p>',
1275
  );
1276

    
1277
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1278
      '#type' => 'fieldset',
1279
      '#title' => 'Distribution filter',
1280
      '#collapsible' => FALSE,
1281
      '#collapsed' => FALSE,
1282
      '#tree' => TRUE,
1283
      '#description' => 'The Distribution filter offers the following options
1284
      <ul>
1285
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1286
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1287
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1288
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1289
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1290
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1291
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1292
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1293
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1294
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1295
      </ul>'
1296
  );
1297

    
1298
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1299
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1300
      '#type' => 'checkboxes',
1301
      '#title' => 'Filter rules',
1302
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1303
      '#options' => array(
1304
          'statusOrderPreference' => 'Status order preference rule',
1305
          'subAreaPreference' => 'Sub area preference rule'
1306
      ),
1307
  );
1308

    
1309
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1310
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1311
      '#type' => 'checkboxes',
1312
      '#title' => 'Hide marked area filter',
1313
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1314
      '#options' => $marker_type_options,
1315
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1316
  );
1317

    
1318
  $form['aggregation'] = array(
1319
      '#type' => 'fieldset',
1320
      '#title' => t('Aggregation of data'),
1321
      '#collapsible' => FALSE,
1322
      '#description' => 'This section covers the different aspects of aggregating information.
1323
          <p>
1324
          </p>',
1325
  );
1326

    
1327
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1328
      '#type' => 'checkboxes',
1329
      '#title' => 'Taxon media filter',
1330
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1331
      '#options' => array(
1332
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1333
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1334
          'includeOccurrences' => 'Media related to specimens and occurrences',
1335
      ),
1336
      '#description' => 'This filter configures which images should be taken into account.',
1337
  );
1338

    
1339
  $form['aggregation']['notice'] = array(
1340
      '#markup' => '<strong>NOTICE:</strong> The below aggregation settings can slow down the data portal, so you may want to sensibly apply these setting and you may also
1341
          want to make use of the caching capabilities of the dataportal.',
1342
  );
1343

    
1344
  $form['aggregation']['media_aggregation'] = array(
1345
      '#type' => 'fieldset',
1346
      '#title' => t('Media aggregation'),
1347
      '#collapsible' => FALSE,
1348
      '#collapsed' => TRUE,
1349
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1350

    
1351
  );
1352
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1353
      '#type' => 'select',
1354
      '#title' => t('Aggregation of taxon pictures') . ':',
1355
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1356
      '#options' => array(
1357
          0 => "Show only pictures of the current taxon",
1358
          1 => "Include pictures of taxonomic children",
1359
      ),
1360
      '#description' => t("Choose whether to include the images of the taxonomic children. This will affect the <em>Images</em> tab and image tumbnails like in the search results."),
1361
  );
1362

    
1363
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1364
      '#type' => 'fieldset',
1365
      '#attributes' => array('class' => array('clearfix')),
1366
      '#title' => t('Aggregation via taxon relationsships'),
1367
      '#collapsible' => TRUE,
1368
      '#collapsed' => TRUE,
1369
      '#tree' => TRUE,
1370
      '#description' => t('Information on taxa will be aggregated along the below chosen
1371
          taxon relation ships. This will affect images and occurrences (specimens).
1372
          Taxon relation ships are directed and point form one taxon to another. The taxon
1373
          relationships to be taken into accunt can therefore configured for the direct direction
1374
          and for the inverse.'),
1375
  );
1376

    
1377
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1378
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1379

    
1380
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1381
      '#type' => 'checkboxes',
1382
      '#title' => t('Direct'),
1383
      '#options' => $taxonRelationshipTypeOptions,
1384
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1385
  );
1386
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1387
      '#type' => 'checkboxes',
1388
      '#title' => t('Invers'),
1389
      '#options' => $taxonRelationshipTypeOptions,
1390
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1391
  );
1392

    
1393
  $form['drupal_integration'] = array(
1394
    '#type' => 'fieldset',
1395
    '#attributes' => array('class'=> array('clearfix')),
1396
    '#title' => t('Drupal integration'),
1397
    '#collapsible' => FALSE,
1398
    '#collapsed' => FALSE,
1399
    '#tree' => FALSE
1400
  );
1401

    
1402
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1403
    '#type' => 'checkbox',
1404
    '#title' => 'Create drupal nodes',
1405
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1406
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1407
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1408
    cdm pages it is required that drupal nodes are created and stored in the database.'
1409
  );
1410

    
1411

    
1412

    
1413
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1414
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1415
    <div class="description">Using this button, you will lose all content associated with the cdm drupal nodes which is stored in the drupal data base.</div>',
1416
  );
1417
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1418
    '#type' => 'submit',
1419
    '#value' => t('Drop all cdm nodes'),
1420
    '#submit' => array('drop_all_cdm_nodes_submit')
1421
  );
1422

    
1423
  $form['drupal_integration']['drop_all_cdm_nodes_warning_post'] = array(
1424
    '#markup' => '<div class="description">All Drupal nodes created for cdm content can be deleted at once using this button.</div>',
1425
  );
1426

    
1427
    // ----------------------
1428
  $form['cdm_js_devel_mode'] = array(
1429
      '#type' => 'checkbox',
1430
      '#title' => 'Java-script developer mode',
1431
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1432
      '#description' => 'In production envirionments the java script libraries
1433
      the cdm_dataportal is making use of are compressed and optimized. This
1434
      is good for performance but a caveat if you need to debug java-script. When the
1435
      java-script developer mode is enabled the uncompressed and commented developer
1436
      versions of java-script libraries will be used where possible.
1437
      <br/><strong>Do not use this option in production!</strong>'
1438
  );
1439
  // ----------------------
1440
  $form['cdm_debug_mode'] = array(
1441
      '#type' => 'checkbox',
1442
      '#title' => 'CDM page debug mode',
1443
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1444
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1445
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1446
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1447
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1448
      The log is written by the drupal devel module function <code>dd()</code>.
1449
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1450
  );
1451

    
1452
  // Comment @WA: D7 form api does not support reset buttons,
1453
  // so to mimic the D5 reset button we add one like this.
1454
  $form['actions']['reset'] = array(
1455
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1456
    '#weight' => 1000,
1457
  );
1458

    
1459
  $form['#submit'][] = 'cdm_settings_general_submit';
1460

    
1461
  return system_settings_form($form);
1462
}
1463

    
1464
/**
1465
 * Submit callback; drops all cdm nodes.
1466
 *
1467
 * @ingroup forms
1468
 */
1469
function drop_all_cdm_nodes_submit($form, &$form_state) {
1470
  cdm_delete_all_cdm_nodes();
1471
  drupal_set_message(t('All cdm nodes dropped.'));
1472
}
1473

    
1474

    
1475
/**
1476
 * LAYOUT settings
1477
 * @return
1478
 *   todo
1479
 */
1480
function cdm_settings_layout() {
1481

    
1482
  $form = array();
1483

    
1484
  $form['about'] = array(
1485
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1486
      layout. If you want to configure the specific sites layout visit the
1487
      respective configuration site for taxon, search or media.') . '</p>',
1488
  );
1489

    
1490
  // ---- footnotes --- //
1491
  $form['footnotes'] = array(
1492
    '#type' => 'fieldset',
1493
    '#title' => t('Footnotes'),
1494
    '#collapsible' => FALSE,
1495
    '#collapsed' => FALSE,
1496
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1497
      media or distribution areas may have annotations or footnotes. When the
1498
      footnotes are enabled they will be visible (if they exist).'),
1499
  );
1500

    
1501
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1502
    '#type' => 'checkbox',
1503
    '#title' => t('Do not show footnotes'),
1504
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1505
    '#description' => t('Check this if you do not want to show any footnotes'),
1506
  );
1507

    
1508
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1509
    '#type' => 'checkbox',
1510
    '#title' => t('Do not show annotation footnotes'),
1511
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1512
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1513
  );
1514

    
1515
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1516
  // Additional option for the NULL case.
1517
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1518
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1519
    '#type' => 'checkboxes',
1520
    '#title' => t('Annotation types as footnotes'),
1521
    '#description' => t("Only annotations of the selected type will be displayed
1522
       as footnotes. You may want to turn 'technical annotations' off."),
1523
    '#options' => $annotationTypeOptions,
1524
  );
1525
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1526
  if (!empty($annotationsTypesAsFootnotes)) {
1527
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1528
  }
1529

    
1530
  // ---- original source --- //
1531
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1532
      '#type' => 'fieldset',
1533
      '#tree' => TRUE,
1534
      '#title' => t('Source Citations'),
1535
      '#collapsible' => FALSE,
1536
      '#collapsed' => FALSE,
1537
  );
1538

    
1539
  $bibliography_settings = get_bibliography_settings(true);
1540

    
1541
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1542
      '#type' => 'checkbox',
1543
      '#title' => t('Original Source in bibliography'),
1544
      '#default_value' => $bibliography_settings['enabled'],
1545
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1546
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1547
       into the bibliography also depends on the settings in the ' .
1548
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1549
        '. For more information please refer to the description on the settings "<em>Sources as content</em>" & "<em>Sources as content to bibliography</em>" in that settings page.'),
1550
  );
1551

    
1552
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1553
    '#type' => 'select',
1554
    '#title' => t('The format of the key numerals'),
1555
    '#default_value' => $bibliography_settings['key_format'],
1556
    '#options' => array('latin' => 'Latin',
1557
      'ROMAN' => 'Roman (upper case)',
1558
      'roman' => 'Roman (lower case)',
1559
      'ALPHA'=> 'Alphabet (upper case)',
1560
      'alpha' => 'Alphabet (lower case)')
1561
  );
1562

    
1563
  // --- Advanced Search --- //
1564
  $form['asearch'] = array(
1565
      '#type' => 'fieldset',
1566
      '#title' => t('Advanced search'),
1567
      '#collapsible' => FALSE,
1568
      '#collapsed' => FALSE,
1569
  );
1570
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1571
      '#type' => 'checkbox',
1572
      '#title' => t('Show advanced search link'),
1573
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1574
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1575
  );
1576

    
1577
  // ---- Taxon Name Rendering --- //
1578
  $form['taxon_name'] = array(
1579
      '#type' => 'fieldset',
1580
      '#title' => t('Taxon name display'),
1581
      '#collapsible' => TRUE,
1582
      '#collapsed' => TRUE,
1583
      '#description' => t('The display of taxon names is configured by two parts.
1584
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1585
          The name parts are defined in the <stong>part definitions</strong>'),
1586
  );
1587

    
1588
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1589
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1590
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1591
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1592

    
1593
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1594
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1595
    $which_version_message = '(These are the old default part definition from before EDIT platform release 3.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1596
  } else if($is_custom_part_definition){
1597
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1598
  } else  {
1599
    $which_version_message = '(These are the default part definition.)';
1600
  }
1601

    
1602
  $diff_viewer_markup = '';
1603
  if($is_custom_part_definition){
1604
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1605
  }
1606

    
1607
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1608
    . $which_version_message
1609
    . '</div>'
1610
    . $diff_viewer_markup;
1611

    
1612
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1613
      '#type' => 'textarea',
1614
      '#title' => t('Part definitions'),
1615
      '#element_validate' => array('form_element_validate_json'),
1616
      '#default_value' =>  $current_part_definition_json,
1617
      '#description' => '
1618
          <p>' . $which_version_message . '</p>
1619
          <p>
1620
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1621
          </p>
1622
          <p>
1623
           A full taxon name plus additional information can consist of the following elements:
1624
          <ul>
1625
             <li>name: the taxon name inclugin rank nbut without author</li>
1626
             <li>authors:  The authors of a reference, also used in taxon names</li>
1627
             <li>reference: the nomenclatural reference,</li>
1628
             <li>microreference:  Volume, page number etc.</li>
1629
             <li>status:  The nomenclatural status of a name</li>
1630
             <li>description: name descriptions like protologues etc ...</li>
1631
          </ul>
1632
          </p>
1633
          <p>
1634
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1635
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1636
           The following parts can be formed and are recognized by the system:
1637
          <ul>
1638
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1639
            <li>authorshipPart: the author (for example: "L.")</li>
1640
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1641
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1642
               be combined when a link to the taxon is rendered.</li>
1643
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1644
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1645
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1646
            <li>statusPart: the nomenclatorical status</li>
1647
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1648
          </ul>
1649
          </p>
1650
          <p>
1651
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1652
           specific parts part definitions:
1653
          <ul>
1654
            <li>BotanicalName</li>
1655
            <li>ZoologicalName</li>
1656
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1657
          </ul>
1658
           An example:
1659
          <pre>
1660
           {
1661
            "ZoologicalName": {
1662
              "namePart": {
1663
                "name": true
1664
              },
1665
              "referencePart": {
1666
                "authors": true
1667
              },
1668
              "microreferencePart": {
1669
                "microreference": true
1670
              },
1671
              "statusPart": {
1672
                "status": true
1673
              },
1674
              "descriptionPart": {
1675
                "description": true
1676
              }
1677
            },
1678
            "BotanicalName": {
1679
              "namePart": {
1680
                "name": true,
1681
                "authors": true
1682
              },
1683
              "referencePart": {
1684
                "reference": true,
1685
                "microreference": true
1686
              },
1687
              "secReferencePart": {
1688
                "secReference": true
1689
              },
1690
              "statusPart": {
1691
                "status": true
1692
              },
1693
              "descriptionPart": {
1694
                "description": true
1695
              }
1696
            }
1697
          }
1698
           </pre>',
1699
  );
1700

    
1701
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1702
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1703
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1704
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1705
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1706

    
1707
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1708
    $which_version_message = '(These are the old default render templates from before EDIT platform release 3.8.0, you may want to reset these by clearing the text area and and submitting the form.)';
1709
  } else if($is_custom_render_template){
1710
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1711
  } else {
1712
    $which_version_message = '(These are the default render templates.)';
1713
  }
1714

    
1715
  $diff_viewer_markup = '';
1716
  if($is_custom_render_template){
1717
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1718
  }
1719

    
1720
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1721
    . $which_version_message
1722
    . '</div>'
1723
    . $diff_viewer_markup;
1724

    
1725
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1726
      '#type' => 'textarea',
1727
      '#title' => t('Name render templates'),
1728
      '#element_validate' => array('form_element_validate_json'),
1729
      '#default_value' =>  $current_render_templates_json,
1730
      '#description' => '
1731
          <p>' . $which_version_message . '</p>
1732
          <p>
1733
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1734
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1735
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1736
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1737
          The following render Path keys are currently recognized:
1738
          <ul>
1739
            <li>list_of_taxa</li>
1740
            <li>acceptedFor</li>
1741
            <li>homonym</li>
1742
            <li>taxon_page_synonymy</li>
1743
            <li>typedesignations</li>
1744
            <li>taxon_page_title</li>
1745
            <li>polytomousKey</li>
1746
            <li>na: name + authorship</li>
1747
            <li>nar:name + authorship + reference</li>
1748
            <li>#DEFAULT</li>
1749
          </ul>
1750
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1751
          array element should be a comma separated list of render paths, without any whitespace!.
1752
          </p>
1753
          <p>
1754
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1755
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1756
          <p>
1757
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1758
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1759
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1760
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1761
          links if the paramters $nameLink or $refenceLink are given to the name render function
1762
          (this is hard coded and cannot be configured here).',
1763
  );
1764

    
1765
  // @WA: D7 form api does not support reset buttons,
1766
  // so to mimic the D5 reset button we add one like this.
1767
  $form['actions']['reset'] = array(
1768
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1769
    '#weight' => 1000,
1770
  );
1771

    
1772
  $form['#submit'] = array('submit_json_as_php_array');
1773
  // #json_elements especially defined for submit_json_as_php_array()
1774
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1775
  return system_settings_form($form);
1776
}
1777

    
1778

    
1779
/**
1780
 * @param $form_name
1781
 * @param $form_title
1782
 * @param $collapsed
1783
 * @param string $form_description
1784
 *   The description for the fieldset of the gallery setting.
1785
 * @return mixed
1786
 */
1787
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1788
  $form[$form_name] = array(
1789
    '#type' => 'fieldset',
1790
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1791
    '#collapsible' => TRUE,
1792
    '#collapsed' => $collapsed,
1793
    '#tree' => TRUE,
1794
    '#description' => $form_description,
1795
  );
1796

    
1797
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1798
  $gallery_settings = variable_get($form_name, $default_values);
1799
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1800
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1801
    /*
1802
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1803
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1804
    '#type' => 'textfield',
1805
    '#title' => t('Search Page Size'),
1806
    '#default_value' => $test,
1807
    '#description' => t('Number of Names to display per page in search results.')
1808
    );
1809
    */
1810
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1811
      '#type' => 'checkbox',
1812
      '#title' => t('Show media thumbnails for accepted taxa'),
1813
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1814
    );
1815

    
1816
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1817
      '#type' => 'checkbox',
1818
      '#title' => t('Show media thumbnails for synonyms'),
1819
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1820
      '#description' => '',
1821
    );
1822
  }
1823

    
1824
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1825
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1826
    '#type' => 'checkbox',
1827
    '#title' => t('Show captions under thumbnails'),
1828
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1829
    '#description' => '',
1830
  );
1831

    
1832
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1833
    '#type' => 'textfield',
1834
    '#title' => t('Thumbnail size') . ':',
1835
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1836
    '#description' => t('Select the size of each individual thumbnail.'),
1837
  );
1838

    
1839
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1840
    '#type' => 'textfield',
1841
    '#title' => t('Number of columns') . ':',
1842
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1843
    '#description' => t('Group the thumbnails in columns: select how many
1844
      columns the gallery should display.'),
1845
  );
1846

    
1847
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1848
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1849
      '#type' => 'textfield',
1850
      '#title' => t('Maximum number of rows') . ':',
1851
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1852
      '#description' => t('You can group the thumbnails in rows, select in how
1853
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1854
        If you want an unlimited number of rows please set to 0.'),
1855
    );
1856
  }
1857

    
1858
  return $form;
1859
}
1860

    
1861
/**
1862
 * @todo document this function.
1863
 */
1864
function cdm_settings_layout_taxon() {
1865
  $collapsed = FALSE;
1866
  $form = array();
1867

    
1868
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1869

    
1870
  // --------- TABBED TAXON ------- //
1871
  $form['taxon_tabs'] = array(
1872
    '#type' => 'fieldset',
1873
    '#title' => t('Taxon tabs'),
1874
    '#collapsible' => TRUE,
1875
    '#collapsed' => TRUE,
1876
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1877
  );
1878

    
1879
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1880
    '#type' => 'checkbox',
1881
    '#title' => t('Tabbed taxon page'),
1882
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1883
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1884
  );
1885

    
1886
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1887
    '#type' => 'checkbox',
1888
    '#title' => t('Synonymy as tab'),
1889
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1890
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1891
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1892
  );
1893

    
1894
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1895
    '#type' => 'checkboxes',
1896
    '#title' => t('Section/Tab visibility') . ':',
1897
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1898
    '#options' => get_taxon_options_list()
1899
  );
1900

    
1901
  // WEIGHT
1902
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1903
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1904
    '#title'  => 'Section/Tab order',
1905
    '#type' => 'fieldset',
1906
    '#collapsible' => false,
1907
    '#tree' => true,
1908
    '#description' => 'The weight value defines the order of the section/tab.'
1909
  );
1910
  // Weights range from -delta to +delta, so delta should be at least half
1911
  // of the amount of tabs present.
1912
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1913
  foreach (get_taxon_tabs_list() as $label) {
1914
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1915
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1916
        '#title' => $label,
1917
        '#type'  => 'weight',
1918
        '#default_value' => $taxon_tabs_weights[$key],
1919
        '#delta' => $tab_weight_delta
1920
    );
1921
  }
1922

    
1923
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1924
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1925
    '#title'  => 'Section/Tab label override',
1926
    '#type' => 'fieldset',
1927
    '#collapsible' => false,
1928
    '#tree' => true,
1929
    '#description' => 'Setting a label for a section/tab will override the default label. 
1930
      Please enter the label text in the default language of the portal.'
1931
  );
1932
  foreach (get_taxon_tabs_list() as $label) {
1933
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1934
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1935
      '#title' => $label,
1936
      '#type'  => 'textfield',
1937
      '#default_value' => $taxon_tabs_labels[$key]
1938
    );
1939
  }
1940

    
1941
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1942
    '#type' => 'select',
1943
    '#title' => t('Default tab to display') . ':',
1944
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1945
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1946
    '#description' => t('<p>Select the default tab to display when visiting a
1947
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1948
      <strong>Note:</strong> After performing a search and clicking in any
1949
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1950
      taxon and not the above selected tab.'),
1951
  );
1952

    
1953
  /* ======  TAXON_PROFILE ====== */
1954
  $form['taxon_profile'] = array(
1955
    '#type' => 'fieldset',
1956
    '#title' => t('Taxon profile (tab)'),
1957
    '#description' => t('<p>This section covers the settings related to the taxon
1958
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1959
    '#collapsible' => TRUE,
1960
    '#collapsed' => TRUE,
1961
  );
1962

    
1963
  // ---- PROFILE PICTURE ----//
1964

    
1965
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1966
    '#type' => 'fieldset',
1967
    '#tree' => TRUE,
1968
    '#title' => t('Taxon profile picture'),
1969
    '#collapsible' => TRUE,
1970
    '#collapsed' => FALSE,
1971
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1972
  );
1973

    
1974
  //FIXME migrate variables:
1975
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1976
  // FIXME
1977
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1978

    
1979
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1980

    
1981
  /*
1982
   * 'show' => 1,
1983
   * 'maxextend' => 184,
1984
   * 'media_uri_query' => ''
1985
   * 'custom_placeholder_image_on' => 1,
1986
   * 'custom_placeholder_image_fid' => ''
1987
   */
1988
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1989
    '#type' => 'checkbox',
1990
    '#title' => t('Enable profile picture'),
1991
    '#description' => t('Show the profile picture.'),
1992
    '#default_value' => $taxon_profile_image_settings['show'],
1993
  );
1994

    
1995
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1996
      '#type' => 'textfield',
1997
      '#tree' => TRUE,
1998
      '#title' => t('Profile picture maximum extend'),
1999
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2000
      '#field_suffix' => 'px',
2001
      '#maxlength' => 4,
2002
      '#size' => 4,
2003
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2004
  );
2005

    
2006
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2007
      '#type' => 'textfield',
2008
      '#tree' => TRUE,
2009
      '#title' => t('Additional URI query parameter'),
2010
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2011
      '#maxlength' => 1024,
2012
      '#size' => 60,
2013
      '#description' => t('Additional query parameters to be used when requesting for the  
2014
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2015
            The query parameters will be appended to the uri of the media representation part
2016
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2017
  );
2018

    
2019
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2020
    '#type' => 'checkbox',
2021
    '#title' => t('Show the placeholder image'),
2022
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2023
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2024
  );
2025

    
2026
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2027
      '#type' => 'checkbox',
2028
      '#title' => t('Use a custom placeholder image'),
2029
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2030
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2031
  );
2032

    
2033
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2034
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2035
        '#type' => 'managed_file',
2036
        '#title' => t('Custom placeholder image file'),
2037
        '#progress_indicator' => 'bar',
2038
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2039
    //       '#name' => 'custom_placeholder_image',
2040
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2041
    );
2042

    
2043
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2044
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2045
      $url = file_create_url($profile_image_file->uri);
2046
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2047
                '#type' => 'item',
2048
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2049
      );
2050
    }
2051
  } else {
2052
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2053
      '#type' => 'hidden',
2054
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2055
    );
2056
  }
2057

    
2058
  $options = cdm_rankVocabulary_as_option();
2059
  array_unshift($options, '-- DISABLED --');
2060
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2061
    '#type' => 'select',
2062
    '#title' => t('Hide profile picture for higher ranks') . ':',
2063
    '#default_value' => variable_get('image_hide_rank', '0'),
2064
    '#options' => $options,
2065
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2066
  );
2067

    
2068
  // -- MEDIA THUMBNAILS -- //
2069
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2070
  $form_title = 'Taxon Profile Images';
2071
  $form_description = '<p>The different section in the taxon  profile can have images associated with them. These images are displayed in a gallery of thumbnails wich can be configuered here:</p>';
2072
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2073

    
2074
  // ---- FEATURE TREE BLOCKS ---- //
2075
  $form['taxon_profile']['feature_blocks'] = array(
2076
    '#type' => 'fieldset',
2077
    '#title' => t('Feature Blocks'),
2078
    '#collapsible' => TRUE,
2079
    '#collapsed' => FALSE,
2080
    '#description' => t("This section covers settings related to the taxon's
2081
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2082
      features such as description, distribution, common names"),
2083
  );
2084
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2085
  $profile_feature_tree = get_profile_feature_tree();
2086
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2087
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2088
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2089
  }
2090
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2091
    '#type' => 'radios',
2092
    '#title' => t('Taxon profile feature tree') . ':',
2093
    '#default_value' => $profile_feature_tree_uuid,
2094
    '#options' =>  $featureTrees['options'],
2095
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2096
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2097
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2098
      profile page.'
2099
    ),
2100
  );
2101

    
2102
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2103
  $profile_feature_tree = get_profile_feature_tree();
2104

    
2105
  if (isset($profile_feature_tree->root->childNodes)) {
2106

    
2107
    $form_feature_block_layout = array(
2108
      '#type' => 'fieldset',
2109
      '#tree' => true,
2110
      '#title' => t('Taxon profile feature block settings'),
2111
      '#collapsible' => TRUE,
2112
      '#collapsed' => FALSE,
2113
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2114
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2115
      The subforms have the following settings in common:<br />
2116
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2117
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2118
      <h6>Link to name used in source:</h6><div>Whether to show name in source information as link which will point to the according name page</div>
2119
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2120
            <ol>
2121
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2122
                appended in brackets like "text (source references)". If the original source has name in source
2123
                information it will be appended to the citation string,
2124
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2125
             <li>if the text of the TextData is empty, the original source citations are the only content
2126
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2127
                prepended to the citation string like: "name in source: citation"</li>
2128
            </ol>
2129
            <strong>If disabled:</strong><br />
2130
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2131
             citations are the only content, the resulting feature block content would only consist of footnotes.
2132
             In this case the display of the respective feature block is suppressed.</div>
2133
      </dl>
2134
      <h6>Sources as content to bibliography:</h6><div>Only valid if <em>Sources as content</em> is enabled, will cause the sources to be also shown
2135
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2136
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2137
        . '</em></div>
2138
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2139
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2140
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2141
      <h6>Element tag:</h6><div>The tag to be used for creating the elements, only applies if "List type" is set to <em>No list</em>
2142
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2143
           cdm_feature_block_element_tag_name()</div>
2144
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2145
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2146
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2147
    );
2148

    
2149

    
2150
    $feature_list_layout_settings_disabled = FALSE;
2151

    
2152
    // creating helper object to retrieve the default settings
2153
    $featureNode = new stdClass();
2154
    $featureNode->feature = new stdClass();
2155
    $featureNode->feature->uuid="DEFAULT";
2156
    $featureNode->feature->representation_L10n = "Default";
2157
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2158

    
2159
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2160

    
2161
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2162

    
2163
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2164
        $subform_id = $featureNode->feature->uuid;
2165
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2166

    
2167
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2168

    
2169
        $form_feature_block_layout[$subform_id] = array(
2170
          '#type' => 'fieldset',
2171
          '#tree' => TRUE,
2172
          '#title' => $featureNode->feature->representation_L10n,
2173
          '#collapsible' => FALSE,
2174
          '#collapsed' => FALSE,
2175
        );
2176
        if($featureNode->feature->uuid == "DEFAULT"){
2177
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2178
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2179
          references</em> and <em>names in source</em> is only possible in the defaults';
2180
        }
2181

    
2182
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2183
          '#type' => 'select',
2184
          '#title' => 'List type',
2185
          '#default_value' => $feature_block_setting['as_list'],
2186
          '#options' => array(
2187
            'div' => 'not as list',
2188
            'ul' => 'bullet list',
2189
            'ol' => 'numbered list',
2190
            'dl' => 'definition list'
2191
          ),
2192
        );
2193

    
2194
        if($featureNode->feature->uuid == "DEFAULT"){
2195
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2196
            '#type' => 'checkbox',
2197
            '#title' => t('Link to reference'),
2198
            '#default_value' => $feature_block_setting['link_to_reference'],
2199
          );
2200

    
2201
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2202
            '#type' => 'checkbox',
2203
            '#title' => 'Link to name used in source',
2204
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2205
          );
2206
        }
2207

    
2208
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2209
          '#type' => 'checkbox',
2210
          '#title' => 'Sources as content',
2211
          '#default_value' => $feature_block_setting['sources_as_content'],
2212
        );
2213

    
2214
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2215
          '#type' => 'checkbox',
2216
          '#title' => 'Put sources also as content to bibliography',
2217
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2218
        );
2219

    
2220
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2221
          '#type' => 'select',
2222
          '#title' => t('Sort elements'),
2223
          '#default_value' => $feature_block_setting['sort_elements'],
2224
          '#options' => array(
2225
            NO_SORT => 'No sorting',
2226
            SORT_ASC => 'Ascending',
2227
            SORT_DESC => 'Descending',
2228
            SORT_HIERARCHICAL => 'Hierarchical'
2229
          ),
2230
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2231
          <dl>
2232
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2233
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2234
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2235
          <dr><dt>Hierarchical</dt><dd>Use the order of items and their hierarchy. This is not possible for all feature and item types.</dd></dr>
2236
          </dl>',
2237
        );
2238

    
2239
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2240
          '#type' => 'select',
2241
          '#title' => t('Element tag'),
2242
          '#options' => array(
2243
            'span' => 'span',
2244
            'div' => 'div',
2245
            'p' => 'p'
2246
          ),
2247
          '#default_value' => $feature_block_setting['element_tag'],
2248
        );
2249
        $form_feature_block_layout[$subform_id]['glue'] = array(
2250
          '#type' => 'textfield',
2251
          '#title' => t('Element glue'),
2252
          '#default_value' => $feature_block_setting['glue'],
2253
          '#size' => 10
2254
      );
2255

    
2256
      }
2257
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2258
    }
2259
  }
2260

    
2261
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2262
  $form['taxon_profile']['structured_description_featuretree'] = array(
2263
    '#type' => 'fieldset',
2264
    '#title' => t('Structured Description Feature Tree'),
2265
    '#collapsible' => TRUE,
2266
    '#collapsed' => FALSE,
2267
  );
2268
  $featureTrees = cdm_get_featureTrees_as_options();
2269
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2270
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2271
    $profile_feature_tree_uuid = NULL;
2272
  }
2273
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2274
    '#type' => 'radios',
2275
    '#title' => t('Natural language representation of structured descriptions') . ':',
2276
    '#default_value' => $profile_feature_tree_uuid,
2277
    '#options' => $featureTrees['options'],
2278
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2279
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2280
    '#description' => t('Taxon descriptions can be stored in a highly structured
2281
      form. The feature tree selected here will be used to generate textual
2282
      representation in natural language.'
2283
    ),
2284
  );
2285

    
2286

    
2287

    
2288
  // ---- DISTRIBUTION LAYOUT ---- //
2289
  $form['taxon_profile']['distribution_layout'] = array(
2290
    '#title' => t('Distribution'),
2291
    '#collapsible' => TRUE,
2292
    '#collapsed' => FALSE,
2293
    '#type' => 'fieldset',
2294
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2295
        Map settings regarding the geometry, layers, etc are found in the '
2296
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2297
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2298
      . l(
2299
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2300
        array('fragment' => 'edit-feature-block-settings')
2301
      )
2302
      . ' More general settings regrading the filtering of Distributions are found at '
2303
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2304
      . '. (These settings here will be merged in future releases into the feature block settings)',
2305

    
2306
  );
2307

    
2308
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2309

    
2310
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2311
    '#type' => 'checkbox',
2312
    '#title' => t('Condensed distribution'),
2313
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2314
    '#description' => 'This option enables the display of a very compact representation
2315
    of the distribution which includes also information on the status.',
2316
  );
2317

    
2318
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2319
    '#type' => 'select',
2320
    '#title' => t('Condensed distribution recipe'),
2321
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2322
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2323
    '#description' => 'Recipe for creating the condensed distribution.',
2324
  );
2325

    
2326
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2327
    '#type' => 'textfield',
2328
    '#title' => t('Condensed distribution info path'),
2329
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2330
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2331
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2332
  );
2333

    
2334

    
2335
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2336
    '#type' => 'radios',
2337
    '#title' => t('Display mode') . ':',
2338
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2339
    '#options' => array(
2340
      'FLAT_ALPHA' => t('Flat list'),
2341
      'TREE' => t('Hierarchically ordered'),
2342
    ),
2343
    '#description' => 'Taxon distribution information is displayed with
2344
    focus on the area of the distribution. The list of areas can either be shown
2345
    as flat list ordered alphabetically or in the hierarchical of the parent
2346
    area and subarea relationship. Fall back areas areas with no Distribution data
2347
    are hidden from the area hierarchy so that their sub areas will move one level up.
2348
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2349
    ' for details on the <em>Marked area filter</em>.',
2350
  );
2351

    
2352
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2353
    '#type' => 'fieldset',
2354
    '#tree' => true,
2355
    '#title' => t('Distribution hierarchy style')
2356
  );
2357

    
2358
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2359
  foreach(array_keys($hierarchy_styles) as $level) {
2360
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2361
      '#type' => 'fieldset',
2362
      '#tree' => true,
2363
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2364
      '#attributes' => array('class' => array('fieldset-float'))
2365
    );
2366
    foreach ($hierarchy_styles[$level] as $key => $value) {
2367
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2368
        '#type' => 'textfield',
2369
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2370
        '#default_value' => $hierarchy_styles[$level][$key],
2371
        '#maxlength' => 4,
2372
        '#size' => 4
2373
      );
2374
    }
2375
  }
2376

    
2377
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2378
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2379
    '#type' => 'checkboxes',
2380
    '#title' => 'Omit area levels',
2381
    '#options' => $level_options,
2382
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2383
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2384
    Areas which belong to the selected area levels will be hidden in the portal.',
2385
  );
2386

    
2387
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2388
    '#type' => 'checkbox',
2389
    '#title' => t('Show TextData elements on top of the map'),
2390
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2391
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2392
      elements on top of the map. Otherwise all <code>TextData</code>
2393
      distribution elements will be listed below the other area elements.
2394
      This option is useful if you need to have descriptive texts for each
2395
      distribution map.'),
2396
  );
2397

    
2398
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2399
      '#type' => 'textarea',
2400
      '#title' => t('Custom status colors'),
2401
      '#element_validate' => array('form_element_validate_json'),
2402
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2403
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2404
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2405
          reference list of the idInVocabulary values of absence and presence terms:
2406
<pre>
2407
Presence Term
2408
p	present
2409
pd	present: doubtfully present
2410
n	native
2411
nq	native: presence questionable
2412
nd	native: doubtfully native
2413
c	cultivated
2414
i	introduced
2415
iq	introduced: presence questionable
2416
id	introduced: doubtfully introduced (perhaps cultivated only)
2417
ip	introduced: uncertain degree of naturalisation
2418
ia	introduced: adventitious (casual)
2419
in	introduced: naturalized
2420
ic	introduced: cultivated
2421
e	endemic for the relevant area
2422
na	naturalised
2423
iv	invasive
2424

    
2425
AbsenceTerm
2426
a	absent
2427
f	reported in error
2428
nf	native: reported in error
2429
if	introduced: reported in error
2430
cf	cultivated: reported in error
2431
ne	native: formerly native
2432
ie	introduced: formerly introduced
2433

    
2434
</pre>'),
2435
  );
2436

    
2437

    
2438
  /* ====== SYNONYMY ====== */
2439
  $form['taxon_synonymy'] = array(
2440
    '#type' => 'fieldset',
2441
    '#title' => t('Taxon synonymy (tab)'),
2442
    '#collapsible' => TRUE,
2443
    '#collapsed' => TRUE,
2444
    '#description' => t('This section covers the settings related to the taxon
2445
      <strong>synonymy</strong> tab.'),
2446
  );
2447

    
2448
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2449
    '#type' => 'checkbox',
2450
    '#title' => t('Show accepted taxon on top of the synonymy'),
2451
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2452
    '#description' => t('If checked, the first homotypic taxon is a repetition
2453
      of the accepted taxon most likely with the full nomenclatural reference
2454
      (depending on the currently chosen theme).'),
2455
  );
2456

    
2457
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2458
    '#type' => 'checkbox',
2459
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2460
      coming from a synonym link.'),
2461
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2462
    '#description' => t('Check this if after doing a search and clicking on a
2463
      synonym you want to see the "accept of" text for the accepted synonym.'),
2464
  );
2465

    
2466
  /* === currently unused ===
2467
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2468
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2469
    '#type' => 'checkboxes',
2470
    '#title' => t('Display name relationships') . ':',
2471
    '#default_value' => variable_get('name_relationships_to_show', 0),
2472
    '#options' => $nameRelationshipTypeOptions,
2473
    '#description' => t('Select the name relationships you want to show for the
2474
      accepted taxa.'),
2475
  );
2476
 */
2477

    
2478
  $form['taxon_synonymy']['taxon_relations'] = array(
2479
    '#type' => 'fieldset',
2480
    '#title' => t('Taxon relationships'),
2481
    '#collapsible' => FALSE,
2482
    '#collapsed' => FALSE
2483
  );
2484

    
2485
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2486
    '#type' => 'checkbox',
2487
    '#title' => t('Show taxon relations ships of accepted taxon'),
2488
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2489
    '#description' => t('If this option is enabled the synonymy will show the
2490
      below selected taxon relationships of accepted taxa.'),
2491
  );
2492

    
2493
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2494
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2495
    '#type' => 'checkboxes',
2496
    '#title' => t('Taxon relationship types') . ':',
2497
    '#description' => t('Only taxon relationships of the selected type will be
2498
      displayed'),
2499
    '#options' => $taxonRelationshipTypeOptions,
2500
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2501
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2502
  );
2503

    
2504
  $form['taxon_synonymy']['name_relations'] = array(
2505
    '#type' => 'fieldset',
2506
    '#title' => t('Name relationships'),
2507
    '#collapsible' => FALSE,
2508
    '#collapsed' => FALSE
2509
  );
2510

    
2511
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2512
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2513
    '#type' => 'checkboxes',
2514
    '#title' => t('Name relationship types') . ':',
2515
    '#description' => t('Only name relationships of the selected type will be
2516
      displayed'),
2517
    '#options' => $taxonRelationshipTypeOptions,
2518
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2519
  );
2520

    
2521
  // ====== SPECIMENS ====== //
2522
  $form['taxon_specimens'] = array(
2523
    '#type' => 'fieldset',
2524
    '#title' => t('Taxon specimens (tab)'),
2525
    '#collapsible' => TRUE,
2526
    '#collapsed' => TRUE,
2527
    '#description' => t('This section covers the settings related to the taxon
2528
      <strong>specimens</strong> tab.'),
2529
  );
2530

    
2531
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2532

    
2533
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2534
    '#type' => 'checkbox',
2535
    '#title' => t('Show specimen derivatives in a compressed table'),
2536
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2537
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2538
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2539
  );
2540

    
2541
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2542
        '#type' => 'textfield',
2543
        '#title' => t('Number of records per page') . ':',
2544
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2545
    );
2546

    
2547
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2548
    '#type' => 'checkbox',
2549
    '#title' => t('Show "Associated with" in specimen table.'),
2550
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2551
  );
2552

    
2553
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2554
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2555
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2556
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2557
  }
2558
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2559
    '#type' => 'radios',
2560
    '#title' => t('Specimen description feature tree') . ':',
2561
    '#default_value' => $profile_feature_tree_uuid,
2562
    '#options' =>  $featureTrees['options'],
2563
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2564
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2565
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2566
    ),
2567
  );
2568

    
2569
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2570
  $form_title = t('Specimen media');
2571
  $form_description = t('Specimens may have media which is displayed at the
2572
     Specimen tab/section as a gallery. It is possible to configure the
2573
     thumbnails gallery here, however for configuring how a single media should
2574
     be displayed please go to !url.</p>',
2575
     array(
2576
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2577
     ));
2578
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2579

    
2580
  // --- MEDIA GALLERY ---- //
2581
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2582
  $form_title = 'Media gallery (tab)';
2583
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2584
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2585
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2586
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2587
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2588
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2589
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2590

    
2591
  // Comment @WA: D7 form api does not support reset buttons,
2592
  // so to mimic the D5 reset button we add one like this.
2593
  $form['actions']['reset'] = array(
2594
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2595
    '#weight' => 1000,
2596
  );
2597
  return system_settings_form($form);
2598
}
2599

    
2600
/**
2601
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2602
 *
2603
 * @param $map_id
2604
 * @param $form
2605
 * @return mixed
2606
 */
2607
function _cdm_map_visibility_setting($map_id)
2608
{
2609
  return array(
2610
    '#type' => 'select',
2611
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2612
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2613
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2614
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2615
        The map also can forced to show up <b>always</b> or <b>never</b>."
2616
  );
2617
}
2618

    
2619
/**
2620
 * @todo document this function.
2621
 */
2622
function cdm_settings_layout_search() {
2623

    
2624
  $form = array();
2625

    
2626
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2627

    
2628
  $form['search_settings'] = array(
2629
    '#type' => 'fieldset',
2630
    '#title' => t('Taxa Search'),
2631
    '#collapsible' => FALSE,
2632
    '#collapsed' => FALSE,
2633
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2634
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2635
         where they can write the text to be searched. You can find Drupal block configuration
2636
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2637
  );
2638

    
2639
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2640
      '#type' => 'checkbox',
2641
      '#title' => t('Ignore the chosen classification in simple search'),
2642
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2643
      '#description' => t('The simple search, which can be executed via the search block,
2644
          will by default search on the classification selected in the classification browser
2645
          selector. Set the tick if you want your portal to search on all classifications.'),
2646
  );
2647

    
2648
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2649
    '#type' => 'checkbox',
2650
    '#title' => t('Run simple search with free-text search backend.'),
2651
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2652
    '#description' => t('The simple search uses by default another search
2653
      backend as the advances search. By checking this option the simple search can be
2654
      configured to also use the free-text search backend.'),
2655
  );
2656

    
2657
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2658
    '#type' => 'textfield',
2659
    '#title' => t('Results per page') . ':',
2660
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2661
    '#description' => t('Number of results to display per page.'),
2662
  );
2663

    
2664
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2665
    '#type' => 'checkbox',
2666
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2667
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2668
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2669
  );
2670

    
2671
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2672
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2673
      '#type' => 'checkboxes',
2674
      '#title' => 'Search mode',
2675
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2676
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2677
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2678
          defaults set here.',
2679
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2680
      '#default_value' => $search_mode_default
2681
      );
2682

    
2683
  $form['search_settings'][CDM_SEARCH_AREA_FILTER_PRESET] = array(
2684
    '#type' => 'textarea',
2685
    '#title' => t('area_filter_preset') . ':',
2686
    '#default_value' => variable_get(CDM_SEARCH_AREA_FILTER_PRESET, ''), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2687

    
2688
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2689
  );
2690

    
2691
  // --- SEARCH TAXA GALLERY ---- //
2692
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2693
  $collapsed = FALSE;
2694
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2695
  $form_title = 'Taxa Search thumbnails';
2696
  $form_description = 'Search results may show thumbnails. ';
2697
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2698

    
2699
  // Comment @WA: D7 form api does not support reset buttons,
2700
  // so to mimic the D5 reset button we add one like this.
2701
  $form['actions']['reset'] = array(
2702
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2703
    '#weight' => 1000,
2704
  );
2705
  return system_settings_form($form);
2706
}
2707

    
2708
/**
2709
 * @todo document this function.
2710
 */
2711
function cdm_settings_layout_media() {
2712

    
2713
  $form = array();
2714

    
2715
  $form['media_settings'] = array(
2716
    '#type' => 'fieldset',
2717
    '#title' => t('Media settings'),
2718
    '#collapsible' => FALSE,
2719
    '#collapsed' => FALSE,
2720
    '#description' => 'This section covers layout settings for media pages.'
2721
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2722
  );
2723

    
2724
  $form['media_settings']['image_gallery_viewer'] = array(
2725
    '#type' => 'select',
2726
    '#title' => t('Image viewer') . ':',
2727
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2728
    '#options' => array(
2729
      'default' => t('Standard image viewer'),
2730
      'fsi' => t('FSI viewer (requires FSI server!)'),
2731
    ),
2732
  );
2733

    
2734
  // --- STANDARD_IMAGE_VIEWER ---- //
2735
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2736
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2737
      '#type' => 'fieldset',
2738
      '#tree' => true,
2739
      '#title' => t('Standard image viewer settings'),
2740
      '#collapsible' => FALSE,
2741
      '#collapsed' => FALSE,
2742
      );
2743

    
2744
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2745
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2746
      '#type' => 'checkbox',
2747
      '#title' => 'Show media representations',
2748
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2749

    
2750
    );
2751
  }
2752

    
2753

    
2754
  // @WA: D7 form api does not support reset buttons,
2755
  // so to mimic the D5 reset button we add one like this.
2756
  $form['actions']['reset'] = array(
2757
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2758
    '#weight' => 1000,
2759
  );
2760
  return system_settings_form($form);
2761
}
2762

    
2763
/**
2764
 * GEOSERVICE and Map settings.
2765
 */
2766
function cdm_settings_geo($form, &$form_state) {
2767

    
2768
  $current_geoserver_settings = get_edit_map_service_settings();
2769
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2770

    
2771

    
2772
  $form = array();
2773

    
2774
  $dummy_distribution_query = NULL;
2775
  if($map_distribution['map_type'] != 1){
2776
    // we need to apply a dummy query since the map service requires for image maps
2777
    // at least as and ad to be defined
2778
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2779
  }
2780

    
2781
  $form['map_preview'] = array(
2782
      '#type' => 'fieldset',
2783
      '#tree' => FALSE,
2784
      '#title' => t('Map preview'),
2785
      '#collapsible' => FALSE,
2786
      '#description' => 'The preview of the map'
2787
       . ($dummy_distribution_query != null ?
2788
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2789
           '.<br/>Hold down Strg and drag with your mouse to select a bbox to zoom to. <br/>The bbox of the visible area of the map is always displayed below the map.')
2790
  );
2791
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2792
    'move' => "this.cdmOpenlayersMap.printInfo",
2793
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2794
  ), true // resizable
2795
  );
2796

    
2797
  /*
2798
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2799
  );
2800
  */
2801

    
2802
  /*
2803
   * GEO SERVER
2804
   */
2805
  $form['edit_map_server'] = array(
2806
    '#type' => 'fieldset',
2807
    '#tree' => true,
2808
    '#title' => t('EDIT map service'),
2809
    '#collapsible' => TRUE,
2810
    '#collapsed' => TRUE,
2811
    '#description' => t('Configuration and selection of your geo server.
2812
      The Geo Server is responsible for generating the maps.'),
2813
  );
2814

    
2815
  $form['edit_map_server']['base_uri'] = array(
2816
    '#type' => 'select',
2817
    '#title' => t('EDIT map service') . ':',
2818
    '#default_value' => $current_geoserver_settings['base_uri'],
2819
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2820
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2821
  );
2822
  $form['edit_map_server']['version'] = array(
2823
      '#type' => 'select',
2824
      '#title' => t('Version') . ':',
2825
      '#default_value' => $current_geoserver_settings['version'],
2826
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2827
      '#description' => t('The version of the EDIT map services'),
2828
  );
2829

    
2830
  /*
2831
   * MAP SETTINGS
2832
   */
2833

    
2834
  $form[CDM_MAP_DISTRIBUTION] = array(
2835
    '#type' => 'fieldset',
2836
    '#tree' => TRUE,
2837
    '#title' => t('Maps settings'),
2838
    '#collapsible' => TRUE,
2839
    '#collapsed' => TRUE,
2840
    '#description' => t('General configuration for all map types.'),
2841
  );
2842

    
2843
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2844
    '#type' => 'radios',
2845
    '#title' => 'Map types',
2846
    '#options' => array(
2847
      1 => "OpenLayers dynamic map viewer",
2848
      0 => "Plain image",
2849
    ),
2850
    '#default_value' => $map_distribution['map_type'],
2851
    '#description' => 'Two different map types are available :
2852
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2853
      which allows zooming and panning. If enabled you can configure the default layer
2854
      (background of your maps) below.</li>
2855
      <li><em>Plain image</em>: The map will be static non interactive
2856
      image.</li></ul>',
2857
  );
2858
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2859

    
2860
  /*
2861
   * settings for the distribution map are used also for specimens map!!!!
2862
   */
2863

    
2864
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2865
      '#type' => 'textfield',
2866
      '#title' => 'Aspect ratio',
2867
      '#default_value' => $map_distribution['aspect_ratio'],
2868
      '#maxlength' => 4,
2869
      '#size' => 4,
2870
      '#element_validate' => array('element_validate_number'),
2871
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2872
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2873
      width by the height:</br>
2874
      <pre>aspect ratio = w / h</pre>
2875
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2876
      for a square map use <strong>1</strong>.',
2877
  );
2878

    
2879
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2880
    '#type' => 'textfield',
2881
    '#title' => 'Bounding box',
2882
    '#default_value' => $map_distribution['bbox'],
2883
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2884
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2885
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2886
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong>map extent bbox</strong> in <strong class="degree-value"">degree</strong></span> from the map.
2887
      (Maybe you need to change the map base layer to OpeLayers.)
2888
      Hold down Strg and drag with your mouse to select a bbox to zoom to. The bbox of the visible area of the map is always displayed
2889
      below the map from where you can copy the bbox string.</p>'),
2890
  );
2891

    
2892
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2893
    '#type' => 'select',
2894
    '#title' => 'Max zoom level',
2895
    '#default_value' => $map_distribution['maxZoom'],
2896
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2897
  );
2898

    
2899
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2900
    '#type' => 'checkbox',
2901
    '#title' => 'Display area labels',
2902
    '#default_value' => $map_distribution['show_labels'],
2903
    '#description' => t('The map will show name labels of the areas'),
2904
  );
2905

    
2906
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2907
    '#type' => 'textfield',
2908
    '#title' => 'Map caption',
2909
    '#default_value' => $map_distribution['caption'],
2910
    '#description' => t('The caption will be shown below the map.'),
2911
  );
2912

    
2913
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2914
    '#type' => 'textfield',
2915
    '#title' => 'Distribution layer opacity',
2916
    '#default_value' => $map_distribution['distribution_opacity'],
2917
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2918
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2919
  );
2920

    
2921
  // --- Plain Image Settings --- //
2922
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2923
    '#type' => 'fieldset',
2924
    '#title' => 'Plain image map settings',
2925
    '#tree' => TRUE,
2926
    '#collapsible' => TRUE,
2927
    '#collapsed' => $open_layers_is_enabled,
2928
    '#description' => 'The settings in this section are still expertimental
2929
      and can only be used with the EDIT map service version 1.1 or above.',
2930
  );
2931
  $edit_mapserver_version = get_edit_map_service_version_number();
2932
  if ($edit_mapserver_version < 1.1) {
2933
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2934
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2935
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2936
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2937
  }
2938

    
2939
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2940
    '#type' => 'textfield',
2941
    '#title' => 'Width',
2942
    '#default_value' => $map_distribution['image_map']['width'],
2943
    '#maxlength' => 4,
2944
    '#size' => 4,
2945
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2946
  );
2947

    
2948
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2949
    '#type' => 'textfield',
2950
    '#title' => 'Background layer',
2951
    '#default_value' => $map_distribution['image_map']['base_layer'],
2952
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2953
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2954
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2955
    )),
2956
  );
2957

    
2958
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2959
    '#type' => 'textfield',
2960
    '#title' => 'Background color',
2961
    '#default_value' => $map_distribution['image_map']['bg_color'],
2962
  );
2963

    
2964
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2965
    '#type' => 'textfield',
2966
    '#title' => 'Background layer style',
2967
     // Only line color by now.
2968
    '#default_value' => $map_distribution['image_map']['layer_style'],
2969
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2970
  );
2971

    
2972
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2973
      '#type' => 'textfield',
2974
      '#title' => 'Projection',
2975
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2976
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2977
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2978
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2979
  );
2980

    
2981

    
2982
  // --- OpenLayers Settings --- //
2983
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2984
    '#type' => 'fieldset',
2985
    '#title' => 'OpenLayers settings',
2986
    '#tree' => TRUE,
2987
    '#collapsible' => TRUE,
2988
    '#collapsed' => !$open_layers_is_enabled,
2989
    '#description' => '',
2990
  );
2991

    
2992

    
2993
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2994
      '#type' => 'checkbox',
2995
      '#title' => 'Display outside max extent',
2996
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2997
      '#description' => t('Allows the map to display parts of the layers which are outside
2998
         the max extent if the aspect ratio of the map and of the baselayer
2999
         are not equal.'),
3000
  );
3001

    
3002

    
3003
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3004
      '#type' => 'checkbox',
3005
      '#title' => 'Show Layer Switcher',
3006
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3007
      '#description' => 'The Layer Switcher control displays a table of contents
3008
      for the map.  This allows the user interface to switch between
3009
      base layers and to show or hide overlays.  By default the switcher is
3010
      shown minimized on the right edge of the map, the user may expand it
3011
      by clicking on the handle.',
3012
  );
3013

    
3014
  if (!$open_layers_is_enabled) {
3015
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3016
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3017
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3018
  }
3019

    
3020
  // The default layer must always be enabled
3021
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3022
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3023

    
3024
  $baselayer_options = array(
3025
    /*
3026
   NOTICE: must correspond to the layers defined in
3027
   js/openlayers_,ap.js#getLayersByName()
3028
   */
3029
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3030
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3031
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3032
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3033
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3034
    // all others EPSG:900913
3035
    'mapnik' => 'OpenStreetMap (mapnik)',
3036
    'stamen_terrain' => 'Stamen Terrain',
3037
    'open_topomap' => 'OpenTopoMap',
3038
    // map quest is no longer free. it is required to sign up for a test plan.
3039
    // 'mapquest_open' => "MapQuest",
3040
    // 'mapquest_sat' => "MapQuest Sattelite",
3041
    'groadmap' => 'Google Roadmap',
3042
    'gsatellite' => 'Google Satellite',
3043
    'ghybrid' => 'Google Hybrid',
3044
    'gterrain' => 'Google Terrain',
3045
//     'veroad' => 'Virtual Earth Roads',
3046
//     'veaer' => 'Virtual Earth Aerial',
3047
//     'vehyb' => 'Virtual Earth Hybrid',
3048
    // 'yahoo' => 'Yahoo Street',
3049
    // 'yahoosat' => 'Yahoo Satellite',
3050
    // 'yahoohyb' => 'Yahoo Hybrid',
3051
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3052
  );
3053

    
3054
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3055
    '#type' => 'checkboxes_preferred',
3056
    '#title' => 'Base Layers',
3057
    '#options' => $baselayer_options,
3058
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3059
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3060
  );
3061

    
3062
  $google_maps_api_key = null;
3063
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3064
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3065
  }
3066
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3067
    '#type' => 'textfield',
3068
    '#title' => 'Google Maps API Key',
3069
    '#default_value' => $google_maps_api_key,
3070
    '#description' => 'In order to use any of the Google map layers you need to provide 
3071
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3072
  );
3073

    
3074
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3075
    $map_distribution['openlayers']['custom_wms_base_layer'],
3076
    'Custom WMS base layer',
3077
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3078
    true // add projection settings
3079
    );
3080

    
3081
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3082
    $map_distribution['openlayers']['wms_overlay_layer'],
3083
    'WMS overlay layer',
3084
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3085
                You can actually combine multiple layers for this overlay. 
3086
                For details please refer to the wms query parameter <code>Layers</code> .'
3087
  );
3088

    
3089
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3090
    '#type' => 'checkbox',
3091
    '#title' => 'Enable overlay layer',
3092
    '#weight' => -100,
3093
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3094
  );
3095

    
3096
  /*
3097
   * Map Legend
3098
   */
3099
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3100
    '#type' => 'fieldset',
3101
    '#title' => 'Map legend',
3102
    '#tree' => TRUE,
3103
    '#collapsible' => TRUE,
3104
    '#collapsed' => TRUE,
3105
    '#description' => 'Configure the maps legend.',
3106
  );
3107

    
3108
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3109
    '#type' => 'checkbox',
3110
    '#title' => 'Display a map legend',
3111
    '#default_value' => $map_distribution['legend']['show'],
3112
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3113
  );
3114

    
3115
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3116
    '#type' => 'textfield',
3117
    '#title' => 'Legend opacity',
3118
    '#default_value' => $map_distribution['legend']['opacity'],
3119
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3120
                         to 0.0 will be not much visible.',
3121
  );
3122

    
3123
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3124
    '#type' => 'textfield',
3125
    '#title' => 'Font size',
3126
    '#default_value' => $map_distribution['legend']['font_size'],
3127
    '#description' => 'Font size in pixels.',
3128
  );
3129

    
3130
  $fontStyles = array(
3131
    0 => "plane",
3132
    1 => "italic",
3133
  );
3134
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3135
    '#type' => 'select',
3136
    '#title' => 'Available font styles',
3137
    '#default_value' => $map_distribution['legend']['font_style'],
3138
    '#options' => $fontStyles,
3139
    '#description' => 'Select a font style for the map legend.',
3140
  );
3141

    
3142
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3143
    '#type' => 'textfield',
3144
    '#title' => 'Icon width',
3145
    '#default_value' => $map_distribution['legend']['icon_width'],
3146
    '#description' => 'Legend icon width in pixels.',
3147
  );
3148
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3149
    '#type' => 'textfield',
3150
    '#title' => 'Icon height',
3151
    '#default_value' => $map_distribution['legend']['icon_height'],
3152
    '#description' => 'Legend icon height in pixels.',
3153
  );
3154

    
3155
  // @WA: D7 form api does not support reset buttons,
3156
  // so to mimic the D5 reset button we add one like this.
3157
  $form['actions']['reset'] = array(
3158
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3159
    '#weight' => 1000,
3160
  );
3161

    
3162
  return system_settings_form($form);
3163
}
3164

    
3165
/**
3166
 * @param $default_settings
3167
 * @param $title
3168
 * @param $description
3169
 * @param bool $add_projection_settings
3170
 * @return array
3171
 */
3172
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3173
{
3174
  $form_elements = array(
3175
    '#type' => 'fieldset',
3176
    '#title' => $title,
3177
    '#tree' => TRUE,
3178
    '#collapsible' => FALSE,
3179
    '#collapsed' => FALSE,
3180
    '#description' => $description,
3181
  );
3182

    
3183
  $form_elements['name'] = array(
3184
    '#type' => 'textfield',
3185
    '#title' => 'Layer name',
3186
    '#default_value' => $default_settings['name'],
3187
    '#description' => 'A arbitrary name for the layer.',
3188
  );
3189
  $form_elements['url'] = array(
3190
    '#type' => 'textfield',
3191
    '#title' => 'WMS url',
3192
    '#default_value' => $default_settings['url'],
3193
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3194
  );
3195
  $form_elements['untiled'] = array(
3196
    '#type' => 'checkbox',
3197
    '#title' => 'Untiled',
3198
    '#default_value' => $default_settings['untiled'],
3199
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3200
  );
3201
  $form_elements['params'] = array(
3202
    '#type' => 'textarea',
3203
    '#title' => 'WMS parameters',
3204
    '#element_validate' => array('form_element_validate_json'),
3205
    '#default_value' => $default_settings['params'],
3206
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3207
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3208
      . '), entered in valid JSON. For example:
3209
<pre> {
3210
  "Layers": "topp:em_tiny_jan2003",
3211
  "Format": "image/png",
3212
  "BGCOLOR": "0xe0faff"
3213
}
3214
</pre>
3215
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3216
  );
3217

    
3218
  if($add_projection_settings){
3219

    
3220
    $form_elements['projection'] = array(
3221
      '#type' => 'textfield',
3222
      '#title' => 'Projection',
3223
      '#default_value' => $default_settings['projection'],
3224
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3225
    );
3226
    $form_elements['proj4js_def'] = array(
3227
      '#type' => 'textfield',
3228
      '#maxlength' => 256,
3229
      '#title' => 'proj4js definition',
3230
      '#default_value' => $default_settings['proj4js_def'],
3231
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3232
              The definitions for
3233
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3234
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3235
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3236
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3237
              choose to display the proj4js definition string.
3238
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3239
              <pre>
3240
  +a         Semimajor radius of the ellipsoid axis
3241
  +alpha     ? Used with Oblique Mercator and possibly a few others
3242
  +axis      Axis orientation (new in 4.8.0)
3243
  +b         Semiminor radius of the ellipsoid axis
3244
  +datum     Datum name (see `proj -ld`)
3245
  +ellps     Ellipsoid name (see `proj -le`)
3246
  +k         Scaling factor (old name)
3247
  +k_0       Scaling factor (new name)
3248
  +lat_0     Latitude of origin
3249
  +lat_1     Latitude of first standard parallel
3250
  +lat_2     Latitude of second standard parallel
3251
  +lat_ts    Latitude of true scale
3252
  +lon_0     Central meridian
3253
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3254
  +lon_wrap  Center longitude to use for wrapping (see below)
3255
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3256
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3257
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3258
  +pm        Alternate prime meridian (typically a city name, see below)
3259
  +proj      Projection name (see `proj -l`)
3260
  +south     Denotes southern hemisphere UTM zone
3261
  +to_meter  Multiplier to convert map units to 1.0m
3262
  +towgs84   3 or 7 term datum transform parameters (see below)
3263
  +units     meters, US survey feet, etc.
3264
  +vto_meter vertical conversion to meters.
3265
  +vunits    vertical units.
3266
  +x_0       False easting
3267
  +y_0       False northing
3268
  +zone      UTM zone
3269
              </pre>
3270
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3271
    );
3272
    $form_elements['max_extent'] = array(
3273
      '#type' => 'textfield',
3274
      '#title' => 'Maximum extent',
3275
      '#default_value' => $default_settings['max_extent'],
3276
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3277
    );
3278
    $form_elements['units'] = array(
3279
      '#type' => 'textfield',
3280
      '#title' => 'Units',
3281
      '#default_value' => $default_settings['units'],
3282
      '#description' => 'The layer map units.  Defaults to null.  Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’.  Normally taken from the projection.  Only required if both map and layers do not define a projection, or if they define a projection which does not define units.'
3283
    );
3284

    
3285
  }
3286
  return $form_elements;
3287
}
3288

    
3289

    
3290
/**
3291
 * @todo document this function.
3292
 */
3293
function cdm_settings_cache() {
3294

    
3295
  $form = array();
3296

    
3297
  $form['cache_settings'] = array(
3298
    '#type' => 'fieldset',
3299
    '#title' => t('Cache Settings'),
3300
    '#collapsible' => FALSE,
3301
    '#collapsed' => FALSE,
3302
    '#description' => t('<p>When caching is enabled all single taxon sites are
3303
      stored in an internal drupal cache doing the portal response of taxa pages
3304
      faster. This is possible because the sites are loaded from the cache and
3305
      are not created from scratch.</p>'),
3306
  );
3307

    
3308
  $form['cache_settings']['cdm_webservice_cache'] = array(
3309
    '#type' => 'checkbox',
3310
    '#title' => t('<strong>Enable caching</strong>'),
3311
    '#options' => cdm_help_general_cache(),
3312
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3313
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3314
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3315
       application the changes will be not visible till the cache is erased.
3316
       Therefore developers should deactived this feature when they are working
3317
       on the CDM Dataportal Module.</p>'),
3318
  );
3319

    
3320
  $form['cache_settings']['cdm_run_cache'] = array(
3321
    '#markup' => cdm_view_cache_site(),
3322
  );
3323

    
3324
  // @WA: D7 form api does not support reset buttons,
3325
  // so to mimic the D5 reset button we add one like this.
3326
  $form['actions']['reset'] = array(
3327
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3328
    '#weight' => 1000,
3329
  );
3330
  return system_settings_form($form);
3331
}
3332

    
3333
/**
3334
 * Walk and cache all taxon pages.
3335
 */
3336
function cdm_view_cache_site() {
3337

    
3338
  $out = '';
3339

    
3340
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3341

    
3342
  $request_params = array();
3343
  $request_params['class'] = "Taxon";
3344

    
3345
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3346
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3347
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3348

    
3349
  $out .= t('<p><strong>Cache all taxon pages</strong></p>');
3350
  $out .= '<p>When you launch the cache process the cache is filled and ready to be enabled.<br/>
3351
  Remember that when you load the taxa from the cache last changes on taxa will be not visible till you erase
3352
  the cache and fill it again.</p>';
3353
  $out .= '<p>Before  running the cache bot you have to empty the cache manually.</p>';
3354

    
3355
  $out .= '<div>' . t('This caching process may take long time and could cause heavy load on your server') . '</div>';
3356
  $out .= '<div id="progress"></div>';
3357

    
3358
  // Comment @WA: A form within a form is not valid html and not needed here.
3359
  // Also, it would be recommended just to include this part of the form in the
3360
  // rest of the form array in cdm_settings_cache().
3361
  // $out .= '<form id="cache_site">';
3362
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3363
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3364
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3365
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3366
  // $out .= '</form>';
3367
  $out .= '</div>';
3368
  /*
3369
  foreach($taxonPager->records as $taxon){
3370
    cdm_dataportal_taxon_view($uuid);
3371
  }
3372
  */
3373
  return $out;
3374
}
3375

    
3376

    
3377
function cdm_settings_layout_taxon_submit($form, &$form_state){
3378
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3379
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3380
    if(is_object($file)){
3381
      $file->status = FILE_STATUS_PERMANENT;
3382
      file_save($file);
3383
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3384
    }
3385
  }
3386
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3387
  $tab_lables_modified = serialize(get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT)) != serialize($form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3388
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3389
  if($tab_lables_modified || $tabs_enabled_modified){
3390
    // we first need to set the variable to persist the changes setting
3391
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3392
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3393
    menu_rebuild();
3394
  }
3395
}
3396

    
3397
function cdm_settings_layout_search_submit($form, &$form_state){
3398
  // the visibility of media thumbnails also affects the ui of the search results
3399
  // so reset the according session variable
3400
  //    1. in order to give the user immediate
3401
  //       feedback on potential setting changes
3402
  //    2. let refresh the default if it has changed
3403
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3404
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3405
  }
3406
}
3407

    
3408
/**
3409
 * Form validation handler for cdm_settings_general
3410
 *
3411
 * @param $form
3412
 * @param $form_state
3413
 */
3414
function cdm_settings_general_validate($form, &$form_state) {
3415

    
3416
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3417
    $form_state['values']['cdm_webservice_url'] .= '/';
3418
  }
3419

    
3420
}
3421

    
3422
/**
3423
 * Form submit handler for settings general.
3424
 *
3425
 * tasks performed:
3426
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3427
 *
3428
 * @param $form
3429
 * @param $form_state
3430
 */
3431
function cdm_settings_general_submit($form, &$form_state){
3432
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3433
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3434
  unset($_SESSION['cdm_login']);
3435
}
3436

    
3437
/**
3438
 * Form validation handler for cdm_settings_cache
3439
 */
3440
function cdm_settings_cache_validate($form, &$form_state) {
3441
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3442
    cache_clear_all(NULL, 'cache_cdm_ws');
3443
    // Better clear secref_cache since I can not be sure if the cache has not
3444
    // be used during this response.
3445
    cdm_api_secref_cache_clear();
3446
  }
3447

    
3448
}
3449

    
3450
/**
3451
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3452
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3453
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3454
 *  - version: the version, e.g.: v1.1
3455
 *
3456
 * @return array
3457
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3458
 */
3459
function get_edit_map_service_settings() {
3460

    
3461
  $settings = variable_get('edit_map_server', array(
3462
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3463
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3464
      )
3465
  );
3466

    
3467
  return $settings;
3468
}
3469

    
3470
/**
3471
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3472
 *
3473
 * @return string
3474
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3475
 */
3476
function get_edit_map_service_full_uri() {
3477
  $settings = get_edit_map_service_settings();
3478
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3479
}
3480

    
3481

    
3482
/**
3483
 * Returns the version number of the currently selected edit mapserver as a float
3484
 *
3485
 * @return float
3486
 *   The version number of the currently selected edit mapserver as a float.
3487
 *   Returns 0 on error.
3488
 */
3489
function get_edit_map_service_version_number() {
3490

    
3491
  $pattern = '/v([\d\.]+).*$/';
3492

    
3493
  $settings = get_edit_map_service_settings();
3494
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3495
  if (isset($matches[1])) {
3496
    // Convert string to float.
3497
    $version = 1 + $matches[1][0] - 1;
3498
    return $version;
3499
  }
3500
  else {
3501
    // Report error.
3502
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3503
        array(
3504
          '!version' => $settings['version'],
3505
          'warning')
3506
        )
3507
      );
3508
    return 0;
3509
  }
3510
}
3511

    
3512
/**
3513
 * Returns the array of selected items in a options array
3514
 *
3515
 * @param array $options
3516
 *   An options array as generated by a form element like checkoxes, select ...,
3517
 */
3518
function get_selection($options) {
3519
  $selection = array();
3520
  foreach ($options as $key=>$val) {
3521
    if (!empty($val)) {
3522
      $selection[] = $val;
3523
    }
3524
  }
3525
  return $selection;
3526
}
3527

    
3528

    
3529
/**
3530
 * Implements hook_element_info().
3531
 *
3532
 * Allows modules to declare their own Form API element types and specify their default values.
3533
 *
3534
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3535
 */
3536
function cdm_dataportal_element_info() {
3537
  $type['checkboxes_preferred'] = array(
3538
    '#input' => TRUE,
3539
    '#process' => array('checkboxes_preferred_expand'),
3540
    '#after_build' => array('checkboxes_preferred_after_build'),
3541
    '#theme' => array('checkboxes_preferred'),
3542
    // '#theme_wrapper' => array('form_element'),
3543
  );
3544
  return $type;
3545
}
3546

    
3547
/**
3548
 * #process callback function for the custom form element type 'checkbox_preferred'
3549
 *
3550
 *
3551
 */
3552
function checkboxes_preferred_expand($element, &$form_state, $form) {
3553

    
3554
  // First of all create checkboxes for each of the elements
3555
  $element = form_process_checkboxes($element);
3556

    
3557
  // compose the element name
3558
  $parents = array();
3559
  array_deep_copy($element['#parents'], $parents);
3560
  $parents[count($parents) -1 ] .= '_preferred';
3561
  $element_name = $parents[0];
3562
  for ($i=1; $i < count($parents); $i++){
3563
    $element_name .= '[' . $parents[$i] . ']';
3564
  }
3565

    
3566
  $children = element_children($element);
3567

    
3568
  $element['table_start'] = array(
3569
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3570
    '#weight' => -1,
3571
  );
3572

    
3573
  // prepare first part each of the table rows which contains the row label
3574
  $weight = 0;
3575
  foreach ($children as $key) {
3576
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3577
    $element[$key]['#weight'] = $weight;
3578
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3579
    $element[$key]['#suffix'] = '</td>';
3580
    unset($element[$key]['#title']);
3581
    $weight += 2;
3582
  }
3583
  $weight = 0;
3584

    
3585
  // add a radio button to each of the checkboxes, the
3586
  // check boxes have already been created at the beginning
3587
  // of this function
3588
  if (count($element['#options']) > 0) {
3589
    foreach ($element['#options'] as $key => $choice) {
3590
      if (!isset($element[$key . '_preferred'])) {
3591
        $element[$key . '_preferred'] = array(
3592
          '#type' => 'radio',
3593
          '#name' => $element_name,
3594
          '#return_value' => check_plain($key),
3595
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3596
          '#attributes' => $element['#attributes'],
3597
          '#parents' => $element['#parents'],
3598
          // '#spawned' => TRUE,
3599
          '#weight' => $weight + 1,
3600
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3601
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3602
        );
3603
      }
3604
      $weight += 2;
3605
    }
3606
  }
3607

    
3608
  // end the table
3609
  $element['table_end'] = array(
3610
    '#markup' => '</table>',
3611
    '#weight' => $weight++,
3612
  );
3613

    
3614
  return $element;
3615
}
3616

    
3617
/**
3618
 * Theme function for the custom form field 'checkboxes_preferred'.
3619
 */
3620
function theme_checkboxes_preferred($variables) {
3621
  $element = $variables['element'];
3622
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3623
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3624
  $out .= drupal_render_children($element);
3625
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3626
  $out .= '</div>';
3627
  return $out;
3628
}
3629

    
3630
/**
3631
 * Callback for checkboxes preferred for widget which will
3632
 * be called after the form or element is built. The call
3633
 * back is configured in the form element by setting it as
3634
 * #after_build parameter.
3635
 *
3636
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3637
 *
3638
 * @param $element
3639
 *   Nested array of form elements that comprise the form.
3640
 * @param $form_state
3641
 *   A keyed array containing the current state of the form.
3642
 *   This includes the current persistent storage data for the form.
3643
 *   Additional information, like the sanitized $_POST data,
3644
 *   is also accumulated here in $form_state['input']
3645
 *
3646
 * @return the modified form array
3647
 */
3648
function checkboxes_preferred_after_build($element, &$form_state) {
3649

    
3650
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3651

    
3652
  if ($_POST && count($_POST) > 0) {
3653
    // TODO use  $form_state['input'] instead of POST !!!
3654
    // First pass of form processing.
3655
    $parents = array();
3656
    array_deep_copy($element['#parents'], $parents);
3657
    $parents[count($parents) - 1] .= '_preferred';
3658
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3659
    $element['#value']['PREFERRED'] = $preferred_layer;
3660
//     $form_state[$parent_id] = $element['#value'];
3661
//     $form_state['values']['baselayers'] = $element['#value'];
3662
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3663
    $form_state_element_values = $element['#value'];
3664
  }
3665
  else {
3666
    // Second pass of form processing.
3667
    $preferred_layer = $element['#value']['PREFERRED'];
3668
  }
3669

    
3670
  // Also set the chosen value (not sure if this is good Drupal style ....).
3671
  foreach ($children = element_children($element) as $key) {
3672
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3673
      $element[$key]['#value'] = $preferred_layer;
3674
    }
3675
  }
3676
  // The default layer must always be enabled.
3677
  $element[$preferred_layer]['#value'] = $preferred_layer;
3678

    
3679
  return $element;
3680
}
3681

    
3682
function radios_prepare_options_suffix(&$elements){
3683

    
3684
  $childrenKeys = element_children($elements);
3685
  foreach($childrenKeys as $key){
3686
    if(!is_array($elements[$key]['#theme_wrappers'])){
3687
      $elements[$key]['#theme_wrappers'] = array();
3688
    }
3689
    if(isset($elements['#options_suffixes'][$key])){
3690
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3691
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3692
    }
3693
  }
3694
  return $elements;
3695

    
3696
}
3697

    
3698
/**
3699
 * TODO
3700
 * @param unknown $variables
3701
 */
3702
function theme_radio_options_suffix($variables) {
3703
  $element = $variables['element'];
3704
  if(isset($element['#options_suffix'])) {
3705
    $element['#children'] .= $element['#options_suffix'];
3706
  }
3707
  return $element['#children'];
3708
}
3709

    
3710

    
3711
/**
3712
 * Element validate callback for text field and arrays containing json.
3713
 *
3714
 * @param $element
3715
 *   The form element to validate
3716
 * @param $form_state
3717
 *   A keyed array containing the current state of the form.
3718
 * @param $form
3719
 *   Nested array of form elements that comprise the form.
3720
 */
3721
function form_element_validate_json($element, &$form_state, $form) {
3722
   if (!empty($element['#value'])) {
3723
     json_decode($element['#value']);
3724
     if(json_last_error() != JSON_ERROR_NONE){
3725
       form_error($element,
3726
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3727
         . l('JSONLint', 'http://jsonlint.com/')
3728
       );
3729
     }
3730
   }
3731
}
3732

    
3733
/**
3734
 * Form submission handler for textareas and textfields containing JSON.
3735
 *
3736
 * The contained JSON will be converted into an php array
3737
 * or object and will be stored in the variables as such.
3738
 *
3739
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3740
 *
3741
 * @param $form
3742
 *   Nested array of form elements that comprise the form.
3743
 * @param $form_state
3744
 *   A keyed array containing the current state of the form.
3745
 *
3746
 */
3747
function submit_json_as_php_array($form, &$form_state) {
3748
  if (is_array($form['#json_elements'])) {
3749
    foreach ($form['#json_elements'] as $element){
3750
      if (trim($form_state['values'][$element])) {
3751
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3752
      } else {
3753
        $form_state['values'][$element] = NULL;
3754
      }
3755
    }
3756
  }