Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / settings.php @ f264279e

History | View | Annotate | Download (158 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
  define('CDM_SEARCH_BLAST_SERVICE_URI', 'http://127.0.0.1:9001/api/sequence');
39
  define('CDM_SEARCH_BLAST_ENABLED', 0);
40
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
41

    
42
  /* annotationTypeKeys */
43
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
44
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
45
    $annotationTypeKeys = array_flip($annotationTypeKeys);
46

    
47
    // Technical annotation are off by default.
48
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
49
    $annotationTypeKeys = array_flip($annotationTypeKeys);
50
    // Additional value for the NULL case.
51
    $annotationTypeKeys[] = 'NULL_VALUE';
52
  }
53

    
54
  define('ANNOTATION_TYPES_VISIBLE', 'annotations_types_as_footnotes');
55
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
56

    
57
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
58
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
59
    'enabled' => 0,
60
    'key_format' => 'ALPHA'
61
  )));
62

    
63
  /* taxonRelationshipTypes */
64
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
65
    array(
66
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
67
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
68
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
69
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
70
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
71
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
72
    )
73
  ));
74

    
75

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

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

    
121

    
122
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
123

    
124
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
125
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
126
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
127
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
128
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
129

    
130
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
131
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
132
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
133
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
134

    
135
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
136
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
137

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

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

    
170

    
171
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
172
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
173
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
174
  array(
175
    'general' => null,
176
    'synonymy' => null,
177
    'images' => null,
178
    'specimens' => null,
179
    'keys' => null,
180
    'experts' => null,
181
  )
182
));
183

    
184
$taxon_tab_options = get_taxon_tabs_list();
185
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
186

    
187
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
188

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

    
199
}
200

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

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

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

    
378
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
379

    
380
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
381
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
382
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
383

    
384
/* Gallery variables. */
385
$gallery_settings = array(
386
    "cdm_dataportal_show_taxon_thumbnails" => 1,
387
    "cdm_dataportal_show_synonym_thumbnails" => 0,
388
    "cdm_dataportal_show_thumbnail_captions" => 1,
389
    "cdm_dataportal_media_maxextend" => 120,
390
    "cdm_dataportal_media_cols" => 3,
391
    "cdm_dataportal_media_maxRows" => 1,
392
);
393

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

    
407
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
408
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
409
  'media_representation_details_enabled' => 0
410
)));
411

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

    
420
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES', 'cdm_name_relationship_types');
421
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT', serialize(
422
    array(
423
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
424
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
425
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
426
    )
427
  )
428
);
429

    
430
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
431
define('CDM_NAME_RELATIONSHIP_LIST_TYPES_DEFAULT', serialize(
432
    array(
433
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
434
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
435
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR,
436
      UUID_NAMERELATIONSHIPTYPE_BASIONYM => UUID_NAMERELATIONSHIPTYPE_BASIONYM,
437
      UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT => UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT,
438
      UUID_NAMERELATIONSHIPTYPE_VALIDATED_BY_NAME => UUID_NAMERELATIONSHIPTYPE_VALIDATED_BY_NAME,
439
      UUID_NAMERELATIONSHIPTYPE_LATER_VALIDATED_BY_NAME => UUID_NAMERELATIONSHIPTYPE_LATER_VALIDATED_BY_NAME,
440
      UUID_NAMERELATIONSHIPTYPE_REPLACED_SYNONYM => UUID_NAMERELATIONSHIPTYPE_REPLACED_SYNONYM
441
    )
442
  )
443
);
444

    
445
/**
446
 * The drupal variable for the configuration of the information aggregation along
447
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
448
 *    - direct: the uuids of the taxon relationship types to take into account in invers
449
 *      direction.
450
 *    - invers: the uuids of the taxon relationship types to take into account in direct
451
 *      direction.
452
 *
453
 * @var String
454
 */
455
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
456
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
457
    array(
458
        'direct'=>array(),
459
        'invers'=>array()
460
     )
461
   ));
462
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
463
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
464
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
465

    
466
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
467
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
468
      array(
469
      'filter_rules' => array(
470
        'statusOrderPreference' => 0,
471
        'subAreaPreference' => 0,
472
      ),
473
      'hiddenAreaMarkerType' => array()
474
     )
475
));
476

    
477
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
478
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
479
  "level_0" => array(
480
    'label_suffix' => ':',
481
    'status_glue' => '',
482
    'item_glue' => ' ',
483
    'item_group_prefix' => '',
484
    'item_group_postfix' => ''
485
  ),
486
  "level_1" => array(
487
    'label_suffix' => '',
488
    'status_glue' => '', // '&#8210; '
489
    'item_glue' => '; ',
490
    'item_group_prefix' => ', ',
491
    'item_group_postfix' => ''
492
  ),
493
  "level_2" => array(
494
    'label_suffix' => '',
495
    'status_glue' => '', // '&#8210; '
496
    'item_glue' => ', ',
497
    'item_group_prefix' => ' (',
498
    'item_group_postfix' => ')'
499
  )
500
)));
501

    
502
/**
503
 * Constant for the drupal variable key distribution_map_visibility
504
 *
505
 * possible values:
506
 *  - never
507
 *  - automatic
508
 *  - always
509
 */
510
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
511
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
512

    
513
/**
514
 * Constant for the drupal variable key specimen_map_visibility
515
 *
516
 * possible values:
517
 *  - never
518
 *  - automatic
519
 *  - always
520
 */
521
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
522
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
523

    
524
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
525
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
526
    array(
527
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
528
        'includeOccurrences' => 0,
529
        'includeTaxonNameDescriptions' => 0
530
     )
531
  ));
532

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

    
588
/**
589
 * Merges the named array variable with the array of defaults.
590
 *
591
 * IMPORTANT: The array keys must be strings. When the keys are integers
592
 * the merging will not take place for these entities. Number keyed entities
593
 * are just appended to the result array.
594
 *
595
 * @param string $variable_name
596
 *     The variable name
597
 * @param string | array $default
598
 *     The array containing the default values either as array or serialized as string.
599
 *     Unserialization is cared for if necessary
600
 * @return array
601
 *     The merged array as returned by drupal_array_merge_deep()
602
 *
603
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
604
 * TODO force $default being an array
605
 */
606
function get_array_variable_merged($variable_name, $default){
607

    
608
    // unserialize if nessecary
609
    if(!is_array($default)){
610
      $default = unserialize($default);
611
    }
612
    $variable = variable_get($variable_name, array());
613
    $result = drupal_array_merge_deep($default, $variable);
614
    return $result;
615
}
616

    
617
/**
618
 * @todo document this function.
619
 */
620
function getGallerySettings($gallery_config_form_name) {
621
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
622
}
623

    
624
/**
625
 * Returns the string representation of the default tab.
626
 *
627
 * @param bool $returnTabIndex
628
 *   Defaults to FALSE, if set true this function will return the index number
629
 *   of the default tab. (used to supply default values to form elements).
630
 */
631
function get_default_taxon_tab($returnTabIndex = FALSE) {
632

    
633
  global $user;
634
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
635
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
636
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
637
  // Get the user value if the used has chosen to overwrite the system settings.
638
  $user_tab_on = variable_get($user_tab_active, FALSE);
639
  if ($user_tab_on) {
640
    $user_value = variable_get($user_tab, 0);
641
    $index_value = $user_value;
642
    // Get the system value.
643
  }
644
  else {
645
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
646
    $index_value = $system_value;
647
  }
648

    
649
  // Return the index value or the string representation.
650
  if ($returnTabIndex) {
651
    return $index_value;
652
  }
653
  else {
654
    return ($values[$index_value]);
655
  }
656
}
657

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

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

    
729
  // ---- DEFAULTS settings
730

    
731
  // only needed as final option, when the settings are not having a default
732
  $default = array(
733
    'DEFAULT' => array(
734
      'as_list' => 'div',
735
      'link_to_reference' => 0,
736
      'link_to_name_used_in_source' => 1,
737
      'sources_as_content' => 0,
738
      'sources_as_content_to_bibliography' => 0,
739
      'sort_elements' => NO_SORT,
740
      'glue' => '',
741
      'element_tag' => NULL
742
    ),
743
    // settings for pseudo feature bibliography
744
    // only hard coded here
745
    'BIBLIOGRAPHY' => array(
746
      'as_list' => 'div',
747
      'link_to_reference' => 0,
748
      'link_to_name_used_in_source' => 1,
749
      'sources_as_content' => 0,
750
      'sources_as_content_to_bibliography' => 0,
751
      'sort_elements' => NO_SORT,
752
      'glue' => '',
753
      'element_tag' => NULL
754
    )
755
  );
756

    
757
  // will be used as preset in the settings
758
  $other_themes_default = array(
759
    'DEFAULT' => array(
760
      'as_list' => 'div',
761
      'link_to_reference' => 0,
762
      'link_to_name_used_in_source' => 1,
763
      'sources_as_content' => 0,
764
      'sources_as_content_to_bibliography' => 0,
765
      'sort_elements' => NO_SORT,
766
      'glue' => '',
767
      'element_tag' => NULL
768
    ),
769
    UUID_CITATION => array(
770
      'as_list' => 'div',
771
      'link_to_reference' => 0,
772
      'link_to_name_used_in_source' => 0,
773
      'sources_as_content' => 1,
774
      'sources_as_content_to_bibliography' => 0,
775
      'sort_elements' => SORT_ASC,
776
      'glue' => '',
777
      'element_tag' => 'div'
778
    ),
779
    UUID_DISTRIBUTION => array(
780
      'as_list' => 'div', // currently ignored
781
      'link_to_reference' => 0,
782
      'link_to_name_used_in_source' => 0,
783
      'sources_as_content' => 0,
784
      'sources_as_content_to_bibliography' => 0,
785
      'sort_elements' => NO_SORT, // will cause ...
786
      'glue' => '',
787
      'element_tag' => 'div',
788
      'special' => array()
789
    ),
790
    UUID_COMMON_NAME => array(
791
      'as_list' => 'div',
792
      'link_to_reference' => 0,
793
      'link_to_name_used_in_source' => 1,
794
      'sources_as_content' => 0,
795
      'sources_as_content_to_bibliography' => 0,
796
      'sort_elements' => NO_SORT,
797
      'glue' => '',
798
      'element_tag' => 'span'
799
    ),
800
  );
801

    
802
  // ---- Special DEFAULTS for existing portals
803
  // TODO:
804
  // this can be removed once the feature block
805
  // settings have been deployed for the first time to these portals
