Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (152 KB)

1
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6

    
7

    
8
  // TODO Genus UUID.
9

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

    
15
  define('NO_SORT', -1);
16
  define('SORT_HIERARCHICAL', 9);
17

    
18
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
19

    
20
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
21
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
22

    
23
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
24
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
25
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
26
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
27
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
28
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
29
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
30
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
31

    
32
  /* annotationTypeKeys */
33
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
34
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
35
    $annotationTypeKeys = array_flip($annotationTypeKeys);
36

    
37
    // Technical annotation are off by default.
38
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
39
    $annotationTypeKeys = array_flip($annotationTypeKeys);
40
    // Additional value for the NULL case.
41
    $annotationTypeKeys[] = 'NULL_VALUE';
42
  }
43
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
44

    
45
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
46
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
47
    'enabled' => 0,
48
    'key_format' => 'ALPHA'
49
  )));
50

    
51
  /* taxonRelationshipTypes */
52
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
53
    array(
54
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
55
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
56
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
57
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
58
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
59
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
60
    )
61
  ));
62

    
63

    
64
  /* ---- MAP SETTING CONSTANTS ---- */
65
  /**
66
   * @var array of URIs eg. http://edit.africamuseum.be"
67
   *   An options array
68
   */
69
  define('EDIT_MAPSERVER_URI', serialize(
70
      array(
71
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
72
      )
73
    )
74
  );
75
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
76
  /**
77
   * @var array of versions eg. "v1.2"
78
   *   An options array
79
   */
80
  define('EDIT_MAPSERVER_VERSION', serialize(
81
      array(
82
//        'v1' => 'v1' ,           // no longer recommended
83
//        'v1.1' => 'v1.1',        // no longer recommended
84
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
85
        'v1.2' => 'v1.2',
86
        'v1.3_dev' => 'v1.3_dev (not recommended)',
87
        'v1.4_dev' => 'v1.4_dev (experimental features)'
88
      )
89
    )
90
  );
91
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
92
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
93

    
94
    // --- Taxon profile settings --- /
95
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
96
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
97
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
98
      array(
99
          'show' => 0,
100
          'maxextend' => 184,
101
          'media_uri_query' => '',
102
          'custom_placeholder_enabled' => 1,
103
          'custom_placeholder_image_on' => 0,
104
          'custom_placeholder_image_fid' => ''
105
      )
106
    )
107
  );
108

    
109

    
110
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
111

    
112
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
113
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
114
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
115
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
116
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
117

    
118
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
119
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
120
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
121
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
122

    
123
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
124
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
125

    
126
/**
127
 * Returns the array of implemented taxon page tabs.
128
 * The array has fixed integer keys which must not be changed.
129
 */
130
function get_taxon_tabs_list() {
131
  $opts = array(
132
    0 => 'General',
133
    1 => 'Synonymy',
134
    2 => 'Images',
135
    3 => 'Specimens',
136
    4 => 'Keys',
137
    5 => 'Experts',
138
  );
139
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
140
    // skip the Synonymy if it is shown in  the general tab
141
    unset($opts[1]);
142
  }
143
  return $opts;
144
}
145

    
146
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
147
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
148
  array(
149
    'general' => '-3',
150
    'synonymy' => '-2',
151
    'images' => '0',
152
    'specimens' => '1',
153
    'keys' => '3',
154
    'experts' => '5',
155
    )
156
));
157

    
158

    
159
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
160
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
161
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
162
  array(
163
    'general' => null,
164
    'synonymy' => null,
165
    'images' => null,
166
    'specimens' => null,
167
    'keys' => null,
168
    'experts' => null,
169
  )
170
));
171

    
172
$taxon_tab_options = get_taxon_tabs_list();
173
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
174

    
175
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
176

    
177
/**
178
 * @todo document this function.
179
 */
180
function get_taxon_options_list() {
181
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
182
  foreach ($taxon_tab_options as $key => $value) {
183
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
184
  }
185
  return $taxon_tab_options;
186

    
187
}
188

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

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

    
354
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
355
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
356
    // to unset a default enntry set the value to 0
357
    array(
358
      'doTaxa'=>'doTaxa',
359
      'doSynonyms' => 'doSynonyms',
360
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
361
      'doMisappliedNames' => 'doMisappliedNames'
362
    )
363
  )
364
);
365

    
366
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
367

    
368
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
369
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
370
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
371

    
372
/* Gallery variables. */
373
$gallery_settings = array(
374
    "cdm_dataportal_show_taxon_thumbnails" => 1,
375
    "cdm_dataportal_show_synonym_thumbnails" => 0,
376
    "cdm_dataportal_show_thumbnail_captions" => 1,
377
    "cdm_dataportal_media_maxextend" => 120,
378
    "cdm_dataportal_media_cols" => 3,
379
    "cdm_dataportal_media_maxRows" => 1,
380
);
381

    
382
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
383
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
384
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
385
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
386
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
387
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
388
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
389
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
390
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
391
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
392
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
393

    
394
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
395
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
396
  'media_representation_details_enabled' => 0
397
)));
398

    
399
/**
400
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
401
 * the snonymy.
402
 *
403
 * @var string
404
 */
405
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
406

    
407
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
408
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
409
    array(
410
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
411
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
412
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
413
    )
414
  )
415
);
416

    
417
/**
418
 * The drupal variable for the configuration of the information aggregation along
419
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
420
 *    - direct: the uuids of the taxon relationship types to take into account in invers
421
 *      direction.
422
 *    - invers: the uuids of the taxon relationship types to take into account in direct
423
 *      direction.
424
 *
425
 * @var String
426
 */
427
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
428
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
429
    array(
430
        'direct'=>array(),
431
        'invers'=>array()
432
     )
433
   ));
434
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
435
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
436
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
437

    
438
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
439
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
440
      array(
441
      'filter_rules' => array(
442
        'statusOrderPreference' => 0,
443
        'subAreaPreference' => 0,
444
      ),
445
      'hiddenAreaMarkerType' => array()
446
     )
447
));
448

    
449
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
450
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
451
  "level_0" => array(
452
    'label_suffix' => ':',
453
    'status_glue' => '',
454
    'item_glue' => ' ',
455
    'item_group_prefix' => '',
456
    'item_group_postfix' => ''
457
  ),
458
  "level_1" => array(
459
    'label_suffix' => '',
460
    'status_glue' => '', // '&#8210; '
461
    'item_glue' => '; ',
462
    'item_group_prefix' => ', ',
463
    'item_group_postfix' => ''
464
  ),
465
  "level_2" => array(
466
    'label_suffix' => '',
467
    'status_glue' => '', // '&#8210; '
468
    'item_glue' => ', ',
469
    'item_group_prefix' => ' (',
470
    'item_group_postfix' => ')'
471
  )
472
)));
473

    
474
/**
475
 * Constant for the drupal variable key distribution_map_visibility
476
 *
477
 * possible values:
478
 *  - never
479
 *  - automatic
480
 *  - always
481
 */
482
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
483
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
484

    
485
/**
486
 * Constant for the drupal variable key specimen_map_visibility
487
 *
488
 * possible values:
489
 *  - never
490
 *  - automatic
491
 *  - always
492
 */
493
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
494
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
495

    
496
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
497
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
498
    array(
499
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
500
        'includeOccurrences' => 0,
501
        'includeTaxonNameDescriptions' => 0
502
     )
503
  ));
504

    
505
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
506
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
507
  // needs to be merged with user setting by drupal_array_merge_deep()
508
  // 'width' => 512, // optimum size for OSM layers is 512
509
  // 'height' => 512 / 2, // optimum size for OSM layers 256
510
  'aspect_ratio' => 2,
511
  'bbox' => '', // empty to allow automatic zooming to extend
512
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
513
  'show_labels' => FALSE,
514
  'caption' => '',
515
  'distribution_opacity' => '0.5',
516
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
517
  'image_map' => array(
518
    'base_layer' => '', // none, formerly this was cyprusdivs
519
    'bg_color' => '1874CD',
520
    'layer_style' => 'ffffff,606060,,',
521
  ),
522
  'openlayers' => array(
523
    'base_layers' =>  array(
524
      // A layer MUST NOT BE SET in the defaults,
525
      // otherwise it can not be overidden by the user settings:
526
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
527
      // it is sufficient to define the preferred layer,
528
      // since it will automatically be enabled:
529
      'PREFERRED' => 'mapproxy_vmap0'),
530
    'custom_wms_base_layer' => array(
531
      'name' => NULL,
532
      'url' => NULL,
533
      'params' =>  NULL,
534
      'projection' => NULL,
535
      'proj4js_def' => NULL,
536
      'max_extent' => NULL,
537
      'units' => NULL,
538
      'untiled' => FALSE
539
    ),
540
    'wms_overlay_layer' => array(
541
      'name' => NULL,
542
      'url' => NULL,
543
      'params' =>  NULL,
544
      'untiled' => FALSE
545
    ),
546
    'show_layer_switcher' => TRUE,
547
    'display_outside_max_extent' => FALSE,
548
    'google_maps_api_key' => NULL,
549
  ),
550
  'legend' => array(
551
    'show' => TRUE,
552
    'opacity' => '0.5',
553
    'font_size' => 10,
554
    'font_style' => FALSE,
555
    'icon_width' => 35,
556
    'icon_height' => 15
557
  )
558
)));
559

    
560
/**
561
 * Merges the named array variable with the array of defaults.
562
 *
563
 * IMPORTANT: The array keys must be strings. When the keys are integers
564
 * the merging will not take place for these entities. Number keyed entities
565
 * are just appended to the result array.
566
 *
567
 * @param string $variable_name
568
 *     The variable name
569
 * @param string | array $default
570
 *     The array containing the default values either as array or serialized as string.
571
 *     Unserialization is cared for if necessary
572
 * @return array
573
 *     The merged array as returned by drupal_array_merge_deep()
574
 *
575
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
576
 * TODO force $default being an array
577
 */
578
function get_array_variable_merged($variable_name, $default){
579

    
580
    // unserialize if nessecary
581
    if(!is_array($default)){
582
      $default = unserialize($default);
583
    }
584
    $variable = variable_get($variable_name, array());
585
    $result = drupal_array_merge_deep($default, $variable);
586
    return $result;
587
}
588

    
589
/**
590
 * @todo document this function.
591
 */
592
function getGallerySettings($gallery_config_form_name) {
593
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
594
}
595

    
596
/**
597
 * Returns the string representation of the default tab.
598
 *
599
 * @param bool $returnTabIndex
600
 *   Defaults to FALSE, if set true this function will return the index number
601
 *   of the default tab. (used to supply default values to form elements).
602
 */
603
function get_default_taxon_tab($returnTabIndex = FALSE) {
604

    
605
  global $user;
606
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
607
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
608
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
609
  // Get the user value if the used has chosen to overwrite the system settings.
610
  $user_tab_on = variable_get($user_tab_active, FALSE);
611
  if ($user_tab_on) {
612
    $user_value = variable_get($user_tab, 0);
613
    $index_value = $user_value;
614
    // Get the system value.
615
  }
616
  else {
617
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
618
    $index_value = $system_value;
619
  }
620

    
621
  // Return the index value or the string representation.
622
  if ($returnTabIndex) {
623
    return $index_value;
624
  }
625
  else {
626
    return ($values[$index_value]);
627
  }
628
}
629

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

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

    
701
  // ---- DEFAULTS settings
