Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

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

    
15
  define('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'=> 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
 * @return
1530
 *   todo
1531
 */
1532
function cdm_settings_layout() {
1533

    
1534
  $form = array();
1535

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

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

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

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

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

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

    
1587

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

    
1597
  $bibliography_settings = get_bibliography_settings(true);
1598

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

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

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

    
1635
  // --- Registrations --- //
1636
  $form['registrations'] = array(
1637
    '#type' => 'fieldset',
1638
    '#title' => t('Registrations'),
1639
    '#collapsible' => FALSE,
1640
    '#collapsed' => FALSE,
1641
  );
1642
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1643
    '#type' => 'checkbox',
1644
    '#title' => t('Use the persistent http identifier as link'),
1645
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1646
    '#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.'),
1647
  );
1648

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1850

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

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

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

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

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

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

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

    
1930
  return $form;
1931
}
1932

    
1933
/**
1934
 * @todo document this function.
1935
 */
1936
function cdm_settings_layout_taxon() {
1937
  $collapsed = FALSE;
1938
  $form = array();
1939

    
1940
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1941

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

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

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

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

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

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

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

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

    
2035
  // ---- PROFILE PICTURE ----//
2036

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

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

    
2051
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2052

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

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

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

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

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

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

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

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

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

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

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

    
2177
  if (isset($profile_feature_tree->root->childNodes)) {
2178

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

    
2221

    
2222
    $feature_list_layout_settings_disabled = FALSE;
2223

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

    
2231
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2232

    
2233
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2234

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

    
2239
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2240

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

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

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

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

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

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

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

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

    
2328
      }
2329
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2330
    }
2331
  }
2332

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

    
2358

    
2359

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

    
2378
  );
2379

    
2380
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2381

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

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

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

    
2406

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

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

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

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

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

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

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

    
2506
</pre>'),
2507
  );
2508

    
2509

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

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

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

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

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

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

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

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

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

    
2588
  $name_relationship_type_options = cdm_vocabulary_as_option(
2589
      UUID_NAME_RELATIONSHIP_TYPE,
2590
      '_cdm_relationship_type_term_inverse_label_callback',
2591
      false,
2592
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2593
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2594
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2595
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2596
  );
2597
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2598
    '#type' => 'checkboxes',
2599
    '#title' => t('Name relationship types') . ':',
2600
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2601
    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') . '.',
2602
    '#options' => $name_relationship_type_options,
2603
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2604
  );
2605

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

    
2616
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2617

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

    
2626
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2627
      '#type' => 'textfield',
2628
      '#title' => t('Number of records per page') . ':',
2629
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2630
  );
2631

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

    
2639

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

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

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

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

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

    
2706
/**
2707
 * @todo document this function.
2708
 */
2709
function cdm_settings_layout_search() {
2710

    
2711
  $form = array();
2712

    
2713
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2714

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

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

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

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

    
2752
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2753
    '#type' => 'textfield',
2754
    '#title' => t('Results per page') . ':',
2755
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2756
    '#description' => t('Number of results to display per page.'),
2757
  );
2758

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

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

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

    
2783
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2784
  );
2785

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

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

    
2803
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2804
    );
2805
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2806
        '#type' => 'textfield',
2807
        '#title' => t('Webservice URL for blast search') . ':',
2808
        '#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)
2809

    
2810
        '#description' => t('Enter the webservice URL for blast search'),
2811
    );
2812

    
2813
  // --- SEARCH TAXA GALLERY ---- //
2814
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2815
  $collapsed = FALSE;
2816
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2817
  $form_title = 'Taxa Search thumbnails';
2818
  $form_description = 'Search results may show thumbnails. ';
2819
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2820

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

    
2830
/**
2831
 * @todo document this function.
2832
 */
