Project

General

Profile

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

    
7

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

    
13
const CDM_NAME_PAGE_AUTOREDIRECT = 'cdm_name_page_autoredirect';
14

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

    
18
const CDM_MEDIA_GALLERY_VIEWER = 'image_gallery_viewer';
19
const CDM_MEDIA_GALLERY_VIEWER_DEFAULT = 'universalviewer';
20
const CDM_MEDIA_GALLERY_VIEWER_SIMPLE = 'default';
21

    
22
const CDM_ADDITIONAL_MEDIA_COPYRIGHT = 'cdm_additional_media_copyright';
23

    
24
const CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES = 'cdm_taxonpage_taxon_node_show_status';
25
define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
26
define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
27
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
28
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
29

    
30
  define('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
31

    
32
  define('NO_SORT', -1);
33
  define('SORT_HIERARCHICAL', 9);
34

    
35
  const CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT = 25;
36
  const CDM_SEARCH_RESULT_PAGE_SIZE = 'cdm_dataportal_search_items_on_page';
37

    
38
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
39
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
40
 const CDM_DATAPORTAL_NOMREF_IN_TITLE = 'cdm_dataportal_nomref_in_title';
41
 const CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT =  1;
42
 const CDM_SPECIMEN_LIST_VIEW_MODE = 'cdm_specimen_list_view_mode';
43
 const CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT = 'derivate_table';
44
 const CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE = 'derivate_table';
45
 const CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE = 'derivate_tree';
46
 const CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_PATH = 'derivate_path';
47
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
48
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
49
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
50
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
51
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
52
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
53
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
54

    
55
  define('CDM_SEARCH_BLAST_SERVICE_URI', 'http://bgbm-import:9001/api/sequence');
56
  define('CDM_SEARCH_BLAST_ENABLED', 0);
57
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
58

    
59
  /* annotationTypeKeys */
60
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
61
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
62
    $annotationTypeKeys = array_flip($annotationTypeKeys);
63

    
64
    // Technical annotation are off by default.
65
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
66
    $annotationTypeKeys = array_flip($annotationTypeKeys);
67
    // Additional value for the NULL case.
68
    $annotationTypeKeys[] = 'NULL_VALUE';
69
  }
70

    
71
  const ANNOTATION_TYPES_VISIBLE = 'annotations_types_as_footnotes';
72
  define('ANNOTATION_TYPES_VISIBLE_DEFAULT', serialize($annotationTypeKeys));
73

    
74
/* extensionTypeKeys */
75
$extensionTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_EXTENSION_TYPE));
76
if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $extensionTypeKeys)) {
77
  // Additional value for the NULL case.
78
  $extensionTypeKeys[] = 'NULL_VALUE';
79
}
80
const EXTENSION_TYPES_VISIBLE = 'extension_types_visible';
81
define('EXTENSION_TYPES_VISIBLE_DEFAULT', serialize([]));
82

    
83
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
84
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
85
    'enabled' => 0,
86
    'key_format' => 'ALPHA'
87
  )));
88

    
89
  /* taxonRelationshipTypes */
90
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
91
    array(
92
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
93
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
94
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
95
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
96
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR
97
    )
98
  ));
99

    
100

    
101
  /* ---- MAP SETTING CONSTANTS ---- */
102
  /**
103
   * @var array of URIs eg. http://edit.africamuseum.be"
104
   *   An options array
105
   */
106
  define('EDIT_MAPSERVER_URI', serialize(
107
      array(
108
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)',
109
        'http://geocatalogue.africamuseum.be'=>'Temporary for migration (http://geocatalogue.africamuseum.be)'
110
      )
111
    )
112
  );
113
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
114
  /**
115
   * @var array of versions eg. "v1.2"
116
   *   An options array
117
   */
118
  define('EDIT_MAPSERVER_VERSION', serialize(
119
      array(
120
//        'v1' => 'v1' ,           // no longer recommended
121
//        'v1.1' => 'v1.1',        // no longer recommended
122
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
123
        'v1.2' => 'v1.2',
124
        'v1.3_dev' => 'v1.3_dev (not recommended)',
125
        'v1.4_dev' => 'v1.4_dev (latest features)'
126
      )
127
    )
128
  );
129
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
130
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
131

    
132
    // --- Taxon profile settings --- /
133
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
134
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
135
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
136
      array(
137
          'show' => 0,
138
          'maxextend' => 184,
139
          'media_uri_query' => '',
140
          'custom_placeholder_enabled' => 1,
141
          'custom_placeholder_image_on' => 0,
142
          'custom_placeholder_image_fid' => ''
143
      )
144
    )
145
  );
146

    
147

    
148
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
149

    
150
define('CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS', 'cdm_pseudo_feature_block_weights');
151
define('CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT', serialize(
152
  [
153
    PSEUDO_FEATURE_NUMBER_OF_TAXA => 0 - FEATURE_BLOCK_WEIGHT_INCREMENT,
154
    PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS => 100,
155
    PSEUDO_FEATURE_BIBLIOGRAPHY => 102
156
  ]
157
));
158

    
159
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
160
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
161
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
162
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
163
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
164

    
165
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
166
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
167
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
168
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
169

    
170
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
171
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
172

    
173
/**
174
 * Returns the array of implemented taxon page tabs.
175
 * The array has fixed integer keys which must not be changed.
176
 */
177
function get_taxon_tabs_list() {
178
  $opts = array(
179
    0 => 'General',
180
    1 => 'Synonymy',
181
    2 => 'Images',
182
    3 => 'Specimens',
183
    4 => 'Keys',
184
    5 => 'Experts',
185
  );
186
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
187
    // skip the Synonymy if it is shown in  the general tab
188
    unset($opts[1]);
189
  }
190
  return $opts;
191
}
192

    
193
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
194
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
195
  array(
196
    'general' => '-3',
197
    'synonymy' => '-2',
198
    'images' => '0',
199
    'specimens' => '1',
200
    'keys' => '3',
201
    'experts' => '5',
202
    )
203
));
204

    
205

    
206
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
207
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
208
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
209
  array(
210
    'general' => null,
211
    'synonymy' => null,
212
    'images' => null,
213
    'specimens' => null,
214
    'keys' => null,
215
    'experts' => null,
216
  )
217
));
218

    
219
$taxon_tab_options = get_taxon_tabs_list();
220
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
221

    
222
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
223

    
224
/**
225
 * @todo document this function.
226
 */
227
function get_taxon_options_list() {
228
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
229
  foreach ($taxon_tab_options as $key => $value) {
230
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
231
  }
232
  return $taxon_tab_options;
233

    
234
}
235

    
236
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
237
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
238
    // to unset a default enntry set the value to 0
239
    array(
240
      'doTaxa'=>'doTaxa',
241
      'doSynonyms' => 'doSynonyms',
242
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
243
      'doMisappliedNames' => 'doMisappliedNames'
244
    )
245
  )
246
);
247

    
248
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
249

    
250
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
251
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
252
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
253

    
254
/* Gallery variables. */
255
$gallery_settings = array(
256
    "cdm_dataportal_show_taxon_thumbnails" => 1,
257
    "cdm_dataportal_show_synonym_thumbnails" => 0,
258
    "cdm_dataportal_show_thumbnail_captions" => 1,
259
    "cdm_dataportal_media_maxextend" => 120,
260
    "cdm_dataportal_media_cols" => 3,
261
    "cdm_dataportal_media_maxRows" => 1,
262
);
263

    
264
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
265
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
266
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
267
define('CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME', 'type_specimen_gallery');
268
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
269
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
270
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
271
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
272
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
273
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
274
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
275
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
276

    
277
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
278
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
279
  'media_representation_details_enabled' => 0
280
)));
281

    
282
/**
283
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
284
 * the synonymy.
285
 *
286
 * @var string
287
 */
288
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
289

    
290
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES', 'cdm_name_relationship_types');
291
define('CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT', serialize(
292
    array(
293
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
294
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
295
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
296
    )
297
  )
298
);
299

    
300
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
301

    
302
/**
303
 * The drupal variable for the configuration of the information aggregation along
304
 * the taxon relation ships. The mapped array is associative and holds two elements:
305
 *    - direct: the uuids of the taxon relationship types to take into account in invers
306
 *      direction.
307
 *    - invers: the uuids of the taxon relationship types to take into account in direct
308
 *      direction.
309
 *
310
 * @var String
311
 */
312
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
313
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
314
    array(
315
        'direct'=>array(),
316
        'invers'=>array()
317
     )
318
   ));
319
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
320
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
321
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
322

    
323
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
324
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
325
      array(
326
      'filter_rules' => array(
327
        'statusOrderPreference' => 0,
328
        'subAreaPreference' => 0,
329
      ),
330
      'hiddenAreaMarkerType' => array()
331
     )
332
));
333

    
334
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
335
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
336
  "level_0" => array(
337
    'label_suffix' => ':',
338
    'status_glue' => '',
339
    'item_glue' => ' ',
340
    'item_group_prefix' => '',
341
    'item_group_postfix' => ''
342
  ),
343
  "level_1" => array(
344
    'label_suffix' => '',
345
    'status_glue' => '‒ ', // '&#8210; '
346
    'item_glue' => '; ',
347
    'item_group_prefix' => ', ',
348
    'item_group_postfix' => ''
349
  ),
350
  "level_2" => array(
351
    'label_suffix' => '',
352
    'status_glue' => '‒ ', // '&#8210; '
353
    'item_glue' => ', ',
354
    'item_group_prefix' => ' (',
355
    'item_group_postfix' => ')'
356
  )
357
)));
358

    
359
/**
360
 * Constant for the drupal variable key distribution_map_visibility
361
 *
362
 * possible values:
363
 *  - never
364
 *  - automatic
365
 *  - always
366
 */
367
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
368
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
369

    
370
/**
371
 * Constant for the drupal variable key specimen_map_visibility
372
 *
373
 * possible values:
374
 *  - never
375
 *  - automatic
376
 *  - always
377
 */
378
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
379
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
380

    
381
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
382
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
383
    array(
384
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
385
        'includeOccurrences' => 0,
386
        'includeTaxonNameDescriptions' => 0
387
     )
388
  ));
389

    
390
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
391
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
392
  // needs to be merged with user setting by drupal_array_merge_deep()
393
  // 'width' => 512, // optimum size for OSM layers is 512
394
  // 'height' => 512 / 2, // optimum size for OSM layers 256
395
  'aspect_ratio' => 2,
396
  'bbox' => '', // empty to allow automatic zooming to extend
397
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
398
  'show_labels' => FALSE,
399
  'caption' => '',
400
  'distribution_opacity' => '0.5',
401
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
402
  'image_map' => array(
403
    'base_layer' => '', // none, formerly this was cyprusdivs
404
    'bg_color' => '1874CD',
405
    'layer_style' => 'ffffff,606060,,',
406
  ),
407
  'openlayers' => array(
408
    'base_layers' =>  array(
409
      // A layer MUST NOT BE SET in the defaults,
410
      // otherwise it can not be overidden by the user settings:
411
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
412
      // it is sufficient to define the preferred layer,
413
      // since it will automatically be enabled:
414
      'PREFERRED' => 'mapproxy_vmap0'),
415
    'custom_wms_base_layer' => array(
416
      'name' => NULL,
417
      'url' => NULL,
418
      'params' =>  NULL,
419
      'projection' => NULL,
420
      'proj4js_def' => NULL,
421
      'max_extent' => NULL,
422
      'units' => NULL,
423
      'untiled' => FALSE
424
    ),
425
    'wms_overlay_layer' => array(
426
      'name' => NULL,
427
      'url' => NULL,
428
      'params' =>  NULL,
429
      'untiled' => FALSE
430
    ),
431
    'show_layer_switcher' => TRUE,
432
    'display_outside_max_extent' => FALSE,
433
    'google_maps_api_key' => NULL,
434
  ),
435
  'legend' => array(
436
    'show' => TRUE,
437
    'opacity' => '0.5',
438
    'font_size' => 10,
439
    'font_style' => FALSE,
440
    'icon_width' => 35,
441
    'icon_height' => 15
442
  )
443
)));
444

    
445
/**
446
 * Merges the named array variable with the array of defaults.
447
 *
448
 * IMPORTANT: The array keys must be strings. When the keys are integers
449
 * the merging will not take place for these entities. Number keyed entities
450
 * are just appended to the result array.
451
 *
452
 * @param string $variable_name
453
 *     The variable name
454
 * @param string | array $default
455
 *     The array containing the default values either as array or serialized as string.
456
 *     Unserialization is cared for if necessary
457
 * @return array
458
 *     The merged array as returned by drupal_array_merge_deep()
459
 *
460
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
461
 * TODO force $default being an array
462
 */
463
function get_array_variable_merged($variable_name, $default){
464

    
465
    // unserialize if nessecary
466
    if(!is_array($default)){
467
      $default = unserialize($default);
468
    }
469
    $variable = variable_get($variable_name, array());
470
    $result = drupal_array_merge_deep($default, $variable);
471
    return $result;
472
}
473

    
474
/**
475
 * @todo document this function.
476
 */
477
function getGallerySettings($gallery_config_form_name) {
478
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
479
}
480

    
481
/**
482
 * Returns the string representation of the default tab.
483
 *
484
 * @param bool $returnTabIndex
485
 *   Defaults to FALSE, if set true this function will return the index number
486
 *   of the default tab. (used to supply default values to form elements).
487
 */
488
function get_default_taxon_tab($returnTabIndex = FALSE) {
489

    
490
  global $user;
491
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
492
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
493
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
494
  // Get the user value if the used has chosen to overwrite the system settings.
495
  $user_tab_on = variable_get($user_tab_active, FALSE);
496
  if ($user_tab_on) {
497
    $user_value = variable_get($user_tab, 0);
498
    $index_value = $user_value;
499
    // Get the system value.
500
  }
501
  else {
502
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
503
    $index_value = $system_value;
504
  }
505

    
506
  // Return the index value or the string representation.
507
  if ($returnTabIndex) {
508
    return $index_value;
509
  }
510
  else {
511
    return ($values[$index_value]);
512
  }
513
}
514

    
515
/**
516
 * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
517
 *
518
 * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
519
 * one or more fields these fields are taken from the default. That is the specific settings are always merges
520
 * with the default.
521
 *
522
 * Note: These settings only apply to feature blocks which do not have a special rendering
523
 * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
524
 * 'special' element of the settings
525
 *
526
 * @param $feature_uuid
527
 *   The uuid string representation of the feature to return the settings for
528
 *
529
 * @return array
530
 *  an associative array of settings, with the following fields:
531
 *    - as_list: string
532
 *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
533
 *        possible values are:
534
 *          div: not as list,
535
 *          ul: as bullet list,
536
 *          ol: as numbered list,
537
 *          dl: as definition list
538
 *        The tag used for the inner element, thus depends on the value of this field. The
539
 *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
540
 *    - link_to_reference: boolean,
541
 *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
542
 *    - link_to_name_used_in_source": boolean
543
 *        whether to show name in source information as link which will point to the according name page
544
 *    - sources_as_content (boolean)
545
 *        TRUE (int: 1):
546
 *          1. If element is of the CDM type TextData and the text is not empty the source references will be
547
 *             appended in brackets like "text (source references)". If the original source has name in source
548
 *             information it will be appended to the citation string,
549
 *             like : "(citation, as name in source; citation, as name in source)"
550
 *          2. if the text of the TextData is empty, the original source citations are the only content
551
 *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
552
 *             prepended to the citation string like: "name in source: citation"
553
 *        FALSE (int: 0):
554
 *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
555
 *          citations are the only content, the resulting feature block content would only consist of footnotes.
556
 *          In this case the display of the respective feature block is suppressed.
557
 *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
558
 *               in future however they will in this case be shown in a separate references section for each
559
 *               feature block.
560
 *    - sources_as_content_to_bibliography  (boolean)
561
 *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
562
 *        in the bibliography.
563
 *    - sort_elements
564
 *        whether and how to sort the elements
565
 *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
566
 *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
567
 *        TODO option to exclude levels, put in special?,
568
 *        TODO make use of this setting in compose_feature_block_wrap_elements())
569
 *    - element_tag
570
 *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
571
 *        possible values are span | div. the proper inner tag name can be retrieved by the function
572
 *        cdm_feature_block_element_tag_name()
573
 *    - special: array()
574
 *        an array with further settings, this field can be used for special
575
 *        settings for specialized rendering like for distributions
576
 *  }
577
 *
578
 */
