Project

General

Profile

Download (161 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 page',
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
  $items['admin/config/cdm_dataportal/settings/layout/name-page'] = array(
1060
    'title' => 'Name page',
1061
    'description' => 'Configure and adjust the layout of your DataPortal ',
1062
    'access arguments' => array('administer cdm_dataportal'),
1063
    'page callback' => 'drupal_get_form',
1064
    'page arguments' => array('cdm_settings_layout_name_page'),
1065
    'weight' => 1,
1066
    'type' => MENU_LOCAL_TASK,
1067
  );
1068
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1069
    'title' => 'Search',
1070
    'description' => 'Configure and adjust the layout of your DataPortal ',
1071
    'access arguments' => array('administer cdm_dataportal'),
1072
    'page callback' => 'drupal_get_form',
1073
    'page arguments' => array('cdm_settings_layout_search'),
1074
    'weight' => 2,
1075
    'type' => MENU_LOCAL_TASK,
1076
  );
1077

    
1078
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1079
    'title' => 'Media',
1080
    'description' => 'Configure and adjust the layout of your DataPortal ',
1081
    'access arguments' => array('administer cdm_dataportal'),
1082
    'page callback' => 'drupal_get_form',
1083
    'page arguments' => array('cdm_settings_layout_media'),
1084
    'weight' => 3,
1085
    'type' => MENU_LOCAL_TASK,
1086
  );
1087

    
1088
}
1089

    
1090
/**
1091
 * @todo document this function.
1092
 */
1093
function cdm_help_general_cache() {
1094
  $form = array();
1095
  $form['cache_help'] = array(
1096
    '#type' => 'fieldset',
1097
    '#title' => t('Help'),
1098
    '#collapsible' => TRUE,
1099
    '#collapsed' => TRUE,
1100
  );
1101
  $form['cache_help']['test'] = array('#value' => t('probando'));
1102
  return drupal_render($form);
1103
  $res = array();
1104
  $res['default'] = drupal_render($help);
1105
  return $res;
1106
}
1107

    
1108
/**
1109
 * Configures the settings form for the CDM-API module.
1110
 *
1111
 * @return array
1112
 *   Drupal settings form.
1113
 */
1114
function cdm_settings_general() {
1115

    
1116
  $form['cdm_webservice'] = array(
1117
    '#type' => 'fieldset',
1118
    '#title' => t('CDM Server'),
1119
    '#collapsible' => FALSE,
1120
    '#collapsed' => FALSE,
1121
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1122
        CDM data base to the web via RESTful web services and thus is the source of the data
1123
        to be displayed by a CDM DataPotal.'),
1124
  );
1125

    
1126
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1127
    '#type' => 'textfield',
1128
    '#title' => t('CDM web service URL') . ':',
1129
    '#description' => t('This is the URL to the CDM-Server exposing your data
1130
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1131
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1132
  );
1133

    
1134
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1135
    '#type' => 'markup',
1136
    '#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')
1137
      . ' visible only for administrators',
1138
  );
1139

    
1140
  $form['cdm_webservice']['freetext_index'] = array(
1141
    '#type' => 'fieldset',
1142
    '#title' => t('Freetext index'),
1143
    '#collapsible' => FALSE,
1144
    '#collapsed' => FALSE,
1145
  );
1146

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

    
1161
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1162
  $trigger_link_options = array(
1163
    'attributes' => array(
1164
      'class' => 'index-trigger'
1165
    ),
1166
  );
1167
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1168
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1169
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1170
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1171
      ))
1172
    . '<div id="index-progress"></div></div>',
1173
  );
1174

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

    
1200
  $form['cdm_webservice']['proxy'] = array(
1201
    '#type' => 'fieldset',
1202
    '#title' => t('Proxy'),
1203
    '#collapsible' => TRUE,
1204
    '#collapsed' => TRUE,
1205
  );
1206

    
1207
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1208
    '#type' => 'textfield',
1209
    '#title' => t('Proxy URL') . ':',
1210
    '#description' => t('If this proxy url is set the cdm api tries
1211
    to connect the web service over the given proxy server.
1212
    Otherwise proxy usage is deactivated.'),
1213
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1214
  );
1215

    
1216
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1217
    '#type' => 'textfield',
1218
    '#title' => t('Proxy port') . ':',
1219
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1220
  );
1221

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

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

    
1234
  $form['sub_tree_filter'] = array(
1235
    '#type' => 'fieldset',
1236
    '#title' => t('Subtree filter'),
1237
    '#collapsible' => FALSE,
1238
    '#collapsed' => TRUE,
1239
    '#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.'),
1240
  );
1241

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

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

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

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

    
1294
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1295
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1296
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1297
      '#type' => 'checkboxes',
1298
      '#title' => t('Included Classifications') . ':',
1299
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1300
      '#options' => cdm_get_taxontrees_as_options(),
1301
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1302
  );
1303

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

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

    
1338
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1339
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1340
      '#type' => 'checkboxes',
1341
      '#title' => 'Filter rules',
1342
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1343
      '#options' => array(
1344
          'statusOrderPreference' => 'Status order preference rule',
1345
          'subAreaPreference' => 'Sub area preference rule'
1346
      ),
1347
  );
1348

    
1349
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1350
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1351
      '#type' => 'checkboxes',
1352
      '#title' => 'Hide marked area filter',
1353
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1354
      '#options' => $marker_type_options,
1355
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1356
  );
1357

    
1358
  $form['aggregation'] = array(
1359
      '#type' => 'fieldset',
1360
      '#title' => t('Aggregation of data'),
1361
      '#collapsible' => FALSE,
1362
      '#description' => 'This section covers the different aspects of aggregating information.
1363
          <p>
1364
          </p>',
1365
  );
1366

    
1367
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1368
      '#type' => 'checkboxes',
1369
      '#title' => 'Taxon media filter',
1370
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1371
      '#options' => array(
1372
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1373
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1374
          'includeOccurrences' => 'Media related to specimens and occurrences',
1375
      ),
1376
      '#description' => 'This filter configures which images should be taken into account.',
1377
  );