2833
function cdm_settings_layout_media() {
2834

    
2835
  $form = array();
2836

    
2837
  $form['media_settings'] = array(
2838
    '#type' => 'fieldset',
2839
    '#title' => t('Media settings'),
2840
    '#collapsible' => FALSE,
2841
    '#collapsed' => FALSE,
2842
    '#description' => 'This section covers layout settings for media pages.'
2843
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2844
  );
2845

    
2846
  $form['media_settings']['image_gallery_viewer'] = array(
2847
    '#type' => 'select',
2848
    '#title' => t('Image viewer') . ':',
2849
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2850
    '#options' => array(
2851
      'default' => t('Standard image viewer'),
2852
      'fsi' => t('FSI viewer (requires FSI server!)'),
2853
    ),
2854
  );
2855

    
2856
  // --- STANDARD_IMAGE_VIEWER ---- //
2857
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2858
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2859
      '#type' => 'fieldset',
2860
      '#tree' => true,
2861
      '#title' => t('Standard image viewer settings'),
2862
      '#collapsible' => FALSE,
2863
      '#collapsed' => FALSE,
2864
      );
2865

    
2866
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2867
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2868
      '#type' => 'checkbox',
2869
      '#title' => 'Show media representations',
2870
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2871

    
2872
    );
2873
  }
2874

    
2875

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

    
2885
/**
2886
 * GEOSERVICE and Map settings.
2887
 */
2888
function cdm_settings_geo($form, &$form_state) {
2889

    
2890
  $current_geoserver_settings = get_edit_map_service_settings();
2891
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2892

    
2893

    
2894
  $form = array();
2895

    
2896
  $dummy_distribution_query = NULL;
2897
  if($map_distribution['map_type'] != 1){
2898
    // we need to apply a dummy query since the map service requires for image maps
2899
    // at least as and ad to be defined
2900
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2901
  }
2902

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

    
2919
  /*
2920
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2921
  );
2922
  */
2923

    
2924
  /*
2925
   * GEO SERVER
2926
   */
2927
  $form['edit_map_server'] = array(
2928
    '#type' => 'fieldset',
2929
    '#tree' => true,
2930
    '#title' => t('EDIT map service'),
2931
    '#collapsible' => TRUE,
2932
    '#collapsed' => TRUE,
2933
    '#description' => t('Configuration and selection of your geo server.
2934
      The Geo Server is responsible for generating the maps.'),
2935
  );
2936

    
2937
  $form['edit_map_server']['base_uri'] = array(
2938
    '#type' => 'select',
2939
    '#title' => t('EDIT map service') . ':',
2940
    '#default_value' => $current_geoserver_settings['base_uri'],
2941
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2942
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2943
  );
2944
  $form['edit_map_server']['version'] = array(
2945
      '#type' => 'select',
2946
      '#title' => t('Version') . ':',
2947
      '#default_value' => $current_geoserver_settings['version'],
2948
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2949
      '#description' => t('The version of the EDIT map services'),
2950
  );
2951

    
2952
  /*
2953
   * MAP SETTINGS
2954
   */
2955

    
2956
  $form[CDM_MAP_DISTRIBUTION] = array(
2957
    '#type' => 'fieldset',
2958
    '#tree' => TRUE,
2959
    '#title' => t('Maps settings'),
2960
    '#collapsible' => TRUE,
2961
    '#collapsed' => TRUE,
2962
    '#description' => t('General configuration for all map types.'),
2963
  );
2964

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

    
2982
  /*
2983
   * settings for the distribution map are used also for specimens map!!!!
2984
   */
2985

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

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

    
3014
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3015
    '#type' => 'select',
3016
    '#title' => 'Max zoom level',
3017
    '#default_value' => $map_distribution['maxZoom'],
3018
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3019
  );
3020

    
3021
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3022
    '#type' => 'checkbox',
3023
    '#title' => 'Display area labels',
3024
    '#default_value' => $map_distribution['show_labels'],
3025
    '#description' => t('The map will show name labels of the areas'),
3026
  );
3027

    
3028
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3029
    '#type' => 'textfield',
3030
    '#title' => 'Map caption',
3031
    '#default_value' => $map_distribution['caption'],
3032
    '#description' => t('The caption will be shown below the map.'),
3033
  );
3034

    
3035
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3036
    '#type' => 'textfield',
3037
    '#title' => 'Distribution layer opacity',
3038
    '#default_value' => $map_distribution['distribution_opacity'],
3039
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3040
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3041
  );