806

    
807
  $cichorieae_default = array(
808
    'DEFAULT' => array(
809
      'as_list' => 'div',
810
      'link_to_reference' => 1,
811
      'link_to_name_used_in_source' => 1,
812
      'sources_as_content' => 1,
813
      'sources_as_content_to_bibliography' => 0,
814
      'sort_elements' => NO_SORT,
815
      'glue' => '',
816
      'element_tag' => 'div'
817
    ),
818
    UUID_CITATION => array(
819
      'as_list' => 'div',
820
      'link_to_reference' => 0,
821
      'link_to_name_used_in_source' => 0,
822
      'sources_as_content' => 1,
823
      'sources_as_content_to_bibliography' => 0,
824
      'sort_elements' => SORT_ASC,
825
      'glue' => '',
826
      'element_tag' => 'div'
827
    ),
828
    UUID_CHROMOSOMES_NUMBERS => array(
829
      'as_list' => 'ul',
830
      'link_to_reference' => 1,
831
      'link_to_name_used_in_source' => 1,
832
      'sources_as_content' => 1,
833
      'sources_as_content_to_bibliography' => 0,
834
      'sort_elements' => NO_SORT,
835
      'glue' => '',
836
      'element_tag' => 'div'
837
    ),
838
    UUID_CHROMOSOMES => array(
839
      'as_list' => 'ul',
840
      'link_to_reference' => 0,
841
      'link_to_name_used_in_source' => 1,
842
      'sources_as_content' => 1,
843
      'sources_as_content_to_bibliography' => 0,
844
      'sort_elements' => NO_SORT,
845
      'glue' => '',
846
      'element_tag' => 'div'
847
    ),
848
    UUID_COMMON_NAME => array(
849
      'as_list' => 'div',
850
      'link_to_reference' => 0,
851
      'link_to_name_used_in_source' => 1,
852
      'sources_as_content' => 0,
853
      'sources_as_content_to_bibliography' => 0,
854
      'sort_elements' => NO_SORT,
855
      'glue' => '',
856
      'element_tag' => 'span'
857
    ),
858
  );
859

    
860
  $palmweb_default = array(
861
    'DEFAULT' => array(
862
      'as_list' => 'ul',
863
      'link_to_reference' => 1,
864
      'link_to_name_used_in_source' => 1,
865
      'sources_as_content' => 1,
866
      'sources_as_content_to_bibliography' => 1,
867
      'sort_elements' => NO_SORT,
868
      'glue' => '',
869
      'element_tag' => NULL
870
    ),
871
    UUID_CITATION => array(
872
      'as_list' => 'ul',
873
      'link_to_reference' => 1,
874
      'link_to_name_used_in_source' => 1,
875
      'sources_as_content' => 0,
876
      'sources_as_content_to_bibliography' => 1,
877
      'sort_elements' => SORT_ASC,
878
      'glue' => '',
879
      'element_tag' => 'div'
880
    ),
881
    UUID_DISTRIBUTION => array(
882
      'as_list' => 'div', // currently ignored
883
      'link_to_reference' => 1,
884
      'link_to_name_used_in_source' => 1,
885
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
886
      'sources_as_content_to_bibliography' => 1,
887
      'sort_elements' => NO_SORT, // will cause ...
888
      'glue' => ', ',
889
      'element_tag' => 'span',
890
      'special' => array()
891
    ),
892
  );
893

    
894
  $cyprus_default = $cichorieae_default;
895
  $cyprus_default[UUID_DISTRIBUTION] = array(
896
    'as_list' => 'div', // currently ignored
897
    'link_to_reference' => 0,
898
    'link_to_name_used_in_source' => 0,
899
    'sources_as_content' => 0,
900
    'sources_as_content_to_bibliography' => 0,
901
    'sort_elements' => NO_SORT, // will cause ...
902
    'glue' => ' ',
903
    'element_tag' => 'div',
904
    'special' => array()
905
  );
906

    
907
  $default_theme = variable_get('theme_default', NULL);
908

    
909
  switch ($default_theme) {
910
    case 'garland_cichorieae':
911
      $settings_for_theme = $cichorieae_default;
912
      break;
913
    case 'cyprus':
914
      // cyprus: no longer used in production,
915
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
916
      $settings_for_theme = $cyprus_default;
917
      break;
918
    case 'flore_afrique_centrale':
919
    case 'flora_malesiana':
920
    case 'flore_gabon':
921
      $settings_for_theme = $cichorieae_default;
922
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
923
      break;
924
    case 'palmweb_2':
925
      $settings_for_theme = $palmweb_default;
926
      break;
927
    default:
928
      $settings_for_theme = $other_themes_default;
929
  }
930
  // add pseudo feature settings
931
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
932

    
933
  // ---- END of DEFAULTS
934

    
935
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
936

    
937
  $feature_block_setting = null;
938

    
939
  if (isset($saved_settings[$feature_uuid])) {
940
    $feature_block_setting = $saved_settings[$feature_uuid];
941
  }
942
  else if (isset($settings_for_theme[$feature_uuid])) {
943
    $feature_block_setting = $settings_for_theme[$feature_uuid];
944
  }
945
  else if (isset($settings_for_theme['DEFAULT'])) {
946
    $feature_block_setting = $settings_for_theme['DEFAULT'];
947
  }
948

    
949
  // now merge the default and specific settings
950
  $settings_to_merge = array($default['DEFAULT']);
951
  if(is_array($saved_settings)){
952
    $settings_to_merge[] = $saved_settings['DEFAULT'];
953
  }
954
  if(isset($feature_block_setting)){
955
    $settings_to_merge[] = $feature_block_setting;
956
  }
957
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
958

    
959
  return $feature_block_setting;
960
}
961

    
962
/**
963
 * returns the current setting for the original source bibliography
964
 *
965
 * Caches internally
966
 *
967
 * @return array
968
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
969
 *   - 'enabled': 1|0
970
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
971
 */
972
function get_bibliography_settings($clear_cache = false){
973
  static $bibliography_settings = null;
974
  if(!$bibliography_settings || $clear_cache){
975
    $bibliography_settings = get_array_variable_merged(
976
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
977
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
978
    );
979
  }
980
  return $bibliography_settings;
981
}
982

    
983
/**
984
 * @todo Please document this function.
985
 * @see http://drupal.org/node/1354
986
 */
987
function cdm_dataportal_menu_admin(&$items) {
988
  // Display section on admin/config page.
989
  $items['admin/config/cdm_dataportal'] = array(
990
    'title' => 'CDM Dataportal',
991
    'description' => 'Settings for the CDM DataPortal.',
992
    'position' => 'right',
993
    'weight' => 10,
994
    'page callback' => 'system_admin_menu_block_page',
995
    'access arguments' => array('administer cdm_dataportal'),
996
    'file' => 'system.admin.inc',
997
    'file path' => drupal_get_path('module', 'system'),
998
  );
999
  $items['admin/config/cdm_dataportal/settings'] = array(
1000
    'title' => 'Settings',
1001
    'description' => 'Settings for the CDM DataPortal.',
1002
    'weight' => 0,
1003
    'page callback' => 'drupal_get_form',
1004
    'page arguments' => array('cdm_settings_general'),
1005
    'access arguments' => array('administer cdm_dataportal'),
1006
    'type' => MENU_NORMAL_ITEM,
1007
  );
1008
  $items['admin/config/cdm_dataportal/settings/general'] = array(
1009
    'title' => 'General',
1010
    'description' => 'General',
1011
    'weight' => 0,
1012
    'page callback' => 'drupal_get_form',
1013
    'page arguments' => array('cdm_settings_general'),
1014
    'access arguments' => array('administer cdm_dataportal'),
1015
    'type' => MENU_DEFAULT_LOCAL_TASK,
1016
  );
1017

    
1018
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
1019
    'title' => 'Cache',
1020
    'description' => 'Cache',
1021
    'access arguments' => array('administer cdm_dataportal'),
1022
    'page callback' => 'drupal_get_form',
1023
    'page arguments' => array('cdm_settings_cache'),
1024
    'weight' => 10,
1025
    'type' => MENU_LOCAL_TASK,
1026
  );
1027

    
1028
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1029
    'title' => 'Geo & Map',
1030
    'description' => 'Geo & Map',
1031
    'access arguments' => array('administer cdm_dataportal'),
1032
    'page callback' => 'drupal_get_form',
1033
    'page arguments' => array('cdm_settings_geo'),
1034
    'weight' => 1,
1035
    'type' => MENU_LOCAL_TASK,
1036
  );
1037

    
1038
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1039
    'title' => 'Layout',
1040
    'description' => 'Configure and adjust the layout of your DataPortal ',
1041
    'access arguments' => array('administer cdm_dataportal'),
1042
    'page callback' => 'drupal_get_form',
1043
    'page arguments' => array('cdm_settings_layout'),
1044
    'weight' => 2,
1045
    'type' => MENU_LOCAL_TASK,
1046
  );
1047

    
1048
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1049
    'title' => 'Taxon',
1050
    'description' => 'Configure and adjust the layout of your DataPortal ',
1051
    'access arguments' => array('administer cdm_dataportal'),
1052
    'page callback' => 'drupal_get_form',
1053
    'page arguments' => array('cdm_settings_layout_taxon'),
1054
    'weight' => 1,
1055
    'type' => MENU_LOCAL_TASK,
1056
  );
1057
  /*
1058
  $items[] = array(
1059
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1060
  'title' => t('Synonymy'),
1061
  'description' => t('Configure and adjust the layout of your DataPortal '),
1062
  'access' => user_access('administer cdm_dataportal'),
1063
  'callback' => 'drupal_get_form',
1064
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1065
  'weight' => 1,
1066
  'type' => MENU_LOCAL_TASK,
1067
  );
1068

1069
  $items[] = array(
1070
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1071
  'title' => t('Specimens'),
1072
  'description' => t('Configure and adjust the layout of your DataPortal '),
1073
  'access' => user_access('administer cdm_dataportal'),
1074
  'callback' => 'drupal_get_form',
1075
  'callback arguments' => array('cdm_settings_layout_specimens'),
1076
  'weight' => 1,
1077
  'type' => MENU_LOCAL_TASK,
1078
  );
1079
  */
1080
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1081
    'title' => 'Search',
1082
    'description' => 'Configure and adjust the layout of your DataPortal ',
1083
    'access arguments' => array('administer cdm_dataportal'),
1084
    'page callback' => 'drupal_get_form',
1085
    'page arguments' => array('cdm_settings_layout_search'),
1086
    'weight' => 2,
1087
    'type' => MENU_LOCAL_TASK,
1088
  );
1089

    
1090
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1091
    'title' => 'Media',
1092
    'description' => 'Configure and adjust the layout of your DataPortal ',
1093
    'access arguments' => array('administer cdm_dataportal'),
