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
      UUID_NAMERELATIONSHIPTYPE_AVOIDS_HOMONYM_OF => UUID_NAMERELATIONSHIPTYPE_AVOIDS_HOMONYM_OF,
298
      UUID_NAMERELATIONSHIPTYPE_IS_NOT => UUID_NAMERELATIONSHIPTYPE_IS_NOT
299
    )
300
  )
301
);
302

    
303
define('CDM_NAME_RELATIONSHIP_LIST_TYPES', 'cdm_name_relationship_list_types');
304

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
592
  // ---- DEFAULTS settings
593

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

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

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

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

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

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

    
770
  $default_theme = variable_get('theme_default', NULL);
771

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

    
796
  // ---- END of DEFAULTS
797

    
798
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
799

    
800
  $feature_block_setting = null;
801

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

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

    
822
  return $feature_block_setting;
823
}
824

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

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

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

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

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

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

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

    
949
}
950

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

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

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

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

    
995
  $form['cdm_webservice']['cdm_webservice_url_ssl_verify'] = array(
996
    '#type' => 'checkbox',
997
    '#title' => t('Verify SSL/TLS certificate') . ':',
998
    '#description' => 'The ssl/tsl certificate of the CDM web service will not be verified if this options is disabled, . 
999
    This can be helpful if you are running your server with self-signed certificates. Since this is 
1000
    discouraged, disabling this options should only be done, if you are fully aware of the security consequences.',
1001
    '#default_value' => variable_get('cdm_webservice_url_ssl_verify', 1),
1002
  );
1003

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1263
  );
1264
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1265
      '#type' => 'select',
1266
      '#title' => t('Aggregation of taxon pictures') . ':',
1267
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1268
      '#options' => array(
1269
          0 => "Show only pictures of the current taxon",
1270
          1 => "Include pictures of taxonomic children",
1271
      ),
1272
      '#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."),
1273
  );
1274

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

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

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

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

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

    
1323

    
1324

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

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

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

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

    
1371
  $form['#submit'][] = 'cdm_settings_general_submit';
1372

    
1373
  return system_settings_form($form);
1374
}
1375

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

    
1386

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

    
1395
  $form = array();
1396

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

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

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

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

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

    
1441

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

    
1451
  $bibliography_settings = get_bibliography_settings(true);
1452

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

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

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

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

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

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

    
1530
  $nameRenderConfiguration = new NameRenderConfiguration();
1531

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

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

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

    
1608
  $nameRenderTemplateConfStatus = $nameRenderConfiguration->nameRenderTemplateConfigurationStatus();
1609

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

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

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

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

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

    
1686

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

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

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

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

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

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

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

    
1765
  return $form;
1766
}
1767

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

    
1776
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1777

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

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

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

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

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

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

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

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

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

    
1886
  // ---- PROFILE PICTURE ----//
1887

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

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

    
1902
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1903

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

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

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

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

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

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

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

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

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

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

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

    
2046

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

    
2050
  if (isset($profile_feature_tree->root->childNodes)) {
2051

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

    
2094

    
2095
    $feature_list_layout_settings_disabled = FALSE;
2096

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

    
2104
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2105

    
2106
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2107

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

    
2112
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2113

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

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

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

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

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

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

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

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

    
2201
      }
2202
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2203
    }
2204
  }
2205

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

    
2231

    
2232

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

    
2251
  );
2252

    
2253
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2254

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

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

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

    
2279

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

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

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

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

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

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

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

    
2379
</pre>'),
2380
  );
2381

    
2382

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

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

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

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

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

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

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

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

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

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

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

    
2493
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2494

    
2495

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

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

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

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

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

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

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

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

    
2598
/**
2599
 * @return array
2600
 *   The form structure.
2601
 */
2602
function cdm_settings_layout_search() {
2603

    
2604
  $form = array();
2605

    
2606
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2607

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

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

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

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

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

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

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

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

    
2676
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2677
  );
2678

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

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

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

    
2703
        '#description' => t('Enter the webservice URL for blast search'),
2704
    );
2705

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

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

    
2723

    
2724
/**
2725
 * @return array
2726
 *   The form structure.
2727
 */
2728
function cdm_settings_layout_name_page()
2729
{
2730

    
2731
  $form = array();
2732

    
2733

    
2734
  $form['name_relations'] = array(
2735
    '#type' => 'fieldset',
2736
    '#title' => t('Name relationship listings'),
2737
    '#collapsible' => FALSE,
2738
    '#collapsed' => FALSE
2739
  );
2740

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

    
2756
  $form[CDM_NAME_PAGE_SECTION_TAXA] = array (
2757
    '#type' => 'checkbox',
2758
    '#title' => 'Show the associated taxa section',
2759
    '#default_value' => variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT)
2760

    
2761
  );