3042

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

    
3061
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3062
    '#type' => 'textfield',
3063
    '#title' => 'Width',
3064
    '#default_value' => $map_distribution['image_map']['width'],
3065
    '#maxlength' => 4,
3066
    '#size' => 4,
3067
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3068
  );
3069

    
3070
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3071
    '#type' => 'textfield',
3072
    '#title' => 'Background layer',
3073
    '#default_value' => $map_distribution['image_map']['base_layer'],
3074
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3075
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3076
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3077
    )),
3078
  );
3079

    
3080
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3081
    '#type' => 'textfield',
3082
    '#title' => 'Background color',
3083
    '#default_value' => $map_distribution['image_map']['bg_color'],
3084
  );
3085

    
3086
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3087
    '#type' => 'textfield',
3088
    '#title' => 'Background layer style',
3089
     // Only line color by now.
3090
    '#default_value' => $map_distribution['image_map']['layer_style'],
3091
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3092
  );
3093

    
3094
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3095
      '#type' => 'textfield',
3096
      '#title' => 'Projection',
3097
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3098
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3099
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3100
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3101
  );
3102

    
3103

    
3104
  // --- OpenLayers Settings --- //
3105
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3106
    '#type' => 'fieldset',
3107
    '#title' => 'OpenLayers settings',
3108
    '#tree' => TRUE,
3109
    '#collapsible' => TRUE,
3110
    '#collapsed' => !$open_layers_is_enabled,
3111
    '#description' => '',
3112
  );
3113

    
3114

    
3115
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3116
      '#type' => 'checkbox',
3117
      '#title' => 'Display outside max extent',
3118
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3119
      '#description' => t('Allows the map to display parts of the layers which are outside
3120
         the max extent if the aspect ratio of the map and of the baselayer
3121
         are not equal.'),
3122
  );
3123

    
3124

    
3125
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3126
      '#type' => 'checkbox',
3127
      '#title' => 'Show Layer Switcher',
3128
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3129
      '#description' => 'The Layer Switcher control displays a table of contents
3130
      for the map.  This allows the user interface to switch between
3131
      base layers and to show or hide overlays.  By default the switcher is
3132
      shown minimized on the right edge of the map, the user may expand it
3133
      by clicking on the handle.',
3134
  );
3135

    
3136
  if (!$open_layers_is_enabled) {
3137
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3138
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3139
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3140
  }
3141

    
3142
  // The default layer must always be enabled
3143
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3144
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3145

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

    
3176
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3177
    '#type' => 'checkboxes_preferred',
3178
    '#title' => 'Base Layers',
3179
    '#options' => $baselayer_options,
3180
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3181
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3182
  );
3183

    
3184
  $google_maps_api_key = null;
3185
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3186
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3187
  }
3188
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3189
    '#type' => 'textfield',
3190
    '#title' => 'Google Maps API Key',
3191
    '#default_value' => $google_maps_api_key,
3192
    '#description' => 'In order to use any of the Google map layers you need to provide 
3193
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3194
  );
3195

    
3196
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3197
    $map_distribution['openlayers']['custom_wms_base_layer'],
3198
    'Custom WMS base layer',
3199
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3200
    true // add projection settings
3201
    );
3202

    
3203
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3204
    $map_distribution['openlayers']['wms_overlay_layer'],
3205
    'WMS overlay layer',
3206
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3207
                You can actually combine multiple layers for this overlay. 
3208
                For details please refer to the wms query parameter <code>Layers</code> .'
3209
  );
3210

    
3211
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3212
    '#type' => 'checkbox',
3213
    '#title' => 'Enable overlay layer',
3214
    '#weight' => -100,
3215
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3216
  );
3217

    
3218
  /*
3219
   * Map Legend
3220
   */
3221
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3222
    '#type' => 'fieldset',
3223
    '#title' => 'Map legend',
3224
    '#tree' => TRUE,
3225
    '#collapsible' => TRUE,
3226
    '#collapsed' => TRUE,
3227
    '#description' => 'Configure the maps legend.',
3228
  );
3229

    
3230
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3231
    '#type' => 'checkbox',
