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 entry set the value to 0
240
    array(
241
      'doTaxa'=>'doTaxa',
242
      'doSynonyms' => 'doSynonyms',
243
      'doTaxaByCommonNames' => 0,
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' => 'open_topomap'),
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_url_ssl_verify'] = array(
994
    '#type' => 'checkbox',
995
    '#title' => t('Verify SSL/TLS certificate') . ':',
996
    '#description' => 'The ssl/tsl certificate of the CDM web service will not be verified if this options is disabled, . 
997
    This can be helpful if you are running your server with self-signed certificates. Since this is 
998
    discouraged, disabling this options should only be done, if you are fully aware of the security consequences.',
999
    '#default_value' => variable_get('cdm_webservice_url_ssl_verify', 1),
1000
  );
1001

    
1002
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1003
    '#type' => 'markup',
1004
    '#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')
1005
      . ' visible only for administrators',
1006
  );
1007

    
1008
  $form['cdm_webservice']['freetext_index'] = array(
1009
    '#type' => 'fieldset',
1010
    '#title' => t('Freetext index'),
1011
    '#collapsible' => FALSE,
1012
    '#collapsed' => FALSE,
1013
  );
1014

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

    
1029
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1030
  $trigger_link_options = array(
1031
    'attributes' => array(
1032
      'class' => 'index-trigger'
1033
    ),
1034
  );
1035
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1036
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1037
        '!url1' => l(t("Purge"), cdm_compose_ws_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1038
        '!url2' => l(t("Reindex"), cdm_compose_ws_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1039
      ))
1040
    . '<div id="index-progress"></div></div>',
1041
  );
1042

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

    
1068
  $form['cdm_webservice']['proxy'] = array(
1069
    '#type' => 'fieldset',
1070
    '#title' => t('Proxy'),
1071
    '#collapsible' => TRUE,
1072
    '#collapsed' => TRUE,
1073
  );
1074

    
1075
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1076
    '#type' => 'textfield',
1077
    '#title' => t('Proxy URL') . ':',
1078
    '#description' => t('If this proxy url is set the cdm api tries
1079
    to connect the web service over the given proxy server.
1080
    Otherwise proxy usage is deactivated.'),
1081
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1082
  );
1083

    
1084
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1085
    '#type' => 'textfield',
1086
    '#title' => t('Proxy port') . ':',
1087
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1088
  );
1089

    
1090
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1091
    '#type' => 'textfield',
1092
    '#title' => t('Login') . ':',
1093
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1094
  );
1095

    
1096
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1097
    '#type' => 'textfield',
1098
    '#title' => t('Password') . ':',
1099
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1100
  );
1101

    
1102
  $form['sub_tree_filter'] = array(
1103
    '#type' => 'fieldset',
1104
    '#title' => t('Subtree filter'),
1105
    '#collapsible' => FALSE,
1106
    '#collapsed' => TRUE,
1107
    '#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.'),
1108
  );
1109

    
1110
  $sub_tree_filter_uuid_value = variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE);
1111
  $taxon_node_info = '';
1112
  if($sub_tree_filter_uuid_value){
1113
    $taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE, array($sub_tree_filter_uuid_value));
1114
    if($taxon_node_dto){
1115
      $taxon_node_info = " Current taxon node: <strong>" . cdm_tagged_text_to_markup($taxon_node_dto->taggedTitle) . " [" . $taxon_node_dto->treeIndex . "]</strong>";
1116
    }
1117
  }
1118
  $form['sub_tree_filter'][CDM_SUB_TREE_FILTER_UUID] = array(
1119
    '#type' => 'textfield',
1120
    '#title' => t('Taxon Node UUID') . ':',
1121
    '#default_value' => variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE),
1122
    '#description' => "The uuid of the TaxonNode entity to be used as filter." . $taxon_node_info
1123
  );
1124

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

    
1141
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1142
    '#type' => 'select',
1143
    '#title' => t('Default classification') . ':',
1144
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1145
    '#options' => cdm_get_taxontrees_as_options(),
1146
    '#description' => t('The default taxa classification to be used in the whole portal. 
1147
      This affects most obviously the classification browser and the search in case it is restricted 
1148
      to a specific classification. See also <i>Included Classifications</i> below.'),
1149
  );
1150

    
1151
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1152
    '#type' => 'select',
1153
    '#title' => t('Rank of highest displayed taxon') . ':',
1154
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1155
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1156
    '#options' => cdm_vocabulary_as_option(UUID_RANK, null, true),
1157
    '#description' => t('This is the rank of the highest displayed taxon in the
1158
      <em>taxon tree</em>. You can select here which rank should be at the top
1159
      level of the tree structure.'),
1160
  );
1161

    
1162
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1163
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1164
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1165
      '#type' => 'checkboxes',
1166
      '#title' => t('Included Classifications') . ':',
1167
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1168
      '#options' => cdm_get_taxontrees_as_options(),
1169
      '#description' => t('Only the checked classifications will be available 
1170
        in the classification selection element of the taxon tree browser and in search forms.'),
1171
  );
1172

    
1173
  $form['distribution'] = array(
1174
      '#type' => 'fieldset',
1175
      '#title' => t('Distributions'),
1176
      '#collapsible' => FALSE,
1177
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1178
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1179
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1180
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1181
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1182
          '<p>
1183
          </p>',
1184
  );
1185

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

    
1208
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1209
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1210
      '#type' => 'checkboxes',
1211
      '#title' => 'Filter rules',
1212
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1213
      '#options' => array(
1214
          'statusOrderPreference' => 'Status order preference rule',
1215
          'subAreaPreference' => 'Sub area preference rule'
1216
      ),
1217
  );
1218

    
1219
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1220
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1221
      '#type' => 'checkboxes',
1222
      '#title' => 'Hide marked area filter',
1223
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1224
      '#options' => $marker_type_options,
1225
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1226
  );
1227

    
1228
  $form['aggregation'] = array(
1229
      '#type' => 'fieldset',
1230
      '#title' => t('Aggregation of data'),
1231
      '#collapsible' => FALSE,
1232
      '#description' => 'This section covers the different aspects of aggregating information.
1233
          <p>
1234
          </p>',
1235
  );
1236

    
1237
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1238
      '#type' => 'checkboxes',
1239
      '#title' => 'Taxon media filter',
1240
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1241
      '#options' => array(
1242
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1243
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1244
          'includeOccurrences' => 'Media related to specimens and occurrences',
1245
      ),
1246
      '#description' => 'This filter configures which images should be taken into account.',
1247
  );
1248

    
1249
  $form['aggregation']['notice'] = array(
1250
      '#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
1251
          want to make use of the caching capabilities of the dataportal.',
1252
  );
1253

    
1254
  $form['aggregation']['media_aggregation'] = array(
1255
      '#type' => 'fieldset',
1256
      '#title' => t('Media aggregation'),
1257
      '#collapsible' => FALSE,
1258
      '#collapsed' => TRUE,
1259
      '#description' => t("The media aggregation is also affected by the settings in \"<strong>Aggregation via taxon relationships</strong>\" below."),
1260

    
1261
  );
1262
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1263
      '#type' => 'select',
1264
      '#title' => t('Aggregation of taxon pictures') . ':',
1265
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1266
      '#options' => array(
1267
          0 => "Show only pictures of the current taxon",
1268
          1 => "Include pictures of taxonomic children",
1269
      ),
1270
      '#description' => t("Choose whether to include the images of the taxonomic children. This will affect the <em>Images</em> tab and image thumbnails like in the search results."),