1094
    'page callback' => 'drupal_get_form',
1095
    'page arguments' => array('cdm_settings_layout_media'),
1096
    'weight' => 3,
1097
    'type' => MENU_LOCAL_TASK,
1098
  );
1099

    
1100
}
1101

    
1102
/**
1103
 * @todo document this function.
1104
 */
1105
function cdm_help_general_cache() {
1106
  $form = array();
1107
  $form['cache_help'] = array(
1108
    '#type' => 'fieldset',
1109
    '#title' => t('Help'),
1110
    '#collapsible' => TRUE,
1111
    '#collapsed' => TRUE,
1112
  );
1113
  $form['cache_help']['test'] = array('#value' => t('probando'));
1114
  return drupal_render($form);
1115
  $res = array();
1116
  $res['default'] = drupal_render($help);
1117
  return $res;
1118
}
1119

    
1120
/**
1121
 * Configures the settings form for the CDM-API module.
1122
 *
1123
 * @return array
1124
 *   Drupal settings form.
1125
 */
1126
function cdm_settings_general() {
1127

    
1128
  $form['cdm_webservice'] = array(
1129
    '#type' => 'fieldset',
1130
    '#title' => t('CDM Server'),
1131
    '#collapsible' => FALSE,
1132
    '#collapsed' => FALSE,
1133
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1134
        CDM data base to the web via RESTful web services and thus is the source of the data
1135
        to be displayed by a CDM DataPotal.'),
1136
  );
1137

    
1138
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1139
    '#type' => 'textfield',
1140
    '#title' => t('CDM web service URL') . ':',
1141
    '#description' => t('This is the URL to the CDM-Server exposing your data
1142
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1143
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1144
  );
1145

    
1146
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1147
    '#type' => 'markup',
1148
    '#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')
1149
      . ' visible only for administrators',
1150
  );
1151

    
1152
  $form['cdm_webservice']['freetext_index'] = array(
1153
    '#type' => 'fieldset',
1154
    '#title' => t('Freetext index'),
1155
    '#collapsible' => FALSE,
1156
    '#collapsed' => FALSE,
1157
  );
1158

    
1159
  // Check the cdmserver port number and display a waring if it is not port 80
1160
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1161
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1162
    $form['cdm_webservice']['freetext_index']['message'] = array(
1163
      '#markup' => "<div class=\"description\">"
1164
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1165
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1166
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1167
          array('!port' => $portNumberMatch[1][0])
1168
        )
1169
      . "</div>",
1170
    );
1171
  };
1172

    
1173
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1174
  $trigger_link_options = array(
1175
    'attributes' => array(
1176
      'class' => 'index-trigger'
1177
    ),
1178
  );
1179
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1180
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1181
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1182
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1183
      ))
1184
    . '<div id="index-progress"></div></div>',
1185
  );
1186

    
1187
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1188
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1189
    '#type' => 'textfield',
1190
    '#title' => t('Login'),
1191
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1192
  );
1193
  drupal_add_js('
1194
        jQuery(document).ready(function() {
1195
             jQuery("#edit-cdm-login").change(function (e) {
1196
                var login = jQuery(e.target).val();
1197
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1198
                   var url = jQuery(this).attr("href");
1199
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1200
                   jQuery(this).attr("href", url);
1201
                });
1202
            });
1203
        });
1204
      ',
1205
    array(
1206
      'type' => 'inline',
1207
      'scope' => 'footer'
1208
    )
1209
  );
1210
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1211

    
1212
  $form['cdm_webservice']['proxy'] = array(
1213
    '#type' => 'fieldset',
1214
    '#title' => t('Proxy'),
1215
    '#collapsible' => TRUE,
1216
    '#collapsed' => TRUE,
1217
  );
1218

    
1219
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1220
    '#type' => 'textfield',
1221
    '#title' => t('Proxy URL') . ':',
1222
    '#description' => t('If this proxy url is set the cdm api tries
1223
    to connect the web service over the given proxy server.
1224
    Otherwise proxy usage is deactivated.'),
1225
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1226
  );
1227

    
1228
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1229
    '#type' => 'textfield',
1230
    '#title' => t('Proxy port') . ':',
1231
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1232
  );
1233

    
1234
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1235
    '#type' => 'textfield',
1236
    '#title' => t('Login') . ':',
1237
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1238
  );
1239

    
1240
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1241
    '#type' => 'textfield',
1242
    '#title' => t('Password') . ':',
1243
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1244
  );
1245

    
1246
  $form['sub_tree_filter'] = array(
1247
    '#type' => 'fieldset',
1248
    '#title' => t('Subtree filter'),
1249
    '#collapsible' => FALSE,
1250
    '#collapsed' => TRUE,
1251
    '#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.'),
1252
  );
1253

    
1254
  $sub_tree_filter_uuid_value = variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE);
1255
  $taxon_node_info = '';
1256
  if($sub_tree_filter_uuid_value){
1257
    $taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE, array($sub_tree_filter_uuid_value));
1258
    if($taxon_node_dto){
1259
      $taxon_node_info = " Current taxon node: <strong>" . cdm_tagged_text_to_markup($taxon_node_dto->taggedTitle) . " [" . $taxon_node_dto->treeIndex . "]</strong>";
1260
    }
1261
  }
1262
  $form['sub_tree_filter'][CDM_SUB_TREE_FILTER_UUID] = array(
1263
    '#type' => 'textfield',
1264
    '#title' => t('Taxon Node UUID') . ':',
1265
    '#default_value' => variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE),
1266
    '#description' => "The uuid of the TaxonNode entity to be used as filter." . $taxon_node_info
1267
  );
1268

    
1269
  // TODO: settings are still incomplete, compare with
1270
  // trunk/dataportal/inc/config_default.php.inc.
1271
  $form['taxon_tree'] = array(
1272
    '#type' => 'fieldset',
1273
    '#title' => t('Taxon Tree'),
1274
    '#collapsible' => FALSE,
1275
    '#collapsed' => TRUE,
1276
    '#description' => t('<p>When you explore your collection, you can navigate
1277
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1278
      able to navigate through your collection the
1279
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1280
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1281
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1282
      </a></p>'),
1283
  );
1284

    
1285
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1286
    '#type' => 'select',
1287
    '#title' => t('Default classification') . ':',
1288
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1289
    '#options' => cdm_get_taxontrees_as_options(),
1290
    '#description' => t('The default taxa classification to be used in the whole portal. 
1291
      This affects most obviously the classification browser and the search in case is is restricted 
1292
      to a specific classification. See also <i>Included Classifications</i> below.'),
1293
  );
1294

    
1295
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1296
    '#type' => 'select',
1297
    '#title' => t('Rank of highest displayed taxon') . ':',
1298
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1299
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1300
    '#options' => cdm_vocabulary_as_option(UUID_RANK, null, true),
1301
    '#description' => t('This is the rank of the highest displayed taxon in the
1302
      <em>taxon tree</em>. You can select here which rank should be at the top
1303
      level of the tree structure.'),
1304
  );
1305

    
1306
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1307
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1308
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1309
      '#type' => 'checkboxes',
1310
      '#title' => t('Included Classifications') . ':',
1311
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1312
      '#options' => cdm_get_taxontrees_as_options(),
1313
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1314
  );
1315

    
1316
  $form['distribution'] = array(
1317
      '#type' => 'fieldset',
1318
      '#title' => t('Distributions'),
1319
      '#collapsible' => FALSE,
1320
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1321
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1322
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1323
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1324
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1325
          '<p>
1326
          </p>',
1327
  );
1328

    
1329
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1330
      '#type' => 'fieldset',
1331
      '#title' => 'Distribution filter',
1332
      '#collapsible' => FALSE,
1333
      '#collapsed' => FALSE,
1334
      '#tree' => TRUE,
1335
      '#description' => 'The Distribution filter offers the following options
1336
      <ul>
1337
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1338
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1339
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1340
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1341
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1342
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1343
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1344
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1345
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1346
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1347
      </ul>'
1348
  );
1349

    
1350
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1351
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1352
      '#type' => 'checkboxes',
1353
      '#title' => 'Filter rules',
1354
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1355
      '#options' => array(
1356
          'statusOrderPreference' => 'Status order preference rule',
1357
          'subAreaPreference' => 'Sub area preference rule'
1358
      ),
1359
  );
1360

    
1361
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1362
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1363
      '#type' => 'checkboxes',
1364
      '#title' => 'Hide marked area filter',
1365
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1366
      '#options' => $marker_type_options,
1367
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1368
  );
1369

    
1370
  $form['aggregation'] = array(
1371
      '#type' => 'fieldset',
1372
      '#title' => t('Aggregation of data'),
1373
      '#collapsible' => FALSE,
1374
      '#description' => 'This section covers the different aspects of aggregating information.
1375
          <p>
1376
          </p>',
1377
  );
1378

    
1379
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1380
      '#type' => 'checkboxes',
1381
      '#title' => 'Taxon media filter',
1382
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1383
      '#options' => array(
1384
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1385
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1386
          'includeOccurrences' => 'Media related to specimens and occurrences',
1387
      ),
1388
      '#description' => 'This filter configures which images should be taken into account.',
1389
  );
1390

    
1391
  $form['aggregation']['notice'] = array(
1392
      '#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
1393
          want to make use of the caching capabilities of the dataportal.',
1394
  );
1395

    
1396
  $form['aggregation']['media_aggregation'] = array(
1397
      '#type' => 'fieldset',
1398
      '#title' => t('Media aggregation'),
1399
      '#collapsible' => FALSE,
1400
      '#collapsed' => TRUE,
1401
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1402

    
1403
  );
1404
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1405
      '#type' => 'select',
1406
      '#title' => t('Aggregation of taxon pictures') . ':',
1407
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1408
      '#options' => array(
1409
          0 => "Show only pictures of the current taxon",
1410
          1 => "Include pictures of taxonomic children",
1411
      ),
1412
      '#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."),
1413
  );
1414

    
1415
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1416
      '#type' => 'fieldset',
1417
      '#attributes' => array('class' => array('clearfix')),
1418
      '#title' => t('Aggregation via taxon relationsships'),
1419
      '#collapsible' => TRUE,
1420
      '#collapsed' => TRUE,
1421
      '#tree' => TRUE,
1422
      '#description' => t('Information on taxa will be aggregated along the below chosen
1423
          taxon relation ships. This will affect images and occurrences (specimens).
1424
          Taxon relation ships are directed and point form one taxon to another. The taxon
1425
          relationships to be taken into accunt can therefore configured for the direct direction
1426
          and for the inverse.'),
1427
  );
1428

    
1429
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1430
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1431

    
1432
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1433
      '#type' => 'checkboxes',