3232
    '#title' => 'Display a map legend',
3233
    '#default_value' => $map_distribution['legend']['show'],
3234
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3235
  );
3236

    
3237
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3238
    '#type' => 'textfield',
3239
    '#title' => 'Legend opacity',
3240
    '#default_value' => $map_distribution['legend']['opacity'],
3241
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3242
                         to 0.0 will be not much visible.',
3243
  );
3244

    
3245
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3246
    '#type' => 'textfield',
3247
    '#title' => 'Font size',
3248
    '#default_value' => $map_distribution['legend']['font_size'],
3249
    '#description' => 'Font size in pixels.',
3250
  );
3251

    
3252
  $fontStyles = array(
3253
    0 => "plane",
3254
    1 => "italic",
3255
  );
3256
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3257
    '#type' => 'select',
3258
    '#title' => 'Available font styles',
3259
    '#default_value' => $map_distribution['legend']['font_style'],
3260
    '#options' => $fontStyles,
3261
    '#description' => 'Select a font style for the map legend.',
3262
  );
3263

    
3264
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3265
    '#type' => 'textfield',
3266
    '#title' => 'Icon width',
3267
    '#default_value' => $map_distribution['legend']['icon_width'],
3268
    '#description' => 'Legend icon width in pixels.',
3269
  );
3270
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3271
    '#type' => 'textfield',
3272
    '#title' => 'Icon height',
3273
    '#default_value' => $map_distribution['legend']['icon_height'],
3274
    '#description' => 'Legend icon height in pixels.',
3275
  );
3276

    
3277
  // @WA: D7 form api does not support reset buttons,
3278
  // so to mimic the D5 reset button we add one like this.
3279
  $form['actions']['reset'] = array(
3280
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3281
    '#weight' => 1000,
3282
  );
3283

    
3284
  return system_settings_form($form);
3285
}
3286

    
3287
/**
3288
 * @param $default_settings
3289
 * @param $title
3290
 * @param $description
3291
 * @param bool $add_projection_settings
3292
 * @return array
3293
 */