702

    
703
  // only needed as final option, when the settings are not having a default
704
  $default = array(
705
    'DEFAULT' => array(
706
      'as_list' => 'div',
707
      'link_to_reference' => 0,
708
      'link_to_name_used_in_source' => 1,
709
      'sources_as_content' => 0,
710
      'sources_as_content_to_bibliography' => 0,
711
      'sort_elements' => NO_SORT,
712
      'glue' => '',
713
      'element_tag' => NULL
714
    ),
715
    // settings for pseudo feature bibliography
716
    // only hard coded here
717
    'BIBLIOGRAPHY' => array(
718
      'as_list' => 'div',
719
      'link_to_reference' => 0,
720
      'link_to_name_used_in_source' => 1,
721
      'sources_as_content' => 0,
722
      'sources_as_content_to_bibliography' => 0,
723
      'sort_elements' => NO_SORT,
724
      'glue' => '',
725
      'element_tag' => NULL
726
    )
727
  );
728

    
729
  // will be used as preset in the settings
730
  $other_themes_default = array(
731
    'DEFAULT' => array(
732
      'as_list' => 'div',
733
      'link_to_reference' => 0,
734
      'link_to_name_used_in_source' => 1,
735
      'sources_as_content' => 0,
736
      'sources_as_content_to_bibliography' => 0,
737
      'sort_elements' => NO_SORT,
738
      'glue' => '',
739
      'element_tag' => NULL
740
    ),
741
    UUID_CITATION => array(
742
      'as_list' => 'div',
743
      'link_to_reference' => 0,
744
      'link_to_name_used_in_source' => 0,
745
      'sources_as_content' => 1,
746
      'sources_as_content_to_bibliography' => 0,
747
      'sort_elements' => SORT_ASC,
748
      'glue' => '',
749
      'element_tag' => 'div'
750
    ),
751
    UUID_DISTRIBUTION => array(
752
      'as_list' => 'div', // currently ignored
753
      'link_to_reference' => 0,
754
      'link_to_name_used_in_source' => 0,
755
      'sources_as_content' => 0,
756
      'sources_as_content_to_bibliography' => 0,
757
      'sort_elements' => NO_SORT, // will cause ...
758
      'glue' => '',
759
      'element_tag' => 'div',
760
      'special' => array()
761
    ),
762
    UUID_COMMON_NAME => array(
763
      'as_list' => 'div',
764
      'link_to_reference' => 0,
765
      'link_to_name_used_in_source' => 1,
766
      'sources_as_content' => 0,
767
      'sources_as_content_to_bibliography' => 0,
768
      'sort_elements' => NO_SORT,
769
      'glue' => '',
770
      'element_tag' => 'span'
771
    ),
772
  );
773

    
774
  // ---- Special DEFAULTS for existing portals
775
  // TODO:
776
  // this can be removed once the feature block
777
  // settings have been deployed for the first time to these portals
778

    
779
  $cichorieae_default = array(
780
    'DEFAULT' => array(
781
      'as_list' => 'div',
782
      'link_to_reference' => 1,
783
      'link_to_name_used_in_source' => 1,
784
      'sources_as_content' => 1,
785
      'sources_as_content_to_bibliography' => 0,
786
      'sort_elements' => NO_SORT,
787
      'glue' => '',
788
      'element_tag' => 'div'
789
    ),
790
    UUID_CITATION => array(
791
      'as_list' => 'div',
792
      'link_to_reference' => 0,
793
      'link_to_name_used_in_source' => 0,
794
      'sources_as_content' => 1,
795
      'sources_as_content_to_bibliography' => 0,
796
      'sort_elements' => SORT_ASC,
797
      'glue' => '',
798
      'element_tag' => 'div'
799
    ),
800
    UUID_CHROMOSOMES_NUMBERS => array(
801
      'as_list' => 'ul',
802
      'link_to_reference' => 1,
803
      'link_to_name_used_in_source' => 1,
804
      'sources_as_content' => 1,
805
      'sources_as_content_to_bibliography' => 0,
806
      'sort_elements' => NO_SORT,
807
      'glue' => '',
808
      'element_tag' => 'div'
809
    ),
810
    UUID_CHROMOSOMES => array(
811
      'as_list' => 'ul',
812
      'link_to_reference' => 0,
813
      'link_to_name_used_in_source' => 1,
814
      'sources_as_content' => 1,
815
      'sources_as_content_to_bibliography' => 0,
816
      'sort_elements' => NO_SORT,
817
      'glue' => '',
818
      'element_tag' => 'div'
819
    ),
820
    UUID_COMMON_NAME => array(
821
      'as_list' => 'div',
822
      'link_to_reference' => 0,
823
      'link_to_name_used_in_source' => 1,
824
      'sources_as_content' => 0,
825
      'sources_as_content_to_bibliography' => 0,
826
      'sort_elements' => NO_SORT,
827
      'glue' => '',
828
      'element_tag' => 'span'
829
    ),
830
  );
831

    
832
  $palmweb_default = array(
833
    'DEFAULT' => array(
834
      'as_list' => 'ul',
835
      'link_to_reference' => 1,
836
      'link_to_name_used_in_source' => 1,
837
      'sources_as_content' => 1,
838
      'sources_as_content_to_bibliography' => 1,
839
      'sort_elements' => NO_SORT,
840
      'glue' => '',
841
      'element_tag' => NULL
842
    ),
843
    UUID_CITATION => array(
844
      'as_list' => 'ul',
845
      'link_to_reference' => 1,
846
      'link_to_name_used_in_source' => 1,
847
      'sources_as_content' => 0,
848
      'sources_as_content_to_bibliography' => 1,
849
      'sort_elements' => SORT_ASC,
850
      'glue' => '',
851
      'element_tag' => 'div'
852
    ),
853
    UUID_DISTRIBUTION => array(
854
      'as_list' => 'div', // currently ignored
855
      'link_to_reference' => 1,
856
      'link_to_name_used_in_source' => 1,
857
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
858
      'sources_as_content_to_bibliography' => 1,
859
      'sort_elements' => NO_SORT, // will cause ...
860
      'glue' => ', ',
861
      'element_tag' => 'span',
862
      'special' => array()
863
    ),
864
  );
865

    
866
  $cyprus_default = $cichorieae_default;
867
  $cyprus_default[UUID_DISTRIBUTION] = array(
868
    'as_list' => 'div', // currently ignored
869
    'link_to_reference' => 0,
870
    'link_to_name_used_in_source' => 0,
871
    'sources_as_content' => 0,
872
    'sources_as_content_to_bibliography' => 0,
873
    'sort_elements' => NO_SORT, // will cause ...
874
    'glue' => ' ',
875
    'element_tag' => 'div',
876
    'special' => array()
877
  );
878

    
879
  $default_theme = variable_get('theme_default', NULL);
880

    
881
  switch ($default_theme) {
882
    case 'garland_cichorieae':
883
      $settings_for_theme = $cichorieae_default;
884
      break;
885
    case 'cyprus':
886
      // cyprus: no longer used in production,
887
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
888
      $settings_for_theme = $cyprus_default;
889
      break;
890
    case 'flore_afrique_centrale':
891
    case 'flora_malesiana':
892
    case 'flore_gabon':
893
      $settings_for_theme = $cichorieae_default;
894
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
895
      break;
896
    case 'palmweb_2':
897
      $settings_for_theme = $palmweb_default;
898
      break;
899
    default:
900
      $settings_for_theme = $other_themes_default;
901
  }
902
  // add pseudo feature settings
903
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
904

    
905
  // ---- END of DEFAULTS
906

    
907
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
908

    
909
  $feature_block_setting = null;
910

    
911
  if (isset($saved_settings[$feature_uuid])) {
912
    $feature_block_setting = $saved_settings[$feature_uuid];
913
  }
914
  else if (isset($settings_for_theme[$feature_uuid])) {
915
    $feature_block_setting = $settings_for_theme[$feature_uuid];
916
  }
917
  else if (isset($settings_for_theme['DEFAULT'])) {
918
    $feature_block_setting = $settings_for_theme['DEFAULT'];
919
  }
920

    
921
  // now merge the default and specific settings
922
  $settings_to_merge = array($default['DEFAULT']);
923
  if(is_array($saved_settings)){
924
    $settings_to_merge[] = $saved_settings['DEFAULT'];
925
  }
926
  if(isset($feature_block_setting)){
927
    $settings_to_merge[] = $feature_block_setting;
928
  }
929
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
930

    
931
  return $feature_block_setting;
932
}
933

    
934
/**
935
 * returns the current setting for the original source bibliography
936
 *
937
 * Caches internally
938
 *
939
 * @return array
940
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
941
 *   - 'enabled': 1|0
942
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
943
 */
944
function get_bibliography_settings($clear_cache = false){
945
  static $bibliography_settings = null;
946
  if(!$bibliography_settings || $clear_cache){
947
    $bibliography_settings = get_array_variable_merged(
948
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
949
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
950
    );
951
  }
952
  return $bibliography_settings;
953
}
954

    
955
/**
956
 * @todo Please document this function.
957
 * @see http://drupal.org/node/1354
958
 */
959
function cdm_dataportal_menu_admin(&$items) {
960
  // Display section on admin/config page.
961
  $items['admin/config/cdm_dataportal'] = array(
962
    'title' => 'CDM Dataportal',
963
    'description' => 'Settings for the CDM DataPortal.',
964
    'position' => 'right',
965
    'weight' => 10,
966
    'page callback' => 'system_admin_menu_block_page',
967
    'access arguments' => array('administer cdm_dataportal'),
968
    'file' => 'system.admin.inc',
969
    'file path' => drupal_get_path('module', 'system'),
970
  );
971
  $items['admin/config/cdm_dataportal/settings'] = array(
972
    'title' => 'Settings',
973
    'description' => 'Settings for the CDM DataPortal.',
974
    'weight' => 0,
975
    'page callback' => 'drupal_get_form',
976
    'page arguments' => array('cdm_settings_general'),
977
    'access arguments' => array('administer cdm_dataportal'),
978
    'type' => MENU_NORMAL_ITEM,
979
  );
980
  $items['admin/config/cdm_dataportal/settings/general'] = array(
981
    'title' => 'General',
982
    'description' => 'General',
983
    'weight' => 0,
984
    'page callback' => 'drupal_get_form',
985
    'page arguments' => array('cdm_settings_general'),
986
    'access arguments' => array('administer cdm_dataportal'),
987
    'type' => MENU_DEFAULT_LOCAL_TASK,
988
  );
989

    
990
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
991
    'title' => 'Cache',
992
    'description' => 'Cache',
993
    'access arguments' => array('administer cdm_dataportal'),
994
    'page callback' => 'drupal_get_form',
995
    'page arguments' => array('cdm_settings_cache'),
996
    'weight' => 10,
997
    'type' => MENU_LOCAL_TASK,
998
  );
999

    
1000
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1001
    'title' => 'Geo & Map',
1002
    'description' => 'Geo & Map',
1003
    'access arguments' => array('administer cdm_dataportal'),
