Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / settings.php @ 023c4a03

History | View | Annotate | Download (151 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(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
53

    
54

    
55
  /* ---- MAP SETTING CONSTANTS ---- */
56
  /**
57
   * @var array of URIs eg. http://edit.africamuseum.be"
58
   *   An options array
59
   */
60
  define('EDIT_MAPSERVER_URI', serialize(
61
      array(
62
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
63
      )
64
    )
65
  );
66
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
67
  /**
68
   * @var array of versions eg. "v1.2"
69
   *   An options array
70
   */
71
  define('EDIT_MAPSERVER_VERSION', serialize(
72
      array(
73
//        'v1' => 'v1' ,           // no longer recommended
74
//        'v1.1' => 'v1.1',        // no longer recommended
75
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
76
        'v1.2' => 'v1.2',
77
        'v1.3_dev' => 'v1.3_dev (not recommended)',
78
        'v1.4_dev' => 'v1.4_dev (experimental features)'
79
      )
80
    )
81
  );
82
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
83
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
84

    
85
    // --- Taxon profile settings --- /
86
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
87
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
88
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
89
      array(
90
          'show' => 0,
91
          'maxextend' => 184,
92
          'media_uri_query' => '',
93
          'custom_placeholder_enabled' => 1,
94
          'custom_placeholder_image_on' => 0,
95
          'custom_placeholder_image_fid' => ''
96
      )
97
    )
98
  );
99

    
100

    
101
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
102

    
103
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
104
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
105
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
106
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
107
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
108

    
109
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
110
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
111
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
112
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
113

    
114
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
115
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
116

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

    
137
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
138
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
139
  array(
140
    'general' => '-3',
141
    'synonymy' => '-2',
142
    'images' => '0',
143
    'specimens' => '1',
144
    'keys' => '3',
145
    'experts' => '5',
146
    )
147
));
148

    
149

    
150
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
151
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
152
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
153
  array(
154
    'general' => null,
155
    'synonymy' => null,
156
    'images' => null,
157
    'specimens' => null,
158
    'keys' => null,
159
    'experts' => null,
160
  )
161
));
162

    
163
$taxon_tab_options = get_taxon_tabs_list();
164
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
165

    
166
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
167

    
168
/**
169
 * @todo document this function.
170
 */
171
function get_taxon_options_list() {
172
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
173
  foreach ($taxon_tab_options as $key => $value) {
174
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
175
  }
176
  return $taxon_tab_options;
177

    
178
}
179

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

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

    
345
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
346
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
347
    // to unset a default enntry set the value to 0
348
    array(
349
      'doTaxa'=>'doTaxa',
350
      'doSynonyms' => 'doSynonyms',
351
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
352
      'doMisappliedNames' => 'doMisappliedNames'
353
    )
354
  )
355
);
356

    
357
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
358

    
359
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
360
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
361
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
362

    
363
/* Gallery variables. */
364
$gallery_settings = array(
365
    "cdm_dataportal_show_taxon_thumbnails" => 1,
366
    "cdm_dataportal_show_synonym_thumbnails" => 0,
367
    "cdm_dataportal_show_thumbnail_captions" => 1,
368
    "cdm_dataportal_media_maxextend" => 120,
369
    "cdm_dataportal_media_cols" => 3,
370
    "cdm_dataportal_media_maxRows" => 1,
371
);
372

    
373
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
374
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
375
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
376
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
377
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
378
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
379
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
380
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
381
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
382
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
383
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
384

    
385
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
386
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
387
  'media_representation_details_enabled' => 0
388
)));
389

    
390
/**
391
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
392
 * the snonymy.
393
 *
394
 * @var string
395
 */
396
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
397

    
398
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
399
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
400
    array(
401
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
402
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
403
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
404
    )
405
  )
406
);
407

    
408
/**
409
 * The drupal variable for the configuration of the information aggregation along
410
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
411
 *    - direct: the uuids of the taxon relationship types to take into account in invers
412
 *      direction.
413
 *    - invers: the uuids of the taxon relationship types to take into account in direct
414
 *      direction.
415
 *
416
 * @var String
417
 */
418
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
419
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
420
    array(
421
        'direct'=>array(),
422
        'invers'=>array()
423
     )
424
   ));
425
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
426
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
427
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
428

    
429
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
430
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
431
      array(
432
      'filter_rules' => array(
433
        'statusOrderPreference' => 0,
434
        'subAreaPreference' => 0,
435
      ),
436
      'hiddenAreaMarkerType' => array()
437
     )
438
));
439

    
440
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
441
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
442
  "level_0" => array(
443
    'label_suffix' => ':',
444
    'status_glue' => '',
445
    'item_glue' => ' ',
446
    'item_group_prefix' => '',
447
    'item_group_postfix' => ''
448
  ),
449
  "level_1" => array(
450
    'label_suffix' => '',
451
    'status_glue' => '', // '&#8210; '
452
    'item_glue' => '; ',
453
    'item_group_prefix' => ', ',
454
    'item_group_postfix' => ''
455
  ),
456
  "level_2" => array(
457
    'label_suffix' => '',
458
    'status_glue' => '', // '&#8210; '
459
    'item_glue' => ', ',
460
    'item_group_prefix' => ' (',
461
    'item_group_postfix' => ')'
462
  )
463
)));
464

    
465
/**
466
 * Constant for the drupal variable key distribution_map_visibility
467
 *
468
 * possible values:
469
 *  - never
470
 *  - automatic
471
 *  - always
472
 */
473
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
474
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
475

    
476
/**
477
 * Constant for the drupal variable key specimen_map_visibility
478
 *
479
 * possible values:
480
 *  - never
481
 *  - automatic
482
 *  - always
483
 */
484
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
485
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
486

    
487
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
488
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
489
    array(
490
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
491
        'includeOccurrences' => 0,
492
        'includeTaxonNameDescriptions' => 0
493
     )
494
  ));
495

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

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

    
571
    // unserialize if nessecary
572
    if(!is_array($default)){
573
      $default = unserialize($default);
574
    }
575
    $variable = variable_get($variable_name, array());
576
    $result = drupal_array_merge_deep($default, $variable);
577
    return $result;
578
}
579

    
580
/**
581
 * @todo document this function.
582
 */
583
function getGallerySettings($gallery_config_form_name) {
584
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
585
}
586

    
587
/**
588
 * Returns the string representation of the default tab.
589
 *
590
 * @param bool $returnTabIndex
591
 *   Defaults to FALSE, if set true this function will return the index number
592
 *   of the default tab. (used to supply default values to form elements).
593
 */
594
function get_default_taxon_tab($returnTabIndex = FALSE) {
595

    
596
  global $user;
597
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
598
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
599
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
600
  // Get the user value if the used has chosen to overwrite the system settings.
601
  $user_tab_on = variable_get($user_tab_active, FALSE);
602
  if ($user_tab_on) {
603
    $user_value = variable_get($user_tab, 0);
604
    $index_value = $user_value;
605
    // Get the system value.
606
  }
607
  else {
608
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
609
    $index_value = $system_value;
610
  }
611

    
612
  // Return the index value or the string representation.
613
  if ($returnTabIndex) {
614
    return $index_value;
615
  }
616
  else {
617
    return ($values[$index_value]);
618
  }
619
}
620

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

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

    
692
  // ---- DEFAULTS settings
693

    
694
  // only needed as final option, when the settings are not having a default
695
  $default = array(
696
    'DEFAULT' => array(
697
      'as_list' => 'div',
698
      'link_to_reference' => 0,
699
      'link_to_name_used_in_source' => 1,
700
      'sources_as_content' => 0,
701
      'sources_as_content_to_bibliography' => 0,
702
      'sort_elements' => NO_SORT,
703
      'glue' => '',
704
      'element_tag' => NULL
705
    ),
706
    // settings for pseudo feature bibliography
707
    // only hard coded here
708
    'BIBLIOGRAPHY' => array(
709
      'as_list' => 'div',
710
      'link_to_reference' => 0,
711
      'link_to_name_used_in_source' => 1,
712
      'sources_as_content' => 0,
713
      'sources_as_content_to_bibliography' => 0,
714
      'sort_elements' => NO_SORT,
715
      'glue' => '',
716
      'element_tag' => NULL
717
    )
718
  );