3294
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3295
{
3296
  $form_elements = array(
3297
    '#type' => 'fieldset',
3298
    '#title' => $title,
3299
    '#tree' => TRUE,
3300
    '#collapsible' => FALSE,
3301
    '#collapsed' => FALSE,
3302
    '#description' => $description,
3303
  );
3304

    
3305
  $form_elements['name'] = array(
3306
    '#type' => 'textfield',
3307
    '#title' => 'Layer name',
3308
    '#default_value' => $default_settings['name'],
3309
    '#description' => 'A arbitrary name for the layer.',
3310
  );
3311
  $form_elements['url'] = array(
3312
    '#type' => 'textfield',
3313
    '#title' => 'WMS url',
3314
    '#default_value' => $default_settings['url'],
3315
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3316
  );
3317
  $form_elements['untiled'] = array(
3318
    '#type' => 'checkbox',
3319
    '#title' => 'Untiled',
3320
    '#default_value' => $default_settings['untiled'],
3321
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3322
  );
3323
  $form_elements['params'] = array(
3324
    '#type' => 'textarea',
3325
    '#title' => 'WMS parameters',
3326
    '#element_validate' => array('form_element_validate_json'),
3327
    '#default_value' => $default_settings['params'],
3328
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3329
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3330
      . '), entered in valid JSON. For example:
3331
<pre> {
3332
  "Layers": "topp:em_tiny_jan2003",
3333
  "Format": "image/png",
3334
  "BGCOLOR": "0xe0faff"
3335
}
3336
</pre>
3337
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3338
  );
3339

    
3340
  if($add_projection_settings){
3341

    
3342
    $form_elements['projection'] = array(
3343
      '#type' => 'textfield',
3344
      '#title' => 'Projection',
3345
      '#default_value' => $default_settings['projection'],
3346
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3347
    );
3348
    $form_elements['proj4js_def'] = array(
3349
      '#type' => 'textfield',
3350
      '#maxlength' => 256,
3351
      '#title' => 'proj4js definition',
3352
      '#default_value' => $default_settings['proj4js_def'],
3353
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3354
              The definitions for
3355
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3356
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3357
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3358
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3359
              choose to display the proj4js definition string.
3360
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3361
              <pre>
3362
  +a         Semimajor radius of the ellipsoid axis
3363
  +alpha     ? Used with Oblique Mercator and possibly a few others
3364
  +axis      Axis orientation (new in 4.8.0)
3365
  +b         Semiminor radius of the ellipsoid axis
3366
  +datum     Datum name (see `proj -ld`)
3367
  +ellps     Ellipsoid name (see `proj -le`)
3368
  +k         Scaling factor (old name)
3369
  +k_0       Scaling factor (new name)
3370
  +lat_0     Latitude of origin
3371
  +lat_1     Latitude of first standard parallel
3372
  +lat_2     Latitude of second standard parallel
3373
  +lat_ts    Latitude of true scale
3374
  +lon_0     Central meridian
3375
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3376
  +lon_wrap  Center longitude to use for wrapping (see below)
3377
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3378
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3379
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3380
  +pm        Alternate prime meridian (typically a city name, see below)
3381
  +proj      Projection name (see `proj -l`)
3382
  +south     Denotes southern hemisphere UTM zone
3383
  +to_meter  Multiplier to convert map units to 1.0m
3384
  +towgs84   3 or 7 term datum transform parameters (see below)
3385
  +units     meters, US survey feet, etc.
3386
  +vto_meter vertical conversion to meters.
3387
  +vunits    vertical units.
3388
  +x_0       False easting
3389
  +y_0       False northing
3390
  +zone      UTM zone
3391
              </pre>
3392
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3393
    );
3394
    $form_elements['max_extent'] = array(
3395
      '#type' => 'textfield',
3396
      '#title' => 'Maximum extent',
3397
      '#default_value' => $default_settings['max_extent'],
3398
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3399
    );
3400
    $form_elements['units'] = array(
3401
      '#type' => 'textfield',
3402
      '#title' => 'Units',
3403
      '#default_value' => $default_settings['units'],
3404
      '#description' => 'The layer map units.  Defaults to null.  Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’.  Normally taken from the projection.  Only required if both map and layers do not define a projection, or if they define a projection which does not define units.'
3405
    );
3406

    
3407
  }
3408
  return $form_elements;
3409
}
3410

    
3411

    
3412
/**
3413
 * @todo document this function.
3414
 */
3415
function cdm_settings_cache() {
3416

    
3417
  $form = array();
3418

    
3419
  $form['cache_settings'] = array(
3420
    '#type' => 'fieldset',
3421
    '#title' => t('Cache Settings'),
3422
    '#collapsible' => FALSE,
3423
    '#collapsed' => FALSE,
3424
    '#description' => t('<p>When caching is enabled all single taxon sites are
3425
      stored in an internal drupal cache doing the portal response of taxa pages
3426
      faster. This is possible because the sites are loaded from the cache and
3427
      are not created from scratch.</p>'),
3428
  );
3429

    
3430
  $form['cache_settings']['cdm_webservice_cache'] = array(
3431
    '#type' => 'checkbox',
3432
    '#title' => t('<strong>Enable caching</strong>'),
3433
    '#options' => cdm_help_general_cache(),
3434
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3435
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3436
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3437
       application the changes will be not visible till the cache is erased.
3438
       Therefore developers should deactived this feature when they are working
3439
       on the CDM Dataportal Module.</p>'),
3440
  );
3441

    
3442
  $form['cache_settings']['cdm_run_cache'] = array(
3443
    '#markup' => cdm_view_cache_site(),
3444
  );
3445

    
3446
  // @WA: D7 form api does not support reset buttons,
3447
  // so to mimic the D5 reset button we add one like this.
3448
  $form['actions']['reset'] = array(
3449
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3450
    '#weight' => 1000,
3451
  );
3452
  return system_settings_form($form);
3453
}
3454

    
3455
/**
3456
 * Walk and cache all taxon pages.
3457
 */
3458
function cdm_view_cache_site() {
3459

    
3460
  $out = '';
3461

    
3462
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3463

    
3464
  $request_params = array();
3465
  $request_params['class'] = "Taxon";
3466

    
3467
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3468
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3469
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3470

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

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

    
3480
  // Comment @WA: A form within a form is not valid html and not needed here.
3481
  // Also, it would be recommended just to include this part of the form in the
3482
  // rest of the form array in cdm_settings_cache().
3483
  // $out .= '<form id="cache_site">';
3484
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3485
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3486
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3487
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3488
  // $out .= '</form>';
3489
  $out .= '</div>';
3490
  /*
3491
  foreach($taxonPager->records as $taxon){
3492
    cdm_dataportal_taxon_view($uuid);
3493
  }
3494
  */
3495
  return $out;
3496
}
3497

    
3498

    
3499
function cdm_settings_layout_taxon_submit($form, &$form_state){
3500
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3501
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3502
    if(is_object($file)){
3503
      $file->status = FILE_STATUS_PERMANENT;
3504
      file_save($file);
3505
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3506
    }
3507
  }
3508
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3509
  $tab_lables_modified = serialize(get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT)) != serialize($form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3510
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3511
  if($tab_lables_modified || $tabs_enabled_modified){
3512
    // we first need to set the variable to persist the changes setting
3513
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3514
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3515
    menu_rebuild();
3516
  }
3517
}
3518

    
3519
function cdm_settings_layout_search_submit($form, &$form_state){
3520
  // the visibility of media thumbnails also affects the ui of the search results
3521
  // so reset the according session variable
3522
  //    1. in order to give the user immediate
3523
  //       feedback on potential setting changes
3524
  //    2. let refresh the default if it has changed
3525
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3526
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3527
  }