1434
      '#title' => t('Direct'),
1435
      '#options' => $taxonRelationshipTypeOptions,
1436
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1437
  );
1438
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1439
      '#type' => 'checkboxes',
1440
      '#title' => t('Invers'),
1441
      '#options' => $taxonRelationshipTypeOptions,
1442
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1443
  );
1444

    
1445
  $form['drupal_integration'] = array(
1446
    '#type' => 'fieldset',
1447
    '#attributes' => array('class'=> array('clearfix')),
1448
    '#title' => t('Drupal integration'),
1449
    '#collapsible' => FALSE,
1450
    '#collapsed' => FALSE,
1451
    '#tree' => FALSE
1452
  );
1453

    
1454
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1455
    '#type' => 'checkbox',
1456
    '#title' => 'Create drupal nodes',
1457
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1458
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1459
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1460
    cdm pages it is required that drupal nodes are created and stored in the database.'
1461
  );
1462

    
1463

    
1464

    
1465
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1466
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1467
    <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>',
1468
  );
1469
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1470
    '#type' => 'submit',
1471
    '#value' => t('Drop all cdm nodes'),
1472
    '#submit' => array('drop_all_cdm_nodes_submit')
1473
  );
1474

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

    
1479
    // ----------------------
1480
  $form['cdm_js_devel_mode'] = array(
1481
      '#type' => 'checkbox',
1482
      '#title' => 'Java-script developer mode',
1483
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1484
      '#description' => 'In production envirionments the java script libraries
1485
      the cdm_dataportal is making use of are compressed and optimized. This
1486
      is good for performance but a caveat if you need to debug java-script. When the
1487
      java-script developer mode is enabled the uncompressed and commented developer
1488
      versions of java-script libraries will be used where possible.
1489
      <br/><strong>Do not use this option in production!</strong>'
1490
  );
1491
  // ----------------------
1492
  $form['cdm_debug_mode'] = array(
1493
      '#type' => 'checkbox',
1494
      '#title' => 'CDM page debug mode',
1495
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1496
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1497
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1498
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1499
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1500
      The log is written by the drupal devel module function <code>dd()</code>.
1501
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1502
  );
1503

    
1504
  // Comment @WA: D7 form api does not support reset buttons,
1505
  // so to mimic the D5 reset button we add one like this.
1506
  $form['actions']['reset'] = array(
1507
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1508
    '#weight' => 1000,
1509
  );
1510

    
1511
  $form['#submit'][] = 'cdm_settings_general_submit';
1512

    
1513
  return system_settings_form($form);
1514
}
1515

    
1516
/**
1517
 * Submit callback; drops all cdm nodes.
1518
 *
1519
 * @ingroup forms
1520
 */
1521
function drop_all_cdm_nodes_submit($form, &$form_state) {
1522
  cdm_delete_all_cdm_nodes();
1523
  drupal_set_message(t('All cdm nodes dropped.'));
1524
}
1525

    
1526

    
1527
/**
1528
 * LAYOUT settings
1529
 *
1530
 * @return array
1531
 *   The form structure.
1532
 */
1533
function cdm_settings_layout() {
1534

    
1535
  $form = array();
1536

    
1537
  $form['about'] = array(
1538
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1539
      layout. If you want to configure the specific sites layout visit the
1540
      respective configuration site for taxon, search or media.') . '</p>',
1541
  );
1542

    
1543
  // ---- footnotes --- //
1544
  $form['footnotes'] = array(
1545
    '#type' => 'fieldset',
1546
    '#title' => t('Footnotes'),
1547
    '#collapsible' => FALSE,
1548
    '#collapsed' => FALSE,
1549
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1550
      media or distribution areas may have annotations or footnotes. When the
1551
      footnotes are enabled they will be visible (if they exist).'),
1552
  );
1553

    
1554
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1555
    '#type' => 'checkbox',
1556
    '#title' => t('Do not show footnotes'),
1557
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1558
    '#description' => t('Check this if you do not want to show any footnotes'),
1559
  );
1560

    
1561
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1562
    '#type' => 'checkbox',
1563
    '#title' => t('Do not show annotation footnotes'),
1564
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1565
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1566
  );
1567

    
1568
  $form['annotations'] = array(
1569
    '#type' => 'fieldset',
1570
    '#title' => t('Annotations'),
1571
    '#collapsible' => FALSE,
1572
    '#collapsed' => FALSE,
1573
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1574
  );
1575

    
1576
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1577
  // Additional option for the NULL case.
1578
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1579
  $annotationsTypesAsFootnotes = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1580
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1581
    '#type' => 'checkboxes',
1582
    '#title' => t('Visbility of annotation types'),
1583
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1584
    '#options' => $annotationTypeOptions,
1585
    '#default_value' => $annotationsTypesAsFootnotes
1586
  );
1587

    
1588

    
1589
  // ---- original source --- //
1590
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1591
      '#type' => 'fieldset',
1592
      '#tree' => TRUE,
1593
      '#title' => t('Source Citations'),
1594
      '#collapsible' => FALSE,
1595
      '#collapsed' => FALSE,
1596
  );
1597

    
1598
  $bibliography_settings = get_bibliography_settings(true);
1599

    
1600
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1601
      '#type' => 'checkbox',
1602
      '#title' => t('Original Source in bibliography'),
1603
      '#default_value' => $bibliography_settings['enabled'],
1604
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1605
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1606
       into the bibliography also depends on the settings in the ' .
1607
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1608
        '. 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.'),
1609
  );
1610

    
1611
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1612
    '#type' => 'select',
1613
    '#title' => t('The format of the key numerals'),
1614
    '#default_value' => $bibliography_settings['key_format'],
1615
    '#options' => array('latin' => 'Latin',
1616
      'ROMAN' => 'Roman (upper case)',
1617
      'roman' => 'Roman (lower case)',
1618
      'ALPHA'=> 'Alphabet (upper case)',
1619
      'alpha' => 'Alphabet (lower case)')
1620
  );
1621

    
1622
  // --- Advanced Search --- //
1623
  $form['asearch'] = array(
1624
      '#type' => 'fieldset',
1625
      '#title' => t('Advanced search'),
1626
      '#collapsible' => FALSE,
1627
      '#collapsed' => FALSE,
1628
  );
1629
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1630
      '#type' => 'checkbox',
1631
      '#title' => t('Show advanced search link'),
1632
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1633
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1634
  );
1635

    
1636
  // --- Registrations --- //
1637
  $form['registrations'] = array(
1638
    '#type' => 'fieldset',
1639
    '#title' => t('Registrations'),
1640
    '#collapsible' => FALSE,
1641
    '#collapsed' => FALSE,
1642
  );
1643
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1644
    '#type' => 'checkbox',
1645
    '#title' => t('Use the persistent http identifier as link'),
1646
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1647
    '#description' => t('Switch the portal from using the drupal path <code>registration/{url encoded persistent http identifier}</code> to using the persistent http identifier directly as link.'),
1648
  );
1649

    
1650
  // ---- Taxon Name Rendering --- //
1651
  $form['taxon_name'] = array(
1652
      '#type' => 'fieldset',
1653
      '#title' => t('Taxon name display'),
1654
      '#collapsible' => TRUE,
1655
      '#collapsed' => TRUE,
1656
      '#description' => t('The display of taxon names is configured by two parts.
1657
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1658
          The name parts are defined in the <stong>part definitions</strong>'),
1659
  );
1660

    
1661
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1662
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1663
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1664
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1665

    
1666
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1667
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1668
    $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.)';
1669
  } else if($is_custom_part_definition){
1670
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1671
  } else  {
1672
    $which_version_message = '(These are the default part definition.)';
1673
  }
1674

    
1675
  $diff_viewer_markup = '';
1676
  if($is_custom_part_definition){
1677
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1678
  }
1679

    
1680
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1681
    . $which_version_message
1682
    . '</div>'
1683
    . $diff_viewer_markup;
1684

    
1685
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1686
      '#type' => 'textarea',
1687
      '#title' => t('Part definitions'),
1688
      '#element_validate' => array('form_element_validate_json'),
1689
      '#default_value' =>  $current_part_definition_json,
1690
      '#description' => '
1691
          <p>' . $which_version_message . '</p>
1692
          <p>
1693
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1694
          </p>
1695
          <p>
1696
           A full taxon name plus additional information can consist of the following elements:
1697
          <ul>
1698
             <li>name: the taxon name inclugin rank nbut without author</li>
1699
             <li>authors:  The authors of a reference, also used in taxon names</li>
1700
             <li>reference: the nomenclatural reference,</li>
1701
             <li>microreference:  Volume, page number etc.</li>
1702
             <li>status:  The nomenclatural status of a name</li>
1703
             <li>description: name descriptions like protologues etc ...</li>
1704
          </ul>
1705
          </p>
1706
          <p>
1707
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1708
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1709
           The following parts can be formed and are recognized by the system:
1710
          <ul>
1711
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1712
            <li>authorshipPart: the author (for example: "L.")</li>
1713
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1714
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1715
               be combined when a link to the taxon is rendered.</li>
1716
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1717
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1718
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1719
            <li>statusPart: the nomenclatorical status</li>
1720
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1721
          </ul>
1722
          </p>
1723
          <p>
1724
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1725
           specific parts part definitions:
1726
          <ul>
1727
            <li>BotanicalName</li>
1728
            <li>ZoologicalName</li>
1729
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1730
          </ul>
1731
           An example:
1732
          <pre>
1733
           {
1734
            "ZoologicalName": {
1735
              "namePart": {
1736
                "name": true
1737
              },
1738
              "referencePart": {
1739
                "authors": true
1740
              },
1741
              "microreferencePart": {
1742
                "microreference": true
1743
              },
1744
              "statusPart": {
1745
                "status": true
1746
              },
1747
              "descriptionPart": {
1748
                "description": true
1749
              }
1750
            },
1751
            "BotanicalName": {
1752
              "namePart": {
1753
                "name": true,
1754
                "authors": true
1755
              },
1756
              "referencePart": {
1757
                "reference": true,
1758
                "microreference": true
1759
              },
1760
              "secReferencePart": {
1761
                "secReference": true
1762
              },
1763
              "statusPart": {
1764
                "status": true
1765
              },
1766
              "descriptionPart": {
1767
                "description": true
1768
              }
1769
            }
1770
          }
1771
           </pre>',
1772
  );
1773

    
1774
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1775
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1776
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1777
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1778
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1779

    
1780
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1781
    $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.)';
1782
  } else if($is_custom_render_template){
1783
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1784
  } else {
1785
    $which_version_message = '(These are the default render templates.)';
1786
  }