719

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

    
765
  // ---- Special DEFAULTS for existing portals
766
  // TODO:
767
  // this can be removed once the feature block
768
  // settings have been deployed for the first time to these portals
769

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

    
823
  $palmweb_default = array(
824
    'DEFAULT' => array(
825
      'as_list' => 'ul',
826
      'link_to_reference' => 1,
827
      'link_to_name_used_in_source' => 1,
828
      'sources_as_content' => 1,
829
      'sources_as_content_to_bibliography' => 1,
830
      'sort_elements' => NO_SORT,
831
      'glue' => '',
832
      'element_tag' => NULL
833
    ),
834
    UUID_CITATION => array(
835
      'as_list' => 'ul',
836
      'link_to_reference' => 1,
837
      'link_to_name_used_in_source' => 1,
838
      'sources_as_content' => 0,
839
      'sources_as_content_to_bibliography' => 1,
840
      'sort_elements' => SORT_ASC,
841
      'glue' => '',
842
      'element_tag' => 'div'
843
    ),
844
    UUID_DISTRIBUTION => array(
845
      'as_list' => 'div', // currently ignored
846
      'link_to_reference' => 1,
847
      'link_to_name_used_in_source' => 1,
848
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
849
      'sources_as_content_to_bibliography' => 1,
850
      'sort_elements' => NO_SORT, // will cause ...
851
      'glue' => ', ',
852
      'element_tag' => 'span',
853
      'special' => array()
854
    ),
855
  );
856

    
857
  $cyprus_default = $cichorieae_default;
858
  $cyprus_default[UUID_DISTRIBUTION] = array(
859
    'as_list' => 'div', // currently ignored
860
    'link_to_reference' => 0,
861
    'link_to_name_used_in_source' => 0,
862
    'sources_as_content' => 0,
863
    'sources_as_content_to_bibliography' => 0,
864
    'sort_elements' => NO_SORT, // will cause ...
865
    'glue' => ' ',
866
    'element_tag' => 'div',
867
    'special' => array()
868
  );
869

    
870
  $default_theme = variable_get('theme_default', NULL);
871

    
872
  switch ($default_theme) {
873
    case 'garland_cichorieae':
874
      $settings_for_theme = $cichorieae_default;
875
      break;
876
    case 'cyprus':
877
      // cyprus: no longer used in production,
878
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
879
      $settings_for_theme = $cyprus_default;
880
      break;
881
    case 'flore_afrique_centrale':
882
    case 'flora_malesiana':
883
    case 'flore_gabon':
884
      $settings_for_theme = $cichorieae_default;
885
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
886
      break;
887
    case 'palmweb_2':
888
      $settings_for_theme = $palmweb_default;
889
      break;
890
    default:
891
      $settings_for_theme = $other_themes_default;
892
  }
893
  // add pseudo feature settings
894
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
895

    
896
  // ---- END of DEFAULTS
897

    
898
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
899

    
900
  $feature_block_setting = null;
901

    
902
  if (isset($saved_settings[$feature_uuid])) {
903
    $feature_block_setting = $saved_settings[$feature_uuid];
904
  }
905
  else if (isset($settings_for_theme[$feature_uuid])) {
906
    $feature_block_setting = $settings_for_theme[$feature_uuid];
907
  }
908
  else if (isset($settings_for_theme['DEFAULT'])) {
909
    $feature_block_setting = $settings_for_theme['DEFAULT'];
910
  }
911

    
912
  // now merge the default and specific settings
913
  $settings_to_merge = array($default['DEFAULT']);
914
  if(is_array($saved_settings)){
915
    $settings_to_merge[] = $saved_settings['DEFAULT'];
916
  }
917
  if(isset($feature_block_setting)){
918
    $settings_to_merge[] = $feature_block_setting;
919
  }
920
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
921

    
922
  return $feature_block_setting;
923
}
924

    
925
/**
926
 * returns the current setting for the original source bibliography
927
 *
928
 * Caches internally
929
 *
930
 * @return array
931
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
932
 *   - 'enabled': 1|0
933
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
934
 */
935
function get_bibliography_settings($clear_cache = false){
936
  static $bibliography_settings = null;
937
  if(!$bibliography_settings || $clear_cache){
938
    $bibliography_settings = get_array_variable_merged(
939
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
940
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
941
    );
942
  }
943
  return $bibliography_settings;
944
}
945

    
946
/**
947
 * @todo Please document this function.
948
 * @see http://drupal.org/node/1354
949
 */
950
function cdm_dataportal_menu_admin(&$items) {
951
  // Display section on admin/config page.
952
  $items['admin/config/cdm_dataportal'] = array(
953
    'title' => 'CDM Dataportal',
954
    'description' => 'Settings for the CDM DataPortal.',
955
    'position' => 'right',
956
    'weight' => 10,
957
    'page callback' => 'system_admin_menu_block_page',
958
    'access arguments' => array('administer cdm_dataportal'),
959
    'file' => 'system.admin.inc',
960
    'file path' => drupal_get_path('module', 'system'),
961
  );
962
  $items['admin/config/cdm_dataportal/settings'] = array(
963
    'title' => 'Settings',
964
    'description' => 'Settings for the CDM DataPortal.',
965
    'weight' => 0,
966
    'page callback' => 'drupal_get_form',
967
    'page arguments' => array('cdm_settings_general'),
968
    'access arguments' => array('administer cdm_dataportal'),
969
    'type' => MENU_NORMAL_ITEM,
970
  );
971
  $items['admin/config/cdm_dataportal/settings/general'] = array(
972
    'title' => 'General',
973
    'description' => 'General',
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_DEFAULT_LOCAL_TASK,
979
  );
980

    
981
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
982
    'title' => 'Cache',
983
    'description' => 'Cache',
984
    'access arguments' => array('administer cdm_dataportal'),
985
    'page callback' => 'drupal_get_form',
986
    'page arguments' => array('cdm_settings_cache'),
987
    'weight' => 10,
988
    'type' => MENU_LOCAL_TASK,
989
  );
990

    
991
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
992
    'title' => 'Geo & Map',
993
    'description' => 'Geo & Map',
994
    'access arguments' => array('administer cdm_dataportal'),
995
    'page callback' => 'drupal_get_form',
996
    'page arguments' => array('cdm_settings_geo'),
997
    'weight' => 1,
998
    'type' => MENU_LOCAL_TASK,
999
  );
1000

    
1001
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1002
    'title' => 'Layout',
1003
    'description' => 'Configure and adjust the layout of your DataPortal ',
1004
    'access arguments' => array('administer cdm_dataportal'),
1005
    'page callback' => 'drupal_get_form',
1006
    'page arguments' => array('cdm_settings_layout'),
1007
    'weight' => 2,
1008
    'type' => MENU_LOCAL_TASK,
1009
  );
1010

    
1011
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1012
    'title' => 'Taxon',
1013
    'description' => 'Configure and adjust the layout of your DataPortal ',
1014
    'access arguments' => array('administer cdm_dataportal'),
1015
    'page callback' => 'drupal_get_form',
1016
    'page arguments' => array('cdm_settings_layout_taxon'),
1017
    'weight' => 1,
1018
    'type' => MENU_LOCAL_TASK,
1019
  );
