Project

General

Profile

Download (159 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
 const CDM_SPECIMEN_DERIVATE_TREE_OPTIONS = 'cdm_specimen_derivate_tree_options';
48
 const CDM_SPECIMEN_DERIVATE_TREE_OPTIONS_DEFAULT = ['field_unit_short_label' => 0];
49
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
50
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
51
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
52
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
53
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
54
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
55
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
56

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

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

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

    
73
  const ANNOTATION_TYPES_VISIBLE = 'annotations_types_as_footnotes';
74
  define('ANNOTATION_TYPES_VISIBLE_DEFAULT', serialize($annotationTypeKeys));
75

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

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

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

    
102

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

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

    
148

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

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

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

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

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

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

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

    
206

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

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

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

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

    
235
}
236

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

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

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

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

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

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

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

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

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

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

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

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

    
363
/**
364
 * Constant for the drupal variable key distribution_map_visibility
365
 *
366
 * possible values:
367
 *  - never
368
 *  - automatic
369
 *  - always
370
 */
371
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
372
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
373

    
374
/**
375
 * Constant for the drupal variable key specimen_map_visibility
376
 *
377
 * possible values:
378
 *  - never
379
 *  - automatic
380
 *  - always
381
 */
382
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
383
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
384

    
385
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
386
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
387
    array(
388
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
389
        'includeOccurrences' => 0,
390
        'includeTaxonNameDescriptions' => 0
391
     )
392
  ));
393

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

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

    
469
    // unserialize if nessecary
470
    if(!is_array($default)){
471
      $default = unserialize($default);
472
    }
473
    $variable = variable_get($variable_name, array());
474
    $result = drupal_array_merge_deep($default, $variable);
475
    return $result;
476
}
477

    
478
/**
479
 * @todo document this function.
480
 */
481
function getGallerySettings($gallery_config_form_name) {
482
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
483
}
484

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

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

    
510
  // Return the index value or the string representation.
511
  if ($returnTabIndex) {
512
    return $index_value;
513
  }
514
  else {
515
    return ($values[$index_value]);
516
  }
517
}
518

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

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

    
590
  // ---- DEFAULTS settings
591

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

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

    
663
  // ---- Special DEFAULTS for existing portals
664
  // TODO:
665
  // this can be removed once the feature block
666
  // settings have been deployed for the first time to these portals
667

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

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

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

    
768
  $default_theme = variable_get('theme_default', NULL);
769

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

    
794
  // ---- END of DEFAULTS
795

    
796
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
797

    
798
  $feature_block_setting = null;
799

    
800
  if (isset($saved_settings[$feature_uuid])) {
801
    $feature_block_setting = $saved_settings[$feature_uuid];
802
  }
803
  else if (isset($settings_for_theme[$feature_uuid])) {
804
    $feature_block_setting = $settings_for_theme[$feature_uuid];
805
  }
806
  else if (isset($settings_for_theme['DEFAULT'])) {
807
    $feature_block_setting = $settings_for_theme['DEFAULT'];
808
  }
809

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

    
820
  return $feature_block_setting;
821
}
822

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

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

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

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

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

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

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

    
947
}
948

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

    
967
/**
968
 * Configures the settings form for the CDM-API module.
969
 *
970
 * @return array
971
 *   Drupal settings form.
972
 */
973
function cdm_settings_general() {
974

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

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

    
993
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
994
    '#type' => 'markup',
995
    '#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')
996
      . ' visible only for administrators',
997
  );
998

    
999
  $form['cdm_webservice']['freetext_index'] = array(
1000
    '#type' => 'fieldset',
1001
    '#title' => t('Freetext index'),
1002
    '#collapsible' => FALSE,
1003
    '#collapsed' => FALSE,
1004
  );
1005

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

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

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

    
1059
  $form['cdm_webservice']['proxy'] = array(
1060
    '#type' => 'fieldset',
1061
    '#title' => t('Proxy'),
1062
    '#collapsible' => TRUE,
1063
    '#collapsed' => TRUE,
1064
  );
1065

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

    
1075
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1076
    '#type' => 'textfield',
1077
    '#title' => t('Proxy port') . ':',
1078
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1079
  );
1080

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

    
1087
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1088
    '#type' => 'textfield',
1089
    '#title' => t('Password') . ':',
1090
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1091
  );
1092

    
1093
  $form['sub_tree_filter'] = array(
1094
    '#type' => 'fieldset',
1095
    '#title' => t('Subtree filter'),
1096
    '#collapsible' => FALSE,
1097
    '#collapsed' => TRUE,
1098
    '#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.'),
1099
  );
1100

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1278
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1279
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1280

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

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

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

    
1312

    
1313

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

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

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

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

    
1360
  $form['#submit'][] = 'cdm_settings_general_submit';
1361

    
1362
  return system_settings_form($form);
1363
}
1364

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

    
1375

    
1376
/**
1377
 * LAYOUT settings
1378
 *
1379
 * @return array
1380
 *   The form structure.
1381
 */
1382
function cdm_settings_layout() {
1383

    
1384
  $form = array();
1385

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

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

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

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

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

    
1430

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

    
1440
  $bibliography_settings = get_bibliography_settings(true);
1441

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

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

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

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

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

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

    
1519
  $nameRenderConfiguration = new NameRenderConfiguration();
1520

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

    
1540
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1541
    . $which_version_message
1542
    . '</div>'
1543
    . $diff_viewer_markup;
1544

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

    
1597
  $nameRenderTemplateConfStatus = $nameRenderConfiguration->nameRenderTemplateConfigurationStatus();
1598

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

    
1617
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1618
    . $which_version_message
1619
    . '</div>'
1620
    . $diff_viewer_markup;
1621

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

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

    
1669
  $form['#submit'] = array('submit_json_as_php_array');
1670
  // #json_elements especially defined for submit_json_as_php_array()
1671
  $form['#json_elements'] = array(NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES, NameRenderConfiguration::CDM_PART_DEFINITIONS);
1672
  return system_settings_form($form);
1673
}
1674

    
1675

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

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

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

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

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

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

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

    
1754
  return $form;