1787

    
1788
  $diff_viewer_markup = '';
1789
  if($is_custom_render_template){
1790
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1791
  }
1792

    
1793
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1794
    . $which_version_message
1795
    . '</div>'
1796
    . $diff_viewer_markup;
1797

    
1798
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1799
      '#type' => 'textarea',
1800
      '#title' => t('Name render templates'),
1801
      '#element_validate' => array('form_element_validate_json'),
1802
      '#default_value' =>  $current_render_templates_json,
1803
      '#description' => '
1804
          <p>' . $which_version_message . '</p>
1805
          <p>
1806
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1807
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1808
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1809
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1810
          The following render Path keys are currently recognized:
1811
          <ul>
1812
            <li>list_of_taxa</li>
1813
            <li>acceptedFor</li>
1814
            <li>homonym</li>
1815
            <li>taxon_page_synonymy</li>
1816
            <li>typedesignations</li>
1817
            <li>taxon_page_title</li>
1818
            <li>polytomousKey</li>
1819
            <li>na: name + authorship</li>
1820
            <li>nar:name + authorship + reference</li>
1821
            <li>#DEFAULT</li>
1822
          </ul>
1823
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1824
          array element should be a comma separated list of render paths, without any whitespace!.
1825
          </p>
1826
          <p>
1827
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1828
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1829
          <p>
1830
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1831
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1832
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1833
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1834
          links if the paramters $nameLink or $refenceLink are given to the name render function
1835
          (this is hard coded and cannot be configured here).',
1836
  );
1837

    
1838
  // @WA: D7 form api does not support reset buttons,
1839
  // so to mimic the D5 reset button we add one like this.
1840
  $form['actions']['reset'] = array(
1841
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1842
    '#weight' => 1000,
1843
  );
1844

    
1845
  $form['#submit'] = array('submit_json_as_php_array');
1846
  // #json_elements especially defined for submit_json_as_php_array()
1847
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1848
  return system_settings_form($form);
1849
}
1850

    
1851

    
1852
/**
1853
 * @param $form_name
1854
 * @param $form_title
1855
 * @param $collapsed
1856
 * @param string $form_description
1857
 *   The description for the fieldset of the gallery setting.
1858
 * @return mixed
1859
 */
1860
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1861
  $form[$form_name] = array(
1862
    '#type' => 'fieldset',
1863
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1864
    '#collapsible' => TRUE,
1865
    '#collapsed' => $collapsed,
1866
    '#tree' => TRUE,
1867
    '#description' => $form_description,
1868
  );
1869

    
1870
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1871
  $gallery_settings = variable_get($form_name, $default_values);
1872
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1873
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1874
    /*
1875
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1876
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1877
    '#type' => 'textfield',
1878
    '#title' => t('Search Page Size'),
1879
    '#default_value' => $test,
1880
    '#description' => t('Number of Names to display per page in search results.')
1881
    );
1882
    */
1883
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1884
      '#type' => 'checkbox',
1885
      '#title' => t('Show media thumbnails for accepted taxa'),
1886
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1887
    );
1888

    
1889
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1890
      '#type' => 'checkbox',
1891
      '#title' => t('Show media thumbnails for synonyms'),
1892
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1893
      '#description' => '',
1894
    );
1895
  }
1896

    
1897
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1898
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1899
    '#type' => 'checkbox',
1900
    '#title' => t('Show captions under thumbnails'),
1901
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1902
    '#description' => '',
1903
  );
1904

    
1905
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1906
    '#type' => 'textfield',
1907
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1908
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1909
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1910
  );
1911

    
1912
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1913
    '#type' => 'textfield',
1914
    '#title' => t('Number of columns') . ':',
1915
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1916
    '#description' => t('Group the thumbnails in columns: select how many
1917
      columns the gallery should display.'),
1918
  );
1919

    
1920
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1921
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1922
      '#type' => 'textfield',
1923
      '#title' => t('Maximum number of rows') . ':',
1924
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1925
      '#description' => t('You can group the thumbnails in rows, select in how
1926
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1927
        If you want an unlimited number of rows please set to 0.'),
1928
    );
1929
  }
1930

    
1931
  return $form;
1932
}
1933

    
1934
/**
1935
 * @return array
1936
 *   The form structure.
1937
 */
1938
function cdm_settings_layout_taxon() {
1939
  $collapsed = FALSE;
1940
  $form = array();
1941

    
1942
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1943

    
1944
  // --------- TABBED TAXON ------- //
1945
  $form['taxon_tabs'] = array(
1946
    '#type' => 'fieldset',
1947
    '#title' => t('Taxon tabs'),
1948
    '#collapsible' => TRUE,
1949
    '#collapsed' => TRUE,
1950
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1951
  );
1952

    
1953
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1954
    '#type' => 'checkbox',
1955
    '#title' => t('Tabbed taxon page'),
1956
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1957
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1958
  );
1959

    
1960
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1961
    '#type' => 'checkbox',
1962
    '#title' => t('Synonymy as tab'),
1963
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1964
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1965
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1966
  );
1967

    
1968
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1969
    '#type' => 'checkboxes',
1970
    '#title' => t('Section/Tab visibility') . ':',
1971
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1972
    '#options' => get_taxon_options_list()
1973
  );
1974

    
1975
  // WEIGHT
1976
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1977
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1978
    '#title'  => 'Section/Tab order',
1979
    '#type' => 'fieldset',
1980
    '#collapsible' => false,
1981
    '#tree' => true,
1982
    '#description' => 'The weight value defines the order of the section/tab.'
1983
  );
1984
  // Weights range from -delta to +delta, so delta should be at least half
1985
  // of the amount of tabs present.
1986
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1987
  foreach (get_taxon_tabs_list() as $label) {
1988
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1989
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1990
        '#title' => $label,
1991
        '#type'  => 'weight',
1992
        '#default_value' => $taxon_tabs_weights[$key],
1993
        '#delta' => $tab_weight_delta
1994
    );
1995
  }
1996

    
1997
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1998
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1999
    '#title'  => 'Section/Tab label override',
2000
    '#type' => 'fieldset',
2001
    '#collapsible' => false,
2002
    '#tree' => true,
2003
    '#description' => 'Setting a label for a section/tab will override the default label. 
2004
      Please enter the label text in the default language of the portal.'
2005
  );
2006
  foreach (get_taxon_tabs_list() as $label) {
2007
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2008
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
2009
      '#title' => $label,
2010
      '#type'  => 'textfield',
2011
      '#default_value' => $taxon_tabs_labels[$key]
2012
    );
2013
  }
2014

    
2015
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
2016
    '#type' => 'select',
2017
    '#title' => t('Default tab to display') . ':',
2018
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
2019
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
2020
    '#description' => t('<p>Select the default tab to display when visiting a
2021
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
2022
      <strong>Note:</strong> After performing a search and clicking in any
2023
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
2024
      taxon and not the above selected tab.'),
2025
  );
2026

    
2027
  /* ======  TAXON_PROFILE ====== */
2028
  $form['taxon_profile'] = array(
2029
    '#type' => 'fieldset',
2030
    '#title' => t('Taxon profile (tab)'),
2031
    '#description' => t('<p>This section covers the settings related to the taxon
2032
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
2033
    '#collapsible' => TRUE,
2034
    '#collapsed' => TRUE,
2035
  );
2036

    
2037
  // ---- PROFILE PICTURE ----//
2038

    
2039
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2040
    '#type' => 'fieldset',
2041
    '#tree' => TRUE,
2042
    '#title' => t('Taxon profile picture'),
2043
    '#collapsible' => TRUE,
2044
    '#collapsed' => FALSE,
2045
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2046
  );
2047

    
2048
  //FIXME migrate variables:
2049
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2050
  // FIXME
2051
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2052

    
2053
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2054

    
2055
  /*
2056
   * 'show' => 1,
2057
   * 'maxextend' => 184,
2058
   * 'media_uri_query' => ''
2059
   * 'custom_placeholder_image_on' => 1,
2060
   * 'custom_placeholder_image_fid' => ''
2061
   */
2062
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2063
    '#type' => 'checkbox',
2064
    '#title' => t('Enable profile picture'),
2065
    '#description' => t('Show the profile picture.'),
2066
    '#default_value' => $taxon_profile_image_settings['show'],
2067
  );
2068

    
2069
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2070
      '#type' => 'textfield',
2071
      '#tree' => TRUE,
2072
      '#title' => t('Profile picture maximum extend'),
2073
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2074
      '#field_suffix' => 'px',
2075
      '#maxlength' => 4,
2076
      '#size' => 4,
2077
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2078
  );
2079

    
2080
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2081
      '#type' => 'textfield',
2082
      '#tree' => TRUE,
2083
      '#title' => t('Additional URI query parameter'),
2084
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2085
      '#maxlength' => 1024,
2086
      '#size' => 60,
2087
      '#description' => t('Additional query parameters to be used when requesting for the  
2088
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2089
            The query parameters will be appended to the uri of the media representation part
2090
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2091
  );
2092

    
2093
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2094
    '#type' => 'checkbox',
2095
    '#title' => t('Show the placeholder image'),
2096
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2097
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2098
  );
2099

    
2100
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2101
      '#type' => 'checkbox',
2102
      '#title' => t('Use a custom placeholder image'),
2103
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2104
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2105
  );
2106

    
2107
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2108
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2109
        '#type' => 'managed_file',
2110
        '#title' => t('Custom placeholder image file'),
2111
        '#progress_indicator' => 'bar',
2112
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2113
    //       '#name' => 'custom_placeholder_image',
2114
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2115
    );
2116

    
2117
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2118
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2119
      $url = file_create_url($profile_image_file->uri);
2120
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2121
                '#type' => 'item',
2122
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2123
      );
2124
    }
2125
  } else {
2126
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2127
      '#type' => 'hidden',
2128
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2129
    );
2130
  }
2131

    
2132
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2133
  array_unshift($options, '-- DISABLED --');
2134
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2135
    '#type' => 'select',
2136
    '#title' => t('Hide profile picture for higher ranks') . ':',
2137
    '#default_value' => variable_get('image_hide_rank', '0'),
2138
    '#options' => $options,
2139
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2140
  );
2141

    
2142
  // -- MEDIA THUMBNAILS -- //
2143
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2144
  $form_title = 'Taxon Profile Images';
2145
  $form_description = '<p>The different sections 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>';
2146
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2147

    
2148
  // ---- FEATURE TREE BLOCKS ---- //