1020
  /*
1021
  $items[] = array(
1022
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1023
  'title' => t('Synonymy'),
1024
  'description' => t('Configure and adjust the layout of your DataPortal '),
1025
  'access' => user_access('administer cdm_dataportal'),
1026
  'callback' => 'drupal_get_form',
1027
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1028
  'weight' => 1,
1029
  'type' => MENU_LOCAL_TASK,
1030
  );
1031

1032
  $items[] = array(
1033
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1034
  'title' => t('Specimens'),
1035
  'description' => t('Configure and adjust the layout of your DataPortal '),
1036
  'access' => user_access('administer cdm_dataportal'),
1037
  'callback' => 'drupal_get_form',
1038
  'callback arguments' => array('cdm_settings_layout_specimens'),
1039
  'weight' => 1,
1040
  'type' => MENU_LOCAL_TASK,
1041
  );
1042
  */
1043
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1044
    'title' => 'Search',
1045
    'description' => 'Configure and adjust the layout of your DataPortal ',
1046
    'access arguments' => array('administer cdm_dataportal'),
1047
    'page callback' => 'drupal_get_form',
1048
    'page arguments' => array('cdm_settings_layout_search'),
1049
    'weight' => 2,
1050
    'type' => MENU_LOCAL_TASK,
1051
  );
1052

    
1053
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1054
    'title' => 'Media',
1055
    'description' => 'Configure and adjust the layout of your DataPortal ',
1056
    'access arguments' => array('administer cdm_dataportal'),
1057
    'page callback' => 'drupal_get_form',
1058
    'page arguments' => array('cdm_settings_layout_media'),
1059
    'weight' => 3,
1060
    'type' => MENU_LOCAL_TASK,
1061
  );
1062

    
1063
}
1064

    
1065
/**
1066
 * @todo document this function.
1067
 */
1068
function cdm_help_general_cache() {
1069
  $form = array();
1070
  $form['cache_help'] = array(
1071
    '#type' => 'fieldset',
1072
    '#title' => t('Help'),
1073
    '#collapsible' => TRUE,
1074
    '#collapsed' => TRUE,
1075
  );
1076
  $form['cache_help']['test'] = array('#value' => t('probando'));
1077
  return drupal_render($form);
1078
  $res = array();
1079
  $res['default'] = drupal_render($help);
1080
  return $res;
1081
}
1082

    
1083
/**
1084
 * Configures the settings form for the CDM-API module.
1085
 *
1086
 * @return array
1087
 *   Drupal settings form.
1088
 */
1089
function cdm_settings_general() {
1090

    
1091
  $form['cdm_webservice'] = array(
1092
    '#type' => 'fieldset',
1093
    '#title' => t('CDM Server'),
1094
    '#collapsible' => FALSE,
1095
    '#collapsed' => FALSE,
1096
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1097
        CDM data base to the web via RESTful web services and thus is the source of the data
1098
        to be displayed by a CDM DataPotal.'),
1099
  );
1100

    
1101
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1102
    '#type' => 'textfield',
1103
    '#title' => t('CDM web service URL') . ':',
1104
    '#description' => t('This is the URL to the CDM-Server exposing your data
1105
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1106
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1107
  );
1108

    
1109
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1110
    '#type' => 'markup',
1111
    '#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')
1112
      . ' visible only for administrators',
1113
  );
1114

    
1115
  $form['cdm_webservice']['freetext_index'] = array(
1116
    '#type' => 'fieldset',
1117
    '#title' => t('Freetext index'),
1118
    '#collapsible' => FALSE,
1119
    '#collapsed' => FALSE,
1120
  );
1121

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

    
1136
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1137
  $trigger_link_options = array(
1138
    'attributes' => array(
1139
      'class' => 'index-trigger'
1140
    ),
1141
  );
1142
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1143
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1144
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1145
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1146
      ))
1147
    . '<div id="index-progress"></div></div>',
1148
  );
1149

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

    
1175
  $form['cdm_webservice']['proxy'] = array(
1176
    '#type' => 'fieldset',
1177
    '#title' => t('Proxy'),
1178
    '#collapsible' => TRUE,
1179
    '#collapsed' => TRUE,
1180
  );
1181

    
1182
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1183
    '#type' => 'textfield',
1184
    '#title' => t('Proxy URL') . ':',
1185
    '#description' => t('If this proxy url is set the cdm api tries
1186
    to connect the web service over the given proxy server.
1187
    Otherwise proxy usage is deactivated.'),
1188
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1189
  );
1190

    
1191
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1192
    '#type' => 'textfield',
1193
    '#title' => t('Proxy port') . ':',
1194
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1195
  );
1196

    
1197
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1198
    '#type' => 'textfield',
1199
    '#title' => t('Login') . ':',
1200
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1201
  );
1202

    
1203
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1204
    '#type' => 'textfield',
1205
    '#title' => t('Password') . ':',
1206
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1207
  );
1208

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

    
1225
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1226
    '#type' => 'select',
1227
    '#title' => t('Default classification') . ':',
1228
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1229
    '#options' => cdm_get_taxontrees_as_options(),
1230
    '#description' => t('The default taxa classification to be used in the whole portal. 
1231
      This affects most obviously the classification browser and the search in case is is restricted 
1232
      to a specific classification. See also <i>Included Classifications</i> below.'),
1233
  );
1234

    
1235
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1236
    '#type' => 'select',
1237
    '#title' => t('Rank of highest displayed taxon') . ':',
1238
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1239
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1240
    '#options' => cdm_rankVocabulary_as_option(),
1241
    '#description' => t('This is the rank of the highest displayed taxon in the
1242
      <em>taxon tree</em>. You can select here which rank should be at the top
1243
      level of the tree structure.'),
1244
  );
1245

    
1246
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1247
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1248
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1249
      '#type' => 'checkboxes',
1250
      '#title' => t('Included Classifications') . ':',
1251
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1252
      '#options' => cdm_get_taxontrees_as_options(),
1253
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1254
  );
1255

    
1256
  $form['distribution'] = array(
1257
      '#type' => 'fieldset',
1258
      '#title' => t('Distributions'),
1259
      '#collapsible' => FALSE,
1260
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1261
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1262
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1263
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1264
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1265
          '<p>
1266
          </p>',
1267
  );
1268

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

    
1290
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1291
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1292
      '#type' => 'checkboxes',
1293
      '#title' => 'Filter rules',
1294
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1295
      '#options' => array(
1296
          'statusOrderPreference' => 'Status order preference rule',
1297
          'subAreaPreference' => 'Sub area preference rule'
1298
      ),
1299
  );
1300

    
1301
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1302
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1303
      '#type' => 'checkboxes',
1304
      '#title' => 'Hide marked area filter',
1305
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1306
      '#options' => $marker_type_options,
1307
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1308
  );
1309

    
1310
  $form['aggregation'] = array(
1311
      '#type' => 'fieldset',
1312
      '#title' => t('Aggregation of data'),
1313
      '#collapsible' => FALSE,
1314
      '#description' => 'This section covers the different aspects of aggregating information.
1315
          <p>
1316
          </p>',
1317
  );
1318

    
1319
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1320
      '#type' => 'checkboxes',
1321
      '#title' => 'Taxon media filter',
1322
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1323
      '#options' => array(
1324
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1325
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1326
          'includeOccurrences' => 'Media related to specimens and occurrences',
1327
      ),
1328
      '#description' => 'This filter configures which images should be taken into account.',
1329
  );
1330

    
1331
  $form['aggregation']['notice'] = array(
1332
      '#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
1333
          want to make use of the caching capabilities of the dataportal.',
1334
  );
1335

    
1336
  $form['aggregation']['media_aggregation'] = array(
1337
      '#type' => 'fieldset',
1338
      '#title' => t('Media aggregation'),
1339
      '#collapsible' => FALSE,
1340
      '#collapsed' => TRUE,
1341
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1342

    
1343
  );
1344
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1345
      '#type' => 'select',
1346
      '#title' => t('Aggregation of taxon pictures') . ':',
1347
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1348
      '#options' => array(
1349
          0 => "Show only pictures of the current taxon",
1350
          1 => "Include pictures of taxonomic children",
1351
      ),
1352
      '#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."),
1353
  );
1354

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

    
1369
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1370
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1371

    
1372
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1373
      '#type' => 'checkboxes',
