Project

General

Profile

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

    
7

    
8
  // TODO Genus UUID.
9

    
10
const CDM_NAME_PAGE_AUTOREDIRECT = 'cdm_name_page_autoredirect';
11

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

    
17
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
18

    
19
  define('NO_SORT', -1);
20
  define('SORT_HIERARCHICAL', 9);
21

    
22
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
23

    
24
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
25
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
26

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

    
40
  define('CDM_SEARCH_BLAST_SERVICE_URI', 'http://bgbm-import:9001/api/sequence');
41
  define('CDM_SEARCH_BLAST_ENABLED', 0);
42
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
43

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

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

    
56
  define('ANNOTATION_TYPES_VISIBLE', 'annotations_types_as_footnotes');
57
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
58

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

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

    
77

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

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

    
123

    
124
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
125

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

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

    
137
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
138
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
139

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

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

    
172

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

    
186
$taxon_tab_options = get_taxon_tabs_list();
187
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
188

    
189
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
190

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

    
201
}
202

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

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

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

    
380
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
381

    
382
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
383
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
384
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
385

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
731
  // ---- DEFAULTS settings
732

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

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

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

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

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

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

    
909
  $default_theme = variable_get('theme_default', NULL);
910

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

    
935
  // ---- END of DEFAULTS
936

    
937
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
938

    
939
  $feature_block_setting = null;
940

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

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

    
961
  return $feature_block_setting;
962
}
963

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

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

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

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

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

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

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

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

    
1102
}
1103

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1465

    
1466

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

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

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

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

    
1513
  $form['#submit'][] = 'cdm_settings_general_submit';
1514

    
1515
  return system_settings_form($form);
1516
}
1517

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

    
1528

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

    
1537
  $form = array();
1538

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

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

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

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

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

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

    
1590

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

    
1600
  $bibliography_settings = get_bibliography_settings(true);
1601

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

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

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

    
1638
  // --- Name page autoredirect feature --- //
1639
  $form['name_page'] = array(
1640
    '#type' => 'fieldset',
1641
    '#title' => t('Name page'),
1642
    '#collapsible' => FALSE,
1643
    '#collapsed' => FALSE,
1644
  );
1645
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1646
    '#type' => 'checkbox',
1647
    '#title' => 'Always redirect to taxon',
1648
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1649
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1650
    Depending on the context from which a user navigates to the name page the data portal chooses to show the name page or it redirects to the related taxon if there is only one. 
1651
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1652
  );
1653

    
1654
  // --- Registrations --- //
1655
  $form['registrations'] = array(
1656
    '#type' => 'fieldset',
1657
    '#title' => t('Registrations'),
1658
    '#collapsible' => FALSE,
1659
    '#collapsed' => FALSE,
1660
  );
1661
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1662
    '#type' => 'checkbox',
1663
    '#title' => t('Use the persistent http identifier as link'),
1664
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1665
    '#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.'),
1666
  );
1667

    
1668
  // ---- Taxon Name Rendering --- //
1669
  $form['taxon_name'] = array(
1670
      '#type' => 'fieldset',
1671
      '#title' => t('Taxon name display'),
1672
      '#collapsible' => TRUE,
1673
      '#collapsed' => TRUE,
1674
      '#description' => t('The display of taxon names is configured by two parts.
1675
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1676
          The name parts are defined in the <stong>part definitions</strong>'),
1677
  );
1678

    
1679
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1680
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1681
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1682
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1683

    
1684
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1685
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1686
    $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.)';
1687
  } else if($is_custom_part_definition){
1688
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1689
  } else  {
1690
    $which_version_message = '(These are the default part definition.)';
1691
  }
1692

    
1693
  $diff_viewer_markup = '';
1694
  if($is_custom_part_definition){
1695
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1696
  }
1697

    
1698
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1699
    . $which_version_message
1700
    . '</div>'
1701
    . $diff_viewer_markup;
1702

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

    
1792
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1793
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1794
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1795
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1796
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1797

    
1798
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1799
    $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.)';
1800
  } else if($is_custom_render_template){
1801
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1802
  } else {
1803
    $which_version_message = '(These are the default render templates.)';
1804
  }
1805

    
1806
  $diff_viewer_markup = '';
1807
  if($is_custom_render_template){
1808
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1809
  }
1810

    
1811
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1812
    . $which_version_message
1813
    . '</div>'
1814
    . $diff_viewer_markup;
1815

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

    
1856
  // @WA: D7 form api does not support reset buttons,
1857
  // so to mimic the D5 reset button we add one like this.
1858
  $form['actions']['reset'] = array(
1859
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1860
    '#weight' => 1000,
1861
  );
1862

    
1863
  $form['#submit'] = array('submit_json_as_php_array');
1864
  // #json_elements especially defined for submit_json_as_php_array()
1865
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1866
  return system_settings_form($form);
1867
}
1868

    
1869

    
1870
/**
1871
 * @param $form_name
1872
 * @param $form_title
1873
 * @param $collapsed
1874
 * @param string $form_description
1875
 *   The description for the fieldset of the gallery setting.
1876
 * @return mixed
1877
 */
1878
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1879
  $form[$form_name] = array(
1880
    '#type' => 'fieldset',
1881
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1882
    '#collapsible' => TRUE,
1883
    '#collapsed' => $collapsed,
1884
    '#tree' => TRUE,
1885
    '#description' => $form_description,
1886
  );
1887

    
1888
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1889
  $gallery_settings = variable_get($form_name, $default_values);
1890
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1891
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1892
    /*
1893
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1894
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1895
    '#type' => 'textfield',
1896
    '#title' => t('Search Page Size'),
1897
    '#default_value' => $test,
1898
    '#description' => t('Number of Names to display per page in search results.')
1899
    );
1900
    */
1901
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1902
      '#type' => 'checkbox',
1903
      '#title' => t('Show media thumbnails for accepted taxa'),
1904
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1905
    );
1906

    
1907
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1908
      '#type' => 'checkbox',
1909
      '#title' => t('Show media thumbnails for synonyms'),
1910
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1911
      '#description' => '',
1912
    );
1913
  }
1914

    
1915
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1916
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1917
    '#type' => 'checkbox',
1918
    '#title' => t('Show captions under thumbnails'),
1919
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1920
    '#description' => '',
1921
  );
1922

    
1923
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1924
    '#type' => 'textfield',
1925
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1926
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1927
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1928
  );
1929

    
1930
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1931
    '#type' => 'textfield',
1932
    '#title' => t('Number of columns') . ':',
1933
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1934
    '#description' => t('Group the thumbnails in columns: select how many
1935
      columns the gallery should display.'),
1936
  );
1937

    
1938
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1939
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1940
      '#type' => 'textfield',
1941
      '#title' => t('Maximum number of rows') . ':',
1942
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1943
      '#description' => t('You can group the thumbnails in rows, select in how
1944
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1945
        If you want an unlimited number of rows please set to 0.'),
1946
    );
1947
  }
1948

    
1949
  return $form;
1950
}
1951

    
1952
/**
1953
 * @return array
1954
 *   The form structure.
1955
 */
1956
function cdm_settings_layout_taxon() {
1957
  $collapsed = FALSE;
1958
  $form = array();
1959

    
1960
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1961

    
1962
  // --------- TABBED TAXON ------- //
1963
  $form['taxon_tabs'] = array(
1964
    '#type' => 'fieldset',
1965
    '#title' => t('Taxon tabs'),
1966
    '#collapsible' => TRUE,
1967
    '#collapsed' => TRUE,
1968
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1969
  );
1970

    
1971
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1972
    '#type' => 'checkbox',
1973
    '#title' => t('Tabbed taxon page'),
1974
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1975
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1976
  );
1977

    
1978
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1979
    '#type' => 'checkbox',
1980
    '#title' => t('Synonymy as tab'),
1981
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1982
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1983
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1984
  );
1985

    
1986
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1987
    '#type' => 'checkboxes',
1988
    '#title' => t('Section/Tab visibility') . ':',
1989
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1990
    '#options' => get_taxon_options_list()
1991
  );
1992

    
1993
  // WEIGHT