579
function get_feature_block_settings($feature_uuid = 'DEFAULT') {
580
  // the default must conform to the default parameter values of
581
  // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
582
  // compose_description_element_text_data() : asListElement = NULL
583

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

    
586
  // ---- DEFAULTS settings
587

    
588
  // only needed as final option, when the settings are not having a default
589
  $default = array(
590
    'DEFAULT' => array(
591
      'as_list' => 'div',
592
      'link_to_reference' => 0,
593
      'link_to_name_used_in_source' => 1,
594
      'sources_as_content' => 0,
595
      'sources_as_content_to_bibliography' => 0,
596
      'sort_elements' => NO_SORT,
597
      'glue' => '',
598
      'element_tag' => NULL
599
    ),
600
    // settings for pseudo feature bibliography
601
    // only hard coded here
602
    'BIBLIOGRAPHY' => array(
603
      'as_list' => 'div',
604
      'link_to_reference' => 0,
605
      'link_to_name_used_in_source' => 1,
606
      'sources_as_content' => 0,
607
      'sources_as_content_to_bibliography' => 0,
608
      'sort_elements' => NO_SORT,
609
      'glue' => '',
610
      'element_tag' => NULL
611
    )
612
  );
613

    
614
  // will be used as preset in the settings
615
  $other_themes_default = array(
616
    'DEFAULT' => array(
617
      'as_list' => 'div',
618
      'link_to_reference' => 0,
619
      'link_to_name_used_in_source' => 1,
620
      'sources_as_content' => 0,
621
      'sources_as_content_to_bibliography' => 0,
622
      'sort_elements' => NO_SORT,
623
      'glue' => '',
624
      'element_tag' => NULL
625
    ),
626
    UUID_CITATION => array(
627
      'as_list' => 'div',
628
      'link_to_reference' => 0,
629
      'link_to_name_used_in_source' => 0,
630
      'sources_as_content' => 1,
631
      'sources_as_content_to_bibliography' => 0,
632
      'sort_elements' => SORT_ASC,
633
      'glue' => '',
634
      'element_tag' => 'div'
635
    ),
636
    UUID_DISTRIBUTION => array(
637
      'as_list' => 'div', // currently ignored
638
      'link_to_reference' => 0,
639
      'link_to_name_used_in_source' => 0,
640
      'sources_as_content' => 0,
641
      'sources_as_content_to_bibliography' => 0,
642
      'sort_elements' => NO_SORT, // will cause ...
643
      'glue' => '',
644
      'element_tag' => 'div',
645
      'special' => array()
646
    ),
647
    UUID_COMMON_NAME => array(
648
      'as_list' => 'div',
649
      'link_to_reference' => 0,
650
      'link_to_name_used_in_source' => 1,
651
      'sources_as_content' => 0,
652
      'sources_as_content_to_bibliography' => 0,
653
      'sort_elements' => NO_SORT,
654
      'glue' => '',
655
      'element_tag' => 'span'
656
    ),
657
  );
658

    
659
  // ---- Special DEFAULTS for existing portals
660
  // TODO:
661
  // this can be removed once the feature block
662
  // settings have been deployed for the first time to these portals
663

    
664
  $cichorieae_default = array(
665
    'DEFAULT' => array(
666
      'as_list' => 'div',
667
      'link_to_reference' => 1,
668
      'link_to_name_used_in_source' => 1,
669
      'sources_as_content' => 1,
670
      'sources_as_content_to_bibliography' => 0,
671
      'sort_elements' => NO_SORT,
672
      'glue' => '',
673
      'element_tag' => 'div'
674
    ),
675
    UUID_CITATION => array(
676
      'as_list' => 'div',
677
      'link_to_reference' => 0,
678
      'link_to_name_used_in_source' => 0,
679
      'sources_as_content' => 1,
680
      'sources_as_content_to_bibliography' => 0,
681
      'sort_elements' => SORT_ASC,
682
      'glue' => '',
683
      'element_tag' => 'div'
684
    ),
685
    UUID_CHROMOSOMES_NUMBERS => array(
686
      'as_list' => 'ul',
687
      'link_to_reference' => 1,
688
      'link_to_name_used_in_source' => 1,
689
      'sources_as_content' => 1,
690
      'sources_as_content_to_bibliography' => 0,
691
      'sort_elements' => NO_SORT,
692
      'glue' => '',
693
      'element_tag' => 'div'
694
    ),
695
    UUID_CHROMOSOMES => array(
696
      'as_list' => 'ul',
697
      'link_to_reference' => 0,
698
      'link_to_name_used_in_source' => 1,
699
      'sources_as_content' => 1,
700
      'sources_as_content_to_bibliography' => 0,
701
      'sort_elements' => NO_SORT,
702
      'glue' => '',
703
      'element_tag' => 'div'
704
    ),
705
    UUID_COMMON_NAME => array(
706
      'as_list' => 'div',
707
      'link_to_reference' => 0,
708
      'link_to_name_used_in_source' => 1,
709
      'sources_as_content' => 0,
710
      'sources_as_content_to_bibliography' => 0,
711
      'sort_elements' => NO_SORT,
712
      'glue' => '',
713
      'element_tag' => 'span'
714
    ),
715
  );
716

    
717
  $palmweb_default = array(
718
    'DEFAULT' => array(
719
      'as_list' => 'ul',
720
      'link_to_reference' => 1,
721
      'link_to_name_used_in_source' => 1,
722
      'sources_as_content' => 1,
723
      'sources_as_content_to_bibliography' => 1,
724
      'sort_elements' => NO_SORT,
725
      'glue' => '',
726
      'element_tag' => NULL
727
    ),
728
    UUID_CITATION => array(
729
      'as_list' => 'ul',
730
      'link_to_reference' => 1,
731
      'link_to_name_used_in_source' => 1,
732
      'sources_as_content' => 0,
733
      'sources_as_content_to_bibliography' => 1,
734
      'sort_elements' => SORT_ASC,
735
      'glue' => '',
736
      'element_tag' => 'div'
737
    ),
738
    UUID_DISTRIBUTION => array(
739
      'as_list' => 'div', // currently ignored
740
      'link_to_reference' => 1,
741
      'link_to_name_used_in_source' => 1,
742
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
743
      'sources_as_content_to_bibliography' => 1,
744
      'sort_elements' => NO_SORT, // will cause ...
745
      'glue' => ', ',
746
      'element_tag' => 'span',
747
      'special' => array()
748
    ),
749
  );
750

    
751
  $cyprus_default = $cichorieae_default;
752
  $cyprus_default[UUID_DISTRIBUTION] = array(
753
    'as_list' => 'div', // currently ignored
754
    'link_to_reference' => 0,
755
    'link_to_name_used_in_source' => 0,
756
    'sources_as_content' => 0,
757
    'sources_as_content_to_bibliography' => 0,
758
    'sort_elements' => NO_SORT, // will cause ...
759
    'glue' => ' ',
760
    'element_tag' => 'div',
761
    'special' => array()
762
  );
763

    
764
  $default_theme = variable_get('theme_default', NULL);
765

    
766
  switch ($default_theme) {
767
    case 'garland_cichorieae':
768
      $settings_for_theme = $cichorieae_default;
769
      break;
770
    case 'cyprus':
771
      // cyprus: no longer used in production,
772
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
773
      $settings_for_theme = $cyprus_default;
774
      break;
775
    case 'flore_afrique_centrale':
776
    case 'flora_malesiana':
777
    case 'flore_gabon':
778
      $settings_for_theme = $cichorieae_default;
779
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
780
      break;
781
    case 'palmweb_2':
782
      $settings_for_theme = $palmweb_default;
783
      break;
784
    default:
785
      $settings_for_theme = $other_themes_default;
786
  }
787
  // add pseudo feature settings
788
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
789

    
790
  // ---- END of DEFAULTS
791

    
792
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
793

    
794
  $feature_block_setting = null;
795

    
796
  if (isset($saved_settings[$feature_uuid])) {
797
    $feature_block_setting = $saved_settings[$feature_uuid];
798
  }
799
  else if (isset($settings_for_theme[$feature_uuid])) {
800
    $feature_block_setting = $settings_for_theme[$feature_uuid];
801
  }
802
  else if (isset($settings_for_theme['DEFAULT'])) {
803
    $feature_block_setting = $settings_for_theme['DEFAULT'];
804
  }
805

    
806
  // now merge the default and specific settings
807
  $settings_to_merge = array($default['DEFAULT']);
808
  if(is_array($saved_settings)){
809
    $settings_to_merge[] = $saved_settings['DEFAULT'];
810
  }
811
  if(isset($feature_block_setting)){
812
    $settings_to_merge[] = $feature_block_setting;
813
  }
814
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
815

    
816
  return $feature_block_setting;
817
}
818

    
819
/**
820
 * returns the current setting for the original source bibliography
821
 *
822
 * Caches internally
823
 *
824
 * @return array
825
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
826
 *   - 'enabled': 1|0
827
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
828
 */
829
function get_bibliography_settings($clear_cache = false){
830
  static $bibliography_settings = null;
831
  if(!$bibliography_settings || $clear_cache){
832
    $bibliography_settings = get_array_variable_merged(
833
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
834
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
835
    );
836
  }
837
  return $bibliography_settings;
838
}
839

    
840
/**
841
 * @todo Please document this function.
842
 * @see http://drupal.org/node/1354
843
 */
844
function cdm_dataportal_menu_admin(&$items) {
845
  // Display section on admin/config page.
846
  $items['admin/config/cdm_dataportal'] = array(
847
    'title' => 'CDM Dataportal',
848
    'description' => 'Settings for the CDM DataPortal.',
849
    'position' => 'right',
850
    'weight' => 10,
851
    'page callback' => 'system_admin_menu_block_page',
852
    'access arguments' => array('administer cdm_dataportal'),
853
    'file' => 'system.admin.inc',
854
    'file path' => drupal_get_path('module', 'system'),
855
  );
856
  $items['admin/config/cdm_dataportal/settings'] = array(
857
    'title' => 'Settings',
858
    'description' => 'Settings for the CDM DataPortal.',
859
    'weight' => 0,
860
    'page callback' => 'drupal_get_form',
861
    'page arguments' => array('cdm_settings_general'),
862
    'access arguments' => array('administer cdm_dataportal'),
863
    'type' => MENU_NORMAL_ITEM,
864
  );
865
  $items['admin/config/cdm_dataportal/settings/general'] = array(
866
    'title' => 'General',
867
    'description' => 'General',
868
    'weight' => 0,
869
    'page callback' => 'drupal_get_form',
870
    'page arguments' => array('cdm_settings_general'),
871
    'access arguments' => array('administer cdm_dataportal'),
872
    'type' => MENU_DEFAULT_LOCAL_TASK,
873
  );
874

    
875
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
876
    'title' => 'Cache',
877
    'description' => 'Cache',
878
    'access arguments' => array('administer cdm_dataportal'),
879
    'page callback' => 'drupal_get_form',
880
    'page arguments' => array('cdm_settings_cache'),
881
    'weight' => 10,
882
    'type' => MENU_LOCAL_TASK,
883
  );
884

    
885
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
886
    'title' => 'Geo & Map',
887
    'description' => 'Geo & Map',
888
    'access arguments' => array('administer cdm_dataportal'),
889
    'page callback' => 'drupal_get_form',
890
    'page arguments' => array('cdm_settings_geo'),
891
    'weight' => 1,
892
    'type' => MENU_LOCAL_TASK,
893
  );
894

    
895
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
896
    'title' => 'Layout',
897
    'description' => 'Configure and adjust the layout of your DataPortal ',
898
    'access arguments' => array('administer cdm_dataportal'),
899
    'page callback' => 'drupal_get_form',
900
    'page arguments' => array('cdm_settings_layout'),
901
    'weight' => 2,
902
    'type' => MENU_LOCAL_TASK,
903
  );
904

    
905
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
906
    'title' => 'Taxon page',
907
    'description' => 'Configure and adjust the layout of your DataPortal ',
908
    'access arguments' => array('administer cdm_dataportal'),
909
    'page callback' => 'drupal_get_form',
910
    'page arguments' => array('cdm_settings_layout_taxon'),
911
    'weight' => 1,
912
    'type' => MENU_LOCAL_TASK,
913
  );
914
  $items['admin/config/cdm_dataportal/settings/layout/name-page'] = array(
915
    'title' => 'Name page',
916
    'description' => 'Configure and adjust the layout of your DataPortal ',
917
    'access arguments' => array('administer cdm_dataportal'),
918
    'page callback' => 'drupal_get_form',
919
    'page arguments' => array('cdm_settings_layout_name_page'),
920
    'weight' => 1,
921
    'type' => MENU_LOCAL_TASK,
922
  );
923
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
924
    'title' => 'Search',
925
    'description' => 'Configure and adjust the layout of your DataPortal ',
926
    'access arguments' => array('administer cdm_dataportal'),
927
    'page callback' => 'drupal_get_form',
928
    'page arguments' => array('cdm_settings_layout_search'),
929
    'weight' => 2,
930
    'type' => MENU_LOCAL_TASK,
931
  );
932

    
933
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
934
    'title' => 'Media',
935
    'description' => 'Configure and adjust the layout of your DataPortal ',
936
    'access arguments' => array('administer cdm_dataportal'),
937
    'page callback' => 'drupal_get_form',
938
    'page arguments' => array('cdm_settings_layout_media'),
939
    'weight' => 3,
940
    'type' => MENU_LOCAL_TASK,
941
  );
942

    
943
}
944

    
945
/**
946
 * @todo document this function.
947
 */
948
function cdm_help_general_cache() {
949
  $form = array();
950
  $form['cache_help'] = array(
951
    '#type' => 'fieldset',
952
    '#title' => t('Help'),
953
    '#collapsible' => TRUE,
954
    '#collapsed' => TRUE,
955
  );
956
  $form['cache_help']['test'] = array('#value' => t('probando'));
957
  return drupal_render($form);
958
  $res = array();
959
  $res['default'] = drupal_render($help);
960
  return $res;
961
}
962

    
963
/**
964
 * Configures the settings form for the CDM-API module.
965
 *
966
 * @return array
967
 *   Drupal settings form.
968
 */