1374
      '#title' => t('Direct'),
1375
      '#options' => $taxonRelationshipTypeOptions,
1376
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1377
  );
1378
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1379
      '#type' => 'checkboxes',
1380
      '#title' => t('Invers'),
1381
      '#options' => $taxonRelationshipTypeOptions,
1382
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1383
  );
1384

    
1385
  $form['drupal_integration'] = array(
1386
    '#type' => 'fieldset',
1387
    '#attributes' => array('class'=> array('clearfix')),
1388
    '#title' => t('Drupal integration'),
1389
    '#collapsible' => FALSE,
1390
    '#collapsed' => FALSE,
1391
    '#tree' => FALSE
1392
  );
1393

    
1394
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1395
    '#type' => 'checkbox',
1396
    '#title' => 'Create drupal nodes',
1397
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1398
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1399
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1400
    cdm pages it is required that drupal nodes are created and stored in the database.'
1401
  );
1402

    
1403

    
1404

    
1405
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1406
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1407
    <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>',
1408
  );
1409
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1410
    '#type' => 'submit',
1411
    '#value' => t('Drop all cdm nodes'),
1412
    '#submit' => array('drop_all_cdm_nodes_submit')
1413
  );
1414

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

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

    
1444
  // Comment @WA: D7 form api does not support reset buttons,
1445
  // so to mimic the D5 reset button we add one like this.
1446
  $form['actions']['reset'] = array(
1447
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1448
    '#weight' => 1000,
1449
  );
1450

    
1451
  $form['#submit'][] = 'cdm_settings_general_submit';
1452

    
1453
  return system_settings_form($form);
1454
}
1455

    
1456
/**
1457
 * Submit callback; drops all cdm nodes.
1458
 *
1459
 * @ingroup forms
1460
 */
1461
function drop_all_cdm_nodes_submit($form, &$form_state) {
1462
  cdm_delete_all_cdm_nodes();
1463
  drupal_set_message(t('All cdm nodes dropped.'));
1464
}
1465

    
1466

    
1467
/**
1468
 * LAYOUT settings
1469
 * @return
1470
 *   todo
1471
 */
1472
function cdm_settings_layout() {
1473

    
1474
  $form = array();
1475

    
1476
  $form['about'] = array(
1477
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1478
      layout. If you want to configure the specific sites layout visit the
1479
      respective configuration site for taxon, search or media.') . '</p>',
1480
  );
1481

    
1482
  // ---- footnotes --- //
1483
  $form['footnotes'] = array(
1484
    '#type' => 'fieldset',
1485
    '#title' => t('Footnotes'),
1486
    '#collapsible' => FALSE,
1487
    '#collapsed' => FALSE,
1488
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1489
      media or distribution areas may have annotations or footnotes. When the
1490
      footnotes are enabled they will be visible (if they exist).'),
1491
  );
1492

    
1493
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1494
    '#type' => 'checkbox',
1495
    '#title' => t('Do not show footnotes'),
1496
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1497
    '#description' => t('Check this if you do not want to show any footnotes'),
1498
  );
1499

    
1500
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1501
    '#type' => 'checkbox',
1502
    '#title' => t('Do not show annotation footnotes'),
1503
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1504
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1505
  );
1506

    
1507
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1508
  // Additional option for the NULL case.
1509
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1510
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1511
    '#type' => 'checkboxes',
1512
    '#title' => t('Annotation types as footnotes'),
1513
    '#description' => t("Only annotations of the selected type will be displayed
1514
       as footnotes. You may want to turn 'technical annotations' off."),
1515
    '#options' => $annotationTypeOptions,
1516
  );
1517
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1518
  if (!empty($annotationsTypesAsFootnotes)) {
1519
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1520
  }
1521

    
1522
  // ---- original source --- //
1523
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1524
      '#type' => 'fieldset',
1525
      '#tree' => TRUE,
1526
      '#title' => t('Source Citations'),
1527
      '#collapsible' => FALSE,
1528
      '#collapsed' => FALSE,
1529
  );
1530

    
1531
  $bibliography_settings = get_bibliography_settings(true);
1532

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

    
1544
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1545
    '#type' => 'select',
1546
    '#title' => t('The format of the key numerals'),
1547
    '#default_value' => $bibliography_settings['key_format'],
1548
    '#options' => array('latin' => 'Latin',
1549
      'ROMAN' => 'Roman (upper case)',
1550
      'roman' => 'Roman (lower case)',
1551
      'ALPHA'=> 'Alphabet (upper case)',
1552
      'alpha' => 'Alphabet (lower case)')
1553
  );
1554

    
1555
  // --- Advanced Search --- //
1556
  $form['asearch'] = array(
1557
      '#type' => 'fieldset',
1558
      '#title' => t('Advanced search'),
1559
      '#collapsible' => FALSE,
1560
      '#collapsed' => FALSE,
1561
  );
1562
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1563
      '#type' => 'checkbox',
1564
      '#title' => t('Show advanced search link'),
1565
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1566
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1567
  );
1568

    
1569
  // ---- Taxon Name Rendering --- //
1570
  $form['taxon_name'] = array(
1571
      '#type' => 'fieldset',
1572
      '#title' => t('Taxon name display'),
1573
      '#collapsible' => TRUE,
1574
      '#collapsed' => TRUE,
1575
      '#description' => t('The display of taxon names is configured by two parts.
1576
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1577
          The name parts are defined in the <stong>part definitions</strong>'),
1578
  );
1579

    
1580
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1581
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1582
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1583
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1584

    
1585
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1586
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1587
    $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.)';
1588
  } else if($is_custom_part_definition){
1589
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1590
  } else  {
1591
    $which_version_message = '(These are the default part definition.)';
1592
  }
1593

    
1594
  $diff_viewer_markup = '';
1595
  if($is_custom_part_definition){
1596
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1597
  }
1598

    
1599
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1600
    . $which_version_message
1601
    . '</div>'
1602
    . $diff_viewer_markup;
1603

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

    
1693
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1694
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1695
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1696
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1697
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1698

    
1699
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1700
    $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.)';
1701
  } else if($is_custom_render_template){
1702
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1703
  } else {
1704
    $which_version_message = '(These are the default render templates.)';
1705
  }
1706

    
1707
  $diff_viewer_markup = '';
1708
  if($is_custom_render_template){
1709
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1710
  }
1711

    
1712
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1713
    . $which_version_message
1714
    . '</div>'
1715
    . $diff_viewer_markup;
1716

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

    
1757
  // @WA: D7 form api does not support reset buttons,
1758
  // so to mimic the D5 reset button we add one like this.
1759
  $form['actions']['reset'] = array(
1760
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1761
    '#weight' => 1000,
1762
  );
1763

    
1764
  $form['#submit'] = array('submit_json_as_php_array');
1765
  // #json_elements especially defined for submit_json_as_php_array()
1766
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1767
  return system_settings_form($form);
1768
}
1769

    
1770

    
1771
/**
1772
 * @param $form_name
1773
 * @param $form_title
1774
 * @param $collapsed
1775
 * @param string $form_description
1776
 *   The description for the fieldset of the gallery setting.
1777
 * @return mixed
1778
 */
1779
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1780
  $form[$form_name] = array(
1781
    '#type' => 'fieldset',
1782
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1783
    '#collapsible' => TRUE,
1784
    '#collapsed' => $collapsed,
1785
    '#tree' => TRUE,
1786
    '#description' => $form_description,
1787
  );
1788

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

    
1808
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1809
      '#type' => 'checkbox',
1810
      '#title' => t('Show media thumbnails for synonyms'),
1811
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1812
      '#description' => '',
1813
    );
1814
  }
1815

    
1816
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1817
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1818
    '#type' => 'checkbox',
1819
    '#title' => t('Show captions under thumbnails'),
1820
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1821
    '#description' => '',
1822
  );
1823

    
1824
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1825
    '#type' => 'textfield',
