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
      )
110
    )
111
  );
112
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
113
  /**
114
   * @var array of versions eg. "v1.2"
115
   *   An options array
116
   */
117
  define('EDIT_MAPSERVER_VERSION', serialize(
118
      array(
119
//        'v1' => 'v1' ,           // no longer recommended
120
//        'v1.1' => 'v1.1',        // no longer recommended
121
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
122
        'v1.2' => 'v1.2',
123
        'v1.3_dev' => 'v1.3_dev (not recommended)',
124
        'v1.4_dev' => 'v1.4_dev (latest features)'
125
      )
126
    )
127
  );
128
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
129
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
130

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

    
146

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

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

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

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

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

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

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

    
204

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

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

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

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

    
233
}
234

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
585
  // ---- DEFAULTS settings
586

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

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

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

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

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

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

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

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

    
789
  // ---- END of DEFAULTS
790

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

    
793
  $feature_block_setting = null;
794

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

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

    
815
  return $feature_block_setting;
816
}
817

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

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

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

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

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

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

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

    
942
}
943

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1088
  $form['sub_tree_filter'] = array(
1089
    '#type' => 'fieldset',
1090
    '#title' => t('Subtree filter'),
1091
    '#collapsible' => FALSE,
1092
    '#collapsed' => TRUE,
1093
    '#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.'),
1094
  );
1095

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1307

    
1308

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

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

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

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

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

    
1357
  return system_settings_form($form);
1358
}
1359

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

    
1370

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

    
1379
  $form = array();
1380

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

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

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

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

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

    
1425

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

    
1435
  $bibliography_settings = get_bibliography_settings(true);
1436

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

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

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

    
1473
  // --- Name page autoredirect feature --- //
1474
  $form['name_page'] = array(
1475
    '#type' => 'fieldset',
1476
    '#title' => t('Name page'),
1477
    '#collapsible' => FALSE,
1478
    '#collapsed' => FALSE,
1479
  );
1480
  $form['name_page'][CDM_NAME_PAGE_AUTOREDIRECT] = array(
1481
    '#type' => 'checkbox',
1482
    '#title' => 'Always redirect to taxon',
1483
    '#default_value' => variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0),
1484
    '#description' => t('By checking this option you can globally enable the redirection behavior of the name page. 
1485
    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. 
1486
    This option allows to enable this behavior also for contexts in which the redirection normally is not active.'),
1487
  );
1488

    
1489
  // --- Registrations --- //
1490
  $form['registrations'] = array(
1491
    '#type' => 'fieldset',
1492
    '#title' => t('Registrations'),
1493
    '#collapsible' => FALSE,
1494
    '#collapsed' => FALSE,
1495
  );
1496
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1497
    '#type' => 'checkbox',
1498
    '#title' => t('Use the persistent http identifier as link'),
1499
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1500
    '#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.'),
1501
  );
1502

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

    
1514
  $nameRenderConfiguration = new NameRenderConfiguration();
1515

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

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

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

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

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

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

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

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

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

    
1670

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

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

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

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

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

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

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

    
1749
  return $form;
1750
}
1751

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

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

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

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

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

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

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

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

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

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

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

    
1870
  // ---- PROFILE PICTURE ----//
1871

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

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

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

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

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

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

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

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

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

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

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

    
1975
  // -- MEDIA THUMBNAILS -- //
1976
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1977
  $form_title = 'Taxon Profile Images';
1978
  $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>';
1979
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1980

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

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

    
2030

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

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

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

    
2078

    
2079
    $feature_list_layout_settings_disabled = FALSE;
2080

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2215

    
2216

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

    
2235
  );
2236

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

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

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

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

    
2263

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

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

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

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

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

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

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

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

    
2366

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

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

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

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

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

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

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

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

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

    
2445
  $name_relationship_type_options = cdm_vocabulary_as_option(
2446
      UUID_NAME_RELATIONSHIP_TYPE,
2447
      '_cdm_relationship_type_term_label_callback',
2448
      false,
2449
      array('uuid' => '/' .UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM . '|'
2450
        . UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM . '|'
2451
        . UUID_NAMERELATIONSHIPTYPE_CONSERVED_AGAINST . '|'
2452
        . UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR . '|'
2453
        . UUID_NAMERELATIONSHIPTYPE_MISSPELLING . '|'
2454
        . UUID_NAMERELATIONSHIPTYPE_ORTHOGRAPHIC_VARIANT . '/' )
2455
  );
2456
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_INLINE_TYPES] = array(
2457
    '#type' => 'checkboxes',
2458
    '#title' => t('Name relationship types') . ':',
2459
    '#description' => 'This setting only affects specific types of name relations which are displayed appended to scientific name. 
2460
    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') . '.',
2461
    '#options' => $name_relationship_type_options,
2462
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_INLINE_TYPES, unserialize(CDM_NAME_RELATIONSHIP_INLINE_TYPES_DEFAULT)),
2463
  );
2464

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

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

    
2477

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

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

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

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

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

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

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

    
2568
  $form = array();
2569

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2687

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

    
2695
  $form = array();
2696

    
2697

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

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

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

    
2725
  );
2726

    
2727
  return system_settings_form($form);
2728
}
2729

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

    
2736
  $form = array();
2737

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

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

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

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

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

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

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

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

    
2810

    
2811
  $form = array();
2812

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

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

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

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

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

    
2869
  /*
2870
   * MAP SETTINGS
2871
   */
2872

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

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

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

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

    
2918
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2919
    '#type' => 'textfield',
2920
    '#title' => 'Bounding box',
2921
    '#default_value' => $map_distribution['bbox'],
2922
    '#description' =>
2923
      '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. 
2924
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
2925
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
2926
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2927
      <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.
2928
      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
2929
      below the map from where you can copy the bbox string.</p>',
2930
  );
2931

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

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

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

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

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

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

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

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

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

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

    
3021

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

    
3032

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

    
3042

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3202
  return system_settings_form($form);
3203
}
3204

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

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

    
3258
  if($add_projection_settings){
3259

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

    
3325
  }
3326
  return $form_elements;
3327
}
3328

    
3329

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

    
3336
  $form = array();
3337

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

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

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

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

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

    
3379
  $out = '';
3380

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

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

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

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

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

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

    
3417

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

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

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

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

    
3461
}
3462

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

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

    
3489
}
3490

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

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

    
3508
  return $settings;
3509
}
3510

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

    
3522

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

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

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

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

    
3569

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

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

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

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

    
3607
  $children = element_children($element);
3608

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

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

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

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

    
3655
  return $element;
3656
}
3657

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

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

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

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

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

    
3720
  return $element;
3721
}
3722

    
3723
function radios_prepare_options_suffix(&$elements){
3724

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

    
3737
}
3738

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

    
3751

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

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