969
function cdm_settings_general() {
970

    
971
  $form['cdm_webservice'] = array(
972
    '#type' => 'fieldset',
973
    '#title' => t('CDM Server'),
974
    '#collapsible' => FALSE,
975
    '#collapsed' => FALSE,
976
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
977
        CDM data base to the web via RESTful web services and thus is the source of the data
978
        to be displayed by a CDM DataPotal.'),
979
  );
980

    
981
  $form['cdm_webservice']['cdm_webservice_url'] = array(
982
    '#type' => 'textfield',
983
    '#title' => t('CDM web service URL') . ':',
984
    '#description' => t('This is the URL to the CDM-Server exposing your data
985
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
986
    '#default_value' => variable_get('cdm_webservice_url', NULL),
987
  );
988

    
989
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
990
    '#type' => 'markup',
991
    '#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')
992
      . ' visible only for administrators',
993
  );
994

    
995
  $form['cdm_webservice']['freetext_index'] = array(
996
    '#type' => 'fieldset',
997
    '#title' => t('Freetext index'),
998
    '#collapsible' => FALSE,
999
    '#collapsed' => FALSE,
1000
  );
1001

    
1002
  // Check the cdmserver port number and display a waring if it is not port 80
1003
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1004
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1005
    $form['cdm_webservice']['freetext_index']['message'] = array(
1006
      '#markup' => "<div class=\"description\">"
1007
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1008
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1009
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1010
          array('!port' => $portNumberMatch[1][0])
1011
        )
1012
      . "</div>",
1013
    );
1014
  };
1015

    
1016
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1017
  $trigger_link_options = array(
1018
    'attributes' => array(
1019
      'class' => 'index-trigger'
1020
    ),
1021
  );
1022
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1023
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1024
        '!url1' => l(t("Purge"), cdm_compose_ws_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1025
        '!url2' => l(t("Reindex"), cdm_compose_ws_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1026
      ))
1027
    . '<div id="index-progress"></div></div>',
1028
  );
1029

    
1030
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1031
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1032
    '#type' => 'textfield',
1033
    '#title' => t('Login'),
1034
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1035
  );
1036
  drupal_add_js('
1037
        jQuery(document).ready(function() {
1038
             jQuery("#edit-cdm-login").change(function (e) {
1039
                var login = jQuery(e.target).val();
1040
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1041
                   var url = jQuery(this).attr("href");
1042
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1043
                   jQuery(this).attr("href", url);
1044
                });
1045
            });
1046
        });
1047
      ',
1048
    array(
1049
      'type' => 'inline',
1050
      'scope' => 'footer'
1051
    )
1052
  );
1053
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1054

    
1055
  $form['cdm_webservice']['proxy'] = array(
1056
    '#type' => 'fieldset',
1057
    '#title' => t('Proxy'),
1058
    '#collapsible' => TRUE,
1059
    '#collapsed' => TRUE,
1060
  );
1061

    
1062
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1063
    '#type' => 'textfield',
1064
    '#title' => t('Proxy URL') . ':',
1065
    '#description' => t('If this proxy url is set the cdm api tries
1066
    to connect the web service over the given proxy server.
1067
    Otherwise proxy usage is deactivated.'),
1068
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1069
  );
1070

    
1071
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1072
    '#type' => 'textfield',
1073
    '#title' => t('Proxy port') . ':',
1074
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1075
  );
1076

    
1077
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1078
    '#type' => 'textfield',
1079
    '#title' => t('Login') . ':',
1080
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1081
  );
1082

    
1083
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1084
    '#type' => 'textfield',
1085
    '#title' => t('Password') . ':',
1086
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1087
  );
1088

    
1089
  $form['sub_tree_filter'] = array(
1090
    '#type' => 'fieldset',
1091
    '#title' => t('Subtree filter'),
1092
    '#collapsible' => FALSE,
1093
    '#collapsed' => TRUE,
1094
    '#description' => t('The Data Portal can be restricted to the taxa which belong to a specific classification subtree. Other taxa will not be shown or accessible otherwise.'),
1095
  );
1096

    
1097
  $sub_tree_filter_uuid_value = variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE);
1098
  $taxon_node_info = '';
1099
  if($sub_tree_filter_uuid_value){
1100
    $taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE, array($sub_tree_filter_uuid_value));
1101
    if($taxon_node_dto){
1102
      $taxon_node_info = " Current taxon node: <strong>" . cdm_tagged_text_to_markup($taxon_node_dto->taggedTitle) . " [" . $taxon_node_dto->treeIndex . "]</strong>";
1103
    }
1104
  }
1105
  $form['sub_tree_filter'][CDM_SUB_TREE_FILTER_UUID] = array(
1106
    '#type' => 'textfield',
1107
    '#title' => t('Taxon Node UUID') . ':',
1108
    '#default_value' => variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE),
1109
    '#description' => "The uuid of the TaxonNode entity to be used as filter." . $taxon_node_info
1110
  );
1111

    
1112
  // TODO: settings are still incomplete, compare with
1113
  // trunk/dataportal/inc/config_default.php.inc.
1114
  $form['taxon_tree'] = array(
1115
    '#type' => 'fieldset',
1116
    '#title' => t('Taxon Tree'),
1117
    '#collapsible' => FALSE,
1118
    '#collapsed' => TRUE,
1119
    '#description' => t('<p>When you explore your collection, you can navigate
1120
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1121
      able to navigate through your collection the
1122
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1123
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1124
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1125
      </a></p>'),
1126
  );
1127

    
1128
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1129
    '#type' => 'select',
1130
    '#title' => t('Default classification') . ':',
1131
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1132
    '#options' => cdm_get_taxontrees_as_options(),
1133
    '#description' => t('The default taxa classification to be used in the whole portal. 
1134
      This affects most obviously the classification browser and the search in case it is restricted 
1135
      to a specific classification. See also <i>Included Classifications</i> below.'),
1136
  );
1137

    
1138
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1139
    '#type' => 'select',
1140
    '#title' => t('Rank of highest displayed taxon') . ':',
1141
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1142
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1143
    '#options' => cdm_vocabulary_as_option(UUID_RANK, null, true),
1144
    '#description' => t('This is the rank of the highest displayed taxon in the
1145
      <em>taxon tree</em>. You can select here which rank should be at the top
1146
      level of the tree structure.'),
1147
  );
1148

    
1149
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1150
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1151
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1152
      '#type' => 'checkboxes',
1153
      '#title' => t('Included Classifications') . ':',
1154
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1155
      '#options' => cdm_get_taxontrees_as_options(),
1156
      '#description' => t('Only the checked classifications will be available 
1157
        in the classification selection element of the taxon tree browser and in search forms.'),
1158
  );
1159

    
1160
  $form['distribution'] = array(
1161
      '#type' => 'fieldset',
1162
      '#title' => t('Distributions'),
1163
      '#collapsible' => FALSE,
1164
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1165
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1166
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1167
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1168
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1169
          '<p>
1170
          </p>',
1171
  );
1172

    
1173
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1174
      '#type' => 'fieldset',
1175
      '#title' => 'Distribution filter',
1176
      '#collapsible' => FALSE,
1177
      '#collapsed' => FALSE,
1178
      '#tree' => TRUE,
1179
      '#description' => 'The Distribution filter offers the following options
1180
      <ul>
1181
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (<code>PresenceAbsenceTermBase</code>) for
1182
        the same area the status with the highest order is preferred, see <code>OrderedTermBase.compareTo(OrderedTermBase)</code>.</li>
1183
      <li><strong>Sub area preference rule:</strong> If there is an area with a direct sub-area and both areas have the same
1184
        computed status only information on the sub-area should be reported, whereas the super-area should be ignored.</li>
1185
      <li><strong>Marked area filter:</strong> Skip distributions for areas having a <code>true</code> marker with one of the specified marker types.
1186
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1187
        area acts as a fallback area for the sub-areas. An area is a <em>fallback area</em> if it is marked to
1188
        be hidden and if it has at least one sub-area which is not marked to be hidden. The <em>fallback area</em>
1189
        will be shown on a map and used in a condensed distributions string if there is no distribution for any of the non-hidden
1190
        sub-areas. In the textual representation it will shown if distribution data for the fallback area itself exists. For more detailed discussion on
1191
        <em>fallback areas</em> see the ticket <a href="https://dev.e-taxonomy.eu/redmine/issues/4408">#4408</a>.</li>
1192
      </ul>'
1193
  );
1194

    
1195
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1196
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1197
      '#type' => 'checkboxes',
1198
      '#title' => 'Filter rules',
1199
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1200
      '#options' => array(
1201
          'statusOrderPreference' => 'Status order preference rule',
1202
          'subAreaPreference' => 'Sub area preference rule'
1203
      ),
1204
  );
1205

    
1206
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1207
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1208
      '#type' => 'checkboxes',
1209
      '#title' => 'Hide marked area filter',
1210
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1211
      '#options' => $marker_type_options,
1212
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1213
  );
1214

    
1215
  $form['aggregation'] = array(
1216
      '#type' => 'fieldset',
1217
      '#title' => t('Aggregation of data'),
1218
      '#collapsible' => FALSE,
1219
      '#description' => 'This section covers the different aspects of aggregating information.
1220
          <p>
1221
          </p>',
1222
  );
1223

    
1224
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1225
      '#type' => 'checkboxes',
1226
      '#title' => 'Taxon media filter',
1227
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1228
      '#options' => array(
1229
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1230
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1231
          'includeOccurrences' => 'Media related to specimens and occurrences',
1232
      ),
1233
      '#description' => 'This filter configures which images should be taken into account.',
1234
  );
1235

    
1236
  $form['aggregation']['notice'] = array(
1237
      '#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
1238
          want to make use of the caching capabilities of the dataportal.',
1239
  );
1240

    
1241
  $form['aggregation']['media_aggregation'] = array(
1242
      '#type' => 'fieldset',
1243
      '#title' => t('Media aggregation'),
1244
      '#collapsible' => FALSE,
1245
      '#collapsed' => TRUE,
1246
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1247

    
1248
  );
1249
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1250
      '#type' => 'select',
1251
      '#title' => t('Aggregation of taxon pictures') . ':',
1252
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1253
      '#options' => array(
1254
          0 => "Show only pictures of the current taxon",
1255
          1 => "Include pictures of taxonomic children",
1256
      ),
1257
      '#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."),
1258
  );
1259

    
1260
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1261
      '#type' => 'fieldset',
1262
      '#attributes' => array('class' => array('clearfix')),
1263
      '#title' => t('Aggregation via taxon relationsships'),
1264
      '#collapsible' => TRUE,
1265
      '#collapsed' => TRUE,
1266
      '#tree' => TRUE,
1267
      '#description' => t('Information on taxa will be aggregated along the below chosen
1268
          taxon relation ships. This will affect images and occurrences (specimens).
1269
          Taxon relation ships are directed and point form one taxon to another. The taxon
1270
          relationships to be taken into accunt can therefore configured for the direct direction
1271
          and for the inverse.'),
1272
  );
1273

    
1274
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1275
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1276

    
1277
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1278
      '#type' => 'checkboxes',
1279
      '#title' => t('Direct'),
1280
      '#options' => $taxonRelationshipTypeOptions,
1281
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1282
  );
1283
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1284
      '#type' => 'checkboxes',
1285
      '#title' => t('Invers'),
1286
      '#options' => $taxonRelationshipTypeOptions,
1287
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1288
  );
1289

    
1290
  $form['drupal_integration'] = array(
1291
    '#type' => 'fieldset',
1292
    '#attributes' => array('class'=> array('clearfix')),
1293
    '#title' => t('Drupal integration'),
1294
    '#collapsible' => FALSE,
1295
    '#collapsed' => FALSE,
1296
    '#tree' => FALSE
1297
  );
1298

    
1299
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1300
    '#type' => 'checkbox',
1301
    '#title' => 'Create drupal nodes',
1302
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1303
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1304
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1305
    cdm pages it is required that drupal nodes are created and stored in the database.'
1306
  );
1307

    
1308

    
1309

    
1310
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1311
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1312
    <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>',
1313
  );
1314
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1315
    '#type' => 'submit',
1316
    '#value' => t('Drop all cdm nodes'),
1317
    '#submit' => array('drop_all_cdm_nodes_submit')
1318
  );
1319

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

    
1324
    // ----------------------
1325
  $form['cdm_js_devel_mode'] = array(
1326
      '#type' => 'checkbox',
1327
      '#title' => 'Java-script developer mode',
1328
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1329
      '#description' => 'In production envirionments the java script libraries
1330
      the cdm_dataportal is making use of are compressed and optimized. This
1331
      is good for performance but a caveat if you need to debug java-script. When the
1332
      java-script developer mode is enabled the uncompressed and commented developer
1333
      versions of java-script libraries will be used where possible.
1334
      <br/><strong>Do not use this option in production!</strong>'
1335
  );
1336
  // ----------------------
1337
  $form['cdm_debug_mode'] = array(
1338
      '#type' => 'checkbox',
1339
      '#title' => 'CDM page debug mode',
1340
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1341
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1342
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1343
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1344
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1345
      The log is written by the drupal devel module function <code>dd()</code>.
1346
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1347
  );
1348

    
1349
  // Comment @WA: D7 form api does not support reset buttons,
1350
  // so to mimic the D5 reset button we add one like this.
1351
  $form['actions']['reset'] = array(
1352
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1353
    '#weight' => 1000,
1354
  );
1355

    
1356
  $form['#submit'][] = 'cdm_settings_general_submit';
1357

    
1358
  return system_settings_form($form);
1359
}
1360

    
1361
/**
1362
 * Submit callback; drops all cdm nodes.
1363
 *
1364
 * @ingroup forms
1365
 */
1366
function drop_all_cdm_nodes_submit($form, &$form_state) {
1367
  cdm_delete_all_cdm_nodes();
1368
  drupal_set_message(t('All cdm nodes dropped.'));
1369
}
1370

    
1371

    
1372
/**
1373
 * LAYOUT settings
1374
 *
1375
 * @return array
1376
 *   The form structure.
1377
 */
1378
function cdm_settings_layout() {
1379

    
1380
  $form = array();
1381

    
1382
  $form['about'] = array(
1383
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1384
      layout. If you want to configure the specific sites layout visit the
1385
      respective configuration site for taxon, search or media.') . '</p>',
1386
  );
1387

    
1388
  $form['annotations'] = array(
1389
    '#type' => 'fieldset',
1390
    '#title' => t('Annotations'),
1391
    '#collapsible' => FALSE,
1392
    '#collapsed' => FALSE,
1393
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1394
  );
1395

    
1396
  $annotation_type_options = cdm_terms_by_type_as_option('AnnotationType');
1397
  // Additional option for the NULL case.
1398
  $annotation_type_options['NULL_VALUE'] = t('untyped');
1399
  $annotations_types_visible = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1400
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1401
    '#type' => 'checkboxes',
1402
    '#title' => t('Visbility of annotation types'),
1403
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1404
    '#options' => $annotation_type_options,
1405
    '#default_value' => $annotations_types_visible
1406
  );
1407

    
1408
  $form['extensions'] = array(
1409
    '#type' => 'fieldset',
1410
    '#title' => t('Extensions'),
1411
    '#collapsible' => FALSE,
1412
    '#collapsed' => FALSE,
1413
    '#description' => t('This sections allows configuring global settings regarding the data type extensions.'),
1414
  );
1415

    
1416
  $extension_type_options = cdm_terms_by_type_as_option('ExtensionType');