2149
  $form['taxon_profile']['feature_blocks'] = array(
2150
    '#type' => 'fieldset',
2151
    '#title' => t('Feature Blocks'),
2152
    '#collapsible' => TRUE,
2153
    '#collapsed' => FALSE,
2154
    '#description' => t("This section covers settings related to the taxon's
2155
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2156
      features such as description, distribution, common names"),
2157
  );
2158
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2159
  $profile_feature_tree = get_profile_feature_tree();
2160
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2161
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2162
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2163
  }
2164
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2165
    '#type' => 'radios',
2166
    '#title' => t('Taxon profile feature tree') . ':',
2167
    '#default_value' => $profile_feature_tree_uuid,
2168
    '#options' =>  $featureTrees['options'],
2169
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2170
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2171
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2172
      profile page.'
2173
    ),
2174
  );
2175

    
2176
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2177
  $profile_feature_tree = get_profile_feature_tree();
2178

    
2179
  if (isset($profile_feature_tree->root->childNodes)) {
2180

    
2181
    $form_feature_block_layout = array(
2182
      '#type' => 'fieldset',
2183
      '#tree' => true,
2184
      '#title' => t('Taxon profile feature block settings'),
2185
      '#collapsible' => TRUE,
2186
      '#collapsed' => FALSE,
2187
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2188
      A sub form for each of the the currently selected feature tree allows to configure each feature block individually.
2189
      The subforms have the following settings in common:<br />
2190
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2191
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2192
      <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>
2193
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2194
            <ol>
2195
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2196
                appended in brackets like "text (source references)". If the original source has name in source
2197
                information it will be appended to the citation string,
2198
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2199
             <li>if the text of the TextData is empty, the original source citations are the only content
2200
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2201
                prepended to the citation string like: "name in source: citation"</li>
2202
            </ol>
2203
            <strong>If disabled:</strong><br />
2204
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2205
             citations are the only content, the resulting feature block content would only consist of footnotes.
2206
             In this case the display of the respective feature block is suppressed.</div>
2207
      </dl>
2208
      <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
2209
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2210
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2211
        . '</em></div>
2212
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2213
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2214
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2215
      <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>
2216
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2217
           cdm_feature_block_element_tag_name()</div>
2218
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2219
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2220
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2221
    );
2222

    
2223

    
2224
    $feature_list_layout_settings_disabled = FALSE;
2225

    
2226
    // creating helper object to retrieve the default settings
2227
    $featureNode = new stdClass();
2228
    $featureNode->term = new stdClass();
2229
    $featureNode->term->uuid="DEFAULT";
2230
    $featureNode->term->representation_L10n = "Default";
2231
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2232

    
2233
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2234

    
2235
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2236

    
2237
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2238
        $subform_id = $featureNode->term->uuid;
2239
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2240

    
2241
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2242

    
2243
        $form_feature_block_layout[$subform_id] = array(
2244
          '#type' => 'fieldset',
2245
          '#tree' => TRUE,
2246
          '#title' => $featureNode->term->representation_L10n,
2247
          '#collapsible' => FALSE,
2248
          '#collapsed' => FALSE,
2249
        );
2250
        if($featureNode->term->uuid == "DEFAULT"){
2251
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2252
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2253
          references</em> and <em>names in source</em> is only possible in the defaults';
2254
        }
2255

    
2256
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2257
          '#type' => 'select',
2258
          '#title' => 'List type',
2259
          '#default_value' => $feature_block_setting['as_list'],
2260
          '#options' => array(
2261
            'div' => 'not as list',
2262
            'ul' => 'bullet list',
2263
            'ol' => 'numbered list',
2264
            'dl' => 'definition list'
2265
          ),
2266
        );
2267

    
2268
        if($featureNode->term->uuid == "DEFAULT"){
2269
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2270
            '#type' => 'checkbox',
2271
            '#title' => t('Link to reference'),
2272
            '#default_value' => $feature_block_setting['link_to_reference'],
2273
          );
2274

    
2275
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2276
            '#type' => 'checkbox',
2277
            '#title' => 'Link to name used in source',
2278
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2279
          );
2280
        }
2281

    
2282
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2283
          '#type' => 'checkbox',
2284
          '#title' => 'Sources as content',
2285
          '#default_value' => $feature_block_setting['sources_as_content'],
2286
        );
2287

    
2288
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2289
          '#type' => 'checkbox',
2290
          '#title' => 'Put sources also as content to bibliography',
2291
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2292
        );
2293

    
2294
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2295
          '#type' => 'select',
2296
          '#title' => t('Sort elements'),
2297
          '#default_value' => $feature_block_setting['sort_elements'],
2298
          '#options' => array(
2299
            NO_SORT => 'No sorting',
2300
            SORT_ASC => 'Ascending',
2301
            SORT_DESC => 'Descending',
2302
            SORT_HIERARCHICAL => 'Hierarchical'
2303
          ),
2304
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2305
          <dl>
2306
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2307
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2308
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2309
          <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>
2310
          </dl>',
2311
        );
2312

    
2313
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2314
          '#type' => 'select',
2315
          '#title' => t('Element tag'),
2316
          '#options' => array(
2317
            'span' => 'span',
2318
            'div' => 'div',
2319
            'p' => 'p'
2320
          ),
2321
          '#default_value' => $feature_block_setting['element_tag'],
2322
        );
2323
        $form_feature_block_layout[$subform_id]['glue'] = array(
2324
          '#type' => 'textfield',
2325
          '#title' => t('Element glue'),
2326
          '#default_value' => $feature_block_setting['glue'],
2327
          '#size' => 10
2328
      );
2329

    
2330
      }
2331
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2332
    }
2333
  }
2334

    
2335
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2336
  $form['taxon_profile']['structured_description_featuretree'] = array(
2337
    '#type' => 'fieldset',
2338
    '#title' => t('Structured Description Feature Tree'),
2339
    '#collapsible' => TRUE,
2340
    '#collapsed' => FALSE,
2341
  );
2342
  $featureTrees = cdm_get_featureTrees_as_options();
2343
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2344
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2345
    $profile_feature_tree_uuid = NULL;
2346
  }
2347
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2348
    '#type' => 'radios',
2349
    '#title' => t('Natural language representation of structured descriptions') . ':',
2350
    '#default_value' => $profile_feature_tree_uuid,
2351
    '#options' => $featureTrees['options'],
2352
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2353
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2354
    '#description' => t('Taxon descriptions can be stored in a highly structured
2355
      form. The feature tree selected here will be used to generate textual
2356
      representation in natural language.'
2357
    ),
2358
  );
2359

    
2360

    
2361

    
2362
  // ---- DISTRIBUTION LAYOUT ---- //
2363
  $form['taxon_profile']['distribution_layout'] = array(
2364
    '#title' => t('Distribution'),
2365
    '#collapsible' => TRUE,
2366
    '#collapsed' => FALSE,
2367
    '#type' => 'fieldset',
2368
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2369
        Map settings regarding the geometry, layers, etc are found in the '
2370
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2371
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2372
      . l(
2373
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2374
        array('fragment' => 'edit-feature-block-settings')
2375
      )
2376
      . ' More general settings regrading the filtering of Distributions are found at '
2377
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2378
      . '. (These settings here will be merged in future releases into the feature block settings)',
2379

    
2380
  );
2381

    
2382
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2383

    
2384
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2385
    '#type' => 'checkbox',
2386
    '#title' => t('Condensed distribution'),
2387
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2388
    '#description' => 'This option enables the display of a very compact representation
2389
    of the distribution which includes also information on the status.',
2390
  );
2391

    
2392
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2393
    '#type' => 'select',
2394
    '#title' => t('Condensed distribution recipe'),
2395
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2396
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2397
    '#description' => 'Recipe for creating the condensed distribution.',
2398
  );
2399

    
2400
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2401
    '#type' => 'textfield',
2402
    '#title' => t('Condensed distribution info path'),
2403
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2404
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2405
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2406
  );
2407

    
2408

    
2409
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2410
    '#type' => 'radios',
2411
    '#title' => t('Display mode') . ':',
2412
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2413
    '#options' => array(
2414
      'FLAT_ALPHA' => t('Flat list'),
2415
      'TREE' => t('Hierarchically ordered'),
2416
    ),
2417
    '#description' => 'Taxon distribution information is displayed with
2418
    focus on the area of the distribution. The list of areas can either be shown
2419
    as flat list ordered alphabetically or in the hierarchical of the parent
2420
    area and subarea relationship. Fall back areas areas with no Distribution data
2421
    are hidden from the area hierarchy so that their sub areas will move one level up.
2422
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2423
    ' for details on the <em>Marked area filter</em>.',
2424
  );
2425

    
2426
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2427
    '#type' => 'fieldset',
2428
    '#tree' => true,
2429
    '#title' => t('Distribution hierarchy style')
2430
  );
2431

    
2432
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2433
  foreach(array_keys($hierarchy_styles) as $level) {
2434
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2435
      '#type' => 'fieldset',
2436
      '#tree' => true,
2437
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2438
      '#attributes' => array('class' => array('fieldset-float'))
2439
    );
2440
    foreach ($hierarchy_styles[$level] as $key => $value) {
2441
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2442
        '#type' => 'textfield',
2443
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2444
        '#default_value' => $hierarchy_styles[$level][$key],
2445
        '#maxlength' => 4,
2446
        '#size' => 4
2447
      );
2448
    }
2449
  }
2450

    
2451
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2452
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2453
    '#type' => 'checkboxes',
2454
    '#title' => 'Omit area levels',
2455
    '#options' => $level_options,
2456
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2457
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2458
    Areas which belong to the selected area levels will be hidden in the portal.',
2459
  );
2460

    
2461
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2462
    '#type' => 'checkbox',
2463
    '#title' => t('Show TextData elements on top of the map'),
2464
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2465
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2466
      elements on top of the map. Otherwise all <code>TextData</code>
2467
      distribution elements will be listed below the other area elements.
2468
      This option is useful if you need to have descriptive texts for each
2469
      distribution map.'),
2470
  );
2471

    
2472
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2473
      '#type' => 'textarea',
2474
      '#title' => t('Custom status colors'),
2475
      '#element_validate' => array('form_element_validate_json'),
2476
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2477
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2478
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2479
          reference list of the idInVocabulary values of absence and presence terms:
2480
<pre>
2481
Presence Term
2482
p        present
2483
pd        present: doubtfully present
2484
n        native
2485
nq        native: presence questionable
2486
nd        native: doubtfully native
2487
c        cultivated
2488
i        introduced
2489
iq        introduced: presence questionable
2490
id        introduced: doubtfully introduced (perhaps cultivated only)
2491
ip        introduced: uncertain degree of naturalisation
2492
ia        introduced: adventitious (casual)
2493
in        introduced: naturalized
2494
ic        introduced: cultivated
2495
e        endemic for the relevant area
2496
na        naturalised
2497
iv        invasive
2498

