Project

General

Profile

Download (160 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
        //'includeOriginals' => 0
394
     )
395
  ));
396

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

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

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

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

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

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

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

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

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

    
593
  // ---- DEFAULTS settings
594

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

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

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

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

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

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

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

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

    
797
  // ---- END of DEFAULTS
798

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

    
801
  $feature_block_setting = null;
802

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

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

    
823
  return $feature_block_setting;
824
}
825

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

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

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

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

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

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

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

    
950
}
951

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1325

    
1326

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

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

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

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

    
1373
  $form['#submit'][] = 'cdm_settings_general_submit';
1374

    
1375
  return system_settings_form($form);
1376
}
1377

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

    
1388

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

    
1397
  $form = array();
1398

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

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

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

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

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

    
1443

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

    
1453
  $bibliography_settings = get_bibliography_settings(true);
1454

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

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

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

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

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

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

    
1532
  $nameRenderConfiguration = new NameRenderConfiguration();
1533

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

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

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

    
1610
  $nameRenderTemplateConfStatus = $nameRenderConfiguration->nameRenderTemplateConfigurationStatus();
1611

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

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

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

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

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

    
1688

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

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

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

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

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

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

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

    
1767
  return $form;
1768
}
1769

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

    
1778
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1779

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

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

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

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

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

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

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

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

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

    
1888
  // ---- PROFILE PICTURE ----//
1889

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

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

    
1904
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1905

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

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

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

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

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

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

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

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

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

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

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

    
2048

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

    
2052
  if (isset($profile_feature_tree->root->childNodes)) {
2053

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

    
2096

    
2097
    $feature_list_layout_settings_disabled = FALSE;
2098

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

    
2106
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2107

    
2108
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2109

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

    
2114
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2115

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

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

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

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

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

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

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

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

    
2203
      }
2204
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2205
    }
2206
  }
2207

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

    
2233

    
2234

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

    
2253
  );
2254

    
2255
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2256

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

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

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

    
2281

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

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

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

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

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

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

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

    
2381
</pre>'),
2382
  );
2383

    
2384

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

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

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

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

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

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

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

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

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

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

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

    
2495
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2496

    
2497

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

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

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

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

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

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

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

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

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

    
2606
  $form = array();
2607

    
2608
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2609

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2725

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

    
2733
  $form = array();
2734

    
2735

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

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

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

    
2763
  );
2764

    
2765
  return system_settings_form($form);
2766
}
2767

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

    
2774
  $form = array();
2775

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

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

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

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

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

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

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

    
2845
  $current_geoserver_settings = get_edit_map_service_settings();
2846
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2847

    
2848

    
2849
  $form = array();
2850

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

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

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

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

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

    
2907
  /*
2908
   * MAP SETTINGS
2909
   */
2910

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

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

    
2937
  /*
2938
   * settings for the distribution map are used also for specimens map!!!!
2939
   */
2940

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

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

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

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

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

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

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

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

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

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

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

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

    
3059

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

    
3070

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

    
3080

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
3240
  return system_settings_form($form);
3241
}
3242

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

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

    
3296
  if($add_projection_settings){
3297

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

    
3363
  }
3364
  return $form_elements;
3365
}
3366

    
3367

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

    
3374
  $form = array();
3375

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

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

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

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

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

    
3417
  $out = '';
3418

    
3419
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3420

    
3421
  $request_params = array();
3422
  $request_params['class'] = "Taxon";
3423

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

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

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

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

    
3455

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

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

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

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

    
3499
}
3500

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

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

    
3527
}
3528

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

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

    
3546
  return $settings;
3547
}
3548

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

    
3560

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

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

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

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

    
3607

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

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

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

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

    
3645
  $children = element_children($element);
3646

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

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

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

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

    
3693
  return $element;
3694
}
3695

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

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

    
3729
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3730

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

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

    
3758
  return $element;
3759
}
3760

    
3761
function radios_prepare_options_suffix(&$elements){
3762

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

    
3775
}
3776

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

    
3789

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

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