Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / settings.php @ 204e8173

History | View | Annotate | Download (155 KB)

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('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
16

    
17
  define('NO_SORT', -1);
18
  define('SORT_HIERARCHICAL', 9);
19

    
20
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
21

    
22
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
23
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
24

    
25
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
26
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
27
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
28
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
29
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
30
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
31
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
32
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
33
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
34
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
35
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
36
  define('CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE', 0);
37

    
38
  /* annotationTypeKeys */
39
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
40
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
41
    $annotationTypeKeys = array_flip($annotationTypeKeys);
42

    
43
    // Technical annotation are off by default.
44
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
45
    $annotationTypeKeys = array_flip($annotationTypeKeys);
46
    // Additional value for the NULL case.
47
    $annotationTypeKeys[] = 'NULL_VALUE';
48
  }
49

    
50
  define('ANNOTATION_TYPES_VISIBLE', 'annotations_types_as_footnotes');
51
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
52

    
53
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
54
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
55
    'enabled' => 0,
56
    'key_format' => 'ALPHA'
57
  )));
58

    
59
  /* taxonRelationshipTypes */
60
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
61
    array(
62
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
63
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
64
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
65
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
66
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
67
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
68
    )
69
  ));
70

    
71

    
72
  /* ---- MAP SETTING CONSTANTS ---- */
73
  /**
74
   * @var array of URIs eg. http://edit.africamuseum.be"
75
   *   An options array
76
   */
77
  define('EDIT_MAPSERVER_URI', serialize(
78
      array(
79
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
80
      )
81
    )
82
  );
83
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
84
  /**
85
   * @var array of versions eg. "v1.2"
86
   *   An options array
87
   */
88
  define('EDIT_MAPSERVER_VERSION', serialize(
89
      array(
90
//        'v1' => 'v1' ,           // no longer recommended
91
//        'v1.1' => 'v1.1',        // no longer recommended
92
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
93
        'v1.2' => 'v1.2',
94
        'v1.3_dev' => 'v1.3_dev (not recommended)',
95
        'v1.4_dev' => 'v1.4_dev (experimental features)'
96
      )
97
    )
98
  );
99
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
100
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
101

    
102
    // --- Taxon profile settings --- /
103
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
104
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
105
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
106
      array(
107
          'show' => 0,
108
          'maxextend' => 184,
109
          'media_uri_query' => '',
110
          'custom_placeholder_enabled' => 1,
111
          'custom_placeholder_image_on' => 0,
112
          'custom_placeholder_image_fid' => ''
113
      )
114
    )
115
  );
116

    
117

    
118
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
119

    
120
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
121
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
122
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
123
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
124
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
125

    
126
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
127
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
128
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
129
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
130

    
131
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
132
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
133

    
134
/**
135
 * Returns the array of implemented taxon page tabs.
136
 * The array has fixed integer keys which must not be changed.
137
 */
138
function get_taxon_tabs_list() {
139
  $opts = array(
140
    0 => 'General',
141
    1 => 'Synonymy',
142
    2 => 'Images',
143
    3 => 'Specimens',
144
    4 => 'Keys',
145
    5 => 'Experts',
146
  );
147
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
148
    // skip the Synonymy if it is shown in  the general tab
149
    unset($opts[1]);
150
  }
151
  return $opts;
152
}
153

    
154
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
155
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
156
  array(
157
    'general' => '-3',
158
    'synonymy' => '-2',
159
    'images' => '0',
160
    'specimens' => '1',
161
    'keys' => '3',
162
    'experts' => '5',
163
    )
164
));
165

    
166

    
167
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
168
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
169
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
170
  array(
171
    'general' => null,
172
    'synonymy' => null,
173
    'images' => null,
174
    'specimens' => null,
175
    'keys' => null,
176
    'experts' => null,
177
  )
178
));
179

    
180
$taxon_tab_options = get_taxon_tabs_list();
181
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
182

    
183
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
184

    
185
/**
186
 * @todo document this function.
187
 */
188
function get_taxon_options_list() {
189
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
190
  foreach ($taxon_tab_options as $key => $value) {
191
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
192
  }
193
  return $taxon_tab_options;
194

    
195
}
196

    
197
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
198
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
199
    array(
200
      'ZoologicalName' => array(
201
        'namePart' => array('name' => TRUE),
202
        'nameAuthorPart' => array('name' => TRUE),
203
        'referencePart' => array('authors' => TRUE),
204
        'microreferencePart' => array('microreference' => TRUE),
205
        'secReferencePart' => array('secReference' => TRUE,),
206
        'statusPart' => array('status' => TRUE),
207
        'descriptionPart' => array('description' => TRUE),
208
      ),
209
      'BotanicalName'=> array(
210
        'namePart' => array('name' => TRUE),
211
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
212
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
213
        'secReferencePart' => array('secReference' => TRUE,),
214
        'referenceYearPart' => array('reference.year' => TRUE),
215
        'statusPart' => array('status' => TRUE),
216
        'descriptionPart' => array('description' => TRUE),
217
      ),
218
     '#DEFAULT' => array(
219
        'namePart' => array(
220
            'name' => TRUE
221
        ),
222
        'nameAuthorPart' => array(
223
            'name' => TRUE,
224
            'authors' => TRUE
225
        ),
226
       'referencePart' => array(
227
         'reference' => TRUE
228
        ),
229
       'secReferencePart' => array(
230
         'secReference' => TRUE,
231
       ),
232
       'microreferencePart' => array(
233
          'microreference' => TRUE,
234
        ),
235
       'statusPart' => array(
236
          'status' => TRUE,
237
        ),
238
       'descriptionPart' => array(
239
          'description' => TRUE,
240
        ),
241
      )
242
    )
243
  )
244
);
245
define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
246
    array(
247
      'ZoologicalName' => array(
248
        'namePart' => array('name' => TRUE),
249
        'nameAuthorPart' => array('name' => TRUE),
250
        'referencePart' => array('authors' => TRUE),
251
        'microreferencePart' => array('microreference' => TRUE),
252
        'statusPart' => array('status' => TRUE),
253
        'descriptionPart' => array('description' => TRUE),
254
      ),
255
      'BotanicalName'=> array(
256
        'namePart' => array('name' => TRUE),
257
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
258
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
259
        'referenceYearPart' => array('reference.year' => TRUE),
260
        'statusPart' => array('status' => TRUE),
261
        'descriptionPart' => array('description' => TRUE),
262
      ),
263
      '#DEFAULT' => array(
264
        'namePart' => array(
265
          'name' => TRUE
266
        ),
267
        'nameAuthorPart' => array(
268
          'name' => TRUE,
269
          'authors' => TRUE
270
        ),
271
        'referencePart' => array(
272
          'reference' => TRUE
273
        ),
274
        'microreferencePart' => array(
275
          'microreference' => TRUE,
276
        ),
277
        'statusPart' => array(
278
          'status' => TRUE,
279
        ),
280
        'descriptionPart' => array(
281
          'description' => TRUE,
282
        ),
283
      )
284
    )
285
  )
286
  );
287

    
288
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
289
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
290
  array (
291
    'taxon_page_title,polytomousKey'=> array(
292
        'namePart' => array('#uri' => TRUE),
293
      ),
294
    'not_in_current_classification' => array(
295
     'nameAuthorPart' => TRUE,
296
     'referencePart' => TRUE,
297
     'statusPart' => TRUE,
298
     'secReferencePart' => TRUE,
299
    ),
300
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
301
      'nameAuthorPart' => array('#uri' => TRUE),
302
      'referencePart' => TRUE,
303
      'descriptionPart' => TRUE,
304
      'statusPart' => TRUE,
305
    ),
306
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
307
      'nameAuthorPart' => array('#uri' => TRUE),
308
      'referencePart' => TRUE,
309
      'descriptionPart' => TRUE,
310
      'statusPart' => TRUE,
311
      'secReferencePart' => TRUE,
312
    ),
313
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
314
      'nameAuthorPart' => array('#uri' => TRUE),
315
      'referencePart' => TRUE,
316
      'descriptionPart' => TRUE,
317
      'statusPart' => TRUE,
318
      /* no sec ref in this case, misapplied names are
319
       * de-duplicated and the sec ref is shown as footnote */
320
    ),
321
    'homonym'=> array(
322
        'nameAuthorPart' => array('#uri' => TRUE),
323
        'referenceYearPart' => TRUE,
324
        'statusPart' => TRUE,
325
    ),
326
    'acceptedFor,typedesignations,list_of_taxa' => array(
327
        'nameAuthorPart' => array('#uri' => TRUE),
328
        'referencePart' => TRUE,
329
      ),
330
    '#DEFAULT' => array(
331
        'nameAuthorPart' => array('#uri' => TRUE),
332
        'referencePart' => TRUE,
333
     )
334
  )
335
));
336
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
337
  array (
338
    'taxon_page_title,polytomousKey'=> array(
339
      'namePart' => array('#uri' => TRUE),
340
    ),
341
    'taxon_page_synonymy,related_taxon'=> array(
342
      'nameAuthorPart' => array('#uri' => TRUE),
343
      'referencePart' => TRUE,
344
      'statusPart' => TRUE,
345
      'descriptionPart' => TRUE,
346
    ),
347
    'homonym'=> array(
348
      'nameAuthorPart' => array('#uri' => TRUE),
349
      'referenceYearPart' => TRUE,
350
    ),
351
    'acceptedFor,typedesignations,list_of_taxa' => array(
352
      'nameAuthorPart' => array('#uri' => TRUE),
353
      'referencePart' => TRUE,
354
    ),
355
    '#DEFAULT' => array(
356
      'nameAuthorPart' => array('#uri' => TRUE),
357
      'referencePart' => TRUE,
358
    )
359
  )
360
));
361

    
362
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
363
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
364
    // to unset a default enntry set the value to 0
365
    array(
366
      'doTaxa'=>'doTaxa',
367
      'doSynonyms' => 'doSynonyms',
368
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
369
      'doMisappliedNames' => 'doMisappliedNames'
370
    )
371
  )
372
);
373

    
374
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
375

    
376
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
377
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
378
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
379

    
380
/* Gallery variables. */
381
$gallery_settings = array(
382
    "cdm_dataportal_show_taxon_thumbnails" => 1,
383
    "cdm_dataportal_show_synonym_thumbnails" => 0,
384
    "cdm_dataportal_show_thumbnail_captions" => 1,
385
    "cdm_dataportal_media_maxextend" => 120,
386
    "cdm_dataportal_media_cols" => 3,
387
    "cdm_dataportal_media_maxRows" => 1,
388
);
389

    
390
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
391
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
392
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
393
define('CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME', 'type_specimen_gallery');
394
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
395
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
396
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
397
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
398
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
399
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
400
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
401
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
402

    
403
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
404
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
405
  'media_representation_details_enabled' => 0
406
)));
407

    
408
/**
409
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
410
 * the snonymy.
411
 *
412
 * @var string
413
 */
414
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
415

    
416
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
417
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
418
    array(
419
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
420
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
421
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
422
    )
423
  )
424
);
425

    
426
/**
427
 * The drupal variable for the configuration of the information aggregation along
428
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
429
 *    - direct: the uuids of the taxon relationship types to take into account in invers
430
 *      direction.
431
 *    - invers: the uuids of the taxon relationship types to take into account in direct
432
 *      direction.
433
 *
434
 * @var String
435
 */
436
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
437
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
438
    array(
439
        'direct'=>array(),
440
        'invers'=>array()
441
     )
442
   ));
443
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
444
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
445
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
446

    
447
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
448
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
449
      array(
450
      'filter_rules' => array(
451
        'statusOrderPreference' => 0,
452
        'subAreaPreference' => 0,
453
      ),
454
      'hiddenAreaMarkerType' => array()
455
     )