1271
  );
1272

    
1273
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1274
      '#type' => 'fieldset',
1275
      '#attributes' => array('class' => array('clearfix')),
1276
      '#title' => t('Aggregation via taxon relationships'),
1277
      '#collapsible' => TRUE,
1278
      '#collapsed' => TRUE,
1279
      '#tree' => TRUE,
1280
      '#description' => t('Information on taxa will be aggregated along the below chosen
1281
          taxon relation ships. This will affect images and occurrences (specimens).
1282
          Taxon relation ships are directed and point form one taxon to another. The taxon
1283
          relationships to be taken into account can therefore configured for the direct direction
1284
          and for the inverse.'),
1285
  );
1286

    
1287
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1288
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1289

    
1290
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1291
      '#type' => 'checkboxes',
1292
      '#title' => t('Direct'),
1293
      '#options' => $taxonRelationshipTypeOptions,
1294
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1295
  );
1296
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1297
      '#type' => 'checkboxes',
1298
      '#title' => t('Invers'),
1299
      '#options' => $taxonRelationshipTypeOptions,
1300
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1301
  );
1302

    
1303
  $form['drupal_integration'] = array(
1304
    '#type' => 'fieldset',
1305
    '#attributes' => array('class'=> array('clearfix')),
1306
    '#title' => t('Drupal integration'),
1307
    '#collapsible' => FALSE,
1308
    '#collapsed' => FALSE,
1309
    '#tree' => FALSE
1310
  );
1311

    
1312
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1313
    '#type' => 'checkbox',
1314
    '#title' => 'Create drupal nodes',
1315
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1316
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1317
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1318
    cdm pages it is required that drupal nodes are created and stored in the database.'
1319
  );
1320

    
1321

    
1322

    
1323
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1324
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1325
    <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>',
1326
  );
1327
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1328
    '#type' => 'submit',
1329
    '#value' => t('Drop all cdm nodes'),
1330
    '#submit' => array('drop_all_cdm_nodes_submit')
1331
  );
1332

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

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

    
1362
  // Comment @WA: D7 form api does not support reset buttons,
1363
  // so to mimic the D5 reset button we add one like this.
1364
  $form['actions']['reset'] = array(
1365
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1366
    '#weight' => 1000,
1367
  );
1368

    
1369
  $form['#submit'][] = 'cdm_settings_general_submit';
1370

    
1371
  return system_settings_form($form);
1372
}
1373

    
1374
/**
1375
 * Submit callback; drops all cdm nodes.
1376
 *
1377
 * @ingroup forms
1378
 */
1379
function drop_all_cdm_nodes_submit($form, &$form_state) {
1380
  cdm_delete_all_cdm_nodes();
1381
  drupal_set_message(t('All cdm nodes dropped.'));
1382
}
1383

    
1384

    
1385
/**
1386
 * LAYOUT settings
1387
 *
1388
 * @return array
1389
 *   The form structure.
1390
 */
1391
function cdm_settings_layout() {
1392

    
1393
  $form = array();
1394

    
1395
  $form['about'] = array(
1396
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1397
      layout. If you want to configure the specific sites layout visit the
1398
      respective configuration site for taxon, search or media.') . '</p>',
1399
  );
1400

    
1401
  $form['annotations'] = array(
1402
    '#type' => 'fieldset',
1403
    '#title' => t('Annotations'),
1404
    '#collapsible' => FALSE,
1405
    '#collapsed' => FALSE,
1406
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1407
  );
1408

    
1409
  $annotation_type_options = cdm_terms_by_type_as_option('AnnotationType');
1410
  // Additional option for the NULL case.
1411
  $annotation_type_options['NULL_VALUE'] = t('untyped');
1412
  $annotations_types_visible = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1413
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1414
    '#type' => 'checkboxes',
1415
    '#title' => t('Visbility of annotation types'),
1416
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1417
    '#options' => $annotation_type_options,
1418
    '#default_value' => $annotations_types_visible
1419
  );
1420

    
1421
  $form['extensions'] = array(
1422
    '#type' => 'fieldset',
1423
    '#title' => t('Extensions'),
1424
    '#collapsible' => FALSE,
1425
    '#collapsed' => FALSE,
1426
    '#description' => t('This sections allows configuring global settings regarding the data type extensions.'),
1427
  );
1428

    
1429
  $extension_type_options = cdm_terms_by_type_as_option('ExtensionType');
1430
  $extension_types_visible = variable_get(EXTENSION_TYPES_VISIBLE, unserialize(EXTENSION_TYPES_VISIBLE_DEFAULT));
1431
  $form['extensions'][EXTENSION_TYPES_VISIBLE] = array(
1432
    '#type' => 'checkboxes',
1433
    '#title' => t('Visbility of extension types'),
1434
    '#description' => t("Only extensions of the selected type will be displayed."),
1435
    '#options' => $extension_type_options,
1436
    '#default_value' => $extension_types_visible
1437
  );
1438

    
1439

    
1440
  // ---- original source --- //
1441
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1442
      '#type' => 'fieldset',
1443
      '#tree' => TRUE,
1444
      '#title' => t('Source Citations'),
1445
      '#collapsible' => FALSE,
1446
      '#collapsed' => FALSE,
1447
  );
1448

    
1449
  $bibliography_settings = get_bibliography_settings(true);
1450

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

    
1462
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1463
    '#type' => 'select',
1464
    '#title' => t('The format of the key numerals'),
1465
    '#default_value' => $bibliography_settings['key_format'],
1466
    '#options' => array('latin' => 'Latin',
1467
      'ROMAN' => 'Roman (upper case)',
1468
      'roman' => 'Roman (lower case)',
1469
      'ALPHA'=> 'Alphabet (upper case)',
1470
      'alpha' => 'Alphabet (lower case)')
1471
  );
1472

    
1473
  // --- Advanced Search --- //
1474
  $form['asearch'] = array(
1475
      '#type' => 'fieldset',
1476
      '#title' => t('Advanced search'),
1477
      '#collapsible' => FALSE,
1478
      '#collapsed' => FALSE,
1479
  );
1480
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1481
      '#type' => 'checkbox',
1482
      '#title' => t('Show advanced search link'),
1483
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1484
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1485
  );
1486

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

    
1503
  // --- Registrations --- //
1504
  $form['registrations'] = array(
1505
    '#type' => 'fieldset',
1506
    '#title' => t('Registrations'),
1507
    '#collapsible' => FALSE,
1508
    '#collapsed' => FALSE,
1509
  );
1510
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1511
    '#type' => 'checkbox',
1512
    '#title' => t('Use the persistent http identifier as link'),
1513
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1514
    '#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.'),
1515
  );
1516

    
1517
  // ---- Taxon Name Rendering --- //
1518
  $form['taxon_name'] = array(
1519
      '#type' => 'fieldset',
1520
      '#title' => t('Taxon name display'),
1521
      '#collapsible' => TRUE,
1522
      '#collapsed' => TRUE,
1523
      '#description' => t('The display of taxon names is configured by two parts.
1524
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1525
          The name parts are defined in the <stong>part definitions</strong>'),
1526
  );
1527

    
1528
  $nameRenderConfiguration = new NameRenderConfiguration();
1529

    
1530
  $partDefinitionConfigStatus = $nameRenderConfiguration->partDefinitionConfigurationStatus();
1531
  switch($partDefinitionConfigStatus){
1532
    case NameRenderConfiguration::PRE380_CONFIGURATION:
1533
      $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.)';
1534
      break;
1535
    case NameRenderConfiguration::CUSTOM_CONFIGURATION:
1536
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1537
      break;
1538
    case NameRenderConfiguration::DEFAULT_CONFIGURATION:
1539
    default:
1540
      $which_version_message = '(These are the default part definition.)';
1541
  }