1378

    
1379
  $form['aggregation']['notice'] = array(
1380
      '#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
1381
          want to make use of the caching capabilities of the dataportal.',
1382
  );
1383

    
1384
  $form['aggregation']['media_aggregation'] = array(
1385
      '#type' => 'fieldset',
1386
      '#title' => t('Media aggregation'),
1387
      '#collapsible' => FALSE,
1388
      '#collapsed' => TRUE,
1389
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1390

    
1391
  );
1392
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1393
      '#type' => 'select',
1394
      '#title' => t('Aggregation of taxon pictures') . ':',
1395
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1396
      '#options' => array(
1397
          0 => "Show only pictures of the current taxon",
1398
          1 => "Include pictures of taxonomic children",
1399
      ),
1400
      '#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."),
1401
  );
1402

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

    
1417
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1418
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1419

    
1420
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1421
      '#type' => 'checkboxes',
1422
      '#title' => t('Direct'),
1423
      '#options' => $taxonRelationshipTypeOptions,
1424
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1425
  );
1426
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1427
      '#type' => 'checkboxes',
1428
      '#title' => t('Invers'),
1429
      '#options' => $taxonRelationshipTypeOptions,
1430
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1431
  );
1432

    
1433
  $form['drupal_integration'] = array(
1434
    '#type' => 'fieldset',
1435
    '#attributes' => array('class'=> array('clearfix')),
1436
    '#title' => t('Drupal integration'),
1437
    '#collapsible' => FALSE,
1438
    '#collapsed' => FALSE,
1439
    '#tree' => FALSE
1440
  );
1441

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

    
1451

    
1452

    
1453
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1454
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1455
    <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>',
1456
  );
1457
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1458
    '#type' => 'submit',
1459
    '#value' => t('Drop all cdm nodes'),
1460
    '#submit' => array('drop_all_cdm_nodes_submit')
1461
  );
1462

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

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

    
1492
  // Comment @WA: D7 form api does not support reset buttons,
1493
  // so to mimic the D5 reset button we add one like this.
1494
  $form['actions']['reset'] = array(
1495
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1496
    '#weight' => 1000,
1497
  );
1498

    
1499
  $form['#submit'][] = 'cdm_settings_general_submit';
1500

    
1501
  return system_settings_form($form);
1502
}
1503

    
1504
/**
1505
 * Submit callback; drops all cdm nodes.
1506
 *
1507
 * @ingroup forms
1508
 */
1509
function drop_all_cdm_nodes_submit($form, &$form_state) {
1510
  cdm_delete_all_cdm_nodes();
1511
  drupal_set_message(t('All cdm nodes dropped.'));
1512
}
1513

    
1514

    
1515
/**
1516
 * LAYOUT settings
1517
 *
1518
 * @return array
1519
 *   The form structure.
1520
 */
1521
function cdm_settings_layout() {
1522

    
1523
  $form = array();
1524

    
1525
  $form['about'] = array(
1526
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1527
      layout. If you want to configure the specific sites layout visit the
1528
      respective configuration site for taxon, search or media.') . '</p>',
1529
  );
1530

    
1531
  // ---- footnotes --- //
1532
  $form['footnotes'] = array(
1533
    '#type' => 'fieldset',
1534
    '#title' => t('Footnotes'),
1535
    '#collapsible' => FALSE,
1536
    '#collapsed' => FALSE,
1537
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1538
      media or distribution areas may have annotations or footnotes. When the
1539
      footnotes are enabled they will be visible (if they exist).'),
1540
  );
1541

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

    
1549
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1550
    '#type' => 'checkbox',
1551
    '#title' => t('Do not show annotation footnotes'),
1552
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1553
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1554
  );
1555

    
1556
  $form['annotations'] = array(
1557
    '#type' => 'fieldset',
1558
    '#title' => t('Annotations'),
1559
    '#collapsible' => FALSE,
1560
    '#collapsed' => FALSE,
1561
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1562
  );
1563

    
1564
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1565
  // Additional option for the NULL case.
1566
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1567
  $annotationsTypesAsFootnotes = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1568
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1569
    '#type' => 'checkboxes',
1570
    '#title' => t('Visbility of annotation types'),
1571
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1572
    '#options' => $annotationTypeOptions,
1573
    '#default_value' => $annotationsTypesAsFootnotes
1574
  );
1575

    
1576

    
1577
  // ---- original source --- //
1578
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1579
      '#type' => 'fieldset',
1580
      '#tree' => TRUE,
1581
      '#title' => t('Source Citations'),
1582
      '#collapsible' => FALSE,
1583
      '#collapsed' => FALSE,
1584
  );
1585

    
1586
  $bibliography_settings = get_bibliography_settings(true);
1587

    
1588
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1589
      '#type' => 'checkbox',
1590
      '#title' => t('Original Source in bibliography'),
1591
      '#default_value' => $bibliography_settings['enabled'],
1592
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1593
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1594
       into the bibliography also depends on the settings in the ' .
1595
        l("Taxon profile feature block settings", "admin/config/cdm_dataportal/settings/layout/taxon") .
1596
        '. 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.'),
1597
  );
1598

    
1599
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1600
    '#type' => 'select',
1601
    '#title' => t('The format of the key numerals'),
1602
    '#default_value' => $bibliography_settings['key_format'],
1603
    '#options' => array('latin' => 'Latin',
1604
      'ROMAN' => 'Roman (upper case)',
1605
      'roman' => 'Roman (lower case)',
1606
      'ALPHA'=> 'Alphabet (upper case)',
1607
      'alpha' => 'Alphabet (lower case)')
1608
  );
1609

    
1610
  // --- Advanced Search --- //
1611
  $form['asearch'] = array(
1612
      '#type' => 'fieldset',
1613
      '#title' => t('Advanced search'),
1614
      '#collapsible' => FALSE,
1615
      '#collapsed' => FALSE,
1616
  );
1617
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1618
      '#type' => 'checkbox',
1619
      '#title' => t('Show advanced search link'),
1620
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1621
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1622
  );
1623

    
1624
  // --- Name page autoredirect feature --- //
1625
  $form['name_page'] = array(
1626
    '#type' => 'fieldset',
1627
    '#title' => t('Name page'),
1628
    '#collapsible' => FALSE,
1629
    '#collapsed' => FALSE,
1630
  );