1417
  $extension_types_visible = variable_get(EXTENSION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1418
  $form['extensions'][EXTENSION_TYPES_VISIBLE] = array(
1419
    '#type' => 'checkboxes',
1420
    '#title' => t('Visbility of extension types'),
1421
    '#description' => t("Only extensions of the selected type will be displayed."),
1422
    '#options' => $extension_type_options,
1423
    '#default_value' => $extension_types_visible
1424
  );
1425

    
1426

    
1427
  // ---- original source --- //
1428
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1429
      '#type' => 'fieldset',
1430
      '#tree' => TRUE,
1431
      '#title' => t('Source Citations'),
1432
      '#collapsible' => FALSE,
1433
      '#collapsed' => FALSE,
1434
  );
1435

    
1436
  $bibliography_settings = get_bibliography_settings(true);
1437

    
1438
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1439
      '#type' => 'checkbox',
1440
      '#title' => t('Original Source in bibliography'),
1441
      '#default_value' => $bibliography_settings['enabled'],
1442
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1443
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1444
       into the bibliography also depends on the settings in the ' .
1445
        l("Taxon profile feature block settings", "admin/config/cdm_dataportal/settings/layout/taxon") .
1446
        '. 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.'),
1447
  );
1448

    
1449
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1450
    '#type' => 'select',
1451
    '#title' => t('The format of the key numerals'),
1452
    '#default_value' => $bibliography_settings['key_format'],
1453
    '#options' => array('latin' => 'Latin',
1454
      'ROMAN' => 'Roman (upper case)',
1455
      'roman' => 'Roman (lower case)',
1456
      'ALPHA'=> 'Alphabet (upper case)',
1457
      'alpha' => 'Alphabet (lower case)')
1458
  );
1459

    
1460
  // --- Advanced Search --- //
1461
  $form['asearch'] = array(
1462
      '#type' => 'fieldset',
1463
      '#title' => t('Advanced search'),
1464
      '#collapsible' => FALSE,
1465
      '#collapsed' => FALSE,
1466
  );
1467
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1468
      '#type' => 'checkbox',
1469
      '#title' => t('Show advanced search link'),
1470
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1471
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1472
  );
1473

    
1474
  // --- Name page autoredirect feature --- //
1475
  $form['name_page'] = array(
1476
    '#type' => 'fieldset',
1477
    '#title' => t('Name page'),
1478
    '#collapsible' => FALSE,
1479
    '#collapsed' => FALSE,
1480
  );
1481
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1482
    '#type' => 'checkbox',
1483
    '#title' => 'Always redirect to taxon',
1484
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1485
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1486
    Depending on the context from which a user navigates to the name page the data portal chooses to show the name page or it redirects to the related taxon if there is only one. 
1487
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1488
  );
1489

    
1490
  // --- Registrations --- //
1491
  $form['registrations'] = array(
1492
    '#type' => 'fieldset',
1493
    '#title' => t('Registrations'),
1494
    '#collapsible' => FALSE,
1495
    '#collapsed' => FALSE,
1496
  );
1497
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1498
    '#type' => 'checkbox',
1499
    '#title' => t('Use the persistent http identifier as link'),
1500
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1501
    '#description' => t('Switch the portal from using the drupal path <code>registration/{url encoded persistent http identifier}</code> to using the persistent http identifier directly as link.'),
1502
  );
1503

    
1504
  // ---- Taxon Name Rendering --- //
1505
  $form['taxon_name'] = array(
1506
      '#type' => 'fieldset',
1507
      '#title' => t('Taxon name display'),
1508
      '#collapsible' => TRUE,
1509
      '#collapsed' => TRUE,
1510
      '#description' => t('The display of taxon names is configured by two parts.
1511
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1512
          The name parts are defined in the <stong>part definitions</strong>'),
1513
  );
1514

    
1515
  $nameRenderConfiguration = new NameRenderConfiguration();
1516

    
1517
  $partDefinitionConfigStatus = $nameRenderConfiguration->partDefinitionConfigurationStatus();
1518
  switch($partDefinitionConfigStatus){
1519
    case NameRenderConfiguration::PRE380_CONFIGURATION:
1520
      $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.)';
1521
      break;
1522
    case NameRenderConfiguration::CUSTOM_CONFIGURATION:
1523
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1524
      break;
1525
    case NameRenderConfiguration::DEFAULT_CONFIGURATION:
1526
    default:
1527
      $which_version_message = '(These are the default part definition.)';
1528
  }
1529
  $current_part_definition_json = $nameRenderConfiguration->getCurrentPartDefinitionJson();
1530
  $default_part_definition_json = $nameRenderConfiguration->getDefaultPartDefinitionJson();
1531
  $diff_viewer_markup = '';
1532
  if($partDefinitionConfigStatus == NameRenderConfiguration::CUSTOM_CONFIGURATION){
1533
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1534
  }
1535

    
1536
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1537
    . $which_version_message
1538
    . '</div>'
1539
    . $diff_viewer_markup;
1540

    
1541
  $form['taxon_name'][NameRenderConfiguration::CDM_PART_DEFINITIONS] = array(
1542
      '#type' => 'textarea',
1543
      '#title' => t('Part definitions'),
1544
      '#element_validate' => array('form_element_validate_json'),
1545
      '#default_value' =>  $current_part_definition_json,
1546
      '#description' => '
1547
          <p>' . $which_version_message . '</p>
1548
          <p>
1549
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1550
          </p>
1551
          <p>
1552
           A full taxon name plus additional information can consist of the following elements:
1553
          <ul>
1554
             <li>name: the taxon name inclugin rank nbut without author</li>
1555
             <li>authors:  The authors of a reference, also used in taxon names</li>
1556
             <li>reference: the nomenclatural reference,</li>
1557
             <li>microreference:  Volume, page number etc.</li>
1558
             <li>status:  The nomenclatural status of a name</li>
1559
             <li>description: name descriptions like protologues etc ...</li>
1560
          </ul>
1561
          </p>
1562
          <p>
1563
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1564
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1565
           The following parts can be formed and are recognized by the system:
1566
          <ul>
1567
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1568
            <li>authorshipPart: the author (for example: "L.")</li>
1569
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1570
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1571
               be combined when a link to the taxon is rendered.</li>
1572
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1573
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1574
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1575
            <li>statusPart: the nomenclatorical status</li>
1576
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1577
          </ul>
1578
          </p>
1579
          <p>
1580
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1581
           specific parts part definitions:
1582
          <ul>
1583
            <li>BotanicalName</li>
1584
            <li>ZoologicalName</li>
1585
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1586
          </ul>
1587
           An example:
1588
          <pre>
1589
           ' . $default_part_definition_json . '
1590
           </pre>',
1591
  );
1592

    
1593
  $nameRenderTemplateConfStatus = $nameRenderConfiguration->nameRenderTemplateConfigurationStatus();
1594

    
1595
  switch($nameRenderTemplateConfStatus){
1596
    case NameRenderConfiguration::PRE380_CONFIGURATION:
1597
      $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.)';
1598
      break;
1599
    case NameRenderConfiguration::CUSTOM_CONFIGURATION:
1600
      $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1601
      break;
1602
    case NameRenderConfiguration::DEFAULT_CONFIGURATION:
1603
    default:
1604
      $which_version_message = '(These are the default render templates.)';
1605
  }
1606
  $default_render_templates_json = $nameRenderConfiguration->getDefaultRenderTemplatesJson();
1607
  $current_render_templates_json = $nameRenderConfiguration->getCurrentRenderTemplatesJson();
1608
  $diff_viewer_markup = '';
1609
  if($nameRenderTemplateConfStatus == NameRenderConfiguration::CUSTOM_CONFIGURATION){
1610
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1611
  }
1612

    
1613
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1614
    . $which_version_message
1615
    . '</div>'
1616
    . $diff_viewer_markup;
1617

    
1618
  $form['taxon_name'][NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES] = array(
1619
      '#type' => 'textarea',
1620
      '#title' => t('Name render templates'),
1621
      '#element_validate' => array('form_element_validate_json'),
1622
      '#default_value' =>  $current_render_templates_json,
1623
      '#description' => '
1624
          <p>' . $which_version_message . '</p>
1625
          <p>
1626
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1627
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1628
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1629
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1630
          The following render Path keys are currently recognized:
1631
          <ul>
1632
            <li>list_of_taxa</li>
1633
            <li>acceptedFor</li>
1634
            <li>homonym</li>
1635
            <li>taxon_page_synonymy</li>
1636
            <li>typedesignations</li>
1637
            <li>taxon_page_title</li>
1638
            <li>polytomousKey</li>
1639
            <li>na: name + authorship</li>
1640
            <li>nar:name + authorship + reference</li>
1641
            <li>#DEFAULT</li>
1642
          </ul>
1643
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1644
          array element should be a comma separated list of render paths, without any whitespace!.
1645
          </p>
1646
          <p>
1647
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1648
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1649
          <p>
1650
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1651
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1652
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1653
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1654
          links if the paramters $nameLink or $refenceLink are given to the name render function
1655
          (this is hard coded and cannot be configured here).',
1656
  );
1657

    
1658
  // @WA: D7 form api does not support reset buttons,
1659
  // so to mimic the D5 reset button we add one like this.
1660
  $form['actions']['reset'] = array(
1661
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1662
    '#weight' => 1000,
1663
  );
1664

    
1665
  $form['#submit'] = array('submit_json_as_php_array');
1666
  // #json_elements especially defined for submit_json_as_php_array()
1667
  $form['#json_elements'] = array(NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES, NameRenderConfiguration::CDM_PART_DEFINITIONS);
1668
  return system_settings_form($form);
1669
}
1670

    
1671

    
1672
/**
1673
 * @param $form_name
1674
 * @param $form_title
1675
 * @param $collapsed
1676
 * @param string $form_description
1677
 *   The description for the fieldset of the gallery setting.
1678
 * @return mixed
1679
 */
1680
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1681
  $form[$form_name] = array(
1682
    '#type' => 'fieldset',
1683
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1684
    '#collapsible' => TRUE,
1685
    '#collapsed' => $collapsed,
1686
    '#tree' => TRUE,
1687
    '#description' => $form_description,
1688
  );
1689

    
1690
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1691
  $gallery_settings = variable_get($form_name, $default_values);
1692
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1693
    /*
1694
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1695
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1696
    '#type' => 'textfield',
1697
    '#title' => t('Search Page Size'),
1698
    '#default_value' => $test,
1699
    '#description' => t('Number of Names to display per page in search results.')
1700
    );
1701
    */
1702
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1703
      '#type' => 'checkbox',
1704
      '#title' => t('Show media thumbnails for accepted taxa'),
1705
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1706
    );
1707

    
1708
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1709
      '#type' => 'checkbox',
1710
      '#title' => t('Show media thumbnails for synonyms'),
1711
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1712
      '#description' => '',
1713
    );
1714
  }
1715

    
1716
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1717
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1718
    '#type' => 'checkbox',
1719
    '#title' => t('Show captions under thumbnails'),
1720
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1721
    '#description' => '',
1722
  );
1723

    
1724
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1725
    '#type' => 'textfield',
1726
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1727
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1728
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1729
  );
1730

    
1731
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1732
    '#type' => 'textfield',
1733
    '#title' => t('Number of columns') . ':',
1734
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1735
    '#description' => t('Group the thumbnails in columns: select how many
1736
      columns the gallery should display.'),
1737
  );
1738

    
1739
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1740
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1741
      '#type' => 'textfield',
1742
      '#title' => t('Maximum number of rows') . ':',
1743
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1744
      '#description' => t('You can group the thumbnails in rows, select in how
1745
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1746
        If you want an unlimited number of rows please set to 0.'),
1747
    );
1748
  }
1749

    
1750
  return $form;
1751
}
1752

    
1753
/**
1754
 * @return array
1755
 *   The form structure.
1756
 */
1757
function cdm_settings_layout_taxon() {
1758
  $collapsed = FALSE;
1759
  $form = array();
1760

    
1761
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1762

    
1763
  // --------- TABBED TAXON ------- //
1764
  $form['taxon_node'] = array(
1765
    '#type' => 'fieldset',
1766
    '#title' => t('Taxon node'),
1767
    '#collapsible' => TRUE,
1768
    '#collapsed' => TRUE,
1769
    '#description' => 'Taxa are organized in a classification tree by taxon nodes. Display of taxon node related information like states can be manged here.'
1770
  );
1771
  $form['taxon_node'][CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES] = array(
1772
    '#type' => 'checkbox',
1773
    '#title' => t('Show taxon node states'),
1774
    '#default_value' => variable_get(CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES, 1),
1775
    '#description' => t('Show the taxon node states excluded, unplaced and placement doubtful.'),
1776
  );
1777

    
1778
  // --------- TABBED TAXON ------- //
1779
  $form['taxon_tabs'] = array(
1780
    '#type' => 'fieldset',
1781
    '#title' => t('Taxon tabs'),
1782
    '#collapsible' => TRUE,
1783
    '#collapsed' => TRUE,
1784
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1785
  );
1786

    
1787
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1788
    '#type' => 'checkbox',
1789
    '#title' => t('Tabbed taxon page'),
1790
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1791
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1792
  );
1793

    
1794
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1795
    '#type' => 'checkbox',
1796
    '#title' => t('Synonymy as tab'),
1797
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1798
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1799
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1800
  );
1801

    
1802
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1803
    '#type' => 'checkboxes',
1804
    '#title' => t('Section/Tab visibility') . ':',
1805
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1806
    '#options' => get_taxon_options_list()
1807
  );
1808

    
1809
  // WEIGHT
1810
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1811
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1812
    '#title'  => 'Section/Tab order',
1813
    '#type' => 'fieldset',
1814
    '#collapsible' => false,
1815
    '#tree' => true,
1816
    '#description' => 'The weight value defines the order of the section/tab.'
1817
  );
1818
  // Weights range from -delta to +delta, so delta should be at least half
1819
  // of the amount of tabs present.
1820
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1821
  foreach (get_taxon_tabs_list() as $label) {
1822
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1823
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1824
        '#title' => $label,
1825
        '#type'  => 'weight',
1826
        '#default_value' => $taxon_tabs_weights[$key],
1827
        '#delta' => $tab_weight_delta
1828
    );
1829
  }
1830

    
1831
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1832
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1833
    '#title'  => 'Section/Tab label override',
1834
    '#type' => 'fieldset',
1835
    '#collapsible' => false,
1836
    '#tree' => true,
1837
    '#description' => 'Setting a label for a section/tab will override the default label. 
1838
      Please enter the label text in the default language of the portal.'
1839
  );
1840
  foreach (get_taxon_tabs_list() as $label) {
1841
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1842
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1843
      '#title' => $label,
1844
      '#type'  => 'textfield',
1845
      '#default_value' => $taxon_tabs_labels[$key]
1846
    );
1847
  }
1848

    
1849
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1850
    '#type' => 'select',
1851
    '#title' => t('Default tab to display') . ':',
1852
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1853
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1854
    '#description' => t('<p>Select the default tab to display when visiting a
1855
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1856
      <strong>Note:</strong> After performing a search and clicking in any
1857
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1858
      taxon and not the above selected tab.'),
1859
  );
1860

    
1861
  /* ======  TAXON_PROFILE ====== */