1542
  $current_part_definition_json = $nameRenderConfiguration->getCurrentPartDefinitionJson();
1543
  $default_part_definition_json = $nameRenderConfiguration->getDefaultPartDefinitionJson();
1544
  $diff_viewer_markup = '';
1545
  if($partDefinitionConfigStatus == NameRenderConfiguration::CUSTOM_CONFIGURATION){
1546
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1547
  }
1548

    
1549
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1550
    . $which_version_message
1551
    . '</div>'
1552
    . $diff_viewer_markup;
1553

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

    
1606
  $nameRenderTemplateConfStatus = $nameRenderConfiguration->nameRenderTemplateConfigurationStatus();
1607

    
1608
  switch($nameRenderTemplateConfStatus){
1609
    case NameRenderConfiguration::PRE380_CONFIGURATION:
1610
      $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.)';
1611
      break;
1612
    case NameRenderConfiguration::CUSTOM_CONFIGURATION:
1613
      $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1614
      break;
1615
    case NameRenderConfiguration::DEFAULT_CONFIGURATION:
1616
    default:
1617
      $which_version_message = '(These are the default render templates.)';
1618
  }
1619
  $default_render_templates_json = $nameRenderConfiguration->getDefaultRenderTemplatesJson();
1620
  $current_render_templates_json = $nameRenderConfiguration->getCurrentRenderTemplatesJson();
1621
  $diff_viewer_markup = '';
1622
  if($nameRenderTemplateConfStatus == NameRenderConfiguration::CUSTOM_CONFIGURATION){
1623
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1624
  }
1625

    
1626
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1627
    . $which_version_message
1628
    . '</div>'
1629
    . $diff_viewer_markup;
1630

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

    
1671
  // @WA: D7 form api does not support reset buttons,
1672
  // so to mimic the D5 reset button we add one like this.
1673
  $form['actions']['reset'] = array(
1674
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1675
    '#weight' => 1000,
1676
  );
1677

    
1678
  $form['#submit'] = array('submit_json_as_php_array');
1679
  // #json_elements especially defined for submit_json_as_php_array()
1680
  $form['#json_elements'] = array(NameRenderConfiguration::CDM_NAME_RENDER_TEMPLATES, NameRenderConfiguration::CDM_PART_DEFINITIONS);
1681
  return system_settings_form($form);
1682
}
1683

    
1684

    
1685
/**
1686
 * @param $form_name
1687
 * @param $form_title
1688
 * @param $collapsed
1689
 * @param string $form_description
1690
 *   The description for the fieldset of the gallery setting.
1691
 * @return mixed
1692
 */
1693
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1694
  $form[$form_name] = array(
1695
    '#type' => 'fieldset',
1696
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1697
    '#collapsible' => TRUE,
1698
    '#collapsed' => $collapsed,
1699
    '#tree' => TRUE,
1700
    '#description' => $form_description,
1701
  );
1702

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

    
1721
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1722
      '#type' => 'checkbox',
1723
      '#title' => t('Show media thumbnails for synonyms'),
1724
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1725
      '#description' => '',
1726
    );
1727
  }
1728

    
1729
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1730
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1731
    '#type' => 'checkbox',
1732
    '#title' => t('Show captions under thumbnails'),
1733
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1734
    '#description' => '',
1735
  );
1736

    
1737
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1738
    '#type' => 'textfield',
1739
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1740
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1741
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1742
  );
1743

    
1744
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1745
    '#type' => 'textfield',
1746
    '#title' => t('Number of columns') . ':',
1747
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1748
    '#description' => t('Group the thumbnails in columns: select how many
1749
      columns the gallery should display.'),
1750
  );
1751

    
1752
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1753
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1754
      '#type' => 'textfield',
1755
      '#title' => t('Maximum number of rows') . ':',
1756
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1757
      '#description' => t('You can group the thumbnails in rows, select in how
1758
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1759
        If you want an unlimited number of rows please set to 0.'),
1760
    );
1761
  }
1762

    
1763
  return $form;
1764
}
1765

    
1766
/**
1767
 * @return array
1768
 *   The form structure.
1769
 */
1770
function cdm_settings_layout_taxon() {
1771
  $collapsed = FALSE;
1772
  $form = array();
1773

    
1774
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1775

    
1776
  // --------- TABBED TAXON ------- //
1777
  $form['taxon_node'] = array(
1778
    '#type' => 'fieldset',
1779
    '#title' => t('Taxon node'),
1780
    '#collapsible' => TRUE,
1781
    '#collapsed' => TRUE,
1782
    '#description' => 'Taxa are organized in a classification tree by taxon nodes. Display of taxon node related information like states can be manged here.'
1783
  );
1784
  $form['taxon_node'][CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES] = array(
1785
    '#type' => 'checkbox',
1786
    '#title' => t('Show taxon node states'),
1787
    '#default_value' => variable_get(CDM_TAXONPAGE_TAXON_NODE_SHOW_STATES, 1),
1788
    '#description' => t('Show the taxon node states excluded, unplaced and placement doubtful.'),
1789
  );
1790

    
1791
  // --------- TABBED TAXON ------- //
1792
  $form['taxon_tabs'] = array(
1793
    '#type' => 'fieldset',
1794
    '#title' => t('Taxon tabs'),
1795
    '#collapsible' => TRUE,
1796
    '#collapsed' => TRUE,
1797
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1798
  );
1799

    
1800
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1801
    '#type' => 'checkbox',
1802
    '#title' => t('Tabbed taxon page'),
1803
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1804
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1805
  );
1806

    
1807
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1808
    '#type' => 'checkbox',
1809
    '#title' => t('Synonymy as tab'),
1810
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1811
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1812
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1813
  );
1814

    
1815
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1816
    '#type' => 'checkboxes',
1817
    '#title' => t('Section/Tab visibility') . ':',
1818
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1819
    '#options' => get_taxon_options_list()
1820
  );
1821

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

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

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

    
1874
  /* ======  TAXON_PROFILE ====== */
1875
  $form['taxon_profile'] = array(
1876
    '#type' => 'fieldset',
1877
    '#title' => t('Taxon profile (tab)'),
1878
    '#description' => t('<p>This section covers the settings related to the taxon
1879
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1880
    '#collapsible' => TRUE,
1881
    '#collapsed' => TRUE,
1882
  );
1883

    
1884
  // ---- PROFILE PICTURE ----//
1885

    
1886
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1887
    '#type' => 'fieldset',
1888
    '#tree' => TRUE,
1889
    '#title' => t('Taxon profile picture'),
1890
    '#collapsible' => TRUE,
1891
    '#collapsed' => FALSE,
1892
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1893
  );
1894

    
1895
  //FIXME migrate variables:
1896
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1897
  // FIXME
1898
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1899

    
1900
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1901

    
1902
  /*
1903
   * 'show' => 1,
1904
   * 'maxextend' => 184,
1905
   * 'media_uri_query' => ''
1906
   * 'custom_placeholder_image_on' => 1,
1907
   * 'custom_placeholder_image_fid' => ''
1908
   */
1909
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1910
    '#type' => 'checkbox',