1631
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1632
    '#type' => 'checkbox',
1633
    '#title' => 'Always redirect to taxon',
1634
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1635
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1636
    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. 
1637
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1638
  );
1639

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

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

    
1665
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1666
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1667
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1668
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1669

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

    
1679
  $diff_viewer_markup = '';
1680
  if($is_custom_part_definition){
1681
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1682
  }
1683

    
1684
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1685
    . $which_version_message
1686
    . '</div>'
1687
    . $diff_viewer_markup;
1688

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

    
1778
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1779
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1780
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1781
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1782
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1783

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

    
1792
  $diff_viewer_markup = '';
1793
  if($is_custom_render_template){
1794
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1795
  }
1796

    
1797
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1798
    . $which_version_message
1799
    . '</div>'
1800
    . $diff_viewer_markup;
1801

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

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

    
1849
  $form['#submit'] = array('submit_json_as_php_array');
1850
  // #json_elements especially defined for submit_json_as_php_array()
1851
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1852
  return system_settings_form($form);
1853
}
1854

    
1855

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

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

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

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

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

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

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

    
1935
  return $form;
1936
}
1937

    
1938
/**
1939
 * @return array
1940
 *   The form structure.
1941
 */
1942
function cdm_settings_layout_taxon() {
1943
  $collapsed = FALSE;
1944
  $form = array();
1945

    
1946
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1947

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

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

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

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

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

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

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

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

    
2041
  // ---- PROFILE PICTURE ----//
2042

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

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

    
2057
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2058

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

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

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

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

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

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

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

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

    
2146
  // -- MEDIA THUMBNAILS -- //
2147
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2148
  $form_title = 'Taxon Profile Images';
2149
  $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>';
2150
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2151

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

    
2180
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2181
  $profile_feature_tree = get_profile_feature_tree();
2182

    
2183
  if (isset($profile_feature_tree->root->childNodes)) {
2184

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

    
2227

    
2228
    $feature_list_layout_settings_disabled = FALSE;
2229

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

    
2237
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2238

    
2239
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2240

    
2241
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2242
        $subform_id = $featureNode->term->uuid;
2243
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2244

    
2245
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2246

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

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

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

    
2279
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2280
            '#type' => 'checkbox',
2281
            '#title' => 'Link to name used in source',
2282
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2283
          );
2284
        }
2285

    
2286
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2287
          '#type' => 'checkbox',
2288
          '#title' => 'Sources as content',
2289
          '#default_value' => $feature_block_setting['sources_as_content'],
2290
        );
2291

    
2292
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2293
          '#type' => 'checkbox',
2294
          '#title' => 'Put sources also as content to bibliography',
2295
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2296
        );
2297

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

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

    
2334
      }
2335
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2336
    }
2337
  }
2338

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

    
2364

    
2365

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

    
2384
  );
2385

    
2386
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2387

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

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

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

    
2412

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

    
2430
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2431
    '#type' => 'fieldset',
2432
    '#tree' => true,
2433
    '#title' => t('Distribution hierarchy style')
2434
  );
2435

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

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

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

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

    
2503
AbsenceTerm
2504
a	absent
2505
f	reported in error
2506
nf	native: reported in error
2507
if	introduced: reported in error
2508
cf	cultivated: reported in error
2509
ne	native: formerly native
2510
ie	introduced: formerly introduced
2511

    
2512
</pre>'),
2513
  );
2514

    
2515

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

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

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

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

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

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

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

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

    
2587
  $form['taxon_synonymy']['name_relations'] = array(
2588
    '#type' => 'fieldset',
2589
    '#title' => t('Name relationships'),
2590
    '#collapsible' => FALSE,
2591
    '#collapsed' => FALSE
2592
  );
2593

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

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

    
2624
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2625

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

    
2634
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2635
      '#type' => 'textfield',
2636
      '#title' => t('Number of records per page') . ':',
2637
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2638
  );
2639

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

    
2647

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

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

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

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

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

    
2714
/**
2715
 * @return array
2716
 *   The form structure.
2717
 */
2718
function cdm_settings_layout_search() {
2719

    
2720
  $form = array();
2721

    
2722
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2723

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

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

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

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

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

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

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

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

    
2792
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2793
  );
2794

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

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

    
2812
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2813
    );
2814
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2815
        '#type' => 'textfield',
2816
        '#title' => t('Webservice URL for blast search') . ':',
2817
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2818

    
2819
        '#description' => t('Enter the webservice URL for blast search'),
2820
    );
2821

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

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

    
2839

    
2840
/**
2841
 * @return array
2842
 *   The form structure.
2843
 */
2844
function cdm_settings_layout_name_page()
2845
{
2846

    
2847
  $form = array();
2848

    
2849

    
2850
  $form['name_relations'] = array(
2851
    '#type' => 'fieldset',
2852
    '#title' => t('Name relationship listings'),
2853
    '#collapsible' => FALSE,
2854
    '#collapsed' => FALSE
2855
  );
2856

    
2857
  $name_relationship_type_options = cdm_vocabulary_as_option(
2858
    UUID_NAME_RELATIONSHIP_TYPE,
2859
    '_cdm_relationship_type_term_label_callback',
2860
    false,
2861
    array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2862
      . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2863
      . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2864
      . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2865
      . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2866
      . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2867
  );
2868
  $form['name_relations'][CDM_NAME_RELATIONSHIP_LIST_TYPES] = array(
2869
    '#type' => 'checkboxes',
2870
    '#title' => t('Name relationship types') . ':',
2871
    '#description' => 'This setting only affects specific types of name relations which are displayed as list. Another representations 
2872
    is the inline style used in the synonymy which may show a different (reduced) set of name relations. 
2873
    The according settings can be adjusted in the ' . l('taxon page settings section synonmy', 'admin/config/cdm_dataportal/settings/layout/taxon') . '.',
2874
    '#options' => $name_relationship_type_options,
2875
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, unserialize(CDM_NAME_RELATIONSHIP_LIST_TYPES_DEFAULT)),
2876
  );
2877

    
2878

    
2879

    
2880
  return system_settings_form($form);