1862
  $form['taxon_profile'] = array(
1863
    '#type' => 'fieldset',
1864
    '#title' => t('Taxon profile (tab)'),
1865
    '#description' => t('<p>This section covers the settings related to the taxon
1866
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1867
    '#collapsible' => TRUE,
1868
    '#collapsed' => TRUE,
1869
  );
1870

    
1871
  // ---- PROFILE PICTURE ----//
1872

    
1873
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1874
    '#type' => 'fieldset',
1875
    '#tree' => TRUE,
1876
    '#title' => t('Taxon profile picture'),
1877
    '#collapsible' => TRUE,
1878
    '#collapsed' => FALSE,
1879
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1880
  );
1881

    
1882
  //FIXME migrate variables:
1883
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1884
  // FIXME
1885
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1886

    
1887
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1888

    
1889
  /*
1890
   * 'show' => 1,
1891
   * 'maxextend' => 184,
1892
   * 'media_uri_query' => ''
1893
   * 'custom_placeholder_image_on' => 1,
1894
   * 'custom_placeholder_image_fid' => ''
1895
   */
1896
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1897
    '#type' => 'checkbox',
1898
    '#title' => t('Enable profile picture'),
1899
    '#description' => t('Show the profile picture.'),
1900
    '#default_value' => $taxon_profile_image_settings['show'],
1901
  );
1902

    
1903
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1904
      '#type' => 'textfield',
1905
      '#tree' => TRUE,
1906
      '#title' => t('Profile picture maximum extend'),
1907
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1908
      '#field_suffix' => 'px',
1909
      '#maxlength' => 4,
1910
      '#size' => 4,
1911
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1912
  );
1913

    
1914
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1915
      '#type' => 'textfield',
1916
      '#tree' => TRUE,
1917
      '#title' => t('Additional URI query parameter'),
1918
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1919
      '#maxlength' => 1024,
1920
      '#size' => 60,
1921
      '#description' => t('Additional query parameters to be used when requesting for the  
1922
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
1923
            The query parameters will be appended to the uri of the media representation part
1924
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1925
  );
1926

    
1927
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1928
    '#type' => 'checkbox',
1929
    '#title' => t('Show the placeholder image'),
1930
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
1931
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1932
  );
1933

    
1934
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1935
      '#type' => 'checkbox',
1936
      '#title' => t('Use a custom placeholder image'),
1937
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1938
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1939
  );
1940

    
1941
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1942
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1943
        '#type' => 'managed_file',
1944
        '#title' => t('Custom placeholder image file'),
1945
        '#progress_indicator' => 'bar',
1946
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1947
    //       '#name' => 'custom_placeholder_image',
1948
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1949
    );
1950

    
1951
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1952
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1953
      $url = file_create_url($profile_image_file->uri);
1954
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1955
                '#type' => 'item',
1956
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1957
      );
1958
    }
1959
  } else {
1960
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1961
      '#type' => 'hidden',
1962
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1963
    );
1964
  }
1965

    
1966
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
1967
  array_unshift($options, '-- DISABLED --');
1968
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1969
    '#type' => 'select',
1970
    '#title' => t('Hide profile picture for higher ranks') . ':',
1971
    '#default_value' => variable_get('image_hide_rank', '0'),
1972
    '#options' => $options,
1973
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1974
  );
1975

    
1976
  // -- MEDIA THUMBNAILS -- //
1977
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1978
  $form_title = 'Taxon Profile Images';
1979
  $form_description = '<p>The different sections in the taxon  profile can have images associated with them. These images are displayed in a gallery of thumbnails wich can be configuered here:</p>';
1980
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1981

    
1982
  // ---- FEATURE TREE BLOCKS ---- //
1983
  $form['taxon_profile']['feature_blocks'] = array(
1984
    '#type' => 'fieldset',
1985
    '#title' => t('Feature Blocks'),
1986
    '#collapsible' => TRUE,
1987
    '#collapsed' => FALSE,
1988
    '#description' => t("This section covers settings related to the taxon's
1989
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
1990
      features such as description, distribution, common names"),
1991
  );
1992
  $featureTrees = cdm_get_featureTrees_as_options(TRUE, TRUE);
1993
  $profile_feature_tree = get_profile_feature_tree();
1994
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
1995
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
1996
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
1997
  }
1998
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
1999
    '#type' => 'radios',
2000
    '#title' => t('Taxon profile feature tree') . ':',
2001
    '#default_value' => $profile_feature_tree_uuid,
2002
    '#options' =>  $featureTrees['options'],
2003
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2004
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2005
    '#description' => t('The Feature Tree selected defines the type and order 
2006
    of the according feature blocks visible in the taxon profile page. A feature block 
2007
    only is shown if any data for it is present. The block weight is shown after the feature label in brackets'
2008
    ),
2009
  );
2010

    
2011
  $pseudo_feature_weights = get_array_variable_merged(CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS, CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS_DEFAULT);
2012
  $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS] = array(
2013
    '#title'  => 'Pseudo feature block weight',
2014
    '#type' => 'fieldset',
2015
    '#collapsible' => false,
2016
    '#tree' => true,
2017
    '#description' => 'Weights for the pseudo feature blocks. The weight value defines the 
2018
    position in the list of blocks. The weight of normal feature is defined by the position 
2019
    of the according feature. Please see the specific feature details above to find the feature weight.'
2020
  );
2021
  foreach ([PSEUDO_FEATURE_NUMBER_OF_TAXA, PSEUDO_FEATURE_AGGREGATION_DESCRIPTIONS, PSEUDO_FEATURE_BIBLIOGRAPHY] as $ps_feature) {
2022
    $form['taxon_profile']['feature_blocks'][CDM_PSEUDO_FEATURE_BLOCK_WEIGHTS][$ps_feature] = array(
2023
      '#title' => $ps_feature,
2024
      '#type'  => 'textfield',
2025
      '#element_validate' => array('element_validate_number'),
2026
      '#size' => 4,
2027
      '#default_value' => $pseudo_feature_weights[$ps_feature]
2028
    );
2029
  }
2030

    
2031

    
2032
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2033
  $profile_feature_tree = get_profile_feature_tree();
2034

    
2035
  if (isset($profile_feature_tree->root->childNodes)) {
2036

    
2037
    $form_feature_block_layout = array(
2038
      '#type' => 'fieldset',
2039
      '#tree' => true,
2040
      '#title' => t('Taxon profile feature block settings'),
2041
      '#collapsible' => TRUE,
2042
      '#collapsed' => FALSE,
2043
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2044
      A sub form for each of the the currently selected feature tree allows to configure each feature block individually.
2045
      The subforms have the following settings in common:<br />
2046
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2047
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2048
      <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>
2049
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2050
            <ol>
2051
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2052
                appended in brackets like "text (source references)". If the original source has name in source
2053
                information it will be appended to the citation string,
2054
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2055
             <li>if the text of the TextData is empty, the original source citations are the only content
2056
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2057
                prepended to the citation string like: "name in source: citation"</li>
2058
            </ol>
2059
            <strong>If disabled:</strong><br />
2060
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2061
             citations are the only content, the resulting feature block content would only consist of footnotes.
2062
             In this case the display of the respective feature block is suppressed.</div>
2063
      </dl>
2064
      <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
2065
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2066
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2067
        . '</em></div>
2068
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2069
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2070
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2071
      <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>
2072
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2073
           cdm_feature_block_element_tag_name()</div>
2074
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2075
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2076
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2077
    );
2078

    
2079

    
2080
    $feature_list_layout_settings_disabled = FALSE;
2081

    
2082
    // creating helper object to retrieve the default settings
2083
    $featureNode = new stdClass();
2084
    $featureNode->term = new stdClass();
2085
    $featureNode->term->uuid="DEFAULT";
2086
    $featureNode->term->representation_L10n = "Default";
2087
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2088

    
2089
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2090

    
2091
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2092

    
2093
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2094
        $subform_id = $featureNode->term->uuid;
2095
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2096

    
2097
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2098

    
2099
        $form_feature_block_layout[$subform_id] = array(
2100
          '#type' => 'fieldset',
2101
          '#tree' => TRUE,
2102
          '#title' => $featureNode->term->representation_L10n,
2103
          '#collapsible' => FALSE,
2104
          '#collapsed' => FALSE,
2105
        );
2106
        if($featureNode->term->uuid == "DEFAULT"){
2107
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2108
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2109
          references</em> and <em>names in source</em> is only possible in the defaults';
2110
        }
2111

    
2112
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2113
          '#type' => 'select',
2114
          '#title' => 'List type',
2115
          '#default_value' => $feature_block_setting['as_list'],
2116
          '#options' => array(
2117
            'div' => 'not as list',
2118
            'ul' => 'bullet list',
2119
            'ol' => 'numbered list',
2120
            'dl' => 'definition list'
2121
          ),
2122
        );
2123

    
2124
        if($featureNode->term->uuid == "DEFAULT"){
2125
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2126
            '#type' => 'checkbox',
2127
            '#title' => t('Link to reference'),
2128
            '#default_value' => $feature_block_setting['link_to_reference'],
2129
          );
2130

    
2131
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2132
            '#type' => 'checkbox',
2133
            '#title' => 'Link to name used in source',
2134
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2135
          );
2136
        }
2137

    
2138
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2139
          '#type' => 'checkbox',
2140
          '#title' => 'Sources as content',
2141
          '#default_value' => $feature_block_setting['sources_as_content'],
2142
        );
2143

    
2144
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2145
          '#type' => 'checkbox',
2146
          '#title' => 'Put sources also as content to bibliography',
2147
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2148
        );
2149

    
2150
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2151
          '#type' => 'select',
2152
          '#title' => t('Sort elements'),
2153
          '#default_value' => $feature_block_setting['sort_elements'],
2154
          '#options' => array(
2155
            NO_SORT => 'No sorting',
2156
            SORT_ASC => 'Ascending',
2157
            SORT_DESC => 'Descending',
2158
            SORT_HIERARCHICAL => 'Hierarchical'
2159
          ),
2160
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2161
          <dl>
2162
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2163
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2164
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2165
          <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>
2166
          </dl>',
2167
        );
2168

    
2169
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2170
          '#type' => 'select',
2171
          '#title' => t('Element tag'),
2172
          '#options' => array(
2173
            'span' => 'span',
2174
            'div' => 'div',
2175
            'p' => 'p'
2176
          ),
2177
          '#default_value' => $feature_block_setting['element_tag'],
2178
        );
2179
        $form_feature_block_layout[$subform_id]['glue'] = array(
2180
          '#type' => 'textfield',
2181
          '#title' => t('Element glue'),
2182
          '#default_value' => $feature_block_setting['glue'],
2183
          '#size' => 10
2184
      );
2185

    
2186
      }
2187
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2188
    }
2189
  }
2190

    
2191
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2192
  $form['taxon_profile']['structured_description_featuretree'] = array(
2193
    '#type' => 'fieldset',
2194
    '#title' => t('Structured Description Feature Tree'),
2195
    '#collapsible' => TRUE,
2196
    '#collapsed' => FALSE,
2197
  );
2198
  $featureTrees = cdm_get_featureTrees_as_options();
2199
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2200
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2201
    $profile_feature_tree_uuid = NULL;
2202
  }
2203
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2204
    '#type' => 'radios',
2205
    '#title' => t('Natural language representation of structured descriptions') . ':',
2206
    '#default_value' => $profile_feature_tree_uuid,
2207
    '#options' => $featureTrees['options'],
2208
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2209
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2210
    '#description' => t('Taxon descriptions can be stored in a highly structured
2211
      form. The feature tree selected here will be used to generate textual
2212
      representation in natural language.'
2213
    ),
2214
  );
2215

    
2216

    
2217

    
2218
  // ---- DISTRIBUTION LAYOUT ---- //
2219
  $form['taxon_profile']['distribution_layout'] = array(
2220
    '#title' => t('Distribution'),
2221
    '#collapsible' => TRUE,
2222
    '#collapsed' => FALSE,
2223
    '#type' => 'fieldset',
2224
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2225
        Map settings regarding the geometry, layers, etc are found in the '
2226
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2227
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2228
      . l(
2229
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2230
        array('fragment' => 'edit-feature-block-settings')
2231
      )
2232
      . ' More general settings regrading the filtering of Distributions are found at '
2233
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2234
      . '. (These settings here will be merged in future releases into the feature block settings)',
2235

    
2236
  );
2237

    
2238
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2239

    
2240
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2241
    '#type' => 'checkbox',
2242
    '#title' => t('Condensed distribution'),
2243
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2244
    '#description' => 'This option enables the display of a very compact representation
2245
    of the distribution which includes also information on the status.',
2246
  );
2247

    
2248
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2249
    '#type' => 'select',
2250
    '#title' => t('Condensed distribution recipe'),
2251
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2252
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2253
    '#description' => 'Recipe for creating the condensed distribution.',
2254
  );
2255

    
2256
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2257
    '#type' => 'textfield',
2258
    '#title' => t('Condensed distribution info path'),
2259
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2260
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2261
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2262
  );
2263

    
2264

    
2265
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2266
    '#type' => 'radios',
2267
    '#title' => t('Display mode') . ':',
2268
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2269
    '#options' => array(
2270
      'FLAT_ALPHA' => t('Flat list'),
2271
      'TREE' => t('Hierarchically ordered'),
2272
    ),
2273
    '#description' => 'Taxon distribution information is displayed with
2274
    focus on the area of the distribution. The list of areas can either be shown
2275
    as flat list ordered alphabetically or in the hierarchical of the parent
2276
    area and subarea relationship. Fall back areas areas with no Distribution data
2277
    are hidden from the area hierarchy so that their sub areas will move one level up.
2278
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2279
    ' for details on the <em>Marked area filter</em>.',
2280
  );
2281

    
2282
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2283
    '#type' => 'fieldset',
2284
    '#tree' => true,
2285
    '#title' => t('Distribution hierarchy style')
2286
  );
2287

    
2288
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2289
  foreach(array_keys($hierarchy_styles) as $level) {
2290
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2291
      '#type' => 'fieldset',
2292
      '#tree' => true,
2293
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2294
      '#attributes' => array('class' => array('fieldset-float'))
2295
    );
2296
    foreach ($hierarchy_styles[$level] as $key => $value) {
2297
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2298
        '#type' => 'textfield',
2299
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2300
        '#default_value' => $hierarchy_styles[$level][$key],
2301
        '#maxlength' => 4,
2302
        '#size' => 4
2303
      );
2304
    }
2305
  }
2306

    
2307
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2308
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2309
    '#type' => 'checkboxes',
2310
    '#title' => 'Omit area levels',
2311
    '#options' => $level_options,
2312
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2313
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2314
    Areas which belong to the selected area levels will be hidden in the portal.',
2315
  );
2316

    
2317
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2318
    '#type' => 'checkbox',
2319
    '#title' => t('Show TextData elements on top of the map'),
2320
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2321
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2322
      elements on top of the map. Otherwise all <code>TextData</code>
2323
      distribution elements will be listed below the other area elements.
2324
      This option is useful if you need to have descriptive texts for each
2325
      distribution map.'),
2326
  );
2327

    
2328
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2329
      '#type' => 'textarea',
2330
      '#title' => t('Custom status colors'),
2331
      '#element_validate' => array('form_element_validate_json'),
2332
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2333
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2334
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2335
          reference list of the idInVocabulary values of absence and presence terms:
2336
<pre>
2337
Presence Term
2338
p	present
2339
pd	present: doubtfully present
2340
n	native
2341
nq	native: presence questionable
2342
nd	native: doubtfully native
2343
c	cultivated
2344
i	introduced
2345
iq	introduced: presence questionable
2346
id	introduced: doubtfully introduced (perhaps cultivated only)
2347
ip	introduced: uncertain degree of naturalisation
2348
ia	introduced: adventitious (casual)
2349
in	introduced: naturalized
2350
ic	introduced: cultivated
2351
e	endemic for the relevant area
2352
na	naturalised
2353
iv	invasive
2354

    
2355
AbsenceTerm
2356
a	absent
2357
f	reported in error
2358
nf	native: reported in error
2359
if	introduced: reported in error
2360
cf	cultivated: reported in error
2361
ne	native: formerly native
2362
ie	introduced: formerly introduced
2363

    
2364
</pre>'),
2365
  );
2366

    
2367

    
2368
  /* ====== SYNONYMY ====== */
2369
  $form['taxon_synonymy'] = array(
2370
    '#type' => 'fieldset',
2371
    '#title' => t('Taxon synonymy (tab)'),
2372
    '#collapsible' => TRUE,
2373
    '#collapsed' => TRUE,
2374
    '#description' => t('This section covers the settings related to the taxon
2375
      <strong>synonymy</strong> tab.'),
2376
  );
2377

    
2378
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2379
    '#type' => 'checkbox',
2380
    '#title' => t('Accepted taxon on top of the synonymy'),
2381
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT),
2382
    '#description' => t('If checked, the first homotypic taxon is a repetition
2383
      of the accepted taxon most likely with the full nomenclatural reference, 
2384
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2385
  );
2386

    
2387
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2388
    '#type' => 'checkbox',
2389
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2390
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2391
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2392
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2393
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2394
    '#disabled' =>  !variable_get(CDM_DATAPORTAL_NOMREF_IN_TITLE, CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT)
2395
  );
2396

    
2397
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2398
    '#type' => 'textfield',
2399
    '#description' => 'Label for the secundum referenence.',
2400
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2401
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2402
    );
2403

    
2404
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2405
    '#type' => 'checkbox',
2406
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2407
      coming from a synonym link.'),
2408
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2409
    '#description' => t('Check this if after doing a search and clicking on a
2410
      synonym you want to see the "accept of" text for the accepted synonym.'),
2411
  );
2412

    
2413
  $form['taxon_synonymy']['taxon_relations'] = array(
2414
    '#type' => 'fieldset',
2415
    '#title' => t('Taxon relationships'),
2416
    '#collapsible' => FALSE,
2417
    '#collapsed' => FALSE
2418
  );
2419

    
2420
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2421
    '#type' => 'checkbox',
2422
    '#title' => t('Show taxon relations ships of accepted taxon'),
2423
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2424
    '#description' => t('If this option is enabled the synonymy will show the
2425
      below selected taxon relationships of accepted taxa.'),
2426
  );
2427

    
2428
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2429
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2430
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2431
    '#type' => 'checkboxes',
2432
    '#title' => t('Taxon relationship types') . ':',
2433
    '#description' => 'Only taxon relationships of the selected type will be displayed',
2434
    '#options' => $taxon_relationship_type_options,
2435
    '#default_value' => $taxon_relationship_type_defaults,
2436
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2437
  );
2438

    
2439
  $form['taxon_synonymy']['name_relations'] = array(
2440
    '#type' => 'fieldset',
2441
    '#title' => t('Name relationships'),
2442
    '#collapsible' => FALSE,
2443
    '#collapsed' => FALSE
2444
  );
2445

    
2446
  $name_relationship_type_options = cdm_vocabulary_as_option(
2447
      UUID_NAME_RELATIONSHIP_TYPE,
2448
      '_cdm_relationship_type_term_label_callback',
2449
      false,
2450
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2451
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2452
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2453
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2454
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2455
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2456
  );
2457
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2458
    '#type' => 'checkboxes',
2459
    '#title' => t('Name relationship types') . ':',
2460
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2461
    A full listing of all name relationships for a scientific name is provided by the taxon ' . l('name page', 'admin/config/cdm_dataportal/settings/layout/name-page') . '.',
2462
    '#options' => $name_relationship_type_options,
2463
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2464
  );
2465

    
2466
  // ====== SPECIMENS ====== //
2467
  $form['taxon_specimens'] = array(
2468
    '#type' => 'fieldset',
2469
    '#title' => t('Taxon specimens (tab)'),
2470
    '#collapsible' => TRUE,
2471
    '#collapsed' => TRUE,
2472
    '#description' => t('This section covers the settings related to the taxon
2473
      <strong>specimens</strong> tab.'),
2474
  );
2475

    
2476
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2477

    
2478

    
2479
  $form['taxon_specimens'][CDM_SPECIMEN_LIST_VIEW_MODE] = array(
2480
      '#type' => 'radios',
2481
      '#title' => t('View mode for lists of specimens or occurrences.'),
2482
      '#default_value' => variable_get(CDM_SPECIMEN_LIST_VIEW_MODE, CDM_SPECIMEN_LIST_VIEW_MODE_DEFAULT),
2483
      '#options' => [
2484
        CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE => 'Compressed derivate table',
2485
        CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE => 'Derivate tree',
2486
        CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_PATH => 'Derivate path'
2487
      ],
2488
      '#description' => 'Available view modes for listing specimens and occurrences are:
2489
        <ul>
2490
         <li>' . CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TABLE . ': As compressed table where every row represents
2491
    a collection. Rows can be expanded to get an overview of the specimens and their derivatives.</li>
2492
         <li>' . CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_TREE . ': As tree of all derivations stemming from the field unit</li>
2493
         <li>' . CDM_SPECIMEN_LIST_VIEW_MODE_OPTION_DERIVATE_PATH . ': As the path of derivatives from the specimen to the field unit</li>
2494
       </ul>'
2495
  );
2496

    
2497
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2498
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2499
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2500
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2501
  }
2502
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2503
    '#type' => 'radios',
2504
    '#title' => t('Specimen description feature tree') . ':',
2505
    '#default_value' => $profile_feature_tree_uuid,
2506
    '#options' =>  $featureTrees['options'],
2507
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2508
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2509
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2510
    ),
2511
  );
2512

    
2513
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2514
  $form_title = t('Specimen media');
2515
  $form_description = t('Specimens may have media which is displayed at the
2516
     Specimen tab/section as a gallery. It is possible to configure the
2517
     thumbnails gallery here, however for configuring how a single media should
2518
     be displayed please go to !url.</p>',
2519
     array(
2520
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2521
     ));
2522
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2523

    
2524
  // --- MEDIA GALLERY ---- //
2525
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2526
  $form_title = 'Media gallery (tab)';
2527
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2528
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2529
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2530
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2531
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2532
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2533
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2534

    
2535
  // Comment @WA: D7 form api does not support reset buttons,
2536
  // so to mimic the D5 reset button we add one like this.
2537
  $form['actions']['reset'] = array(
2538
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2539
    '#weight' => 1000,
2540
  );
2541
  return system_settings_form($form);
2542
}
2543

    
2544
/**
2545
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2546
 *
2547
 * @param $map_id
2548
 * @param $form
2549
 * @return mixed
2550
 */
2551
function _cdm_map_visibility_setting($map_id)
2552
{
2553
  return array(
2554
    '#type' => 'select',
2555
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2556
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2557
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2558
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2559
        The map also can forced to show up <b>always</b> or <b>never</b>."
2560
  );
2561
}
2562

    
2563
/**
2564
 * @return array
2565
 *   The form structure.
2566
 */
2567
function cdm_settings_layout_search() {
2568

    
2569
  $form = array();
2570

    
2571
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2572

    
2573
  $form['search_settings'] = array(
2574
    '#type' => 'fieldset',
2575
    '#title' => t('Taxa Search'),
2576
    '#collapsible' => FALSE,
2577
    '#collapsed' => FALSE,
2578
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2579
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2580
         where they can write the text to be searched. You can find Drupal block configuration
2581
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2582
  );
2583

    
2584
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2585
      '#type' => 'checkbox',
2586
      '#title' => t('Ignore the chosen classification in simple search'),
2587
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2588
      '#description' => t('The simple search, which can be executed via the search block,
2589
          will by default search on the classification selected in the classification browser
2590
          selector. Set the tick if you want your portal to search on all classifications.'),
2591
  );
2592

    
2593
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2594
    '#type' => 'checkbox',
2595
    '#title' => t('Run simple search with free-text search backend.'),
2596
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2597
    '#description' => t('The simple search uses by default another search
2598
      backend as the advances search. By checking this option the simple search can be
2599
      configured to also use the free-text search backend.'),
2600
  );
2601

    
2602
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2603
    '#type' => 'checkbox',
2604
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2605
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2606
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2607
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2608
  );
2609

    
2610
  $form['search_settings'][CDM_SEARCH_RESULT_PAGE_SIZE] = array(
2611
    '#type' => 'textfield',
2612
    '#title' => t('Results per page') . ':',
2613
    '#default_value' => variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT),
2614
    '#description' => t('Number of results to display per page.'),
2615
  );
2616

    
2617
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2618
    '#type' => 'checkbox',
2619
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2620
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2621
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2622
  );
2623

    
2624
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2625
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2626
      '#type' => 'checkboxes',
2627
      '#title' => 'Search mode',
2628
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2629
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2630
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2631
          defaults set here.',
2632
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2633
      '#default_value' => $search_mode_default
2634
      );
2635

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

    
2641
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2642
  );
2643

    
2644
    $form['blast_search_settings'] = array(
2645
        '#type' => 'fieldset',
2646
        '#title' => t('Blast Search'),
2647
        '#collapsible' => TRUE,
2648
        '#collapsed' => TRUE,
2649
        '#description' => t('<p>To perform blast searchs
2650
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2651
         where they can write the text to be searched. You can find Drupal block configuration
2652
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2653
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2654
    );
2655

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

    
2661
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2662
    );
2663
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2664
        '#type' => 'textfield',
2665
        '#title' => t('Webservice URL for blast search') . ':',
2666
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2667

    
2668
        '#description' => t('Enter the webservice URL for blast search'),
2669
    );
2670

    
2671
  // --- SEARCH TAXA GALLERY ---- //
2672
  $items = variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT);
2673
  $collapsed = FALSE;
2674
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2675
  $form_title = 'Taxa Search thumbnails';
2676
  $form_description = 'Search results may show thumbnails. ';
2677
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2678

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

    
2688

    
2689
/**
2690
 * @return array
2691
 *   The form structure.
2692
 */
2693
function cdm_settings_layout_name_page()
2694
{
2695

    
2696
  $form = array();
2697

    
2698

    
2699
  $form['name_relations'] = array(
2700
    '#type' => 'fieldset',
2701
    '#title' => t('Name relationship listings'),
2702
    '#collapsible' => FALSE,
2703
    '#collapsed' => FALSE
2704
  );
2705

    
2706
  $name_relationship_type_options = cdm_vocabulary_as_option(
2707
    UUID_NAME_RELATIONSHIP_TYPE,
2708
    '_cdm_relationship_type_term_label_callback',
2709
    false
2710
  );
2711
  $form['name_relations'][CDM_NAME_RELATIONSHIP_LIST_TYPES] = array(
2712
    '#type' => 'checkboxes',
2713
    '#title' => t('Name relationship types') . ':',
2714
    '#description' => 'This setting only affects specific types of name relations which are displayed as list. Another representations 
2715
    is the inline style used in the synonymy which may show a different (reduced) set of name relations. 
2716
    The according settings can be adjusted in the ' . l('taxon page settings section synonmy', 'admin/config/cdm_dataportal/settings/layout/taxon') . '.',
2717
    '#options' => $name_relationship_type_options,
2718
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE)),
2719
  );
2720

    
2721
  $form[CDM_NAME_PAGE_SECTION_TAXA] = array (
2722
    '#type' => 'checkbox',
2723
    '#title' => 'Show the associated taxa section',
2724
    '#default_value' => variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT)
2725

    
2726
  );
2727

    
2728
  return system_settings_form($form);
2729
}
2730

    
2731
/**
2732
 * @return array
2733
 *   The form structure.
2734
 */
2735
function cdm_settings_layout_media() {
2736

    
2737
  $form = array();
2738

    
2739
  $form['media_settings'] = array(
2740
    '#type' => 'fieldset',
2741
    '#title' => t('Media settings'),
2742
    '#collapsible' => FALSE,
2743
    '#collapsed' => FALSE,
2744
    '#description' => 'This section covers layout settings for media pages.'
2745
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2746
  );
2747

    
2748
  $form['media_settings'][CDM_MEDIA_GALLERY_VIEWER] = array(
2749
    '#type' => 'select',
2750
    '#title' => t('Image viewer') . ':',
2751
    '#default_value' => variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT),
2752
    '#options' => array(
2753
      CDM_MEDIA_GALLERY_VIEWER_DEFAULT => t('Universalviewer'),
2754
      'fsi' => t('FSI viewer (requires FSI server!)'),
2755
      'default' => t('Simple viewer'),
2756
    ),
2757
    '#description' => 'The <b>Universalviewer</b> is a feature rich image gallery and viewer which provides support
2758
            for mobile devices and thus is highly recommended over the other options.<br/>
2759
            <b>Simple viewer</b> combines a HTML gallery with a simple image viewer and only provides basic functionality 
2760
            and does not work well on mobile devices.<br />
2761
            <b>FSI Viewer</b> can only be used in conjunction with images served by an FSI server.'
2762
  );
2763

    
2764
  // --- STANDARD_IMAGE_VIEWER ---- //
2765
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT) == CDM_MEDIA_GALLERY_VIEWER_SIMPLE) {
2766
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2767
      '#type' => 'fieldset',
2768
      '#tree' => true,
2769
      '#title' => t('Standard image viewer settings'),
2770
      '#collapsible' => FALSE,
2771
      '#collapsed' => FALSE,
2772
      );
2773

    
2774
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2775
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2776
      '#type' => 'checkbox',
2777
      '#title' => 'Show media representations',
2778
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2779
    );
2780

    
2781
  }
2782
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, 'default') == CDM_MEDIA_GALLERY_VIEWER_DEFAULT) {
2783
    $form['media_settings'][CDM_ADDITIONAL_MEDIA_COPYRIGHT] = [
2784
      '#type' => 'textarea',
2785
      '#title' => 'Additional media copyright statement',
2786
      '#default_value' => variable_get(CDM_ADDITIONAL_MEDIA_COPYRIGHT, NULL),
2787
      '#description' => 'This statement will be shown below the <b>Universal imgage viewer only</b>'
2788
    ];
2789
  }
2790

    
2791
  // @WA: D7 form api does not support reset buttons,
2792
  // so to mimic the D5 reset button we add one like this.
2793
  $form['actions']['reset'] = array(
2794
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2795
    '#weight' => 1000,
2796
  );
2797
  return system_settings_form($form);
2798
}
2799

    
2800
/**
2801
 * GEOSERVICE and Map settings.
2802
 *
2803
 *  @return array
2804
 *   The form structure.
2805
 */
