Project

General

Profile

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

    
7

    
8
const FEATURE_BLOCK_WEIGHT_INCREMENT = 2;
9
const PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS = 'AGGREGATION_DESCRIPTIONS';
10
const PSEUDO_FEATURE_BIBLIOGRAPHY = 'BIBLIOGRAPHY';
11
const PSEUDO_FEATURE_NUMBER_OF_TAXA = 'NUMBER_OF_TAXA';
12

    
13
const CDM_NAME_PAGE_AUTOREDIRECT = 'cdm_name_page_autoredirect';
14

    
15
const CDM_NAME_PAGE_SECTION_TAXA = 'cdm_name_page_section_taxa';
16
const CDM_NAME_PAGE_SECTION_TAXA_DEFAULT = 1;
17

    
18
const CDM_MEDIA_GALLERY_VIEWER = 'image_gallery_viewer';
19
const CDM_MEDIA_GALLERY_VIEWER_DEFAULT = 'universalviewer';
20

    
21
define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
22
define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
23
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
24
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
25

    
26
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
27

    
28
  define('NO_SORT', -1);
29
  define('SORT_HIERARCHICAL', 9);
30

    
31
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
32

    
33
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
34
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
35

    
36
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
37
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
38
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
39
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
40
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
41
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
42
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
43
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
44
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
45
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
46
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
47
  define('CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE', 0);
48

    
49
  define('CDM_SEARCH_BLAST_SERVICE_URI', 'http://bgbm-import:9001/api/sequence');
50
  define('CDM_SEARCH_BLAST_ENABLED', 0);
51
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
52

    
53
  /* annotationTypeKeys */
54
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
55
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
56
    $annotationTypeKeys = array_flip($annotationTypeKeys);
57

    
58
    // Technical annotation are off by default.
59
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
60
    $annotationTypeKeys = array_flip($annotationTypeKeys);
61
    // Additional value for the NULL case.
62
    $annotationTypeKeys[] = 'NULL_VALUE';
63
  }
64

    
65
  define('ANNOTATION_TYPES_VISIBLE', 'annotations_types_as_footnotes');
66
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
67

    
68
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
69
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
70
    'enabled' => 0,
71
    'key_format' => 'ALPHA'
72
  )));
73

    
74
  /* taxonRelationshipTypes */
75
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
76
    array(
77
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
78
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
79
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
80
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
81
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
82
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
83
    )
84
  ));
85

    
86

    
87
  /* ---- MAP SETTING CONSTANTS ---- */
88
  /**
89
   * @var array of URIs eg. http://edit.africamuseum.be"
90
   *   An options array
91
   */
92
  define('EDIT_MAPSERVER_URI', serialize(
93
      array(
94
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
95
      )
96
    )
97
  );
98
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
99
  /**
100
   * @var array of versions eg. "v1.2"
101
   *   An options array
102
   */
103
  define('EDIT_MAPSERVER_VERSION', serialize(
104
      array(
105
//        'v1' => 'v1' ,           // no longer recommended
106
//        'v1.1' => 'v1.1',        // no longer recommended
107
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
108
        'v1.2' => 'v1.2',
109
        'v1.3_dev' => 'v1.3_dev (not recommended)',
110
        'v1.4_dev' => 'v1.4_dev (experimental features)'
111
      )
112
    )
113
  );
114
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
115
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
116

    
117
    // --- Taxon profile settings --- /
118
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
119
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
120
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
121
      array(
122
          'show' => 0,
123
          'maxextend' => 184,
124
          'media_uri_query' => '',
125
          'custom_placeholder_enabled' => 1,
126
          'custom_placeholder_image_on' => 0,
127
          'custom_placeholder_image_fid' => ''
128
      )
129
    )
130
  );
131

    
132

    
133
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
134

    
135
define('CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS', 'cdm_pseudo_feature_block_weights');
136
define('CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT', serialize(
137
  [
138
    PSEUDO_FEATURE_NUMBER_OF_TAXA => 0 - FEATURE_BLOCK_WEIGHT_INCREMENT,
139
    PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS => 100,
140
    PSEUDO_FEATURE_BIBLIOGRAPHY => 102
141
  ]
142
));
143

    
144
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
145
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
146
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
147
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
148
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
149

    
150
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
151
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
152
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
153
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
154

    
155
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
156
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
157

    
158
/**
159
 * Returns the array of implemented taxon page tabs.
160
 * The array has fixed integer keys which must not be changed.
161
 */
162
function get_taxon_tabs_list() {
163
  $opts = array(
164
    0 => 'General',
165
    1 => 'Synonymy',
166
    2 => 'Images',
167
    3 => 'Specimens',
168
    4 => 'Keys',
169
    5 => 'Experts',
170
  );
171
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
172
    // skip the Synonymy if it is shown in  the general tab
173
    unset($opts[1]);
174
  }
175
  return $opts;
176
}
177

    
178
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
179
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
180
  array(
181
    'general' => '-3',
182
    'synonymy' => '-2',
183
    'images' => '0',
184
    'specimens' => '1',
185
    'keys' => '3',
186
    'experts' => '5',
187
    )
188
));
189

    
190

    
191
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
192
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
193
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
194
  array(
195
    'general' => null,
196
    'synonymy' => null,
197
    'images' => null,
198
    'specimens' => null,
199
    'keys' => null,
200
    'experts' => null,
201
  )
202
));
203

    
204
$taxon_tab_options = get_taxon_tabs_list();
205
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
206

    
207
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
208

    
209
/**
210
 * @todo document this function.
211
 */
212
function get_taxon_options_list() {
213
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
214
  foreach ($taxon_tab_options as $key => $value) {
215
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
216
  }
217
  return $taxon_tab_options;
218

    
219
}
220

    
221
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
222
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
223
    array(
224
      'ZoologicalName' => array(
225
        'namePart' => array('name' => TRUE),
226
        'nameAuthorPart' => array('name' => TRUE),
227
        'referencePart' => array('authors' => TRUE),
228
        'microreferencePart' => array('microreference' => TRUE),
229
        'secReferencePart' => array('secReference' => TRUE,),
230
        'statusPart' => array('status' => TRUE),
231
        'descriptionPart' => array('description' => TRUE),
232
      ),
233
      'BotanicalName'=> array(
234
        'namePart' => array('name' => TRUE),
235
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
236
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
237
        'secReferencePart' => array('secReference' => TRUE,),
238
        'referenceYearPart' => array('reference.year' => TRUE),
239
        'statusPart' => array('status' => TRUE),
240
        'descriptionPart' => array('description' => TRUE),
241
      ),
242
     '#DEFAULT' => array(
243
        'namePart' => array(
244
            'name' => TRUE
245
        ),
246
        'nameAuthorPart' => array(
247
            'name' => TRUE,
248
            'authors' => TRUE
249
        ),
250
       'referencePart' => array(
251
         'reference' => TRUE
252
        ),
253
       'secReferencePart' => array(
254
         'secReference' => TRUE,
255
       ),
256
       'microreferencePart' => array(
257
          'microreference' => TRUE,
258
        ),
259
       'statusPart' => array(
260
          'status' => TRUE,
261
        ),
262
       'descriptionPart' => array(
263
          'description' => TRUE,
264
        ),
265
      )
266
    )
267
  )
268
);
269
define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
270
    array(
271
      'ZoologicalName' => array(
272
        'namePart' => array('name' => TRUE),
273
        'nameAuthorPart' => array('name' => TRUE),
274
        'referencePart' => array('authors' => TRUE),
275
        'microreferencePart' => array('microreference' => TRUE),
276
        'statusPart' => array('status' => TRUE),
277
        'descriptionPart' => array('description' => TRUE),
278
      ),
279
      'BotanicalName'=> array(
280
        'namePart' => array('name' => TRUE),
281
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
282
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
283
        'referenceYearPart' => array('reference.year' => TRUE),
284
        'statusPart' => array('status' => TRUE),
285
        'descriptionPart' => array('description' => TRUE),
286
      ),
287
      '#DEFAULT' => array(
288
        'namePart' => array(
289
          'name' => TRUE
290
        ),
291
        'nameAuthorPart' => array(
292
          'name' => TRUE,
293
          'authors' => TRUE
294
        ),
295
        'referencePart' => array(
296
          'reference' => TRUE
297
        ),
298
        'microreferencePart' => array(
299
          'microreference' => TRUE,
300
        ),
301
        'statusPart' => array(
302
          'status' => TRUE,
303
        ),
304
        'descriptionPart' => array(
305
          'description' => TRUE,
306
        ),
307
      )
308
    )
309
  )
310
  );
311

    
312
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
313
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
314
  array (
315
    'taxon_page_title,polytomousKey'=> array(
316
        'namePart' => array('#uri' => TRUE),
317
      ),
318
    'not_in_current_classification' => array(
319
     'nameAuthorPart' => TRUE,
320
     'referencePart' => TRUE,
321
     'statusPart' => TRUE,
322
     'secReferencePart' => TRUE,
323
    ),
324
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy,name_page,registration_page'=> array(
325
      'nameAuthorPart' => array('#uri' => TRUE),
326
      'referencePart' => TRUE,
327
      'descriptionPart' => TRUE,
328
      'statusPart' => TRUE,
329
    ),
330
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
331
      'nameAuthorPart' => array('#uri' => TRUE),
332
      'referencePart' => TRUE,
333
      'descriptionPart' => TRUE,
334
      'statusPart' => TRUE,
335
      'secReferencePart' => TRUE,
336
    ),
337
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
338
      'nameAuthorPart' => array('#uri' => TRUE),
339
      'referencePart' => TRUE,
340
      'descriptionPart' => TRUE,
341
      'statusPart' => TRUE,
342
      /* no sec ref in this case, misapplied names are
343
       * de-duplicated and the sec ref is shown as footnote */
344
    ),
345
    'homonym'=> array(
346
        'nameAuthorPart' => array('#uri' => TRUE),
347
        'referenceYearPart' => TRUE,
348
        'statusPart' => TRUE,
349
    ),
350
    'acceptedFor,typedesignations,list_of_taxa' => array(
351
        'nameAuthorPart' => array('#uri' => TRUE),
352
        'referencePart' => TRUE,
353
      ),