456
));
457

    
458
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
459
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
460
  "level_0" => array(
461
    'label_suffix' => ':',
462
    'status_glue' => '',
463
    'item_glue' => ' ',
464
    'item_group_prefix' => '',
465
    'item_group_postfix' => ''
466
  ),
467
  "level_1" => array(
468
    'label_suffix' => '',
469
    'status_glue' => '', // '&#8210; '
470
    'item_glue' => '; ',
471
    'item_group_prefix' => ', ',
472
    'item_group_postfix' => ''
473
  ),
474
  "level_2" => array(
475
    'label_suffix' => '',
476
    'status_glue' => '', // '&#8210; '
477
    'item_glue' => ', ',
478
    'item_group_prefix' => ' (',
479
    'item_group_postfix' => ')'
480
  )
481
)));
482

    
483
/**
484
 * Constant for the drupal variable key distribution_map_visibility
485
 *
486
 * possible values:
487
 *  - never
488
 *  - automatic
489
 *  - always
490
 */
491
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
492
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
493

    
494
/**
495
 * Constant for the drupal variable key specimen_map_visibility
496
 *
497
 * possible values:
498
 *  - never
499
 *  - automatic
500
 *  - always
501
 */
502
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
503
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
504

    
505
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
506
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
507
    array(
508
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
509
        'includeOccurrences' => 0,
510
        'includeTaxonNameDescriptions' => 0
511
     )
512
  ));
513

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

    
569
/**
570
 * Merges the named array variable with the array of defaults.
571
 *
572
 * IMPORTANT: The array keys must be strings. When the keys are integers
573
 * the merging will not take place for these entities. Number keyed entities
574
 * are just appended to the result array.
575
 *
576
 * @param string $variable_name
577
 *     The variable name
578
 * @param string | array $default
579
 *     The array containing the default values either as array or serialized as string.
580
 *     Unserialization is cared for if necessary
581
 * @return array
582
 *     The merged array as returned by drupal_array_merge_deep()
583
 *
584
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
585
 * TODO force $default being an array
586
 */
587
function get_array_variable_merged($variable_name, $default){
588

    
589
    // unserialize if nessecary
590
    if(!is_array($default)){
591
      $default = unserialize($default);
592
    }
593
    $variable = variable_get($variable_name, array());
594
    $result = drupal_array_merge_deep($default, $variable);
595
    return $result;
596
}
597

    
598
/**
599
 * @todo document this function.
600
 */
601
function getGallerySettings($gallery_config_form_name) {
602
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
603
}
604

    
605
/**
606
 * Returns the string representation of the default tab.
607
 *
608
 * @param bool $returnTabIndex
609
 *   Defaults to FALSE, if set true this function will return the index number
610
 *   of the default tab. (used to supply default values to form elements).
611
 */
612
function get_default_taxon_tab($returnTabIndex = FALSE) {
613

    
614
  global $user;
615
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
616
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
617
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
618
  // Get the user value if the used has chosen to overwrite the system settings.
619
  $user_tab_on = variable_get($user_tab_active, FALSE);
620
  if ($user_tab_on) {
621
    $user_value = variable_get($user_tab, 0);
622
    $index_value = $user_value;
623
    // Get the system value.
624
  }
625
  else {
626
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
627
    $index_value = $system_value;
628
  }
629

    
630
  // Return the index value or the string representation.
631
  if ($returnTabIndex) {
632
    return $index_value;
633
  }
634
  else {
635
    return ($values[$index_value]);
636
  }
637
}
638

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

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

    
710
  // ---- DEFAULTS settings
711

    
712
  // only needed as final option, when the settings are not having a default
713
  $default = array(
714
    'DEFAULT' => array(
715
      'as_list' => 'div',
716
      'link_to_reference' => 0,
717
      'link_to_name_used_in_source' => 1,
718
      'sources_as_content' => 0,
719
      'sources_as_content_to_bibliography' => 0,
720
      'sort_elements' => NO_SORT,
721
      'glue' => '',
722
      'element_tag' => NULL
723
    ),
724
    // settings for pseudo feature bibliography
725
    // only hard coded here
726
    'BIBLIOGRAPHY' => array(
727
      'as_list' => 'div',
728
      'link_to_reference' => 0,
729
      'link_to_name_used_in_source' => 1,
730
      'sources_as_content' => 0,
731
      'sources_as_content_to_bibliography' => 0,
732
      'sort_elements' => NO_SORT,
733
      'glue' => '',
734
      'element_tag' => NULL
735
    )
736
  );
737

    
738
  // will be used as preset in the settings
739
  $other_themes_default = array(
740
    'DEFAULT' => array(
741
      'as_list' => 'div',
742
      'link_to_reference' => 0,
743
      'link_to_name_used_in_source' => 1,
744
      'sources_as_content' => 0,
745
      'sources_as_content_to_bibliography' => 0,
746
      'sort_elements' => NO_SORT,
747
      'glue' => '',
748
      'element_tag' => NULL
749
    ),
750
    UUID_CITATION => array(
751
      'as_list' => 'div',
752
      'link_to_reference' => 0,
753
      'link_to_name_used_in_source' => 0,
754
      'sources_as_content' => 1,
755
      'sources_as_content_to_bibliography' => 0,
756
      'sort_elements' => SORT_ASC,
757
      'glue' => '',
758
      'element_tag' => 'div'
759
    ),
760
    UUID_DISTRIBUTION => array(
761
      'as_list' => 'div', // currently ignored
762
      'link_to_reference' => 0,
763
      'link_to_name_used_in_source' => 0,
764
      'sources_as_content' => 0,
765
      'sources_as_content_to_bibliography' => 0,
766
      'sort_elements' => NO_SORT, // will cause ...
767
      'glue' => '',
768
      'element_tag' => 'div',
769
      'special' => array()
770
    ),
771
    UUID_COMMON_NAME => array(
772
      'as_list' => 'div',
773
      'link_to_reference' => 0,
774
      'link_to_name_used_in_source' => 1,
775
      'sources_as_content' => 0,
776
      'sources_as_content_to_bibliography' => 0,
777
      'sort_elements' => NO_SORT,
778
      'glue' => '',
779
      'element_tag' => 'span'
780
    ),
781
  );
782

    
783
  // ---- Special DEFAULTS for existing portals
784
  // TODO:
785
  // this can be removed once the feature block
786
  // settings have been deployed for the first time to these portals
787

    
788
  $cichorieae_default = array(
789
    'DEFAULT' => array(
790
      'as_list' => 'div',
791
      'link_to_reference' => 1,
792
      'link_to_name_used_in_source' => 1,
793
      'sources_as_content' => 1,
794
      'sources_as_content_to_bibliography' => 0,
795
      'sort_elements' => NO_SORT,
796
      'glue' => '',
797
      'element_tag' => 'div'
798
    ),
799
    UUID_CITATION => array(
800
      'as_list' => 'div',
801
      'link_to_reference' => 0,
802
      'link_to_name_used_in_source' => 0,
803
      'sources_as_content' => 1,
804
      'sources_as_content_to_bibliography' => 0,
805
      'sort_elements' => SORT_ASC,
806
      'glue' => '',
807
      'element_tag' => 'div'
808
    ),
809
    UUID_CHROMOSOMES_NUMBERS => array(
810
      'as_list' => 'ul',
811
      'link_to_reference' => 1,
812
      'link_to_name_used_in_source' => 1,
813
      'sources_as_content' => 1,
814
      'sources_as_content_to_bibliography' => 0,
815
      'sort_elements' => NO_SORT,
816
      'glue' => '',
817
      'element_tag' => 'div'
818
    ),
819
    UUID_CHROMOSOMES => array(
820
      'as_list' => 'ul',
821
      'link_to_reference' => 0,
822
      'link_to_name_used_in_source' => 1,
823
      'sources_as_content' => 1,
824
      'sources_as_content_to_bibliography' => 0,
825
      'sort_elements' => NO_SORT,
826
      'glue' => '',
827
      'element_tag' => 'div'
828
    ),
829
    UUID_COMMON_NAME => array(
830
      'as_list' => 'div',
831
      'link_to_reference' => 0,
832
      'link_to_name_used_in_source' => 1,
833
      'sources_as_content' => 0,
834
      'sources_as_content_to_bibliography' => 0,
835
      'sort_elements' => NO_SORT,
836
      'glue' => '',
837
      'element_tag' => 'span'
838
    ),
839
  );
840

    
841
  $palmweb_default = array(
842
    'DEFAULT' => array(
843
      'as_list' => 'ul',
844
      'link_to_reference' => 1,
845
      'link_to_name_used_in_source' => 1,
846
      'sources_as_content' => 1,
847
      'sources_as_content_to_bibliography' => 1,
848
      'sort_elements' => NO_SORT,
849
      'glue' => '',
850
      'element_tag' => NULL
851
    ),
852
    UUID_CITATION => array(
853
      'as_list' => 'ul',
854
      'link_to_reference' => 1,
855
      'link_to_name_used_in_source' => 1,
856
      'sources_as_content' => 0,
857
      'sources_as_content_to_bibliography' => 1,
858
      'sort_elements' => SORT_ASC,
859
      'glue' => '',
860
      'element_tag' => 'div'
861
    ),
862
    UUID_DISTRIBUTION => array(
863
      'as_list' => 'div', // currently ignored
864
      'link_to_reference' => 1,
865
      'link_to_name_used_in_source' => 1,
866
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
867
      'sources_as_content_to_bibliography' => 1,
868
      'sort_elements' => NO_SORT, // will cause ...
869
      'glue' => ', ',
870
      'element_tag' => 'span',
871
      'special' => array()
872
    ),
873
  );
874

    
875
  $cyprus_default = $cichorieae_default;
876
  $cyprus_default[UUID_DISTRIBUTION] = array(
877
    'as_list' => 'div', // currently ignored
878
    'link_to_reference' => 0,
879
    'link_to_name_used_in_source' => 0,
880
    'sources_as_content' => 0,
881
    'sources_as_content_to_bibliography' => 0,
882
    'sort_elements' => NO_SORT, // will cause ...
883
    'glue' => ' ',
884
    'element_tag' => 'div',
885
    'special' => array()
886
  );
887

    
888
  $default_theme = variable_get('theme_default', NULL);
889

    
890
  switch ($default_theme) {
891
    case 'garland_cichorieae':
892
      $settings_for_theme = $cichorieae_default;
893
      break;
894
    case 'cyprus':
895
      // cyprus: no longer used in production,
896
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
897
      $settings_for_theme = $cyprus_default;
898
      break;
899
    case 'flore_afrique_centrale':
900
    case 'flora_malesiana':
901
    case 'flore_gabon':
902
      $settings_for_theme = $cichorieae_default;
903
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
904
      break;
905
    case 'palmweb_2':
906
      $settings_for_theme = $palmweb_default;
907
      break;
908
    default:
909
      $settings_for_theme = $other_themes_default;
910
  }
911
  // add pseudo feature settings
912
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
913

    
914
  // ---- END of DEFAULTS
915

    
916
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
917

    
918
  $feature_block_setting = null;
919

    
920
  if (isset($saved_settings[$feature_uuid])) {
921
    $feature_block_setting = $saved_settings[$feature_uuid];
922
  }
923
  else if (isset($settings_for_theme[$feature_uuid])) {
924
    $feature_block_setting = $settings_for_theme[$feature_uuid];
925
  }
926
  else if (isset($settings_for_theme['DEFAULT'])) {
927
    $feature_block_setting = $settings_for_theme['DEFAULT'];
928
  }