1994
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1995
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1996
    '#title'  => 'Section/Tab order',
1997
    '#type' => 'fieldset',
1998
    '#collapsible' => false,
1999
    '#tree' => true,
2000
    '#description' => 'The weight value defines the order of the section/tab.'
2001
  );
2002
  // Weights range from -delta to +delta, so delta should be at least half
2003
  // of the amount of tabs present.
2004
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
2005
  foreach (get_taxon_tabs_list() as $label) {
2006
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2007
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
2008
        '#title' => $label,
2009
        '#type'  => 'weight',
2010
        '#default_value' => $taxon_tabs_weights[$key],
2011
        '#delta' => $tab_weight_delta
2012
    );
2013
  }
2014

    
2015
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
2016
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
2017
    '#title'  => 'Section/Tab label override',
2018
    '#type' => 'fieldset',
2019
    '#collapsible' => false,
2020
    '#tree' => true,
2021
    '#description' => 'Setting a label for a section/tab will override the default label. 
2022
      Please enter the label text in the default language of the portal.'
2023
  );
2024
  foreach (get_taxon_tabs_list() as $label) {
2025
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
2026
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
2027
      '#title' => $label,
2028
      '#type'  => 'textfield',
2029
      '#default_value' => $taxon_tabs_labels[$key]
2030
    );
2031
  }
2032

    
2033
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
2034
    '#type' => 'select',
2035
    '#title' => t('Default tab to display') . ':',
2036
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
2037
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
2038
    '#description' => t('<p>Select the default tab to display when visiting a
2039
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
2040
      <strong>Note:</strong> After performing a search and clicking in any
2041
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
2042
      taxon and not the above selected tab.'),
2043
  );
2044

    
2045
  /* ======  TAXON_PROFILE ====== */
2046
  $form['taxon_profile'] = array(
2047
    '#type' => 'fieldset',
2048
    '#title' => t('Taxon profile (tab)'),
2049
    '#description' => t('<p>This section covers the settings related to the taxon
2050
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
2051
    '#collapsible' => TRUE,
2052
    '#collapsed' => TRUE,
2053
  );
2054

    
2055
  // ---- PROFILE PICTURE ----//
2056

    
2057
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2058
    '#type' => 'fieldset',
2059
    '#tree' => TRUE,
2060
    '#title' => t('Taxon profile picture'),
2061
    '#collapsible' => TRUE,
2062
    '#collapsed' => FALSE,
2063
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2064
  );
2065

    
2066
  //FIXME migrate variables:
2067
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2068
  // FIXME
2069
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2070

    
2071
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2072

    
2073
  /*
2074
   * 'show' => 1,
2075
   * 'maxextend' => 184,
2076
   * 'media_uri_query' => ''
2077
   * 'custom_placeholder_image_on' => 1,
2078
   * 'custom_placeholder_image_fid' => ''
2079
   */
2080
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2081
    '#type' => 'checkbox',
2082
    '#title' => t('Enable profile picture'),
2083
    '#description' => t('Show the profile picture.'),
2084
    '#default_value' => $taxon_profile_image_settings['show'],
2085
  );
2086

    
2087
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2088
      '#type' => 'textfield',
2089
      '#tree' => TRUE,
2090
      '#title' => t('Profile picture maximum extend'),
2091
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2092
      '#field_suffix' => 'px',
2093
      '#maxlength' => 4,
2094
      '#size' => 4,
2095
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2096
  );
2097

    
2098
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2099
      '#type' => 'textfield',
2100
      '#tree' => TRUE,
2101
      '#title' => t('Additional URI query parameter'),
2102
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2103
      '#maxlength' => 1024,
2104
      '#size' => 60,
2105
      '#description' => t('Additional query parameters to be used when requesting for the  
2106
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2107
            The query parameters will be appended to the uri of the media representation part
2108
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2109
  );
2110

    
2111
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2112
    '#type' => 'checkbox',
2113
    '#title' => t('Show the placeholder image'),
2114
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2115
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2116
  );
2117

    
2118
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2119
      '#type' => 'checkbox',
2120
      '#title' => t('Use a custom placeholder image'),
2121
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2122
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2123
  );
2124

    
2125
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2126
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2127
        '#type' => 'managed_file',
2128
        '#title' => t('Custom placeholder image file'),
2129
        '#progress_indicator' => 'bar',
2130
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2131
    //       '#name' => 'custom_placeholder_image',
2132
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2133
    );
2134

    
2135
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2136
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2137
      $url = file_create_url($profile_image_file->uri);
2138
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2139
                '#type' => 'item',
2140
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2141
      );
2142
    }
2143
  } else {
2144
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2145
      '#type' => 'hidden',
2146
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2147
    );
2148
  }
2149

    
2150
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2151
  array_unshift($options, '-- DISABLED --');
2152
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2153
    '#type' => 'select',
2154
    '#title' => t('Hide profile picture for higher ranks') . ':',
2155
    '#default_value' => variable_get('image_hide_rank', '0'),
2156
    '#options' => $options,
2157
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2158
  );
2159

    
2160
  // -- MEDIA THUMBNAILS -- //
2161
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2162
  $form_title = 'Taxon Profile Images';
2163
  $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>';
2164
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2165

    
2166
  // ---- FEATURE TREE BLOCKS ---- //
2167
  $form['taxon_profile']['feature_blocks'] = array(
2168
    '#type' => 'fieldset',
2169
    '#title' => t('Feature Blocks'),
2170
    '#collapsible' => TRUE,
2171
    '#collapsed' => FALSE,
2172
    '#description' => t("This section covers settings related to the taxon's
2173
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2174
      features such as description, distribution, common names"),
2175
  );
2176
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2177
  $profile_feature_tree = get_profile_feature_tree();
2178
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2179
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2180
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2181
  }
2182
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2183
    '#type' => 'radios',
2184
    '#title' => t('Taxon profile feature tree') . ':',
2185
    '#default_value' => $profile_feature_tree_uuid,
2186
    '#options' =>  $featureTrees['options'],
2187
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2188
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2189
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2190
      profile page.'
2191
    ),
2192
  );
2193

    
2194
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2195
  $profile_feature_tree = get_profile_feature_tree();
2196

    
2197
  if (isset($profile_feature_tree->root->childNodes)) {
2198

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

    
2241

    
2242
    $feature_list_layout_settings_disabled = FALSE;
2243

    
2244
    // creating helper object to retrieve the default settings
2245
    $featureNode = new stdClass();
2246
    $featureNode->term = new stdClass();
2247
    $featureNode->term->uuid="DEFAULT";
2248
    $featureNode->term->representation_L10n = "Default";
2249
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2250

    
2251
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2252

    
2253
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2254

    
2255
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2256
        $subform_id = $featureNode->term->uuid;
2257
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2258

    
2259
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2260

    
2261
        $form_feature_block_layout[$subform_id] = array(
2262
          '#type' => 'fieldset',
2263
          '#tree' => TRUE,
2264
          '#title' => $featureNode->term->representation_L10n,
2265
          '#collapsible' => FALSE,
2266
          '#collapsed' => FALSE,
2267
        );
2268
        if($featureNode->term->uuid == "DEFAULT"){
2269
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2270
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2271
          references</em> and <em>names in source</em> is only possible in the defaults';
2272
        }
2273

    
2274
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2275
          '#type' => 'select',
2276
          '#title' => 'List type',
2277
          '#default_value' => $feature_block_setting['as_list'],
2278
          '#options' => array(
2279
            'div' => 'not as list',
2280
            'ul' => 'bullet list',
2281
            'ol' => 'numbered list',
2282
            'dl' => 'definition list'
2283
          ),
2284
        );
2285

    
2286
        if($featureNode->term->uuid == "DEFAULT"){
2287
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2288
            '#type' => 'checkbox',
2289
            '#title' => t('Link to reference'),
2290
            '#default_value' => $feature_block_setting['link_to_reference'],
2291
          );
2292

    
2293
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2294
            '#type' => 'checkbox',
2295
            '#title' => 'Link to name used in source',
2296
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2297
          );
2298
        }
2299

    
2300
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2301
          '#type' => 'checkbox',