1826
    '#title' => t('Thumbnail size') . ':',
1827
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1828
    '#description' => t('Select the size of each individual thumbnail.'),
1829
  );
1830

    
1831
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1832
    '#type' => 'textfield',
1833
    '#title' => t('Number of columns') . ':',
1834
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1835
    '#description' => t('Group the thumbnails in columns: select how many
1836
      columns the gallery should display.'),
1837
  );
1838

    
1839
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1840
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1841
      '#type' => 'textfield',
1842
      '#title' => t('Maximum number of rows') . ':',
1843
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1844
      '#description' => t('You can group the thumbnails in rows, select in how
1845
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1846
        If you want an unlimited number of rows please set to 0.'),
1847
    );
1848
  }
1849

    
1850
  return $form;
1851
}
1852

    
1853
/**
1854
 * @todo document this function.
1855
 */
1856
function cdm_settings_layout_taxon() {
1857
  $collapsed = FALSE;
1858
  $form = array();
1859

    
1860
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1861

    
1862
  // --------- TABBED TAXON ------- //
1863
  $form['taxon_tabs'] = array(
1864
    '#type' => 'fieldset',
1865
    '#title' => t('Taxon tabs'),
1866
    '#collapsible' => TRUE,
1867
    '#collapsed' => TRUE,
1868
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1869
  );
1870

    
1871
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1872
    '#type' => 'checkbox',
1873
    '#title' => t('Tabbed taxon page'),
1874
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1875
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1876
  );
1877

    
1878
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1879
    '#type' => 'checkbox',
1880
    '#title' => t('Synonymy as tab'),
1881
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1882
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1883
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1884
  );
1885

    
1886
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1887
    '#type' => 'checkboxes',
1888
    '#title' => t('Section/Tab visibility') . ':',
1889
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1890
    '#options' => get_taxon_options_list()
1891
  );
1892

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

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

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

    
1945
  /* ======  TAXON_PROFILE ====== */
1946
  $form['taxon_profile'] = array(
1947
    '#type' => 'fieldset',
1948
    '#title' => t('Taxon profile (tab)'),
1949
    '#description' => t('<p>This section covers the settings related to the taxon
1950
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1951
    '#collapsible' => TRUE,
1952
    '#collapsed' => TRUE,
1953
  );
1954

    
1955
  // ---- PROFILE PICTURE ----//
1956

    
1957
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1958
    '#type' => 'fieldset',
1959
    '#tree' => TRUE,
1960
    '#title' => t('Taxon profile picture'),
1961
    '#collapsible' => TRUE,
1962
    '#collapsed' => FALSE,
1963
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1964
  );
1965

    
1966
  //FIXME migrate variables:
1967
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1968
  // FIXME
1969
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1970

    
1971
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1972

    
1973
  /*
1974
   * 'show' => 1,
1975
   * 'maxextend' => 184,
1976
   * 'media_uri_query' => ''
1977
   * 'custom_placeholder_image_on' => 1,
1978
   * 'custom_placeholder_image_fid' => ''
1979
   */
1980
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1981
    '#type' => 'checkbox',
1982
    '#title' => t('Enable profile picture'),
1983
    '#description' => t('Show the profile picture.'),
1984
    '#default_value' => $taxon_profile_image_settings['show'],
1985
  );
1986

    
1987
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1988
      '#type' => 'textfield',
1989
      '#tree' => TRUE,
1990
      '#title' => t('Profile picture maximum extend'),
1991
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1992
      '#field_suffix' => 'px',
1993
      '#maxlength' => 4,
1994
      '#size' => 4,
1995
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1996
  );
1997

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

    
2011
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2012
    '#type' => 'checkbox',
2013
    '#title' => t('Show the placeholder image'),
2014
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2015
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2016
  );
2017

    
2018
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2019
      '#type' => 'checkbox',
2020
      '#title' => t('Use a custom placeholder image'),
2021
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2022
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2023
  );
2024

    
2025
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2026
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2027
        '#type' => 'managed_file',
2028
        '#title' => t('Custom placeholder image file'),
2029
        '#progress_indicator' => 'bar',
2030
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2031
    //       '#name' => 'custom_placeholder_image',
2032
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2033
    );
2034

    
2035
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2036
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2037
      $url = file_create_url($profile_image_file->uri);
2038
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2039
                '#type' => 'item',
2040
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2041
      );
2042
    }
2043
  } else {
2044
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2045
      '#type' => 'hidden',
2046
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2047
    );
2048
  }
2049

    
2050
  $options = cdm_rankVocabulary_as_option();
2051
  array_unshift($options, '-- DISABLED --');
2052
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2053
    '#type' => 'select',
2054
    '#title' => t('Hide profile picture for higher ranks') . ':',
2055
    '#default_value' => variable_get('image_hide_rank', '0'),
2056
    '#options' => $options,
2057
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2058
  );
2059

    
2060
  // -- MEDIA THUMBNAILS -- //
2061
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2062
  $form_title = 'Taxon Profile Images';
2063
  $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>';
2064
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2065

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

    
2094
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2095
  $profile_feature_tree = get_profile_feature_tree();
2096

    
2097
  if (isset($profile_feature_tree->root->childNodes)) {
2098

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

    
2141

    
2142
    $feature_list_layout_settings_disabled = FALSE;
2143

    
2144
    // creating helper object to retrieve the default settings
2145
    $featureNode = new stdClass();
2146
    $featureNode->feature = new stdClass();
2147
    $featureNode->feature->uuid="DEFAULT";
2148
    $featureNode->feature->representation_L10n = "Default";
2149
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2150

    
2151
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2152

    
2153
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2154

    
2155
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2156
        $subform_id = $featureNode->feature->uuid;
2157
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2158

    
2159
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2160

    
2161
        $form_feature_block_layout[$subform_id] = array(
2162
          '#type' => 'fieldset',
2163
          '#tree' => TRUE,
2164
          '#title' => $featureNode->feature->representation_L10n,
2165
          '#collapsible' => FALSE,
2166
          '#collapsed' => FALSE,
2167
        );
2168
        if($featureNode->feature->uuid == "DEFAULT"){
2169
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2170
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2171
          references</em> and <em>names in source</em> is only possible in the defaults';
2172
        }
2173

    
2174
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2175
          '#type' => 'select',
2176
          '#title' => 'List type',
2177
          '#default_value' => $feature_block_setting['as_list'],
2178
          '#options' => array(
2179
            'div' => 'not as list',
2180
            'ul' => 'bullet list',
2181
            'ol' => 'numbered list',
2182
            'dl' => 'definition list'
2183
          ),
2184
        );
2185

    
2186
        if($featureNode->feature->uuid == "DEFAULT"){
2187
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2188
            '#type' => 'checkbox',
2189
            '#title' => t('Link to reference'),
2190
            '#default_value' => $feature_block_setting['link_to_reference'],
2191
          );
2192

    
2193
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2194
            '#type' => 'checkbox',
2195
            '#title' => 'Link to name used in source',
2196
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2197
          );
2198
        }
2199

    
2200
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2201
          '#type' => 'checkbox',
2202
          '#title' => 'Sources as content',
2203
          '#default_value' => $feature_block_setting['sources_as_content'],
2204
        );
2205

    
2206
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2207
          '#type' => 'checkbox',
2208
          '#title' => 'Put sources also as content to bibliography',
2209
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2210
        );
2211

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

    
2231
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2232
          '#type' => 'select',
2233
          '#title' => t('Element tag'),
2234
          '#options' => array(
2235
            'span' => 'span',
2236
            'div' => 'div',
2237
            'p' => 'p'
2238
          ),
2239
          '#default_value' => $feature_block_setting['element_tag'],
2240
        );
2241
        $form_feature_block_layout[$subform_id]['glue'] = array(
2242
          '#type' => 'textfield',
2243
          '#title' => t('Element glue'),
2244
          '#default_value' => $feature_block_setting['glue'],
2245
          '#size' => 10
2246
      );