929

    
930
  // now merge the default and specific settings
931
  $settings_to_merge = array($default['DEFAULT']);
932
  if(is_array($saved_settings)){
933
    $settings_to_merge[] = $saved_settings['DEFAULT'];
934
  }
935
  if(isset($feature_block_setting)){
936
    $settings_to_merge[] = $feature_block_setting;
937
  }
938
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
939

    
940
  return $feature_block_setting;
941
}
942

    
943
/**
944
 * returns the current setting for the original source bibliography
945
 *
946
 * Caches internally
947
 *
948
 * @return array
949
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
950
 *   - 'enabled': 1|0
951
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
952
 */
953
function get_bibliography_settings($clear_cache = false){
954
  static $bibliography_settings = null;
955
  if(!$bibliography_settings || $clear_cache){
956
    $bibliography_settings = get_array_variable_merged(
957
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
958
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
959
    );
960
  }
961
  return $bibliography_settings;
962
}
963

    
964
/**
965
 * @todo Please document this function.
966
 * @see http://drupal.org/node/1354
967
 */
968
function cdm_dataportal_menu_admin(&$items) {
969
  // Display section on admin/config page.
970
  $items['admin/config/cdm_dataportal'] = array(
971
    'title' => 'CDM Dataportal',
972
    'description' => 'Settings for the CDM DataPortal.',
973
    'position' => 'right',
974
    'weight' => 10,
975
    'page callback' => 'system_admin_menu_block_page',
976
    'access arguments' => array('administer cdm_dataportal'),
977
    'file' => 'system.admin.inc',
978
    'file path' => drupal_get_path('module', 'system'),
979
  );
980
  $items['admin/config/cdm_dataportal/settings'] = array(
981
    'title' => 'Settings',
982
    'description' => 'Settings for the CDM DataPortal.',
983
    'weight' => 0,
984
    'page callback' => 'drupal_get_form',
985
    'page arguments' => array('cdm_settings_general'),
986
    'access arguments' => array('administer cdm_dataportal'),
987
    'type' => MENU_NORMAL_ITEM,
988
  );
989
  $items['admin/config/cdm_dataportal/settings/general'] = array(
990
    'title' => 'General',
991
    'description' => 'General',
992
    'weight' => 0,
993
    'page callback' => 'drupal_get_form',
994
    'page arguments' => array('cdm_settings_general'),
995
    'access arguments' => array('administer cdm_dataportal'),
996
    'type' => MENU_DEFAULT_LOCAL_TASK,
997
  );
998

    
999
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
1000
    'title' => 'Cache',
1001
    'description' => 'Cache',
1002
    'access arguments' => array('administer cdm_dataportal'),
1003
    'page callback' => 'drupal_get_form',
1004
    'page arguments' => array('cdm_settings_cache'),
1005
    'weight' => 10,
1006
    'type' => MENU_LOCAL_TASK,
1007
  );
1008

    
1009
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1010
    'title' => 'Geo & Map',
1011
    'description' => 'Geo & Map',
1012
    'access arguments' => array('administer cdm_dataportal'),
1013
    'page callback' => 'drupal_get_form',
1014
    'page arguments' => array('cdm_settings_geo'),
1015
    'weight' => 1,
1016
    'type' => MENU_LOCAL_TASK,
1017
  );
1018

    
1019
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1020
    'title' => 'Layout',
1021
    'description' => 'Configure and adjust the layout of your DataPortal ',
1022
    'access arguments' => array('administer cdm_dataportal'),
1023
    'page callback' => 'drupal_get_form',
1024
    'page arguments' => array('cdm_settings_layout'),
1025
    'weight' => 2,
1026
    'type' => MENU_LOCAL_TASK,
1027
  );
1028

    
1029
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1030
    'title' => 'Taxon',
1031
    'description' => 'Configure and adjust the layout of your DataPortal ',
1032
    'access arguments' => array('administer cdm_dataportal'),
1033
    'page callback' => 'drupal_get_form',
1034
    'page arguments' => array('cdm_settings_layout_taxon'),
1035
    'weight' => 1,
1036
    'type' => MENU_LOCAL_TASK,
1037
  );
1038
  /*
1039
  $items[] = array(
1040
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1041
  'title' => t('Synonymy'),
1042
  'description' => t('Configure and adjust the layout of your DataPortal '),
1043
  'access' => user_access('administer cdm_dataportal'),
1044
  'callback' => 'drupal_get_form',
1045
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1046
  'weight' => 1,
1047
  'type' => MENU_LOCAL_TASK,
1048
  );
1049

1050
  $items[] = array(
1051
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1052
  'title' => t('Specimens'),
1053
  'description' => t('Configure and adjust the layout of your DataPortal '),
1054
  'access' => user_access('administer cdm_dataportal'),
1055
  'callback' => 'drupal_get_form',
1056
  'callback arguments' => array('cdm_settings_layout_specimens'),
1057
  'weight' => 1,
1058
  'type' => MENU_LOCAL_TASK,
1059
  );
1060
  */
1061
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1062
    'title' => 'Search',
1063
    'description' => 'Configure and adjust the layout of your DataPortal ',
1064
    'access arguments' => array('administer cdm_dataportal'),
1065
    'page callback' => 'drupal_get_form',
1066
    'page arguments' => array('cdm_settings_layout_search'),
1067
    'weight' => 2,
1068
    'type' => MENU_LOCAL_TASK,
1069
  );
1070

    
1071
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1072
    'title' => 'Media',
1073
    'description' => 'Configure and adjust the layout of your DataPortal ',
1074
    'access arguments' => array('administer cdm_dataportal'),
1075
    'page callback' => 'drupal_get_form',
1076
    'page arguments' => array('cdm_settings_layout_media'),
1077
    'weight' => 3,
1078
    'type' => MENU_LOCAL_TASK,
1079
  );
1080

    
1081
}
1082

    
1083
/**
1084
 * @todo document this function.
1085
 */
1086
function cdm_help_general_cache() {
1087
  $form = array();
1088
  $form['cache_help'] = array(
1089
    '#type' => 'fieldset',
1090
    '#title' => t('Help'),
1091
    '#collapsible' => TRUE,
1092
    '#collapsed' => TRUE,
1093
  );
1094
  $form['cache_help']['test'] = array('#value' => t('probando'));
1095
  return drupal_render($form);
1096
  $res = array();
1097
  $res['default'] = drupal_render($help);
1098
  return $res;
1099
}
1100

    
1101
/**
1102
 * Configures the settings form for the CDM-API module.
1103
 *
1104
 * @return array
1105
 *   Drupal settings form.
1106
 */
1107
function cdm_settings_general() {
1108

    
1109
  $form['cdm_webservice'] = array(
1110
    '#type' => 'fieldset',
1111
    '#title' => t('CDM Server'),
1112
    '#collapsible' => FALSE,
1113
    '#collapsed' => FALSE,
1114
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1115
        CDM data base to the web via RESTful web services and thus is the source of the data
1116
        to be displayed by a CDM DataPotal.'),
1117
  );
1118

    
1119
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1120
    '#type' => 'textfield',
1121
    '#title' => t('CDM web service URL') . ':',
1122
    '#description' => t('This is the URL to the CDM-Server exposing your data
1123
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1124
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1125
  );
1126

    
1127
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1128
    '#type' => 'markup',
1129
    '#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')
1130
      . ' visible only for administrators',
1131
  );
1132

    
1133
  $form['cdm_webservice']['freetext_index'] = array(
1134
    '#type' => 'fieldset',
1135
    '#title' => t('Freetext index'),
1136
    '#collapsible' => FALSE,
1137
    '#collapsed' => FALSE,
1138
  );
1139

    
1140
  // Check the cdmserver port number and display a waring if it is not port 80
1141
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1142
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1143
    $form['cdm_webservice']['freetext_index']['message'] = array(
1144
      '#markup' => "<div class=\"description\">"
1145
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1146
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1147
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1148
          array('!port' => $portNumberMatch[1][0])
1149
        )
1150
      . "</div>",
1151
    );
1152
  };
1153

    
1154
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1155
  $trigger_link_options = array(
1156
    'attributes' => array(
1157
      'class' => 'index-trigger'
1158
    ),
1159
  );
1160
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1161
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1162
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1163
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1164
      ))
1165
    . '<div id="index-progress"></div></div>',
1166
  );
1167

    
1168
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1169
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1170
    '#type' => 'textfield',
1171
    '#title' => t('Login'),
1172
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1173
  );
1174
  drupal_add_js('
1175
        jQuery(document).ready(function() {
1176
             jQuery("#edit-cdm-login").change(function (e) {
1177
                var login = jQuery(e.target).val();
1178
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1179
                   var url = jQuery(this).attr("href");
1180
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1181
                   jQuery(this).attr("href", url);
1182
                });
1183
            });
1184
        });
1185
      ',
1186
    array(
1187
      'type' => 'inline',
1188
      'scope' => 'footer'
1189
    )
1190
  );
1191
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1192

    
1193
  $form['cdm_webservice']['proxy'] = array(
1194
    '#type' => 'fieldset',
1195
    '#title' => t('Proxy'),
1196
    '#collapsible' => TRUE,
1197
    '#collapsed' => TRUE,
1198
  );
1199

    
1200
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1201
    '#type' => 'textfield',
1202
    '#title' => t('Proxy URL') . ':',
1203
    '#description' => t('If this proxy url is set the cdm api tries
1204
    to connect the web service over the given proxy server.
1205
    Otherwise proxy usage is deactivated.'),
1206
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1207
  );
1208

    
1209
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1210
    '#type' => 'textfield',
1211
    '#title' => t('Proxy port') . ':',
1212
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1213
  );
1214

    
1215
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1216
    '#type' => 'textfield',
1217
    '#title' => t('Login') . ':',
1218
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1219
  );
1220

    
1221
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1222
    '#type' => 'textfield',
1223
    '#title' => t('Password') . ':',
1224
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1225
  );
1226

    
1227
  $form['sub_tree_filter'] = array(
1228
    '#type' => 'fieldset',
1229
    '#title' => t('Subtree filter'),
1230
    '#collapsible' => FALSE,
1231
    '#collapsed' => TRUE,
1232
    '#description' => t('The Data Portal can be restricted to the taxa which belong to a specific classification subtree. Other taxa will not be shown or accessible otherwise.'),
1233
  );
1234

    
1235
  $sub_tree_filter_uuid_value = variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE);
1236
  $taxon_node_info = '';
1237
  if($sub_tree_filter_uuid_value){
1238
    $taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE, array($sub_tree_filter_uuid_value));
1239
    if($taxon_node_dto){
1240
      $taxon_node_info = " Current taxon node: <strong>" . cdm_tagged_text_to_markup($taxon_node_dto->taggedTitle) . " [" . $taxon_node_dto->treeIndex . "]</strong>";
1241
    }
1242
  }
1243
  $form['sub_tree_filter'][CDM_SUB_TREE_FILTER_UUID] = array(
1244
    '#type' => 'textfield',
1245
    '#title' => t('Taxon Node UUID') . ':',
1246
    '#default_value' => variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE),
1247
    '#description' => "The uuid of the TaxonNode entity to be used as filter." . $taxon_node_info
1248
  );
1249

    
1250
  // TODO: settings are still incomplete, compare with
1251
  // trunk/dataportal/inc/config_default.php.inc.