2302
          '#title' => 'Sources as content',
2303
          '#default_value' => $feature_block_setting['sources_as_content'],
2304
        );
2305

    
2306
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2307
          '#type' => 'checkbox',
2308
          '#title' => 'Put sources also as content to bibliography',
2309
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2310
        );
2311

    
2312
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2313
          '#type' => 'select',
2314
          '#title' => t('Sort elements'),
2315
          '#default_value' => $feature_block_setting['sort_elements'],
2316
          '#options' => array(
2317
            NO_SORT => 'No sorting',
2318
            SORT_ASC => 'Ascending',
2319
            SORT_DESC => 'Descending',
2320
            SORT_HIERARCHICAL => 'Hierarchical'
2321
          ),
2322
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2323
          <dl>
2324
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2325
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2326
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2327
          <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>
2328
          </dl>',
2329
        );
2330

    
2331
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2332
          '#type' => 'select',
2333
          '#title' => t('Element tag'),
2334
          '#options' => array(
2335
            'span' => 'span',
2336
            'div' => 'div',
2337
            'p' => 'p'
2338
          ),
2339
          '#default_value' => $feature_block_setting['element_tag'],
2340
        );
2341
        $form_feature_block_layout[$subform_id]['glue'] = array(
2342
          '#type' => 'textfield',
2343
          '#title' => t('Element glue'),
2344
          '#default_value' => $feature_block_setting['glue'],
2345
          '#size' => 10
2346
      );
2347

    
2348
      }
2349
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2350
    }
2351
  }
2352

    
2353
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2354
  $form['taxon_profile']['structured_description_featuretree'] = array(
2355
    '#type' => 'fieldset',
2356
    '#title' => t('Structured Description Feature Tree'),
2357
    '#collapsible' => TRUE,
2358
    '#collapsed' => FALSE,
2359
  );
2360
  $featureTrees = cdm_get_featureTrees_as_options();
2361
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2362
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2363
    $profile_feature_tree_uuid = NULL;
2364
  }
2365
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2366
    '#type' => 'radios',
2367
    '#title' => t('Natural language representation of structured descriptions') . ':',
2368
    '#default_value' => $profile_feature_tree_uuid,
2369
    '#options' => $featureTrees['options'],
2370
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2371
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2372
    '#description' => t('Taxon descriptions can be stored in a highly structured
2373
      form. The feature tree selected here will be used to generate textual
2374
      representation in natural language.'
2375
    ),
2376
  );
2377

    
2378

    
2379

    
2380
  // ---- DISTRIBUTION LAYOUT ---- //
2381
  $form['taxon_profile']['distribution_layout'] = array(
2382
    '#title' => t('Distribution'),
2383
    '#collapsible' => TRUE,
2384
    '#collapsed' => FALSE,
2385
    '#type' => 'fieldset',
2386
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2387
        Map settings regarding the geometry, layers, etc are found in the '
2388
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2389
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2390
      . l(
2391
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2392
        array('fragment' => 'edit-feature-block-settings')
2393
      )
2394
      . ' More general settings regrading the filtering of Distributions are found at '
2395
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2396
      . '. (These settings here will be merged in future releases into the feature block settings)',
2397

    
2398
  );
2399

    
2400
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2401

    
2402
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2403
    '#type' => 'checkbox',
2404
    '#title' => t('Condensed distribution'),
2405
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2406
    '#description' => 'This option enables the display of a very compact representation
2407
    of the distribution which includes also information on the status.',
2408
  );
2409

    
2410
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2411
    '#type' => 'select',
2412
    '#title' => t('Condensed distribution recipe'),
2413
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2414
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2415
    '#description' => 'Recipe for creating the condensed distribution.',
2416
  );
2417

    
2418
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2419
    '#type' => 'textfield',
2420
    '#title' => t('Condensed distribution info path'),
2421
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2422
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2423
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2424
  );
2425

    
2426

    
2427
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2428
    '#type' => 'radios',
2429
    '#title' => t('Display mode') . ':',
2430
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2431
    '#options' => array(
2432
      'FLAT_ALPHA' => t('Flat list'),
2433
      'TREE' => t('Hierarchically ordered'),
2434
    ),
2435
    '#description' => 'Taxon distribution information is displayed with
2436
    focus on the area of the distribution. The list of areas can either be shown
2437
    as flat list ordered alphabetically or in the hierarchical of the parent
2438
    area and subarea relationship. Fall back areas areas with no Distribution data
2439
    are hidden from the area hierarchy so that their sub areas will move one level up.
2440
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2441
    ' for details on the <em>Marked area filter</em>.',
2442
  );
2443

    
2444
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2445
    '#type' => 'fieldset',
2446
    '#tree' => true,
2447
    '#title' => t('Distribution hierarchy style')
2448
  );
2449

    
2450
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2451
  foreach(array_keys($hierarchy_styles) as $level) {
2452
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2453
      '#type' => 'fieldset',
2454
      '#tree' => true,
2455
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2456
      '#attributes' => array('class' => array('fieldset-float'))
2457
    );
2458
    foreach ($hierarchy_styles[$level] as $key => $value) {
2459
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2460
        '#type' => 'textfield',
2461
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2462
        '#default_value' => $hierarchy_styles[$level][$key],
2463
        '#maxlength' => 4,
2464
        '#size' => 4
2465
      );
2466
    }
2467
  }
2468

    
2469
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2470
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2471
    '#type' => 'checkboxes',
2472
    '#title' => 'Omit area levels',
2473
    '#options' => $level_options,
2474
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2475
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2476
    Areas which belong to the selected area levels will be hidden in the portal.',
2477
  );
2478

    
2479
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2480
    '#type' => 'checkbox',
2481
    '#title' => t('Show TextData elements on top of the map'),
2482
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2483
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2484
      elements on top of the map. Otherwise all <code>TextData</code>
2485
      distribution elements will be listed below the other area elements.
2486
      This option is useful if you need to have descriptive texts for each
2487
      distribution map.'),
2488
  );
2489

    
2490
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2491
      '#type' => 'textarea',
2492
      '#title' => t('Custom status colors'),
2493
      '#element_validate' => array('form_element_validate_json'),
2494
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2495
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2496
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2497
          reference list of the idInVocabulary values of absence and presence terms:
2498
<pre>
2499
Presence Term
2500
p	present
2501
pd	present: doubtfully present
2502
n	native
2503
nq	native: presence questionable
2504
nd	native: doubtfully native
2505
c	cultivated
2506
i	introduced
2507
iq	introduced: presence questionable
2508
id	introduced: doubtfully introduced (perhaps cultivated only)
2509
ip	introduced: uncertain degree of naturalisation
2510
ia	introduced: adventitious (casual)
2511
in	introduced: naturalized
2512
ic	introduced: cultivated
2513
e	endemic for the relevant area
2514
na	naturalised
2515
iv	invasive
2516

    
2517
AbsenceTerm
2518
a	absent
2519
f	reported in error
2520
nf	native: reported in error
2521
if	introduced: reported in error
2522
cf	cultivated: reported in error
2523
ne	native: formerly native
2524
ie	introduced: formerly introduced
2525

    
2526
</pre>'),
2527
  );
2528

    
2529

    
2530
  /* ====== SYNONYMY ====== */
2531
  $form['taxon_synonymy'] = array(
2532
    '#type' => 'fieldset',
2533
    '#title' => t('Taxon synonymy (tab)'),
2534
    '#collapsible' => TRUE,
2535
    '#collapsed' => TRUE,
2536
    '#description' => t('This section covers the settings related to the taxon
2537
      <strong>synonymy</strong> tab.'),
2538
  );
2539

    
2540
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2541
    '#type' => 'checkbox',
2542
    '#title' => t('Accepted taxon on top of the synonymy'),
2543
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2544
    '#description' => t('If checked, the first homotypic taxon is a repetition
2545
      of the accepted taxon most likely with the full nomenclatural reference, 
2546
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2547
  );
2548

    
2549
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2550
    '#type' => 'checkbox',
2551
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2552
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2553
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2554
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2555
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2556
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE)
2557
  );
2558

    
2559
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2560
    '#type' => 'textfield',