2247

    
2248
      }
2249
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2250
    }
2251
  }
2252

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

    
2278

    
2279

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

    
2298
  );
2299

    
2300
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2301

    
2302
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2303
    '#type' => 'checkbox',
2304
    '#title' => t('Condensed distribution'),
2305
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2306
    '#description' => 'This option enables the display of a very compact representation
2307
    of the distribution which includes also information on the status.',
2308
  );
2309

    
2310
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2311
    '#type' => 'select',
2312
    '#title' => t('Condensed distribution recipe'),
2313
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2314
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2315
    '#description' => 'Recipe for creating the condensed distribution.',
2316
  );
2317

    
2318
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2319
    '#type' => 'textfield',
2320
    '#title' => t('Condensed distribution info path'),
2321
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2322
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2323
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2324
  );
2325

    
2326

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

    
2344
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2345
    '#type' => 'fieldset',
2346
    '#tree' => true,
2347
    '#title' => t('Distribution hierarchy style')
2348
  );
2349

    
2350
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2351
  foreach(array_keys($hierarchy_styles) as $level) {
2352
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2353
      '#type' => 'fieldset',
2354
      '#tree' => true,
2355
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2356
      '#attributes' => array('class' => array('fieldset-float'))
2357
    );
2358
    foreach ($hierarchy_styles[$level] as $key => $value) {
2359
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2360
        '#type' => 'textfield',
2361
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2362
        '#default_value' => $hierarchy_styles[$level][$key],
2363
        '#maxlength' => 4,
2364
        '#size' => 4
2365
      );
2366
    }
2367
  }
2368

    
2369
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2370
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2371
    '#type' => 'checkboxes',
2372
    '#title' => 'Omit area levels',
2373
    '#options' => $level_options,
2374
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2375
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2376
    Areas which belong to the selected area levels will be hidden in the portal.',
2377
  );
2378

    
2379
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2380
    '#type' => 'checkbox',
2381
    '#title' => t('Show TextData elements on top of the map'),
2382
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2383
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2384
      elements on top of the map. Otherwise all <code>TextData</code>
2385
      distribution elements will be listed below the other area elements.
2386
      This option is useful if you need to have descriptive texts for each
2387
      distribution map.'),
2388
  );
2389

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

2417
AbsenceTerm
2418
a        absent
2419
f        reported in error
2420
nf        native: reported in error
2421
if        introduced: reported in error
2422
cf        cultivated: reported in error
2423
ne        native: formerly native
2424
ie        introduced: formerly introduced
2425

2426
</pre>'),
2427
  );
2428

    
2429

    
2430
  /* ====== SYNONYMY ====== */
2431
  $form['taxon_synonymy'] = array(
2432
    '#type' => 'fieldset',
2433
    '#title' => t('Taxon synonymy (tab)'),
2434
    '#collapsible' => TRUE,
2435
    '#collapsed' => TRUE,
2436
    '#description' => t('This section covers the settings related to the taxon
2437
      <strong>synonymy</strong> tab.'),
2438
  );
2439

    
2440
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2441
    '#type' => 'checkbox',
2442
    '#title' => t('Show accepted taxon on top of the synonymy'),
2443
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2444
    '#description' => t('If checked, the first homotypic taxon is a repetition
2445
      of the accepted taxon most likely with the full nomenclatural reference
2446
      (depending on the currently chosen theme).'),
2447
  );
2448

    
2449
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2450
    '#type' => 'checkbox',
2451
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2452
      coming from a synonym link.'),
2453
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2454
    '#description' => t('Check this if after doing a search and clicking on a
2455
      synonym you want to see the "accept of" text for the accepted synonym.'),
2456
  );
2457

    
2458
  /* === currently unused ===
2459
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2460
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2461
    '#type' => 'checkboxes',
2462
    '#title' => t('Display name relationships') . ':',
2463
    '#default_value' => variable_get('name_relationships_to_show', 0),
2464
    '#options' => $nameRelationshipTypeOptions,
2465
    '#description' => t('Select the name relationships you want to show for the
2466
      accepted taxa.'),
2467
  );
2468
 */
2469

    
2470
  $form['taxon_synonymy']['taxon_relations'] = array(
2471
    '#type' => 'fieldset',
2472
    '#title' => t('Taxon relationships'),
2473
    '#collapsible' => FALSE,
2474
    '#collapsed' => FALSE
2475
  );
2476

    
2477
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2478
    '#type' => 'checkbox',
2479
    '#title' => t('Show taxon relations ships of accepted taxon'),
2480
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2481
    '#description' => t('If this option is enabled the synonymy will show the
2482
      below selected taxon relationships of accepted taxa.'),
2483
  );
2484

    
2485
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2486
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2487
    '#type' => 'checkboxes',
2488
    '#title' => t('Taxon relationship types') . ':',
2489
    '#description' => t('Only taxon relationships of the selected type will be
2490
      displayed'),
2491
    '#options' => $taxonRelationshipTypeOptions,
2492
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2493
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2494
  );
2495

    
2496
  $form['taxon_synonymy']['name_relations'] = array(
2497
    '#type' => 'fieldset',
2498
    '#title' => t('Name relationships'),
2499
    '#collapsible' => FALSE,
2500
    '#collapsed' => FALSE
2501
  );
2502

    
2503
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2504
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2505
    '#type' => 'checkboxes',
2506
    '#title' => t('Name relationship types') . ':',
2507
    '#description' => t('Only name relationships of the selected type will be
2508
      displayed'),
2509
    '#options' => $taxonRelationshipTypeOptions,
2510
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2511
  );
2512

    
2513
  // ====== SPECIMENS ====== //
2514
  $form['taxon_specimens'] = array(
2515
    '#type' => 'fieldset',
2516
    '#title' => t('Taxon specimens (tab)'),
2517
    '#collapsible' => TRUE,
2518
    '#collapsed' => TRUE,
2519
    '#description' => t('This section covers the settings related to the taxon
2520
      <strong>specimens</strong> tab.'),
2521
  );
2522

    
2523
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2524

    
2525
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2526
    '#type' => 'checkbox',
2527
    '#title' => t('Show specimen derivatives in a compressed table'),
2528
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2529
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2530
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2531
  );
2532

    
2533
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2534
        '#type' => 'textfield',
2535
        '#title' => t('Number of records per page') . ':',
2536
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2537
    );
2538

    
2539
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2540
    '#type' => 'checkbox',
2541
    '#title' => t('Show "Associated with" in specimen table.'),
2542
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2543
  );
2544

    
2545
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2546
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2547
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2548
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2549
  }
2550
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2551
    '#type' => 'radios',
2552
    '#title' => t('Specimen description feature tree') . ':',
2553
    '#default_value' => $profile_feature_tree_uuid,
2554
    '#options' =>  $featureTrees['options'],
2555
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2556
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2557
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2558
    ),
2559
  );
2560

    
2561
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2562
  $form_title = t('Specimen media');
2563
  $form_description = t('Specimens may have media which is displayed at the
2564
     Specimen tab/section as a gallery. It is possible to configure the
2565
     thumbnails gallery here, however for configuring how a single media should
2566
     be displayed please go to !url.</p>',
2567
     array(
2568
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2569
     ));
2570
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2571

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

    
2583
  // Comment @WA: D7 form api does not support reset buttons,
2584
  // so to mimic the D5 reset button we add one like this.
2585
  $form['actions']['reset'] = array(
2586
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2587
    '#weight' => 1000,
2588
  );
2589
  return system_settings_form($form);
2590
}
2591

    
2592
/**
2593
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2594
 *
2595
 * @param $map_id
2596
 * @param $form
2597
 * @return mixed
2598
 */
2599
function _cdm_map_visibility_setting($map_id)
2600
{
2601
  return array(
2602
    '#type' => 'select',
2603
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2604
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2605
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2606
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2607
        The map also can forced to show up <b>always</b> or <b>never</b>."
2608
  );
2609
}
2610

    
2611
/**
2612
 * @todo document this function.
2613
 */