354
    '#DEFAULT' => array(
355
        'nameAuthorPart' => array('#uri' => TRUE),
356
        'referencePart' => TRUE,
357
     )
358
  )
359
));
360
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
361
  array (
362
    'taxon_page_title,polytomousKey'=> array(
363
      'namePart' => array('#uri' => TRUE),
364
    ),
365
    'taxon_page_synonymy,related_taxon'=> array(
366
      'nameAuthorPart' => array('#uri' => TRUE),
367
      'referencePart' => TRUE,
368
      'statusPart' => TRUE,
369
      'descriptionPart' => TRUE,
370
    ),
371
    'homonym'=> array(
372
      'nameAuthorPart' => array('#uri' => TRUE),
373
      'referenceYearPart' => TRUE,
374
    ),
375
    'acceptedFor,typedesignations,list_of_taxa' => array(
376
      'nameAuthorPart' => array('#uri' => TRUE),
377
      'referencePart' => TRUE,
378
    ),
379
    '#DEFAULT' => array(
380
      'nameAuthorPart' => array('#uri' => TRUE),
381
      'referencePart' => TRUE,
382
    )
383
  )
384
));
385

    
386
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
387
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
388
    // to unset a default enntry set the value to 0
389
    array(
390
      'doTaxa'=>'doTaxa',
391
      'doSynonyms' => 'doSynonyms',
392
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
393
      'doMisappliedNames' => 'doMisappliedNames'
394
    )
395
  )
396
);
397

    
398
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
399

    
400
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
401
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
402
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
403

    
404
/* Gallery variables. */
405
$gallery_settings = array(
406
    "cdm_dataportal_show_taxon_thumbnails" => 1,
407
    "cdm_dataportal_show_synonym_thumbnails" => 0,
408
    "cdm_dataportal_show_thumbnail_captions" => 1,
409
    "cdm_dataportal_media_maxextend" => 120,
410
    "cdm_dataportal_media_cols" => 3,
411
    "cdm_dataportal_media_maxRows" => 1,
412
);
413

    
414
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
415
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
416
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
417
define('CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME', 'type_specimen_gallery');
418
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
419
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
420
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
421
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
422
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
423
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
424
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
425
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
426

    
427
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
428
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
429
  'media_representation_details_enabled' => 0
430
)));
431

    
432
/**
433
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
434
 * the synonymy.
435
 *
436
 * @var string
437
 */
438
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
439

    
440
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES', 'cdm_name_relationship_types');
441
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT', serialize(
442
    array(
443
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
444
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
445
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
446
    )
447
  )
448
);
449

    
450
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
451

    
452

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

    
474
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
475
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
476
      array(
477
      'filter_rules' => array(
478
        'statusOrderPreference' => 0,
479
        'subAreaPreference' => 0,
480
      ),
481
      'hiddenAreaMarkerType' => array()
482
     )
483
));
484

    
485
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
486
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
487
  "level_0" => array(
488
    'label_suffix' => ':',
489
    'status_glue' => '',
490
    'item_glue' => ' ',
491
    'item_group_prefix' => '',
492
    'item_group_postfix' => ''
493
  ),
494
  "level_1" => array(
495
    'label_suffix' => '',
496
    'status_glue' => '‒ ', // '&#8210; '
497
    'item_glue' => '; ',
498
    'item_group_prefix' => ', ',
499
    'item_group_postfix' => ''
500
  ),
501
  "level_2" => array(
502
    'label_suffix' => '',
503
    'status_glue' => '‒ ', // '&#8210; '
504
    'item_glue' => ', ',
505
    'item_group_prefix' => ' (',
506
    'item_group_postfix' => ')'
507
  )
508
)));
509

    
510
/**
511
 * Constant for the drupal variable key distribution_map_visibility
512
 *
513
 * possible values:
514
 *  - never
515
 *  - automatic
516
 *  - always
517
 */
518
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
519
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
520

    
521
/**
522
 * Constant for the drupal variable key specimen_map_visibility
523
 *
524
 * possible values:
525
 *  - never
526
 *  - automatic
527
 *  - always
528
 */
529
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
530
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
531

    
532
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
533
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
534
    array(
535
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
536
        'includeOccurrences' => 0,
537
        'includeTaxonNameDescriptions' => 0
538
     )
539
  ));
540

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

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

    
616
    // unserialize if nessecary
617
    if(!is_array($default)){
618
      $default = unserialize($default);
619
    }
620
    $variable = variable_get($variable_name, array());
621
    $result = drupal_array_merge_deep($default, $variable);
622
    return $result;
623
}
624

    
625
/**
626
 * @todo document this function.
627
 */
628
function getGallerySettings($gallery_config_form_name) {
629
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
630
}
631

    
632
/**
633
 * Returns the string representation of the default tab.
634
 *
635
 * @param bool $returnTabIndex
636
 *   Defaults to FALSE, if set true this function will return the index number
637
 *   of the default tab. (used to supply default values to form elements).
638
 */
639
function get_default_taxon_tab($returnTabIndex = FALSE) {
640

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

    
657
  // Return the index value or the string representation.
658
  if ($returnTabIndex) {
659
    return $index_value;
660
  }
661
  else {
662
    return ($values[$index_value]);
663
  }
664
}
665

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

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

    
737
  // ---- DEFAULTS settings
738

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

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

    
810
  // ---- Special DEFAULTS for existing portals
811
  // TODO:
812
  // this can be removed once the feature block
813
  // settings have been deployed for the first time to these portals
814

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

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

    
902
  $cyprus_default = $cichorieae_default;
903
  $cyprus_default[UUID_DISTRIBUTION] = array(
904
    'as_list' => 'div', // currently ignored
905
    'link_to_reference' => 0,
906
    'link_to_name_used_in_source' => 0,
907
    'sources_as_content' => 0,
908
    'sources_as_content_to_bibliography' => 0,
909
    'sort_elements' => NO_SORT, // will cause ...
910
    'glue' => ' ',
911
    'element_tag' => 'div',
912
    'special' => array()
913
  );
914

    
915
  $default_theme = variable_get('theme_default', NULL);
916

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

    
941
  // ---- END of DEFAULTS
942

    
943
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
944

    
945
  $feature_block_setting = null;
946

    
947
  if (isset($saved_settings[$feature_uuid])) {
948
    $feature_block_setting = $saved_settings[$feature_uuid];
949
  }
950
  else if (isset($settings_for_theme[$feature_uuid])) {
951
    $feature_block_setting = $settings_for_theme[$feature_uuid];
952
  }
953
  else if (isset($settings_for_theme['DEFAULT'])) {
954
    $feature_block_setting = $settings_for_theme['DEFAULT'];
955
  }
956

    
957
  // now merge the default and specific settings
958
  $settings_to_merge = array($default['DEFAULT']);
959
  if(is_array($saved_settings)){
960
    $settings_to_merge[] = $saved_settings['DEFAULT'];
961
  }
962
  if(isset($feature_block_setting)){
963
    $settings_to_merge[] = $feature_block_setting;
964
  }
965
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
966

    
967
  return $feature_block_setting;
968
}
969

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

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

    
1026
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
1027
    'title' => 'Cache',
1028
    'description' => 'Cache',
1029
    'access arguments' => array('administer cdm_dataportal'),
1030
    'page callback' => 'drupal_get_form',
1031
    'page arguments' => array('cdm_settings_cache'),
1032
    'weight' => 10,
1033
    'type' => MENU_LOCAL_TASK,
1034
  );
1035

    
1036
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1037
    'title' => 'Geo & Map',
1038
    'description' => 'Geo & Map',
1039
    'access arguments' => array('administer cdm_dataportal'),
1040
    'page callback' => 'drupal_get_form',
1041
    'page arguments' => array('cdm_settings_geo'),
1042
    'weight' => 1,
1043
    'type' => MENU_LOCAL_TASK,
1044
  );
1045

    
1046
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1047
    'title' => 'Layout',
1048
    'description' => 'Configure and adjust the layout of your DataPortal ',
1049
    'access arguments' => array('administer cdm_dataportal'),
1050
    'page callback' => 'drupal_get_form',
1051
    'page arguments' => array('cdm_settings_layout'),
1052
    'weight' => 2,
1053
    'type' => MENU_LOCAL_TASK,
1054
  );
1055

    
1056
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1057
    'title' => 'Taxon page',
1058
    'description' => 'Configure and adjust the layout of your DataPortal ',
1059
    'access arguments' => array('administer cdm_dataportal'),
1060
    'page callback' => 'drupal_get_form',
1061
    'page arguments' => array('cdm_settings_layout_taxon'),
1062
    'weight' => 1,
1063
    'type' => MENU_LOCAL_TASK,
1064
  );
1065
  $items['admin/config/cdm_dataportal/settings/layout/name-page'] = array(
1066
    'title' => 'Name page',
1067
    'description' => 'Configure and adjust the layout of your DataPortal ',
1068
    'access arguments' => array('administer cdm_dataportal'),
1069
    'page callback' => 'drupal_get_form',
1070
    'page arguments' => array('cdm_settings_layout_name_page'),
1071
    'weight' => 1,
1072
    'type' => MENU_LOCAL_TASK,
1073
  );
1074
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1075
    'title' => 'Search',
1076
    'description' => 'Configure and adjust the layout of your DataPortal ',
1077
    'access arguments' => array('administer cdm_dataportal'),
1078
    'page callback' => 'drupal_get_form',
1079
    'page arguments' => array('cdm_settings_layout_search'),
1080
    'weight' => 2,
1081
    'type' => MENU_LOCAL_TASK,
1082
  );
1083

    
1084
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1085
    'title' => 'Media',
1086
    'description' => 'Configure and adjust the layout of your DataPortal ',
1087
    'access arguments' => array('administer cdm_dataportal'),
1088
    'page callback' => 'drupal_get_form',
1089
    'page arguments' => array('cdm_settings_layout_media'),
1090
    'weight' => 3,
1091
    'type' => MENU_LOCAL_TASK,
1092
  );