2561
    '#description' => 'Label for the secundum referenence.',
2562
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2563
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2564
    );
2565

    
2566
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2567
    '#type' => 'checkbox',
2568
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2569
      coming from a synonym link.'),
2570
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2571
    '#description' => t('Check this if after doing a search and clicking on a
2572
      synonym you want to see the "accept of" text for the accepted synonym.'),
2573
  );
2574

    
2575
  $form['taxon_synonymy']['taxon_relations'] = array(
2576
    '#type' => 'fieldset',
2577
    '#title' => t('Taxon relationships'),
2578
    '#collapsible' => FALSE,
2579
    '#collapsed' => FALSE
2580
  );
2581

    
2582
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2583
    '#type' => 'checkbox',
2584
    '#title' => t('Show taxon relations ships of accepted taxon'),
2585
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2586
    '#description' => t('If this option is enabled the synonymy will show the
2587
      below selected taxon relationships of accepted taxa.'),
2588
  );
2589

    
2590
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2591
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2592
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2593
    '#type' => 'checkboxes',
2594
    '#title' => t('Taxon relationship types') . ':',
2595
    '#description' => 'Only taxon relationships of the selected type will be displayed',
2596
    '#options' => $taxon_relationship_type_options,
2597
    '#default_value' => $taxon_relationship_type_defaults,
2598
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2599
  );
2600

    
2601
  $form['taxon_synonymy']['name_relations'] = array(
2602
    '#type' => 'fieldset',
2603
    '#title' => t('Name relationships'),
2604
    '#collapsible' => FALSE,
2605
    '#collapsed' => FALSE
2606
  );
2607

    
2608
  $name_relationship_type_options = cdm_vocabulary_as_option(
2609
      UUID_NAME_RELATIONSHIP_TYPE,
2610
      '_cdm_relationship_type_term_label_callback',
2611
      false,
2612
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2613
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2614
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2615
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2616
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2617
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2618
  );
2619
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2620
    '#type' => 'checkboxes',
2621
    '#title' => t('Name relationship types') . ':',
2622
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2623
    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') . '.',
2624
    '#options' => $name_relationship_type_options,
2625
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2626
  );
2627

    
2628
  // ====== SPECIMENS ====== //
2629
  $form['taxon_specimens'] = array(
2630
    '#type' => 'fieldset',
2631
    '#title' => t('Taxon specimens (tab)'),
2632
    '#collapsible' => TRUE,
2633
    '#collapsed' => TRUE,
2634
    '#description' => t('This section covers the settings related to the taxon
2635
      <strong>specimens</strong> tab.'),
2636
  );
2637

    
2638
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2639

    
2640
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2641
    '#type' => 'checkbox',
2642
    '#title' => t('Show specimen derivatives in a compressed table'),
2643
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2644
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2645
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2646
  );
2647

    
2648
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2649
      '#type' => 'textfield',
2650
      '#title' => t('Number of records per page') . ':',
2651
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2652
  );
2653

    
2654
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2655
        '#type' => 'checkbox',
2656
        '#title' => t('Show specimen derivatives in a tree view'),
2657
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2658
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2659
    );
2660

    
2661

    
2662
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2663
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2664
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2665
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2666
  }
2667
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2668
    '#type' => 'radios',
2669
    '#title' => t('Specimen description feature tree') . ':',
2670
    '#default_value' => $profile_feature_tree_uuid,
2671
    '#options' =>  $featureTrees['options'],
2672
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2673
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2674
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2675
    ),
2676
  );
2677

    
2678
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2679
  $form_title = t('Specimen media');
2680
  $form_description = t('Specimens may have media which is displayed at the
2681
     Specimen tab/section as a gallery. It is possible to configure the
2682
     thumbnails gallery here, however for configuring how a single media should
2683
     be displayed please go to !url.</p>',
2684
     array(
2685
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2686
     ));
2687
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2688

    
2689
  // --- MEDIA GALLERY ---- //
2690
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2691
  $form_title = 'Media gallery (tab)';
2692
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2693
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2694
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2695
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2696
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2697
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2698
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2699

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

    
2709
/**
2710
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2711
 *
2712
 * @param $map_id
2713
 * @param $form
2714
 * @return mixed
2715
 */
2716
function _cdm_map_visibility_setting($map_id)
2717
{
2718
  return array(
2719
    '#type' => 'select',
2720
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2721
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2722
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2723
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2724
        The map also can forced to show up <b>always</b> or <b>never</b>."
2725
  );
2726
}
2727

    
2728
/**
2729
 * @return array
2730
 *   The form structure.
2731
 */
2732
function cdm_settings_layout_search() {
2733

    
2734
  $form = array();
2735

    
2736
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2737

    
2738
  $form['search_settings'] = array(
2739
    '#type' => 'fieldset',
2740
    '#title' => t('Taxa Search'),
2741
    '#collapsible' => FALSE,
2742
    '#collapsed' => FALSE,
2743
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2744
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2745
         where they can write the text to be searched. You can find Drupal block configuration
2746
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2747
  );
2748

    
2749
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2750
      '#type' => 'checkbox',
2751
      '#title' => t('Ignore the chosen classification in simple search'),
2752
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2753
      '#description' => t('The simple search, which can be executed via the search block,
2754
          will by default search on the classification selected in the classification browser
2755
          selector. Set the tick if you want your portal to search on all classifications.'),
2756
  );
2757

    
2758
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2759
    '#type' => 'checkbox',
2760
    '#title' => t('Run simple search with free-text search backend.'),
2761
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2762
    '#description' => t('The simple search uses by default another search
2763
      backend as the advances search. By checking this option the simple search can be
2764
      configured to also use the free-text search backend.'),
2765
  );
2766

    
2767
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2768
    '#type' => 'checkbox',
2769
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2770
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2771
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2772
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2773
  );
2774

    
2775
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2776
    '#type' => 'textfield',
2777
    '#title' => t('Results per page') . ':',
2778
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2779
    '#description' => t('Number of results to display per page.'),
2780
  );
2781

    
2782
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2783
    '#type' => 'checkbox',
2784
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2785
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2786
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2787
  );
2788

    
2789
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2790
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2791
      '#type' => 'checkboxes',
2792
      '#title' => 'Search mode',
2793
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2794
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2795
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2796
          defaults set here.',
2797
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2798
      '#default_value' => $search_mode_default
2799
      );
2800

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

    
2806
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2807
  );
2808

    
2809
    $form['blast_search_settings'] = array(
2810
        '#type' => 'fieldset',
2811
        '#title' => t('Blast Search'),
2812
        '#collapsible' => TRUE,
2813
        '#collapsed' => TRUE,
2814
        '#description' => t('<p>To perform blast searchs
2815
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2816
         where they can write the text to be searched. You can find Drupal block configuration
2817
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2818
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2819
    );
2820

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

    
2826
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2827
    );
2828
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2829
        '#type' => 'textfield',
2830
        '#title' => t('Webservice URL for blast search') . ':',
2831
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2832

    
2833
        '#description' => t('Enter the webservice URL for blast search'),
2834
    );
2835

    
2836
  // --- SEARCH TAXA GALLERY ---- //
2837
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2838
  $collapsed = FALSE;
2839
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2840
  $form_title = 'Taxa Search thumbnails';
2841
  $form_description = 'Search results may show thumbnails. ';
2842
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2843

    
2844
  // Comment @WA: D7 form api does not support reset buttons,
2845
  // so to mimic the D5 reset button we add one like this.
2846
  $form['actions']['reset'] = array(
2847
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2848
    '#weight' => 1000,
2849
  );
2850
  return system_settings_form($form);
2851
}
2852

    
2853
/**
2854
 * @return array
2855
 *   The form structure.
2856
 */