2614
function cdm_settings_layout_search() {
2615

    
2616
  $form = array();
2617

    
2618
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2619

    
2620
  $form['search_settings'] = array(
2621
    '#type' => 'fieldset',
2622
    '#title' => t('Taxa Search'),
2623
    '#collapsible' => FALSE,
2624
    '#collapsed' => FALSE,
2625
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2626
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2627
         where they can write the text to be searched. You can find Drupal block configuration
2628
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2629
  );
2630

    
2631
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2632
      '#type' => 'checkbox',
2633
      '#title' => t('Ignore the chosen classification in simple search'),
2634
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2635
      '#description' => t('The simple search, which can be executed via the search block,
2636
          will by default search on the classification selected in the classification browser
2637
          selector. Set the tick if you want your portal to search on all classifications.'),
2638
  );
2639

    
2640
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2641
    '#type' => 'checkbox',
2642
    '#title' => t('Run simple search with free-text search backend.'),
2643
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2644
    '#description' => t('The simple search uses by default another search
2645
      backend as the advances search. By checking this option the simple search can be
2646
      configured to also use the free-text search backend.'),
2647
  );
2648

    
2649
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2650
    '#type' => 'checkbox',
2651
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2652
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2653
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2654
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2655
  );
2656

    
2657
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2658
    '#type' => 'textfield',
2659
    '#title' => t('Results per page') . ':',
2660
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2661
    '#description' => t('Number of results to display per page.'),
2662
  );
2663
    
2664
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2665
    '#type' => 'checkbox',
2666
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2667
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2668
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2669
  );
2670

    
2671
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2672
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2673
      '#type' => 'checkboxes',
2674
      '#title' => 'Search mode',
2675
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2676
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2677
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2678
          defaults set here.',
2679
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2680
      '#default_value' => $search_mode_default
2681
      );
2682

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

    
2688
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2689
  );
2690

    
2691
  // --- SEARCH TAXA GALLERY ---- //
2692
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2693
  $collapsed = FALSE;
2694
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2695
  $form_title = 'Taxa Search thumbnails';
2696
  $form_description = 'Search results may show thumbnails. ';
2697
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2698

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

    
2708
/**
2709
 * @todo document this function.
2710
 */
2711
function cdm_settings_layout_media() {
2712

    
2713
  $form = array();
2714

    
2715
  $form['media_settings'] = array(
2716
    '#type' => 'fieldset',
2717
    '#title' => t('Media settings'),
2718
    '#collapsible' => FALSE,
2719
    '#collapsed' => FALSE,
2720
    '#description' => 'This section covers layout settings for media pages.'
2721
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2722
  );
2723

    
2724
  $form['media_settings']['image_gallery_viewer'] = array(
2725
    '#type' => 'select',
2726
    '#title' => t('Image viewer') . ':',
2727
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2728
    '#options' => array(
2729
      'default' => t('Standard image viewer'),
2730
      'fsi' => t('FSI viewer (requires FSI server!)'),
2731
    ),
2732
  );
2733

    
2734
  // --- STANDARD_IMAGE_VIEWER ---- //
2735
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2736
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2737
      '#type' => 'fieldset',
2738
      '#tree' => true,
2739
      '#title' => t('Standard image viewer settings'),
2740
      '#collapsible' => FALSE,
2741
      '#collapsed' => FALSE,
2742
      );
2743

    
2744
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2745
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2746
      '#type' => 'checkbox',
2747
      '#title' => 'Show media representations',
2748
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2749

    
2750
    );
2751
  }
2752

    
2753

    
2754
  // @WA: D7 form api does not support reset buttons,
2755
  // so to mimic the D5 reset button we add one like this.
2756
  $form['actions']['reset'] = array(
2757
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2758
    '#weight' => 1000,
2759
  );
2760
  return system_settings_form($form);
2761
}
2762

    
2763
/**
2764
 * GEOSERVICE and Map settings.
2765
 */
2766
function cdm_settings_geo($form, &$form_state) {
2767

    
2768
  $current_geoserver_settings = get_edit_map_service_settings();
2769
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2770

    
2771

    
2772
  $form = array();
2773

    
2774
  $dummy_distribution_query = NULL;
2775
  if($map_distribution['map_type'] != 1){
2776
    // we need to apply a dummy query since the map service requires for image maps
2777
    // at least as and ad to be defined
2778
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2779
  }
2780

    
2781
  $form['map_preview'] = array(
2782
      '#type' => 'fieldset',
2783
      '#tree' => FALSE,
2784
      '#title' => t('Map preview'),
2785
      '#collapsible' => FALSE,
2786
      '#description' => 'The preview of the map'
2787
       . ($dummy_distribution_query != null ?
2788
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2789
           '.<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.')
2790
  );
2791
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2792
    'move' => "this.cdmOpenlayersMap.printInfo",
2793
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2794
  ), true // resizable
2795
  );
2796

    
2797
  /*
2798
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2799
  );
2800
  */
2801

    
2802
  /*
2803
   * GEO SERVER
2804
   */
2805
  $form['edit_map_server'] = array(
2806
    '#type' => 'fieldset',
2807
    '#tree' => true,
2808
    '#title' => t('EDIT map service'),
2809
    '#collapsible' => TRUE,
2810
    '#collapsed' => TRUE,
2811
    '#description' => t('Configuration and selection of your geo server.
2812
      The Geo Server is responsible for generating the maps.'),
2813
  );
2814

    
2815
  $form['edit_map_server']['base_uri'] = array(
2816
    '#type' => 'select',
2817
    '#title' => t('EDIT map service') . ':',
2818
    '#default_value' => $current_geoserver_settings['base_uri'],
2819
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2820
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2821
  );
2822
  $form['edit_map_server']['version'] = array(
2823
      '#type' => 'select',
2824
      '#title' => t('Version') . ':',
2825
      '#default_value' => $current_geoserver_settings['version'],
2826
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2827
      '#description' => t('The version of the EDIT map services'),
2828
  );
2829

    
2830
  /*
2831
   * MAP SETTINGS
2832
   */
2833

    
2834
  $form[CDM_MAP_DISTRIBUTION] = array(
2835
    '#type' => 'fieldset',
2836
    '#tree' => TRUE,
2837
    '#title' => t('Maps settings'),
2838
    '#collapsible' => TRUE,
2839
    '#collapsed' => TRUE,
2840
    '#description' => t('General configuration for all map types.'),
2841
  );
2842

    
2843
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2844
    '#type' => 'radios',
2845
    '#title' => 'Map types',
2846
    '#options' => array(
2847
      1 => "OpenLayers dynamic map viewer",
2848
      0 => "Plain image",
2849
    ),
2850
    '#default_value' => $map_distribution['map_type'],
2851
    '#description' => 'Two different map types are available :
2852
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2853
      which allows zooming and panning. If enabled you can configure the default layer
2854
      (background of your maps) below.</li>
2855
      <li><em>Plain image</em>: The map will be static non interactive
2856
      image.</li></ul>',
2857
  );
2858
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2859

    
2860
  /*
2861
   * settings for the distribution map are used also for specimens map!!!!
2862
   */
2863

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

    
2879
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2880
    '#type' => 'textfield',
2881
    '#title' => 'Bounding box',
2882
    '#default_value' => $map_distribution['bbox'],
2883
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2884
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2885
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2886
      <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.
2887
      (Maybe you need to change the map base layer to OpeLayers.)
2888
      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
2889
      below the map from where you can copy the bbox string.</p>'),
2890
  );
2891

    
2892
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2893
    '#type' => 'select',
2894
    '#title' => 'Max zoom level',
2895
    '#default_value' => $map_distribution['maxZoom'],
2896
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2897
  );
2898

    
2899
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2900
    '#type' => 'checkbox',
2901
    '#title' => 'Display area labels',
2902
    '#default_value' => $map_distribution['show_labels'],