2881
}
2882

    
2883
/**
2884
 * @return array
2885
 *   The form structure.
2886
 */
2887
function cdm_settings_layout_media() {
2888

    
2889
  $form = array();
2890

    
2891
  $form['media_settings'] = array(
2892
    '#type' => 'fieldset',
2893
    '#title' => t('Media settings'),
2894
    '#collapsible' => FALSE,
2895
    '#collapsed' => FALSE,
2896
    '#description' => 'This section covers layout settings for media pages.'
2897
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2898
  );
2899

    
2900
  $form['media_settings']['image_gallery_viewer'] = array(
2901
    '#type' => 'select',
2902
    '#title' => t('Image viewer') . ':',
2903
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2904
    '#options' => array(
2905
      'default' => t('Standard image viewer'),
2906
      'fsi' => t('FSI viewer (requires FSI server!)'),
2907
    ),
2908
  );
2909

    
2910
  // --- STANDARD_IMAGE_VIEWER ---- //
2911
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2912
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2913
      '#type' => 'fieldset',
2914
      '#tree' => true,
2915
      '#title' => t('Standard image viewer settings'),
2916
      '#collapsible' => FALSE,
2917
      '#collapsed' => FALSE,
2918
      );
2919

    
2920
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2921
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2922
      '#type' => 'checkbox',
2923
      '#title' => 'Show media representations',
2924
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2925

    
2926
    );
2927
  }
2928

    
2929

    
2930
  // @WA: D7 form api does not support reset buttons,
2931
  // so to mimic the D5 reset button we add one like this.
2932
  $form['actions']['reset'] = array(
2933
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2934
    '#weight' => 1000,
2935
  );
2936
  return system_settings_form($form);
2937
}
2938

    
2939
/**
2940
 * GEOSERVICE and Map settings.
2941
 *
2942
 *  @return array
2943
 *   The form structure.
2944
 */
2945
function cdm_settings_geo($form, &$form_state) {
2946

    
2947
  $current_geoserver_settings = get_edit_map_service_settings();
2948
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2949

    
2950

    
2951
  $form = array();
2952

    
2953
  $dummy_distribution_query = NULL;
2954
  if($map_distribution['map_type'] != 1){
2955
    // we need to apply a dummy query since the map service requires for image maps
2956
    // at least as and ad to be defined
2957
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2958
  }
2959

    
2960
  $form['map_preview'] = array(
2961
      '#type' => 'fieldset',
2962
      '#tree' => FALSE,
2963
      '#title' => t('Map preview'),
2964
      '#collapsible' => FALSE,
2965
      '#description' => 'The preview of the map'
2966
       . ($dummy_distribution_query != null ?
2967
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2968
           '.<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.')
2969
  );
2970
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2971
    'move' => "this.cdmOpenlayersMap.printInfo",
2972
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2973
  ), true // resizable
2974
  );
2975

    
2976
  /*
2977
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2978
  );
2979
  */
2980

    
2981
  /*
2982
   * GEO SERVER
2983
   */
2984
  $form['edit_map_server'] = array(
2985
    '#type' => 'fieldset',
2986
    '#tree' => true,
2987
    '#title' => t('EDIT map service'),
2988
    '#collapsible' => TRUE,
2989
    '#collapsed' => TRUE,
2990
    '#description' => t('Configuration and selection of your geo server.
2991
      The Geo Server is responsible for generating the maps.'),
2992
  );
2993

    
2994
  $form['edit_map_server']['base_uri'] = array(
2995
    '#type' => 'select',
2996
    '#title' => t('EDIT map service') . ':',
2997
    '#default_value' => $current_geoserver_settings['base_uri'],
2998
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2999
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
3000
  );
3001
  $form['edit_map_server']['version'] = array(
3002
      '#type' => 'select',
3003
      '#title' => t('Version') . ':',
3004
      '#default_value' => $current_geoserver_settings['version'],
3005
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
3006
      '#description' => t('The version of the EDIT map services'),
3007
  );
3008

    
3009
  /*
3010
   * MAP SETTINGS
3011
   */
3012

    
3013
  $form[CDM_MAP_DISTRIBUTION] = array(
3014
    '#type' => 'fieldset',
3015
    '#tree' => TRUE,
3016
    '#title' => t('Maps settings'),
3017
    '#collapsible' => TRUE,
3018
    '#collapsed' => TRUE,
3019
    '#description' => t('General configuration for all map types.'),
3020
  );
3021

    
3022
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
3023
    '#type' => 'radios',
3024
    '#title' => 'Map types',
3025
    '#options' => array(
3026
      1 => "OpenLayers dynamic map viewer",
3027
      0 => "Plain image",
3028
    ),
3029
    '#default_value' => $map_distribution['map_type'],
3030
    '#description' => 'Two different map types are available :
3031
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
3032
      which allows zooming and panning. If enabled you can configure the default layer
3033
      (background of your maps) below.</li>
3034
      <li><em>Plain image</em>: The map will be static non interactive
3035
      image.</li></ul>',
3036
  );
3037
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
3038

    
3039
  /*
3040
   * settings for the distribution map are used also for specimens map!!!!
3041
   */
3042

    
3043
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
3044
      '#type' => 'textfield',
3045
      '#title' => 'Aspect ratio',
3046
      '#default_value' => $map_distribution['aspect_ratio'],
3047
      '#maxlength' => 4,
3048
      '#size' => 4,
3049
      '#element_validate' => array('element_validate_number'),
3050
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
3051
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
3052
      width by the height:</br>
3053
      <pre>aspect ratio = w / h</pre>
3054
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
3055
      for a square map use <strong>1</strong>.',
3056
  );
3057

    
3058
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3059
    '#type' => 'textfield',
3060
    '#title' => 'Bounding box',
3061
    '#default_value' => $map_distribution['bbox'],
3062
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
3063
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
3064
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3065
      <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.
3066
      (Maybe you need to change the map base layer to OpeLayers.)
3067
      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
3068
      below the map from where you can copy the bbox string.</p>'),
3069
  );
3070

    
3071
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3072
    '#type' => 'select',
3073
    '#title' => 'Max zoom level',