2857
function cdm_settings_layout_media() {
2858

    
2859
  $form = array();
2860

    
2861
  $form['media_settings'] = array(
2862
    '#type' => 'fieldset',
2863
    '#title' => t('Media settings'),
2864
    '#collapsible' => FALSE,
2865
    '#collapsed' => FALSE,
2866
    '#description' => 'This section covers layout settings for media pages.'
2867
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2868
  );
2869

    
2870
  $form['media_settings']['image_gallery_viewer'] = array(
2871
    '#type' => 'select',
2872
    '#title' => t('Image viewer') . ':',
2873
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2874
    '#options' => array(
2875
      'default' => t('Standard image viewer'),
2876
      'fsi' => t('FSI viewer (requires FSI server!)'),
2877
    ),
2878
  );
2879

    
2880
  // --- STANDARD_IMAGE_VIEWER ---- //
2881
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2882
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2883
      '#type' => 'fieldset',
2884
      '#tree' => true,
2885
      '#title' => t('Standard image viewer settings'),
2886
      '#collapsible' => FALSE,
2887
      '#collapsed' => FALSE,
2888
      );
2889

    
2890
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2891
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2892
      '#type' => 'checkbox',
2893
      '#title' => 'Show media representations',
2894
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2895

    
2896
    );
2897
  }
2898

    
2899

    
2900
  // @WA: D7 form api does not support reset buttons,
2901
  // so to mimic the D5 reset button we add one like this.
2902
  $form['actions']['reset'] = array(
2903
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2904
    '#weight' => 1000,
2905
  );
2906
  return system_settings_form($form);
2907
}
2908

    
2909
/**
2910
 * GEOSERVICE and Map settings.
2911
 *
2912
 *  @return array
2913
 *   The form structure.
2914
 */
2915
function cdm_settings_geo($form, &$form_state) {
2916

    
2917
  $current_geoserver_settings = get_edit_map_service_settings();
2918
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2919

    
2920

    
2921
  $form = array();
2922

    
2923
  $dummy_distribution_query = NULL;
2924
  if($map_distribution['map_type'] != 1){
2925
    // we need to apply a dummy query since the map service requires for image maps
2926
    // at least as and ad to be defined
2927
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2928
  }
2929

    
2930
  $form['map_preview'] = array(
2931
      '#type' => 'fieldset',
2932
      '#tree' => FALSE,
2933
      '#title' => t('Map preview'),
2934
      '#collapsible' => FALSE,
2935
      '#description' => 'The preview of the map'
2936
       . ($dummy_distribution_query != null ?
2937
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2938
           '.<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.')
2939
  );
2940
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2941
    'move' => "this.cdmOpenlayersMap.printInfo",
2942
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2943
  ), true // resizable
2944
  );
2945

    
2946
  /*
2947
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2948
  );
2949
  */
2950

    
2951
  /*
2952
   * GEO SERVER
2953
   */
2954
  $form['edit_map_server'] = array(
2955
    '#type' => 'fieldset',
2956
    '#tree' => true,
2957
    '#title' => t('EDIT map service'),
2958
    '#collapsible' => TRUE,
2959
    '#collapsed' => TRUE,
2960
    '#description' => t('Configuration and selection of your geo server.
2961
      The Geo Server is responsible for generating the maps.'),
2962
  );
2963

    
2964
  $form['edit_map_server']['base_uri'] = array(
2965
    '#type' => 'select',
2966
    '#title' => t('EDIT map service') . ':',
2967
    '#default_value' => $current_geoserver_settings['base_uri'],
2968
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2969
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2970
  );
2971
  $form['edit_map_server']['version'] = array(
2972
      '#type' => 'select',
2973
      '#title' => t('Version') . ':',
2974
      '#default_value' => $current_geoserver_settings['version'],
2975
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2976
      '#description' => t('The version of the EDIT map services'),
2977
  );
2978

    
2979
  /*
2980
   * MAP SETTINGS
2981
   */
2982

    
2983
  $form[CDM_MAP_DISTRIBUTION] = array(
2984
    '#type' => 'fieldset',
2985
    '#tree' => TRUE,
2986
    '#title' => t('Maps settings'),
2987
    '#collapsible' => TRUE,
2988
    '#collapsed' => TRUE,
2989
    '#description' => t('General configuration for all map types.'),
2990
  );
2991

    
2992
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2993
    '#type' => 'radios',
2994
    '#title' => 'Map types',
2995
    '#options' => array(
2996
      1 => "OpenLayers dynamic map viewer",
2997
      0 => "Plain image",
2998
    ),
2999
    '#default_value' => $map_distribution['map_type'],
3000
    '#description' => 'Two different map types are available :
3001
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
3002
      which allows zooming and panning. If enabled you can configure the default layer
3003
      (background of your maps) below.</li>
3004
      <li><em>Plain image</em>: The map will be static non interactive
3005
      image.</li></ul>',
3006
  );
3007
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
3008

    
3009
  /*
3010
   * settings for the distribution map are used also for specimens map!!!!
3011
   */
3012

    
3013
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
3014
      '#type' => 'textfield',
3015
      '#title' => 'Aspect ratio',
3016
      '#default_value' => $map_distribution['aspect_ratio'],
3017
      '#maxlength' => 4,
3018
      '#size' => 4,
3019
      '#element_validate' => array('element_validate_number'),
3020
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
3021
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
3022
      width by the height:</br>
3023
      <pre>aspect ratio = w / h</pre>
3024
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
3025
      for a square map use <strong>1</strong>.',
3026
  );
3027

    
3028
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3029
    '#type' => 'textfield',
3030
    '#title' => 'Bounding box',
3031
    '#default_value' => $map_distribution['bbox'],
3032
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
3033
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
3034
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3035
      <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.
3036
      (Maybe you need to change the map base layer to OpeLayers.)
3037
      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
3038
      below the map from where you can copy the bbox string.</p>'),
3039
  );
3040

    
3041
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3042
    '#type' => 'select',
3043
    '#title' => 'Max zoom level',
3044
    '#default_value' => $map_distribution['maxZoom'],
3045
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3046
  );
3047

    
3048
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3049
    '#type' => 'checkbox',
3050
    '#title' => 'Display area labels',
3051
    '#default_value' => $map_distribution['show_labels'],
3052
    '#description' => t('The map will show name labels of the areas'),
3053
  );
3054

    
3055
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3056
    '#type' => 'textfield',
3057
    '#title' => 'Map caption',
3058
    '#default_value' => $map_distribution['caption'],
3059
    '#description' => t('The caption will be shown below the map.'),
3060
  );
3061

    
3062
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3063
    '#type' => 'textfield',
3064
    '#title' => 'Distribution layer opacity',
3065
    '#default_value' => $map_distribution['distribution_opacity'],
3066
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3067
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3068
  );
3069

    
3070
  // --- Plain Image Settings --- //
3071
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
3072
    '#type' => 'fieldset',
3073
    '#title' => 'Plain image map settings',
3074
    '#tree' => TRUE,
3075
    '#collapsible' => TRUE,
3076
    '#collapsed' => $open_layers_is_enabled,
3077
    '#description' => 'The settings in this section are still expertimental
3078
      and can only be used with the EDIT map service version 1.1 or above.',
3079
  );
3080
  $edit_mapserver_version = get_edit_map_service_version_number();
3081
  if ($edit_mapserver_version < 1.1) {
3082
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3083
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3084
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3085
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3086
  }
3087

    
3088
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3089
    '#type' => 'textfield',
3090
    '#title' => 'Width',
3091
    '#default_value' => $map_distribution['image_map']['width'],
3092
    '#maxlength' => 4,
3093
    '#size' => 4,
3094
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3095
  );
3096

    
3097
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3098
    '#type' => 'textfield',
3099
    '#title' => 'Background layer',
3100
    '#default_value' => $map_distribution['image_map']['base_layer'],
3101
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3102
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3103
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3104
    )),
3105
  );
3106

    
3107
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3108
    '#type' => 'textfield',
3109
    '#title' => 'Background color',
3110
    '#default_value' => $map_distribution['image_map']['bg_color'],
3111
  );
3112

    
3113
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3114
    '#type' => 'textfield',
3115
    '#title' => 'Background layer style',
3116
     // Only line color by now.
3117
    '#default_value' => $map_distribution['image_map']['layer_style'],
3118
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3119
  );
3120

    
3121
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3122
      '#type' => 'textfield',
3123
      '#title' => 'Projection',
3124
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3125
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3126
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3127
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3128
  );