3528
}
3529

    
3530
/**
3531
 * Form validation handler for cdm_settings_general
3532
 *
3533
 * @param $form
3534
 * @param $form_state
3535
 */
3536
function cdm_settings_general_validate($form, &$form_state) {
3537

    
3538
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3539
    $form_state['values']['cdm_webservice_url'] .= '/';
3540
  }
3541

    
3542
}
3543

    
3544
/**
3545
 * Form submit handler for settings general.
3546
 *
3547
 * tasks performed:
3548
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3549
 *
3550
 * @param $form
3551
 * @param $form_state
3552
 */
3553
function cdm_settings_general_submit($form, &$form_state){
3554
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3555
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3556
  unset($_SESSION['cdm_login']);
3557
}
3558

    
3559
/**
3560
 * Form validation handler for cdm_settings_cache
3561
 */
3562
function cdm_settings_cache_validate($form, &$form_state) {
3563
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3564
    cache_clear_all(NULL, 'cache_cdm_ws');
3565
    // Better clear secref_cache since I can not be sure if the cache has not
3566
    // be used during this response.
3567
    cdm_api_secref_cache_clear();
3568
  }
3569

    
3570
}
3571

    
3572
/**
3573
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3574
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3575
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3576
 *  - version: the version, e.g.: v1.1
3577
 *
3578
 * @return array
3579
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3580
 */
3581
function get_edit_map_service_settings() {
3582

    
3583
  $settings = variable_get('edit_map_server', array(
3584
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3585
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3586
      )
3587
  );
3588

    
3589
  return $settings;
3590
}
3591

    
3592
/**
3593
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3594
 *
3595
 * @return string
3596
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3597
 */
3598
function get_edit_map_service_full_uri() {
3599
  $settings = get_edit_map_service_settings();
3600
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3601
}
3602

    
3603

    
3604
/**
3605
 * Returns the version number of the currently selected edit mapserver as a float
3606
 *
3607
 * @return float
3608
 *   The version number of the currently selected edit mapserver as a float.
3609
 *   Returns 0 on error.
3610
 */
3611
function get_edit_map_service_version_number() {
3612

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

    
3615
  $settings = get_edit_map_service_settings();
3616
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3617
  if (isset($matches[1])) {
3618
    // Convert string to float.
3619
    $version = 1 + $matches[1][0] - 1;
3620
    return $version;
3621
  }
3622
  else {
3623
    // Report error.
3624
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3625
        array(
3626
          '!version' => $settings['version'],
3627
          'warning')
3628
        )
3629
      );