3074
    '#default_value' => $map_distribution['maxZoom'],
3075
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3076
  );
3077

    
3078
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3079
    '#type' => 'checkbox',
3080
    '#title' => 'Display area labels',
3081
    '#default_value' => $map_distribution['show_labels'],
3082
    '#description' => t('The map will show name labels of the areas'),
3083
  );
3084

    
3085
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3086
    '#type' => 'textfield',
3087
    '#title' => 'Map caption',
3088
    '#default_value' => $map_distribution['caption'],
3089
    '#description' => t('The caption will be shown below the map.'),
3090
  );
3091

    
3092
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3093
    '#type' => 'textfield',
3094
    '#title' => 'Distribution layer opacity',
3095
    '#default_value' => $map_distribution['distribution_opacity'],
3096
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3097
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3098
  );
3099

    
3100
  // --- Plain Image Settings --- //
3101
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
3102
    '#type' => 'fieldset',
3103
    '#title' => 'Plain image map settings',
3104
    '#tree' => TRUE,
3105
    '#collapsible' => TRUE,
3106
    '#collapsed' => $open_layers_is_enabled,
3107
    '#description' => 'The settings in this section are still expertimental
3108
      and can only be used with the EDIT map service version 1.1 or above.',
3109
  );
3110
  $edit_mapserver_version = get_edit_map_service_version_number();
3111
  if ($edit_mapserver_version < 1.1) {
3112
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3113
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3114
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3115
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3116
  }
3117

    
3118
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3119
    '#type' => 'textfield',
3120
    '#title' => 'Width',
3121
    '#default_value' => $map_distribution['image_map']['width'],
3122
    '#maxlength' => 4,
3123
    '#size' => 4,
3124
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3125
  );
3126

    
3127
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3128
    '#type' => 'textfield',
3129
    '#title' => 'Background layer',
3130
    '#default_value' => $map_distribution['image_map']['base_layer'],
3131
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3132
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3133
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3134
    )),
3135
  );
3136

    
3137
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3138
    '#type' => 'textfield',
3139
    '#title' => 'Background color',
3140
    '#default_value' => $map_distribution['image_map']['bg_color'],
3141
  );
3142

    
3143
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3144
    '#type' => 'textfield',
3145
    '#title' => 'Background layer style',
3146
     // Only line color by now.
3147
    '#default_value' => $map_distribution['image_map']['layer_style'],
3148
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3149
  );
3150

    
3151
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3152
      '#type' => 'textfield',
3153
      '#title' => 'Projection',
3154
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3155
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3156
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3157
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3158
  );
3159

    
3160

    
3161
  // --- OpenLayers Settings --- //
3162
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3163
    '#type' => 'fieldset',
3164
    '#title' => 'OpenLayers settings',
3165
    '#tree' => TRUE,
3166
    '#collapsible' => TRUE,
3167
    '#collapsed' => !$open_layers_is_enabled,
3168
    '#description' => '',
3169
  );
3170

    
3171

    
3172
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3173
      '#type' => 'checkbox',
3174
      '#title' => 'Display outside max extent',
3175
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3176
      '#description' => t('Allows the map to display parts of the layers which are outside
3177
         the max extent if the aspect ratio of the map and of the baselayer
3178
         are not equal.'),
3179
  );
3180

    
3181

    
3182
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3183
      '#type' => 'checkbox',
3184
      '#title' => 'Show Layer Switcher',
3185
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3186
      '#description' => 'The Layer Switcher control displays a table of contents
3187
      for the map.  This allows the user interface to switch between
3188
      base layers and to show or hide overlays.  By default the switcher is
3189
      shown minimized on the right edge of the map, the user may expand it
3190
      by clicking on the handle.',
3191
  );
3192

    
3193
  if (!$open_layers_is_enabled) {
3194
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3195
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3196
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3197
  }
3198

    
3199
  // The default layer must always be enabled
3200
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3201
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3202

    
3203
  $baselayer_options = array(
3204
    /*
3205
   NOTICE: must correspond to the layers defined in
3206
   js/openlayers_,ap.js#getLayersByName()
3207
   */
3208
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3209
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3210
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3211
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3212
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3213
    // all others EPSG:900913
3214
    'mapnik' => 'OpenStreetMap (mapnik)',
3215
    'stamen_terrain' => 'Stamen Terrain',
3216
    'open_topomap' => 'OpenTopoMap',
3217
    // map quest is no longer free. it is required to sign up for a test plan.
3218
    // 'mapquest_open' => "MapQuest",
3219
    // 'mapquest_sat' => "MapQuest Sattelite",
3220
    'groadmap' => 'Google Roadmap',
3221
    'gsatellite' => 'Google Satellite',
3222
    'ghybrid' => 'Google Hybrid',
3223
    'gterrain' => 'Google Terrain',
3224
//     'veroad' => 'Virtual Earth Roads',
3225
//     'veaer' => 'Virtual Earth Aerial',
3226
//     'vehyb' => 'Virtual Earth Hybrid',
3227
    // 'yahoo' => 'Yahoo Street',
3228
    // 'yahoosat' => 'Yahoo Satellite',
3229
    // 'yahoohyb' => 'Yahoo Hybrid',
3230
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3231
  );
3232

    
3233
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3234
    '#type' => 'checkboxes_preferred',
3235
    '#title' => 'Base Layers',
3236
    '#options' => $baselayer_options,
3237
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3238
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3239
  );
3240

    
3241
  $google_maps_api_key = null;
3242
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3243
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3244
  }
3245
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3246
    '#type' => 'textfield',
3247
    '#title' => 'Google Maps API Key',
3248
    '#default_value' => $google_maps_api_key,
3249
    '#description' => 'In order to use any of the Google map layers you need to provide 
3250
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3251
  );
3252

    
3253
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3254
    $map_distribution['openlayers']['custom_wms_base_layer'],
3255
    'Custom WMS base layer',
3256
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3257
    true // add projection settings
3258
    );
3259

    
3260
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3261
    $map_distribution['openlayers']['wms_overlay_layer'],
3262
    'WMS overlay layer',
3263
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3264
                You can actually combine multiple layers for this overlay. 