2806
function cdm_settings_geo($form, &$form_state) {
2807

    
2808
  $current_geoserver_settings = get_edit_map_service_settings();
2809
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2810

    
2811

    
2812
  $form = array();
2813

    
2814
  $dummy_distribution_query = NULL;
2815
  if($map_distribution['map_type'] != 1){
2816
    // we need to apply a dummy query since the map service requires for image maps
2817
    // at least as and ad to be defined
2818
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2819
  }
2820

    
2821
  $form['map_preview'] = array(
2822
      '#type' => 'fieldset',
2823
      '#tree' => FALSE,
2824
      '#title' => t('Map preview'),
2825
      '#collapsible' => FALSE,
2826
      '#description' => 'The preview of the map'
2827
       . ($dummy_distribution_query != null ?
2828
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2829
           '.<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.')
2830
  );
2831
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, NULL, $dummy_distribution_query, NULL, [
2832
    'move' => "this.cdmOpenlayersMap.printInfo",
2833
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2834
  ], TRUE // resizable
2835
  );
2836

    
2837
  /*
2838
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2839
  );
2840
  */
2841

    
2842
  /*
2843
   * GEO SERVER
2844
   */
2845
  $form['edit_map_server'] = array(
2846
    '#type' => 'fieldset',
2847
    '#tree' => true,
2848
    '#title' => t('EDIT map service'),
2849
    '#collapsible' => TRUE,
2850
    '#collapsed' => TRUE,
2851
    '#description' => t('Configuration and selection of your geo server.
2852
      The Geo Server is responsible for generating the maps.'),
2853
  );
2854

    
2855
  $form['edit_map_server']['base_uri'] = array(
2856
    '#type' => 'select',
2857
    '#title' => t('EDIT map service') . ':',
2858
    '#default_value' => $current_geoserver_settings['base_uri'],
2859
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2860
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2861
  );
2862
  $form['edit_map_server']['version'] = array(
2863
      '#type' => 'select',
2864
      '#title' => t('Version') . ':',
2865
      '#default_value' => $current_geoserver_settings['version'],
2866
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2867
      '#description' => t('The version of the EDIT map services'),
2868
  );
2869

    
2870
  /*
2871
   * MAP SETTINGS
2872
   */
2873

    
2874
  $form[CDM_MAP_DISTRIBUTION] = array(
2875
    '#type' => 'fieldset',
2876
    '#tree' => TRUE,
2877
    '#title' => t('Maps settings'),
2878
    '#collapsible' => TRUE,
2879
    '#collapsed' => TRUE,
2880
    '#description' => t('General configuration for all map types.'),
2881
  );
2882

    
2883
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2884
    '#type' => 'radios',
2885
    '#title' => 'Map types',
2886
    '#options' => array(
2887
      1 => "OpenLayers dynamic map viewer",
2888
      0 => "Plain image",
2889
    ),
2890
    '#default_value' => $map_distribution['map_type'],
2891
    '#description' => 'Two different map types are available :
2892
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2893
      which allows zooming and panning. If enabled you can configure the default layer
2894
      (background of your maps) below.</li>
2895
      <li><em>Plain image</em>: The map will be static non interactive
2896
      image.</li></ul>',
2897
  );
2898
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2899

    
2900
  /*
2901
   * settings for the distribution map are used also for specimens map!!!!
2902
   */
2903

    
2904
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2905
      '#type' => 'textfield',
2906
      '#title' => 'Aspect ratio',
2907
      '#default_value' => $map_distribution['aspect_ratio'],
2908
      '#maxlength' => 4,
2909
      '#size' => 4,
2910
      '#element_validate' => array('element_validate_number'),
2911
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2912
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2913
      width by the height:</br>
2914
      <pre>aspect ratio = w / h</pre>
2915
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2916
      for a square map use <strong>1</strong>.',
2917
  );
2918

    
2919
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2920
    '#type' => 'textfield',
2921
    '#title' => 'Bounding box',
2922
    '#default_value' => $map_distribution['bbox'],
2923
    '#description' =>
2924
      'The bounding box (left, bottom, right, top) defines the area to be initially displayed in maps. The bbox must be given in coordinates of the projection of the chosen layer. 
2925
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
2926
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
2927
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2928
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong class="layer-value">map extent bbox</strong></span> from the details information.
2929
      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
2930
      below the map from where you can copy the bbox string.</p>',
2931
  );
2932

    
2933
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2934
    '#type' => 'select',
2935
    '#title' => 'Max zoom level',
2936
    '#default_value' => $map_distribution['maxZoom'],
2937
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
2938
  );
2939

    
2940
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2941
    '#type' => 'checkbox',
2942
    '#title' => 'Display area labels',
2943
    '#default_value' => $map_distribution['show_labels'],
2944
    '#description' => t('The map will show name labels of the areas'),
2945
  );
2946

    
2947
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2948
    '#type' => 'textfield',
2949
    '#title' => 'Map caption',
2950
    '#default_value' => $map_distribution['caption'],
2951
    '#description' => t('The caption will be shown below the map.'),
2952
  );
2953

    
2954
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2955
    '#type' => 'textfield',
2956
    '#title' => 'Distribution layer opacity',
2957
    '#default_value' => $map_distribution['distribution_opacity'],
2958
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2959
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2960
  );
2961

    
2962
  // --- Plain Image Settings --- //
2963
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2964
    '#type' => 'fieldset',
2965
    '#title' => 'Plain image map settings',
2966
    '#tree' => TRUE,
2967
    '#collapsible' => TRUE,
2968
    '#collapsed' => $open_layers_is_enabled,
2969
    '#description' => 'The settings in this section are still expertimental
2970
      and can only be used with the EDIT map service version 1.1 or above.',
2971
  );
2972
  $edit_mapserver_version = get_edit_map_service_version_number();
2973
  if ($edit_mapserver_version < 1.1) {
2974
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2975
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2976
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2977
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2978
  }
2979

    
2980
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2981
    '#type' => 'textfield',
2982
    '#title' => 'Width',
2983
    '#default_value' => $map_distribution['image_map']['width'],
2984
    '#maxlength' => 4,
2985
    '#size' => 4,
2986
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2987
  );
2988

    
2989
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2990
    '#type' => 'textfield',
2991
    '#title' => 'Background layer',
2992
    '#default_value' => $map_distribution['image_map']['base_layer'],
2993
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2994
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2995
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2996
    )),
2997
  );
2998

    
2999
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3000
    '#type' => 'textfield',
3001
    '#title' => 'Background color',
3002
    '#default_value' => $map_distribution['image_map']['bg_color'],
3003
  );
3004

    
3005
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3006
    '#type' => 'textfield',
3007
    '#title' => 'Background layer style',
3008
     // Only line color by now.
3009
    '#default_value' => $map_distribution['image_map']['layer_style'],
3010
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3011
  );
3012

    
3013
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3014
      '#type' => 'textfield',
3015
      '#title' => 'Projection',
3016
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3017
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3018
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3019
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3020
  );
3021

    
3022

    
3023
  // --- OpenLayers Settings --- //
3024
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3025
    '#type' => 'fieldset',
3026
    '#title' => 'OpenLayers settings',
3027
    '#tree' => TRUE,
3028
    '#collapsible' => TRUE,
3029
    '#collapsed' => !$open_layers_is_enabled,
3030
    '#description' => '',
3031
  );
3032

    
3033

    
3034
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3035
      '#type' => 'checkbox',
3036
      '#title' => 'Display outside max extent',
3037
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3038
      '#description' => t('Allows the map to display parts of the layers which are outside
3039
         the max extent if the aspect ratio of the map and of the baselayer
3040
         are not equal.'),
3041
  );
3042

    
3043

    
3044
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3045
      '#type' => 'checkbox',
3046
      '#title' => 'Show Layer Switcher',
3047
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3048
      '#description' => 'The Layer Switcher control displays a table of contents
3049
      for the map.  This allows the user interface to switch between
3050
      base layers and to show or hide overlays.  By default the switcher is
3051
      shown minimized on the right edge of the map, the user may expand it
3052
      by clicking on the handle.',
3053
  );
3054

    
3055
  if (!$open_layers_is_enabled) {
3056
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3057
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3058
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3059
  }
3060

    
3061
  // The default layer must always be enabled
3062
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3063
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3064

    
3065
  $baselayer_options = array(
3066
    /*
3067
   NOTICE: must correspond to the layers defined in
3068
   js/openlayers_,ap.js#getLayersByName()
3069
   */
3070
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3071
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3072
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3073
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3074
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3075
    // all others EPSG:900913
3076
    'mapnik' => 'OpenStreetMap (mapnik)',
3077
    'stamen_terrain' => 'Stamen Terrain',
3078
    'open_topomap' => 'OpenTopoMap',
3079
    // map quest is no longer free. it is required to sign up for a test plan.
3080
    // 'mapquest_open' => "MapQuest",
3081
    // 'mapquest_sat' => "MapQuest Sattelite",
3082
    'groadmap' => 'Google Roadmap',
3083
    'gsatellite' => 'Google Satellite',
3084
    'ghybrid' => 'Google Hybrid',
3085
    'gterrain' => 'Google Terrain',
3086
//     'veroad' => 'Virtual Earth Roads',
3087
//     'veaer' => 'Virtual Earth Aerial',
3088
//     'vehyb' => 'Virtual Earth Hybrid',
3089
    // 'yahoo' => 'Yahoo Street',
3090
    // 'yahoosat' => 'Yahoo Satellite',
3091
    // 'yahoohyb' => 'Yahoo Hybrid',
3092
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3093
  );
3094

    
3095
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3096
    '#type' => 'checkboxes_preferred',
3097
    '#title' => 'Base Layers',
3098
    '#options' => $baselayer_options,
3099
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3100
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3101
  );
3102

    
3103
  $google_maps_api_key = null;
3104
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3105
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3106
  }
3107
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3108
    '#type' => 'textfield',
3109
    '#title' => 'Google Maps API Key',
3110
    '#default_value' => $google_maps_api_key,
3111
    '#description' => 'In order to use any of the Google map layers you need to provide 
3112
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3113
  );
3114

    
3115
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3116
    $map_distribution['openlayers']['custom_wms_base_layer'],
3117
    'Custom WMS base layer',
3118
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3119
    true // add projection settings
3120
    );
3121

    
3122
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3123
    $map_distribution['openlayers']['wms_overlay_layer'],
3124
    'WMS overlay layer',
3125
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3126
                You can actually combine multiple layers for this overlay. 
3127
                For details please refer to the wms query parameter <code>Layers</code> .'
3128
  );
3129

    
3130
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3131
    '#type' => 'checkbox',
3132
    '#title' => 'Enable overlay layer',
3133
    '#weight' => -100,
3134
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3135
  );
3136

    
3137
  /*
3138
   * Map Legend
3139
   */
3140
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3141
    '#type' => 'fieldset',
3142
    '#title' => 'Map legend',
3143
    '#tree' => TRUE,
3144
    '#collapsible' => TRUE,
3145
    '#collapsed' => TRUE,
3146
    '#description' => 'Configure the maps legend.',
3147
  );
3148

    
3149
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3150
    '#type' => 'checkbox',
3151
    '#title' => 'Display a map legend',
3152
    '#default_value' => $map_distribution['legend']['show'],
3153
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3154
  );
3155

    
3156
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3157
    '#type' => 'textfield',
3158
    '#title' => 'Legend opacity',
3159
    '#default_value' => $map_distribution['legend']['opacity'],
3160
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3161
                         to 0.0 will be not much visible.',
3162
  );
3163

    
3164
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3165
    '#type' => 'textfield',
3166
    '#title' => 'Font size',
3167
    '#default_value' => $map_distribution['legend']['font_size'],
3168
    '#description' => 'Font size in pixels.',
3169
  );
3170

    
3171
  $fontStyles = array(
3172
    0 => "plane",
3173
    1 => "italic",
3174
  );
3175
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3176
    '#type' => 'select',
3177
    '#title' => 'Available font styles',
3178
    '#default_value' => $map_distribution['legend']['font_style'],
3179
    '#options' => $fontStyles,
3180
    '#description' => 'Select a font style for the map legend.',
3181
  );
3182

    
3183
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3184
    '#type' => 'textfield',
3185
    '#title' => 'Icon width',
3186
    '#default_value' => $map_distribution['legend']['icon_width'],
3187
    '#description' => 'Legend icon width in pixels.',
3188
  );
3189
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3190
    '#type' => 'textfield',
3191
    '#title' => 'Icon height',
3192
    '#default_value' => $map_distribution['legend']['icon_height'],
3193
    '#description' => 'Legend icon height in pixels.',
3194
  );
3195

    
3196
  // @WA: D7 form api does not support reset buttons,
3197
  // so to mimic the D5 reset button we add one like this.
3198
  $form['actions']['reset'] = array(
3199
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3200
    '#weight' => 1000,
3201
  );
3202

    
3203
  return system_settings_form($form);
3204
}
3205

    
3206
/**
3207
 * @param $default_settings
3208
 * @param $title
3209
 * @param $description
3210
 * @param bool $add_projection_settings
3211
 * @return array
3212
 */
3213
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3214
{
3215
  $form_elements = array(
3216
    '#type' => 'fieldset',
3217
    '#title' => $title,
3218
    '#tree' => TRUE,
3219
    '#collapsible' => FALSE,
3220
    '#collapsed' => FALSE,
3221
    '#description' => $description,
3222
  );
3223

    
3224
  $form_elements['name'] = array(
3225
    '#type' => 'textfield',
3226
    '#title' => 'Layer name',
3227
    '#default_value' => $default_settings['name'],
3228
    '#description' => 'A arbitrary name for the layer.',
3229
  );
3230
  $form_elements['url'] = array(
3231
    '#type' => 'textfield',
3232
    '#title' => 'WMS url',
3233
    '#default_value' => $default_settings['url'],
3234
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3235
  );
3236
  $form_elements['untiled'] = array(
3237
    '#type' => 'checkbox',
3238
    '#title' => 'Untiled',
3239
    '#default_value' => $default_settings['untiled'],
3240
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3241
  );
3242
  $form_elements['params'] = array(
3243
    '#type' => 'textarea',
3244
    '#title' => 'WMS parameters',
3245
    '#element_validate' => array('form_element_validate_json'),
3246
    '#default_value' => $default_settings['params'],
3247
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3248
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3249
      . '), entered in valid JSON. For example:
3250
<pre> {
3251
  "Layers": "topp:em_tiny_jan2003",
3252
  "Format": "image/png",
3253
  "BGCOLOR": "0xe0faff"
3254
}
3255
</pre>
3256
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3257
  );
3258

    
3259
  if($add_projection_settings){
3260

    
3261
    $form_elements['projection'] = array(
3262
      '#type' => 'textfield',
3263
      '#title' => 'Projection',
3264
      '#default_value' => $default_settings['projection'],
3265
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3266
    );
3267
    $form_elements['proj4js_def'] = array(
3268
      '#type' => 'textfield',
3269
      '#maxlength' => 256,
3270
      '#title' => 'proj4js definition',
3271
      '#default_value' => $default_settings['proj4js_def'],
3272
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3273
              The definitions for
3274
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3275
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3276
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3277
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3278
              choose to display the proj4js definition string.
3279
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3280
              <pre>
3281
  +a         Semimajor radius of the ellipsoid axis
3282
  +alpha     ? Used with Oblique Mercator and possibly a few others
3283
  +axis      Axis orientation (new in 4.8.0)
3284
  +b         Semiminor radius of the ellipsoid axis
3285
  +datum     Datum name (see `proj -ld`)
3286
  +ellps     Ellipsoid name (see `proj -le`)
3287
  +k         Scaling factor (old name)
3288
  +k_0       Scaling factor (new name)
3289
  +lat_0     Latitude of origin
3290
  +lat_1     Latitude of first standard parallel
3291
  +lat_2     Latitude of second standard parallel
3292
  +lat_ts    Latitude of true scale
3293
  +lon_0     Central meridian
3294
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3295
  +lon_wrap  Center longitude to use for wrapping (see below)
3296
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3297
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3298
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3299
  +pm        Alternate prime meridian (typically a city name, see below)
3300
  +proj      Projection name (see `proj -l`)
3301
  +south     Denotes southern hemisphere UTM zone
3302
  +to_meter  Multiplier to convert map units to 1.0m
3303
  +towgs84   3 or 7 term datum transform parameters (see below)
3304
  +units     meters, US survey feet, etc.
3305
  +vto_meter vertical conversion to meters.
3306
  +vunits    vertical units.
3307
  +x_0       False easting
3308
  +y_0       False northing
3309
  +zone      UTM zone
3310
              </pre>
3311
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3312
    );
3313
    $form_elements['max_extent'] = array(
3314
      '#type' => 'textfield',
3315
      '#title' => 'Maximum extent',
3316
      '#default_value' => $default_settings['max_extent'],
3317
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3318
    );
3319
    $form_elements['units'] = array(
3320
      '#type' => 'textfield',
3321
      '#title' => 'Units',
3322
      '#default_value' => $default_settings['units'],
3323
      '#description' => 'The layer map units.  Defaults to null.  Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’.  Normally taken from the projection.  Only required if both map and layers do not define a projection, or if they define a projection which does not define units.'
3324
    );
3325

    
3326
  }
3327
  return $form_elements;
3328
}
3329

    
3330

    
3331
/**
3332
 * @return array
3333
 *   The form structure.
3334
 */