3630
    return 0;
3631
  }
3632
}
3633

    
3634
/**
3635
 * Returns the array of selected items in a options array
3636
 *
3637
 * @param array $options
3638
 *   An options array as generated by a form element like checkoxes, select ...,
3639
 */
3640
function get_selection($options) {
3641
  $selection = array();
3642
  foreach ($options as $key=>$val) {
3643
    if (!empty($val)) {
3644
      $selection[] = $val;
3645
    }
3646
  }
3647
  return $selection;
3648
}
3649

    
3650

    
3651
/**
3652
 * Implements hook_element_info().
3653
 *
3654
 * Allows modules to declare their own Form API element types and specify their default values.
3655
 *
3656
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3657
 */
3658
function cdm_dataportal_element_info() {
3659
  $type['checkboxes_preferred'] = array(
3660
    '#input' => TRUE,
3661
    '#process' => array('checkboxes_preferred_expand'),
3662
    '#after_build' => array('checkboxes_preferred_after_build'),
3663
    '#theme' => array('checkboxes_preferred'),
3664
    // '#theme_wrapper' => array('form_element'),
3665
  );
3666
  return $type;
3667
}
3668

    
3669
/**
3670
 * #process callback function for the custom form element type 'checkbox_preferred'
3671
 *
3672
 *
3673
 */
3674
function checkboxes_preferred_expand($element, &$form_state, $form) {
3675

    
3676
  // First of all create checkboxes for each of the elements
3677
  $element = form_process_checkboxes($element);
3678

    
3679
  // compose the element name
3680
  $parents = array();
3681
  array_deep_copy($element['#parents'], $parents);
3682
  $parents[count($parents) -1 ] .= '_preferred';
3683
  $element_name = $parents[0];
3684
  for ($i=1; $i < count($parents); $i++){
3685
    $element_name .= '[' . $parents[$i] . ']';
3686
  }
3687

    
3688
  $children = element_children($element);
3689

    
3690
  $element['table_start'] = array(
3691
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3692
    '#weight' => -1,
3693
  );
3694

    
3695
  // prepare first part each of the table rows which contains the row label
3696
  $weight = 0;
3697
  foreach ($children as $key) {
3698
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3699
    $element[$key]['#weight'] = $weight;
3700
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3701
    $element[$key]['#suffix'] = '</td>';
3702
    unset($element[$key]['#title']);
3703
    $weight += 2;
3704
  }
3705
  $weight = 0;
3706

    
3707
  // add a radio button to each of the checkboxes, the
3708
  // check boxes have already been created at the beginning
3709
  // of this function
3710
  if (count($element['#options']) > 0) {
3711
    foreach ($element['#options'] as $key => $choice) {
3712
      if (!isset($element[$key . '_preferred'])) {
3713
        $element[$key . '_preferred'] = array(
3714
          '#type' => 'radio',
3715
          '#name' => $element_name,
3716
          '#return_value' => check_plain($key),
3717
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3718
          '#attributes' => $element['#attributes'],
3719
          '#parents' => $element['#parents'],
3720
          // '#spawned' => TRUE,
3721
          '#weight' => $weight + 1,
3722
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3723
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3724
        );
3725
      }
3726
      $weight += 2;
3727
    }
3728
  }
3729

    
3730
  // end the table
3731
  $element['table_end'] = array(
3732
    '#markup' => '</table>',
3733
    '#weight' => $weight++,
3734
  );
3735

    
3736
  return $element;
3737
}
3738

    
3739
/**
3740
 * Theme function for the custom form field 'checkboxes_preferred'.
3741
 */
3742
function theme_checkboxes_preferred($variables) {
3743
  $element = $variables['element'];
3744
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3745
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3746
  $out .= drupal_render_children($element);
3747
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3748
  $out .= '</div>';
3749
  return $out;
3750
}
3751

    
3752
/**
3753
 * Callback for checkboxes preferred for widget which will
3754
 * be called after the form or element is built. The call
3755
 * back is configured in the form element by setting it as
3756
 * #after_build parameter.
3757
 *
3758
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3759
 *
3760
 * @param $element
3761
 *   Nested array of form elements that comprise the form.
3762
 * @param $form_state
3763
 *   A keyed array containing the current state of the form.
3764
 *   This includes the current persistent storage data for the form.
3765
 *   Additional information, like the sanitized $_POST data,
3766
 *   is also accumulated here in $form_state['input']
3767
 *
3768
 * @return the modified form array
3769
 */