3265
                For details please refer to the wms query parameter <code>Layers</code> .'
3266
  );
3267

    
3268
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3269
    '#type' => 'checkbox',
3270
    '#title' => 'Enable overlay layer',
3271
    '#weight' => -100,
3272
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3273
  );
3274

    
3275
  /*
3276
   * Map Legend
3277
   */
3278
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3279
    '#type' => 'fieldset',
3280
    '#title' => 'Map legend',
3281
    '#tree' => TRUE,
3282
    '#collapsible' => TRUE,
3283
    '#collapsed' => TRUE,
3284
    '#description' => 'Configure the maps legend.',
3285
  );
3286

    
3287
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3288
    '#type' => 'checkbox',
3289
    '#title' => 'Display a map legend',
3290
    '#default_value' => $map_distribution['legend']['show'],
3291
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3292
  );
3293

    
3294
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3295
    '#type' => 'textfield',
3296
    '#title' => 'Legend opacity',
3297
    '#default_value' => $map_distribution['legend']['opacity'],
3298
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3299
                         to 0.0 will be not much visible.',
3300
  );
3301

    
3302
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3303
    '#type' => 'textfield',
3304
    '#title' => 'Font size',
3305
    '#default_value' => $map_distribution['legend']['font_size'],
3306
    '#description' => 'Font size in pixels.',
3307
  );
3308

    
3309
  $fontStyles = array(
3310
    0 => "plane",
3311
    1 => "italic",
3312
  );
3313
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3314
    '#type' => 'select',
3315
    '#title' => 'Available font styles',
3316
    '#default_value' => $map_distribution['legend']['font_style'],
3317
    '#options' => $fontStyles,
3318
    '#description' => 'Select a font style for the map legend.',
3319
  );
3320

    
3321
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3322
    '#type' => 'textfield',
3323
    '#title' => 'Icon width',
3324
    '#default_value' => $map_distribution['legend']['icon_width'],
3325
    '#description' => 'Legend icon width in pixels.',
3326
  );
3327
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3328
    '#type' => 'textfield',
3329
    '#title' => 'Icon height',
3330
    '#default_value' => $map_distribution['legend']['icon_height'],
3331
    '#description' => 'Legend icon height in pixels.',
3332
  );
3333

    
3334
  // @WA: D7 form api does not support reset buttons,
3335
  // so to mimic the D5 reset button we add one like this.
3336
  $form['actions']['reset'] = array(
3337
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3338
    '#weight' => 1000,
3339
  );
3340

    
3341
  return system_settings_form($form);
3342
}
3343

    
3344
/**
3345
 * @param $default_settings
3346
 * @param $title
3347
 * @param $description
3348
 * @param bool $add_projection_settings
3349
 * @return array
3350
 */
3351
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3352
{
3353
  $form_elements = array(
3354
    '#type' => 'fieldset',
3355
    '#title' => $title,
3356
    '#tree' => TRUE,
3357
    '#collapsible' => FALSE,
3358
    '#collapsed' => FALSE,
3359
    '#description' => $description,
3360
  );
3361

    
3362
  $form_elements['name'] = array(
3363
    '#type' => 'textfield',
3364
    '#title' => 'Layer name',
3365
    '#default_value' => $default_settings['name'],
3366
    '#description' => 'A arbitrary name for the layer.',
3367
  );
3368
  $form_elements['url'] = array(
3369
    '#type' => 'textfield',
3370
    '#title' => 'WMS url',
3371
    '#default_value' => $default_settings['url'],
3372
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3373
  );
3374
  $form_elements['untiled'] = array(
3375
    '#type' => 'checkbox',
3376
    '#title' => 'Untiled',
3377
    '#default_value' => $default_settings['untiled'],
3378
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3379
  );
3380
  $form_elements['params'] = array(
3381
    '#type' => 'textarea',
3382
    '#title' => 'WMS parameters',
3383
    '#element_validate' => array('form_element_validate_json'),
3384
    '#default_value' => $default_settings['params'],
3385
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3386
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3387
      . '), entered in valid JSON. For example:
3388
<pre> {
3389
  "Layers": "topp:em_tiny_jan2003",
3390
  "Format": "image/png",
3391
  "BGCOLOR": "0xe0faff"
3392
}
3393
</pre>
3394
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3395
  );
3396

    
3397
  if($add_projection_settings){
3398

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

    
3464
  }
3465
  return $form_elements;
3466
}
3467

    
3468

    
3469
/**
3470
 * @return array
3471
 *   The form structure.
3472
 */
3473
function cdm_settings_cache() {
3474

    
3475
  $form = array();
3476

    
3477
  $form['cache_settings'] = array(
3478
    '#type' => 'fieldset',
3479
    '#title' => t('Cache Settings'),
3480
    '#collapsible' => FALSE,
3481
    '#collapsed' => FALSE,
3482
    '#description' => t('<p>When caching is enabled all single taxon sites are
3483
      stored in an internal drupal cache doing the portal response of taxa pages
3484
      faster. This is possible because the sites are loaded from the cache and
3485
      are not created from scratch.</p>'),
3486
  );
3487

    
3488
  $form['cache_settings']['cdm_webservice_cache'] = array(
3489
    '#type' => 'checkbox',
3490
    '#title' => t('<strong>Enable caching</strong>'),
3491
    '#options' => cdm_help_general_cache(),
3492
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3493
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3494
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3495
       application the changes will be not visible till the cache is erased.
3496
       Therefore developers should deactived this feature when they are working
3497
       on the CDM Dataportal Module.</p>'),
3498
  );
3499

    
3500
  $form['cache_settings']['cdm_run_cache'] = array(
3501
    '#markup' => cdm_view_cache_site(),
3502
  );
3503

    
3504
  // @WA: D7 form api does not support reset buttons,
3505
  // so to mimic the D5 reset button we add one like this.
3506
  $form['actions']['reset'] = array(
3507
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3508
    '#weight' => 1000,
3509
  );
3510
  return system_settings_form($form);
3511
}
3512

    
3513
/**
3514
 * Walk and cache all taxon pages.
3515
 */
3516
function cdm_view_cache_site() {
3517

    
3518
  $out = '';
3519

    
3520
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3521

    
3522
  $request_params = array();
3523
  $request_params['class'] = "Taxon";
3524

    
3525
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3526
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3527
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3528

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

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

    
3538
  // Comment @WA: A form within a form is not valid html and not needed here.
3539
  // Also, it would be recommended just to include this part of the form in the
3540
  // rest of the form array in cdm_settings_cache().
3541
  // $out .= '<form id="cache_site">';
3542
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3543
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3544
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3545
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3546
  // $out .= '</form>';
3547
  $out .= '</div>';
3548
  /*
3549
  foreach($taxonPager->records as $taxon){
3550
    cdm_dataportal_taxon_view($uuid);
3551
  }
3552
  */
3553
  return $out;
3554
}
3555

    
3556

    
3557
function cdm_settings_layout_taxon_submit($form, &$form_state){
3558
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3559
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3560
    if(is_object($file)){
3561
      $file->status = FILE_STATUS_PERMANENT;
3562
      file_save($file);
3563
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3564
    }
3565
  }
3566
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3567
  $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]);