1755
}
1756

    
1757
/**
1758
 * @return array
1759
 *   The form structure.
1760
 */
1761
function cdm_settings_layout_taxon() {
1762
  $collapsed = FALSE;
1763
  $form = array();
1764

    
1765
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1766

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

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

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

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

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

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

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

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

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

    
1875
  // ---- PROFILE PICTURE ----//
1876

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

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

    
1891
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1892

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

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

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

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

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

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

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

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

    
1980
  // -- MEDIA THUMBNAILS -- //
1981
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1982
  $form_title = 'Taxon Profile Images';
1983
  $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>';
1984
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1985

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

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

    
2035

    
2036
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2037
  $profile_feature_tree = get_profile_feature_tree();
2038

    
2039
  if (isset($profile_feature_tree->root->childNodes)) {
2040

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

    
2083

    
2084
    $feature_list_layout_settings_disabled = FALSE;
2085

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

    
2093
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2094

    
2095
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2096

    
2097
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2098
        $subform_id = $featureNode->term->uuid;
2099
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2100

    
2101
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2102

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

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

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

    
2135
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2136
            '#type' => 'checkbox',
2137
            '#title' => 'Link to name used in source',
2138
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2139
          );
2140
        }
2141

    
2142
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2143
          '#type' => 'checkbox',
2144
          '#title' => 'Sources as content',
2145
          '#default_value' => $feature_block_setting['sources_as_content'],
2146
        );
2147

    
2148
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2149
          '#type' => 'checkbox',
2150
          '#title' => 'Put sources also as content to bibliography',
2151
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2152
        );
2153

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

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

    
2190
      }
2191
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2192
    }
2193
  }
2194

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

    
2220

    
2221

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

    
2240
  );
2241

    
2242
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2243

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

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

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

    
2268

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

    
2286
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2287
    '#type' => 'fieldset',
2288
    '#tree' => true,
2289
    '#title' => t('Distribution hierarchy style')
2290
  );
2291

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

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

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

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

    
2359
AbsenceTerm
2360
a	absent
2361
f	reported in error
2362
nf	native: reported in error
2363
if	introduced: reported in error
2364
cf	cultivated: reported in error
2365
ne	native: formerly native
2366
ie	introduced: formerly introduced
2367

    
2368
</pre>'),
2369
  );
2370

    
2371

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

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

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

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

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

    
2417
  $form['taxon_synonymy']['taxon_relations'] = array(
2418
    '#type' => 'fieldset',
2419
    '#title' => t('Taxon relationships'),
2420
    '#collapsible' => FALSE,
2421
    '#collapsed' => FALSE
2422
  );
2423

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

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

    
2443
  $form['taxon_synonymy']['name_relations'] = array(
2444
    '#type' => 'fieldset',
2445
    '#title' => t('Name relationships'),
2446
    '#collapsible' => FALSE,
2447
    '#collapsed' => FALSE
2448
  );
2449

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

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

    
2480
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2481

    
2482

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

    
2501
  $specimen_derivate_tree_options = get_array_variable_merged(CDM_SPECIMEN_DERIVATE_TREE_OPTIONS, CDM_SPECIMEN_DERIVATE_TREE_OPTIONS_DEFAULT);
2502
  $form['taxon_specimens'][CDM_SPECIMEN_DERIVATE_TREE_OPTIONS] = [
2503
    '#type' => 'fieldset',
2504
    '#tree' => TRUE,
2505
    '#title' => 'Derivate tree options',
2506
    '#collapsible' => FALSE,
2507
    '#collapsed' => FALSE,
2508
    '#description' => t('These setting only apply to the <i>Derivate tree</i> view mode (see above).'),
2509
  ];
2510

    
2511
  $form['taxon_specimens'][CDM_SPECIMEN_DERIVATE_TREE_OPTIONS]['field_unit_short_label'] = [
2512
    '#type' => 'checkbox',
2513
    '#title' => 'Field unit short label',
2514
    '#default_value' => $specimen_derivate_tree_options['field_unit_short_label'],
2515
    '#description' => t('Use the short collecting string for field units 
2516
    instead of the long summary label, which also includes location information.'),
2517
  ];
2518

    
2519
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2520
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2521
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2522
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2523
  }
2524
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2525
    '#type' => 'radios',
2526
    '#title' => t('Specimen description feature tree') . ':',
2527
    '#default_value' => $profile_feature_tree_uuid,
2528
    '#options' =>  $featureTrees['options'],
2529
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2530
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2531
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2532
    ),
2533
  );
2534

    
2535
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2536
  $form_title = t('Specimen media');
2537
  $form_description = t('Specimens may have media which is displayed at the
2538
     Specimen tab/section as a gallery. It is possible to configure the
2539
     thumbnails gallery here, however for configuring how a single media should
2540
     be displayed please go to !url.</p>',
2541
     array(
2542
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2543
     ));
2544
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2545

    
2546
  // --- MEDIA GALLERY ---- //
2547
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2548
  $form_title = 'Media gallery (tab)';
2549
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2550
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2551
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2552
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2553
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2554
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2555
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2556

    
2557
  // Comment @WA: D7 form api does not support reset buttons,
2558
  // so to mimic the D5 reset button we add one like this.
2559
  $form['actions']['reset'] = array(
2560
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2561
    '#weight' => 1000,
2562
  );
2563
  return system_settings_form($form);
2564
}
2565

    
2566
/**
2567
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2568
 *
2569
 * @param $map_id
2570
 * @param $form
2571
 * @return mixed
2572
 */
2573
function _cdm_map_visibility_setting($map_id)
2574
{
2575
  return array(
2576
    '#type' => 'select',
2577
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2578
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2579
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2580
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2581
        The map also can forced to show up <b>always</b> or <b>never</b>."
2582
  );
2583
}
2584

    
2585
/**
2586
 * @return array
2587
 *   The form structure.
2588
 */