1252
  $form['taxon_tree'] = array(
1253
    '#type' => 'fieldset',
1254
    '#title' => t('Taxon Tree'),
1255
    '#collapsible' => FALSE,
1256
    '#collapsed' => TRUE,
1257
    '#description' => t('<p>When you explore your collection, you can navigate
1258
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1259
      able to navigate through your collection the
1260
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1261
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1262
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1263
      </a></p>'),
1264
  );
1265

    
1266
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1267
    '#type' => 'select',
1268
    '#title' => t('Default classification') . ':',
1269
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1270
    '#options' => cdm_get_taxontrees_as_options(),
1271
    '#description' => t('The default taxa classification to be used in the whole portal. 
1272
      This affects most obviously the classification browser and the search in case is is restricted 
1273
      to a specific classification. See also <i>Included Classifications</i> below.'),
1274
  );
1275

    
1276
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1277
    '#type' => 'select',
1278
    '#title' => t('Rank of highest displayed taxon') . ':',
1279
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1280
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1281
    '#options' => cdm_vocabulary_as_option(UUID_RANK, null, true),
1282
    '#description' => t('This is the rank of the highest displayed taxon in the
1283
      <em>taxon tree</em>. You can select here which rank should be at the top
1284
      level of the tree structure.'),
1285
  );
1286

    
1287
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1288
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1289
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1290
      '#type' => 'checkboxes',
1291
      '#title' => t('Included Classifications') . ':',
1292
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1293
      '#options' => cdm_get_taxontrees_as_options(),
1294
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1295
  );
1296

    
1297
  $form['distribution'] = array(
1298
      '#type' => 'fieldset',
1299
      '#title' => t('Distributions'),
1300
      '#collapsible' => FALSE,
1301
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1302
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1303
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1304
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1305
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1306
          '<p>
1307
          </p>',
1308
  );
1309

    
1310
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1311
      '#type' => 'fieldset',
1312
      '#title' => 'Distribution filter',
1313
      '#collapsible' => FALSE,
1314
      '#collapsed' => FALSE,
1315
      '#tree' => TRUE,
1316
      '#description' => 'The Distribution filter offers the following options
1317
      <ul>
1318
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1319
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1320
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1321
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1322
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1323
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1324
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1325
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1326
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1327
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1328
      </ul>'
1329
  );
1330

    
1331
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1332
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1333
      '#type' => 'checkboxes',
1334
      '#title' => 'Filter rules',
1335
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1336
      '#options' => array(
1337
          'statusOrderPreference' => 'Status order preference rule',
1338
          'subAreaPreference' => 'Sub area preference rule'
1339
      ),
1340
  );
1341

    
1342
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1343
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1344
      '#type' => 'checkboxes',
1345
      '#title' => 'Hide marked area filter',
1346
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1347
      '#options' => $marker_type_options,
1348
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1349
  );
1350

    
1351
  $form['aggregation'] = array(
1352
      '#type' => 'fieldset',
1353
      '#title' => t('Aggregation of data'),
1354
      '#collapsible' => FALSE,
1355
      '#description' => 'This section covers the different aspects of aggregating information.
1356
          <p>
1357
          </p>',
1358
  );
1359

    
1360
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1361
      '#type' => 'checkboxes',
1362
      '#title' => 'Taxon media filter',
1363
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1364
      '#options' => array(
1365
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1366
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1367
          'includeOccurrences' => 'Media related to specimens and occurrences',
1368
      ),
1369
      '#description' => 'This filter configures which images should be taken into account.',
1370
  );
1371

    
1372
  $form['aggregation']['notice'] = array(
1373
      '#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
1374
          want to make use of the caching capabilities of the dataportal.',
1375
  );
1376

    
1377
  $form['aggregation']['media_aggregation'] = array(
1378
      '#type' => 'fieldset',
1379
      '#title' => t('Media aggregation'),
1380
      '#collapsible' => FALSE,
1381
      '#collapsed' => TRUE,
1382
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1383

    
1384
  );
1385
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1386
      '#type' => 'select',
1387
      '#title' => t('Aggregation of taxon pictures') . ':',
1388
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1389
      '#options' => array(
1390
          0 => "Show only pictures of the current taxon",
1391
          1 => "Include pictures of taxonomic children",
1392
      ),
1393
      '#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."),
1394
  );
1395

    
1396
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1397
      '#type' => 'fieldset',
1398
      '#attributes' => array('class' => array('clearfix')),
1399
      '#title' => t('Aggregation via taxon relationsships'),
1400
      '#collapsible' => TRUE,
1401
      '#collapsed' => TRUE,
1402
      '#tree' => TRUE,
1403
      '#description' => t('Information on taxa will be aggregated along the below chosen
1404
          taxon relation ships. This will affect images and occurrences (specimens).
1405
          Taxon relation ships are directed and point form one taxon to another. The taxon
1406
          relationships to be taken into accunt can therefore configured for the direct direction
1407
          and for the inverse.'),
1408
  );
1409

    
1410
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1411
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1412

    
1413
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1414
      '#type' => 'checkboxes',
1415
      '#title' => t('Direct'),
1416
      '#options' => $taxonRelationshipTypeOptions,
1417
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1418
  );
1419
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1420
      '#type' => 'checkboxes',
1421
      '#title' => t('Invers'),
1422
      '#options' => $taxonRelationshipTypeOptions,
1423
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1424
  );
1425

    
1426
  $form['drupal_integration'] = array(
1427
    '#type' => 'fieldset',
1428
    '#attributes' => array('class'=> array('clearfix')),
1429
    '#title' => t('Drupal integration'),
1430
    '#collapsible' => FALSE,
1431
    '#collapsed' => FALSE,
1432
    '#tree' => FALSE
1433
  );
1434

    
1435
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1436
    '#type' => 'checkbox',
1437
    '#title' => 'Create drupal nodes',
1438
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1439
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1440
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1441
    cdm pages it is required that drupal nodes are created and stored in the database.'
1442
  );
1443

    
1444

    
1445

    
1446
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1447
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1448
    <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>',
1449
  );
1450
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1451
    '#type' => 'submit',
1452
    '#value' => t('Drop all cdm nodes'),
1453
    '#submit' => array('drop_all_cdm_nodes_submit')
1454
  );
1455

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

    
1460
    // ----------------------
1461
  $form['cdm_js_devel_mode'] = array(
1462
      '#type' => 'checkbox',
1463
      '#title' => 'Java-script developer mode',
1464
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1465
      '#description' => 'In production envirionments the java script libraries
1466
      the cdm_dataportal is making use of are compressed and optimized. This
1467
      is good for performance but a caveat if you need to debug java-script. When the
1468
      java-script developer mode is enabled the uncompressed and commented developer
1469
      versions of java-script libraries will be used where possible.
1470
      <br/><strong>Do not use this option in production!</strong>'
1471
  );
1472
  // ----------------------
1473
  $form['cdm_debug_mode'] = array(
1474
      '#type' => 'checkbox',
1475
      '#title' => 'CDM page debug mode',
1476
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1477
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1478
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1479
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1480
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1481
      The log is written by the drupal devel module function <code>dd()</code>.
1482
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1483
  );
1484

    
1485
  // Comment @WA: D7 form api does not support reset buttons,
1486
  // so to mimic the D5 reset button we add one like this.
1487
  $form['actions']['reset'] = array(
1488
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1489
    '#weight' => 1000,
1490
  );
1491

    
1492
  $form['#submit'][] = 'cdm_settings_general_submit';
1493

    
1494
  return system_settings_form($form);
1495
}
1496

    
1497
/**
1498
 * Submit callback; drops all cdm nodes.
1499
 *
1500
 * @ingroup forms
1501
 */
1502
function drop_all_cdm_nodes_submit($form, &$form_state) {
1503
  cdm_delete_all_cdm_nodes();
1504
  drupal_set_message(t('All cdm nodes dropped.'));
1505
}
1506

    
1507

    
1508
/**
1509
 * LAYOUT settings
1510
 * @return
1511
 *   todo
1512
 */
1513
function cdm_settings_layout() {
1514

    
1515
  $form = array();
1516

    
1517
  $form['about'] = array(
1518
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1519
      layout. If you want to configure the specific sites layout visit the
1520
      respective configuration site for taxon, search or media.') . '</p>',
1521
  );
1522

    
1523
  // ---- footnotes --- //
1524
  $form['footnotes'] = array(
1525
    '#type' => 'fieldset',
1526
    '#title' => t('Footnotes'),
1527
    '#collapsible' => FALSE,
1528
    '#collapsed' => FALSE,
1529
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1530
      media or distribution areas may have annotations or footnotes. When the
1531
      footnotes are enabled they will be visible (if they exist).'),
1532
  );
1533

    
1534
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1535
    '#type' => 'checkbox',
1536
    '#title' => t('Do not show footnotes'),
1537
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1538
    '#description' => t('Check this if you do not want to show any footnotes'),
1539
  );
1540

    
1541
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1542
    '#type' => 'checkbox',
1543
    '#title' => t('Do not show annotation footnotes'),
1544
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1545
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1546
  );
1547

    
1548
  $form['annotations'] = array(
1549
    '#type' => 'fieldset',
1550
    '#title' => t('Annotations'),
1551
    '#collapsible' => FALSE,
1552
    '#collapsed' => FALSE,
1553
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1554
  );
1555

    
1556
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1557
  // Additional option for the NULL case.
1558
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1559
  $annotationsTypesAsFootnotes = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1560
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1561
    '#type' => 'checkboxes',
1562
    '#title' => t('Visbility of annotation types'),
1563
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1564
    '#options' => $annotationTypeOptions,
1565
    '#default_value' => $annotationsTypesAsFootnotes
1566
  );
1567

    
1568

    
1569
  // ---- original source --- //
1570
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1571
      '#type' => 'fieldset',
1572
      '#tree' => TRUE,
1573
      '#title' => t('Source Citations'),
1574
      '#collapsible' => FALSE,
1575
      '#collapsed' => FALSE,
1576
  );
1577

    
1578
  $bibliography_settings = get_bibliography_settings(true);
1579

    
1580
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1581
      '#type' => 'checkbox',
1582
      '#title' => t('Original Source in bibliography'),
1583
      '#default_value' => $bibliography_settings['enabled'],
1584
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1585
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1586
       into the bibliography also depends on the settings in the ' .
1587
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1588
        '. 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.'),
1589
  );
1590

    
1591
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1592
    '#type' => 'select',
1593
    '#title' => t('The format of the key numerals'),
1594
    '#default_value' => $bibliography_settings['key_format'],
1595
    '#options' => array('latin' => 'Latin',
1596
      'ROMAN' => 'Roman (upper case)',
1597
      'roman' => 'Roman (lower case)',
1598
      'ALPHA'=> 'Alphabet (upper case)',
1599
      'alpha' => 'Alphabet (lower case)')
1600
  );
1601

    
1602
  // --- Advanced Search --- //
1603
  $form['asearch'] = array(
1604
      '#type' => 'fieldset',
1605
      '#title' => t('Advanced search'),
1606
      '#collapsible' => FALSE,
1607
      '#collapsed' => FALSE,
1608
  );
1609
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1610
      '#type' => 'checkbox',
1611
      '#title' => t('Show advanced search link'),
1612
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1613
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1614
  );
1615

    
1616
  // ---- Taxon Name Rendering --- //
1617
  $form['taxon_name'] = array(
1618
      '#type' => 'fieldset',
1619
      '#title' => t('Taxon name display'),
1620
      '#collapsible' => TRUE,
1621
      '#collapsed' => TRUE,
1622
      '#description' => t('The display of taxon names is configured by two parts.
1623
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1624
          The name parts are defined in the <stong>part definitions</strong>'),
1625
  );
1626

    
1627
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1628
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1629
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1630
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1631

    
1632
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1633
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1634
    $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.)';
1635
  } else if($is_custom_part_definition){
1636
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1637
  } else  {
1638
    $which_version_message = '(These are the default part definition.)';
1639
  }