3568
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3569
  if($tab_lables_modified || $tabs_enabled_modified){
3570
    // we first need to set the variable to persist the changes setting
3571
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3572
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3573
    menu_rebuild();
3574
  }
3575
}
3576

    
3577
function cdm_settings_layout_search_submit($form, &$form_state){
3578
  // the visibility of media thumbnails also affects the ui of the search results
3579
  // so reset the according session variable
3580
  //    1. in order to give the user immediate
3581
  //       feedback on potential setting changes
3582
  //    2. let refresh the default if it has changed
3583
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3584
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3585
  }
3586
}
3587

    
3588
/**
3589
 * Form validation handler for cdm_settings_general
3590
 *
3591
 * @param $form
3592
 * @param $form_state
3593
 */
3594
function cdm_settings_general_validate($form, &$form_state) {
3595

    
3596
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3597
    $form_state['values']['cdm_webservice_url'] .= '/';
3598
  }
3599

    
3600
}
3601

    
3602
/**
3603
 * Form submit handler for settings general.
3604
 *
3605
 * tasks performed:
3606
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3607
 *
3608
 * @param $form
3609
 * @param $form_state
3610
 */
3611
function cdm_settings_general_submit($form, &$form_state){
3612
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3613
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3614
  unset($_SESSION['cdm_login']);
3615
}
3616

    
3617
/**
3618
 * Form validation handler for cdm_settings_cache
3619
 */
3620
function cdm_settings_cache_validate($form, &$form_state) {
3621
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3622
    cache_clear_all(NULL, 'cache_cdm_ws');
3623
    // Better clear secref_cache since I can not be sure if the cache has not
3624
    // be used during this response.
3625
    cdm_api_secref_cache_clear();
3626
  }
3627

    
3628
}
3629

    
3630
/**
3631
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3632
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3633
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3634
 *  - version: the version, e.g.: v1.1
3635
 *
3636
 * @return array
3637
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3638
 */
3639
function get_edit_map_service_settings() {
3640

    
3641
  $settings = variable_get('edit_map_server', array(
3642
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3643
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3644
      )
3645
  );
3646

    
3647
  return $settings;
3648
}
3649

    
3650
/**
3651
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3652
 *
3653
 * @return string
3654
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3655
 */
3656
function get_edit_map_service_full_uri() {
3657
  $settings = get_edit_map_service_settings();
3658
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3659
}
3660

    
3661

    
3662
/**
3663
 * Returns the version number of the currently selected edit mapserver as a float
3664
 *
3665
 * @return float
3666
 *   The version number of the currently selected edit mapserver as a float.
3667
 *   Returns 0 on error.
3668
 */
3669
function get_edit_map_service_version_number() {
3670

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

    
3673
  $settings = get_edit_map_service_settings();
3674
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3675
  if (isset($matches[1])) {
3676
    // Convert string to float.
3677
    $version = 1 + $matches[1][0] - 1;
3678
    return $version;
3679
  }
3680
  else {
3681
    // Report error.
3682
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3683
        array(
3684
          '!version' => $settings['version'],
3685
          'warning')
3686
        )
3687
      );
3688
    return 0;
3689
  }
3690
}
3691

    
3692
/**
3693
 * Returns the array of selected items in a options array
3694
 *
3695
 * @param array $options
3696
 *   An options array as generated by a form element like checkoxes, select ...,
3697
 */
3698
function get_selection($options) {
3699
  $selection = array();
3700
  foreach ($options as $key=>$val) {
3701
    if (!empty($val)) {
3702
      $selection[] = $val;
3703
    }
3704
  }
3705
  return $selection;
3706
}
3707

    
3708

    
3709
/**
3710
 * Implements hook_element_info().
3711
 *
3712
 * Allows modules to declare their own Form API element types and specify their default values.
3713
 *
3714
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3715
 */
3716
function cdm_dataportal_element_info() {
3717
  $type['checkboxes_preferred'] = array(
3718
    '#input' => TRUE,
3719
    '#process' => array('checkboxes_preferred_expand'),
3720
    '#after_build' => array('checkboxes_preferred_after_build'),
3721
    '#theme' => array('checkboxes_preferred'),
3722
    // '#theme_wrapper' => array('form_element'),
3723
  );
3724
  return $type;
3725
}
3726

    
3727
/**
3728
 * #process callback function for the custom form element type 'checkbox_preferred'
3729
 *
3730
 *
3731
 */