1911
    '#title' => t('Enable profile picture'),
1912
    '#description' => t('Show the profile picture.'),
1913
    '#default_value' => $taxon_profile_image_settings['show'],
1914
  );
1915

    
1916
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1917
      '#type' => 'textfield',
1918
      '#tree' => TRUE,
1919
      '#title' => t('Profile picture maximum extend'),
1920
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1921
      '#field_suffix' => 'px',
1922
      '#maxlength' => 4,
1923
      '#size' => 4,
1924
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1925
  );
1926

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

    
1940
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1941
    '#type' => 'checkbox',
1942
    '#title' => t('Show the placeholder image'),
1943
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
1944
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
1945
  );
1946

    
1947
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
1948
      '#type' => 'checkbox',
1949
      '#title' => t('Use a custom placeholder image'),
1950
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
1951
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
1952
  );
1953

    
1954
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
1955
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1956
        '#type' => 'managed_file',
1957
        '#title' => t('Custom placeholder image file'),
1958
        '#progress_indicator' => 'bar',
1959
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
1960
    //       '#name' => 'custom_placeholder_image',
1961
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
1962
    );
1963

    
1964
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
1965
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
1966
      $url = file_create_url($profile_image_file->uri);
1967
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
1968
                '#type' => 'item',
1969
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
1970
      );
1971
    }
1972
  } else {
1973
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
1974
      '#type' => 'hidden',
1975
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
1976
    );
1977
  }
1978

    
1979
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
1980
  array_unshift($options, '-- DISABLED --');
1981
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
1982
    '#type' => 'select',
1983
    '#title' => t('Hide profile picture for higher ranks') . ':',
1984
    '#default_value' => variable_get('image_hide_rank', '0'),
1985
    '#options' => $options,
1986
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1987
  );
1988

    
1989
  // -- MEDIA THUMBNAILS -- //
1990
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
1991
  $form_title = 'Taxon Profile Images';
1992
  $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>';
1993
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
1994

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

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

    
2044

    
2045
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2046
  $profile_feature_tree = get_profile_feature_tree();
2047

    
2048
  if (isset($profile_feature_tree->root->childNodes)) {
2049

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

    
2092

    
2093
    $feature_list_layout_settings_disabled = FALSE;
2094

    
2095
    // creating helper object to retrieve the default settings
2096
    $featureNode = new stdClass();
2097
    $featureNode->term = new stdClass();
2098
    $featureNode->term->uuid="DEFAULT";
2099
    $featureNode->term->representation_L10n = "Default";
2100
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2101

    
2102
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2103

    
2104
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2105

    
2106
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2107
        $subform_id = $featureNode->term->uuid;
2108
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2109

    
2110
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2111

    
2112
        $form_feature_block_layout[$subform_id] = array(
2113
          '#type' => 'fieldset',
2114
          '#tree' => TRUE,
2115
          '#title' => $featureNode->term->representation_L10n,
2116
          '#collapsible' => FALSE,
2117
          '#collapsed' => FALSE,
2118
        );
2119
        if($featureNode->term->uuid == "DEFAULT"){
2120
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2121
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2122
          references</em> and <em>names in source</em> is only possible in the defaults';
2123
        }
2124

    
2125
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2126
          '#type' => 'select',
2127
          '#title' => 'List type',
2128
          '#default_value' => $feature_block_setting['as_list'],
2129
          '#options' => array(
2130
            'div' => 'not as list',
2131
            'ul' => 'bullet list',
2132
            'ol' => 'numbered list',
2133
            'dl' => 'definition list'
2134
          ),
2135
        );
2136

    
2137
        if($featureNode->term->uuid == "DEFAULT"){
2138
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2139
            '#type' => 'checkbox',
2140
            '#title' => t('Link to reference'),
2141
            '#default_value' => $feature_block_setting['link_to_reference'],
2142
          );
2143

    
2144
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2145
            '#type' => 'checkbox',
2146
            '#title' => 'Link to name used in source',
2147
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2148
          );
2149
        }
2150

    
2151
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2152
          '#type' => 'checkbox',
2153
          '#title' => 'Sources as content',
2154
          '#default_value' => $feature_block_setting['sources_as_content'],
2155
        );
2156

    
2157
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2158
          '#type' => 'checkbox',
2159
          '#title' => 'Put sources also as content to bibliography',
2160
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2161
        );
2162

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

    
2182
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2183
          '#type' => 'select',
2184
          '#title' => t('Element tag'),
2185
          '#options' => array(
2186
            'span' => 'span',
2187
            'div' => 'div',
2188
            'p' => 'p'
2189
          ),
2190
          '#default_value' => $feature_block_setting['element_tag'],
2191
        );
2192
        $form_feature_block_layout[$subform_id]['glue'] = array(
2193
          '#type' => 'textfield',
2194
          '#title' => t('Element glue'),
2195
          '#default_value' => $feature_block_setting['glue'],
2196
          '#size' => 10
2197
      );
2198

    
2199
      }
2200
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2201
    }
2202
  }
2203

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

    
2229

    
2230

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

    
2249
  );
2250

    
2251
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2252

    
2253
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2254
    '#type' => 'checkbox',
2255
    '#title' => t('Condensed distribution'),
2256
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2257
    '#description' => 'This option enables the display of a very compact representation
2258
    of the distribution which includes also information on the status.',
2259
  );
2260

    
2261
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2262
    '#type' => 'select',
2263
    '#title' => t('Condensed distribution recipe'),
2264
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2265
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2266
    '#description' => 'Recipe for creating the condensed distribution.',
2267
  );
2268

    
2269
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2270
    '#type' => 'textfield',
2271
    '#title' => t('Condensed distribution info path'),
2272
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2273
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2274
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2275
  );
2276

    
2277

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

    
2295
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2296
    '#type' => 'fieldset',
2297
    '#tree' => true,
2298
    '#title' => t('Distribution hierarchy style')
2299
  );
2300

    
2301
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2302
  foreach(array_keys($hierarchy_styles) as $level) {
2303
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2304
      '#type' => 'fieldset',
2305
      '#tree' => true,
2306
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2307
      '#attributes' => array('class' => array('fieldset-float'))
2308
    );
2309
    foreach ($hierarchy_styles[$level] as $key => $value) {
2310
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2311
        '#type' => 'textfield',
2312
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2313
        '#default_value' => $hierarchy_styles[$level][$key],
2314
        '#maxlength' => 4,
2315
        '#size' => 4
2316
      );
2317
    }
2318
  }
2319

    
2320
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2321
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2322
    '#type' => 'checkboxes',
2323
    '#title' => 'Omit area levels',
2324
    '#options' => $level_options,
2325
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2326
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2327
    Areas which belong to the selected area levels will be hidden in the portal.',
2328
  );
2329

    
2330
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2331
    '#type' => 'checkbox',
2332
    '#title' => t('Show TextData elements on top of the map'),
2333
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2334
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2335
      elements on top of the map. Otherwise all <code>TextData</code>
2336
      distribution elements will be listed below the other area elements.
2337
      This option is useful if you need to have descriptive texts for each
2338
      distribution map.'),
2339
  );
2340

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

    
2368
AbsenceTerm
2369
a	absent
2370
f	reported in error
2371
nf	native: reported in error
2372
if	introduced: reported in error
2373
cf	cultivated: reported in error
2374
ne	native: formerly native
2375
ie	introduced: formerly introduced
2376

    
2377
</pre>'),
2378
  );