2589
function cdm_settings_layout_search() {
2590

    
2591
  $form = array();
2592

    
2593
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2594

    
2595
  $form['search_settings'] = array(
2596
    '#type' => 'fieldset',
2597
    '#title' => t('Taxa Search'),
2598
    '#collapsible' => FALSE,
2599
    '#collapsed' => FALSE,
2600
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2601
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2602
         where they can write the text to be searched. You can find Drupal block configuration
2603
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2604
  );
2605

    
2606
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2607
      '#type' => 'checkbox',
2608
      '#title' => t('Ignore the chosen classification in simple search'),
2609
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2610
      '#description' => t('The simple search, which can be executed via the search block,
2611
          will by default search on the classification selected in the classification browser
2612
          selector. Set the tick if you want your portal to search on all classifications.'),
2613
  );
2614

    
2615
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2616
    '#type' => 'checkbox',
2617
    '#title' => t('Run simple search with free-text search backend.'),
2618
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2619
    '#description' => t('The simple search uses by default another search
2620
      backend as the advances search. By checking this option the simple search can be
2621
      configured to also use the free-text search backend.'),
2622
  );
2623

    
2624
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2625
    '#type' => 'checkbox',
2626
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2627
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2628
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2629
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2630
  );
2631

    
2632
  $form['search_settings'][CDM_SEARCH_RESULT_PAGE_SIZE] = array(
2633
    '#type' => 'textfield',
2634
    '#title' => t('Results per page') . ':',
2635
    '#default_value' => variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT),
2636
    '#description' => t('Number of results to display per page.'),
2637
  );
2638

    
2639
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2640
    '#type' => 'checkbox',
2641
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2642
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2643
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2644
  );
2645

    
2646
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2647
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2648
      '#type' => 'checkboxes',
2649
      '#title' => 'Search mode',
2650
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2651
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2652
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2653
          defaults set here.',
2654
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2655
      '#default_value' => $search_mode_default
2656
      );
2657

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

    
2663
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2664
  );
2665

    
2666
    $form['blast_search_settings'] = array(
2667
        '#type' => 'fieldset',
2668
        '#title' => t('Blast Search'),
2669
        '#collapsible' => TRUE,
2670
        '#collapsed' => TRUE,
2671
        '#description' => t('<p>To perform blast searchs
2672
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2673
         where they can write the text to be searched. You can find Drupal block configuration
2674
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p>
2675
         <p>To perform a blast search a blast database for the cdm instance is needed.</p> '),
2676
    );
2677

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

    
2683
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2684
    );
2685
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2686
        '#type' => 'textfield',
2687
        '#title' => t('Webservice URL for blast search') . ':',
2688
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2689

    
2690
        '#description' => t('Enter the webservice URL for blast search'),
2691
    );
2692

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

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

    
2710

    
2711
/**
2712
 * @return array
2713
 *   The form structure.
2714
 */
2715
function cdm_settings_layout_name_page()
2716
{
2717

    
2718
  $form = array();
2719

    
2720

    
2721
  $form['name_relations'] = array(
2722
    '#type' => 'fieldset',
2723
    '#title' => t('Name relationship listings'),
2724
    '#collapsible' => FALSE,
2725
    '#collapsed' => FALSE
2726
  );
2727

    
2728
  $name_relationship_type_options = cdm_vocabulary_as_option(
2729
    UUID_NAME_RELATIONSHIP_TYPE,
2730
    '_cdm_relationship_type_term_label_callback',
2731
    false
2732
  );
2733
  $form['name_relations'][CDM_NAME_RELATIONSHIP_LIST_TYPES] = array(
2734
    '#type' => 'checkboxes',
2735
    '#title' => t('Name relationship types') . ':',
2736
    '#description' => 'This setting only affects specific types of name relations which are displayed as list. Another representations 
2737
    is the inline style used in the synonymy which may show a different (reduced) set of name relations. 
2738
    The according settings can be adjusted in the ' . l('taxon page settings section synonmy', 'admin/config/cdm_dataportal/settings/layout/taxon') . '.',
2739
    '#options' => $name_relationship_type_options,
2740
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_LIST_TYPES, cdm_vocabulary_as_defaults(UUID_NAME_RELATIONSHIP_TYPE)),
2741
  );
2742

    
2743
  $form[CDM_NAME_PAGE_SECTION_TAXA] = array (
2744
    '#type' => 'checkbox',
2745
    '#title' => 'Show the associated taxa section',
2746
    '#default_value' => variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT)
2747

    
2748
  );
2749

    
2750
  return system_settings_form($form);
2751
}
2752

    
2753
/**
2754
 * @return array
2755
 *   The form structure.
2756
 */
2757
function cdm_settings_layout_media() {
2758

    
2759
  $form = array();
2760

    
2761
  $form['media_settings'] = array(
2762
    '#type' => 'fieldset',
2763
    '#title' => t('Media settings'),
2764
    '#collapsible' => FALSE,
2765
    '#collapsed' => FALSE,
2766
    '#description' => 'This section covers layout settings for media pages.'
2767
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2768
  );
2769

    
2770
  $form['media_settings'][CDM_MEDIA_GALLERY_VIEWER] = array(
2771
    '#type' => 'select',
2772
    '#title' => t('Image viewer') . ':',
2773
    '#default_value' => variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT),
2774
    '#options' => array(
2775
      CDM_MEDIA_GALLERY_VIEWER_DEFAULT => t('Universalviewer'),
2776
      'fsi' => t('FSI viewer (requires FSI server!)'),
2777
      'default' => t('Simple viewer'),
2778
    ),
2779
    '#description' => 'The <b>Universalviewer</b> is a feature rich image gallery and viewer which provides support
2780
            for mobile devices and thus is highly recommended over the other options.<br/>
2781
            <b>Simple viewer</b> combines a HTML gallery with a simple image viewer and only provides basic functionality 
2782
            and does not work well on mobile devices.<br />
2783
            <b>FSI Viewer</b> can only be used in conjunction with images served by an FSI server.'
2784
  );
2785

    
2786
  // --- STANDARD_IMAGE_VIEWER ---- //
2787
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT) == CDM_MEDIA_GALLERY_VIEWER_SIMPLE) {
2788
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2789
      '#type' => 'fieldset',
2790
      '#tree' => true,
2791
      '#title' => t('Standard image viewer settings'),
2792
      '#collapsible' => FALSE,
2793
      '#collapsed' => FALSE,
2794
      );