3732
function checkboxes_preferred_expand($element, &$form_state, $form) {
3733

    
3734
  // First of all create checkboxes for each of the elements
3735
  $element = form_process_checkboxes($element);
3736

    
3737
  // compose the element name
3738
  $parents = array();
3739
  array_deep_copy($element['#parents'], $parents);
3740
  $parents[count($parents) -1 ] .= '_preferred';
3741
  $element_name = $parents[0];
3742
  for ($i=1; $i < count($parents); $i++){
3743
    $element_name .= '[' . $parents[$i] . ']';
3744
  }
3745

    
3746
  $children = element_children($element);
3747

    
3748
  $element['table_start'] = array(
3749
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3750
    '#weight' => -1,
3751
  );
3752

    
3753
  // prepare first part each of the table rows which contains the row label
3754
  $weight = 0;
3755
  foreach ($children as $key) {
3756
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3757
    $element[$key]['#weight'] = $weight;
3758
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3759
    $element[$key]['#suffix'] = '</td>';
3760
    unset($element[$key]['#title']);
3761
    $weight += 2;
3762
  }
3763
  $weight = 0;
3764

    
3765
  // add a radio button to each of the checkboxes, the
3766
  // check boxes have already been created at the beginning
3767
  // of this function
3768
  if (count($element['#options']) > 0) {
3769
    foreach ($element['#options'] as $key => $choice) {
3770
      if (!isset($element[$key . '_preferred'])) {
3771
        $element[$key . '_preferred'] = array(
3772
          '#type' => 'radio',
3773
          '#name' => $element_name,
3774
          '#return_value' => check_plain($key),
3775
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3776
          '#attributes' => $element['#attributes'],
3777
          '#parents' => $element['#parents'],
3778
          // '#spawned' => TRUE,
3779
          '#weight' => $weight + 1,
3780
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3781
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3782
        );
3783
      }
3784
      $weight += 2;
3785
    }
3786
  }
3787

    
3788
  // end the table
3789
  $element['table_end'] = array(
3790
    '#markup' => '</table>',
3791
    '#weight' => $weight++,
3792
  );
3793

    
3794
  return $element;
3795
}
3796

    
3797
/**
3798
 * Theme function for the custom form field 'checkboxes_preferred'.
3799
 */
3800
function theme_checkboxes_preferred($variables) {
3801
  $element = $variables['element'];
3802
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3803
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3804
  $out .= drupal_render_children($element);
3805
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3806
  $out .= '</div>';
3807
  return $out;
3808
}
3809

    
3810
/**
3811
 * Callback for checkboxes preferred for widget which will
3812
 * be called after the form or element is built. The call
3813
 * back is configured in the form element by setting it as
3814
 * #after_build parameter.
3815
 *
3816
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3817
 *
3818
 * @param $element
3819
 *   Nested array of form elements that comprise the form.
3820
 * @param $form_state
3821
 *   A keyed array containing the current state of the form.
3822
 *   This includes the current persistent storage data for the form.
3823
 *   Additional information, like the sanitized $_POST data,
3824
 *   is also accumulated here in $form_state['input']
3825
 *
3826
 * @return the modified form array
3827
 */
3828
function checkboxes_preferred_after_build($element, &$form_state) {
3829

    
3830
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3831

    
3832
  if ($_POST && count($_POST) > 0) {
3833
    // TODO use  $form_state['input'] instead of POST !!!
3834
    // First pass of form processing.
3835
    $parents = array();
3836
    array_deep_copy($element['#parents'], $parents);
3837
    $parents[count($parents) - 1] .= '_preferred';
3838
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3839
    $element['#value']['PREFERRED'] = $preferred_layer;
3840
//     $form_state[$parent_id] = $element['#value'];
3841
//     $form_state['values']['baselayers'] = $element['#value'];
3842
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3843
    $form_state_element_values = $element['#value'];
3844
  }
3845
  else {
3846
    // Second pass of form processing.
3847
    $preferred_layer = $element['#value']['PREFERRED'];
3848
  }
3849

    
3850
  // Also set the chosen value (not sure if this is good Drupal style ....).
3851
  foreach ($children = element_children($element) as $key) {
3852
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3853
      $element[$key]['#value'] = $preferred_layer;
3854
    }
3855
  }
3856
  // The default layer must always be enabled.
3857
  $element[$preferred_layer]['#value'] = $preferred_layer;
3858

    
3859
  return $element;
3860
}
3861

    
3862
function radios_prepare_options_suffix(&$elements){
3863

    
3864
  $childrenKeys = element_children($elements);
3865
  foreach($childrenKeys as $key){
3866
    if(!is_array($elements[$key]['#theme_wrappers'])){
3867
      $elements[$key]['#theme_wrappers'] = array();
3868
    }
3869
    if(isset($elements['#options_suffixes'][$key])){
3870
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3871
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3872
    }
3873
  }
3874
  return $elements;
3875

    
3876
}
3877

    
3878
/**
3879
 * TODO
3880
 * @param unknown $variables
3881
 */
3882
function theme_radio_options_suffix($variables) {
3883
  $element = $variables['element'];
3884
  if(isset($element['#options_suffix'])) {
3885
    $element['#children'] .= $element['#options_suffix'];
3886
  }
3887
  return $element['#children'];
3888
}
3889

    
3890

    
3891
/**
3892
 * Element validate callback for text field and arrays containing json.
3893
 *
3894
 * @param $element
3895
 *   The form element to validate
3896
 * @param $form_state
3897
 *   A keyed array containing the current state of the form.
3898
 * @param $form
3899
 *   Nested array of form elements that comprise the form.
3900
 */
3901
function form_element_validate_json($element, &$form_state, $form) {
3902
   if (!empty($element['#value'])) {
3903
     json_decode($element['#value']);
3904
     if(json_last_error() != JSON_ERROR_NONE){
3905
       form_error($element,
3906
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3907
         . l('JSONLint', 'http://jsonlint.com/')
3908
       );
3909
     }
3910
   }
3911
}
3912

    
3913
/**
3914
 * Form submission handler for textareas and textfields containing JSON.
3915
 *
3916
 * The contained JSON will be converted into an php array
3917
 * or object and will be stored in the variables as such.
3918
 *
3919
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3920
 *
3921
 * @param $form
3922
 *   Nested array of form elements that comprise the form.
3923
 * @param $form_state
3924
 *   A keyed array containing the current state of the form.
3925
 *
3926
 */
3927
function submit_json_as_php_array($form, &$form_state) {
3928
  if (is_array($form['#json_elements'])) {
3929
    foreach ($form['#json_elements'] as $element){
3930
      if (trim($form_state['values'][$element])) {
3931
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3932
      } else {
3933
        $form_state['values'][$element] = NULL;
3934
      }
3935
    }
3936
  }
3937
}
(18-18/18)