1093

    
1094
}
1095

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

    
1114
/**
1115
 * Configures the settings form for the CDM-API module.
1116
 *
1117
 * @return array
1118
 *   Drupal settings form.
1119
 */
1120
function cdm_settings_general() {
1121

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

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

    
1140
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1141
    '#type' => 'markup',
1142
    '#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')
1143
      . ' visible only for administrators',
1144
  );
1145

    
1146
  $form['cdm_webservice']['freetext_index'] = array(
1147
    '#type' => 'fieldset',
1148
    '#title' => t('Freetext index'),
1149
    '#collapsible' => FALSE,
1150
    '#collapsed' => FALSE,
1151
  );
1152

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

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

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

    
1206
  $form['cdm_webservice']['proxy'] = array(
1207
    '#type' => 'fieldset',
1208
    '#title' => t('Proxy'),
1209
    '#collapsible' => TRUE,
1210
    '#collapsed' => TRUE,
1211
  );
1212

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

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

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

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

    
1240
  $form['sub_tree_filter'] = array(
1241
    '#type' => 'fieldset',
1242
    '#title' => t('Subtree filter'),
1243
    '#collapsible' => FALSE,
1244
    '#collapsed' => TRUE,
1245
    '#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.'),
1246
  );
1247

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

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

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

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

    
1300
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1301
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1302
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1303
      '#type' => 'checkboxes',
1304
      '#title' => t('Included Classifications') . ':',
1305
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1306
      '#options' => cdm_get_taxontrees_as_options(),
1307
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1308
  );
1309

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

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

    
1344
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1345
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1346
      '#type' => 'checkboxes',
1347
      '#title' => 'Filter rules',
1348
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1349
      '#options' => array(
1350
          'statusOrderPreference' => 'Status order preference rule',
1351
          'subAreaPreference' => 'Sub area preference rule'
1352
      ),
1353
  );
1354

    
1355
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1356
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1357
      '#type' => 'checkboxes',
1358
      '#title' => 'Hide marked area filter',
1359
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1360
      '#options' => $marker_type_options,
1361
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1362
  );
1363

    
1364
  $form['aggregation'] = array(
1365
      '#type' => 'fieldset',
1366
      '#title' => t('Aggregation of data'),
1367
      '#collapsible' => FALSE,
1368
      '#description' => 'This section covers the different aspects of aggregating information.
1369
          <p>
1370
          </p>',
1371
  );
1372

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

    
1385
  $form['aggregation']['notice'] = array(
1386
      '#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
1387
          want to make use of the caching capabilities of the dataportal.',
1388
  );
1389

    
1390
  $form['aggregation']['media_aggregation'] = array(
1391
      '#type' => 'fieldset',
1392
      '#title' => t('Media aggregation'),
1393
      '#collapsible' => FALSE,
1394
      '#collapsed' => TRUE,
1395
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1396

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

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

    
1423
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1424
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1425

    
1426
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1427
      '#type' => 'checkboxes',
1428
      '#title' => t('Direct'),
1429
      '#options' => $taxonRelationshipTypeOptions,
1430
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1431
  );
1432
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1433
      '#type' => 'checkboxes',
1434
      '#title' => t('Invers'),
1435
      '#options' => $taxonRelationshipTypeOptions,
1436
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1437
  );
1438

    
1439
  $form['drupal_integration'] = array(
1440
    '#type' => 'fieldset',
1441
    '#attributes' => array('class'=> array('clearfix')),
1442
    '#title' => t('Drupal integration'),
1443
    '#collapsible' => FALSE,
1444
    '#collapsed' => FALSE,
1445
    '#tree' => FALSE
1446
  );
1447

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

    
1457

    
1458

    
1459
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1460
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1461
    <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>',
1462
  );
1463
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1464
    '#type' => 'submit',
1465
    '#value' => t('Drop all cdm nodes'),
1466
    '#submit' => array('drop_all_cdm_nodes_submit')
1467
  );
1468

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

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

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

    
1505
  $form['#submit'][] = 'cdm_settings_general_submit';
1506

    
1507
  return system_settings_form($form);
1508
}
1509

    
1510
/**
1511
 * Submit callback; drops all cdm nodes.
1512
 *
1513
 * @ingroup forms
1514
 */
1515
function drop_all_cdm_nodes_submit($form, &$form_state) {
1516
  cdm_delete_all_cdm_nodes();
1517
  drupal_set_message(t('All cdm nodes dropped.'));
1518
}
1519

    
1520

    
1521
/**
1522
 * LAYOUT settings
1523
 *
1524
 * @return array
1525
 *   The form structure.
1526
 */
1527
function cdm_settings_layout() {
1528

    
1529
  $form = array();
1530

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

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

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

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

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

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

    
1582

    
1583
  // ---- original source --- //
1584
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1585
      '#type' => 'fieldset',
1586
      '#tree' => TRUE,
1587
      '#title' => t('Source Citations'),
1588
      '#collapsible' => FALSE,
1589
      '#collapsed' => FALSE,
1590
  );
1591

    
1592
  $bibliography_settings = get_bibliography_settings(true);
1593

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

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

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

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

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

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

    
1671
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1672
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1673
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1674
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1675

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

    
1685
  $diff_viewer_markup = '';
1686
  if($is_custom_part_definition){
1687
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1688
  }
1689

    
1690
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1691
    . $which_version_message
1692
    . '</div>'
1693
    . $diff_viewer_markup;
1694

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

    
1784
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1785
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1786
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1787
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1788
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1789

    
1790
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1791
    $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.)';
1792
  } else if($is_custom_render_template){
1793
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1794
  } else {
1795
    $which_version_message = '(These are the default render templates.)';
1796
  }
1797

    
1798
  $diff_viewer_markup = '';
1799
  if($is_custom_render_template){
1800
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1801
  }
1802

    
1803
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1804
    . $which_version_message
1805
    . '</div>'
1806
    . $diff_viewer_markup;
1807

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

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

    
1855
  $form['#submit'] = array('submit_json_as_php_array');
1856
  // #json_elements especially defined for submit_json_as_php_array()
1857
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1858
  return system_settings_form($form);
1859
}
1860

    
1861

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

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

    
1899
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1900
      '#type' => 'checkbox',
1901
      '#title' => t('Show media thumbnails for synonyms'),
1902
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1903
      '#description' => '',
1904
    );
1905
  }
1906

    
1907
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1908
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1909
    '#type' => 'checkbox',
1910
    '#title' => t('Show captions under thumbnails'),
1911
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1912
    '#description' => '',
1913
  );
1914

    
1915
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1916
    '#type' => 'textfield',
1917
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1918
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1919
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1920
  );
1921

    
1922
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1923
    '#type' => 'textfield',
1924
    '#title' => t('Number of columns') . ':',
1925
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1926
    '#description' => t('Group the thumbnails in columns: select how many
1927
      columns the gallery should display.'),
1928
  );
1929

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

    
1941
  return $form;
1942
}
1943

    
1944
/**
1945
 * @return array
1946
 *   The form structure.
1947
 */
1948
function cdm_settings_layout_taxon() {
1949
  $collapsed = FALSE;
1950
  $form = array();
1951

    
1952
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1953

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

    
1963
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1964
    '#type' => 'checkbox',
1965
    '#title' => t('Tabbed taxon page'),
1966
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1967
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1968
  );
1969

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

    
1978
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1979
    '#type' => 'checkboxes',
1980
    '#title' => t('Section/Tab visibility') . ':',
1981
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1982
    '#options' => get_taxon_options_list()
1983
  );
1984

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

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

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

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

    
2047
  // ---- PROFILE PICTURE ----//
2048

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

    
2058
  //FIXME migrate variables:
2059
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2060
  // FIXME
2061
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2062

    
2063
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2064

    
2065
  /*
2066
   * 'show' => 1,
2067
   * 'maxextend' => 184,
2068
   * 'media_uri_query' => ''
2069
   * 'custom_placeholder_image_on' => 1,
2070
   * 'custom_placeholder_image_fid' => ''
2071
   */
2072
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2073
    '#type' => 'checkbox',
2074
    '#title' => t('Enable profile picture'),
2075
    '#description' => t('Show the profile picture.'),
2076
    '#default_value' => $taxon_profile_image_settings['show'],
2077
  );
2078

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

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

    
2103
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2104
    '#type' => 'checkbox',
2105
    '#title' => t('Show the placeholder image'),
2106
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2107
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2108
  );
2109

    
2110
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2111
      '#type' => 'checkbox',
2112
      '#title' => t('Use a custom placeholder image'),
2113
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2114
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2115
  );
2116

    
2117
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2118
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2119
        '#type' => 'managed_file',
2120
        '#title' => t('Custom placeholder image file'),
2121
        '#progress_indicator' => 'bar',
2122
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2123
    //       '#name' => 'custom_placeholder_image',
2124
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2125
    );
2126

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

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

    
2152
  // -- MEDIA THUMBNAILS -- //
2153
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2154
  $form_title = 'Taxon Profile Images';
2155
  $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>';
2156
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2157

    
2158
  // ---- FEATURE TREE BLOCKS ---- //
2159
  $form['taxon_profile']['feature_blocks'] = array(
2160
    '#type' => 'fieldset',
2161
    '#title' => t('Feature Blocks'),
2162
    '#collapsible' => TRUE,
2163
    '#collapsed' => FALSE,
2164
    '#description' => t("This section covers settings related to the taxon's
2165
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2166
      features such as description, distribution, common names"),
2167
  );
2168
  $featureTrees = cdm_get_featureTrees_as_options(TRUE, TRUE);
2169
  $profile_feature_tree = get_profile_feature_tree();
2170
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2171
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2172
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2173
  }
2174
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2175
    '#type' => 'radios',
2176
    '#title' => t('Taxon profile feature tree') . ':',
2177
    '#default_value' => $profile_feature_tree_uuid,
2178
    '#options' =>  $featureTrees['options'],
2179
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2180
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2181
    '#description' => t('The Feature Tree selected defines the type and order 
2182
    of the according feature blocks visible in the taxon profile page. A feature block 
2183
    only is shown if any data for it is present. The block weight is shown after the feature label in brackets'
2184
    ),
2185
  );