2499
AbsenceTerm
2500
a        absent
2501
f        reported in error
2502
nf        native: reported in error
2503
if        introduced: reported in error
2504
cf        cultivated: reported in error
2505
ne        native: formerly native
2506
ie        introduced: formerly introduced
2507

2508
</pre>'),
2509
  );
2510

    
2511

    
2512
  /* ====== SYNONYMY ====== */
2513
  $form['taxon_synonymy'] = array(
2514
    '#type' => 'fieldset',
2515
    '#title' => t('Taxon synonymy (tab)'),
2516
    '#collapsible' => TRUE,
2517
    '#collapsed' => TRUE,
2518
    '#description' => t('This section covers the settings related to the taxon
2519
      <strong>synonymy</strong> tab.'),
2520
  );
2521

    
2522
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2523
    '#type' => 'checkbox',
2524
    '#title' => t('Accepted taxon on top of the synonymy'),
2525
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2526
    '#description' => t('If checked, the first homotypic taxon is a repetition
2527
      of the accepted taxon most likely with the full nomenclatural reference, 
2528
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2529
  );
2530

    
2531
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2532
    '#type' => 'checkbox',
2533
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2534
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2535
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2536
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2537
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2538
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE)
2539
  );
2540

    
2541
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2542
    '#type' => 'textfield',
2543
    '#description' => 'Label for the secundum referenence.',
2544
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2545
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2546
    );
2547

    
2548
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2549
    '#type' => 'checkbox',
2550
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2551
      coming from a synonym link.'),
2552
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2553
    '#description' => t('Check this if after doing a search and clicking on a
2554
      synonym you want to see the "accept of" text for the accepted synonym.'),
2555
  );
2556

    
2557
  $form['taxon_synonymy']['taxon_relations'] = array(
2558
    '#type' => 'fieldset',
2559
    '#title' => t('Taxon relationships'),
2560
    '#collapsible' => FALSE,
2561
    '#collapsed' => FALSE
2562
  );
2563

    
2564
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2565
    '#type' => 'checkbox',
2566
    '#title' => t('Show taxon relations ships of accepted taxon'),
2567
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2568
    '#description' => t('If this option is enabled the synonymy will show the
2569
      below selected taxon relationships of accepted taxa.'),
2570
  );
2571

    
2572
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2573
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2574
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2575
    '#type' => 'checkboxes',
2576
    '#title' => t('Taxon relationship types') . ':',
2577
    '#description' => 'Only taxon relationships of the selected type will be displayed',
2578
    '#options' => $taxon_relationship_type_options,
2579
    '#default_value' => $taxon_relationship_type_defaults,
2580
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2581
  );
2582

    
2583
  $form['taxon_synonymy']['name_relations'] = array(
2584
    '#type' => 'fieldset',
2585
    '#title' => t('Name relationships'),
2586
    '#collapsible' => FALSE,
2587
    '#collapsed' => FALSE
2588
  );
2589

    
2590
  $name_relationship_type_options = cdm_vocabulary_as_option(
2591
      UUID_NAME_RELATIONSHIP_TYPE,
2592
      '_cdm_relationship_type_term_label_callback',
2593
      false,
2594
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2595
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2596
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2597
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2598
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2599
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2600
  );
2601
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2602
    '#type' => 'checkboxes',
2603
    '#title' => t('Name relationship types') . ':',
2604
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2605
    A full listing of all name relationships for a scientific name is provided by the taxon ' . l('name page', 'admin/config/cdm_dataportal/settings/layout/name-page') . '.',
2606
    '#options' => $name_relationship_type_options,
2607
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2608
  );
2609

    
2610
  // ====== SPECIMENS ====== //
2611
  $form['taxon_specimens'] = array(
2612
    '#type' => 'fieldset',
2613
    '#title' => t('Taxon specimens (tab)'),
2614
    '#collapsible' => TRUE,
2615
    '#collapsed' => TRUE,
2616
    '#description' => t('This section covers the settings related to the taxon
2617
      <strong>specimens</strong> tab.'),
2618
  );
2619

    
2620
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2621

    
2622
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2623
    '#type' => 'checkbox',
2624
    '#title' => t('Show specimen derivatives in a compressed table'),
2625
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2626
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2627
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2628
  );
2629

    
2630
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2631
      '#type' => 'textfield',
2632
      '#title' => t('Number of records per page') . ':',
2633
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2634
  );
2635

    
2636
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2637
        '#type' => 'checkbox',
2638
        '#title' => t('Show specimen derivatives in a tree view'),
2639
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2640
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2641
    );
2642

    
2643

    
2644
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2645
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2646
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2647
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2648
  }
2649
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2650
    '#type' => 'radios',
2651
    '#title' => t('Specimen description feature tree') . ':',
2652
    '#default_value' => $profile_feature_tree_uuid,
2653
    '#options' =>  $featureTrees['options'],
2654
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2655
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2656
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2657
    ),
2658
  );
2659

    
2660
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2661
  $form_title = t('Specimen media');
2662
  $form_description = t('Specimens may have media which is displayed at the
2663
     Specimen tab/section as a gallery. It is possible to configure the
2664
     thumbnails gallery here, however for configuring how a single media should
2665
     be displayed please go to !url.</p>',
2666
     array(
2667
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2668
     ));
2669
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2670

    
2671
  // --- MEDIA GALLERY ---- //
2672
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2673
  $form_title = 'Media gallery (tab)';
2674
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2675
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2676
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2677
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2678
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2679
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2680
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2681

    
2682
  // Comment @WA: D7 form api does not support reset buttons,
2683
  // so to mimic the D5 reset button we add one like this.
2684
  $form['actions']['reset'] = array(
2685
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2686
    '#weight' => 1000,
2687
  );
2688
  return system_settings_form($form);
2689
}
2690

    
2691
/**
2692
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2693
 *
2694
 * @param $map_id
2695
 * @param $form
2696
 * @return mixed
2697
 */
2698
function _cdm_map_visibility_setting($map_id)
2699
{
2700
  return array(
2701
    '#type' => 'select',
2702
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2703
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2704
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2705
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2706
        The map also can forced to show up <b>always</b> or <b>never</b>."
2707
  );
2708
}
2709

    
2710
/**
2711
 * @return array
2712
 *   The form structure.
2713
 */
2714
function cdm_settings_layout_search() {
2715

    
2716
  $form = array();
2717

    
2718
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2719

    
2720
  $form['search_settings'] = array(
2721
    '#type' => 'fieldset',
2722
    '#title' => t('Taxa Search'),
2723
    '#collapsible' => FALSE,
2724
    '#collapsed' => FALSE,
2725
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2726
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2727
         where they can write the text to be searched. You can find Drupal block configuration
2728
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2729
  );
2730

    
2731
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2732
      '#type' => 'checkbox',
2733
      '#title' => t('Ignore the chosen classification in simple search'),
2734
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2735
      '#description' => t('The simple search, which can be executed via the search block,
2736
          will by default search on the classification selected in the classification browser
2737
          selector. Set the tick if you want your portal to search on all classifications.'),
2738
  );
2739

    
2740
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2741
    '#type' => 'checkbox',
2742
    '#title' => t('Run simple search with free-text search backend.'),
2743
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2744
    '#description' => t('The simple search uses by default another search
2745
      backend as the advances search. By checking this option the simple search can be
2746
      configured to also use the free-text search backend.'),
2747
  );
2748

    
2749
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2750
    '#type' => 'checkbox',
2751
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2752
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2753
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2754
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2755
  );
2756

    
2757
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2758
    '#type' => 'textfield',
2759
    '#title' => t('Results per page') . ':',
2760
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2761
    '#description' => t('Number of results to display per page.'),
2762
  );
2763

    
2764
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2765
    '#type' => 'checkbox',
2766
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2767
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2768
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2769
  );
2770

    
2771
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2772
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2773
      '#type' => 'checkboxes',
2774
      '#title' => 'Search mode',
2775
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2776
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2777
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2778
          defaults set here.',
2779
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2780
      '#default_value' => $search_mode_default
2781
      );
2782

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

    
2788
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2789
  );
2790

    
2791
    $form['blast_search_settings'] = array(
2792
        '#type' => 'fieldset',
2793
        '#title' => t('Blast Search'),
2794
        '#collapsible' => TRUE,
2795
        '#collapsed' => TRUE,
2796
        '#description' => t('<p>To perform blast searchs
2797
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2798
         where they can write the text to be searched. You can find Drupal block configuration
2799
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2800
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2801
    );
2802

    
2803
    $form['blast_search_settings'][CDM_SEARCH_BLAST_ENABLED] = array(
2804
        '#type' => 'checkbox',
2805
        '#title' => t('Activate Blast search') . ':',
2806
        '#default_value' => variable_get(CDM_SEARCH_BLAST_ENABLED, 0), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2807

    
2808
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2809
    );
2810
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2811
        '#type' => 'textfield',
2812
        '#title' => t('Webservice URL for blast search') . ':',
2813
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://127.0.0.1:9001/api/sequence'), // '05b0dd06-30f8-477d-bf4c-30d9def56320' =>  Caucasia (Ab + Ar + Gg + Rf(CS)) (Cc)
2814

    
2815
        '#description' => t('Enter the webservice URL for blast search'),
2816
    );
2817

    
2818
  // --- SEARCH TAXA GALLERY ---- //
2819
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2820
  $collapsed = FALSE;
2821
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2822
  $form_title = 'Taxa Search thumbnails';
2823
  $form_description = 'Search results may show thumbnails. ';
2824
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2825

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

    
2835
/**
2836
 * @return array
2837
 *   The form structure.
2838
 */
2839
function cdm_settings_layout_media() {
2840

    
2841
  $form = array();
2842

    
2843
  $form['media_settings'] = array(
2844
    '#type' => 'fieldset',
2845
    '#title' => t('Media settings'),
2846
    '#collapsible' => FALSE,
2847
    '#collapsed' => FALSE,
2848
    '#description' => 'This section covers layout settings for media pages.'
2849
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2850
  );
2851

    
2852
  $form['media_settings']['image_gallery_viewer'] = array(
2853
    '#type' => 'select',
2854
    '#title' => t('Image viewer') . ':',
2855
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2856
    '#options' => array(
2857
      'default' => t('Standard image viewer'),
2858
      'fsi' => t('FSI viewer (requires FSI server!)'),
2859
    ),
2860
  );
2861

    
2862
  // --- STANDARD_IMAGE_VIEWER ---- //
2863
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2864
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2865
      '#type' => 'fieldset',
2866
      '#tree' => true,
2867
      '#title' => t('Standard image viewer settings'),
2868
      '#collapsible' => FALSE,
2869
      '#collapsed' => FALSE,
2870
      );