1004
    'page callback' => 'drupal_get_form',
1005
    'page arguments' => array('cdm_settings_geo'),
1006
    'weight' => 1,
1007
    'type' => MENU_LOCAL_TASK,
1008
  );
1009

    
1010
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1011
    'title' => 'Layout',
1012
    'description' => 'Configure and adjust the layout of your DataPortal ',
1013
    'access arguments' => array('administer cdm_dataportal'),
1014
    'page callback' => 'drupal_get_form',
1015
    'page arguments' => array('cdm_settings_layout'),
1016
    'weight' => 2,
1017
    'type' => MENU_LOCAL_TASK,
1018
  );
1019

    
1020
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1021
    'title' => 'Taxon',
1022
    'description' => 'Configure and adjust the layout of your DataPortal ',
1023
    'access arguments' => array('administer cdm_dataportal'),
1024
    'page callback' => 'drupal_get_form',
1025
    'page arguments' => array('cdm_settings_layout_taxon'),
1026
    'weight' => 1,
1027
    'type' => MENU_LOCAL_TASK,
1028
  );
1029
  /*
1030
  $items[] = array(
1031
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1032
  'title' => t('Synonymy'),
1033
  'description' => t('Configure and adjust the layout of your DataPortal '),
1034
  'access' => user_access('administer cdm_dataportal'),
1035
  'callback' => 'drupal_get_form',
1036
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1037
  'weight' => 1,
1038
  'type' => MENU_LOCAL_TASK,
1039
  );
1040

1041
  $items[] = array(
1042
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1043
  'title' => t('Specimens'),
1044
  'description' => t('Configure and adjust the layout of your DataPortal '),
1045
  'access' => user_access('administer cdm_dataportal'),
1046
  'callback' => 'drupal_get_form',
1047
  'callback arguments' => array('cdm_settings_layout_specimens'),
1048
  'weight' => 1,
1049
  'type' => MENU_LOCAL_TASK,
1050
  );
1051
  */
1052
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1053
    'title' => 'Search',
1054
    'description' => 'Configure and adjust the layout of your DataPortal ',
1055
    'access arguments' => array('administer cdm_dataportal'),
1056
    'page callback' => 'drupal_get_form',
1057
    'page arguments' => array('cdm_settings_layout_search'),
1058
    'weight' => 2,
1059
    'type' => MENU_LOCAL_TASK,
1060
  );
1061

    
1062
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1063
    'title' => 'Media',
1064
    'description' => 'Configure and adjust the layout of your DataPortal ',
1065
    'access arguments' => array('administer cdm_dataportal'),
1066
    'page callback' => 'drupal_get_form',
1067
    'page arguments' => array('cdm_settings_layout_media'),
1068
    'weight' => 3,
1069
    'type' => MENU_LOCAL_TASK,
1070
  );
1071

    
1072
}
1073

    
1074
/**
1075
 * @todo document this function.
1076
 */
1077
function cdm_help_general_cache() {
1078
  $form = array();
1079
  $form['cache_help'] = array(
1080
    '#type' => 'fieldset',
1081
    '#title' => t('Help'),
1082
    '#collapsible' => TRUE,
1083
    '#collapsed' => TRUE,
1084
  );
1085
  $form['cache_help']['test'] = array('#value' => t('probando'));
1086
  return drupal_render($form);
1087
  $res = array();
1088
  $res['default'] = drupal_render($help);
1089
  return $res;
1090
}
1091

    
1092
/**
1093
 * Configures the settings form for the CDM-API module.
1094
 *
1095
 * @return array
1096
 *   Drupal settings form.
1097
 */
1098
function cdm_settings_general() {
1099

    
1100
  $form['cdm_webservice'] = array(
1101
    '#type' => 'fieldset',
1102
    '#title' => t('CDM Server'),
1103
    '#collapsible' => FALSE,
1104
    '#collapsed' => FALSE,
1105
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1106
        CDM data base to the web via RESTful web services and thus is the source of the data
1107
        to be displayed by a CDM DataPotal.'),
1108
  );
1109

    
1110
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1111
    '#type' => 'textfield',
1112
    '#title' => t('CDM web service URL') . ':',
1113
    '#description' => t('This is the URL to the CDM-Server exposing your data
1114
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1115
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1116
  );
1117

    
1118
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1119
    '#type' => 'markup',
1120
    '#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')
1121
      . ' visible only for administrators',
1122
  );
1123

    
1124
  $form['cdm_webservice']['freetext_index'] = array(
1125
    '#type' => 'fieldset',
1126
    '#title' => t('Freetext index'),
1127
    '#collapsible' => FALSE,
1128
    '#collapsed' => FALSE,
1129
  );
1130

    
1131
  // Check the cdmserver port number and display a waring if it is not port 80
1132
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1133
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1134
    $form['cdm_webservice']['freetext_index']['message'] = array(
1135
      '#markup' => "<div class=\"description\">"
1136
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1137
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1138
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1139
          array('!port' => $portNumberMatch[1][0])
1140
        )
1141
      . "</div>",
1142
    );
1143
  };
1144

    
1145
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1146
  $trigger_link_options = array(
1147
    'attributes' => array(
1148
      'class' => 'index-trigger'
1149
    ),
1150
  );
1151
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1152
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1153
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1154
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1155
      ))
1156
    . '<div id="index-progress"></div></div>',
1157
  );
1158

    
1159
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1160
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1161
    '#type' => 'textfield',
1162
    '#title' => t('Login'),
1163
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1164
  );
1165
  drupal_add_js('
1166
        jQuery(document).ready(function() {
1167
             jQuery("#edit-cdm-login").change(function (e) {
1168
                var login = jQuery(e.target).val();
1169
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1170
                   var url = jQuery(this).attr("href");
1171
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1172
                   jQuery(this).attr("href", url);
1173
                });
1174
            });
1175
        });
1176
      ',
1177
    array(
1178
      'type' => 'inline',
1179
      'scope' => 'footer'
1180
    )
1181
  );
1182
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1183

    
1184
  $form['cdm_webservice']['proxy'] = array(
1185
    '#type' => 'fieldset',
1186
    '#title' => t('Proxy'),
1187
    '#collapsible' => TRUE,
1188
    '#collapsed' => TRUE,
1189
  );
1190

    
1191
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1192
    '#type' => 'textfield',
1193
    '#title' => t('Proxy URL') . ':',
1194
    '#description' => t('If this proxy url is set the cdm api tries
1195
    to connect the web service over the given proxy server.
1196
    Otherwise proxy usage is deactivated.'),
1197
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1198
  );
1199

    
1200
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1201
    '#type' => 'textfield',
1202
    '#title' => t('Proxy port') . ':',
1203
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1204
  );
1205

    
1206
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1207
    '#type' => 'textfield',
1208
    '#title' => t('Login') . ':',
1209
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1210
  );
1211

    
1212
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1213
    '#type' => 'textfield',
1214
    '#title' => t('Password') . ':',
1215
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1216
  );
1217

    
1218
  // TODO: settings are still incomplete, compare with
1219
  // trunk/dataportal/inc/config_default.php.inc.
1220
  $form['taxon_tree'] = array(
1221
    '#type' => 'fieldset',
1222
    '#title' => t('Taxon Tree'),
1223
    '#collapsible' => FALSE,
1224
    '#collapsed' => TRUE,
1225
    '#description' => t('<p>When you explore your collection, you can navigate
1226
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1227
      able to navigate through your collection the
1228
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1229
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1230
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1231
      </a></p>'),
1232
  );
1233

    
1234
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1235
    '#type' => 'select',
1236
    '#title' => t('Default classification') . ':',
1237
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1238
    '#options' => cdm_get_taxontrees_as_options(),
1239
    '#description' => t('The default taxa classification to be used in the whole portal. 
1240
      This affects most obviously the classification browser and the search in case is is restricted 
1241
      to a specific classification. See also <i>Included Classifications</i> below.'),
1242
  );
1243

    
1244
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1245
    '#type' => 'select',
1246
    '#title' => t('Rank of highest displayed taxon') . ':',
1247
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1248
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1249
    '#options' => cdm_rankVocabulary_as_option(),
1250
    '#description' => t('This is the rank of the highest displayed taxon in the
1251
      <em>taxon tree</em>. You can select here which rank should be at the top
1252
      level of the tree structure.'),
1253
  );
1254

    
1255
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1256
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1257
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1258
      '#type' => 'checkboxes',
1259
      '#title' => t('Included Classifications') . ':',
1260
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1261
      '#options' => cdm_get_taxontrees_as_options(),
1262
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1263
  );
1264

    
1265
  $form['distribution'] = array(
1266
      '#type' => 'fieldset',
1267
      '#title' => t('Distributions'),
1268
      '#collapsible' => FALSE,
1269
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1270
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1271
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1272
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1273
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1274
          '<p>
1275
          </p>',
1276
  );
1277

    
1278
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1279
      '#type' => 'fieldset',
1280
      '#title' => 'Distribution filter',
1281
      '#collapsible' => FALSE,
1282
      '#collapsed' => FALSE,
1283
      '#tree' => TRUE,
1284
      '#description' => 'The Distribution filter offers the following options
1285
      <ul>
1286
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1287
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1288
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1289
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1290
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1291
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1292
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1293
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1294
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1295
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1296
      </ul>'
1297
  );
1298

    
1299
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1300
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1301
      '#type' => 'checkboxes',
1302
      '#title' => 'Filter rules',
1303
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1304
      '#options' => array(
1305
          'statusOrderPreference' => 'Status order preference rule',
1306
          'subAreaPreference' => 'Sub area preference rule'
1307
      ),
1308
  );
1309

    
1310
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1311
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1312
      '#type' => 'checkboxes',
1313
      '#title' => 'Hide marked area filter',
1314
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1315
      '#options' => $marker_type_options,
1316
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1317
  );
1318

    
1319
  $form['aggregation'] = array(
1320
      '#type' => 'fieldset',
1321
      '#title' => t('Aggregation of data'),
1322
      '#collapsible' => FALSE,
1323
      '#description' => 'This section covers the different aspects of aggregating information.
1324
          <p>
1325
          </p>',
1326
  );
1327

    
1328
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1329
      '#type' => 'checkboxes',
1330
      '#title' => 'Taxon media filter',
1331
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1332
      '#options' => array(
1333
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1334
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1335
          'includeOccurrences' => 'Media related to specimens and occurrences',
1336
      ),
1337
      '#description' => 'This filter configures which images should be taken into account.',
1338
  );
1339

    
1340
  $form['aggregation']['notice'] = array(
1341
      '#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
1342
          want to make use of the caching capabilities of the dataportal.',
1343
  );
1344

    
1345
  $form['aggregation']['media_aggregation'] = array(
1346
      '#type' => 'fieldset',
1347
      '#title' => t('Media aggregation'),
1348
      '#collapsible' => FALSE,
1349
      '#collapsed' => TRUE,
1350
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1351

    
1352
  );
1353
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1354
      '#type' => 'select',
1355
      '#title' => t('Aggregation of taxon pictures') . ':',
1356
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1357
      '#options' => array(
1358
          0 => "Show only pictures of the current taxon",
1359
          1 => "Include pictures of taxonomic children",
1360
      ),