2379

    
2380

    
2381
  /* ====== SYNONYMY ====== */
2382
  $form['taxon_synonymy'] = array(
2383
    '#type' => 'fieldset',
2384
    '#title' => t('Taxon synonymy (tab)'),
2385
    '#collapsible' => TRUE,
2386
    '#collapsed' => TRUE,
2387
    '#description' => t('This section covers the settings related to the taxon
2388
      <strong>synonymy</strong> tab.'),
2389
  );
2390

    
2391
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2392
    '#type' => 'checkbox',
2393
    '#title' => t('Accepted taxon on top of the synonymy'),
2394
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE_DEFAULT),
2395
    '#description' => t('If checked, the first homotypic taxon is a repetition
2396
      of the accepted taxon most likely with the full nomenclatural reference, 
2397
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2398
  );
2399

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

    
2410
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2411
    '#type' => 'textfield',
2412
    '#description' => 'Label for the secundum referenence.',
2413
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2414
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2415
    );
2416

    
2417
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2418
    '#type' => 'checkbox',
2419
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2420
      coming from a synonym link.'),
2421
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2422
    '#description' => t('Check this if after doing a search and clicking on a
2423
      synonym you want to see the "accept of" text for the accepted synonym.'),
2424
  );
2425

    
2426
  $form['taxon_synonymy']['taxon_relations'] = array(
2427
    '#type' => 'fieldset',
2428
    '#title' => t('Taxon relationships'),
2429
    '#collapsible' => FALSE,
2430
    '#collapsed' => FALSE
2431
  );
2432

    
2433
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2434
    '#type' => 'checkbox',
2435
    '#title' => t('Show taxon relations ships of accepted taxon'),
2436
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2437
    '#description' => t('If this option is enabled the synonymy will show the
2438
      below selected taxon relationships of accepted taxa.'),
2439
  );
2440

    
2441
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2442
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2443
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2444
    '#type' => 'checkboxes',
2445
    '#title' => t('Taxon relationship types') . ':',
2446
    '#description' => 'Only taxon relationships of the selected type will be displayed',
2447
    '#options' => $taxon_relationship_type_options,
2448
    '#default_value' => $taxon_relationship_type_defaults,
2449
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2450
  );
2451

    
2452
  $form['taxon_synonymy']['name_relations'] = array(
2453
    '#type' => 'fieldset',
2454
    '#title' => t('Name relationships'),
2455
    '#collapsible' => FALSE,
2456
    '#collapsed' => FALSE
2457
  );
2458

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

    
2479
  // ====== SPECIMENS ====== //
2480
  $form['taxon_specimens'] = array(
2481
    '#type' => 'fieldset',
2482
    '#title' => t('Taxon specimens (tab)'),
2483
    '#collapsible' => TRUE,
2484
    '#collapsed' => TRUE,
2485
    '#description' => t('This section covers the settings related to the taxon
2486
      <strong>specimens</strong> tab.'),
2487
  );
2488

    
2489
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2490

    
2491

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

    
2510
  $specimen_derivate_tree_options = get_array_variable_merged(CDM_SPECIMEN_DERIVATE_TREE_OPTIONS, CDM_SPECIMEN_DERIVATE_TREE_OPTIONS_DEFAULT);
2511
  $form['taxon_specimens'][CDM_SPECIMEN_DERIVATE_TREE_OPTIONS] = [
2512
    '#type' => 'fieldset',
2513
    '#tree' => TRUE,
2514
    '#title' => 'Derivate tree options',
2515
    '#collapsible' => FALSE,
2516
    '#collapsed' => FALSE,
2517
    '#description' => t('These setting only apply to the <i>Derivate tree</i> view mode (see above).'),
2518
  ];
2519

    
2520
  $form['taxon_specimens'][CDM_SPECIMEN_DERIVATE_TREE_OPTIONS]['field_unit_short_label'] = [
2521
    '#type' => 'checkbox',
2522
    '#title' => 'Field unit short label',
2523
    '#default_value' => $specimen_derivate_tree_options['field_unit_short_label'],
2524
    '#description' => t('Use the short collecting string for field units 
2525
    instead of the long summary label, which also includes location information.'),
2526
  ];
2527

    
2528
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2529
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2530
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2531
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2532
  }
2533
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2534
    '#type' => 'radios',
2535
    '#title' => t('Specimen description feature tree') . ':',
2536
    '#default_value' => $profile_feature_tree_uuid,
2537
    '#options' =>  $featureTrees['options'],
2538
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2539
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2540
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2541
    ),
2542
  );
2543

    
2544
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2545
  $form_title = t('Specimen media');
2546
  $form_description = t('Specimens may have media which is displayed at the
2547
     Specimen tab/section as a gallery. It is possible to configure the
2548
     thumbnails gallery here, however for configuring how a single media should
2549
     be displayed please go to !url.</p>',
2550
     array(
2551
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2552
     ));
2553
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2554

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

    
2566
  // Comment @WA: D7 form api does not support reset buttons,
2567
  // so to mimic the D5 reset button we add one like this.
2568
  $form['actions']['reset'] = array(
2569
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2570
    '#weight' => 1000,
2571
  );
2572
  return system_settings_form($form);
2573
}
2574

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

    
2594
/**
2595
 * @return array
2596
 *   The form structure.
2597
 */
2598
function cdm_settings_layout_search() {
2599

    
2600
  $form = array();
2601

    
2602
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2603

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

    
2615
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2616
      '#type' => 'checkbox',
2617
      '#title' => t('Ignore the chosen classification in simple search'),
2618
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2619
      '#description' => t('The simple search, which can be executed via the search block,
2620
          will by default search on the classification selected in the classification browser
2621
          selector. Set the tick if you want your portal to search on all classifications.'),
2622
  );
2623

    
2624
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2625
    '#type' => 'checkbox',
2626
    '#title' => t('Run simple search with free-text search backend.'),
2627
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2628
    '#description' => t('The simple search uses by default another search
2629
      backend as the advances search. By checking this option the simple search can be
2630
      configured to also use the free-text search backend.'),
2631
  );
2632

    
2633
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2634
    '#type' => 'checkbox',
2635
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2636
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2637
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2638
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2639
  );
2640

    
2641
  $form['search_settings'][CDM_SEARCH_RESULT_PAGE_SIZE] = array(
2642
    '#type' => 'textfield',
2643
    '#title' => t('Results per page') . ':',
2644
    '#default_value' => variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT),
2645
    '#description' => t('Number of results to display per page.'),
2646
  );
2647

    
2648
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2649
    '#type' => 'checkbox',
2650
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2651
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2652
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2653
  );
2654

    
2655
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2656
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2657
      '#type' => 'checkboxes',
2658
      '#title' => 'Search mode',
2659
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2660
          taxa by its common name and even taxa which have been used as misapplied names. The settings made here will affect the default
2661
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2662
          defaults set here.',
2663
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2664
      '#default_value' => $search_mode_default
2665
      );
2666

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

    
2672
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2673
  );
2674

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

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

    
2692
        '#description' => t('Activate the blast search for this portal, this works only with an existing blast database!'),
2693
    );
2694
    $form['blast_search_settings'][CDM_SEARCH_BLAST_SERVICE_URI] = array(
2695
        '#type' => 'textfield',
2696
        '#title' => t('Webservice URL for blast search') . ':',
2697
        '#default_value' => variable_get(CDM_SEARCH_BLAST_SERVICE_URI, 'http://130.133.70.28:9001/api/sequence'),
2698

    
2699
        '#description' => t('Enter the webservice URL for blast search'),
2700
    );