2186

    
2187
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
2188
  $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS] = array(
2189
    '#title'  => 'Pseudo feature block weight',
2190
    '#type' => 'fieldset',
2191
    '#collapsible' => false,
2192
    '#tree' => true,
2193
    '#description' => 'Weights for the pseudo feature blocks. The weight value defines the 
2194
    position in the list of blocks. The weight of normal feature is defined by the position 
2195
    of the according feature. Please see the specific feature details above to find the feature weight.'
2196
  );
2197
  foreach ([PSEUDO_FEATURE_NUMBER_OF_TAXA, PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS, PSEUDO_FEATURE_BIBLIOGRAPHY] as $ps_feature) {
2198
    $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS][$ps_feature] = array(
2199
      '#title' => $ps_feature,
2200
      '#type'  => 'textfield',
2201
      '#element_validate' => array('element_validate_number'),
2202
      '#size' => 4,
2203
      '#default_value' => $pseudo_feature_weights[$ps_feature]
2204
    );
2205
  }
2206

    
2207

    
2208
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2209
  $profile_feature_tree = get_profile_feature_tree();
2210

    
2211
  if (isset($profile_feature_tree->root->childNodes)) {
2212

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

    
2255

    
2256
    $feature_list_layout_settings_disabled = FALSE;
2257

    
2258
    // creating helper object to retrieve the default settings
2259
    $featureNode = new stdClass();
2260
    $featureNode->term = new stdClass();
2261
    $featureNode->term->uuid="DEFAULT";
2262
    $featureNode->term->representation_L10n = "Default";
2263
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2264

    
2265
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2266

    
2267
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2268

    
2269
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2270
        $subform_id = $featureNode->term->uuid;
2271
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2272

    
2273
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2274

    
2275
        $form_feature_block_layout[$subform_id] = array(
2276
          '#type' => 'fieldset',
2277
          '#tree' => TRUE,
2278
          '#title' => $featureNode->term->representation_L10n,
2279
          '#collapsible' => FALSE,
2280
          '#collapsed' => FALSE,
2281
        );
2282
        if($featureNode->term->uuid == "DEFAULT"){
2283
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2284
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2285
          references</em> and <em>names in source</em> is only possible in the defaults';
2286
        }
2287

    
2288
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2289
          '#type' => 'select',
2290
          '#title' => 'List type',
2291
          '#default_value' => $feature_block_setting['as_list'],
2292
          '#options' => array(
2293
            'div' => 'not as list',
2294
            'ul' => 'bullet list',
2295
            'ol' => 'numbered list',
2296
            'dl' => 'definition list'
2297
          ),
2298
        );
2299

    
2300
        if($featureNode->term->uuid == "DEFAULT"){
2301
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2302
            '#type' => 'checkbox',
2303
            '#title' => t('Link to reference'),
2304
            '#default_value' => $feature_block_setting['link_to_reference'],
2305
          );
2306

    
2307
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2308
            '#type' => 'checkbox',
2309
            '#title' => 'Link to name used in source',
2310
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2311
          );
2312
        }
2313

    
2314
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2315
          '#type' => 'checkbox',
2316
          '#title' => 'Sources as content',
2317
          '#default_value' => $feature_block_setting['sources_as_content'],
2318
        );
2319

    
2320
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2321
          '#type' => 'checkbox',
2322
          '#title' => 'Put sources also as content to bibliography',
2323
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2324
        );
2325

    
2326
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2327
          '#type' => 'select',
2328
          '#title' => t('Sort elements'),
2329
          '#default_value' => $feature_block_setting['sort_elements'],
2330
          '#options' => array(
2331
            NO_SORT => 'No sorting',
2332
            SORT_ASC => 'Ascending',
2333
            SORT_DESC => 'Descending',
2334
            SORT_HIERARCHICAL => 'Hierarchical'
2335
          ),
2336
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2337
          <dl>
2338
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2339
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2340
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2341
          <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>
2342
          </dl>',
2343
        );
2344

    
2345
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2346
          '#type' => 'select',
2347
          '#title' => t('Element tag'),
2348
          '#options' => array(
2349
            'span' => 'span',
2350
            'div' => 'div',
2351
            'p' => 'p'
2352
          ),
2353
          '#default_value' => $feature_block_setting['element_tag'],
2354
        );
2355
        $form_feature_block_layout[$subform_id]['glue'] = array(
2356
          '#type' => 'textfield',
2357
          '#title' => t('Element glue'),
2358
          '#default_value' => $feature_block_setting['glue'],
2359
          '#size' => 10
2360
      );
2361

    
2362
      }
2363
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2364
    }
2365
  }
2366

    
2367
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2368
  $form['taxon_profile']['structured_description_featuretree'] = array(
2369
    '#type' => 'fieldset',
2370
    '#title' => t('Structured Description Feature Tree'),
2371
    '#collapsible' => TRUE,
2372
    '#collapsed' => FALSE,
2373
  );
2374
  $featureTrees = cdm_get_featureTrees_as_options();
2375
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2376
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2377
    $profile_feature_tree_uuid = NULL;
2378
  }
2379
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2380
    '#type' => 'radios',
2381
    '#title' => t('Natural language representation of structured descriptions') . ':',
2382
    '#default_value' => $profile_feature_tree_uuid,
2383
    '#options' => $featureTrees['options'],
2384
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2385
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2386
    '#description' => t('Taxon descriptions can be stored in a highly structured
2387
      form. The feature tree selected here will be used to generate textual
2388
      representation in natural language.'
2389
    ),
2390
  );
2391

    
2392

    
2393

    
2394
  // ---- DISTRIBUTION LAYOUT ---- //
2395
  $form['taxon_profile']['distribution_layout'] = array(
2396
    '#title' => t('Distribution'),
2397
    '#collapsible' => TRUE,
2398
    '#collapsed' => FALSE,
2399
    '#type' => 'fieldset',
2400
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2401
        Map settings regarding the geometry, layers, etc are found in the '
2402
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2403
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2404
      . l(
2405
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2406
        array('fragment' => 'edit-feature-block-settings')
2407
      )
2408
      . ' More general settings regrading the filtering of Distributions are found at '
2409
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2410
      . '. (These settings here will be merged in future releases into the feature block settings)',
2411

    
2412
  );
2413

    
2414
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2415

    
2416
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2417
    '#type' => 'checkbox',
2418
    '#title' => t('Condensed distribution'),
2419
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2420
    '#description' => 'This option enables the display of a very compact representation
2421
    of the distribution which includes also information on the status.',
2422
  );
2423

    
2424
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2425
    '#type' => 'select',
2426
    '#title' => t('Condensed distribution recipe'),
2427
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2428
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2429
    '#description' => 'Recipe for creating the condensed distribution.',
2430
  );
2431

    
2432
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2433
    '#type' => 'textfield',
2434
    '#title' => t('Condensed distribution info path'),
2435
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2436
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2437
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2438
  );
2439

    
2440

    
2441
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2442
    '#type' => 'radios',
2443
    '#title' => t('Display mode') . ':',
2444
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2445
    '#options' => array(
2446
      'FLAT_ALPHA' => t('Flat list'),
2447
      'TREE' => t('Hierarchically ordered'),
2448
    ),
2449
    '#description' => 'Taxon distribution information is displayed with
2450
    focus on the area of the distribution. The list of areas can either be shown
2451
    as flat list ordered alphabetically or in the hierarchical of the parent
2452
    area and subarea relationship. Fall back areas areas with no Distribution data
2453
    are hidden from the area hierarchy so that their sub areas will move one level up.
2454
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2455
    ' for details on the <em>Marked area filter</em>.',
2456
  );
2457

    
2458
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2459
    '#type' => 'fieldset',
2460
    '#tree' => true,
2461
    '#title' => t('Distribution hierarchy style')
2462
  );
2463

    
2464
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2465
  foreach(array_keys($hierarchy_styles) as $level) {
2466
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2467
      '#type' => 'fieldset',
2468
      '#tree' => true,
2469
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2470
      '#attributes' => array('class' => array('fieldset-float'))
2471
    );
2472
    foreach ($hierarchy_styles[$level] as $key => $value) {
2473
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2474
        '#type' => 'textfield',
2475
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2476
        '#default_value' => $hierarchy_styles[$level][$key],
2477
        '#maxlength' => 4,
2478
        '#size' => 4
2479
      );
2480
    }
2481
  }
2482

    
2483
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2484
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2485
    '#type' => 'checkboxes',
2486
    '#title' => 'Omit area levels',
2487
    '#options' => $level_options,
2488
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2489
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2490
    Areas which belong to the selected area levels will be hidden in the portal.',
2491
  );
2492

    
2493
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2494
    '#type' => 'checkbox',
2495
    '#title' => t('Show TextData elements on top of the map'),
2496
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2497
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2498
      elements on top of the map. Otherwise all <code>TextData</code>
2499
      distribution elements will be listed below the other area elements.
2500
      This option is useful if you need to have descriptive texts for each
2501
      distribution map.'),
2502
  );
2503

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

    
2531
AbsenceTerm
2532
a	absent
2533
f	reported in error
2534
nf	native: reported in error
2535
if	introduced: reported in error
2536
cf	cultivated: reported in error
2537
ne	native: formerly native
2538
ie	introduced: formerly introduced
2539

    
2540
</pre>'),
2541
  );
2542

    
2543

    
2544
  /* ====== SYNONYMY ====== */
2545
  $form['taxon_synonymy'] = array(
2546
    '#type' => 'fieldset',
2547
    '#title' => t('Taxon synonymy (tab)'),
2548
    '#collapsible' => TRUE,
2549
    '#collapsed' => TRUE,
2550
    '#description' => t('This section covers the settings related to the taxon
2551
      <strong>synonymy</strong> tab.'),
2552
  );
2553

    
2554
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2555
    '#type' => 'checkbox',
2556
    '#title' => t('Accepted taxon on top of the synonymy'),
2557
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2558
    '#description' => t('If checked, the first homotypic taxon is a repetition
2559
      of the accepted taxon most likely with the full nomenclatural reference, 
2560
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2561
  );
2562

    
2563
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2564
    '#type' => 'checkbox',
2565
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2566
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2567
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2568
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2569
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2570
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE)
2571
  );