3335
function cdm_settings_cache() {
3336

    
3337
  $form = array();
3338

    
3339
  $form['cache_settings'] = array(
3340
    '#type' => 'fieldset',
3341
    '#title' => t('Cache Settings'),
3342
    '#collapsible' => FALSE,
3343
    '#collapsed' => FALSE,
3344
    '#description' => t('<p>When caching is enabled all single taxon sites are
3345
      stored in an internal drupal cache doing the portal response of taxa pages
3346
      faster. This is possible because the sites are loaded from the cache and
3347
      are not created from scratch.</p>'),
3348
  );
3349

    
3350
  $form['cache_settings']['cdm_webservice_cache'] = array(
3351
    '#type' => 'checkbox',
3352
    '#title' => t('<strong>Enable caching</strong>'),
3353
    '#options' => cdm_help_general_cache(),
3354
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3355
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3356
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3357
       application the changes will be not visible till the cache is erased.
3358
       Therefore developers should deactived this feature when they are working
3359
       on the CDM Dataportal Module.</p>'),
3360
  );
3361

    
3362
  $form['cache_settings']['cdm_run_cache'] = array(
3363
    '#markup' => cdm_view_cache_site(),
3364
  );
3365

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

    
3375
/**
3376
 * Walk and cache all taxon pages.
3377
 */
3378
function cdm_view_cache_site() {
3379

    
3380
  $out = '';
3381

    
3382
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3383

    
3384
  $request_params = array();
3385
  $request_params['class'] = "Taxon";
3386

    
3387
  $cdm_ws_page_taxa_url = cdm_compose_ws_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3388
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3389
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3390

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

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

    
3400
  // Comment @WA: A form within a form is not valid html and not needed here.
3401
  // Also, it would be recommended just to include this part of the form in the
3402
  // rest of the form array in cdm_settings_cache().
3403
  // $out .= '<form id="cache_site">';
3404
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3405
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3406
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3407
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3408
  // $out .= '</form>';
3409
  $out .= '</div>';
3410
  /*
3411
  foreach($taxonPager->records as $taxon){
3412
    cdm_dataportal_taxon_view($uuid);
3413
  }
3414
  */
3415
  return $out;
3416
}
3417

    
3418

    
3419
function cdm_settings_layout_taxon_submit($form, &$form_state){
3420
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3421
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3422
    if(is_object($file)){
3423
      $file->status = FILE_STATUS_PERMANENT;
3424
      file_save($file);
3425
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3426
    }
3427
  }
3428
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3429
  $tab_lables_modified = serialize(get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT)) != serialize($form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3430
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3431
  if($tab_lables_modified || $tabs_enabled_modified){
3432
    // we first need to set the variable to persist the changes setting
3433
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3434
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3435
    menu_rebuild();
3436
  }
3437
}
3438

    
3439
function cdm_settings_layout_search_submit($form, &$form_state){
3440
  // the visibility of media thumbnails also affects the ui of the search results
3441
  // so reset the according session variable
3442
  //    1. in order to give the user immediate
3443
  //       feedback on potential setting changes
3444
  //    2. let refresh the default if it has changed
3445
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3446
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3447
  }
3448
}
3449

    
3450
/**
3451
 * Form validation handler for cdm_settings_general
3452
 *
3453
 * @param $form
3454
 * @param $form_state
3455
 */
3456
function cdm_settings_general_validate($form, &$form_state) {
3457

    
3458
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3459
    $form_state['values']['cdm_webservice_url'] .= '/';
3460
  }
3461

    
3462
}
3463

    
3464
/**
3465
 * Form submit handler for settings general.
3466
 *
3467
 * tasks performed:
3468
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3469
 *
3470
 * @param $form
3471
 * @param $form_state
3472
 */
3473
function cdm_settings_general_submit($form, &$form_state){
3474
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3475
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3476
  unset($_SESSION['cdm_login']);
3477
}
3478

    
3479
/**
3480
 * Form validation handler for cdm_settings_cache
3481
 */
3482
function cdm_settings_cache_validate($form, &$form_state) {
3483
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3484
    cache_clear_all(NULL, 'cache_cdm_ws');
3485
    // Better clear secref_cache since I can not be sure if the cache has not
3486
    // be used during this response.
3487
    cdm_api_secref_cache_clear();
3488
  }
3489

    
3490
}
3491

    
3492
/**
3493
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3494
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3495
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3496
 *  - version: the version, e.g.: v1.1
3497
 *
3498
 * @return array
3499
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3500
 */
3501
function get_edit_map_service_settings() {
3502

    
3503
  $settings = variable_get('edit_map_server', array(
3504
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3505
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3506
      )
3507
  );
3508

    
3509
  return $settings;
3510
}
3511

    
3512
/**
3513
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3514
 *
3515
 * @return string
3516
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3517
 */
3518
function get_edit_map_service_full_uri() {
3519
  $settings = get_edit_map_service_settings();
3520
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3521
}
3522

    
3523

    
3524
/**
3525
 * Returns the version number of the currently selected edit mapserver as a float
3526
 *
3527
 * @return float
3528
 *   The version number of the currently selected edit mapserver as a float.
3529
 *   Returns 0 on error.
3530
 */
3531
function get_edit_map_service_version_number() {
3532

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

    
3535
  $settings = get_edit_map_service_settings();
3536
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3537
  if (isset($matches[1])) {
3538
    // Convert string to float.
3539
    $version = 1 + $matches[1][0] - 1;
3540
    return $version;
3541
  }
3542
  else {
3543
    // Report error.
3544
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3545
        array(
3546
          '!version' => $settings['version'],
3547
          'warning')
3548
        )
3549
      );
3550
    return 0;
3551
  }
3552
}
3553

    
3554
/**
3555
 * Returns the array of selected items in a options array
3556
 *
3557
 * @param array $options
3558
 *   An options array as generated by a form element like checkoxes, select ...,
3559
 */
3560
function get_selection($options) {
3561
  $selection = array();
3562
  foreach ($options as $key=>$val) {
3563
    if (!empty($val)) {
3564
      $selection[] = $val;
3565
    }
3566
  }
3567
  return $selection;
3568
}
3569

    
3570

    
3571
/**
3572
 * Implements hook_element_info().
3573
 *
3574
 * Allows modules to declare their own Form API element types and specify their default values.
3575
 *
3576
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3577
 */
3578
function cdm_dataportal_element_info() {
3579
  $type['checkboxes_preferred'] = array(
3580
    '#input' => TRUE,
3581
    '#process' => array('checkboxes_preferred_expand'),
3582
    '#after_build' => array('checkboxes_preferred_after_build'),
3583
    '#theme' => array('checkboxes_preferred'),
3584
    // '#theme_wrapper' => array('form_element'),
3585
  );
3586
  return $type;
3587
}
3588

    
3589
/**
3590
 * #process callback function for the custom form element type 'checkbox_preferred'
3591
 *
3592
 *
3593
 */
3594
function checkboxes_preferred_expand($element, &$form_state, $form) {
3595

    
3596
  // First of all create checkboxes for each of the elements
3597
  $element = form_process_checkboxes($element);
3598

    
3599
  // compose the element name
3600
  $parents = array();
3601
  array_deep_copy($element['#parents'], $parents);
3602
  $parents[count($parents) -1 ] .= '_preferred';
3603
  $element_name = $parents[0];
3604
  for ($i=1; $i < count($parents); $i++){
3605
    $element_name .= '[' . $parents[$i] . ']';
3606
  }
3607

    
3608
  $children = element_children($element);
3609

    
3610
  $element['table_start'] = array(
3611
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3612
    '#weight' => -1,
3613
  );
3614

    
3615
  // prepare first part each of the table rows which contains the row label
3616
  $weight = 0;
3617
  foreach ($children as $key) {
3618
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3619
    $element[$key]['#weight'] = $weight;
3620
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3621
    $element[$key]['#suffix'] = '</td>';
3622
    unset($element[$key]['#title']);
3623
    $weight += 2;
3624
  }
3625
  $weight = 0;
3626

    
3627
  // add a radio button to each of the checkboxes, the
3628
  // check boxes have already been created at the beginning
3629
  // of this function
3630
  if (count($element['#options']) > 0) {
3631
    foreach ($element['#options'] as $key => $choice) {
3632
      if (!isset($element[$key . '_preferred'])) {
3633
        $element[$key . '_preferred'] = array(
3634
          '#type' => 'radio',
3635
          '#name' => $element_name,
3636
          '#return_value' => check_plain($key),
3637
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3638
          '#attributes' => $element['#attributes'],
3639
          '#parents' => $element['#parents'],
3640
          // '#spawned' => TRUE,
3641
          '#weight' => $weight + 1,
3642
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3643
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3644
        );
3645
      }
3646
      $weight += 2;
3647
    }
3648
  }
3649

    
3650
  // end the table
3651
  $element['table_end'] = array(
3652
    '#markup' => '</table>',
3653
    '#weight' => $weight++,
3654
  );
3655

    
3656
  return $element;
3657
}
3658

    
3659
/**
3660
 * Theme function for the custom form field 'checkboxes_preferred'.
3661
 */
3662
function theme_checkboxes_preferred($variables) {
3663
  $element = $variables['element'];
3664
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3665
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3666
  $out .= drupal_render_children($element);
3667
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3668
  $out .= '</div>';
3669
  return $out;
3670
}
3671

    
3672
/**
3673
 * Callback for checkboxes preferred for widget which will
3674
 * be called after the form or element is built. The call
3675
 * back is configured in the form element by setting it as
3676
 * #after_build parameter.
3677
 *
3678
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3679
 *
3680
 * @param $element
3681
 *   Nested array of form elements that comprise the form.
3682
 * @param $form_state
3683
 *   A keyed array containing the current state of the form.
3684
 *   This includes the current persistent storage data for the form.
3685
 *   Additional information, like the sanitized $_POST data,
3686
 *   is also accumulated here in $form_state['input']
3687
 *
3688
 * @return the modified form array
3689
 */
3690
function checkboxes_preferred_after_build($element, &$form_state) {
3691

    
3692
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3693

    
3694
  if ($_POST && count($_POST) > 0) {
3695
    // TODO use  $form_state['input'] instead of POST !!!
3696
    // First pass of form processing.
3697
    $parents = array();
3698
    array_deep_copy($element['#parents'], $parents);
3699
    $parents[count($parents) - 1] .= '_preferred';
3700
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3701
    $element['#value']['PREFERRED'] = $preferred_layer;
3702
//     $form_state[$parent_id] = $element['#value'];
3703
//     $form_state['values']['baselayers'] = $element['#value'];
3704
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3705
    $form_state_element_values = $element['#value'];
3706
  }
3707
  else {
3708
    // Second pass of form processing.
3709
    $preferred_layer = $element['#value']['PREFERRED'];
3710
  }
3711

    
3712
  // Also set the chosen value (not sure if this is good Drupal style ....).
3713
  foreach ($children = element_children($element) as $key) {
3714
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3715
      $element[$key]['#value'] = $preferred_layer;
3716
    }
3717
  }
3718
  // The default layer must always be enabled.
3719
  $element[$preferred_layer]['#value'] = $preferred_layer;
3720

    
3721
  return $element;
3722
}
3723

    
3724
function radios_prepare_options_suffix(&$elements){
3725

    
3726
  $childrenKeys = element_children($elements);
3727
  foreach($childrenKeys as $key){
3728
    if(!is_array($elements[$key]['#theme_wrappers'])){
3729
      $elements[$key]['#theme_wrappers'] = array();
3730
    }
3731
    if(isset($elements['#options_suffixes'][$key])){
3732
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3733
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3734
    }
3735
  }
3736
  return $elements;
3737

    
3738
}
3739

    
3740
/**
3741
 * TODO
3742
 * @param unknown $variables
3743
 */
3744
function theme_radio_options_suffix($variables) {
3745
  $element = $variables['element'];
3746
  if(isset($element['#options_suffix'])) {
3747
    $element['#children'] .= $element['#options_suffix'];
3748
  }
3749
  return $element['#children'];
3750
}
3751

    
3752

    
3753
/**
3754
 * Element validate callback for text field and arrays containing json.
3755
 *
3756
 * @param $element
3757
 *   The form element to validate
3758
 * @param $form_state
3759
 *   A keyed array containing the current state of the form.
3760
 * @param $form
3761
 *   Nested array of form elements that comprise the form.
3762
 */
3763
function form_element_validate_json($element, &$form_state, $form) {
3764
   if (!empty($element['#value'])) {
3765
     json_decode($element['#value']);
3766
     if(json_last_error() != JSON_ERROR_NONE){
3767
       form_error($element,
3768
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3769
         . l('JSONLint', 'http://jsonlint.com/')
3770
       );
3771
     }
3772
   }
3773
}
3774

    
3775
/**
3776
 * Form submission handler for textareas and textfields containing JSON.
3777
 *
3778
 * The contained JSON will be converted into an php array
3779
 * or object and will be stored in the variables as such.
3780
 *
3781
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3782
 *
3783
 * @param $form
3784
 *   Nested array of form elements that comprise the form.
3785
 * @param $form_state
3786
 *   A keyed array containing the current state of the form.
3787
 *
3788
 */
3789
function submit_json_as_php_array($form, &$form_state) {
3790
  if (is_array($form['#json_elements'])) {
3791
    foreach ($form['#json_elements'] as $element){
3792
      if (trim($form_state['values'][$element])) {
3793
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3794
      } else {
3795
        $form_state['values'][$element] = NULL;
3796
      }
3797
    }
3798
  }
3799
}
(18-18/18)