1361
      '#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."),
1362
  );
1363

    
1364
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1365
      '#type' => 'fieldset',
1366
      '#attributes' => array('class' => array('clearfix')),
1367
      '#title' => t('Aggregation via taxon relationsships'),
1368
      '#collapsible' => TRUE,
1369
      '#collapsed' => TRUE,
1370
      '#tree' => TRUE,
1371
      '#description' => t('Information on taxa will be aggregated along the below chosen
1372
          taxon relation ships. This will affect images and occurrences (specimens).
1373
          Taxon relation ships are directed and point form one taxon to another. The taxon
1374
          relationships to be taken into accunt can therefore configured for the direct direction
1375
          and for the inverse.'),
1376
  );
1377

    
1378
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1379
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1380

    
1381
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1382
      '#type' => 'checkboxes',
1383
      '#title' => t('Direct'),
1384
      '#options' => $taxonRelationshipTypeOptions,
1385
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1386
  );
1387
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1388
      '#type' => 'checkboxes',
1389
      '#title' => t('Invers'),
1390
      '#options' => $taxonRelationshipTypeOptions,
1391
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1392
  );
1393

    
1394
  $form['drupal_integration'] = array(
1395
    '#type' => 'fieldset',
1396
    '#attributes' => array('class'=> array('clearfix')),
1397
    '#title' => t('Drupal integration'),
1398
    '#collapsible' => FALSE,
1399
    '#collapsed' => FALSE,
1400
    '#tree' => FALSE
1401
  );
1402

    
1403
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1404
    '#type' => 'checkbox',
1405
    '#title' => 'Create drupal nodes',
1406
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1407
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1408
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1409
    cdm pages it is required that drupal nodes are created and stored in the database.'
1410
  );
1411

    
1412

    
1413

    
1414
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1415
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1416
    <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>',
1417
  );
1418
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1419
    '#type' => 'submit',
1420
    '#value' => t('Drop all cdm nodes'),
1421
    '#submit' => array('drop_all_cdm_nodes_submit')
1422
  );
1423

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

    
1428
    // ----------------------
1429
  $form['cdm_js_devel_mode'] = array(
1430
      '#type' => 'checkbox',
1431
      '#title' => 'Java-script developer mode',
1432
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1433
      '#description' => 'In production envirionments the java script libraries
1434
      the cdm_dataportal is making use of are compressed and optimized. This
1435
      is good for performance but a caveat if you need to debug java-script. When the
1436
      java-script developer mode is enabled the uncompressed and commented developer
1437
      versions of java-script libraries will be used where possible.
1438
      <br/><strong>Do not use this option in production!</strong>'
1439
  );
1440
  // ----------------------
1441
  $form['cdm_debug_mode'] = array(
1442
      '#type' => 'checkbox',
1443
      '#title' => 'CDM page debug mode',
1444
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1445
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1446
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1447
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1448
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1449
      The log is written by the drupal devel module function <code>dd()</code>.
1450
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1451
  );
1452

    
1453
  // Comment @WA: D7 form api does not support reset buttons,
1454
  // so to mimic the D5 reset button we add one like this.
1455
  $form['actions']['reset'] = array(
1456
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1457
    '#weight' => 1000,
1458
  );
1459

    
1460
  $form['#submit'][] = 'cdm_settings_general_submit';
1461

    
1462
  return system_settings_form($form);
1463
}
1464

    
1465
/**
1466
 * Submit callback; drops all cdm nodes.
1467
 *
1468
 * @ingroup forms
1469
 */
1470
function drop_all_cdm_nodes_submit($form, &$form_state) {
1471
  cdm_delete_all_cdm_nodes();
1472
  drupal_set_message(t('All cdm nodes dropped.'));
1473
}
1474

    
1475

    
1476
/**
1477
 * LAYOUT settings
1478
 * @return
1479
 *   todo
1480
 */
1481
function cdm_settings_layout() {
1482

    
1483
  $form = array();
1484

    
1485
  $form['about'] = array(
1486
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1487
      layout. If you want to configure the specific sites layout visit the
1488
      respective configuration site for taxon, search or media.') . '</p>',
1489
  );
1490

    
1491
  // ---- footnotes --- //
1492
  $form['footnotes'] = array(
1493
    '#type' => 'fieldset',
1494
    '#title' => t('Footnotes'),
1495
    '#collapsible' => FALSE,
1496
    '#collapsed' => FALSE,
1497
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1498
      media or distribution areas may have annotations or footnotes. When the
1499
      footnotes are enabled they will be visible (if they exist).'),
1500
  );
1501

    
1502
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1503
    '#type' => 'checkbox',
1504
    '#title' => t('Do not show footnotes'),
1505
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1506
    '#description' => t('Check this if you do not want to show any footnotes'),
1507
  );
1508

    
1509
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1510
    '#type' => 'checkbox',
1511
    '#title' => t('Do not show annotation footnotes'),
1512
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1513
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1514
  );
1515

    
1516
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1517
  // Additional option for the NULL case.
1518
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1519
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1520
    '#type' => 'checkboxes',
1521
    '#title' => t('Annotation types as footnotes'),
1522
    '#description' => t("Only annotations of the selected type will be displayed
1523
       as footnotes. You may want to turn 'technical annotations' off."),
1524
    '#options' => $annotationTypeOptions,
1525
  );
1526
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1527
  if (!empty($annotationsTypesAsFootnotes)) {
1528
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1529
  }
1530

    
1531
  // ---- original source --- //
1532
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1533
      '#type' => 'fieldset',
1534
      '#tree' => TRUE,
1535
      '#title' => t('Source Citations'),
1536
      '#collapsible' => FALSE,
1537
      '#collapsed' => FALSE,
1538
  );
1539

    
1540
  $bibliography_settings = get_bibliography_settings(true);
1541

    
1542
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1543
      '#type' => 'checkbox',
1544
      '#title' => t('Original Source in bibliography'),
1545
      '#default_value' => $bibliography_settings['enabled'],
1546
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1547
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1548
       into the bibliography also depends on the settings in the ' .
1549
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1550
        '. 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.'),
1551
  );
1552

    
1553
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1554
    '#type' => 'select',
1555
    '#title' => t('The format of the key numerals'),
1556
    '#default_value' => $bibliography_settings['key_format'],
1557
    '#options' => array('latin' => 'Latin',
1558
      'ROMAN' => 'Roman (upper case)',
1559
      'roman' => 'Roman (lower case)',
1560
      'ALPHA'=> 'Alphabet (upper case)',
1561
      'alpha' => 'Alphabet (lower case)')
1562
  );
1563

    
1564
  // --- Advanced Search --- //
1565
  $form['asearch'] = array(
1566
      '#type' => 'fieldset',
1567
      '#title' => t('Advanced search'),
1568
      '#collapsible' => FALSE,
1569
      '#collapsed' => FALSE,
1570
  );
1571
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1572
      '#type' => 'checkbox',
1573
      '#title' => t('Show advanced search link'),
1574
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1575
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1576
  );
1577

    
1578
  // ---- Taxon Name Rendering --- //
1579
  $form['taxon_name'] = array(
1580
      '#type' => 'fieldset',
1581
      '#title' => t('Taxon name display'),
1582
      '#collapsible' => TRUE,
1583
      '#collapsed' => TRUE,
1584
      '#description' => t('The display of taxon names is configured by two parts.
1585
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1586
          The name parts are defined in the <stong>part definitions</strong>'),
1587
  );
1588

    
1589
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1590
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1591
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1592
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1593

    
1594
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1595
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1596
    $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.)';
1597
  } else if($is_custom_part_definition){
1598
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1599
  } else  {
1600
    $which_version_message = '(These are the default part definition.)';
1601
  }
1602

    
1603
  $diff_viewer_markup = '';
1604
  if($is_custom_part_definition){
1605
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1606
  }
1607

    
1608
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1609
    . $which_version_message
1610
    . '</div>'
1611
    . $diff_viewer_markup;
1612

    
1613
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1614
      '#type' => 'textarea',
1615
      '#title' => t('Part definitions'),
1616
      '#element_validate' => array('form_element_validate_json'),
1617
      '#default_value' =>  $current_part_definition_json,
1618
      '#description' => '
1619
          <p>' . $which_version_message . '</p>
1620
          <p>
1621
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1622
          </p>
1623
          <p>
1624
           A full taxon name plus additional information can consist of the following elements:
1625
          <ul>
1626
             <li>name: the taxon name inclugin rank nbut without author</li>
1627
             <li>authors:  The authors of a reference, also used in taxon names</li>
1628
             <li>reference: the nomenclatural reference,</li>
1629
             <li>microreference:  Volume, page number etc.</li>
1630
             <li>status:  The nomenclatural status of a name</li>
1631
             <li>description: name descriptions like protologues etc ...</li>
1632
          </ul>
1633
          </p>
1634
          <p>
1635
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1636
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1637
           The following parts can be formed and are recognized by the system:
1638
          <ul>
1639
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1640
            <li>authorshipPart: the author (for example: "L.")</li>
1641
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1642
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1643
               be combined when a link to the taxon is rendered.</li>
1644
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1645
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1646
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1647
            <li>statusPart: the nomenclatorical status</li>
1648
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1649
          </ul>
1650
          </p>
1651
          <p>
1652
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1653
           specific parts part definitions:
1654
          <ul>
1655
            <li>BotanicalName</li>
1656
            <li>ZoologicalName</li>
1657
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1658
          </ul>
1659
           An example:
1660
          <pre>
1661
           {
1662
            "ZoologicalName": {
1663
              "namePart": {
1664
                "name": true
1665
              },
1666
              "referencePart": {
1667
                "authors": true
1668
              },
1669
              "microreferencePart": {
1670
                "microreference": true
1671
              },
1672
              "statusPart": {
1673
                "status": true
1674
              },
1675
              "descriptionPart": {
1676
                "description": true
1677
              }
1678
            },
1679
            "BotanicalName": {
1680
              "namePart": {
1681
                "name": true,
1682
                "authors": true
1683
              },
1684
              "referencePart": {
1685
                "reference": true,
1686
                "microreference": true
1687
              },
1688
              "secReferencePart": {
1689
                "secReference": true
1690
              },
1691
              "statusPart": {
1692
                "status": true
1693
              },
1694
              "descriptionPart": {
1695
                "description": true
1696
              }
1697
            }
1698
          }
1699
           </pre>',
1700
  );
1701

    
1702
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1703
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1704
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1705
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1706
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1707

    
1708
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1709
    $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.)';
1710
  } else if($is_custom_render_template){
1711
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1712
  } else {
1713
    $which_version_message = '(These are the default render templates.)';
1714
  }
1715

    
1716
  $diff_viewer_markup = '';
1717
  if($is_custom_render_template){
1718
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1719
  }
1720

    
1721
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1722
    . $which_version_message
1723
    . '</div>'
1724
    . $diff_viewer_markup;
1725

    
1726
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1727
      '#type' => 'textarea',
1728
      '#title' => t('Name render templates'),
1729
      '#element_validate' => array('form_element_validate_json'),
1730
      '#default_value' =>  $current_render_templates_json,
1731
      '#description' => '
1732
          <p>' . $which_version_message . '</p>
1733
          <p>