2871

    
2872
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2873
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2874
      '#type' => 'checkbox',
2875
      '#title' => 'Show media representations',
2876
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2877

    
2878
    );
2879
  }
2880

    
2881

    
2882
  // @WA: D7 form api does not support reset buttons,
2883
  // so to mimic the D5 reset button we add one like this.
2884
  $form['actions']['reset'] = array(
2885
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2886
    '#weight' => 1000,
2887
  );
2888
  return system_settings_form($form);
2889
}
2890

    
2891
/**
2892
 * GEOSERVICE and Map settings.
2893
 *
2894
 *  @return array
2895
 *   The form structure.
2896
 */
2897
function cdm_settings_geo($form, &$form_state) {
2898

    
2899
  $current_geoserver_settings = get_edit_map_service_settings();
2900
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2901

    
2902

    
2903
  $form = array();
2904

    
2905
  $dummy_distribution_query = NULL;
2906
  if($map_distribution['map_type'] != 1){
2907
    // we need to apply a dummy query since the map service requires for image maps
2908
    // at least as and ad to be defined
2909
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2910
  }
2911

    
2912
  $form['map_preview'] = array(
2913
      '#type' => 'fieldset',
2914
      '#tree' => FALSE,
2915
      '#title' => t('Map preview'),
2916
      '#collapsible' => FALSE,
2917
      '#description' => 'The preview of the map'
2918
       . ($dummy_distribution_query != null ?
2919
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2920
           '.<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.')
2921
  );
2922
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2923
    'move' => "this.cdmOpenlayersMap.printInfo",
2924
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2925
  ), true // resizable
2926
  );
2927

    
2928
  /*
2929
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2930
  );
2931
  */
2932

    
2933
  /*
2934
   * GEO SERVER
2935
   */
2936
  $form['edit_map_server'] = array(
2937
    '#type' => 'fieldset',
2938
    '#tree' => true,
2939
    '#title' => t('EDIT map service'),
2940
    '#collapsible' => TRUE,
2941
    '#collapsed' => TRUE,
2942
    '#description' => t('Configuration and selection of your geo server.
2943
      The Geo Server is responsible for generating the maps.'),
2944
  );
2945

    
2946
  $form['edit_map_server']['base_uri'] = array(
2947
    '#type' => 'select',
2948
    '#title' => t('EDIT map service') . ':',
2949
    '#default_value' => $current_geoserver_settings['base_uri'],
2950
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2951
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2952
  );
2953
  $form['edit_map_server']['version'] = array(
2954
      '#type' => 'select',
2955
      '#title' => t('Version') . ':',
2956
      '#default_value' => $current_geoserver_settings['version'],
2957
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2958
      '#description' => t('The version of the EDIT map services'),
2959
  );
2960

    
2961
  /*
2962
   * MAP SETTINGS
2963
   */
2964

    
2965
  $form[CDM_MAP_DISTRIBUTION] = array(
2966
    '#type' => 'fieldset',
2967
    '#tree' => TRUE,
2968
    '#title' => t('Maps settings'),
2969
    '#collapsible' => TRUE,
2970
    '#collapsed' => TRUE,
2971
    '#description' => t('General configuration for all map types.'),
2972
  );
2973

    
2974
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2975
    '#type' => 'radios',
2976
    '#title' => 'Map types',
2977
    '#options' => array(
2978
      1 => "OpenLayers dynamic map viewer",
2979
      0 => "Plain image",
2980
    ),
2981
    '#default_value' => $map_distribution['map_type'],
2982
    '#description' => 'Two different map types are available :
2983
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2984
      which allows zooming and panning. If enabled you can configure the default layer
2985
      (background of your maps) below.</li>
2986
      <li><em>Plain image</em>: The map will be static non interactive
2987
      image.</li></ul>',
2988
  );
2989
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2990

    
2991
  /*
2992
   * settings for the distribution map are used also for specimens map!!!!
2993
   */
2994

    
2995
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2996
      '#type' => 'textfield',
2997
      '#title' => 'Aspect ratio',
2998
      '#default_value' => $map_distribution['aspect_ratio'],
2999
      '#maxlength' => 4,
3000
      '#size' => 4,
3001
      '#element_validate' => array('element_validate_number'),
3002
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
3003
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
3004
      width by the height:</br>
3005
      <pre>aspect ratio = w / h</pre>
3006
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
3007
      for a square map use <strong>1</strong>.',
3008
  );
3009

    
3010
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3011
    '#type' => 'textfield',
3012
    '#title' => 'Bounding box',
3013
    '#default_value' => $map_distribution['bbox'],
3014
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
3015
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
3016
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3017
      <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.
3018
      (Maybe you need to change the map base layer to OpeLayers.)
3019
      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
3020
      below the map from where you can copy the bbox string.</p>'),
3021
  );
3022

    
3023
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3024
    '#type' => 'select',
3025
    '#title' => 'Max zoom level',
3026
    '#default_value' => $map_distribution['maxZoom'],
3027
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3028
  );
3029

    
3030
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3031
    '#type' => 'checkbox',
3032
    '#title' => 'Display area labels',
3033
    '#default_value' => $map_distribution['show_labels'],
3034
    '#description' => t('The map will show name labels of the areas'),
3035
  );
3036

    
3037
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3038
    '#type' => 'textfield',
3039
    '#title' => 'Map caption',
3040
    '#default_value' => $map_distribution['caption'],
3041
    '#description' => t('The caption will be shown below the map.'),
3042
  );
3043

    
3044
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3045
    '#type' => 'textfield',
3046
    '#title' => 'Distribution layer opacity',
3047
    '#default_value' => $map_distribution['distribution_opacity'],
3048
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3049
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3050
  );
3051

    
3052
  // --- Plain Image Settings --- //
3053
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
3054
    '#type' => 'fieldset',
3055
    '#title' => 'Plain image map settings',
3056
    '#tree' => TRUE,
3057
    '#collapsible' => TRUE,
3058
    '#collapsed' => $open_layers_is_enabled,
3059
    '#description' => 'The settings in this section are still expertimental
3060
      and can only be used with the EDIT map service version 1.1 or above.',
3061
  );
3062
  $edit_mapserver_version = get_edit_map_service_version_number();
3063
  if ($edit_mapserver_version < 1.1) {
3064
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3065
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3066
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3067
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3068
  }
3069

    
3070
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3071
    '#type' => 'textfield',
3072
    '#title' => 'Width',
3073
    '#default_value' => $map_distribution['image_map']['width'],
3074
    '#maxlength' => 4,
3075
    '#size' => 4,
3076
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3077
  );
3078

    
3079
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3080
    '#type' => 'textfield',
3081
    '#title' => 'Background layer',
3082
    '#default_value' => $map_distribution['image_map']['base_layer'],
3083
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3084
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3085
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3086
    )),
3087
  );
3088

    
3089
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3090
    '#type' => 'textfield',
3091
    '#title' => 'Background color',
3092
    '#default_value' => $map_distribution['image_map']['bg_color'],
3093
  );
3094

    
3095
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3096
    '#type' => 'textfield',
3097
    '#title' => 'Background layer style',
3098
     // Only line color by now.
3099
    '#default_value' => $map_distribution['image_map']['layer_style'],
3100
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3101
  );
3102

    
3103
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3104
      '#type' => 'textfield',
3105
      '#title' => 'Projection',
3106
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3107
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3108
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3109
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3110
  );
3111

    
3112

    
3113
  // --- OpenLayers Settings --- //
3114
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3115
    '#type' => 'fieldset',
3116
    '#title' => 'OpenLayers settings',
3117
    '#tree' => TRUE,
3118
    '#collapsible' => TRUE,
3119
    '#collapsed' => !$open_layers_is_enabled,
3120
    '#description' => '',
3121
  );
3122

    
3123

    
3124
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3125
      '#type' => 'checkbox',
3126
      '#title' => 'Display outside max extent',
3127
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3128
      '#description' => t('Allows the map to display parts of the layers which are outside
3129
         the max extent if the aspect ratio of the map and of the baselayer
3130
         are not equal.'),
3131
  );
3132

    
3133

    
3134
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3135
      '#type' => 'checkbox',
3136
      '#title' => 'Show Layer Switcher',
3137
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3138
      '#description' => 'The Layer Switcher control displays a table of contents
3139
      for the map.  This allows the user interface to switch between
3140
      base layers and to show or hide overlays.  By default the switcher is
3141
      shown minimized on the right edge of the map, the user may expand it
3142
      by clicking on the handle.',
3143
  );
3144

    
3145
  if (!$open_layers_is_enabled) {
3146
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3147
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3148
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3149
  }
3150

    
3151
  // The default layer must always be enabled
3152
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3153
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3154

    
3155
  $baselayer_options = array(
3156
    /*
3157
   NOTICE: must correspond to the layers defined in
3158
   js/openlayers_,ap.js#getLayersByName()
3159
   */
3160
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3161
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3162
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3163
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3164
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3165
    // all others EPSG:900913
3166
    'mapnik' => 'OpenStreetMap (mapnik)',
3167
    'stamen_terrain' => 'Stamen Terrain',
3168
    'open_topomap' => 'OpenTopoMap',
3169
    // map quest is no longer free. it is required to sign up for a test plan.
3170
    // 'mapquest_open' => "MapQuest",
3171
    // 'mapquest_sat' => "MapQuest Sattelite",
3172
    'groadmap' => 'Google Roadmap',
3173
    'gsatellite' => 'Google Satellite',
3174
    'ghybrid' => 'Google Hybrid',
3175
    'gterrain' => 'Google Terrain',
3176
//     'veroad' => 'Virtual Earth Roads',
3177
//     'veaer' => 'Virtual Earth Aerial',
3178
//     'vehyb' => 'Virtual Earth Hybrid',
3179
    // 'yahoo' => 'Yahoo Street',
3180
    // 'yahoosat' => 'Yahoo Satellite',
3181
    // 'yahoohyb' => 'Yahoo Hybrid',
3182
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3183
  );
3184

    
3185
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3186
    '#type' => 'checkboxes_preferred',
3187
    '#title' => 'Base Layers',
3188
    '#options' => $baselayer_options,
3189
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3190
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3191
  );
3192

    
3193
  $google_maps_api_key = null;
3194
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3195
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3196
  }
3197
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3198
    '#type' => 'textfield',
3199
    '#title' => 'Google Maps API Key',
3200
    '#default_value' => $google_maps_api_key,
3201
    '#description' => 'In order to use any of the Google map layers you need to provide 
3202
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3203
  );
3204

    
3205
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3206
    $map_distribution[