2795

    
2796
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2797
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2798
      '#type' => 'checkbox',
2799
      '#title' => 'Show media representations',
2800
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2801
    );
2802

    
2803
  }
2804
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, 'default') == CDM_MEDIA_GALLERY_VIEWER_DEFAULT) {
2805
    $form['media_settings'][CDM_ADDITIONAL_MEDIA_COPYRIGHT] = [
2806
      '#type' => 'textarea',
2807
      '#title' => 'Additional media copyright statement',
2808
      '#default_value' => variable_get(CDM_ADDITIONAL_MEDIA_COPYRIGHT, NULL),
2809
      '#description' => 'This statement will be shown below the <b>Universal imgage viewer only</b>'
2810
    ];
2811
  }
2812

    
2813
  // @WA: D7 form api does not support reset buttons,
2814
  // so to mimic the D5 reset button we add one like this.
2815
  $form['actions']['reset'] = array(
2816
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2817
    '#weight' => 1000,
2818
  );
2819
  return system_settings_form($form);
2820
}
2821

    
2822
/**
2823
 * GEOSERVICE and Map settings.
2824
 *
2825
 *  @return array
2826
 *   The form structure.
2827
 */
2828
function cdm_settings_geo($form, &$form_state) {
2829

    
2830
  $current_geoserver_settings = get_edit_map_service_settings();
2831
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2832

    
2833

    
2834
  $form = array();
2835

    
2836
  $dummy_distribution_query = NULL;
2837
  if($map_distribution['map_type'] != 1){
2838
    // we need to apply a dummy query since the map service requires for image maps
2839
    // at least as and ad to be defined
2840
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2841
  }
2842

    
2843
  $form['map_preview'] = array(
2844
      '#type' => 'fieldset',
2845
      '#tree' => FALSE,
2846
      '#title' => t('Map preview'),
2847
      '#collapsible' => FALSE,
2848
      '#description' => 'The preview of the map'
2849
       . ($dummy_distribution_query != null ?
2850
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2851
           '.<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.')
2852
  );
2853
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, NULL, $dummy_distribution_query, NULL, [
2854
    'move' => "this.cdmOpenlayersMap.printInfo",
2855
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2856
  ], TRUE // resizable
2857
  );
2858

    
2859
  /*
2860
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2861
  );
2862
  */
2863

    
2864
  /*
2865
   * GEO SERVER
2866
   */
2867
  $form['edit_map_server'] = array(
2868
    '#type' => 'fieldset',
2869
    '#tree' => true,
2870
    '#title' => t('EDIT map service'),
2871
    '#collapsible' => TRUE,
2872
    '#collapsed' => TRUE,
2873
    '#description' => t('Configuration and selection of your geo server.
2874
      The Geo Server is responsible for generating the maps.'),
2875
  );
2876

    
2877
  $form['edit_map_server']['base_uri'] = array(
2878
    '#type' => 'select',
2879
    '#title' => t('EDIT map service') . ':',
2880
    '#default_value' => $current_geoserver_settings['base_uri'],
2881
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2882
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2883
  );
2884
  $form['edit_map_server']['version'] = array(
2885
      '#type' => 'select',
2886
      '#title' => t('Version') . ':',
2887
      '#default_value' => $current_geoserver_settings['version'],
2888
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2889
      '#description' => t('The version of the EDIT map services'),
2890
  );
2891

    
2892
  /*
2893
   * MAP SETTINGS
2894
   */
2895

    
2896
  $form[CDM_MAP_DISTRIBUTION] = array(
2897
    '#type' => 'fieldset',
2898
    '#tree' => TRUE,
2899
    '#title' => t('Maps settings'),
2900
    '#collapsible' => TRUE,
2901
    '#collapsed' => TRUE,
2902
    '#description' => t('General configuration for all map types.'),
2903
  );
2904

    
2905
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2906
    '#type' => 'radios',
2907
    '#title' => 'Map types',
2908
    '#options' => array(
2909
      1 => "OpenLayers dynamic map viewer",
2910
      0 => "Plain image",
2911
    ),
2912
    '#default_value' => $map_distribution['map_type'],
2913
    '#description' => 'Two different map types are available :
2914
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2915
      which allows zooming and panning. If enabled you can configure the default layer
2916
      (background of your maps) below.</li>
2917
      <li><em>Plain image</em>: The map will be static non interactive
2918
      image.</li></ul>',
2919
  );
2920
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2921

    
2922
  /*
2923
   * settings for the distribution map are used also for specimens map!!!!
2924
   */
2925

    
2926
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2927
      '#type' => 'textfield',
2928
      '#title' => 'Aspect ratio',
2929
      '#default_value' => $map_distribution['aspect_ratio'],
2930
      '#maxlength' => 4,
2931
      '#size' => 4,
2932
      '#element_validate' => array('element_validate_number'),
2933
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2934
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2935
      width by the height:</br>
2936
      <pre>aspect ratio = w / h</pre>
2937
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2938
      for a square map use <strong>1</strong>.',
2939
  );
2940

    
2941
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2942
    '#type' => 'textfield',
2943
    '#title' => 'Bounding box',
2944
    '#default_value' => $map_distribution['bbox'],
2945
    '#description' =>
2946
      '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. 
2947
      For the whole world use Use <code>-180,-90,180,90</code>" for EPSG:4326 layers, for Web Mercator maps Open Street Map or 
2948
      Google maps the maximum bounds of the world are <code>-27395030.933594,-13697515.466797,27395030.933594,13697515.466797</code>.
2949
      Leave <strong>empty</strong> to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2950
      <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.
2951
      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
2952
      below the map from where you can copy the bbox string.</p>',
2953
  );
2954

    
2955
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2956
    '#type' => 'select',
2957
    '#title' => 'Max zoom level',
2958
    '#default_value' => $map_distribution['maxZoom'],
2959
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
2960
  );
2961

    
2962
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2963
    '#type' => 'checkbox',
2964
    '#title' => 'Display area labels',