3129

    
3130

    
3131
  // --- OpenLayers Settings --- //
3132
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3133
    '#type' => 'fieldset',
3134
    '#title' => 'OpenLayers settings',
3135
    '#tree' => TRUE,
3136
    '#collapsible' => TRUE,
3137
    '#collapsed' => !$open_layers_is_enabled,
3138
    '#description' => '',
3139
  );
3140

    
3141

    
3142
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3143
      '#type' => 'checkbox',
3144
      '#title' => 'Display outside max extent',
3145
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3146
      '#description' => t('Allows the map to display parts of the layers which are outside
3147
         the max extent if the aspect ratio of the map and of the baselayer
3148
         are not equal.'),
3149
  );
3150

    
3151

    
3152
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3153
      '#type' => 'checkbox',
3154
      '#title' => 'Show Layer Switcher',
3155
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3156
      '#description' => 'The Layer Switcher control displays a table of contents
3157
      for the map.  This allows the user interface to switch between
3158
      base layers and to show or hide overlays.  By default the switcher is
3159
      shown minimized on the right edge of the map, the user may expand it
3160
      by clicking on the handle.',
3161
  );
3162

    
3163
  if (!$open_layers_is_enabled) {
3164
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3165
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3166
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3167
  }
3168

    
3169
  // The default layer must always be enabled
3170
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3171
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3172

    
3173
  $baselayer_options = array(
3174
    /*
3175
   NOTICE: must correspond to the layers defined in
3176
   js/openlayers_,ap.js#getLayersByName()
3177
   */
3178
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3179
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3180
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3181
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3182
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3183
    // all others EPSG:900913
3184
    'mapnik' => 'OpenStreetMap (mapnik)',
3185
    'stamen_terrain' => 'Stamen Terrain',
3186
    'open_topomap' => 'OpenTopoMap',
3187
    // map quest is no longer free. it is required to sign up for a test plan.
3188
    // 'mapquest_open' => "MapQuest",
3189
    // 'mapquest_sat' => "MapQuest Sattelite",
3190
    'groadmap' => 'Google Roadmap',
3191
    'gsatellite' => 'Google Satellite',
3192
    'ghybrid' => 'Google Hybrid',
3193
    'gterrain' => 'Google Terrain',
3194
//     'veroad' => 'Virtual Earth Roads',
3195
//     'veaer' => 'Virtual Earth Aerial',
3196
//     'vehyb' => 'Virtual Earth Hybrid',
3197
    // 'yahoo' => 'Yahoo Street',
3198
    // 'yahoosat' => 'Yahoo Satellite',
3199
    // 'yahoohyb' => 'Yahoo Hybrid',
3200
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3201
  );
3202

    
3203
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3204
    '#type' => 'checkboxes_preferred',
3205
    '#title' => 'Base Layers',
3206
    '#options' => $baselayer_options,
3207
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3208
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3209
  );
3210

    
3211
  $google_maps_api_key = null;
3212
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3213
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3214
  }
3215
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3216
    '#type' => 'textfield',
3217
    '#title' => 'Google Maps API Key',
3218
    '#default_value' => $google_maps_api_key,
3219
    '#description' => 'In order to use any of the Google map layers you need to provide 
3220
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3221
  );
3222

    
3223
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3224
    $map_distribution['openlayers']['custom_wms_base_layer'],
3225
    'Custom WMS base layer',
3226
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3227
    true // add projection settings
3228
    );
3229

    
3230
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3231
    $map_distribution['openlayers']['wms_overlay_layer'],
3232
    'WMS overlay layer',
3233
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3234
                You can actually combine multiple layers for this overlay. 
3235
                For details please refer to the wms query parameter <code>Layers</code> .'
3236
  );
3237

    
3238
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3239
    '#type' => 'checkbox',
3240
    '#title' => 'Enable overlay layer',
3241
    '#weight' => -100,
3242
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3243
  );
3244

    
3245
  /*
3246
   * Map Legend
3247
   */
3248
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3249
    '#type' => 'fieldset',
3250
    '#title' => 'Map legend',
3251
    '#tree' => TRUE,
3252
    '#collapsible' => TRUE,
3253
    '#collapsed' => TRUE,
3254
    '#description' => 'Configure the maps legend.',
3255
  );
3256

    
3257
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3258
    '#type' => 'checkbox',
3259
    '#title' => 'Display a map legend',
3260
    '#default_value' => $map_distribution['legend']['show'],
3261
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3262
  );
3263

    
3264
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3265
    '#type' => 'textfield',
3266
    '#title' => 'Legend opacity',
3267
    '#default_value' => $map_distribution['legend']['opacity'],
3268
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3269
                         to 0.0 will be not much visible.',
3270
  );
3271

    
3272
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3273
    '#type' => 'textfield',
3274
    '#title' => 'Font size',
3275
    '#default_value' => $map_distribution['legend']['font_size'],
3276
    '#description' => 'Font size in pixels.',
3277
  );
3278

    
3279
  $fontStyles = array(
3280
    0 => "plane",
3281
    1 => "italic",
3282
  );
3283
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3284
    '#type' => 'select',
3285
    '#title' => 'Available font styles',
3286
    '#default_value' => $map_distribution['legend']['font_style'],
3287
    '#options' => $fontStyles,
3288
    '#description' => 'Select a font style for the map legend.',
3289
  );
3290

    
3291
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3292
    '#type' => 'textfield',
3293
    '#title' => 'Icon width',
3294
    '#default_value' => $map_distribution['legend']['icon_width'],
3295
    '#description' => 'Legend icon width in pixels.',
3296
  );
3297
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3298
    '#type' => 'textfield',
3299
    '#title' => 'Icon height',
3300
    '#default_value' => $map_distribution['legend']['icon_height'],
3301
    '#description' => 'Legend icon height in pixels.',
3302
  );
3303

    
3304
  // @WA: D7 form api does not support reset buttons,
3305
  // so to mimic the D5 reset button we add one like this.
3306
  $form['actions']['reset'] = array(
3307
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3308
    '#weight' => 1000,
3309
  );
3310

    
3311
  return system_settings_form($form);
3312
}
3313

    
3314
/**
3315
 * @param $default_settings
3316
 * @param $title
3317
 * @param $description
3318
 * @param bool $add_projection_settings
3319
 * @return array
3320
 */