1640

    
1641
  $diff_viewer_markup = '';
1642
  if($is_custom_part_definition){
1643
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1644
  }
1645

    
1646
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1647
    . $which_version_message
1648
    . '</div>'
1649
    . $diff_viewer_markup;
1650

    
1651
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1652
      '#type' => 'textarea',
1653
      '#title' => t('Part definitions'),
1654
      '#element_validate' => array('form_element_validate_json'),
1655
      '#default_value' =>  $current_part_definition_json,
1656
      '#description' => '
1657
          <p>' . $which_version_message . '</p>
1658
          <p>
1659
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1660
          </p>
1661
          <p>
1662
           A full taxon name plus additional information can consist of the following elements:
1663
          <ul>
1664
             <li>name: the taxon name inclugin rank nbut without author</li>
1665
             <li>authors:  The authors of a reference, also used in taxon names</li>
1666
             <li>reference: the nomenclatural reference,</li>
1667
             <li>microreference:  Volume, page number etc.</li>
1668
             <li>status:  The nomenclatural status of a name</li>
1669
             <li>description: name descriptions like protologues etc ...</li>
1670
          </ul>
1671
          </p>
1672
          <p>
1673
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1674
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1675
           The following parts can be formed and are recognized by the system:
1676
          <ul>
1677
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1678
            <li>authorshipPart: the author (for example: "L.")</li>
1679
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1680
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1681
               be combined when a link to the taxon is rendered.</li>
1682
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1683
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1684
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1685
            <li>statusPart: the nomenclatorical status</li>
1686
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1687
          </ul>
1688
          </p>
1689
          <p>
1690
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1691
           specific parts part definitions:
1692
          <ul>
1693
            <li>BotanicalName</li>
1694
            <li>ZoologicalName</li>
1695
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1696
          </ul>
1697
           An example:
1698
          <pre>
1699
           {
1700
            "ZoologicalName": {
1701
              "namePart": {
1702
                "name": true
1703
              },
1704
              "referencePart": {
1705
                "authors": true
1706
              },
1707
              "microreferencePart": {
1708
                "microreference": true
1709
              },
1710
              "statusPart": {
1711
                "status": true
1712
              },
1713
              "descriptionPart": {
1714
                "description": true
1715
              }
1716
            },
1717
            "BotanicalName": {
1718
              "namePart": {
1719
                "name": true,
1720
                "authors": true
1721
              },
1722
              "referencePart": {
1723
                "reference": true,
1724
                "microreference": true
1725
              },
1726
              "secReferencePart": {
1727
                "secReference": true
1728
              },
1729
              "statusPart": {
1730
                "status": true
1731
              },
1732
              "descriptionPart": {
1733
                "description": true
1734
              }
1735
            }
1736
          }
1737
           </pre>',
1738
  );
1739

    
1740
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1741
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1742
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1743
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1744
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1745

    
1746
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1747
    $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.)';
1748
  } else if($is_custom_render_template){
1749
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1750
  } else {
1751
    $which_version_message = '(These are the default render templates.)';
1752
  }
1753

    
1754
  $diff_viewer_markup = '';
1755
  if($is_custom_render_template){
1756
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1757
  }
1758

    
1759
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1760
    . $which_version_message
1761
    . '</div>'
1762
    . $diff_viewer_markup;
1763

    
1764
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1765
      '#type' => 'textarea',
1766
      '#title' => t('Name render templates'),
1767
      '#element_validate' => array('form_element_validate_json'),
1768
      '#default_value' =>  $current_render_templates_json,
1769
      '#description' => '
1770
          <p>' . $which_version_message . '</p>
1771
          <p>
1772
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1773
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1774
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1775
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1776
          The following render Path keys are currently recognized:
1777
          <ul>
1778
            <li>list_of_taxa</li>
1779
            <li>acceptedFor</li>
1780
            <li>homonym</li>
1781
            <li>taxon_page_synonymy</li>
1782
            <li>typedesignations</li>
1783
            <li>taxon_page_title</li>
1784
            <li>polytomousKey</li>
1785
            <li>na: name + authorship</li>
1786
            <li>nar:name + authorship + reference</li>
1787
            <li>#DEFAULT</li>
1788
          </ul>
1789
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1790
          array element should be a comma separated list of render paths, without any whitespace!.
1791
          </p>
1792
          <p>
1793
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1794
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1795
          <p>
1796
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1797
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1798
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1799
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1800
          links if the paramters $nameLink or $refenceLink are given to the name render function
1801
          (this is hard coded and cannot be configured here).',
1802
  );
1803

    
1804
  // @WA: D7 form api does not support reset buttons,
1805
  // so to mimic the D5 reset button we add one like this.
1806
  $form['actions']['reset'] = array(
1807
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1808
    '#weight' => 1000,
1809
  );
1810

    
1811
  $form['#submit'] = array('submit_json_as_php_array');
1812
  // #json_elements especially defined for submit_json_as_php_array()
1813
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1814
  return system_settings_form($form);
1815
}
1816

    
1817

    
1818
/**
1819
 * @param $form_name
1820
 * @param $form_title
1821
 * @param $collapsed
1822
 * @param string $form_description
1823
 *   The description for the fieldset of the gallery setting.
1824
 * @return mixed
1825
 */
1826
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1827
  $form[$form_name] = array(
1828
    '#type' => 'fieldset',
1829
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1830
    '#collapsible' => TRUE,
1831
    '#collapsed' => $collapsed,
1832
    '#tree' => TRUE,
1833
    '#description' => $form_description,
1834
  );
1835

    
1836
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1837
  $gallery_settings = variable_get($form_name, $default_values);
1838
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1839
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1840
    /*
1841
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1842
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1843
    '#type' => 'textfield',
1844
    '#title' => t('Search Page Size'),
1845
    '#default_value' => $test,
1846
    '#description' => t('Number of Names to display per page in search results.')
1847
    );
1848
    */
1849
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1850
      '#type' => 'checkbox',
1851
      '#title' => t('Show media thumbnails for accepted taxa'),
1852
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1853
    );
1854

    
1855
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1856
      '#type' => 'checkbox',
1857
      '#title' => t('Show media thumbnails for synonyms'),
1858
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1859
      '#description' => '',
1860
    );
1861
  }
1862

    
1863
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1864
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1865
    '#type' => 'checkbox',
1866
    '#title' => t('Show captions under thumbnails'),
1867
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1868
    '#description' => '',
1869
  );
1870

    
1871
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1872
    '#type' => 'textfield',
1873
    '#title' => t('Thumbnail size') . ':',
1874
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1875
    '#description' => t('Select the size of each individual thumbnail.'),
1876
  );
1877

    
1878
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1879
    '#type' => 'textfield',
1880
    '#title' => t('Number of columns') . ':',
1881
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1882
    '#description' => t('Group the thumbnails in columns: select how many
1883
      columns the gallery should display.'),
1884
  );
1885

    
1886
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1887
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1888
      '#type' => 'textfield',
1889
      '#title' => t('Maximum number of rows') . ':',
1890
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1891
      '#description' => t('You can group the thumbnails in rows, select in how
1892
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1893
        If you want an unlimited number of rows please set to 0.'),
1894
    );
1895
  }
1896

    
1897
  return $form;
1898
}
1899

    
1900
/**
1901
 * @todo document this function.
1902
 */
1903
function cdm_settings_layout_taxon() {
1904
  $collapsed = FALSE;
1905
  $form = array();
1906

    
1907
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1908

    
1909
  // --------- TABBED TAXON ------- //
1910
  $form['taxon_tabs'] = array(
1911
    '#type' => 'fieldset',
1912
    '#title' => t('Taxon tabs'),
1913
    '#collapsible' => TRUE,
1914
    '#collapsed' => TRUE,
1915
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1916
  );
1917

    
1918
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1919
    '#type' => 'checkbox',
1920
    '#title' => t('Tabbed taxon page'),
1921
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1922
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1923
  );
1924

    
1925
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1926
    '#type' => 'checkbox',
1927
    '#title' => t('Synonymy as tab'),
1928
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1929
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1930
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1931
  );
1932

    
1933
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1934
    '#type' => 'checkboxes',
1935
    '#title' => t('Section/Tab visibility') . ':',
1936
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1937
    '#options' => get_taxon_options_list()
1938
  );
1939

    
1940
  // WEIGHT
1941
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1942
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1943
    '#title'  => 'Section/Tab order',
1944
    '#type' => 'fieldset',
1945
    '#collapsible' => false,
1946
    '#tree' => true,
1947
    '#description' => 'The weight value defines the order of the section/tab.'
1948
  );
1949
  // Weights range from -delta to +delta, so delta should be at least half
1950
  // of the amount of tabs present.
1951
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1952
  foreach (get_taxon_tabs_list() as $label) {
1953
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1954
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1955
        '#title' => $label,
1956
        '#type'  => 'weight',
1957
        '#default_value' => $taxon_tabs_weights[$key],
1958
        '#delta' => $tab_weight_delta
1959
    );
1960
  }
1961

    
1962
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1963
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1964
    '#title'  => 'Section/Tab label override',
1965
    '#type' => 'fieldset',
1966
    '#collapsible' => false,
1967
    '#tree' => true,
1968
    '#description' => 'Setting a label for a section/tab will override the default label. 
1969
      Please enter the label text in the default language of the portal.'
1970
  );
1971
  foreach (get_taxon_tabs_list() as $label) {
1972
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1973
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1974
      '#title' => $label,
1975
      '#type'  => 'textfield',
1976
      '#default_value' => $taxon_tabs_labels[$key]
1977
    );
1978
  }
1979

    
1980
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1981
    '#type' => 'select',
1982
    '#title' => t('Default tab to display') . ':',
1983
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1984
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1985
    '#description' => t('<p>Select the default tab to display when visiting a
1986
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1987
      <strong>Note:</strong> After performing a search and clicking in any
1988
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1989
      taxon and not the above selected tab.'),
1990
  );
1991

    
1992
  /* ======  TAXON_PROFILE ====== */
1993
  $form['taxon_profile'] = array(
1994
    '#type' => 'fieldset',
1995
    '#title' => t('Taxon profile (tab)'),
1996
    '#description' => t('<p>This section covers the settings related to the taxon
1997
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1998
    '#collapsible' => TRUE,
1999
    '#collapsed' => TRUE,
2000
  );
2001

    
2002
  // ---- PROFILE PICTURE ----//
2003

    
2004
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2005
    '#type' => 'fieldset',
2006
    '#tree' => TRUE,
2007
    '#title' => t('Taxon profile picture'),
2008
    '#collapsible' => TRUE,
2009
    '#collapsed' => FALSE,
2010
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2011
  );
2012

    
2013
  //FIXME migrate variables:
2014
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2015
  // FIXME
2016
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2017

    
2018
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2019

    
2020
  /*
2021
   * 'show' => 1,
2022
   * 'maxextend' => 184,
2023
   * 'media_uri_query' => ''
2024
   * 'custom_placeholder_image_on' => 1,
2025
   * 'custom_placeholder_image_fid' => ''
2026
   */
2027
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2028
    '#type' => 'checkbox',
2029
    '#title' => t('Enable profile picture'),
2030
    '#description' => t('Show the profile picture.'),
2031
    '#default_value' => $taxon_profile_image_settings['show'],
2032
  );
2033

    
2034
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2035
      '#type' => 'textfield',
2036
      '#tree' => TRUE,
2037
      '#title' => t('Profile picture maximum extend'),
2038
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2039
      '#field_suffix' => 'px',
2040
      '#maxlength' => 4,
2041
      '#size' => 4,
2042
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2043
  );
2044

    
2045
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2046
      '#type' => 'textfield',