2965
    '#default_value' => $map_distribution['show_labels'],
2966
    '#description' => t('The map will show name labels of the areas'),
2967
  );
2968

    
2969
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2970
    '#type' => 'textfield',
2971
    '#title' => 'Map caption',
2972
    '#default_value' => $map_distribution['caption'],
2973
    '#description' => t('The caption will be shown below the map.'),
2974
  );
2975

    
2976
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2977
    '#type' => 'textfield',
2978
    '#title' => 'Distribution layer opacity',
2979
    '#default_value' => $map_distribution['distribution_opacity'],
2980
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2981
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2982
  );
2983

    
2984
  // --- Plain Image Settings --- //
2985
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2986
    '#type' => 'fieldset',
2987
    '#title' => 'Plain image map settings',
2988
    '#tree' => TRUE,
2989
    '#collapsible' => TRUE,
2990
    '#collapsed' => $open_layers_is_enabled,
2991
    '#description' => 'The settings in this section are still expertimental
2992
      and can only be used with the EDIT map service version 1.1 or above.',
2993
  );
2994
  $edit_mapserver_version = get_edit_map_service_version_number();
2995
  if ($edit_mapserver_version < 1.1) {
2996
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2997
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2998
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2999
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
3000
  }
3001

    
3002
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3003
    '#type' => 'textfield',
3004
    '#title' => 'Width',
3005
    '#default_value' => $map_distribution['image_map']['width'],
3006
    '#maxlength' => 4,
3007
    '#size' => 4,
3008
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3009
  );
3010

    
3011
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3012
    '#type' => 'textfield',
3013
    '#title' => 'Background layer',
3014
    '#default_value' => $map_distribution['image_map']['base_layer'],
3015
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3016
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3017
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3018
    )),
3019
  );
3020

    
3021
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3022
    '#type' => 'textfield',
3023
    '#title' => 'Background color',
3024
    '#default_value' => $map_distribution['image_map']['bg_color'],
3025
  );
3026

    
3027
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3028
    '#type' => 'textfield',
3029
    '#title' => 'Background layer style',
3030
     // Only line color by now.
3031
    '#default_value' => $map_distribution['image_map']['layer_style'],
3032
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3033
  );
3034

    
3035
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3036
      '#type' => 'textfield',
3037
      '#title' => 'Projection',
3038
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3039
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3040
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3041
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3042
  );
3043

    
3044

    
3045
  // --- OpenLayers Settings --- //
3046
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3047
    '#type' => 'fieldset',
3048
    '#title' => 'OpenLayers settings',
3049
    '#tree' => TRUE,
3050
    '#collapsible' => TRUE,
3051
    '#collapsed' => !$open_layers_is_enabled,
3052
    '#description' => '',
3053
  );
3054

    
3055

    
3056
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3057
      '#type' => 'checkbox',
3058
      '#title' => 'Display outside max extent',
3059
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3060
      '#description' => t('Allows the map to display parts of the layers which are outside
3061
         the max extent if the aspect ratio of the map and of the baselayer
3062
         are not equal.'),
3063
  );
3064

    
3065

    
3066
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3067
      '#type' => 'checkbox',
3068
      '#title' => 'Show Layer Switcher',
3069
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3070
      '#description' => 'The Layer Switcher control displays a table of contents
3071
      for the map.  This allows the user interface to switch between
3072
      base layers and to show or hide overlays.  By default the switcher is
3073
      shown minimized on the right edge of the map, the user may expand it
3074
      by clicking on the handle.',
3075
  );
3076

    
3077
  if (!$open_layers_is_enabled) {
3078
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3079
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3080
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3081
  }
3082

    
3083
  // The default layer must always be enabled
3084
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3085
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3086

    
3087
  $baselayer_options = array(
3088
    /*
3089
   NOTICE: must correspond to the layers defined in
3090
   js/openlayers_,ap.js#getLayersByName()
3091
   */
3092
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3093
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3094
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3095
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3096
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3097
    // all others EPSG:900913
3098
    'mapnik' => 'OpenStreetMap (mapnik)',
3099
    'stamen_terrain' => 'Stamen Terrain',
3100
    'open_topomap' => 'OpenTopoMap',
3101
    // map quest is no longer free. it is required to sign up for a test plan.
3102
    // 'mapquest_open' => "MapQuest",
3103
    // 'mapquest_sat' => "MapQuest Sattelite",
3104
    'groadmap' => 'Google Roadmap',
3105
    'gsatellite' => 'Google Satellite',
3106
    'ghybrid' => 'Google Hybrid',
3107
    'gterrain' => 'Google Terrain',
3108
//     'veroad' => 'Virtual Earth Roads',
3109
//     'veaer' => 'Virtual Earth Aerial',
3110
//     'vehyb' => 'Virtual Earth Hybrid',
3111
    // 'yahoo' => 'Yahoo Street',
3112
    // 'yahoosat' => 'Yahoo Satellite',
3113
    // 'yahoohyb' => 'Yahoo Hybrid',
3114
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3115
  );
3116

    
3117
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3118
    '#type' => 'checkboxes_preferred',
3119
    '#title' => 'Base Layers',
3120
    '#options' => $baselayer_options,
3121
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3122
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3123
  );
3124

    
3125
  $google_maps_api_key = null;
3126
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3127
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3128
  }
3129
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3130
    '#type' => 'textfield',
3131
    '#title' => 'Google Maps API Key',
3132
    '#default_value' => $google_maps_api_key,
3133
    '#description' => 'In order to use any of the Google map layers you need to provide 
3134
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3135
  );
3136

    
3137
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3138
    $map_distribution['openlayers']['custom_wms_base_layer'],
3139
    'Custom WMS base layer',
3140
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3141
    true // add projection settings
3142
    );
3143

    
3144
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3145
    $map_distribution['openlayers']['wms_overlay_layer'],
3146
    'WMS overlay layer',
3147
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3148
                You can actually combine multiple layers for this overlay. 
3149
                For details please refer to the wms query parameter <code>Layers</code> .'
3150
  );
3151

    
3152
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3153
    '#type' => 'checkbox',
3154
    '#title' => 'Enable overlay layer',