3321
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3322
{
3323
  $form_elements = array(
3324
    '#type' => 'fieldset',
3325
    '#title' => $title,
3326
    '#tree' => TRUE,
3327
    '#collapsible' => FALSE,
3328
    '#collapsed' => FALSE,
3329
    '#description' => $description,
3330
  );
3331

    
3332
  $form_elements['name'] = array(
3333
    '#type' => 'textfield',
3334
    '#title' => 'Layer name',
3335
    '#default_value' => $default_settings['name'],
3336
    '#description' => 'A arbitrary name for the layer.',
3337
  );
3338
  $form_elements['url'] = array(
3339
    '#type' => 'textfield',
3340
    '#title' => 'WMS url',
3341
    '#default_value' => $default_settings['url'],
3342
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3343
  );
3344
  $form_elements['untiled'] = array(
3345
    '#type' => 'checkbox',
3346
    '#title' => 'Untiled',
3347
    '#default_value' => $default_settings['untiled'],
3348
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3349
  );
3350
  $form_elements['params'] = array(
3351
    '#type' => 'textarea',
3352
    '#title' => 'WMS parameters',
3353
    '#element_validate' => array('form_element_validate_json'),
3354
    '#default_value' => $default_settings['params'],
3355
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3356
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3357
      . '), entered in valid JSON. For example:
3358
<pre> {
3359
  "Layers": "topp:em_tiny_jan2003",
3360
  "Format": "image/png",
3361
  "BGCOLOR": "0xe0faff"
3362
}
3363
</pre>
3364
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3365
  );
3366

    
3367
  if($add_projection_settings){
3368

    
3369
    $form_elements['projection'] = array(
3370
      '#type' => 'textfield',
3371
      '#title' => 'Projection',
3372
      '#default_value' => $default_settings['projection'],
3373
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3374
    );
3375
    $form_elements['proj4js_def'] = array(
3376
      '#type' => 'textfield',
3377
      '#maxlength' => 256,
3378
      '#title' => 'proj4js definition',
3379
      '#default_value' => $default_settings['proj4js_def'],
3380
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3381
              The definitions for
3382
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3383
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3384
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3385
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3386
              choose to display the proj4js definition string.
3387
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3388
              <pre>
3389
  +a         Semimajor radius of the ellipsoid axis
3390
  +alpha     ? Used with Oblique Mercator and possibly a few others
3391
  +axis      Axis orientation (new in 4.8.0)
3392
  +b         Semiminor radius of the ellipsoid axis
3393
  +datum     Datum name (see `proj -ld`)
3394
  +ellps     Ellipsoid name (see `proj -le`)
3395
  +k         Scaling factor (old name)
3396
  +k_0       Scaling factor (new name)
3397
  +lat_0     Latitude of origin
3398
  +lat_1     Latitude of first standard parallel
3399
  +lat_2     Latitude of second standard parallel
3400
  +lat_ts    Latitude of true scale
3401
  +lon_0     Central meridian
3402
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3403
  +lon_wrap  Center longitude to use for wrapping (see below)
3404
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3405
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3406
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3407
  +pm        Alternate prime meridian (typically a city name, see below)
3408
  +proj      Projection name (see `proj -l`)
3409
  +south     Denotes southern hemisphere UTM zone
3410
  +to_meter  Multiplier to convert map units to 1.0m
3411
  +towgs84   3 or 7 term datum transform parameters (see below)
3412
  +units     meters, US survey feet, etc.
3413
  +vto_meter vertical conversion to meters.
3414
  +vunits    vertical units.
3415
  +x_0       False easting
3416
  +y_0       False northing
3417
  +zone      UTM zone
3418
              </pre>
3419
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3420
    );
3421
    $form_elements['max_extent'] = array(
3422
      '#type' => 'textfield',
3423
      '#title' => 'Maximum extent',
3424
      '#default_value' => $default_settings['max_extent'],
3425
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3426
    );
3427
    $form_elements['units'] = array(
3428
      '#type' => 'textfield',
3429
      '#title' => 'Units',
3430
      '#default_value' => $default_settings['units'],
3431
      '#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.'
3432
    );
3433

    
3434
  }
3435
  return $form_elements;
3436
}
3437

    
3438

    
3439
/**
3440
 * @return array
3441
 *   The form structure.
3442
 */
3443
function cdm_settings_cache() {
3444

    
3445
  $form = array();
3446

    
3447
  $form['cache_settings'] = array(
3448
    '#type' => 'fieldset',
3449
    '#title' => t('Cache Settings'),
3450
    '#collapsible' => FALSE,
3451
    '#collapsed' => FALSE,
3452
    '#description' => t('<p>When caching is enabled all single taxon sites are
3453
      stored in an internal drupal cache doing the portal response of taxa pages
3454
      faster. This is possible because the sites are loaded from the cache and
3455
      are not created from scratch.</p>'),
3456
  );
3457

    
3458
  $form['cache_settings']['cdm_webservice_cache'] = array(
3459
    '#type' => 'checkbox',
3460
    '#title' => t('<strong>Enable caching</strong>'),
3461
    '#options' => cdm_help_general_cache(),
3462
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3463
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3464
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3465
       application the changes will be not visible till the cache is erased.
3466
       Therefore developers should deactived this feature when they are working
3467
       on the CDM Dataportal Module.</p>'),
3468
  );
3469

    
3470
  $form['cache_settings']['cdm_run_cache'] = array(
3471
    '#markup' => cdm_view_cache_site(),
3472
  );
3473

    
3474
  // @WA: D7 form api does not support reset buttons,
3475
  // so to mimic the D5 reset button we add one like this.
3476
  $form['actions']['reset'] = array(
3477
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3478
    '#weight' => 1000,
3479
  );
3480
  return system_settings_form($form);
3481
}
3482

    
3483
/**
3484
 * Walk and cache all taxon pages.
3485
 */
3486
function cdm_view_cache_site() {
3487

    
3488
  $out = '';
3489

    
3490
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3491

    
3492
  $request_params = array();
3493
  $request_params['class'] = "Taxon";
3494

    
3495
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3496
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3497
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3498

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

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

    
3508
  // Comment @WA: A form within a form is not valid html and not needed here.
3509
  // Also, it would be recommended just to include this part of the form in the
3510
  // rest of the form array in cdm_settings_cache().
3511
  // $out .= '<form id="cache_site">';
3512
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3513
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3514
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3515
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3516
  // $out .= '</form>';
3517
  $out .= '</div>';
3518
  /*
3519
  foreach($taxonPager->records as $taxon){
3520
    cdm_dataportal_taxon_view($uuid);
3521
  }
3522
  */
3523
  return $out;
3524
}
3525

    
3526

    
3527
function cdm_settings_layout_taxon_submit($form, &$form_state){
3528
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3529
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3530
    if(is_object($file)){
3531
      $file->status = FILE_STATUS_PERMANENT;
3532
      file_save($file);
3533
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3534
    }
3535
  }
3536
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3537
  $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]);
3538
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3539
  if($tab_lables_modified || $tabs_enabled_modified){
3540
    // we first need to set the variable to persist the changes setting
3541
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3542
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3543
    menu_rebuild();
3544
  }
3545
}
3546

    
3547
function cdm_settings_layout_search_submit($form, &$form_state){
3548
  // the visibility of media thumbnails also affects the ui of the search results
3549
  // so reset the according session variable
3550
  //    1. in order to give the user immediate
3551
  //       feedback on potential setting changes
3552
  //    2. let refresh the default if it has changed
3553
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3554
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3555
  }
3556
}
3557

    
3558
/**
3559
 * Form validation handler for cdm_settings_general
3560
 *
3561
 * @param $form
3562
 * @param $form_state
3563
 */
3564
function cdm_settings_general_validate($form, &$form_state) {
3565

    
3566
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3567
    $form_state['values']['cdm_webservice_url'] .= '/';
3568
  }
3569

    
3570
}
3571

    
3572
/**
3573
 * Form submit handler for settings general.
3574
 *
3575
 * tasks performed:
3576
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3577
 *
3578
 * @param $form
3579
 * @param $form_state
3580
 */
3581
function cdm_settings_general_submit($form, &$form_state){
3582
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3583
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3584
  unset($_SESSION['cdm_login']);
3585
}
3586

    
3587
/**
3588
 * Form validation handler for cdm_settings_cache
3589
 */
3590
function cdm_settings_cache_validate($form, &$form_state) {
3591
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3592
    cache_clear_all(NULL, 'cache_cdm_ws');
3593
    // Better clear secref_cache since I can not be sure if the cache has not
3594
    // be used during this response.
3595
    cdm_api_secref_cache_clear();
3596
  }
3597

    
3598
}
3599

    
3600
/**
3601
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3602
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3603
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3604
 *  - version: the version, e.g.: v1.1
3605
 *
3606
 * @return array
3607
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3608
 */
3609
function get_edit_map_service_settings() {
3610

    
3611
  $settings = variable_get('edit_map_server', array(
3612
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3613
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3614
      )
3615
  );
3616

    
3617
  return $settings;
3618
}
3619

    
3620
/**
3621
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3622
 *
3623
 * @return string
3624
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3625
 */
3626
function get_edit_map_service_full_uri() {
3627
  $settings = get_edit_map_service_settings();
3628
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3629
}
3630

    
3631

    
3632
/**
3633
 * Returns the version number of the currently selected edit mapserver as a float
3634
 *
3635
 * @return float
3636
 *   The version number of the currently selected edit mapserver as a float.
3637
 *   Returns 0 on error.
3638
 */
3639
function get_edit_map_service_version_number() {
3640

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

    
3643
  $settings = get_edit_map_service_settings();
3644
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3645
  if (isset($matches[1])) {
3646
    // Convert string to float.
3647
    $version = 1 + $matches[1][0] - 1;
3648
    return $version;
3649
  }
3650
  else {
3651
    // Report error.
3652
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3653
        array(
3654
          '!version' => $settings['version'],
3655
          'warning')
3656
        )
3657
      );