1734
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1735
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1736
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1737
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1738
          The following render Path keys are currently recognized:
1739
          <ul>
1740
            <li>list_of_taxa</li>
1741
            <li>acceptedFor</li>
1742
            <li>homonym</li>
1743
            <li>taxon_page_synonymy</li>
1744
            <li>typedesignations</li>
1745
            <li>taxon_page_title</li>
1746
            <li>polytomousKey</li>
1747
            <li>na: name + authorship</li>
1748
            <li>nar:name + authorship + reference</li>
1749
            <li>#DEFAULT</li>
1750
          </ul>
1751
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1752
          array element should be a comma separated list of render paths, without any whitespace!.
1753
          </p>
1754
          <p>
1755
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1756
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1757
          <p>
1758
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1759
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1760
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1761
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1762
          links if the paramters $nameLink or $refenceLink are given to the name render function
1763
          (this is hard coded and cannot be configured here).',
1764
  );
1765

    
1766
  // @WA: D7 form api does not support reset buttons,
1767
  // so to mimic the D5 reset button we add one like this.
1768
  $form['actions']['reset'] = array(
1769
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1770
    '#weight' => 1000,
1771
  );
1772

    
1773
  $form['#submit'] = array('submit_json_as_php_array');
1774
  // #json_elements especially defined for submit_json_as_php_array()
1775
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1776
  return system_settings_form($form);
1777
}
1778

    
1779

    
1780
/**
1781
 * @param $form_name
1782
 * @param $form_title
1783
 * @param $collapsed
1784
 * @param string $form_description
1785
 *   The description for the fieldset of the gallery setting.
1786
 * @return mixed
1787
 */
1788
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1789
  $form[$form_name] = array(
1790
    '#type' => 'fieldset',
1791
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1792
    '#collapsible' => TRUE,
1793
    '#collapsed' => $collapsed,
1794
    '#tree' => TRUE,
1795
    '#description' => $form_description,
1796
  );
1797

    
1798
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1799
  $gallery_settings = variable_get($form_name, $default_values);
1800
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1801
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1802
    /*
1803
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1804
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1805
    '#type' => 'textfield',
1806
    '#title' => t('Search Page Size'),
1807
    '#default_value' => $test,
1808
    '#description' => t('Number of Names to display per page in search results.')
1809
    );
1810
    */
1811
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1812
      '#type' => 'checkbox',
1813
      '#title' => t('Show media thumbnails for accepted taxa'),
1814
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1815
    );
1816

    
1817
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1818
      '#type' => 'checkbox',
1819
      '#title' => t('Show media thumbnails for synonyms'),
1820
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1821
      '#description' => '',
1822
    );
1823
  }
1824

    
1825
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1826
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1827
    '#type' => 'checkbox',
1828
    '#title' => t('Show captions under thumbnails'),
1829
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1830
    '#description' => '',
1831
  );
1832

    
1833
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1834
    '#type' => 'textfield',
1835
    '#title' => t('Thumbnail size') . ':',
1836
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1837
    '#description' => t('Select the size of each individual thumbnail.'),
1838
  );
1839

    
1840
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1841
    '#type' => 'textfield',
1842
    '#title' => t('Number of columns') . ':',
1843
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1844
    '#description' => t('Group the thumbnails in columns: select how many
1845
      columns the gallery should display.'),
1846
  );
1847

    
1848
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1849
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1850
      '#type' => 'textfield',
1851
      '#title' => t('Maximum number of rows') . ':',
1852
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1853
      '#description' => t('You can group the thumbnails in rows, select in how
1854
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1855
        If you want an unlimited number of rows please set to 0.'),
1856
    );
1857
  }
1858

    
1859
  return $form;
1860
}
1861

    
1862
/**
1863
 * @todo document this function.
1864
 */
1865
function cdm_settings_layout_taxon() {
1866
  $collapsed = FALSE;
1867
  $form = array();
1868

    
1869
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1870

    
1871
  // --------- TABBED TAXON ------- //
1872
  $form['taxon_tabs'] = array(
1873
    '#type' => 'fieldset',
1874
    '#title' => t('Taxon tabs'),
1875
    '#collapsible' => TRUE,
1876
    '#collapsed' => TRUE,
1877
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1878
  );
1879

    
1880
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1881
    '#type' => 'checkbox',
1882
    '#title' => t('Tabbed taxon page'),
1883
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1884
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1885
  );
1886

    
1887
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1888
    '#type' => 'checkbox',
1889
    '#title' => t('Synonymy as tab'),
1890
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1891
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1892
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1893
  );
1894

    
1895
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1896
    '#type' => 'checkboxes',
1897
    '#title' => t('Section/Tab visibility') . ':',
1898
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1899
    '#options' => get_taxon_options_list()
1900
  );
1901

    
1902
  // WEIGHT
1903
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1904
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1905
    '#title'  => 'Section/Tab order',
1906
    '#type' => 'fieldset',
1907
    '#collapsible' => false,
1908
    '#tree' => true,
1909
    '#description' => 'The weight value defines the order of the section/tab.'
1910
  );
1911
  // Weights range from -delta to +delta, so delta should be at least half
1912
  // of the amount of tabs present.
1913
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1914
  foreach (get_taxon_tabs_list() as $label) {
1915
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1916
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1917
        '#title' => $label,
1918
        '#type'  => 'weight',
1919
        '#default_value' => $taxon_tabs_weights[$key],
1920
        '#delta' => $tab_weight_delta
1921
    );
1922
  }
1923

    
1924
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1925
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1926
    '#title'  => 'Section/Tab label override',
1927
    '#type' => 'fieldset',
1928
    '#collapsible' => false,
1929
    '#tree' => true,
1930
    '#description' => 'Setting a label for a section/tab will override the default label. 
1931
      Please enter the label text in the default language of the portal.'
1932
  );
1933
  foreach (get_taxon_tabs_list() as $label) {
1934
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1935
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1936
      '#title' => $label,
1937
      '#type'  => 'textfield',
1938
      '#default_value' => $taxon_tabs_labels[$key]
1939
    );
1940
  }
1941

    
1942
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1943
    '#type' => 'select',
1944
    '#title' => t('Default tab to display') . ':',
1945
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1946
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1947
    '#description' => t('<p>Select the default tab to display when visiting a
1948
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1949
      <strong>Note:</strong> After performing a search and clicking in any
1950
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1951
      taxon and not the above selected tab.'),
1952
  );
1953

    
1954
  /* ======  TAXON_PROFILE ====== */
1955
  $form['taxon_profile'] = array(
1956
    '#type' => 'fieldset',
1957
    '#title' => t('Taxon profile (tab)'),
1958
    '#description' => t('<p>This section covers the settings related to the taxon
1959
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1960
    '#collapsible' => TRUE,
1961
    '#collapsed' => TRUE,
1962
  );
1963

    
1964
  // ---- PROFILE PICTURE ----//
1965

    
1966
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1967
    '#type' => 'fieldset',
1968
    '#tree' => TRUE,
1969
    '#title' => t('Taxon profile picture'),
1970
    '#collapsible' => TRUE,
1971
    '#collapsed' => FALSE,
1972
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1973
  );
1974

    
1975
  //FIXME migrate variables:
1976
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1977
  // FIXME
1978
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1979

    
1980
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1981

    
1982
  /*
1983
   * 'show' => 1,
1984
   * 'maxextend' => 184,
1985
   * 'media_uri_query' => ''
1986
   * 'custom_placeholder_image_on' => 1,
1987
   * 'custom_placeholder_image_fid' => ''
1988
   */
1989
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1990
    '#type' => 'checkbox',
1991
    '#title' => t('Enable profile picture'),
1992
    '#description' => t('Show the profile picture.'),
1993
    '#default_value' => $taxon_profile_image_settings['show'],
1994
  );
1995

    
1996
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1997
      '#type' => 'textfield',
1998
      '#tree' => TRUE,
1999
      '#title' => t('Profile picture maximum extend'),
2000
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2001
      '#field_suffix' => 'px',
2002
      '#maxlength' => 4,
2003
      '#size' => 4,
2004
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2005
  );
2006

    
2007
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2008
      '#type' => 'textfield',
2009
      '#tree' => TRUE,
2010
      '#title' => t('Additional URI query parameter'),
2011
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2012
      '#maxlength' => 1024,
2013
      '#size' => 60,
2014
      '#description' => t('Additional query parameters to be used when requesting for the  
2015
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2016
            The query parameters will be appended to the uri of the media representation part
2017
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2018
  );
2019

    
2020
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2021
    '#type' => 'checkbox',
2022
    '#title' => t('Show the placeholder image'),
2023
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2024
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2025
  );
2026

    
2027
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2028
      '#type' => 'checkbox',
2029
      '#title' => t('Use a custom placeholder image'),
2030
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2031
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2032
  );
2033

    
2034
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2035
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2036
        '#type' => 'managed_file',
2037
        '#title' => t('Custom placeholder image file'),
2038
        '#progress_indicator' => 'bar',
2039
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2040
    //       '#name' => 'custom_placeholder_image',
2041
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2042
    );
2043

    
2044
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2045
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2046
      $url = file_create_url($profile_image_file->uri);
2047
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2048
                '#type' => 'item',
2049
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2050
      );
2051
    }
2052
  } else {
2053
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2054
      '#type' => 'hidden',
2055
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2056
    );
2057
  }
2058

    
2059
  $options = cdm_rankVocabulary_as_option();
2060
  array_unshift($options, '-- DISABLED --');
2061
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2062
    '#type' => 'select',
2063
    '#title' => t('Hide profile picture for higher ranks') . ':',
2064
    '#default_value' => variable_get('image_hide_rank', '0'),
2065
    '#options' => $options,
2066
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2067
  );
2068

    
2069
  // -- MEDIA THUMBNAILS -- //
2070
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2071
  $form_title = 'Taxon Profile Images';
2072
  $form_description = '<p>The different section 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>';
2073
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2074

    
2075
  // ---- FEATURE TREE BLOCKS ---- //
2076
  $form['taxon_profile']['feature_blocks'] = array(
2077
    '#type' => 'fieldset',
2078
    '#title' => t('Feature Blocks'),
2079
    '#collapsible' => TRUE,
2080
    '#collapsed' => FALSE,
2081
    '#description' => t("This section covers settings related to the taxon's
2082
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2083
      features such as description, distribution, common names"),
2084
  );
2085
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2086
  $profile_feature_tree = get_profile_feature_tree();
2087
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2088
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2089
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2090
  }
2091
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2092
    '#type' => 'radios',
2093
    '#title' => t('Taxon profile feature tree') . ':',
2094
    '#default_value' => $profile_feature_tree_uuid,
2095
    '#options' =>  $featureTrees['options'],
2096
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2097
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2098
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2099
      profile page.'
2100
    ),
2101
  );
2102

    
2103
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2104
  $profile_feature_tree = get_profile_feature_tree();