3155
    '#weight' => -100,
3156
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3157
  );
3158

    
3159
  /*
3160
   * Map Legend
3161
   */
3162
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3163
    '#type' => 'fieldset',
3164
    '#title' => 'Map legend',
3165
    '#tree' => TRUE,
3166
    '#collapsible' => TRUE,
3167
    '#collapsed' => TRUE,
3168
    '#description' => 'Configure the maps legend.',
3169
  );
3170

    
3171
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3172
    '#type' => 'checkbox',
3173
    '#title' => 'Display a map legend',
3174
    '#default_value' => $map_distribution['legend']['show'],
3175
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3176
  );
3177

    
3178
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3179
    '#type' => 'textfield',
3180
    '#title' => 'Legend opacity',
3181
    '#default_value' => $map_distribution['legend']['opacity'],
3182
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3183
                         to 0.0 will be not much visible.',
3184
  );
3185

    
3186
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3187
    '#type' => 'textfield',
3188
    '#title' => 'Font size',
3189
    '#default_value' => $map_distribution['legend']['font_size'],
3190
    '#description' => 'Font size in pixels.',
3191
  );
3192

    
3193
  $fontStyles = array(
3194
    0 => "plane",
3195
    1 => "italic",
3196
  );
3197
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3198
    '#type' => 'select',
3199
    '#title' => 'Available font styles',
3200
    '#default_value' => $map_distribution['legend']['font_style'],
3201
    '#options' => $fontStyles,
3202
    '#description' => 'Select a font style for the map legend.',
3203
  );
3204

    
3205
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3206
    '#type' => 'textfield',
3207
    '#title' => 'Icon width',
3208
    '#default_value' => $map_distribution['legend']['icon_width'],
3209
    '#description' => 'Legend icon width in pixels.',
3210
  );
3211
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3212
    '#type' => 'textfield',
3213
    '#title' => 'Icon height',
3214
    '#default_value' => $map_distribution['legend']['icon_height'],
3215
    '#description' => 'Legend icon height in pixels.',
3216
  );
3217

    
3218
  // @WA: D7 form api does not support reset buttons,
3219
  // so to mimic the D5 reset button we add one like this.
3220
  $form['actions']['reset'] = array(
3221
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3222
    '#weight' => 1000,
3223
  );
3224

    
3225
  return system_settings_form($form);
3226
}
3227

    
3228
/**
3229
 * @param $default_settings
3230
 * @param $title
3231
 * @param $description
3232
 * @param bool $add_projection_settings
3233
 * @return array
3234
 */
3235
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3236
{
3237
  $form_elements = array(
3238
    '#type' => 'fieldset',
3239
    '#title' => $title,
3240
    '#tree' => TRUE,
3241
    '#collapsible' => FALSE,
3242
    '#collapsed' => FALSE,
3243
    '#description' => $description,
3244
  );
3245

    
3246
  $form_elements['name'] = array(
3247
    '#type' => 'textfield',
3248
    '#title' => 'Layer name',
3249
    '#default_value' => $default_settings['name'],
3250
    '#description' => 'A arbitrary name for the layer.',
3251
  );
3252
  $form_elements['url'] = array(
3253
    '#type' => 'textfield',
3254
    '#title' => 'WMS url',
3255
    '#default_value' => $default_settings['url'],
3256
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3257
  );
3258
  $form_elements['untiled'] = array(
3259
    '#type' => 'checkbox',
3260
    '#title' => 'Untiled',
3261
    '#default_value' => $default_settings['untiled'],
3262
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3263
  );
3264
  $form_elements['params'] = array(
3265
    '#type' => 'textarea',
3266
    '#title' => 'WMS parameters',
3267
    '#element_validate' => array('form_element_validate_json'),
3268
    '#default_value' => $default_settings['params'],
3269
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3270
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3271
      . '), entered in valid JSON. For example:
3272
<pre> {
3273
  "Layers": "topp:em_tiny_jan2003",
3274
  "Format": "image/png",
3275
  "BGCOLOR": "0xe0faff"
3276
}
3277
</pre>
3278
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3279
  );
3280

    
3281
  if($add_projection_settings){
3282

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

    
3348
  }
3349
  return $form_elements;
3350
}
3351

    
3352

    
3353
/**
3354
 * @return array
3355
 *   The form structure.
3356
 */
3357
function cdm_settings_cache() {
3358

    
3359
  $form = array();
3360

    
3361
  $form['cache_settings'] = array(
3362
    '#type' => 'fieldset',
3363
    '#title' => t('Cache Settings'),
3364
    '#collapsible' => FALSE,
3365
    '#collapsed' => FALSE,
3366
    '#description' => t('<p>When caching is enabled all single taxon sites are
3367
      stored in an internal drupal cache doing the portal response of taxa pages
3368
      faster. This is possible because the sites are loaded from the cache and
3369
      are not created from scratch.</p>'),
3370
  );
3371

    
3372
  $form['cache_settings']['cdm_webservice_cache'] = array(
3373
    '#type' => 'checkbox',
3374
    '#title' => t('<strong>Enable caching</strong>'),
3375
    '#options' => cdm_help_general_cache(),
3376
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3377
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3378
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3379
       application the changes will be not visible till the cache is erased.
3380
       Therefore developers should deactived this feature when they are working
3381
       on the CDM Dataportal Module.</p>'),
3382
  );
3383

    
3384
  $form['cache_settings']['cdm_run_cache'] = array(
3385
    '#markup' => cdm_view_cache_site(),
3386
  );
3387

    
3388
  // @WA: D7 form api does not support reset buttons,
3389
  // so to mimic the D5 reset button we add one like this.
3390
  $form['actions']['reset'] = array(
3391
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3392
    '#weight' => 1000,
3393
  );
3394
  return system_settings_form($form);
3395
}
3396

    
3397
/**
3398
 * Walk and cache all taxon pages.
3399
 */
3400
function cdm_view_cache_site() {
3401

    
3402
  $out = '';
3403

    
3404
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3405

    
3406
  $request_params = array();
3407
  $request_params['class'] = "Taxon";
3408

    
3409
  $cdm_ws_page_taxa_url = cdm_compose_ws_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3410
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3411
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3412

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

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

    
3422
  // Comment @WA: A form within a form is not valid html and not needed here.
3423
  // Also, it would be recommended just to include this part of the form in the
3424
  // rest of the form array in cdm_settings_cache().
3425
  // $out .= '<form id="cache_site">';
3426
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3427
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3428
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3429
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3430
  // $out .= '</form>';
3431
  $out .= '</div>';
3432
  /*
3433
  foreach($taxonPager->records as $taxon){
3434
    cdm_dataportal_taxon_view($uuid);
3435
  }
3436
  */
3437
  return $out;
3438
}
3439

    
3440

    
3441
function cdm_settings_layout_taxon_submit($form, &$form_state){
3442
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3443
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3444
    if(is_object($file)){
3445
      $file->status = FILE_STATUS_PERMANENT;
3446
      file_save($file);
3447
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3448
    }
3449
  }
3450
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3451
  $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]);