2572

    
2573
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2574
    '#type' => 'textfield',
2575
    '#description' => 'Label for the secundum referenence.',
2576
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2577
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2578
    );
2579

    
2580
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2581
    '#type' => 'checkbox',
2582
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2583
      coming from a synonym link.'),
2584
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2585
    '#description' => t('Check this if after doing a search and clicking on a
2586
      synonym you want to see the "accept of" text for the accepted synonym.'),
2587
  );
2588

    
2589
  $form['taxon_synonymy']['taxon_relations'] = array(
2590
    '#type' => 'fieldset',
2591
    '#title' => t('Taxon relationships'),
2592
    '#collapsible' => FALSE,
2593
    '#collapsed' => FALSE
2594
  );
2595

    
2596
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2597
    '#type' => 'checkbox',
2598
    '#title' => t('Show taxon relations ships of accepted taxon'),
2599
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2600
    '#description' => t('If this option is enabled the synonymy will show the
2601
      below selected taxon relationships of accepted taxa.'),
2602
  );
2603

    
2604
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2605
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2606
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2607
    '#type' => 'checkboxes',
2608
    '#title' => t('Taxon relationship types') . ':',
2609
    '#description' => 'Only taxon relationships of the selected type will be displayed',
2610
    '#options' => $taxon_relationship_type_options,
2611
    '#default_value' => $taxon_relationship_type_defaults,
2612
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2613
  );
2614

    
2615
  $form['taxon_synonymy']['name_relations'] = array(
2616
    '#type' => 'fieldset',
2617
    '#title' => t('Name relationships'),
2618
    '#collapsible' => FALSE,
2619
    '#collapsed' => FALSE
2620
  );
2621

    
2622
  $name_relationship_type_options = cdm_vocabulary_as_option(
2623
      UUID_NAME_RELATIONSHIP_TYPE,
2624
      '_cdm_relationship_type_term_label_callback',
2625
      false,
2626
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2627
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2628
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2629
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2630
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2631
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2632
  );
2633
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2634
    '#type' => 'checkboxes',
2635
    '#title' => t('Name relationship types') . ':',
2636
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2637
    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') . '.',
2638
    '#options' => $name_relationship_type_options,
2639
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2640
  );
2641

    
2642
  // ====== SPECIMENS ====== //
2643
  $form['taxon_specimens'] = array(
2644
    '#type' => 'fieldset',
2645
    '#title' => t('Taxon specimens (tab)'),
2646
    '#collapsible' => TRUE,
2647
    '#collapsed' => TRUE,
2648
    '#description' => t('This section covers the settings related to the taxon
2649
      <strong>specimens</strong> tab.'),
2650
  );
2651

    
2652
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2653

    
2654
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2655
    '#type' => 'checkbox',
2656
    '#title' => t('Show specimen derivatives in a compressed table'),
2657
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2658
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2659
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2660
  );
2661

    
2662
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2663
      '#type' => 'textfield',
2664
      '#title' => t('Number of records per page') . ':',
2665
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2666
  );
2667

    
2668
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2669
        '#type' => 'checkbox',
2670
        '#title' => t('Show specimen derivatives in a tree view'),
2671
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2672
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2673
    );
2674

    
2675

    
2676
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2677
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2678
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2679
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2680
  }
2681
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2682
    '#type' => 'radios',
2683
    '#title' => t('Specimen description feature tree') . ':',
2684
    '#default_value' => $profile_feature_tree_uuid,
2685
    '#options' =>  $featureTrees['options'],
2686
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2687
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2688
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2689
    ),
2690
  );
2691

    
2692
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2693
  $form_title = t('Specimen media');
2694
  $form_description = t('Specimens may have media which is displayed at the
2695
     Specimen tab/section as a gallery. It is possible to configure the
2696
     thumbnails gallery here, however for configuring how a single media should
2697
     be displayed please go to !url.</p>',
2698
     array(
2699
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2700
     ));
2701
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2702

    
2703
  // --- MEDIA GALLERY ---- //
2704
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2705
  $form_title = 'Media gallery (tab)';
2706
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2707
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2708
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2709
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2710
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2711
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2712
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2713

    
2714
  // Comment @WA: D7 form api does not support reset buttons,
2715
  // so to mimic the D5 reset button we add one like this.
2716
  $form['actions']['reset'] = array(
2717
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2718
    '#weight' => 1000,
2719
  );
2720
  return system_settings_form($form);
2721
}
2722

    
2723
/**
2724
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2725
 *
2726
 * @param $map_id
2727
 * @param $form
2728
 * @return mixed
2729
 */
2730
function _cdm_map_visibility_setting($map_id)
2731
{
2732
  return array(
2733
    '#type' => 'select',
2734
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2735
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2736
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2737
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2738
        The map also can forced to show up <b>always</b> or <b>never</b>."
2739
  );
2740
}
2741

    
2742
/**
2743
 * @return array
2744
 *   The form structure.
2745
 */
2746
function cdm_settings_layout_search() {
2747

    
2748
  $form = array();
2749

    
2750
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2751

    
2752
  $form['search_settings'] = array(
2753
    '#type' => 'fieldset',
2754
    '#title' => t('Taxa Search'),
2755
    '#collapsible' => FALSE,
2756
    '#collapsed' => FALSE,
2757
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2758
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2759
         where they can write the text to be searched. You can find Drupal block configuration
2760
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2761
  );
2762

    
2763
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2764
      '#type' => 'checkbox',
2765
      '#title' => t('Ignore the chosen classification in simple search'),
2766
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2767
      '#description' => t('The simple search, which can be executed via the search block,
2768
          will by default search on the classification selected in the classification browser
2769
          selector. Set the tick if you want your portal to search on all classifications.'),
2770
  );
2771

    
2772
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2773
    '#type' => 'checkbox',
2774
    '#title' => t('Run simple search with free-text search backend.'),
2775
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2776
    '#description' => t('The simple search uses by default another search
2777
      backend as the advances search. By checking this option the simple search can be
2778
      configured to also use the free-text search backend.'),
2779
  );
2780

    
2781
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2782
    '#type' => 'checkbox',
2783
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2784
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2785
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2786
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2787
  );
2788

    
2789
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2790
    '#type' => 'textfield',
2791
    '#title' => t('Results per page') . ':',
2792
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2793
    '#description' => t('Number of results to display per page.'),
2794
  );
2795

    
2796
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2797
    '#type' => 'checkbox',
2798
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2799
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2800
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2801
  );
2802

    
2803
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2804
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2805
      '#type' => 'checkboxes',
2806
      '#title' => 'Search mode',
2807
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2808
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2809
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2810
          defaults set here.',
2811
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2812
      '#default_value' => $search_mode_default
2813
      );
2814

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

    
2820
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2821
  );
2822

    
2823
    $form['blast_search_settings'] = array(
2824
        '#type' => 'fieldset',
2825
        '#title' => t('Blast Search'),
2826
        '#collapsible' => TRUE,
2827
        '#collapsed' => TRUE,
2828
        '#description' => t('<p>To perform blast searchs
2829
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2830
         where they can write the text to be searched. You can find Drupal block configuration
2831
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2832
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2833
    );
2834

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

    
2840
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2841
    );
2842
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2843
        '#type' => 'textfield',
2844
        '#title' => t('Webservice URL for blast search') . ':',
2845
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2846

    
2847
        '#description' => t('Enter the webservice URL for blast search'),
2848
    );
2849

    
2850
  // --- SEARCH TAXA GALLERY ---- //
2851
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2852
  $collapsed = FALSE;
2853
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2854
  $form_title = 'Taxa Search thumbnails';
2855
  $form_description = 'Search results may show thumbnails. ';
2856
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2857

    
2858
  // Comment @WA: D7 form api does not support reset buttons,
2859
  // so to mimic the D5 reset button we add one like this.
2860
  $form['actions']['reset'] = array(
2861
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2862
    '#weight' => 1000,
2863
  );
2864
  return system_settings_form($form);
2865
}
2866

    
2867

    
2868
/**
2869
 * @return array
2870
 *   The form structure.
2871
 */
2872
function cdm_settings_layout_name_page()
2873
{
2874

    
2875
  $form = array();
2876

    
2877

    
2878
  $form['name_relations'] = array(
2879
    '#type' => 'fieldset',
2880
    '#title' => t('Name relationship listings'),
2881
    '#collapsible' => FALSE,
2882
    '#collapsed' => FALSE
2883
  );
2884

    
2885
  $name_relationship_type_options = cdm_vocabulary_as_option(
2886
    UUID_NAME_RELATIONSHIP_TYPE,
2887
    '_cdm_relationship_type_term_label_callback',
2888
    false
2889
  );
2890
  $form['name_relations'][CDM_NAME_RELATIONSHIP_LIST_TYPES] = array(
2891
    '#type' => 'checkboxes',
2892
    '#title' => t('Name relationship types') . ':',
2893
    '#description' => 'This setting only affects specific types of name relations which are displayed as list. Another representations 
2894
    is the inline style used in the synonymy which may show a different (reduced) set of name relations. 
2895
    The according settings can be adjusted in the ' . l('taxon page settings section synonmy', 'admin/config/cdm_dataportal/settings/layout/taxon') . '.',
2896
    '#options' => $name_relationship_type_options,
2897
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE)),
2898
  );
2899

    
2900
  $form[CDM_NAME_PAGE_SECTION_TAXA] = array (
2901
    '#type' => 'checkbox',
2902
    '#title' => 'Show the associated taxa section',
2903
    '#default_value' => variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT)
2904

    
2905
  );
2906

    
2907
  return system_settings_form($form);
2908
}
2909

    
2910
/**
2911
 * @return array
2912
 *   The form structure.
2913
 */