2047
      '#tree' => TRUE,
2048
      '#title' => t('Additional URI query parameter'),
2049
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2050
      '#maxlength' => 1024,
2051
      '#size' => 60,
2052
      '#description' => t('Additional query parameters to be used when requesting for the  
2053
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2054
            The query parameters will be appended to the uri of the media representation part
2055
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2056
  );
2057

    
2058
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2059
    '#type' => 'checkbox',
2060
    '#title' => t('Show the placeholder image'),
2061
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2062
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2063
  );
2064

    
2065
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2066
      '#type' => 'checkbox',
2067
      '#title' => t('Use a custom placeholder image'),
2068
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2069
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2070
  );
2071

    
2072
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2073
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2074
        '#type' => 'managed_file',
2075
        '#title' => t('Custom placeholder image file'),
2076
        '#progress_indicator' => 'bar',
2077
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2078
    //       '#name' => 'custom_placeholder_image',
2079
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2080
    );
2081

    
2082
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2083
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2084
      $url = file_create_url($profile_image_file->uri);
2085
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2086
                '#type' => 'item',
2087
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2088
      );
2089
    }
2090
  } else {
2091
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2092
      '#type' => 'hidden',
2093
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2094
    );
2095
  }
2096

    
2097
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2098
  array_unshift($options, '-- DISABLED --');
2099
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2100
    '#type' => 'select',
2101
    '#title' => t('Hide profile picture for higher ranks') . ':',
2102
    '#default_value' => variable_get('image_hide_rank', '0'),
2103
    '#options' => $options,
2104
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2105
  );
2106

    
2107
  // -- MEDIA THUMBNAILS -- //
2108
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2109
  $form_title = 'Taxon Profile Images';
2110
  $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>';
2111
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2112

    
2113
  // ---- FEATURE TREE BLOCKS ---- //
2114
  $form['taxon_profile']['feature_blocks'] = array(
2115
    '#type' => 'fieldset',
2116
    '#title' => t('Feature Blocks'),
2117
    '#collapsible' => TRUE,
2118
    '#collapsed' => FALSE,
2119
    '#description' => t("This section covers settings related to the taxon's
2120
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2121
      features such as description, distribution, common names"),
2122
  );
2123
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2124
  $profile_feature_tree = get_profile_feature_tree();
2125
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2126
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2127
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2128
  }
2129
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2130
    '#type' => 'radios',
2131
    '#title' => t('Taxon profile feature tree') . ':',
2132
    '#default_value' => $profile_feature_tree_uuid,
2133
    '#options' =>  $featureTrees['options'],
2134
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2135
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2136
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2137
      profile page.'
2138
    ),
2139
  );
2140

    
2141
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2142
  $profile_feature_tree = get_profile_feature_tree();
2143

    
2144
  if (isset($profile_feature_tree->root->childNodes)) {
2145

    
2146
    $form_feature_block_layout = array(
2147
      '#type' => 'fieldset',
2148
      '#tree' => true,
2149
      '#title' => t('Taxon profile feature block settings'),
2150
      '#collapsible' => TRUE,
2151
      '#collapsed' => FALSE,
2152
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2153
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2154
      The subforms have the following settings in common:<br />
2155
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2156
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2157
      <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>
2158
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2159
            <ol>
2160
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2161
                appended in brackets like "text (source references)". If the original source has name in source
2162
                information it will be appended to the citation string,
2163
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2164
             <li>if the text of the TextData is empty, the original source citations are the only content
2165
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2166
                prepended to the citation string like: "name in source: citation"</li>
2167
            </ol>
2168
            <strong>If disabled:</strong><br />
2169
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2170
             citations are the only content, the resulting feature block content would only consist of footnotes.
2171
             In this case the display of the respective feature block is suppressed.</div>
2172
      </dl>
2173
      <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
2174
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2175
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2176
        . '</em></div>
2177
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2178
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2179
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2180
      <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>
2181
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2182
           cdm_feature_block_element_tag_name()</div>
2183
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2184
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2185
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2186
    );
2187

    
2188

    
2189
    $feature_list_layout_settings_disabled = FALSE;
2190

    
2191
    // creating helper object to retrieve the default settings
2192
    $featureNode = new stdClass();
2193
    $featureNode->feature = new stdClass();
2194
    $featureNode->feature->uuid="DEFAULT";
2195
    $featureNode->feature->representation_L10n = "Default";
2196
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2197

    
2198
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2199

    
2200
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2201

    
2202
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2203
        $subform_id = $featureNode->feature->uuid;
2204
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2205

    
2206
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2207

    
2208
        $form_feature_block_layout[$subform_id] = array(
2209
          '#type' => 'fieldset',
2210
          '#tree' => TRUE,
2211
          '#title' => $featureNode->feature->representation_L10n,
2212
          '#collapsible' => FALSE,
2213
          '#collapsed' => FALSE,
2214
        );
2215
        if($featureNode->feature->uuid == "DEFAULT"){
2216
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2217
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2218
          references</em> and <em>names in source</em> is only possible in the defaults';
2219
        }
2220

    
2221
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2222
          '#type' => 'select',
2223
          '#title' => 'List type',
2224
          '#default_value' => $feature_block_setting['as_list'],
2225
          '#options' => array(
2226
            'div' => 'not as list',
2227
            'ul' => 'bullet list',
2228
            'ol' => 'numbered list',
2229
            'dl' => 'definition list'
2230
          ),
2231
        );
2232

    
2233
        if($featureNode->feature->uuid == "DEFAULT"){
2234
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2235
            '#type' => 'checkbox',
2236
            '#title' => t('Link to reference'),
2237
            '#default_value' => $feature_block_setting['link_to_reference'],
2238
          );
2239

    
2240
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2241
            '#type' => 'checkbox',
2242
            '#title' => 'Link to name used in source',
2243
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2244
          );
2245
        }
2246

    
2247
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2248
          '#type' => 'checkbox',
2249
          '#title' => 'Sources as content',
2250
          '#default_value' => $feature_block_setting['sources_as_content'],
2251
        );
2252

    
2253
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2254
          '#type' => 'checkbox',
2255
          '#title' => 'Put sources also as content to bibliography',
2256
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2257
        );
2258

    
2259
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2260
          '#type' => 'select',
2261
          '#title' => t('Sort elements'),
2262
          '#default_value' => $feature_block_setting['sort_elements'],
2263
          '#options' => array(
2264
            NO_SORT => 'No sorting',
2265
            SORT_ASC => 'Ascending',
2266
            SORT_DESC => 'Descending',
2267
            SORT_HIERARCHICAL => 'Hierarchical'
2268
          ),
2269
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2270
          <dl>
2271
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2272
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2273
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2274
          <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>
2275
          </dl>',
2276
        );
2277

    
2278
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2279
          '#type' => 'select',
2280
          '#title' => t('Element tag'),
2281
          '#options' => array(
2282
            'span' => 'span',
2283
            'div' => 'div',
2284
            'p' => 'p'
2285
          ),
2286
          '#default_value' => $feature_block_setting['element_tag'],
2287
        );
2288
        $form_feature_block_layout[$subform_id]['glue'] = array(
2289
          '#type' => 'textfield',
2290
          '#title' => t('Element glue'),
2291
          '#default_value' => $feature_block_setting['glue'],
2292
          '#size' => 10
2293
      );
2294

    
2295
      }
2296
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2297
    }
2298
  }
2299

    
2300
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2301
  $form['taxon_profile']['structured_description_featuretree'] = array(
2302
    '#type' => 'fieldset',
2303
    '#title' => t('Structured Description Feature Tree'),
2304
    '#collapsible' => TRUE,
2305
    '#collapsed' => FALSE,
2306
  );
2307
  $featureTrees = cdm_get_featureTrees_as_options();
2308
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2309
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2310
    $profile_feature_tree_uuid = NULL;
2311
  }
2312
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2313
    '#type' => 'radios',
2314
    '#title' => t('Natural language representation of structured descriptions') . ':',
2315
    '#default_value' => $profile_feature_tree_uuid,
2316
    '#options' => $featureTrees['options'],
2317
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2318
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2319
    '#description' => t('Taxon descriptions can be stored in a highly structured
2320
      form. The feature tree selected here will be used to generate textual
2321
      representation in natural language.'
2322
    ),
2323
  );
2324

    
2325

    
2326

    
2327
  // ---- DISTRIBUTION LAYOUT ---- //
2328
  $form['taxon_profile']['distribution_layout'] = array(
2329
    '#title' => t('Distribution'),
2330
    '#collapsible' => TRUE,
2331
    '#collapsed' => FALSE,
2332
    '#type' => 'fieldset',
2333
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2334
        Map settings regarding the geometry, layers, etc are found in the '
2335
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2336
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2337
      . l(
2338
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2339
        array('fragment' => 'edit-feature-block-settings')
2340
      )
2341
      . ' More general settings regrading the filtering of Distributions are found at '
2342
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2343
      . '. (These settings here will be merged in future releases into the feature block settings)',
2344

    
2345
  );
2346

    
2347
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2348

    
2349
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2350
    '#type' => 'checkbox',
2351
    '#title' => t('Condensed distribution'),
2352
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2353
    '#description' => 'This option enables the display of a very compact representation
2354
    of the distribution which includes also information on the status.',
2355
  );
2356

    
2357
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2358
    '#type' => 'select',
2359
    '#title' => t('Condensed distribution recipe'),
2360
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2361
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2362
    '#description' => 'Recipe for creating the condensed distribution.',
2363
  );
2364

    
2365
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2366
    '#type' => 'textfield',
2367
    '#title' => t('Condensed distribution info path'),
2368
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2369
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2370
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2371
  );
2372

    
2373

    
2374
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2375
    '#type' => 'radios',
2376
    '#title' => t('Display mode') . ':',
2377
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2378
    '#options' => array(
2379
      'FLAT_ALPHA' => t('Flat list'),
2380
      'TREE' => t('Hierarchically ordered'),
2381
    ),
2382
    '#description' => 'Taxon distribution information is displayed with
2383
    focus on the area of the distribution. The list of areas can either be shown
2384
    as flat list ordered alphabetically or in the hierarchical of the parent
2385
    area and subarea relationship. Fall back areas areas with no Distribution data
2386
    are hidden from the area hierarchy so that their sub areas will move one level up.
2387
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2388
    ' for details on the <em>Marked area filter</em>.',
2389
  );
2390

    
2391
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2392
    '#type' => 'fieldset',
2393
    '#tree' => true,
2394
    '#title' => t('Distribution hierarchy style')
2395
  );
2396

    
2397
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2398
  foreach(array_keys($hierarchy_styles) as $level) {
2399
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2400
      '#type' => 'fieldset',
2401
      '#tree' => true,
2402
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2403
      '#attributes' => array('class' => array('fieldset-float'))
2404
    );
2405
    foreach ($hierarchy_styles[$level] as $key => $value) {
2406
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2407
        '#type' => 'textfield',
2408
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2409
        '#default_value' => $hierarchy_styles[$level][$key],
2410
        '#maxlength' => 4,
2411
        '#size' => 4
2412
      );
2413
    }
2414
  }
2415

    
2416
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2417
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2418
    '#type' => 'checkboxes',
2419
    '#title' => 'Omit area levels',
2420
    '#options' => $level_options,
2421
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2422
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2423
    Areas which belong to the selected area levels will be hidden in the portal.',
2424
  );
2425

    
2426
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2427
    '#type' => 'checkbox',
2428
    '#title' => t('Show TextData elements on top of the map'),
2429
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2430
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2431
      elements on top of the map. Otherwise all <code>TextData</code>
2432
      distribution elements will be listed below the other area elements.