2105

    
2106
  if (isset($profile_feature_tree->root->childNodes)) {
2107

    
2108
    $form_feature_block_layout = array(
2109
      '#type' => 'fieldset',
2110
      '#tree' => true,
2111
      '#title' => t('Taxon profile feature block settings'),
2112
      '#collapsible' => TRUE,
2113
      '#collapsed' => FALSE,
2114
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2115
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2116
      The subforms have the following settings in common:<br />
2117
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2118
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2119
      <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>
2120
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2121
            <ol>
2122
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2123
                appended in brackets like "text (source references)". If the original source has name in source
2124
                information it will be appended to the citation string,
2125
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2126
             <li>if the text of the TextData is empty, the original source citations are the only content
2127
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2128
                prepended to the citation string like: "name in source: citation"</li>
2129
            </ol>
2130
            <strong>If disabled:</strong><br />
2131
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2132
             citations are the only content, the resulting feature block content would only consist of footnotes.
2133
             In this case the display of the respective feature block is suppressed.</div>
2134
      </dl>
2135
      <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
2136
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2137
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2138
        . '</em></div>
2139
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2140
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2141
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2142
      <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>
2143
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2144
           cdm_feature_block_element_tag_name()</div>
2145
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2146
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2147
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2148
    );
2149

    
2150

    
2151
    $feature_list_layout_settings_disabled = FALSE;
2152

    
2153
    // creating helper object to retrieve the default settings
2154
    $featureNode = new stdClass();
2155
    $featureNode->feature = new stdClass();
2156
    $featureNode->feature->uuid="DEFAULT";
2157
    $featureNode->feature->representation_L10n = "Default";
2158
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2159

    
2160
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2161

    
2162
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2163

    
2164
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2165
        $subform_id = $featureNode->feature->uuid;
2166
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2167

    
2168
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2169

    
2170
        $form_feature_block_layout[$subform_id] = array(
2171
          '#type' => 'fieldset',
2172
          '#tree' => TRUE,
2173
          '#title' => $featureNode->feature->representation_L10n,
2174
          '#collapsible' => FALSE,
2175
          '#collapsed' => FALSE,
2176
        );
2177
        if($featureNode->feature->uuid == "DEFAULT"){
2178
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2179
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2180
          references</em> and <em>names in source</em> is only possible in the defaults';
2181
        }
2182

    
2183
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2184
          '#type' => 'select',
2185
          '#title' => 'List type',
2186
          '#default_value' => $feature_block_setting['as_list'],
2187
          '#options' => array(
2188
            'div' => 'not as list',
2189
            'ul' => 'bullet list',
2190
            'ol' => 'numbered list',
2191
            'dl' => 'definition list'
2192
          ),
2193
        );
2194

    
2195
        if($featureNode->feature->uuid == "DEFAULT"){
2196
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2197
            '#type' => 'checkbox',
2198
            '#title' => t('Link to reference'),
2199
            '#default_value' => $feature_block_setting['link_to_reference'],
2200
          );
2201

    
2202
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2203
            '#type' => 'checkbox',
2204
            '#title' => 'Link to name used in source',
2205
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2206
          );
2207
        }
2208

    
2209
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2210
          '#type' => 'checkbox',
2211
          '#title' => 'Sources as content',
2212
          '#default_value' => $feature_block_setting['sources_as_content'],
2213
        );
2214

    
2215
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2216
          '#type' => 'checkbox',
2217
          '#title' => 'Put sources also as content to bibliography',
2218
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2219
        );
2220

    
2221
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2222
          '#type' => 'select',
2223
          '#title' => t('Sort elements'),
2224
          '#default_value' => $feature_block_setting['sort_elements'],
2225
          '#options' => array(
2226
            NO_SORT => 'No sorting',
2227
            SORT_ASC => 'Ascending',
2228
            SORT_DESC => 'Descending',
2229
            SORT_HIERARCHICAL => 'Hierarchical'
2230
          ),
2231
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2232
          <dl>
2233
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2234
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2235
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2236
          <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>
2237
          </dl>',
2238
        );
2239

    
2240
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2241
          '#type' => 'select',
2242
          '#title' => t('Element tag'),
2243
          '#options' => array(
2244
            'span' => 'span',
2245
            'div' => 'div',
2246
            'p' => 'p'
2247
          ),
2248
          '#default_value' => $feature_block_setting['element_tag'],
2249
        );
2250
        $form_feature_block_layout[$subform_id]['glue'] = array(
2251
          '#type' => 'textfield',
2252
          '#title' => t('Element glue'),
2253
          '#default_value' => $feature_block_setting['glue'],
2254
          '#size' => 10
2255
      );
2256

    
2257
      }
2258
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2259
    }
2260
  }
2261

    
2262
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2263
  $form['taxon_profile']['structured_description_featuretree'] = array(
2264
    '#type' => 'fieldset',
2265
    '#title' => t('Structured Description Feature Tree'),
2266
    '#collapsible' => TRUE,
2267
    '#collapsed' => FALSE,
2268
  );
2269
  $featureTrees = cdm_get_featureTrees_as_options();
2270
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2271
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2272
    $profile_feature_tree_uuid = NULL;
2273
  }
2274
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2275
    '#type' => 'radios',
2276
    '#title' => t('Natural language representation of structured descriptions') . ':',
2277
    '#default_value' => $profile_feature_tree_uuid,
2278
    '#options' => $featureTrees['options'],
2279
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2280
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2281
    '#description' => t('Taxon descriptions can be stored in a highly structured
2282
      form. The feature tree selected here will be used to generate textual
2283
      representation in natural language.'
2284
    ),
2285
  );
2286

    
2287

    
2288

    
2289
  // ---- DISTRIBUTION LAYOUT ---- //
2290
  $form['taxon_profile']['distribution_layout'] = array(
2291
    '#title' => t('Distribution'),
2292
    '#collapsible' => TRUE,
2293
    '#collapsed' => FALSE,
2294
    '#type' => 'fieldset',
2295
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2296
        Map settings regarding the geometry, layers, etc are found in the '
2297
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2298
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2299
      . l(
2300
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2301
        array('fragment' => 'edit-feature-block-settings')
2302
      )
2303
      . ' More general settings regrading the filtering of Distributions are found at '
2304
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2305
      . '. (These settings here will be merged in future releases into the feature block settings)',
2306

    
2307
  );
2308

    
2309
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2310

    
2311
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2312
    '#type' => 'checkbox',
2313
    '#title' => t('Condensed distribution'),
2314
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2315
    '#description' => 'This option enables the display of a very compact representation
2316
    of the distribution which includes also information on the status.',
2317
  );
2318

    
2319
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2320
    '#type' => 'select',
2321
    '#title' => t('Condensed distribution recipe'),
2322
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2323
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2324
    '#description' => 'Recipe for creating the condensed distribution.',
2325
  );
2326

    
2327
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2328
    '#type' => 'textfield',
2329
    '#title' => t('Condensed distribution info path'),
2330
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2331
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2332
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2333
  );
2334

    
2335

    
2336
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2337
    '#type' => 'radios',
2338
    '#title' => t('Display mode') . ':',
2339
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2340
    '#options' => array(
2341
      'FLAT_ALPHA' => t('Flat list'),
2342
      'TREE' => t('Hierarchically ordered'),
2343
    ),
2344
    '#description' => 'Taxon distribution information is displayed with
2345
    focus on the area of the distribution. The list of areas can either be shown
2346
    as flat list ordered alphabetically or in the hierarchical of the parent
2347
    area and subarea relationship. Fall back areas areas with no Distribution data
2348
    are hidden from the area hierarchy so that their sub areas will move one level up.
2349
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2350
    ' for details on the <em>Marked area filter</em>.',
2351
  );
2352

    
2353
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2354
    '#type' => 'fieldset',
2355
    '#tree' => true,
2356
    '#title' => t('Distribution hierarchy style')
2357
  );
2358

    
2359
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2360
  foreach(array_keys($hierarchy_styles) as $level) {
2361
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2362
      '#type' => 'fieldset',
2363
      '#tree' => true,
2364
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2365
      '#attributes' => array('class' => array('fieldset-float'))
2366
    );
2367
    foreach ($hierarchy_styles[$level] as $key => $value) {
2368
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2369
        '#type' => 'textfield',
2370
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2371
        '#default_value' => $hierarchy_styles[$level][$key],
2372
        '#maxlength' => 4,
2373
        '#size' => 4
2374
      );
2375
    }
2376
  }
2377

    
2378
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2379
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2380
    '#type' => 'checkboxes',
2381
    '#title' => 'Omit area levels',
2382
    '#options' => $level_options,
2383
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2384
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2385
    Areas which belong to the selected area levels will be hidden in the portal.',
2386
  );
2387

    
2388
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2389
    '#type' => 'checkbox',
2390
    '#title' => t('Show TextData elements on top of the map'),
2391
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2392
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2393
      elements on top of the map. Otherwise all <code>TextData</code>
2394
      distribution elements will be listed below the other area elements.
2395
      This option is useful if you need to have descriptive texts for each
2396
      distribution map.'),
2397
  );
2398

    
2399
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2400
      '#type' => 'textarea',
2401
      '#title' => t('Custom status colors'),
2402
      '#element_validate' => array('form_element_validate_json'),
2403
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2404
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2405
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2406
          reference list of the idInVocabulary values of absence and presence terms:
2407
<pre>
2408
Presence Term
2409
p        present
2410
pd        present: doubtfully present
2411
n        native
2412
nq        native: presence questionable
2413
nd        native: doubtfully native
2414
c        cultivated
2415
i        introduced
2416
iq        introduced: presence questionable
2417
id        introduced: doubtfully introduced (perhaps cultivated only)
2418
ip        introduced: uncertain degree of naturalisation
2419
ia        introduced: adventitious (casual)
2420
in        introduced: naturalized
2421
ic        introduced: cultivated
2422
e        endemic for the relevant area
2423
na        naturalised
2424
iv        invasive
2425

2426
AbsenceTerm
2427
a        absent
2428
f        reported in error
2429
nf        native: reported in error
2430
if        introduced: reported in error
2431
cf        cultivated: reported in error
2432
ne        native: formerly native
2433
ie        introduced: formerly introduced
2434

2435
</pre>'),
2436
  );
2437

    
2438

    
2439
  /* ====== SYNONYMY ====== */