2914
function cdm_settings_layout_media() {
2915

    
2916
  $form = array();
2917

    
2918
  $form['media_settings'] = array(
2919
    '#type' => 'fieldset',
2920
    '#title' => t('Media settings'),
2921
    '#collapsible' => FALSE,
2922
    '#collapsed' => FALSE,
2923
    '#description' => 'This section covers layout settings for media pages.'
2924
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2925
  );
2926

    
2927
  $form['media_settings'][CDM_MEDIA_GALLERY_VIEWER] = array(
2928
    '#type' => 'select',
2929
    '#title' => t('Image viewer') . ':',
2930
    '#default_value' => variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT),
2931
    '#options' => array(
2932
      CDM_MEDIA_GALLERY_VIEWER_DEFAULT => t('Universalviewer (new default)'),
2933
      'fsi' => t('FSI viewer (requires FSI server!)'),
2934
      'default' => t('Standard image viewer (deprecated)'),
2935
    ),
2936
  );
2937

    
2938
  // --- STANDARD_IMAGE_VIEWER ---- //
2939
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, 'default') == 'default') {
2940
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2941
      '#type' => 'fieldset',
2942
      '#tree' => true,
2943
      '#title' => t('Standard image viewer settings'),
2944
      '#collapsible' => FALSE,
2945
      '#collapsed' => FALSE,
2946
      );
2947

    
2948
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2949
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2950
      '#type' => 'checkbox',
2951
      '#title' => 'Show media representations',
2952
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2953

    
2954
    );
2955
  }
2956

    
2957

    
2958
  // @WA: D7 form api does not support reset buttons,
2959
  // so to mimic the D5 reset button we add one like this.
2960
  $form['actions']['reset'] = array(
2961
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2962
    '#weight' => 1000,
2963
  );
2964
  return system_settings_form($form);
2965
}
2966

    
2967
/**
2968
 * GEOSERVICE and Map settings.
2969
 *
2970
 *  @return array
2971
 *   The form structure.
2972
 */
2973
function cdm_settings_geo($form, &$form_state) {
2974

    
2975
  $current_geoserver_settings = get_edit_map_service_settings();
2976
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2977

    
2978

    
2979
  $form = array();
2980

    
2981
  $dummy_distribution_query = NULL;
2982
  if($map_distribution['map_type'] != 1){
2983
    // we need to apply a dummy query since the map service requires for image maps
2984
    // at least as and ad to be defined
2985
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2986
  }
2987

    
2988
  $form['map_preview'] = array(
2989
      '#type' => 'fieldset',
2990
      '#tree' => FALSE,
2991
      '#title' => t('Map preview'),
2992
      '#collapsible' => FALSE,
2993
      '#description' => 'The preview of the map'
2994
       . ($dummy_distribution_query != null ?
2995
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2996
           '.<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.')
2997
  );
2998
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2999
    'move' => "this.cdmOpenlayersMap.printInfo",
3000
    '#execute' => "this.cdmOpenlayersMap.printInfo"
3001
  ), true // resizable
3002
  );
3003

    
3004
  /*
3005
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
3006
  );
3007
  */
3008

    
3009
  /*
3010
   * GEO SERVER
3011
   */
3012
  $form['edit_map_server'] = array(
3013
    '#type' => 'fieldset',
3014
    '#tree' => true,
3015
    '#title' => t('EDIT map service'),
3016
    '#collapsible' => TRUE,
3017
    '#collapsed' => TRUE,
3018
    '#description' => t('Configuration and selection of your geo server.
3019
      The Geo Server is responsible for generating the maps.'),
3020
  );
3021

    
3022
  $form['edit_map_server']['base_uri'] = array(
3023
    '#type' => 'select',
3024
    '#title' => t('EDIT map service') . ':',
3025
    '#default_value' => $current_geoserver_settings['base_uri'],
3026
    '#options' => unserialize(EDIT_MAPSERVER_URI),
3027
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
3028
  );
3029
  $form['edit_map_server']['version'] = array(
3030
      '#type' => 'select',
3031
      '#title' => t('Version') . ':',
3032
      '#default_value' => $current_geoserver_settings['version'],
3033
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
3034
      '#description' => t('The version of the EDIT map services'),
3035
  );
3036

    
3037
  /*
3038
   * MAP SETTINGS
3039
   */
3040

    
3041
  $form[CDM_MAP_DISTRIBUTION] = array(
3042
    '#type' => 'fieldset',
3043
    '#tree' => TRUE,
3044
    '#title' => t('Maps settings'),
3045
    '#collapsible' => TRUE,
3046
    '#collapsed' => TRUE,
3047
    '#description' => t('General configuration for all map types.'),
3048
  );
3049

    
3050
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
3051
    '#type' => 'radios',
3052
    '#title' => 'Map types',
3053
    '#options' => array(
3054
      1 => "OpenLayers dynamic map viewer",
3055
      0 => "Plain image",
3056
    ),
3057
    '#default_value' => $map_distribution['map_type'],
3058
    '#description' => 'Two different map types are available :
3059
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
3060
      which allows zooming and panning. If enabled you can configure the default layer
3061
      (background of your maps) below.</li>
3062
      <li><em>Plain image</em>: The map will be static non interactive
3063
      image.</li></ul>',
3064
  );
3065
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
3066

    
3067
  /*
3068
   * settings for the distribution map are used also for specimens map!!!!
3069
   */
3070

    
3071
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
3072
      '#type' => 'textfield',
3073
      '#title' => 'Aspect ratio',
3074
      '#default_value' => $map_distribution['aspect_ratio'],
3075
      '#maxlength' => 4,
3076
      '#size' => 4,
3077
      '#element_validate' => array('element_validate_number'),
3078
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
3079
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
3080
      width by the height:</br>
3081
      <pre>aspect ratio = w / h</pre>
3082
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
3083
      for a square map use <strong>1</strong>.',
3084
  );
3085

    
3086
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
3087
    '#type' => 'textfield',
3088
    '#title' => 'Bounding box',
3089
    '#default_value' => $map_distribution['bbox'],
3090
    '#description' =>
3091
      'The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps. The bbox must be given in coordinates of the projection of the chosen layer. 
3092
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
3093
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
3094
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
3095
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong class="layer-value">map extent bbox</strong></span> from the details information.
3096
      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
3097
      below the map from where you can copy the bbox string.</p>',
3098
  );
3099

    
3100
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
3101
    '#type' => 'select',
3102
    '#title' => 'Max zoom level',
3103
    '#default_value' => $map_distribution['maxZoom'],
3104
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
3105
  );
3106

    
3107
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
3108
    '#type' => 'checkbox',
3109
    '#title' => 'Display area labels',
3110
    '#default_value' => $map_distribution['show_labels'],
3111
    '#description' => t('The map will show name labels of the areas'),
3112
  );
3113

    
3114
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
3115
    '#type' => 'textfield',
3116
    '#title' => 'Map caption',
3117
    '#default_value' => $map_distribution['caption'],
3118
    '#description' => t('The caption will be shown below the map.'),
3119
  );
3120

    
3121
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
3122
    '#type' => 'textfield',
3123
    '#title' => 'Distribution layer opacity',
3124
    '#default_value' => $map_distribution['distribution_opacity'],
3125
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
3126
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
3127
  );
3128

    
3129
  // --- Plain Image Settings --- //
3130
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
3131
    '#type' => 'fieldset',
3132
    '#title' => 'Plain image map settings',
3133
    '#tree' => TRUE,
3134
    '#collapsible' => TRUE,
3135
    '#collapsed' => $open_layers_is_enabled,
3136
    '#description' => 'The settings in this section are still expertimental
3137
      and can only be used with the EDIT map service version 1.1 or above.',
3138
  );
3139
  $edit_mapserver_version = get_edit_map_service_version_number();
3140
  if ($edit_mapserver_version < 1.1) {
3141
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
3142
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
3143
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
3144
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3145
  }
3146

    
3147
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3148
    '#type' => 'textfield',
3149
    '#title' => 'Width',
3150
    '#default_value' => $map_distribution['image_map']['width'],
3151
    '#maxlength' => 4,
3152
    '#size' => 4,
3153
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3154
  );
3155

    
3156
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3157
    '#type' => 'textfield',
3158
    '#title' => 'Background layer',
3159
    '#default_value' => $map_distribution['image_map']['base_layer'],
3160
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3161
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3162
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3163
    )),
3164
  );
3165

    
3166
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3167
    '#type' => 'textfield',
3168
    '#title' => 'Background color',
3169
    '#default_value' => $map_distribution['image_map']['bg_color'],
3170
  );
3171

    
3172
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3173
    '#type' => 'textfield',
3174
    '#title' => 'Background layer style',
3175
     // Only line color by now.
3176
    '#default_value' => $map_distribution['image_map']['layer_style'],
3177
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3178
  );
3179

    
3180
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3181
      '#type' => 'textfield',
3182
      '#title' => 'Projection',
3183
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3184
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3185
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3186
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3187
  );
3188

    
3189

    
3190
  // --- OpenLayers Settings --- //
3191
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3192
    '#type' => 'fieldset',
3193
    '#title' => 'OpenLayers settings',
3194
    '#tree' => TRUE,
3195
    '#collapsible' => TRUE,
3196
    '#collapsed' => !$open_layers_is_enabled,
3197
    '#description' => '',
3198
  );
3199

    
3200

    
3201
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3202
      '#type' => 'checkbox',
3203
      '#title' => 'Display outside max extent',
3204
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3205
      '#description' => t('Allows the map to display parts of the layers which are outside
3206
         the max extent if the aspect ratio of the map and of the baselayer
3207
         are not equal.'),
3208
  );
3209

    
3210

    
3211
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3212
      '#type' => 'checkbox',
3213
      '#title' => 'Show Layer Switcher',
3214
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3215
      '#description' => 'The Layer Switcher control displays a table of contents
3216
      for the map.  This allows the user interface to switch between
3217
      base layers and to show or hide overlays.  By default the switcher is
3218
      shown minimized on the right edge of the map, the user may expand it
3219
      by clicking on the handle.',
3220
  );
3221

    
3222
  if (!$open_layers_is_enabled) {
3223
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3224
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3225
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3226
  }
3227

    
3228
  // The default layer must always be enabled