2433
      This option is useful if you need to have descriptive texts for each
2434
      distribution map.'),
2435
  );
2436

    
2437
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2438
      '#type' => 'textarea',
2439
      '#title' => t('Custom status colors'),
2440
      '#element_validate' => array('form_element_validate_json'),
2441
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2442
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2443
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2444
          reference list of the idInVocabulary values of absence and presence terms:
2445
<pre>
2446
Presence Term
2447
p        present
2448
pd        present: doubtfully present
2449
n        native
2450
nq        native: presence questionable
2451
nd        native: doubtfully native
2452
c        cultivated
2453
i        introduced
2454
iq        introduced: presence questionable
2455
id        introduced: doubtfully introduced (perhaps cultivated only)
2456
ip        introduced: uncertain degree of naturalisation
2457
ia        introduced: adventitious (casual)
2458
in        introduced: naturalized
2459
ic        introduced: cultivated
2460
e        endemic for the relevant area
2461
na        naturalised
2462
iv        invasive
2463

2464
AbsenceTerm
2465
a        absent
2466
f        reported in error
2467
nf        native: reported in error
2468
if        introduced: reported in error
2469
cf        cultivated: reported in error
2470
ne        native: formerly native
2471
ie        introduced: formerly introduced
2472

2473
</pre>'),
2474
  );
2475

    
2476

    
2477
  /* ====== SYNONYMY ====== */
2478
  $form['taxon_synonymy'] = array(
2479
    '#type' => 'fieldset',
2480
    '#title' => t('Taxon synonymy (tab)'),
2481
    '#collapsible' => TRUE,
2482
    '#collapsed' => TRUE,
2483
    '#description' => t('This section covers the settings related to the taxon
2484
      <strong>synonymy</strong> tab.'),
2485
  );
2486

    
2487
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2488
    '#type' => 'checkbox',
2489
    '#title' => t('Accepted taxon on top of the synonymy'),
2490
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2491
    '#description' => t('If checked, the first homotypic taxon is a repetition
2492
      of the accepted taxon most likely with the full nomenclatural reference, 
2493
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2494
  );
2495

    
2496
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2497
    '#type' => 'checkbox',
2498
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2499
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2500
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2501
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2502
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2503
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE)
2504
  );
2505

    
2506
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2507
    '#type' => 'textfield',
2508
    '#description' => 'Label for the secundum referenence.',
2509
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2510
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2511
    );
2512

    
2513
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2514
    '#type' => 'checkbox',
2515
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2516
      coming from a synonym link.'),
2517
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2518
    '#description' => t('Check this if after doing a search and clicking on a
2519
      synonym you want to see the "accept of" text for the accepted synonym.'),
2520
  );
2521

    
2522
  /* === currently unused ===
2523
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2524
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2525
    '#type' => 'checkboxes',
2526
    '#title' => t('Display name relationships') . ':',
2527
    '#default_value' => variable_get('name_relationships_to_show', 0),
2528
    '#options' => $nameRelationshipTypeOptions,
2529
    '#description' => t('Select the name relationships you want to show for the
2530
      accepted taxa.'),
2531
  );
2532
 */
2533

    
2534
  $form['taxon_synonymy']['taxon_relations'] = array(
2535
    '#type' => 'fieldset',
2536
    '#title' => t('Taxon relationships'),
2537
    '#collapsible' => FALSE,
2538
    '#collapsed' => FALSE
2539
  );
2540

    
2541
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2542
    '#type' => 'checkbox',
2543
    '#title' => t('Show taxon relations ships of accepted taxon'),
2544
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2545
    '#description' => t('If this option is enabled the synonymy will show the
2546
      below selected taxon relationships of accepted taxa.'),
2547
  );
2548

    
2549
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2550
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2551
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2552
    '#type' => 'checkboxes',
2553
    '#title' => t('Taxon relationship types') . ':',
2554
    '#description' => t('Only taxon relationships of the selected type will be
2555
      displayed'),
2556
    '#options' => $taxon_relationship_type_options,
2557
    '#default_value' => $taxon_relationship_type_defaults,
2558
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2559
  );
2560

    
2561
  $form['taxon_synonymy']['name_relations'] = array(
2562
    '#type' => 'fieldset',
2563
    '#title' => t('Name relationships'),
2564
    '#collapsible' => FALSE,
2565
    '#collapsed' => FALSE
2566
  );
2567

    
2568
  $name_relationship_type_options = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2569
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2570
    '#type' => 'checkboxes',
2571
    '#title' => t('Name relationship types') . ':',
2572
    '#description' => t('Only name relationships of the selected type will be
2573
      displayed'),
2574
    '#options' => $name_relationship_type_options,
2575
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2576
  );
2577

    
2578
  // ====== SPECIMENS ====== //
2579
  $form['taxon_specimens'] = array(
2580
    '#type' => 'fieldset',
2581
    '#title' => t('Taxon specimens (tab)'),
2582
    '#collapsible' => TRUE,
2583
    '#collapsed' => TRUE,
2584
    '#description' => t('This section covers the settings related to the taxon
2585
      <strong>specimens</strong> tab.'),
2586
  );
2587

    
2588
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2589

    
2590
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2591
    '#type' => 'checkbox',
2592
    '#title' => t('Show specimen derivatives in a compressed table'),
2593
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2594
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2595
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2596
  );
2597

    
2598
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2599
      '#type' => 'textfield',
2600
      '#title' => t('Number of records per page') . ':',
2601
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2602
  );
2603

    
2604
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2605
        '#type' => 'checkbox',
2606
        '#title' => t('Show specimen derivatives in a tree view'),
2607
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2608
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2609
    );
2610

    
2611

    
2612
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2613
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2614
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2615
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2616
  }
2617
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2618
    '#type' => 'radios',
2619
    '#title' => t('Specimen description feature tree') . ':',
2620
    '#default_value' => $profile_feature_tree_uuid,
2621
    '#options' =>  $featureTrees['options'],
2622
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2623
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2624
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2625
    ),
2626
  );
2627

    
2628
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2629
  $form_title = t('Specimen media');
2630
  $form_description = t('Specimens may have media which is displayed at the
2631
     Specimen tab/section as a gallery. It is possible to configure the
2632
     thumbnails gallery here, however for configuring how a single media should
2633
     be displayed please go to !url.</p>',
2634
     array(
2635
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2636
     ));
2637
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2638

    
2639
  // --- MEDIA GALLERY ---- //
2640
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2641
  $form_title = 'Media gallery (tab)';
2642
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2643
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2644
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2645
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2646
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2647
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2648
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2649

    
2650
  // Comment @WA: D7 form api does not support reset buttons,
2651
  // so to mimic the D5 reset button we add one like this.
2652
  $form['actions']['reset'] = array(
2653
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2654
    '#weight' => 1000,
2655
  );
2656
  return system_settings_form($form);
2657
}
2658

    
2659
/**
2660
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2661
 *
2662
 * @param $map_id
2663
 * @param $form
2664
 * @return mixed
2665
 */
2666
function _cdm_map_visibility_setting($map_id)
2667
{
2668
  return array(
2669
    '#type' => 'select',
2670
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2671
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2672
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2673
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2674
        The map also can forced to show up <b>always</b> or <b>never</b>."
2675
  );
2676
}
2677

    
2678
/**
2679
 * @todo document this function.
2680
 */
2681
function cdm_settings_layout_search() {
2682

    
2683
  $form = array();
2684

    
2685
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2686

    
2687
  $form['search_settings'] = array(
2688
    '#type' => 'fieldset',
2689
    '#title' => t('Taxa Search'),
2690
    '#collapsible' => FALSE,
2691
    '#collapsed' => FALSE,
2692
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2693
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2694
         where they can write the text to be searched. You can find Drupal block configuration
2695
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2696
  );
2697

    
2698
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2699
      '#type' => 'checkbox',
2700
      '#title' => t('Ignore the chosen classification in simple search'),
2701
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2702
      '#description' => t('The simple search, which can be executed via the search block,
2703
          will by default search on the classification selected in the classification browser
2704
          selector. Set the tick if you want your portal to search on all classifications.'),
2705
  );
2706

    
2707
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2708
    '#type' => 'checkbox',
2709
    '#title' => t('Run simple search with free-text search backend.'),
2710
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2711
    '#description' => t('The simple search uses by default another search
2712
      backend as the advances search. By checking this option the simple search can be
2713
      configured to also use the free-text search backend.'),
2714
  );
2715

    
2716
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2717
    '#type' => 'checkbox',
2718
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2719
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2720
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2721
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2722
  );
2723

    
2724
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2725
    '#type' => 'textfield',
2726
    '#title' => t('Results per page') . ':',
2727
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2728
    '#description' => t('Number of results to display per page.'),
2729
  );
2730

    
2731
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2732
    '#type' => 'checkbox',
2733
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2734
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2735
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2736
  );
2737

    
2738
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2739
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2740
      '#type' => 'checkboxes',
2741
      '#title' => 'Search mode',
2742
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2743
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2744
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2745
          defaults set here.',
2746
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2747
      '#default_value' => $search_mode_default
2748
      );
2749

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

    
2755
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2756
  );
2757

    
2758
  // --- SEARCH TAXA GALLERY ---- //
2759
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2760
  $collapsed = FALSE;
2761
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2762
  $form_title = 'Taxa Search thumbnails';
2763
  $form_description = 'Search results may show thumbnails. ';
2764
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2765

    
2766
  // Comment @WA: D7 form api does not support reset buttons,
2767
  // so to mimic the D5 reset button we add one like this.
2768
  $form['actions']['reset'] = array(
2769
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2770
    '#weight' => 1000,
2771
  );
2772
  return system_settings_form($form);
2773
}
2774

    
2775
/**
2776
 * @todo document this function.
2777
 */
2778
function cdm_settings_layout_media() {
2779

    
2780
  $form = array();
2781

    
2782
  $form['media_settings'] = array(
2783
    '#type' => 'fieldset',
2784
    '#title' => t('Media settings'),
2785
    '#collapsible' => FALSE,
2786
    '#collapsed' => FALSE,
2787
    '#description' => 'This section covers layout settings for media pages.'
2788
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2789
  );
2790

    
2791
  $form['media_settings']['image_gallery_viewer'] = array(
2792
    '#type' => 'select',
2793
    '#title' => t('Image viewer') . ':',
2794
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2795
    '#options' => array(
2796
      'default' => t('Standard image viewer'),
2797
      'fsi' => t('FSI viewer (requires FSI server!)'),
2798
    ),
2799
  );
2800

    
2801
  // --- STANDARD_IMAGE_VIEWER ---- //
2802
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2803
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2804
      '#type' => 'fieldset',
2805
      '#tree' => true,
2806
      '#title' => t('Standard image viewer settings'),
2807
      '#collapsible' => FALSE,
2808
      '#collapsed' => FALSE,
2809
      );
2810

    
2811
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2812
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2813
      '#type' => 'checkbox',
2814
      '#title' => 'Show media representations',
2815
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2816

    
2817
    );
2818
  }
2819

    
2820

    
2821
  // @WA: D7 form api does not support reset buttons,
2822
  // so to mimic the D5 reset button we add one like this.
2823
  $form['actions']['reset'] = array(
2824
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2825
    '#weight' => 1000,
2826
  );
2827
  return system_settings_form($form);
2828
}
2829

    
2830
/**
2831
 * GEOSERVICE and Map settings.
2832
 */