3770
function checkboxes_preferred_after_build($element, &$form_state) {
3771

    
3772
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3773

    
3774
  if ($_POST && count($_POST) > 0) {
3775
    // TODO use  $form_state['input'] instead of POST !!!
3776
    // First pass of form processing.
3777
    $parents = array();
3778
    array_deep_copy($element['#parents'], $parents);
3779
    $parents[count($parents) - 1] .= '_preferred';
3780
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3781
    $element['#value']['PREFERRED'] = $preferred_layer;
3782
//     $form_state[$parent_id] = $element['#value'];
3783
//     $form_state['values']['baselayers'] = $element['#value'];
3784
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3785
    $form_state_element_values = $element['#value'];
3786
  }
3787
  else {
3788
    // Second pass of form processing.
3789
    $preferred_layer = $element['#value']['PREFERRED'];
3790
  }
3791

    
3792
  // Also set the chosen value (not sure if this is good Drupal style ....).
3793
  foreach ($children = element_children($element) as $key) {
3794
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3795
      $element[$key]['#value'] = $preferred_layer;
3796
    }
3797
  }
3798
  // The default layer must always be enabled.
3799
  $element[$preferred_layer]['#value'] = $preferred_layer;
3800

    
3801
  return $element;
3802
}
3803

    
3804
function radios_prepare_options_suffix(&$elements){
3805

    
3806
  $childrenKeys = element_children($elements);
3807
  foreach($childrenKeys as $key){
3808
    if(!is_array($elements[$key]['#theme_wrappers'])){
3809
      $elements[$key]['#theme_wrappers'] = array();
3810
    }
3811
    if(isset($elements['#options_suffixes'][$key])){
3812
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3813
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3814
    }
3815
  }
3816
  return $elements;
3817

    
3818
}
3819

    
3820
/**
3821
 * TODO
3822
 * @param unknown $variables
3823
 */
3824
function theme_radio_options_suffix($variables) {
3825
  $element = $variables['element'];
3826
  if(isset($element['#options_suffix'])) {
3827
    $element['#children'] .= $element['#options_suffix'];
3828
  }
3829
  return $element['#children'];
3830
}
3831

    
3832

    
3833
/**
3834
 * Element validate callback for text field and arrays containing json.
3835
 *
3836
 * @param $element
3837
 *   The form element to validate
3838
 * @param $form_state
3839
 *   A keyed array containing the current state of the form.
3840
 * @param $form
3841
 *   Nested array of form elements that comprise the form.
3842
 */
3843
function form_element_validate_json($element, &$form_state, $form) {
3844
   if (!empty($element['#value'])) {
3845
     json_decode($element['#value']);
3846
     if(json_last_error() != JSON_ERROR_NONE){
3847
       form_error($element,
3848
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3849
         . l('JSONLint', 'http://jsonlint.com/')
3850
       );
3851
     }
3852
   }
3853
}
3854

    
3855
/**
3856
 * Form submission handler for textareas and textfields containing JSON.
3857
 *
3858
 * The contained JSON will be converted into an php array
3859
 * or object and will be stored in the variables as such.
3860
 *
3861
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3862
 *
3863
 * @param $form
3864
 *   Nested array of form elements that comprise the form.
3865
 * @param $form_state
3866
 *   A keyed array containing the current state of the form.
3867
 *
3868
 */
3869
function submit_json_as_php_array($form, &$form_state) {
3870
  if (is_array($form['#json_elements'])) {
3871
    foreach ($form['#json_elements'] as $element){
3872
      if (trim($form_state['values'][$element])) {
3873
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3874
      } else {
3875
        $form_state['values'][$element] = NULL;
3876
      }
3877
    }
3878
  }
3879
}
(18-18/18)