3229
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3230
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3231

    
3232
  $baselayer_options = array(
3233
    /*
3234
   NOTICE: must correspond to the layers defined in
3235
   js/openlayers_,ap.js#getLayersByName()
3236
   */
3237
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3238
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3239
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3240
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3241
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3242
    // all others EPSG:900913
3243
    'mapnik' => 'OpenStreetMap (mapnik)',
3244
    'stamen_terrain' => 'Stamen Terrain',
3245
    'open_topomap' => 'OpenTopoMap',
3246
    // map quest is no longer free. it is required to sign up for a test plan.
3247
    // 'mapquest_open' => "MapQuest",
3248
    // 'mapquest_sat' => "MapQuest Sattelite",
3249
    'groadmap' => 'Google Roadmap',
3250
    'gsatellite' => 'Google Satellite',
3251
    'ghybrid' => 'Google Hybrid',
3252
    'gterrain' => 'Google Terrain',
3253
//     'veroad' => 'Virtual Earth Roads',
3254
//     'veaer' => 'Virtual Earth Aerial',
3255
//     'vehyb' => 'Virtual Earth Hybrid',
3256
    // 'yahoo' => 'Yahoo Street',
3257
    // 'yahoosat' => 'Yahoo Satellite',
3258
    // 'yahoohyb' => 'Yahoo Hybrid',
3259
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3260
  );
3261

    
3262
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3263
    '#type' => 'checkboxes_preferred',
3264
    '#title' => 'Base Layers',
3265
    '#options' => $baselayer_options,
3266
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3267
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3268
  );
3269

    
3270
  $google_maps_api_key = null;
3271
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3272
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3273
  }
3274
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3275
    '#type' => 'textfield',
3276
    '#title' => 'Google Maps API Key',
3277
    '#default_value' => $google_maps_api_key,
3278
    '#description' => 'In order to use any of the Google map layers you need to provide 
3279
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3280
  );
3281

    
3282
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3283
    $map_distribution['openlayers']['custom_wms_base_layer'],
3284
    'Custom WMS base layer',
3285
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3286
    true // add projection settings
3287
    );
3288

    
3289
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3290
    $map_distribution['openlayers']['wms_overlay_layer'],
3291
    'WMS overlay layer',
3292
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3293
                You can actually combine multiple layers for this overlay. 
3294
                For details please refer to the wms query parameter <code>Layers</code> .'
3295
  );
3296

    
3297
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3298
    '#type' => 'checkbox',
3299
    '#title' => 'Enable overlay layer',
3300
    '#weight' => -100,
3301
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3302
  );
3303

    
3304
  /*
3305
   * Map Legend
3306
   */
3307
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3308
    '#type' => 'fieldset',
3309
    '#title' => 'Map legend',
3310
    '#tree' => TRUE,
3311
    '#collapsible' => TRUE,
3312
    '#collapsed' => TRUE,
3313
    '#description' => 'Configure the maps legend.',
3314
  );
3315

    
3316
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3317
    '#type' => 'checkbox',
3318
    '#title' => 'Display a map legend',
3319
    '#default_value' => $map_distribution['legend']['show'],
3320
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3321
  );
3322

    
3323
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3324
    '#type' => 'textfield',
3325
    '#title' => 'Legend opacity',
3326
    '#default_value' => $map_distribution['legend']['opacity'],
3327
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3328
                         to 0.0 will be not much visible.',
3329
  );
3330

    
3331
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3332
    '#type' => 'textfield',
3333
    '#title' => 'Font size',
3334
    '#default_value' => $map_distribution['legend']['font_size'],
3335
    '#description' => 'Font size in pixels.',
3336
  );
3337

    
3338
  $fontStyles = array(
3339
    0 => "plane",
3340
    1 => "italic",
3341
  );
3342
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3343
    '#type' => 'select',
3344
    '#title' => 'Available font styles',
3345
    '#default_value' => $map_distribution['legend']['font_style'],
3346
    '#options' => $fontStyles,
3347
    '#description' => 'Select a font style for the map legend.',
3348
  );
3349

    
3350
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3351
    '#type' => 'textfield',
3352
    '#title' => 'Icon width',
3353
    '#default_value' => $map_distribution['legend']['icon_width'],
3354
    '#description' => 'Legend icon width in pixels.',
3355
  );
3356
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3357
    '#type' => 'textfield',
3358
    '#title' => 'Icon height',
3359
    '#default_value' => $map_distribution['legend']['icon_height'],
3360
    '#description' => 'Legend icon height in pixels.',
3361
  );
3362

    
3363
  // @WA: D7 form api does not support reset buttons,
3364
  // so to mimic the D5 reset button we add one like this.
3365
  $form['actions']['reset'] = array(
3366
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3367
    '#weight' => 1000,
3368
  );
3369

    
3370
  return system_settings_form($form);
3371
}
3372

    
3373
/**
3374
 * @param $default_settings
3375
 * @param $title
3376
 * @param $description
3377
 * @param bool $add_projection_settings
3378
 * @return array
3379
 */
3380
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3381
{
3382
  $form_elements = array(
3383
    '#type' => 'fieldset',
3384
    '#title' => $title,
3385
    '#tree' => TRUE,
3386
    '#collapsible' => FALSE,
3387
    '#collapsed' => FALSE,
3388
    '#description' => $description,
3389
  );
3390

    
3391
  $form_elements['name'] = array(
3392
    '#type' => 'textfield',
3393
    '#title' => 'Layer name',
3394
    '#default_value' => $default_settings['name'],
3395
    '#description' => 'A arbitrary name for the layer.',
3396
  );
3397
  $form_elements['url'] = array(
3398
    '#type' => 'textfield',
3399
    '#title' => 'WMS url',
3400
    '#default_value' => $default_settings['url'],
3401
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3402
  );
3403
  $form_elements['untiled'] = array(
3404
    '#type' => 'checkbox',
3405
    '#title' => 'Untiled',
3406
    '#default_value' => $default_settings['untiled'],
3407
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3408
  );
3409
  $form_elements['params'] = array(
3410
    '#type' => 'textarea',
3411
    '#title' => 'WMS parameters',
3412
    '#element_validate' => array('form_element_validate_json'),
3413
    '#default_value' => $default_settings['params'],
3414
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3415
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3416
      . '), entered in valid JSON. For example:
3417
<pre> {
3418
  "Layers": "topp:em_tiny_jan2003",
3419
  "Format": "image/png",
3420
  "BGCOLOR": "0xe0faff"
3421
}
3422
</pre>
3423
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3424
  );
3425

    
3426
  if($add_projection_settings){
3427

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

    
3493
  }
3494
  return $form_elements;
3495
}
3496

    
3497

    
3498
/**
3499
 * @return array
3500
 *   The form structure.
3501
 */
3502
function cdm_settings_cache() {
3503

    
3504
  $form = array();
3505

    
3506
  $form['cache_settings'] = array(
3507
    '#type' => 'fieldset',
3508
    '#title' => t('Cache Settings'),
3509
    '#collapsible' => FALSE,
3510
    '#collapsed' => FALSE,
3511
    '#description' => t('<p>When caching is enabled all single taxon sites are
3512
      stored in an internal drupal cache doing the portal response of taxa pages
3513
      faster. This is possible because the sites are loaded from the cache and
3514
      are not created from scratch.</p>'),
3515
  );
3516

    
3517
  $form['cache_settings']['cdm_webservice_cache'] = array(
3518
    '#type' => 'checkbox',
3519
    '#title' => t('<strong>Enable caching</strong>'),
3520
    '#options' => cdm_help_general_cache(),
3521
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3522
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3523
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3524
       application the changes will be not visible till the cache is erased.
3525
       Therefore developers should deactived this feature when they are working
3526
       on the CDM Dataportal Module.</p>'),
3527
  );
3528

    
3529
  $form['cache_settings']['cdm_run_cache'] = array(
3530
    '#markup' => cdm_view_cache_site(),
3531
  );
3532

    
3533
  // @WA: D7 form api does not support reset buttons,
3534
  // so to mimic the D5 reset button we add one like this.
3535
  $form['actions']['reset'] = array(
3536
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3537
    '#weight' => 1000,
3538
  );
3539
  return system_settings_form($form);
3540
}
3541

    
3542
/**
3543
 * Walk and cache all taxon pages.
3544
 */
3545
function cdm_view_cache_site() {
3546

    
3547
  $out = '';
3548

    
3549
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3550

    
3551
  $request_params = array();
3552
  $request_params['class'] = "Taxon";
3553

    
3554
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3555
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3556
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3557

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

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

    
3567
  // Comment @WA: A form within a form is not valid html and not needed here.
3568
  // Also, it would be recommended just to include this part of the form in the
3569
  // rest of the form array in cdm_settings_cache().
3570
  // $out .= '<form id="cache_site">';
3571
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3572
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3573
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3574
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3575
  // $out .= '</form>';
3576
  $out .= '</div>';
3577
  /*
3578
  foreach($taxonPager->records as $taxon){
3579
    cdm_dataportal_taxon_view($uuid);
3580
  }
3581
  */
3582
  return $out;
3583
}
3584

    
3585

    
3586
function cdm_settings_layout_taxon_submit($form, &$form_state){
3587
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3588
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3589
    if(is_object($file)){
3590
      $file->status = FILE_STATUS_PERMANENT;
3591
      file_save($file);
3592
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3593
    }
3594
  }
3595
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3596
  $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]);
3597
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3598
  if($tab_lables_modified || $tabs_enabled_modified){
3599
    // we first need to set the variable to persist the changes setting
3600
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3601
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3602
    menu_rebuild();
3603
  }
3604
}
3605

    
3606
function cdm_settings_layout_search_submit($form, &$form_state){
3607
  // the visibility of media thumbnails also affects the ui of the search results
3608
  // so reset the according session variable
3609
  //    1. in order to give the user immediate
3610
  //       feedback on potential setting changes
3611
  //    2. let refresh the default if it has changed
3612
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3613
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3614
  }
3615
}
3616

    
3617
/**
3618
 * Form validation handler for cdm_settings_general
3619
 *
3620
 * @param $form
3621
 * @param $form_state
3622
 */
3623
function cdm_settings_general_validate($form, &$form_state) {
3624

    
3625
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3626
    $form_state['values']['cdm_webservice_url'] .= '/';
3627
  }