3658
    return 0;
3659
  }
3660
}
3661

    
3662
/**
3663
 * Returns the array of selected items in a options array
3664
 *
3665
 * @param array $options
3666
 *   An options array as generated by a form element like checkoxes, select ...,
3667
 */
3668
function get_selection($options) {
3669
  $selection = array();
3670
  foreach ($options as $key=>$val) {
3671
    if (!empty($val)) {
3672
      $selection[] = $val;
3673
    }
3674
  }
3675
  return $selection;
3676
}
3677

    
3678

    
3679
/**
3680
 * Implements hook_element_info().
3681
 *
3682
 * Allows modules to declare their own Form API element types and specify their default values.
3683
 *
3684
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3685
 */
3686
function cdm_dataportal_element_info() {
3687
  $type['checkboxes_preferred'] = array(
3688
    '#input' => TRUE,
3689
    '#process' => array('checkboxes_preferred_expand'),
3690
    '#after_build' => array('checkboxes_preferred_after_build'),
3691
    '#theme' => array('checkboxes_preferred'),
3692
    // '#theme_wrapper' => array('form_element'),
3693
  );
3694
  return $type;
3695
}
3696

    
3697
/**
3698
 * #process callback function for the custom form element type 'checkbox_preferred'
3699
 *
3700
 *
3701
 */
3702
function checkboxes_preferred_expand($element, &$form_state, $form) {
3703

    
3704
  // First of all create checkboxes for each of the elements
3705
  $element = form_process_checkboxes($element);
3706

    
3707
  // compose the element name
3708
  $parents = array();
3709
  array_deep_copy($element['#parents'], $parents);
3710
  $parents[count($parents) -1 ] .= '_preferred';
3711
  $element_name = $parents[0];
3712
  for ($i=1; $i < count($parents); $i++){
3713
    $element_name .= '[' . $parents[$i] . ']';
3714
  }
3715

    
3716
  $children = element_children($element);
3717

    
3718
  $element['table_start'] = array(
3719
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3720
    '#weight' => -1,
3721
  );
3722

    
3723
  // prepare first part each of the table rows which contains the row label
3724
  $weight = 0;
3725
  foreach ($children as $key) {
3726
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3727
    $element[$key]['#weight'] = $weight;
3728
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3729
    $element[$key]['#suffix'] = '</td>';
3730
    unset($element[$key]['#title']);
3731
    $weight += 2;
3732
  }
3733
  $weight = 0;
3734

    
3735
  // add a radio button to each of the checkboxes, the
3736
  // check boxes have already been created at the beginning
3737
  // of this function
3738
  if (count($element['#options']) > 0) {
3739
    foreach ($element['#options'] as $key => $choice) {
3740
      if (!isset($element[$key . '_preferred'])) {
3741
        $element[$key . '_preferred'] = array(
3742
          '#type' => 'radio',
3743
          '#name' => $element_name,
3744
          '#return_value' => check_plain($key),
3745
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3746
          '#attributes' => $element['#attributes'],
3747
          '#parents' => $element['#parents'],
3748
          // '#spawned' => TRUE,
3749
          '#weight' => $weight + 1,
3750
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3751
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3752
        );
3753
      }
3754
      $weight += 2;
3755
    }
3756
  }
3757

    
3758
  // end the table
3759
  $element['table_end'] = array(
3760
    '#markup' => '</table>',
3761
    '#weight' => $weight++,
3762
  );
3763

    
3764
  return $element;
3765
}
3766

    
3767
/**
3768
 * Theme function for the custom form field 'checkboxes_preferred'.
3769
 */
3770
function theme_checkboxes_preferred($variables) {
3771
  $element = $variables['element'];
3772
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3773
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3774
  $out .= drupal_render_children($element);
3775
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3776
  $out .= '</div>';
3777
  return $out;
3778
}
3779

    
3780
/**
3781
 * Callback for checkboxes preferred for widget which will
3782
 * be called after the form or element is built. The call
3783
 * back is configured in the form element by setting it as
3784
 * #after_build parameter.
3785
 *
3786
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3787
 *
3788
 * @param $element
3789
 *   Nested array of form elements that comprise the form.
3790
 * @param $form_state
3791
 *   A keyed array containing the current state of the form.
3792
 *   This includes the current persistent storage data for the form.
3793
 *   Additional information, like the sanitized $_POST data,
3794
 *   is also accumulated here in $form_state['input']
3795
 *
3796
 * @return the modified form array
3797
 */
3798
function checkboxes_preferred_after_build($element, &$form_state) {
3799

    
3800
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3801

    
3802
  if ($_POST && count($_POST) > 0) {
3803
    // TODO use  $form_state['input'] instead of POST !!!
3804
    // First pass of form processing.
3805
    $parents = array();
3806
    array_deep_copy($element['#parents'], $parents);
3807
    $parents[count($parents) - 1] .= '_preferred';
3808
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3809
    $element['#value']['PREFERRED'] = $preferred_layer;
3810
//     $form_state[$parent_id] = $element['#value'];
3811
//     $form_state['values']['baselayers'] = $element['#value'];
3812
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3813
    $form_state_element_values = $element['#value'];
3814
  }
3815
  else {
3816
    // Second pass of form processing.
3817
    $preferred_layer = $element['#value']['PREFERRED'];
3818
  }
3819

    
3820
  // Also set the chosen value (not sure if this is good Drupal style ....).
3821
  foreach ($children = element_children($element) as $key) {
3822
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3823
      $element[$key]['#value'] = $preferred_layer;
3824
    }
3825
  }
3826
  // The default layer must always be enabled.
3827
  $element[$preferred_layer]['#value'] = $preferred_layer;
3828

    
3829
  return $element;
3830
}
3831

    
3832
function radios_prepare_options_suffix(&$elements){
3833

    
3834
  $childrenKeys = element_children($elements);
3835
  foreach($childrenKeys as $key){
3836
    if(!is_array($elements[$key]['#theme_wrappers'])){
3837
      $elements[$key]['#theme_wrappers'] = array();
3838
    }
3839
    if(isset($elements['#options_suffixes'][$key])){
3840
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3841
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3842
    }
3843
  }
3844
  return $elements;
3845

    
3846
}
3847

    
3848
/**
3849
 * TODO
3850
 * @param unknown $variables
3851
 */
3852
function theme_radio_options_suffix($variables) {
3853
  $element = $variables['element'];
3854
  if(isset($element['#options_suffix'])) {
3855
    $element['#children'] .= $element['#options_suffix'];
3856
  }
3857
  return $element['#children'];
3858
}
3859

    
3860

    
3861
/**
3862
 * Element validate callback for text field and arrays containing json.
3863
 *
3864
 * @param $element
3865
 *   The form element to validate
3866
 * @param $form_state
3867
 *   A keyed array containing the current state of the form.
3868
 * @param $form
3869
 *   Nested array of form elements that comprise the form.
3870
 */
3871
function form_element_validate_json($element, &$form_state, $form) {
3872
   if (!empty($element['#value'])) {
3873
     json_decode($element['#value']);
3874
     if(json_last_error() != JSON_ERROR_NONE){
3875
       form_error($element,
3876
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3877
         . l('JSONLint', 'http://jsonlint.com/')
3878
       );
3879
     }
3880
   }
3881
}
3882

    
3883
/**
3884
 * Form submission handler for textareas and textfields containing JSON.
3885
 *
3886
 * The contained JSON will be converted into an php array
3887
 * or object and will be stored in the variables as such.
3888
 *
3889
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3890
 *
3891
 * @param $form
3892
 *   Nested array of form elements that comprise the form.
3893
 * @param $form_state
3894
 *   A keyed array containing the current state of the form.
3895
 *
3896
 */
3897
function submit_json_as_php_array($form, &$form_state) {
3898
  if (is_array($form['#json_elements'])) {
3899
    foreach ($form['#json_elements'] as $element){
3900
      if (trim($form_state['values'][$element])) {
3901
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3902
      } else {
3903
        $form_state['values'][$element] = NULL;
3904
      }
3905
    }
3906
  }
3907
}
(18-18/18)