3452
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3453
  if($tab_lables_modified || $tabs_enabled_modified){
3454
    // we first need to set the variable to persist the changes setting
3455
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3456
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3457
    menu_rebuild();
3458
  }
3459
}
3460

    
3461
function cdm_settings_layout_search_submit($form, &$form_state){
3462
  // the visibility of media thumbnails also affects the ui of the search results
3463
  // so reset the according session variable
3464
  //    1. in order to give the user immediate
3465
  //       feedback on potential setting changes
3466
  //    2. let refresh the default if it has changed
3467
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3468
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3469
  }
3470
}
3471

    
3472
/**
3473
 * Form validation handler for cdm_settings_general
3474
 *
3475
 * @param $form
3476
 * @param $form_state
3477
 */
3478
function cdm_settings_general_validate($form, &$form_state) {
3479

    
3480
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3481
    $form_state['values']['cdm_webservice_url'] .= '/';
3482
  }
3483

    
3484
}
3485

    
3486
/**
3487
 * Form submit handler for settings general.
3488
 *
3489
 * tasks performed:
3490
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3491
 *
3492
 * @param $form
3493
 * @param $form_state
3494
 */
3495
function cdm_settings_general_submit($form, &$form_state){
3496
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3497
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3498
  unset($_SESSION['cdm_login']);
3499
}
3500

    
3501
/**
3502
 * Form validation handler for cdm_settings_cache
3503
 */
3504
function cdm_settings_cache_validate($form, &$form_state) {
3505
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3506
    cache_clear_all(NULL, 'cache_cdm_ws');
3507
    // Better clear secref_cache since I can not be sure if the cache has not
3508
    // be used during this response.
3509
    cdm_api_secref_cache_clear();
3510
  }
3511

    
3512
}
3513

    
3514
/**
3515
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3516
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3517
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3518
 *  - version: the version, e.g.: v1.1
3519
 *
3520
 * @return array
3521
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3522
 */
3523
function get_edit_map_service_settings() {
3524

    
3525
  $settings = variable_get('edit_map_server', array(
3526
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3527
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3528
      )
3529
  );
3530

    
3531
  return $settings;
3532
}
3533

    
3534
/**
3535
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3536
 *
3537
 * @return string
3538
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3539
 */
3540
function get_edit_map_service_full_uri() {
3541
  $settings = get_edit_map_service_settings();
3542
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3543
}
3544

    
3545

    
3546
/**
3547
 * Returns the version number of the currently selected edit mapserver as a float
3548
 *
3549
 * @return float
3550
 *   The version number of the currently selected edit mapserver as a float.
3551
 *   Returns 0 on error.
3552
 */
3553
function get_edit_map_service_version_number() {
3554

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

    
3557
  $settings = get_edit_map_service_settings();
3558
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3559
  if (isset($matches[1])) {
3560
    // Convert string to float.
3561
    $version = 1 + $matches[1][0] - 1;
3562
    return $version;
3563
  }
3564
  else {
3565
    // Report error.
3566
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3567
        array(
3568
          '!version' => $settings['version'],
3569
          'warning')
3570
        )
3571
      );
3572
    return 0;
3573
  }
3574
}
3575

    
3576
/**
3577
 * Returns the array of selected items in a options array
3578
 *
3579
 * @param array $options
3580
 *   An options array as generated by a form element like checkoxes, select ...,
3581
 */
3582
function get_selection($options) {
3583
  $selection = array();
3584
  foreach ($options as $key=>$val) {
3585
    if (!empty($val)) {
3586
      $selection[] = $val;
3587
    }
3588
  }
3589
  return $selection;
3590
}
3591

    
3592

    
3593
/**
3594
 * Implements hook_element_info().
3595
 *
3596
 * Allows modules to declare their own Form API element types and specify their default values.
3597
 *
3598
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3599
 */
3600
function cdm_dataportal_element_info() {
3601
  $type['checkboxes_preferred'] = array(
3602
    '#input' => TRUE,
3603
    '#process' => array('checkboxes_preferred_expand'),
3604
    '#after_build' => array('checkboxes_preferred_after_build'),
3605
    '#theme' => array('checkboxes_preferred'),
3606
    // '#theme_wrapper' => array('form_element'),
3607
  );
3608
  return $type;
3609
}
3610

    
3611
/**
3612
 * #process callback function for the custom form element type 'checkbox_preferred'
3613
 *
3614
 *
3615
 */