3628

    
3629
}
3630

    
3631
/**
3632
 * Form submit handler for settings general.
3633
 *
3634
 * tasks performed:
3635
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3636
 *
3637
 * @param $form
3638
 * @param $form_state
3639
 */
3640
function cdm_settings_general_submit($form, &$form_state){
3641
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3642
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3643
  unset($_SESSION['cdm_login']);
3644
}
3645

    
3646
/**
3647
 * Form validation handler for cdm_settings_cache
3648
 */
3649
function cdm_settings_cache_validate($form, &$form_state) {
3650
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3651
    cache_clear_all(NULL, 'cache_cdm_ws');
3652
    // Better clear secref_cache since I can not be sure if the cache has not
3653
    // be used during this response.
3654
    cdm_api_secref_cache_clear();
3655
  }
3656

    
3657
}
3658

    
3659
/**
3660
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3661
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3662
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3663
 *  - version: the version, e.g.: v1.1
3664
 *
3665
 * @return array
3666
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3667
 */
3668
function get_edit_map_service_settings() {
3669

    
3670
  $settings = variable_get('edit_map_server', array(
3671
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3672
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3673
      )
3674
  );
3675

    
3676
  return $settings;
3677
}
3678

    
3679
/**
3680
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3681
 *
3682
 * @return string
3683
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3684
 */
3685
function get_edit_map_service_full_uri() {
3686
  $settings = get_edit_map_service_settings();
3687
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3688
}
3689

    
3690

    
3691
/**
3692
 * Returns the version number of the currently selected edit mapserver as a float
3693
 *
3694
 * @return float
3695
 *   The version number of the currently selected edit mapserver as a float.
3696
 *   Returns 0 on error.
3697
 */
3698
function get_edit_map_service_version_number() {
3699

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

    
3702
  $settings = get_edit_map_service_settings();
3703
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3704
  if (isset($matches[1])) {
3705
    // Convert string to float.
3706
    $version = 1 + $matches[1][0] - 1;
3707
    return $version;
3708
  }
3709
  else {
3710
    // Report error.
3711
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3712
        array(
3713
          '!version' => $settings['version'],
3714
          'warning')
3715
        )
3716
      );
3717
    return 0;
3718
  }
3719
}
3720

    
3721
/**
3722
 * Returns the array of selected items in a options array
3723
 *
3724
 * @param array $options
3725
 *   An options array as generated by a form element like checkoxes, select ...,
3726
 */
3727
function get_selection($options) {
3728
  $selection = array();
3729
  foreach ($options as $key=>$val) {
3730
    if (!empty($val)) {
3731
      $selection[] = $val;
3732
    }
3733
  }
3734
  return $selection;
3735
}
3736

    
3737

    
3738
/**
3739
 * Implements hook_element_info().
3740
 *
3741
 * Allows modules to declare their own Form API element types and specify their default values.
3742
 *
3743
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3744
 */
3745
function cdm_dataportal_element_info() {
3746
  $type['checkboxes_preferred'] = array(
3747
    '#input' => TRUE,
3748
    '#process' => array('checkboxes_preferred_expand'),
3749
    '#after_build' => array('checkboxes_preferred_after_build'),
3750
    '#theme' => array('checkboxes_preferred'),
3751
    // '#theme_wrapper' => array('form_element'),
3752
  );
3753
  return $type;
3754
}
3755

    
3756
/**
3757
 * #process callback function for the custom form element type 'checkbox_preferred'
3758
 *
3759
 *
3760
 */
3761
function checkboxes_preferred_expand($element, &$form_state, $form) {
3762

    
3763
  // First of all create checkboxes for each of the elements
3764
  $element = form_process_checkboxes($element);
3765

    
3766
  // compose the element name
3767
  $parents = array();
3768
  array_deep_copy($element['#parents'], $parents);
3769
  $parents[count($parents) -1 ] .= '_preferred';
3770
  $element_name = $parents[0];
3771
  for ($i=1; $i < count($parents); $i++){
3772
    $element_name .= '[' . $parents[$i] . ']';
3773
  }
3774

    
3775
  $children = element_children($element);
3776

    
3777
  $element['table_start'] = array(
3778
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3779
    '#weight' => -1,
3780
  );
3781

    
3782
  // prepare first part each of the table rows which contains the row label
3783
  $weight = 0;
3784
  foreach ($children as $key) {
3785
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3786
    $element[$key]['#weight'] = $weight;
3787
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3788
    $element[$key]['#suffix'] = '</td>';
3789
    unset($element[$key]['#title']);
3790
    $weight += 2;
3791
  }
3792
  $weight = 0;
3793

    
3794
  // add a radio button to each of the checkboxes, the
3795
  // check boxes have already been created at the beginning
3796
  // of this function
3797
  if (count($element['#options']) > 0) {
3798
    foreach ($element['#options'] as $key => $choice) {
3799
      if (!isset($element[$key . '_preferred'])) {
3800
        $element[$key . '_preferred'] = array(
3801
          '#type' => 'radio',
3802
          '#name' => $element_name,
3803
          '#return_value' => check_plain($key),
3804
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3805
          '#attributes' => $element['#attributes'],
3806
          '#parents' => $element['#parents'],
3807
          // '#spawned' => TRUE,
3808
          '#weight' => $weight + 1,
3809
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3810
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3811
        );
3812
      }
3813
      $weight += 2;
3814
    }
3815
  }
3816

    
3817
  // end the table
3818
  $element['table_end'] = array(
3819
    '#markup' => '</table>',
3820
    '#weight' => $weight++,
3821
  );
3822

    
3823
  return $element;
3824
}
3825

    
3826
/**
3827
 * Theme function for the custom form field 'checkboxes_preferred'.
3828
 */
3829
function theme_checkboxes_preferred($variables) {
3830
  $element = $variables['element'];
3831
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3832
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3833
  $out .= drupal_render_children($element);
3834
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3835
  $out .= '</div>';
3836
  return $out;
3837
}
3838

    
3839
/**
3840
 * Callback for checkboxes preferred for widget which will
3841
 * be called after the form or element is built. The call
3842
 * back is configured in the form element by setting it as
3843
 * #after_build parameter.
3844
 *
3845
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3846
 *
3847
 * @param $element
3848
 *   Nested array of form elements that comprise the form.
3849
 * @param $form_state
3850
 *   A keyed array containing the current state of the form.
3851
 *   This includes the current persistent storage data for the form.
3852
 *   Additional information, like the sanitized $_POST data,
3853
 *   is also accumulated here in $form_state['input']
3854
 *
3855
 * @return the modified form array
3856
 */
3857
function checkboxes_preferred_after_build($element, &$form_state) {
3858

    
3859
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3860

    
3861
  if ($_POST && count($_POST) > 0) {
3862
    // TODO use  $form_state['input'] instead of POST !!!
3863
    // First pass of form processing.
3864
    $parents = array();
3865
    array_deep_copy($element['#parents'], $parents);
3866
    $parents[count($parents) - 1] .= '_preferred';
3867
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3868
    $element['#value']['PREFERRED'] = $preferred_layer;
3869
//     $form_state[$parent_id] = $element['#value'];
3870
//     $form_state['values']['baselayers'] = $element['#value'];
3871
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3872
    $form_state_element_values = $element['#value'];
3873
  }
3874
  else {
3875
    // Second pass of form processing.
3876
    $preferred_layer = $element['#value']['PREFERRED'];
3877
  }
3878

    
3879
  // Also set the chosen value (not sure if this is good Drupal style ....).
3880
  foreach ($children = element_children($element) as $key) {
3881
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3882
      $element[$key]['#value'] = $preferred_layer;
3883
    }
3884
  }
3885
  // The default layer must always be enabled.
3886
  $element[$preferred_layer]['#value'] = $preferred_layer;
3887

    
3888
  return $element;
3889
}
3890

    
3891
function radios_prepare_options_suffix(&$elements){
3892

    
3893
  $childrenKeys = element_children($elements);
3894
  foreach($childrenKeys as $key){
3895
    if(!is_array($elements[$key]['#theme_wrappers'])){
3896
      $elements[$key]['#theme_wrappers'] = array();
3897
    }
3898
    if(isset($elements['#options_suffixes'][$key])){
3899
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3900
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3901
    }
3902
  }
3903
  return $elements;
3904

    
3905
}
3906

    
3907
/**
3908
 * TODO
3909
 * @param unknown $variables
3910
 */
3911
function theme_radio_options_suffix($variables) {
3912
  $element = $variables['element'];
3913
  if(isset($element['#options_suffix'])) {
3914
    $element['#children'] .= $element['#options_suffix'];
3915
  }
3916
  return $element['#children'];
3917
}
3918

    
3919

    
3920
/**
3921
 * Element validate callback for text field and arrays containing json.
3922
 *
3923
 * @param $element
3924
 *   The form element to validate
3925
 * @param $form_state
3926
 *   A keyed array containing the current state of the form.
3927
 * @param $form
3928
 *   Nested array of form elements that comprise the form.
3929
 */
3930
function form_element_validate_json($element, &$form_state, $form) {
3931
   if (!empty($element['#value'])) {
3932
     json_decode($element['#value']);
3933
     if(json_last_error() != JSON_ERROR_NONE){
3934
       form_error($element,
3935
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3936
         . l('JSONLint', 'http://jsonlint.com/')
3937
       );
3938
     }
3939
   }
3940
}
3941

    
3942
/**
3943
 * Form submission handler for textareas and textfields containing JSON.
3944
 *
3945
 * The contained JSON will be converted into an php array
3946
 * or object and will be stored in the variables as such.
3947
 *
3948
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3949
 *
3950
 * @param $form
3951
 *   Nested array of form elements that comprise the form.
3952
 * @param $form_state
3953
 *   A keyed array containing the current state of the form.
3954
 *
3955
 */
3956
function submit_json_as_php_array($form, &$form_state) {
3957
  if (is_array($form['#json_elements'])) {
3958
    foreach ($form['#json_elements'] as $element){
3959
      if (trim($form_state['values'][$element])) {
3960
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3961
      } else {
3962
        $form_state['values'][$element] = NULL;
3963
      }
3964
    }
3965
  }
3966
}
(18-18/18)