2701

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

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

    
2719

    
2720
/**
2721
 * @return array
2722
 *   The form structure.
2723
 */
2724
function cdm_settings_layout_name_page()
2725
{
2726

    
2727
  $form = array();
2728

    
2729

    
2730
  $form['name_relations'] = array(
2731
    '#type' => 'fieldset',
2732
    '#title' => t('Name relationship listings'),
2733
    '#collapsible' => FALSE,
2734
    '#collapsed' => FALSE
2735
  );
2736

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

    
2752
  $form[CDM_NAME_PAGE_SECTION_TAXA] = array (
2753
    '#type' => 'checkbox',
2754
    '#title' => 'Show the associated taxa section',
2755
    '#default_value' => variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT)
2756

    
2757
  );
2758

    
2759
  return system_settings_form($form);
2760
}
2761

    
2762
/**
2763
 * @return array
2764
 *   The form structure.
2765
 */
2766
function cdm_settings_layout_media() {
2767

    
2768
  $form = array();
2769

    
2770
  $form['media_settings'] = array(
2771
    '#type' => 'fieldset',
2772
    '#title' => t('Media settings'),
2773
    '#collapsible' => FALSE,
2774
    '#collapsed' => FALSE,
2775
    '#description' => 'This section covers layout settings for media pages.'
2776
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2777
  );
2778

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

    
2795
  // --- STANDARD_IMAGE_VIEWER ---- //
2796
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, CDM_MEDIA_GALLERY_VIEWER_DEFAULT) == CDM_MEDIA_GALLERY_VIEWER_SIMPLE) {
2797
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2798
      '#type' => 'fieldset',
2799
      '#tree' => true,
2800
      '#title' => t('Standard image viewer settings'),
2801
      '#collapsible' => FALSE,
2802
      '#collapsed' => FALSE,
2803
      );
2804

    
2805
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2806
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2807
      '#type' => 'checkbox',
2808
      '#title' => 'Show media representations',
2809
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2810
    );
2811

    
2812
  }
2813
  if(variable_get(CDM_MEDIA_GALLERY_VIEWER, 'default') == CDM_MEDIA_GALLERY_VIEWER_DEFAULT) {
2814
    $form['media_settings'][CDM_ADDITIONAL_MEDIA_COPYRIGHT] = [
2815
      '#type' => 'textarea',
2816
      '#title' => 'Additional media copyright statement',
2817
      '#default_value' => variable_get(CDM_ADDITIONAL_MEDIA_COPYRIGHT, NULL),
2818
      '#description' => 'This statement will be shown below the <b>Universal imgage viewer only</b>'
2819
    ];
2820
  }
2821

    
2822
  // @WA: D7 form api does not support reset buttons,
2823
  // so to mimic the D5 reset button we add one like this.
2824
  $form['actions']['reset'] = array(
2825
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2826
    '#weight' => 1000,
2827
  );
2828
  return system_settings_form($form);
2829
}
2830

    
2831
/**
2832
 * GEOSERVICE and Map settings.
2833
 *
2834
 *  @return array
2835
 *   The form structure.
2836
 */
2837
function cdm_settings_geo($form, &$form_state) {
2838

    
2839
  $current_geoserver_settings = get_edit_map_service_settings();
2840
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2841

    
2842

    
2843
  $form = array();
2844

    
2845
  $dummy_distribution_query = NULL;
2846
  if($map_distribution['map_type'] != 1){
2847
    // we need to apply a dummy query since the map service requires for image maps
2848
    // at least as and ad to be defined
2849
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2850
  }
2851

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

    
2868
  /*
2869
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2870
  );
2871
  */
2872

    
2873
  /*
2874
   * GEO SERVER
2875
   */
2876
  $form['edit_map_server'] = array(
2877
    '#type' => 'fieldset',
2878
    '#tree' => true,
2879
    '#title' => t('EDIT map service'),
2880
    '#collapsible' => TRUE,
2881
    '#collapsed' => TRUE,
2882
    '#description' => t('Configuration and selection of your geo server.
2883
      The Geo Server is responsible for generating the maps.'),
2884
  );
2885

    
2886
  $form['edit_map_server']['base_uri'] = array(
2887
    '#type' => 'select',
2888
    '#title' => t('EDIT map service') . ':',
2889
    '#default_value' => $current_geoserver_settings['base_uri'],
2890
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2891
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2892
  );
2893
  $form['edit_map_server']['version'] = array(
2894
      '#type' => 'select',
2895
      '#title' => t('Version') . ':',
2896
      '#default_value' => $current_geoserver_settings['version'],
2897
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2898
      '#description' => t('The version of the EDIT map services'),
2899
  );
2900

    
2901
  /*
2902
   * MAP SETTINGS
2903
   */
2904

    
2905
  $form[CDM_MAP_DISTRIBUTION] = array(
2906
    '#type' => 'fieldset',
2907
    '#tree' => TRUE,
2908
    '#title' => t('Maps settings'),
2909
    '#collapsible' => TRUE,
2910
    '#collapsed' => TRUE,
2911
    '#description' => t('General configuration for all map types.'),
2912
  );
2913

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

    
2931
  /*
2932
   * settings for the distribution map are used also for specimens map!!!!
2933
   */
2934

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

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

    
2964
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2965
    '#type' => 'select',
2966
    '#title' => 'Max zoom level',
2967
    '#default_value' => $map_distribution['maxZoom'],
2968
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
2969
  );
2970

    
2971
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2972
    '#type' => 'checkbox',
2973
    '#title' => 'Display area labels',
2974
    '#default_value' => $map_distribution['show_labels'],
2975
    '#description' => t('The map will show name labels of the areas'),
2976
  );
2977

    
2978
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2979
    '#type' => 'textfield',
2980
    '#title' => 'Map caption',
2981
    '#default_value' => $map_distribution['caption'],
2982
    '#description' => t('The caption will be shown below the map.'),
2983
  );
2984

    
2985
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2986
    '#type' => 'textfield',
2987
    '#title' => 'Distribution layer opacity',
2988
    '#default_value' => $map_distribution['distribution_opacity'],
2989
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2990
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2991
  );
2992

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

    
3011
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
3012
    '#type' => 'textfield',
3013
    '#title' => 'Width',
3014
    '#default_value' => $map_distribution['image_map']['width'],
3015
    '#maxlength' => 4,
3016
    '#size' => 4,
3017
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
3018
  );
3019

    
3020
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
3021
    '#type' => 'textfield',
3022
    '#title' => 'Background layer',
3023
    '#default_value' => $map_distribution['image_map']['base_layer'],
3024
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
3025
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
3026
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
3027
    )),
3028
  );
3029

    
3030
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3031
    '#type' => 'textfield',
3032
    '#title' => 'Background color',
3033
    '#default_value' => $map_distribution['image_map']['bg_color'],
3034
  );
3035

    
3036
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
3037
    '#type' => 'textfield',
3038
    '#title' => 'Background layer style',
3039
     // Only line color by now.
3040
    '#default_value' => $map_distribution['image_map']['layer_style'],
3041
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
3042
  );
3043

    
3044
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
3045
      '#type' => 'textfield',
3046
      '#title' => 'Projection',
3047
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
3048
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
3049
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
3050
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
3051
  );
3052

    
3053

    
3054
  // --- OpenLayers Settings --- //
3055
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3056
    '#type' => 'fieldset',