3616
function checkboxes_preferred_expand($element, &$form_state, $form) {
3617

    
3618
  // First of all create checkboxes for each of the elements
3619
  $element = form_process_checkboxes($element);
3620

    
3621
  // compose the element name
3622
  $parents = array();
3623
  array_deep_copy($element['#parents'], $parents);
3624
  $parents[count($parents) -1 ] .= '_preferred';
3625
  $element_name = $parents[0];
3626
  for ($i=1; $i < count($parents); $i++){
3627
    $element_name .= '[' . $parents[$i] . ']';
3628
  }
3629

    
3630
  $children = element_children($element);
3631

    
3632
  $element['table_start'] = array(
3633
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3634
    '#weight' => -1,
3635
  );
3636

    
3637
  // prepare first part each of the table rows which contains the row label
3638
  $weight = 0;
3639
  foreach ($children as $key) {
3640
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3641
    $element[$key]['#weight'] = $weight;
3642
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3643
    $element[$key]['#suffix'] = '</td>';
3644
    unset($element[$key]['#title']);
3645
    $weight += 2;
3646
  }
3647
  $weight = 0;
3648

    
3649
  // add a radio button to each of the checkboxes, the
3650
  // check boxes have already been created at the beginning
3651
  // of this function
3652
  if (count($element['#options']) > 0) {
3653
    foreach ($element['#options'] as $key => $choice) {
3654
      if (!isset($element[$key . '_preferred'])) {
3655
        $element[$key . '_preferred'] = array(
3656
          '#type' => 'radio',
3657
          '#name' => $element_name,
3658
          '#return_value' => check_plain($key),
3659
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3660
          '#attributes' => $element['#attributes'],
3661
          '#parents' => $element['#parents'],
3662
          // '#spawned' => TRUE,
3663
          '#weight' => $weight + 1,
3664
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3665
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3666
        );
3667
      }
3668
      $weight += 2;
3669
    }
3670
  }
3671

    
3672
  // end the table
3673
  $element['table_end'] = array(
3674
    '#markup' => '</table>',
3675
    '#weight' => $weight++,
3676
  );
3677

    
3678
  return $element;
3679
}
3680

    
3681
/**
3682
 * Theme function for the custom form field 'checkboxes_preferred'.
3683
 */
3684
function theme_checkboxes_preferred($variables) {
3685
  $element = $variables['element'];
3686
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3687
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3688
  $out .= drupal_render_children($element);
3689
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3690
  $out .= '</div>';
3691
  return $out;
3692
}
3693

    
3694
/**
3695
 * Callback for checkboxes preferred for widget which will
3696
 * be called after the form or element is built. The call
3697
 * back is configured in the form element by setting it as
3698
 * #after_build parameter.
3699
 *
3700
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3701
 *
3702
 * @param $element
3703
 *   Nested array of form elements that comprise the form.
3704
 * @param $form_state
3705
 *   A keyed array containing the current state of the form.
3706
 *   This includes the current persistent storage data for the form.
3707
 *   Additional information, like the sanitized $_POST data,
3708
 *   is also accumulated here in $form_state['input']
3709
 *
3710
 * @return the modified form array
3711
 */
3712
function checkboxes_preferred_after_build($element, &$form_state) {
3713

    
3714
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3715

    
3716
  if ($_POST && count($_POST) > 0) {
3717
    // TODO use  $form_state['input'] instead of POST !!!
3718
    // First pass of form processing.
3719
    $parents = array();
3720
    array_deep_copy($element['#parents'], $parents);
3721
    $parents[count($parents) - 1] .= '_preferred';
3722
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3723
    $element['#value']['PREFERRED'] = $preferred_layer;
3724
//     $form_state[$parent_id] = $element['#value'];
3725
//     $form_state['values']['baselayers'] = $element['#value'];
3726
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3727
    $form_state_element_values = $element['#value'];
3728
  }
3729
  else {
3730
    // Second pass of form processing.
3731
    $preferred_layer = $element['#value']['PREFERRED'];
3732
  }
3733

    
3734
  // Also set the chosen value (not sure if this is good Drupal style ....).
3735
  foreach ($children = element_children($element) as $key) {
3736
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3737
      $element[$key]['#value'] = $preferred_layer;
3738
    }
3739
  }
3740
  // The default layer must always be enabled.
3741
  $element[$preferred_layer]['#value'] = $preferred_layer;
3742

    
3743
  return $element;
3744
}
3745

    
3746
function radios_prepare_options_suffix(&$elements){
3747

    
3748
  $childrenKeys = element_children($elements);
3749
  foreach($childrenKeys as $key){
3750
    if(!is_array($elements[$key]['#theme_wrappers'])){
3751
      $elements[$key]['#theme_wrappers'] = array();
3752
    }
3753
    if(isset($elements['#options_suffixes'][$key])){
3754
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3755
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3756
    }
3757
  }
3758
  return $elements;
3759

    
3760
}
3761

    
3762
/**
3763
 * TODO
3764
 * @param unknown $variables
3765
 */
3766
function theme_radio_options_suffix($variables) {
3767
  $element = $variables['element'];
3768
  if(isset($element['#options_suffix'])) {
3769
    $element['#children'] .= $element['#options_suffix'];
3770
  }
3771
  return $element['#children'];
3772
}
3773

    
3774

    
3775
/**
3776
 * Element validate callback for text field and arrays containing json.
3777
 *
3778
 * @param $element
3779
 *   The form element to validate
3780
 * @param $form_state
3781
 *   A keyed array containing the current state of the form.
3782
 * @param $form
3783
 *   Nested array of form elements that comprise the form.
3784
 */
3785
function form_element_validate_json($element, &$form_state, $form) {
3786
   if (!empty($element['#value'])) {
3787
     json_decode($element['#value']);
3788
     if(json_last_error() != JSON_ERROR_NONE){
3789
       form_error($element,
3790
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3791
         . l('JSONLint', 'http://jsonlint.com/')
3792
       );
3793
     }
3794
   }
3795
}
3796

    
3797
/**
3798
 * Form submission handler for textareas and textfields containing JSON.
3799
 *
3800
 * The contained JSON will be converted into an php array
3801
 * or object and will be stored in the variables as such.
3802
 *
3803
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3804
 *
3805
 * @param $form
3806
 *   Nested array of form elements that comprise the form.
3807
 * @param $form_state
3808
 *   A keyed array containing the current state of the form.
3809
 *
3810
 */
3811
function submit_json_as_php_array($form, &$form_state) {
3812
  if (is_array($form['#json_elements'])) {
3813
    foreach ($form['#json_elements'] as $element){
3814
      if (trim($form_state['values'][$element])) {
3815
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3816
      } else {
3817
        $form_state['values'][$element] = NULL;
3818
      }
3819
    }
3820
  }
3821
}
(19-19/19)