2762

    
2763
  return system_settings_form($form);
2764
}
2765

    
2766
/**
2767
 * @return array
2768
 *   The form structure.
2769
 */
2770
function cdm_settings_layout_media() {
2771

    
2772
  $form = array();
2773

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

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

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

    
2809
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2810
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2811
      '#type' => 'checkbox',
2812
      '#title' => 'Show media representations',
2813
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2814
    );
2815

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

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

    
2835
/**
2836
 * GEOSERVICE and Map settings.
2837
 *
2838
 *  @return array
2839
 *   The form structure.
2840
 */
2841
function cdm_settings_geo($form, &$form_state) {
2842

    
2843
  $current_geoserver_settings = get_edit_map_service_settings();
2844
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2845

    
2846

    
2847
  $form = array();
2848

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

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

    
2872
  /*
2873
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2874
  );
2875
  */
2876

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

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

    
2905
  /*
2906
   * MAP SETTINGS
2907
   */
2908

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

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

    
2935
  /*
2936
   * settings for the distribution map are used also for specimens map!!!!
2937
   */
2938

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

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

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

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

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

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

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

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

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

    
3034
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3035
    '#type' => 'textfield',
3036
    '#title' => 'Background color',
3037
    '#default_value' => $map_distribution['image_map']['bg_color'],
3038
  );
3039

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

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

    
3057

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

    
3068

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

    
3078

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

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

    
3096
  // The default layer must always be enabled
3097
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3098
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3099

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

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

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

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

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

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

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

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

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

    
3199
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3200
    '#type' => 'textfield',
3201
    '#title' => 'Font size',
3202
    '#default_value' => $map_distribution['legend']['font_size'],
3203
    '#description' => 'Font size in pixels.',
3204
  );
3205

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

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

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

    
3238
  return system_settings_form($form);
3239
}
3240

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

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

    
3294
  if($add_projection_settings){
3295

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

    
3361
  }
3362
  return $form_elements;
3363
}
3364

    
3365

    
3366
/**
3367
 * @return array
3368
 *   The form structure.
3369
 */
3370
function cdm_settings_cache() {
3371

    
3372
  $form = array();
3373

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

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

    
3397
  $form['cache_settings']['cdm_run_cache'] = array(
3398
    '#markup' => cdm_view_cache_site(),
3399
  );
3400

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

    
3410
/**
3411
 * Walk and cache all taxon pages.
3412
 */
3413
function cdm_view_cache_site() {
3414

    
3415
  $out = '';
3416

    
3417
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3418

    
3419
  $request_params = array();
3420
  $request_params['class'] = "Taxon";
3421

    
3422
  $cdm_ws_page_taxa_url = cdm_compose_ws_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3423
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3424
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3425

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

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

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

    
3453

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

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

    
3485
/**
3486
 * Form validation handler for cdm_settings_general
3487
 *
3488
 * @param $form
3489
 * @param $form_state
3490
 */
3491
function cdm_settings_general_validate($form, &$form_state) {
3492

    
3493
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3494
    $form_state['values']['cdm_webservice_url'] .= '/';
3495
  }
3496

    
3497
}
3498

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

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

    
3525
}
3526

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

    
3538
  $settings = variable_get('edit_map_server', array(
3539
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3540
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3541
      )
3542
  );
3543

    
3544
  return $settings;
3545
}
3546

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

    
3558

    
3559
/**
3560
 * Returns the version number of the currently selected edit mapserver as a float
3561
 *
3562
 * @return float
3563
 *   The version number of the currently selected edit mapserver as a float.
3564
 *   Returns 0 on error.
3565
 */
3566
function get_edit_map_service_version_number() {
3567

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

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

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

    
3605

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

    
3624
/**
3625
 * #process callback function for the custom form element type 'checkbox_preferred'
3626
 *
3627
 *
3628
 */
3629
function checkboxes_preferred_expand($element, &$form_state, $form) {
3630

    
3631
  // First of all create checkboxes for each of the elements
3632
  $element = form_process_checkboxes($element);
3633

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

    
3643
  $children = element_children($element);
3644

    
3645
  $element['table_start'] = array(
3646
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3647
    '#weight' => -1,
3648
  );
3649

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

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

    
3685
  // end the table
3686
  $element['table_end'] = array(
3687
    '#markup' => '</table>',
3688
    '#weight' => $weight++,
3689
  );
3690

    
3691
  return $element;
3692
}
3693

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

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

    
3727
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3728

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

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

    
3756
  return $element;
3757
}
3758

    
3759
function radios_prepare_options_suffix(&$elements){
3760

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

    
3773
}
3774

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

    
3787

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

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