3057
    '#title' => 'OpenLayers settings',
3058
    '#tree' => TRUE,
3059
    '#collapsible' => TRUE,
3060
    '#collapsed' => !$open_layers_is_enabled,
3061
    '#description' => '',
3062
  );
3063

    
3064

    
3065
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3066
      '#type' => 'checkbox',
3067
      '#title' => 'Display outside max extent',
3068
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3069
      '#description' => t('Allows the map to display parts of the layers which are outside
3070
         the max extent if the aspect ratio of the map and of the baselayer
3071
         are not equal.'),
3072
  );
3073

    
3074

    
3075
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3076
      '#type' => 'checkbox',
3077
      '#title' => 'Show Layer Switcher',
3078
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3079
      '#description' => 'The Layer Switcher control displays a table of contents
3080
      for the map.  This allows the user interface to switch between
3081
      base layers and to show or hide overlays.  By default the switcher is
3082
      shown minimized on the right edge of the map, the user may expand it
3083
      by clicking on the handle.',
3084
  );
3085

    
3086
  if (!$open_layers_is_enabled) {
3087
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3088
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3089
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3090
  }
3091

    
3092
  // The default layer must always be enabled
3093
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3094
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3095

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

    
3126
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3127
    '#type' => 'checkboxes_preferred',
3128
    '#title' => 'Base Layers',
3129
    '#options' => $baselayer_options,
3130
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3131
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3132
  );
3133

    
3134
  $google_maps_api_key = null;
3135
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3136
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3137
  }
3138
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3139
    '#type' => 'textfield',
3140
    '#title' => 'Google Maps API Key',
3141
    '#default_value' => $google_maps_api_key,
3142
    '#description' => 'In order to use any of the Google map layers you need to provide 
3143
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3144
  );
3145

    
3146
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3147
    $map_distribution['openlayers']['custom_wms_base_layer'],
3148
    'Custom WMS base layer',
3149
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3150
    true // add projection settings
3151
    );
3152

    
3153
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3154
    $map_distribution['openlayers']['wms_overlay_layer'],
3155
    'WMS overlay layer',
3156
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3157
                You can actually combine multiple layers for this overlay. 
3158
                For details please refer to the wms query parameter <code>Layers</code> .'
3159
  );
3160

    
3161
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3162
    '#type' => 'checkbox',
3163
    '#title' => 'Enable overlay layer',
3164
    '#weight' => -100,
3165
    '#default_value' => isset($map_distribution['openlayers']['wms_overlay_layer']['is_enabled']) && $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3166
  );
3167

    
3168
  /*
3169
   * Map Legend
3170
   */
3171
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3172
    '#type' => 'fieldset',
3173
    '#title' => 'Map legend',
3174
    '#tree' => TRUE,
3175
    '#collapsible' => TRUE,
3176
    '#collapsed' => TRUE,
3177
    '#description' => 'Configure the maps legend.',
3178
  );
3179

    
3180
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3181
    '#type' => 'checkbox',
3182
    '#title' => 'Display a map legend',
3183
    '#default_value' => $map_distribution['legend']['show'],
3184
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3185
  );
3186

    
3187
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3188
    '#type' => 'textfield',
3189
    '#title' => 'Legend opacity',
3190
    '#default_value' => $map_distribution['legend']['opacity'],
3191
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3192
                         to 0.0 will be not much visible.',
3193
  );
3194

    
3195
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3196
    '#type' => 'textfield',
3197
    '#title' => 'Font size',
3198
    '#default_value' => $map_distribution['legend']['font_size'],
3199
    '#description' => 'Font size in pixels.',
3200
  );
3201

    
3202
  $fontStyles = array(
3203
    0 => "plane",
3204
    1 => "italic",
3205
  );
3206
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3207
    '#type' => 'select',
3208
    '#title' => 'Available font styles',
3209
    '#default_value' => $map_distribution['legend']['font_style'],
3210
    '#options' => $fontStyles,
3211
    '#description' => 'Select a font style for the map legend.',
3212
  );
3213

    
3214
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3215
    '#type' => 'textfield',
3216
    '#title' => 'Icon width',
3217
    '#default_value' => $map_distribution['legend']['icon_width'],
3218
    '#description' => 'Legend icon width in pixels.',
3219
  );
3220
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3221
    '#type' => 'textfield',
3222
    '#title' => 'Icon height',
3223
    '#default_value' => $map_distribution['legend']['icon_height'],
3224
    '#description' => 'Legend icon height in pixels.',
3225
  );
3226

    
3227
  // @WA: D7 form api does not support reset buttons,
3228
  // so to mimic the D5 reset button we add one like this.
3229
  $form['actions']['reset'] = array(
3230
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3231
    '#weight' => 1000,
3232
  );
3233

    
3234
  return system_settings_form($form);
3235
}
3236

    
3237
/**
3238
 * @param $default_settings
3239
 * @param $title
3240
 * @param $description
3241
 * @param bool $add_projection_settings
3242
 * @return array
3243
 */
3244
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3245
{
3246
  $form_elements = array(
3247
    '#type' => 'fieldset',
3248
    '#title' => $title,
3249
    '#tree' => TRUE,
3250
    '#collapsible' => FALSE,
3251
    '#collapsed' => FALSE,
3252
    '#description' => $description,
3253
  );
3254

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

    
3290
  if($add_projection_settings){
3291

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

    
3357
  }
3358
  return $form_elements;
3359
}
3360

    
3361

    
3362
/**
3363
 * @return array
3364
 *   The form structure.
3365
 */
3366
function cdm_settings_cache() {
3367

    
3368
  $form = array();
3369

    
3370
  $form['cache_settings'] = array(
3371
    '#type' => 'fieldset',
3372
    '#title' => t('Cache Settings'),
3373
    '#collapsible' => FALSE,
3374
    '#collapsed' => FALSE,
3375
    '#description' => t('<p>When caching is enabled all single taxon sites are
3376
      stored in an internal drupal cache doing the portal response of taxa pages
3377
      faster. This is possible because the sites are loaded from the cache and
3378
      are not created from scratch.</p>'),
3379
  );
3380

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

    
3393
  $form['cache_settings']['cdm_run_cache'] = array(
3394
    '#markup' => cdm_view_cache_site(),
3395
  );
3396

    
3397
  // @WA: D7 form api does not support reset buttons,
3398
  // so to mimic the D5 reset button we add one like this.
3399
  $form['actions']['reset'] = array(
3400
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3401
    '#weight' => 1000,
3402
  );
3403
  return system_settings_form($form);
3404
}
3405

    
3406
/**
3407
 * Walk and cache all taxon pages.
3408
 */
3409
function cdm_view_cache_site() {
3410

    
3411
  $out = '';
3412

    
3413
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3414

    
3415
  $request_params = array();
3416
  $request_params['class'] = "Taxon";
3417

    
3418
  $cdm_ws_page_taxa_url = cdm_compose_ws_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3419
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3420
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3421

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

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

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

    
3449

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

    
3470
function cdm_settings_layout_search_submit($form, &$form_state){
3471
  // the visibility of media thumbnails also affects the ui of the search results
3472
  // so reset the according session variable
3473
  //    1. in order to give the user immediate
3474
  //       feedback on potential setting changes
3475
  //    2. let refresh the default if it has changed
3476
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3477
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3478
  }
3479
}
3480

    
3481
/**
3482
 * Form validation handler for cdm_settings_general
3483
 *
3484
 * @param $form
3485
 * @param $form_state
3486
 */
3487
function cdm_settings_general_validate($form, &$form_state) {
3488

    
3489
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3490
    $form_state['values']['cdm_webservice_url'] .= '/';
3491
  }
3492

    
3493
}
3494

    
3495
/**
3496
 * Form submit handler for settings general.
3497
 *
3498
 * tasks performed:
3499
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3500
 *
3501
 * @param $form
3502
 * @param $form_state
3503
 */