2833
function cdm_settings_geo($form, &$form_state) {
2834

    
2835
  $current_geoserver_settings = get_edit_map_service_settings();
2836
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2837

    
2838

    
2839
  $form = array();
2840

    
2841
  $dummy_distribution_query = NULL;
2842
  if($map_distribution['map_type'] != 1){
2843
    // we need to apply a dummy query since the map service requires for image maps
2844
    // at least as and ad to be defined
2845
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2846
  }
2847

    
2848
  $form['map_preview'] = array(
2849
      '#type' => 'fieldset',
2850
      '#tree' => FALSE,
2851
      '#title' => t('Map preview'),
2852
      '#collapsible' => FALSE,
2853
      '#description' => 'The preview of the map'
2854
       . ($dummy_distribution_query != null ?
2855
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2856
           '.<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.')
2857
  );
2858
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2859
    'move' => "this.cdmOpenlayersMap.printInfo",
2860
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2861
  ), true // resizable
2862
  );
2863

    
2864
  /*
2865
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2866
  );
2867
  */
2868

    
2869
  /*
2870
   * GEO SERVER
2871
   */
2872
  $form['edit_map_server'] = array(
2873
    '#type' => 'fieldset',
2874
    '#tree' => true,
2875
    '#title' => t('EDIT map service'),
2876
    '#collapsible' => TRUE,
2877
    '#collapsed' => TRUE,
2878
    '#description' => t('Configuration and selection of your geo server.
2879
      The Geo Server is responsible for generating the maps.'),
2880
  );
2881

    
2882
  $form['edit_map_server']['base_uri'] = array(
2883
    '#type' => 'select',
2884
    '#title' => t('EDIT map service') . ':',
2885
    '#default_value' => $current_geoserver_settings['base_uri'],
2886
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2887
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2888
  );
2889
  $form['edit_map_server']['version'] = array(
2890
      '#type' => 'select',
2891
      '#title' => t('Version') . ':',
2892
      '#default_value' => $current_geoserver_settings['version'],
2893
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2894
      '#description' => t('The version of the EDIT map services'),
2895
  );
2896

    
2897
  /*
2898
   * MAP SETTINGS
2899
   */
2900

    
2901
  $form[CDM_MAP_DISTRIBUTION] = array(
2902
    '#type' => 'fieldset',
2903
    '#tree' => TRUE,
2904
    '#title' => t('Maps settings'),
2905
    '#collapsible' => TRUE,
2906
    '#collapsed' => TRUE,
2907
    '#description' => t('General configuration for all map types.'),
2908
  );
2909

    
2910
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2911
    '#type' => 'radios',
2912
    '#title' => 'Map types',
2913
    '#options' => array(
2914
      1 => "OpenLayers dynamic map viewer",
2915
      0 => "Plain image",
2916
    ),
2917
    '#default_value' => $map_distribution['map_type'],
2918
    '#description' => 'Two different map types are available :
2919
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2920
      which allows zooming and panning. If enabled you can configure the default layer
2921
      (background of your maps) below.</li>
2922
      <li><em>Plain image</em>: The map will be static non interactive
2923
      image.</li></ul>',
2924
  );
2925
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2926

    
2927
  /*
2928
   * settings for the distribution map are used also for specimens map!!!!
2929
   */
2930

    
2931
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2932
      '#type' => 'textfield',
2933
      '#title' => 'Aspect ratio',
2934
      '#default_value' => $map_distribution['aspect_ratio'],
2935
      '#maxlength' => 4,
2936
      '#size' => 4,
2937
      '#element_validate' => array('element_validate_number'),
2938
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2939
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2940
      width by the height:</br>
2941
      <pre>aspect ratio = w / h</pre>
2942
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2943
      for a square map use <strong>1</strong>.',
2944
  );
2945

    
2946
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2947
    '#type' => 'textfield',
2948
    '#title' => 'Bounding box',
2949
    '#default_value' => $map_distribution['bbox'],
2950
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2951
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2952
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2953
      <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.
2954
      (Maybe you need to change the map base layer to OpeLayers.)
2955
      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
2956
      below the map from where you can copy the bbox string.</p>'),
2957
  );
2958

    
2959
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2960
    '#type' => 'select',
2961
    '#title' => 'Max zoom level',
2962
    '#default_value' => $map_distribution['maxZoom'],
2963
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2964
  );
2965

    
2966
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2967
    '#type' => 'checkbox',
2968
    '#title' => 'Display area labels',
2969
    '#default_value' => $map_distribution['show_labels'],
2970
    '#description' => t('The map will show name labels of the areas'),
2971
  );
2972

    
2973
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2974
    '#type' => 'textfield',
2975
    '#title' => 'Map caption',
2976
    '#default_value' => $map_distribution['caption'],
2977
    '#description' => t('The caption will be shown below the map.'),
2978
  );
2979

    
2980
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2981
    '#type' => 'textfield',
2982
    '#title' => 'Distribution layer opacity',
2983
    '#default_value' => $map_distribution['distribution_opacity'],
2984
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2985
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2986
  );
2987

    
2988
  // --- Plain Image Settings --- //
2989
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2990
    '#type' => 'fieldset',
2991
    '#title' => 'Plain image map settings',
2992
    '#tree' => TRUE,
2993
    '#collapsible' => TRUE,
2994
    '#collapsed' => $open_layers_is_enabled,
2995
    '#description' => 'The settings in this section are still expertimental
2996
      and can only be used with the EDIT map service version 1.1 or above.',
2997
  );
2998
  $edit_mapserver_version = get_edit_map_service_version_number();
2999
  if ($edit_mapserver_version < 1.1) {
3000
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3001
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3002
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3003
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3004
  }
3005

    
3006
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3007
    '#type' => 'textfield',
3008
    '#title' => 'Width',
3009
    '#default_value' => $map_distribution['image_map']['width'],
3010
    '#maxlength' => 4,
3011
    '#size' => 4,
3012
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3013
  );
3014

    
3015
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3016
    '#type' => 'textfield',
3017
    '#title' => 'Background layer',
3018
    '#default_value' => $map_distribution['image_map']['base_layer'],
3019
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3020
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3021
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3022
    )),
3023
  );
3024

    
3025
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3026
    '#type' => 'textfield',
3027
    '#title' => 'Background color',
3028
    '#default_value' => $map_distribution['image_map']['bg_color'],
3029
  );
3030

    
3031
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3032
    '#type' => 'textfield',
3033
    '#title' => 'Background layer style',
3034
     // Only line color by now.
3035
    '#default_value' => $map_distribution['image_map']['layer_style'],
3036
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3037
  );
3038

    
3039
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3040
      '#type' => 'textfield',
3041
      '#title' => 'Projection',
3042
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3043
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3044
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3045
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3046
  );
3047

    
3048

    
3049
  // --- OpenLayers Settings --- //
3050
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3051
    '#type' => 'fieldset',
3052
    '#title' => 'OpenLayers settings',
3053
    '#tree' => TRUE,
3054
    '#collapsible' => TRUE,
3055
    '#collapsed' => !$open_layers_is_enabled,
3056
    '#description' => '',
3057
  );
3058

    
3059

    
3060
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3061
      '#type' => 'checkbox',
3062
      '#title' => 'Display outside max extent',
3063
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3064
      '#description' => t('Allows the map to display parts of the layers which are outside
3065
         the max extent if the aspect ratio of the map and of the baselayer
3066
         are not equal.'),
3067
  );
3068

    
3069

    
3070
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3071
      '#type' => 'checkbox',
3072
      '#title' => 'Show Layer Switcher',
3073
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3074
      '#description' => 'The Layer Switcher control displays a table of contents
3075
      for the map.  This allows the user interface to switch between
3076
      base layers and to show or hide overlays.  By default the switcher is
3077
      shown minimized on the right edge of the map, the user may expand it
3078
      by clicking on the handle.',
3079
  );
3080

    
3081
  if (!$open_layers_is_enabled) {
3082
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3083
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3084
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3085
  }
3086

    
3087
  // The default layer must always be enabled
3088
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3089
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3090

    
3091
  $baselayer_options = array(
3092
    /*
3093
   NOTICE: must correspond to the layers defined in
3094
   js/openlayers_,ap.js#getLayersByName()
3095
   */
3096
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3097
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3098
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3099
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3100
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3101
    // all others EPSG:900913
3102
    'mapnik' => 'OpenStreetMap (mapnik)',
3103
    'stamen_terrain' => 'Stamen Terrain',
3104
    'open_topomap' => 'OpenTopoMap',
3105
    // map quest is no longer free. it is required to sign up for a test plan.
3106
    // 'mapquest_open' => "MapQuest",
3107
    // 'mapquest_sat' => "MapQuest Sattelite",
3108
    'groadmap' => 'Google Roadmap',
3109
    'gsatellite' => 'Google Satellite',
3110
    'ghybrid' => 'Google Hybrid',
3111
    'gterrain' => 'Google Terrain',
3112
//     'veroad' => 'Virtual Earth Roads',
3113
//     'veaer' => 'Virtual Earth Aerial',
3114
//     'vehyb' => 'Virtual Earth Hybrid',
3115
    // 'yahoo' => 'Yahoo Street',
3116
    // 'yahoosat' => 'Yahoo Satellite',
3117
    // 'yahoohyb' => 'Yahoo Hybrid',
3118
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3119
  );
3120

    
3121
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3122
    '#type' => 'checkboxes_preferred',
3123
    '#title' => 'Base Layers',
3124
    '#options' => $baselayer_options,
3125
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3126
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3127
  );
3128

    
3129
  $google_maps_api_key = null;
3130
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3131
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3132
  }
3133
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3134
    '#type' => 'textfield',
3135
    '#title' => 'Google Maps API Key',
3136
    '#default_value' => $google_maps_api_key,
3137
    '#description' => 'In order to use any of the Google map layers you need to provide 
3138
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3139
  );
3140

    
3141
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3142
    $map_distribution['openlayers']['custom_wms_base_layer'],
3143
    'Custom WMS base layer',
3144
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3145
    true // add projection settings
3146
    );
3147

    
3148
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3149
    $map_distribution['openlayers']['wms_overlay_layer'],
3150
    'WMS overlay layer',
3151
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3152
                You can actually combine multiple layers for this overlay. 
3153
                For details please refer to the wms query parameter <code>Layers</code> .'
3154
  );
3155

    
3156
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3157
    '#type' => 'checkbox',
3158
    '#title' => 'Enable overlay layer',
3159
    '#weight' => -100,
3160
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3161
  );
3162

    
3163
  /*
3164
   * Map Legend
3165
   */
3166
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3167
    '#type' => 'fieldset',
3168
    '#title' => 'Map legend',
3169
    '#tree' => TRUE,
3170
    '#collapsible' => TRUE,
3171
    '#collapsed' => TRUE,
3172
    '#description' => 'Configure the maps legend.',
3173
  );
3174

    
3175
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3176
    '#type' => 'checkbox',
3177
    '#title' => 'Display a map legend',
3178
    '#default_value' => $map_distribution['legend']['show'],
3179
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3180
  );
3181

    
3182
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3183
    '#type' => 'textfield',
3184
    '#title' => 'Legend opacity',
3185
    '#default_value' => $map_distribution['legend']['opacity'],
3186
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3187
                         to 0.0 will be not much visible.',
3188
  );
3189

    
3190
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3191
    '#type' => 'textfield',
3192
    '#title' => 'Font size',
3193
    '#default_value' => $map_distribution['legend']['font_size'],
3194
    '#description' => 'Font size in pixels.',
3195
  );
3196

    
3197
  $fontStyles = array(
3198
    0 => "plane",
3199
    1 => "italic",
3200
  );
3201
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3202
    '#type' => 'select',
3203
    '#title' => 'Available font styles',
3204
    '#default_value' => $map_distribution['legend']['font_style'],
3205
    '#options' => $fontStyles,
3206