2903
    '#description' => t('The map will show name labels of the areas'),
2904
  );
2905

    
2906
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2907
    '#type' => 'textfield',
2908
    '#title' => 'Map caption',
2909
    '#default_value' => $map_distribution['caption'],
2910
    '#description' => t('The caption will be shown below the map.'),
2911
  );
2912

    
2913
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2914
    '#type' => 'textfield',
2915
    '#title' => 'Distribution layer opacity',
2916
    '#default_value' => $map_distribution['distribution_opacity'],
2917
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2918
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2919
  );
2920

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

    
2939
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2940
    '#type' => 'textfield',
2941
    '#title' => 'Width',
2942
    '#default_value' => $map_distribution['image_map']['width'],
2943
    '#maxlength' => 4,
2944
    '#size' => 4,
2945
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2946
  );
2947

    
2948
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2949
    '#type' => 'textfield',
2950
    '#title' => 'Background layer',
2951
    '#default_value' => $map_distribution['image_map']['base_layer'],
2952
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2953
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2954
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2955
    )),
2956
  );
2957

    
2958
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2959
    '#type' => 'textfield',
2960
    '#title' => 'Background color',
2961
    '#default_value' => $map_distribution['image_map']['bg_color'],
2962
  );
2963

    
2964
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2965
    '#type' => 'textfield',
2966
    '#title' => 'Background layer style',
2967
     // Only line color by now.
2968
    '#default_value' => $map_distribution['image_map']['layer_style'],
2969
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2970
  );
2971

    
2972
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2973
      '#type' => 'textfield',
2974
      '#title' => 'Projection',
2975
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2976
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2977
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2978
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2979
  );
2980

    
2981

    
2982
  // --- OpenLayers Settings --- //
2983
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2984
    '#type' => 'fieldset',
2985
    '#title' => 'OpenLayers settings',
2986
    '#tree' => TRUE,
2987
    '#collapsible' => TRUE,
2988
    '#collapsed' => !$open_layers_is_enabled,
2989
    '#description' => '',
2990
  );
2991

    
2992

    
2993
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2994
      '#type' => 'checkbox',
2995
      '#title' => 'Display outside max extent',
2996
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2997
      '#description' => t('Allows the map to display parts of the layers which are outside
2998
         the max extent if the aspect ratio of the map and of the baselayer
2999
         are not equal.'),
3000
  );
3001

    
3002

    
3003
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3004
      '#type' => 'checkbox',
3005
      '#title' => 'Show Layer Switcher',
3006
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3007
      '#description' => 'The Layer Switcher control displays a table of contents
3008
      for the map.  This allows the user interface to switch between
3009
      base layers and to show or hide overlays.  By default the switcher is
3010
      shown minimized on the right edge of the map, the user may expand it
3011
      by clicking on the handle.',
3012
  );
3013

    
3014
  if (!$open_layers_is_enabled) {
3015
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3016
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3017
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3018
  }
3019

    
3020
  // The default layer must always be enabled
3021
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3022
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3023

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

    
3054
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3055
    '#type' => 'checkboxes_preferred',
3056
    '#title' => 'Base Layers',
3057
    '#options' => $baselayer_options,
3058
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3059
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3060
  );
3061

    
3062
  $google_maps_api_key = null;
3063
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3064
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3065
  }
3066
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3067
    '#type' => 'textfield',
3068
    '#title' => 'Google Maps API Key',
3069
    '#default_value' => $google_maps_api_key,
3070
    '#description' => 'In order to use any of the Google map layers you need to provide 
3071
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3072
  );
3073

    
3074
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3075
    $map_distribution['openlayers']['custom_wms_base_layer'],
3076
    'Custom WMS base layer',
3077
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3078
    true // add projection settings
3079
    );
3080

    
3081
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3082
    $map_distribution['openlayers']['wms_overlay_layer'],
3083
    'WMS overlay layer',
3084
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3085
                You can actually combine multiple layers for this overlay. 
3086
                For details please refer to the wms query parameter <code>Layers</code> .'
3087
  );
3088

    
3089
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3090
    '#type' => 'checkbox',
3091
    '#title' => 'Enable overlay layer',
3092
    '#weight' => -100,
3093
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3094
  );
3095

    
3096
  /*
3097
   * Map Legend
3098
   */
3099
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3100
    '#type' => 'fieldset',
3101
    '#title' => 'Map legend',
3102
    '#tree' => TRUE,
3103
    '#collapsible' => TRUE,
3104
    '#collapsed' => TRUE,
3105
    '#description' => 'Configure the maps legend.',
3106
  );
3107

    
3108
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3109
    '#type' => 'checkbox',
3110
    '#title' => 'Display a map legend',
3111
    '#default_value' => $map_distribution['legend']['show'],
3112
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3113
  );
3114

    
3115
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3116
    '#type' => 'textfield',
3117
    '#title' => 'Legend opacity',
3118
    '#default_value' => $map_distribution['legend']['opacity'],
3119
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3120
                         to 0.0 will be not much visible.',
3121
  );
3122

    
3123
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3124
    '#type' => 'textfield',
3125
    '#title' => 'Font size',
3126
    '#default_value' => $map_distribution['legend']['font_size'],
3127
    '#description' => 'Font size in pixels.',
3128
  );
3129

    
3130
  $fontStyles = array(
3131
    0 => "plane",
3132
    1 => "italic",
3133
  );
3134
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3135
    '#type' => 'select',
3136
    '#title' => 'Available font styles',
3137
    '#default_value' => $map_distribution['legend']['font_style'],
3138
    '#options' => $fontStyles,
3139
    '#description' => 'Select a font style for the map legend.',
3140
  );
3141

    
3142
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3143
    '#type' => 'textfield',
3144
    '#title' => 'Icon width',
3145
    '#default_value' => $map_distribution['legend']['icon_width'],
3146
    '#description' => 'Legend icon width in pixels.',
3147
  );
3148
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3149
    '#type' => 'textfield',
3150
    '#title' => 'Icon height',
3151
    '#default_value' => $map_distribution['legend']['icon_height'],
3152
    '#description' => 'Legend icon height in pixels.',
3153
  );
3154

    
3155
  // @WA: D7 form api does not support reset buttons,
3156
  // so to mimic the D5 reset button we add one like this.
3157
  $form['actions']['reset'] = array(
3158
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3159
    '#weight' => 1000,
3160
  );
3161

    
3162
  return system_settings_form($form);
3163
}
3164

    
3165
/**
3166
 * @param $default_settings
3167
 * @param $title
3168
 * @param $description
3169
 * @param bool $add_projection_settings
3170
 * @return array
3171
 */
3172
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3173
{
3174
  $form_elements = array(
3175
    '#type' => 'fieldset',
3176
    '#title' => $title,
3177
    '#tree' => TRUE,
3178
    '#collapsible' => FALSE,
3179
    '#collapsed' => FALSE,
3180
    '#description' => $description,
3181
  );
3182

    
3183
  $form_elements['name'] = array(
3184
    '#type' => 'textfield',
3185
    '#title' => 'Layer name',
3186
    '#default_value' => $default_settings['name'],
3187
    '#description' => 'A arbitrary name for the layer.',
3188
  );
3189
  $form_elements['url'] = array(
3190
    '#type' => 'textfield',
3191
    '#title' => 'WMS url',
3192
    '#default_value' => $default_settings['url'],
3193
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3194
  );
3195
  $form_elements['untiled'] = array(
3196
    '#type' => 'checkbox',
3197
    '#title' => 'Untiled',
3198
    '#default_value' => $default_settings['untiled'],
3199
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3200
  );
3201
  $form_elements['params'] = array(
3202
    '#type' => 'textarea',
3203
    '#title' => 'WMS parameters',
3204
    '#element_validate' => array('form_element_validate_json'),
3205
    '#default_value' => $default_settings['params'],
3206
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3207
      .l('Geoserver WMS parameter reference</