3504
function cdm_settings_general_submit($form, &$form_state){
3505
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3506
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3507
  unset($_SESSION['cdm_login']);
3508
}
3509

    
3510
/**
3511
 * Form validation handler for cdm_settings_cache
3512
 */
3513
function cdm_settings_cache_validate($form, &$form_state) {
3514
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3515
    cache_clear_all(NULL, 'cache_cdm_ws');
3516
    // Better clear secref_cache since I can not be sure if the cache has not
3517
    // be used during this response.
3518
    cdm_api_secref_cache_clear();
3519
  }
3520

    
3521
}
3522

    
3523
/**
3524
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3525
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3526
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3527
 *  - version: the version, e.g.: v1.1
3528
 *
3529
 * @return array
3530
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3531
 */
3532
function get_edit_map_service_settings() {
3533

    
3534
  $settings = variable_get('edit_map_server', array(
3535
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3536
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3537
      )
3538
  );
3539

    
3540
  return $settings;
3541
}
3542

    
3543
/**
3544
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3545
 *
3546
 * @return string
3547
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3548
 */
3549
function get_edit_map_service_full_uri() {
3550
  $settings = get_edit_map_service_settings();
3551
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3552
}
3553

    
3554

    
3555
/**
3556
 * Returns the version number of the currently selected edit mapserver as a float
3557
 *
3558
 * @return float
3559
 *   The version number of the currently selected edit mapserver as a float.
3560
 *   Returns 0 on error.
3561
 */
3562
function get_edit_map_service_version_number() {
3563

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

    
3566
  $settings = get_edit_map_service_settings();
3567
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3568
  if (isset($matches[1])) {
3569
    // Convert string to float.
3570
    $version = 1 + $matches[1][0] - 1;
3571
    return $version;
3572
  }
3573
  else {
3574
    // Report error.
3575
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3576
        array(
3577
          '!version' => $settings['version'],
3578
          'warning')
3579
        )
3580
      );
3581
    return 0;
3582
  }
3583
}
3584

    
3585
/**
3586
 * Returns the array of selected items in a options array
3587
 *
3588
 * @param array $options
3589
 *   An options array as generated by a form element like checkoxes, select ...,
3590
 */
3591
function get_selection($options) {
3592
  $selection = array();
3593
  foreach ($options as $key=>$val) {
3594
    if (!empty($val)) {
3595
      $selection[] = $val;
3596
    }
3597
  }
3598
  return $selection;
3599
}
3600

    
3601

    
3602
/**
3603
 * Implements hook_element_info().
3604
 *
3605
 * Allows modules to declare their own Form API element types and specify their default values.
3606
 *
3607
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3608
 */
3609
function cdm_dataportal_element_info() {
3610
  $type['checkboxes_preferred'] = array(
3611
    '#input' => TRUE,
3612
    '#process' => array('checkboxes_preferred_expand'),
3613
    '#after_build' => array('checkboxes_preferred_after_build'),
3614
    '#theme' => array('checkboxes_preferred'),
3615
    // '#theme_wrapper' => array('form_element'),
3616
  );
3617
  return $type;
3618
}
3619

    
3620
/**
3621
 * #process callback function for the custom form element type 'checkbox_preferred'
3622
 *
3623
 *
3624
 */
3625
function checkboxes_preferred_expand($element, &$form_state, $form) {
3626

    
3627
  // First of all create checkboxes for each of the elements
3628
  $element = form_process_checkboxes($element);
3629

    
3630
  // compose the element name
3631
  $parents = array();
3632
  array_deep_copy($element['#parents'], $parents);
3633
  $parents[count($parents) -1 ] .= '_preferred';
3634
  $element_name = $parents[0];
3635
  for ($i=1; $i < count($parents); $i++){
3636
    $element_name .= '[' . $parents[$i] . ']';
3637
  }
3638

    
3639
  $children = element_children($element);
3640

    
3641
  $element['table_start'] = array(
3642
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3643
    '#weight' => -1,
3644
  );
3645

    
3646
  // prepare first part each of the table rows which contains the row label
3647
  $weight = 0;
3648
  foreach ($children as $key) {
3649
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3650
    $element[$key]['#weight'] = $weight;
3651
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3652
    $element[$key]['#suffix'] = '</td>';
3653
    unset($element[$key]['#title']);
3654
    $weight += 2;
3655
  }
3656
  $weight = 0;
3657

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

    
3681
  // end the table
3682
  $element['table_end'] = array(
3683
    '#markup' => '</table>',
3684
    '#weight' => $weight++,
3685
  );
3686

    
3687
  return $element;
3688
}
3689

    
3690
/**
3691
 * Theme function for the custom form field 'checkboxes_preferred'.
3692
 */
3693
function theme_checkboxes_preferred($variables) {
3694
  $element = $variables['element'];
3695
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3696
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3697
  $out .= drupal_render_children($element);
3698
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3699
  $out .= '</div>';
3700
  return $out;
3701
}
3702

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

    
3723
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3724

    
3725
  if ($_POST && count($_POST) > 0) {
3726
    // TODO use  $form_state['input'] instead of POST !!!
3727
    // First pass of form processing.
3728
    $parents = array();
3729
    array_deep_copy($element['#parents'], $parents);
3730
    $parents[count($parents) - 1] .= '_preferred';
3731
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3732
    $element['#value']['PREFERRED'] = $preferred_layer;
3733
//     $form_state[$parent_id] = $element['#value'];
3734
//     $form_state['values']['baselayers'] = $element['#value'];
3735
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3736
    $form_state_element_values = $element['#value'];
3737
  }
3738
  else {
3739
    // Second pass of form processing.
3740
    $preferred_layer = $element['#value']['PREFERRED'];
3741
  }
3742

    
3743
  // Also set the chosen value (not sure if this is good Drupal style ....).
3744
  foreach ($children = element_children($element) as $key) {
3745
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3746
      $element[$key]['#value'] = $preferred_layer;
3747
    }
3748
  }
3749
  // The default layer must always be enabled.
3750
  $element[$preferred_layer]['#value'] = $preferred_layer;
3751

    
3752
  return $element;
3753
}
3754

    
3755
function radios_prepare_options_suffix(&$elements){
3756

    
3757
  $childrenKeys = element_children($elements);
3758
  foreach($childrenKeys as $key){
3759
    if(!is_array($elements[$key]['#theme_wrappers'])){
3760
      $elements[$key]['#theme_wrappers'] = array();
3761
    }
3762
    if(isset($elements['#options_suffixes'][$key])){
3763
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3764
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3765
    }
3766
  }
3767
  return $elements;
3768

    
3769
}
3770

    
3771
/**
3772
 * TODO
3773
 * @param unknown $variables
3774
 */
3775
function theme_radio_options_suffix($variables) {
3776
  $element = $variables['element'];
3777
  if(isset($element['#options_suffix'])) {
3778
    $element['#children'] .= $element['#options_suffix'];
3779
  }
3780
  return $element['#children'];
3781
}
3782

    
3783

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

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