2440
  $form['taxon_synonymy'] = array(
2441
    '#type' => 'fieldset',
2442
    '#title' => t('Taxon synonymy (tab)'),
2443
    '#collapsible' => TRUE,
2444
    '#collapsed' => TRUE,
2445
    '#description' => t('This section covers the settings related to the taxon
2446
      <strong>synonymy</strong> tab.'),
2447
  );
2448

    
2449
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2450
    '#type' => 'checkbox',
2451
    '#title' => t('Show accepted taxon on top of the synonymy'),
2452
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2453
    '#description' => t('If checked, the first homotypic taxon is a repetition
2454
      of the accepted taxon most likely with the full nomenclatural reference
2455
      (depending on the currently chosen theme).'),
2456
  );
2457

    
2458
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2459
    '#type' => 'checkbox',
2460
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2461
      coming from a synonym link.'),
2462
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2463
    '#description' => t('Check this if after doing a search and clicking on a
2464
      synonym you want to see the "accept of" text for the accepted synonym.'),
2465
  );
2466

    
2467
  /* === currently unused ===
2468
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2469
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2470
    '#type' => 'checkboxes',
2471
    '#title' => t('Display name relationships') . ':',
2472
    '#default_value' => variable_get('name_relationships_to_show', 0),
2473
    '#options' => $nameRelationshipTypeOptions,
2474
    '#description' => t('Select the name relationships you want to show for the
2475
      accepted taxa.'),
2476
  );
2477
 */
2478

    
2479
  $form['taxon_synonymy']['taxon_relations'] = array(
2480
    '#type' => 'fieldset',
2481
    '#title' => t('Taxon relationships'),
2482
    '#collapsible' => FALSE,
2483
    '#collapsed' => FALSE
2484
  );
2485

    
2486
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2487
    '#type' => 'checkbox',
2488
    '#title' => t('Show taxon relations ships of accepted taxon'),
2489
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2490
    '#description' => t('If this option is enabled the synonymy will show the
2491
      below selected taxon relationships of accepted taxa.'),
2492
  );
2493

    
2494
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2495
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2496
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2497
    '#type' => 'checkboxes',
2498
    '#title' => t('Taxon relationship types') . ':',
2499
    '#description' => t('Only taxon relationships of the selected type will be
2500
      displayed'),
2501
    '#options' => $taxon_relationship_type_options,
2502
    '#default_value' => $taxon_relationship_type_defaults,
2503
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2504
  );
2505

    
2506
  $form['taxon_synonymy']['name_relations'] = array(
2507
    '#type' => 'fieldset',
2508
    '#title' => t('Name relationships'),
2509
    '#collapsible' => FALSE,
2510
    '#collapsed' => FALSE
2511
  );
2512

    
2513
  $name_relationship_type_options = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2514
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2515
    '#type' => 'checkboxes',
2516
    '#title' => t('Name relationship types') . ':',
2517
    '#description' => t('Only name relationships of the selected type will be
2518
      displayed'),
2519
    '#options' => $name_relationship_type_options,
2520
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2521
  );
2522

    
2523
  // ====== SPECIMENS ====== //
2524
  $form['taxon_specimens'] = array(
2525
    '#type' => 'fieldset',
2526
    '#title' => t('Taxon specimens (tab)'),
2527
    '#collapsible' => TRUE,
2528
    '#collapsed' => TRUE,
2529
    '#description' => t('This section covers the settings related to the taxon
2530
      <strong>specimens</strong> tab.'),
2531
  );
2532

    
2533
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2534

    
2535
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2536
    '#type' => 'checkbox',
2537
    '#title' => t('Show specimen derivatives in a compressed table'),
2538
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2539
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2540
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2541
  );
2542

    
2543
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2544
        '#type' => 'textfield',
2545
        '#title' => t('Number of records per page') . ':',
2546
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2547
    );
2548

    
2549
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2550
    '#type' => 'checkbox',
2551
    '#title' => t('Show "Associated with" in specimen table.'),
2552
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2553
  );
2554

    
2555
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2556
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2557
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2558
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2559
  }
2560
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2561
    '#type' => 'radios',
2562
    '#title' => t('Specimen description feature tree') . ':',
2563
    '#default_value' => $profile_feature_tree_uuid,
2564
    '#options' =>  $featureTrees['options'],
2565
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2566
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2567
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2568
    ),
2569
  );
2570

    
2571
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2572
  $form_title = t('Specimen media');
2573
  $form_description = t('Specimens may have media which is displayed at the
2574
     Specimen tab/section as a gallery. It is possible to configure the
2575
     thumbnails gallery here, however for configuring how a single media should
2576
     be displayed please go to !url.</p>',
2577
     array(
2578
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2579
     ));
2580
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2581

    
2582
  // --- MEDIA GALLERY ---- //
2583
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2584
  $form_title = 'Media gallery (tab)';
2585
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2586
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2587
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2588
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2589
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2590
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2591
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2592

    
2593
  // Comment @WA: D7 form api does not support reset buttons,
2594
  // so to mimic the D5 reset button we add one like this.
2595
  $form['actions']['reset'] = array(
2596
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2597
    '#weight' => 1000,
2598
  );
2599
  return system_settings_form($form);
2600
}
2601

    
2602
/**
2603
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2604
 *
2605
 * @param $map_id
2606
 * @param $form
2607
 * @return mixed
2608
 */
2609
function _cdm_map_visibility_setting($map_id)
2610
{
2611
  return array(
2612
    '#type' => 'select',
2613
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2614
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2615
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2616
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2617
        The map also can forced to show up <b>always</b> or <b>never</b>."
2618
  );
2619
}
2620

    
2621
/**
2622
 * @todo document this function.
2623
 */
2624
function cdm_settings_layout_search() {
2625

    
2626
  $form = array();
2627

    
2628
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2629

    
2630
  $form['search_settings'] = array(
2631
    '#type' => 'fieldset',
2632
    '#title' => t('Taxa Search'),
2633
    '#collapsible' => FALSE,
2634
    '#collapsed' => FALSE,
2635
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2636
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2637
         where they can write the text to be searched. You can find Drupal block configuration
2638
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2639
  );
2640

    
2641
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2642
      '#type' => 'checkbox',
2643
      '#title' => t('Ignore the chosen classification in simple search'),
2644
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2645
      '#description' => t('The simple search, which can be executed via the search block,
2646
          will by default search on the classification selected in the classification browser
2647
          selector. Set the tick if you want your portal to search on all classifications.'),
2648
  );
2649

    
2650
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2651
    '#type' => 'checkbox',
2652
    '#title' => t('Run simple search with free-text search backend.'),
2653
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2654
    '#description' => t('The simple search uses by default another search
2655
      backend as the advances search. By checking this option the simple search can be
2656
      configured to also use the free-text search backend.'),
2657
  );
2658

    
2659
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2660
    '#type' => 'checkbox',
2661
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2662
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2663
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2664
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2665
  );
2666

    
2667
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2668
    '#type' => 'textfield',
2669
    '#title' => t('Results per page') . ':',
2670
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2671
    '#description' => t('Number of results to display per page.'),
2672
  );
2673
    
2674
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2675
    '#type' => 'checkbox',
2676
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2677
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2678
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2679
  );
2680

    
2681
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2682
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2683
      '#type' => 'checkboxes',
2684
      '#title' => 'Search mode',
2685
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2686
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2687
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2688
          defaults set here.',
2689
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2690
      '#default_value' => $search_mode_default
2691
      );
2692

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

    
2698
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2699
  );
2700

    
2701
  // --- SEARCH TAXA GALLERY ---- //
2702
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2703
  $collapsed = FALSE;
2704
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2705
  $form_title = 'Taxa Search thumbnails';
2706
  $form_description = 'Search results may show thumbnails. ';
2707
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2708

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

    
2718
/**
2719
 * @todo document this function.
2720
 */
2721
function cdm_settings_layout_media() {
2722

    
2723
  $form = array();
2724

    
2725
  $form['media_settings'] = array(
2726
    '#type' => 'fieldset',
2727
    '#title' => t('Media settings'),
2728
    '#collapsible' => FALSE,
2729
    '#collapsed' => FALSE,
2730
    '#description' => 'This section covers layout settings for media pages.'
2731
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2732
  );
2733

    
2734
  $form['media_settings']['image_gallery_viewer'] = array(
2735
    '#type' => 'select',
2736
    '#title' => t('Image viewer') . ':',
2737
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2738
    '#options' => array(
2739
      'default' => t('Standard image viewer'),
2740
      'fsi' => t('FSI viewer (requires FSI server!)'),
2741
    ),
2742
  );
2743

    
2744
  // --- STANDARD_IMAGE_VIEWER ---- //
2745
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2746
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2747
      '#type' => 'fieldset',
2748
      '#tree' => true,
2749
      '#title' => t('Standard image viewer settings'),
2750
      '#collapsible' => FALSE,
2751
      '#collapsed' => FALSE,
2752
      );
2753

    
2754
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2755
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2756
      '#type' => 'checkbox',
2757
      '#title' => 'Show media representations',
2758
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2759

    
2760
    );
2761
  }
2762

    
2763

    
2764
  // @WA: D7 form api does not support reset buttons,
2765
  // so to mimic the D5 reset button we add one like this.
2766
  $form['actions']['reset'] = array(
2767
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2768
    '#weight' => 1000,
2769
  );
2770
  return system_settings_form($form);
2771
}
2772

    
2773
/**
2774
 * GEOSERVICE and Map settings.
2775
 */
2776
function cdm_settings_geo($form, &$form_state) {
2777

    
2778
  $current_geoserver_settings = get_edit_map_service_settings();
2779
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2780

    
2781

    
2782
  $form = array();
2783

    
2784
  $dummy_distribution_query = NULL;
2785
  if($map_distribution['map_type'] != 1){
2786
    // we need to apply a dummy query since the map service requires for image maps
2787
    // at least as and ad to be defined
2788
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2789
  }
2790

    
2791
  $form['map_preview'] = array(
2792
      '#type' => 'fieldset',
2793
      '#tree' => FALSE,
2794
      '#title' => t('Map preview'),
2795
      '#collapsible' => FALSE,
2796
      '#description' => 'The preview of the map'
2797
       . ($dummy_distribution_query != null ?
2798
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2799
           '.<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.')
2800
  );
2801
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2802
    'move' => "this.cdmOpenlayersMap.printInfo",
2803
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2804
  ), true // resizable
2805
  );
2806

    
2807
  /*
2808
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2809
  );
2810
  */
2811

    
2812
  /*
2813
   * GEO SERVER
2814
   */
2815
  $form['edit_map_server'] = array(
2816
    '#type' => 'fieldset',
2817
    '#tree' => true,
2818
    '#title' => t('EDIT map service'),
2819
    '#collapsible' => TRUE,
2820
    '#collapsed' => TRUE,
2821
    '#description' => t('Configuration and selection of your geo server.
2822
      The Geo Server is responsible for generating the maps.'),
2823
  );
2824

    
2825
  $form['edit_map_server']['base_uri'] = array(
2826
    '#type' => 'select',
2827
    '#title' => t('EDIT map service') . ':',
2828
    '#default_value' => $current_geoserver_settings['base_uri'],
2829
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2830
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2831
  );
2832
  $form['edit_map_server']['version'] = array(
2833
      '#type' => 'select',
2834
      '#title' => t('Version') . ':',
2835
      '#default_value' => $current_geoserver_settings['version'],
2836
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2837
      '#description' => t('The version of the EDIT map services'),
2838
  );
2839

    
2840
  /*
2841
   * MAP SETTINGS
2842
   */
2843

    
2844
  $form[CDM_MAP_DISTRIBUTION] = array(
2845
    '#type' => 'fieldset',
2846
    '#tree' => TRUE,
2847
    '#title' => t('Maps settings'),
2848
    '#collapsible' => TRUE,
2849
    '#collapsed' => TRUE,
2850
    '#description' => t('General configuration for all map types.'),
2851
  );
2852

    
2853
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2854
    '#type' => 'radios',
2855
    '#title' => 'Map types',
2856
    '#options' => array(
2857
      1 => "OpenLayers dynamic map viewer",
2858
      0 => "Plain image",
2859
    ),
2860
    '#default_value' => $map_distribution['map_type'],
2861
    '#description' => 'Two different map types are available :
2862
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2863
      which allows zooming and panning. If enabled you can configure the default layer
2864
      (background of your maps) below.</li>
2865
      <li><em>Plain image</em>: The map will be static non interactive
2866
      image.</li></ul>',
2867
  );
2868
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2869

    
2870
  /*
2871
   * settings for the distribution map are used also for specimens map!!!!
2872
   */
2873

    
2874
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2875
      '#type' => 'textfield',
2876
      '#title' => 'Aspect ratio',
2877
      '#default_value' => $map_distribution['aspect_ratio'],
2878
      '#maxlength' => 4,
2879
      '#size' => 4,
2880
      '#element_validate' => array('element_validate_number'),
2881
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2882
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2883
      width by the height:</br>
2884
      <pre>aspect ratio = w / h</pre>
2885
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2886
      for a square map use <strong>1</strong>.',
2887
  );
2888

    
2889
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2890
    '#type' => 'textfield',
2891
    '#title' => 'Bounding box',
2892
    '#default_value' => $map_distribution['bbox'],
2893
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2894
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2895
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2896
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong>map extent bbox</strong> in <strong class="degree-value"">degree</strong></span> from the map.
2897
      (Maybe you need to change the map base layer to OpeLayers.)
2898
      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
2899
      below the map from where you can copy the bbox string.</p>'),
2900
  );
2901

    
2902
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2903
    '#type' => 'select',
2904
    '#title' => 'Max zoom level',
2905
    '#default_value' => $map_distribution['maxZoom'],
2906
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2907
  );
2908

    
2909
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2910
    '#type' => 'checkbox',
2911
    '#title' => 'Display area labels',
2912
    '#default_value' => $map_distribution['show_labels'],
2913
    '#description' => t('The map will show name labels of the areas'),
2914
  );
2915

    
2916
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2917
    '#type' => 'textfield',
2918
    '#title' => 'Map caption',
2919
    '#default_value' => $map_distribution['caption'],
2920
    '#description' => t('The caption will be shown below the map.'),
2921
  );
2922

    
2923
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2924
    '#type' => 'textfield',
2925
    '#title' => 'Distribution layer opacity',
2926
    '#default_value' => $map_distribution['distribution_opacity'],
2927
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2928
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2929
  );
2930

    
2931
  // --- Plain Image Settings --- //
2932
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2933
    '#type' => 'fieldset',
2934
    '#title' => 'Plain image map settings',
2935
    '#tree' => TRUE,
2936
    '#collapsible' => TRUE,
2937
    '#collapsed' => $open_layers_is_enabled,
2938
    '#description' => 'The settings in this section are still expertimental
2939
      and can only be used with the EDIT map service version 1.1 or above.',
2940
  );
2941
  $edit_mapserver_version = get_edit_map_service_version_number();
2942
  if ($edit_mapserver_version < 1.1) {
2943
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2944
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2945
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2946
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2947
  }
2948

    
2949
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2950
    '#type' => 'textfield',
2951
    '#title' => 'Width',
2952
    '#default_value' => $map_distribution['image_map']['width'],
2953
    '#maxlength' => 4,
2954
    '#size' => 4,
2955
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2956
  );
2957

    
2958
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2959
    '#type' => 'textfield',
2960
    '#title' => 'Background layer',
2961
    '#default_value' => $map_distribution['image_map']['base_layer'],
2962
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2963
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2964
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2965
    )),
2966
  );
2967

    
2968
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2969
    '#type' => 'textfield',
2970
    '#title' => 'Background color',
2971
    '#default_value' => $map_distribution['image_map']['bg_color'],
2972
  );
2973

    
2974
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2975
    '#type' => 'textfield',
2976
    '#title' => 'Background layer style',
2977
     // Only line color by now.
2978
    '#default_value' => $map_distribution['image_map']['layer_style'],
2979
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2980
  );
2981

    
2982
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2983
      '#type' => 'textfield',
2984
      '#title' => 'Projection',
2985
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2986
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2987
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2988
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2989
  );
2990

    
2991

    
2992
  // --- OpenLayers Settings --- //
2993
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2994
    '#type' => 'fieldset',
2995
    '#title' => 'OpenLayers settings',
2996
    '#tree' => TRUE,
2997
    '#collapsible' => TRUE,
2998
    '#collapsed' => !$open_layers_is_enabled,
2999
    '#description' => '',
3000
  );
3001

    
3002

    
3003
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3004
      '#type' => 'checkbox',
3005
      '#title' => 'Display outside max extent',
3006
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3007
      '#description' => t('Allows the map to display parts of the layers which are outside
3008
         the max extent if the aspect ratio of the map and of the baselayer
3009
         are not equal.'),
3010
  );
3011

    
3012

    
3013
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3014
      '#type' => 'checkbox',
3015
      '#title' => 'Show Layer Switcher',
3016
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3017
      '#description' => 'The Layer Switcher control displays a table of contents
3018
      for the map.  This allows the user interface to switch between
3019
      base layers and to show or hide overlays.  By default the switcher is
3020
      shown minimized on the right edge of the map, the user may expand it
3021
      by clicking on the handle.',
3022
  );
3023

    
3024
  if (!$open_layers_is_enabled) {
3025
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3026
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3027
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3028
  }
3029

    
3030
  // The default layer must always be enabled
3031
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3032
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3033

    
3034
  $baselayer_options = array(
3035
    /*
3036
   NOTICE: must correspond to the layers defined in
3037
   js/openlayers_,ap.js#getLayersByName()
3038
   */
3039
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3040
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3041
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3042
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3043
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3044
    // all others EPSG:900913
3045
    'mapnik' => 'OpenStreetMap (mapnik)',
3046
    'stamen_terrain' => 'Stamen Terrain',
3047
    'open_topomap' => 'OpenTopoMap',
3048
    // map quest is no longer free. it is required to sign up for a test plan.
3049
    // 'mapquest_open' => "MapQuest",
3050
    // 'mapquest_sat' => "MapQuest Sattelite",
3051
    'groadmap' => 'Google Roadmap',
3052
    'gsatellite' => 'Google Satellite',
3053
    'ghybrid' => 'Google Hybrid',
3054
    'gterrain' => 'Google Terrain',
3055
//     'veroad' => 'Virtual Earth Roads',
3056
//     'veaer' => 'Virtual Earth Aerial',
3057
//     'vehyb' => 'Virtual Earth Hybrid',
3058
    // 'yahoo' => 'Yahoo Street',
3059
    // 'yahoosat' => 'Yahoo Satellite',
3060
    // 'yahoohyb' => 'Yahoo Hybrid',
3061
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3062
  );
3063

    
3064
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3065
    '#type' => 'checkboxes_preferred',
3066
    '#title' => 'Base Layers',
3067
    '#options' => $baselayer_options,
3068
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3069
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3070
  );
3071

    
3072
  $google_maps_api_key = null;
3073
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3074
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3075
  }
3076
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3077
    '#type' => 'textfield',
3078
    '#title' => 'Google Maps API Key',
3079
    '#default_value' => $google_maps_api_key,
3080
    '#description' => 'In order to use any of the Google map layers you need to provide 
3081
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3082
  );
3083

    
3084
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3085
    $map_distribution['openlayers']['custom_wms_base_layer'],
3086
    'Custom WMS base layer',
3087
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3088
    true // add projection settings
3089
    );
3090

    
3091
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3092
    $map_distribution['openlayers']['wms_overlay_layer'],
3093
    'WMS overlay layer',
3094
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3095
                You can actually combine multiple layers for this overlay. 
3096
                For details please refer to the wms query parameter <code>Layers</code> .'
3097
  );
3098

    
3099
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3100
    '#type' => 'checkbox',
3101
    '#title' => 'Enable overlay layer',
3102
    '#weight' => -100,
3103
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3104
  );
3105

    
3106
  /*
3107
   * Map Legend
3108
   */
3109
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3110
    '#type' => 'fieldset',
3111
    '#title' => 'Map legend',
3112
    '#tree' => TRUE,
3113
    '#collapsible' => TRUE,
3114
    '#collapsed' => TRUE,
3115
    '#description' => 'Configure the maps legend.',
3116
  );
3117

    
3118
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3119
    '#type' => 'checkbox',
3120
    '#title' => 'Display a map legend',
3121
    '#default_value' => $map_distribution['legend']['show'],
3122
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3123
  );
3124

    
3125
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3126
    '#type' => 'textfield',
3127
    '#title' => 'Legend opacity',
3128
    '#default_value' => $map_distribution['legend']['opacity'],
3129
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3130
                         to 0.0 will be not much visible.',
3131
  );
3132

    
3133
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3134
    '#type' => 'textfield',
3135
    '#title' => 'Font size',
3136
    '#default_value' => $map_distribution['legend']['font_size'],
3137
    '#description' => 'Font size in pixels.',
3138
  );
3139

    
3140
  $fontStyles = array(
3141
    0 => "plane",
3142
    1 => "italic",
3143
  );
3144
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3145
    '#type' => 'select',
3146
    '#title' => 'Available font styles',
3147
    '#default_value' => $map_distribution['legend']['font_style'],
3148
    '#options' => $fontStyles,
3149
    '#description' => 'Select a font style for the map legend.',
3150
  );
3151

    
3152
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3153
    '#type' => 'textfield',
3154
    '#title' => 'Icon width',
3155
    '#default_value' => $map_distribution['legend']['icon_width'],
3156
    '#description' => 'Legend icon width in pixels.',
3157
  );
3158
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3159
    '#type' => 'textfield',
3160
    '#title' => 'Icon height',
3161
    '#default_value' => $map_distribution['legend']['icon_height'],
3162
    '#description' => 'Legend icon height in pixels.',
3163
  );
3164

    
3165
  // @WA: D7 form api does not support reset buttons,
3166
  // so to mimic the D5 reset button we add one like this.
3167
  $form['actions']['reset'] = array(
3168
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3169
    '#weight' => 1000,
3170
  );
3171

    
3172
  return system_settings_form($form);
3173
}
3174

    
3175
/**
3176
 * @param $default_settings
3177
 * @param $title
3178
 * @param $description
3179
 * @param bool $add_projection_settings
3180
 * @return array
3181
 */
3182
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3183
{
3184
  $form_elements = array(
3185
    '#type' => 'fieldset',
3186
    '#title' => $title,
3187
    '#tree' => TRUE,
3188
    '#collapsible' => FALSE,
3189
    '#collapsed' => FALSE,
3190
    '#description' => $description,
3191
  );
3192

    
3193
  $form_elements['name'] = array(
3194
    '#type' => 'textfield',
3195
    '#title' => 'Layer name',
3196
    '#default_value' => $default_settings['name'],
3197
    '#description' => 'A arbitrary name for the layer.',
3198
  );
3199
  $form_elements['url'] = array(
3200
    '#type' => 'textfield',
3201
    '#title' => 'WMS url',
3202
    '#default_value' => $default_settings['url'],
3203
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3204
  );
3205
  $form_elements['untiled'] = array(
3206
    '#type' => 'checkbox',
3207
    '#title' => 'Untiled',
3208
    '#default_value' => $default_settings['untiled'],
3209
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3210
  );
3211
  $form_elements['params'] = array(
3212
    '#type' => 'textarea',
3213
    '#title' => 'WMS parameters',
3214
    '#element_validate' => array('form_element_validate_json')