Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / settings.php @ c6c196ff

History | View | Annotate | Download (150 KB)

1
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6

    
7

    
8
  // TODO Genus UUID.
9

    
10
  define('TAXONTREE_RANKLIMIT', 'cdm_taxontree_ranklimit');
11
  define('TAXONTREE_RANKLIMIT_DEFAULT', 0);
12
  define('CDM_TAXONOMICTREE_UUID', 'cdm_taxonomictree_uuid');
13
  define('CDM_TAXONTREE_INCLUDES', 'taxontree_includes');
14

    
15
  define('NO_SORT', -1);
16
  define('SORT_HIERARCHICAL', 9);
17

    
18
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
19

    
20
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
21
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
22

    
23
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
24
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
25
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
26
  define('CDM_DATAPORTAL_TAXON_AUTO_SUGGEST', 0);
27
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 1);
28
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
29
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
30
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
31
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
32

    
33
  /* annotationTypeKeys */
34
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
35
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
36
    $annotationTypeKeys = array_flip($annotationTypeKeys);
37

    
38
    // Technical annotation are off by default.
39
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
40
    $annotationTypeKeys = array_flip($annotationTypeKeys);
41
    // Additional value for the NULL case.
42
    $annotationTypeKeys[] = 'NULL_VALUE';
43
  }
44
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
45

    
46
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
47
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
48
    'enabled' => 0,
49
    'key_format' => 'ALPHA'
50
  )));
51

    
52
  /* taxonRelationshipTypes */
53
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(array(UUID_MISAPPLIED_NAME_FOR, UUID_INVALID_DESIGNATION_FOR)));
54

    
55

    
56
  /* ---- MAP SETTING CONSTANTS ---- */
57
  /**
58
   * @var array of URIs eg. http://edit.africamuseum.be"
59
   *   An options array
60
   */
61
  define('EDIT_MAPSERVER_URI', serialize(
62
      array(
63
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
64
      )
65
    )
66
  );
67
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
68
  /**
69
   * @var array of versions eg. "v1.2"
70
   *   An options array
71
   */
72
  define('EDIT_MAPSERVER_VERSION', serialize(
73
      array(
74
//        'v1' => 'v1' ,           // no longer recommended
75
//        'v1.1' => 'v1.1',        // no longer recommended
76
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
77
        'v1.2' => 'v1.2',
78
        'v1.3_dev' => 'v1.3_dev (not recommended)',
79
        'v1.4_dev' => 'v1.4_dev (experimental features)'
80
      )
81
    )
82
  );
83
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
84
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
85

    
86
    // --- Taxon profile settings --- /
87
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
88
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
89
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
90
      array(
91
          'show' => 0,
92
          'maxextend' => 184,
93
          'media_uri_query' => '',
94
          'custom_placeholder_enabled' => 1,
95
          'custom_placeholder_image_on' => 0,
96
          'custom_placeholder_image_fid' => ''
97
      )
98
    )
99
  );
100

    
101

    
102
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
103

    
104
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
105
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
106
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
107
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
108
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
109

    
110
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
111
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
112
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
113
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
114

    
115
/**
116
 * Returns the array of implemented taxon page tabs.
117
 * The array has fixed integer keys which must not be changed.
118
 */
119
function get_taxon_tabs_list() {
120
  return array(
121
    0 => 'General',
122
    1 => 'Synonymy',
123
    2 => 'Images',
124
    3 => 'Specimens',
125
    4 => 'Keys',
126
    5 => 'Experts',
127
  );
128
}
129

    
130
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
131
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
132
  array(
133
    'general' => '-3',
134
    'synonymy' => '-2',
135
    'images' => '0',
136
    'specimens' => '1',
137
    'keys' => '3',
138
    'experts' => '5',
139
    )
140
));
141

    
142

    
143
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
144
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
145
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
146
  array(
147
    'general' => null,
148
    'synonymy' => null,
149
    'images' => null,
150
    'specimens' => null,
151
    'keys' => null,
152
    'experts' => null,
153
  )
154
));
155

    
156
$taxon_tab_options = get_taxon_tabs_list();
157
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
158

    
159
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
160

    
161
/**
162
 * @todo document this function.
163
 */
164
function get_taxon_options_list() {
165
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
166
  foreach ($taxon_tab_options as $key => $value) {
167
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
168
  }
169
  return $taxon_tab_options;
170

    
171
}
172

    
173
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
174
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
175
  array(
176
      'ZoologicalName' => array(
177
        'namePart' => array('name' => TRUE),
178
        'nameAuthorPart' => array('name' => TRUE),
179
        'referencePart' => array('authors' => TRUE),
180
        'microreferencePart' => array('microreference' => TRUE),
181
        'secReferencePart' => array('secReference' => TRUE,),
182
        'statusPart' => array('status' => TRUE),
183
        'descriptionPart' => array('description' => TRUE),
184
      ),
185
      'BotanicalName'=> array(
186
        'namePart' => array('name' => TRUE),
187
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
188
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
189
        'secReferencePart' => array('secReference' => TRUE,),
190
        'referenceYearPart' => array('reference.year' => TRUE),
191
        'statusPart' => array('status' => TRUE),
192
        'descriptionPart' => array('description' => TRUE),
193
      ),
194
     '#DEFAULT' => array(
195
        'namePart' => array(
196
            'name' => TRUE
197
        ),
198
        'nameAuthorPart' => array(
199
            'name' => TRUE,
200
            'authors' => TRUE
201
        ),
202
       'referencePart' => array(
203
         'reference' => TRUE
204
        ),
205
       'secReferencePart' => array(
206
         'secReference' => TRUE,
207
       ),
208
       'microreferencePart' => array(
209
          'microreference' => TRUE,
210
        ),
211
       'statusPart' => array(
212
          'status' => TRUE,
213
        ),
214
       'descriptionPart' => array(
215
          'description' => TRUE,
216
        ),
217
      )
218
    )
219
  )
220
);
221
  define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
222
    array(
223
      'ZoologicalName' => array(
224
        'namePart' => array('name' => TRUE),
225
        'nameAuthorPart' => array('name' => TRUE),
226
        'referencePart' => array('authors' => TRUE),
227
        'microreferencePart' => array('microreference' => TRUE),
228
        'statusPart' => array('status' => TRUE),
229
        'descriptionPart' => array('description' => TRUE),
230
      ),
231
      'BotanicalName'=> array(
232
        'namePart' => array('name' => TRUE),
233
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
234
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
235
        'referenceYearPart' => array('reference.year' => TRUE),
236
        'statusPart' => array('status' => TRUE),
237
        'descriptionPart' => array('description' => TRUE),
238
      ),
239
      '#DEFAULT' => array(
240
        'namePart' => array(
241
          'name' => TRUE
242
        ),
243
        'nameAuthorPart' => array(
244
          'name' => TRUE,
245
          'authors' => TRUE
246
        ),
247
        'referencePart' => array(
248
          'reference' => TRUE
249
        ),
250
        'microreferencePart' => array(
251
          'microreference' => TRUE,
252
        ),
253
        'statusPart' => array(
254
          'status' => TRUE,
255
        ),
256
        'descriptionPart' => array(
257
          'description' => TRUE,
258
        ),
259
      )
260
    )
261
  )
262
  );
263

    
264
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
265
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
266
  array (
267
    'taxon_page_title,polytomousKey'=> array(
268
        'namePart' => array('#uri' => TRUE),
269
      ),
270
    'not_in_current_classification' => array(
271
     'nameAuthorPart' => TRUE,
272
     'referencePart' => TRUE,
273
     'statusPart' => TRUE,
274
     'secReferencePart' => TRUE,
275
    ),
276
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
277
      'nameAuthorPart' => array('#uri' => TRUE),
278
      'referencePart' => TRUE,
279
      'statusPart' => TRUE,
280
      'descriptionPart' => TRUE,
281
    ),
282
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
283
      'nameAuthorPart' => array('#uri' => TRUE),
284
      'referencePart' => TRUE,
285
      'statusPart' => TRUE,
286
      'secReferencePart' => TRUE,
287
      'descriptionPart' => TRUE,
288
    ),
289
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
290
      'nameAuthorPart' => array('#uri' => TRUE),
291
      'referencePart' => TRUE,
292
      'statusPart' => TRUE,
293
      /* no sec ref in this case, misapplied names are
294
       * de-duplicated and the sec ref is shown as footnote */
295
      'descriptionPart' => TRUE,
296
    ),
297
    'homonym'=> array(
298
        'nameAuthorPart' => array('#uri' => TRUE),
299
        'referenceYearPart' => TRUE,
300
        'statusPart' => TRUE,
301
    ),
302
    'acceptedFor,typedesignations,list_of_taxa' => array(
303
        'nameAuthorPart' => array('#uri' => TRUE),
304
        'referencePart' => TRUE,
305
      ),
306
    '#DEFAULT' => array(
307
        'nameAuthorPart' => array('#uri' => TRUE),
308
        'referencePart' => TRUE,
309
     )
310
  )
311
));
312
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
313
  array (
314
    'taxon_page_title,polytomousKey'=> array(
315
      'namePart' => array('#uri' => TRUE),
316
    ),
317
    'taxon_page_synonymy,related_taxon'=> array(
318
      'nameAuthorPart' => array('#uri' => TRUE),
319
      'referencePart' => TRUE,
320
      'statusPart' => TRUE,
321
      'descriptionPart' => TRUE,
322
    ),
323
    'homonym'=> array(
324
      'nameAuthorPart' => array('#uri' => TRUE),
325
      'referenceYearPart' => TRUE,
326
    ),
327
    'acceptedFor,typedesignations,list_of_taxa' => array(
328
      'nameAuthorPart' => array('#uri' => TRUE),
329
      'referencePart' => TRUE,
330
    ),
331
    '#DEFAULT' => array(
332
      'nameAuthorPart' => array('#uri' => TRUE),
333
      'referencePart' => TRUE,
334
    )
335
  )
336
));
337

    
338
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
339
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
340
    // to unset a default enntry set the value to 0
341
    array(
342
      'doTaxa'=>'doTaxa',
343
      'doSynonyms' => 'doSynonyms',
344
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
345
      'doMisappliedNames' => 'doMisappliedNames'
346
    )
347
  )
348
);
349

    
350
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
351

    
352
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
353
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
354

    
355
/* Gallery variables. */
356
$gallery_settings = array(
357
    "cdm_dataportal_show_taxon_thumbnails" => 1,
358
    "cdm_dataportal_show_synonym_thumbnails" => 0,
359
    "cdm_dataportal_show_thumbnail_captions" => 1,
360
    "cdm_dataportal_media_maxextend" => 120,
361
    "cdm_dataportal_media_cols" => 3,
362
    "cdm_dataportal_media_maxRows" => 1,
363
);
364

    
365
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
366
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
367
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
368
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
369
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
370
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
371
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
372
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
373
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
374
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
375
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
376
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
377

    
378
/**
379
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
380
 * the snonymy.
381
 *
382
 * @var string
383
 */
384
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
385

    
386
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
387
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
388
    array(
389
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
390
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
391
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
392
    )
393
  )
394
);
395

    
396
/**
397
 * The drupal variable for the configuration of the information aggregation along
398
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
399
 *    - direct: the uuids of the taxon relationship types to take into account in invers
400
 *      direction.
401
 *    - invers: the uuids of the taxon relationship types to take into account in direct
402
 *      direction.
403
 *
404
 * @var String
405
 */
406
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
407
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
408
    array(
409
        'direct'=>array(),
410
        'invers'=>array()
411
     )
412
   ));
413
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
414
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
415
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
416

    
417
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
418
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
419
      array(
420
      'filter_rules' => array(
421
        'statusOrderPreference' => 0,
422
        'subAreaPreference' => 0,
423
      ),
424
      'hiddenAreaMarkerType' => array()
425
     )
426
));
427

    
428
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
429
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
430
  "level_0" => array(
431
    'label_suffix' => ':',
432
    'status_glue' => '',
433
    'item_glue' => ' ',
434
    'item_group_prefix' => '',
435
    'item_group_postfix' => ''
436
  ),
437
  "level_1" => array(
438
    'label_suffix' => '',
439
    'status_glue' => '', // '&#8210; '
440
    'item_glue' => '; ',
441
    'item_group_prefix' => ', ',
442
    'item_group_postfix' => ''
443
  ),
444
  "level_2" => array(
445
    'label_suffix' => '',
446
    'status_glue' => '', // '&#8210; '
447
    'item_glue' => ', ',
448
    'item_group_prefix' => ' (',
449
    'item_group_postfix' => ')'
450
  )
451
)));
452

    
453
/**
454
 * Constant for the drupal variable key distribution_map_visibility
455
 *
456
 * possible values:
457
 *  - never
458
 *  - automatic
459
 *  - always
460
 */
461
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
462
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
463

    
464
/**
465
 * Constant for the drupal variable key specimen_map_visibility
466
 *
467
 * possible values:
468
 *  - never
469
 *  - automatic
470
 *  - always
471
 */
472
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
473
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
474

    
475
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
476
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
477
    array(
478
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
479
        'includeOccurrences' => 0,
480
        'includeTaxonNameDescriptions' => 0
481
     )
482
  ));
483

    
484
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
485
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
486
  // needs to be merged with user setting by drupal_array_merge_deep()
487
  // 'width' => 512, // optimum size for OSM layers is 512
488
  // 'height' => 512 / 2, // optimum size for OSM layers 256
489
  'aspect_ratio' => 2,
490
  'bbox' => '', // empty to allow automatic zooming to extend
491
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
492
  'show_labels' => FALSE,
493
  'caption' => '',
494
  'distribution_opacity' => '0.5',
495
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
496
  'image_map' => array(
497
    'base_layer' => '', // none, formerly this was cyprusdivs
498
    'bg_color' => '1874CD',
499
    'layer_style' => 'ffffff,606060,,',
500
  ),
501
  'openlayers' => array(
502
    'base_layers' =>  array(
503
      // A layer MUST NOT BE SET in the defaults,
504
      // otherwise it can not be overidden by the user settings:
505
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
506
      // it is sufficient to define the preferred layer,
507
      // since it will automatically be enabled:
508
      'PREFERRED' => 'mapproxy_vmap0'),
509
    'custom_wms_base_layer' => array(
510
      'name' => NULL,
511
      'url' => NULL,
512
      'params' =>  NULL,
513
      'projection' => NULL,
514
      'proj4js_def' => NULL,
515
      'max_extent' => NULL,
516
      'units' => NULL
517
    ),
518
    'show_layer_switcher' => TRUE,
519
    'display_outside_max_extent' => FALSE,
520
    'google_maps_api_key' => NULL,
521
  ),
522
  'legend' => array(
523
    'show' => TRUE,
524
    'opacity' => '0.5',
525
    'font_size' => 10,
526
    'font_style' => FALSE,
527
    'icon_width' => 35,
528
    'icon_height' => 15
529
  )
530
)));
531

    
532
/**
533
 * Merges the named array variable with the array of defaults.
534
 *
535
 * IMPORTANT: The array keys must be strings. When the keys are integers
536
 * the merging will not take place for these entities. Number keyed entities
537
 * are just appended to the result array.
538
 *
539
 * @param string $variable_name
540
 *     The variable name
541
 * @param string | array $default
542
 *     The array containing the default values either as array or serialized as string.
543
 *     Unserialization is cared for if necessary
544
 * @return array
545
 *     The merged array as returned by drupal_array_merge_deep()
546
 *
547
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
548
 * TODO force $default being an array
549
 */
550
function get_array_variable_merged($variable_name, $default){
551

    
552
    // unserialize if nessecary
553
    if(!is_array($default)){
554
      $default = unserialize($default);
555
    }
556
    $variable = variable_get($variable_name, array());
557
    $result = drupal_array_merge_deep($default, $variable);
558
    return $result;
559
}
560

    
561
/**
562
 * @todo document this function.
563
 */
564
function getGallerySettings($gallery_config_form_name) {
565
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
566
}
567

    
568
/**
569
 * Returns the string representation of the default tab.
570
 *
571
 * @param bool $returnTabIndex
572
 *   Defaults to FALSE, if set true this function will return the index number
573
 *   of the default tab. (used to supply default values to form elements).
574
 */
575
function get_default_taxon_tab($returnTabIndex = FALSE) {
576

    
577
  global $user;
578
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
579
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
580
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
581
  // Get the user value if the used has chosen to overwrite the system settings.
582
  $user_tab_on = variable_get($user_tab_active, FALSE);
583
  if ($user_tab_on) {
584
    $user_value = variable_get($user_tab, 0);
585
    $index_value = $user_value;
586
    // Get the system value.
587
  }
588
  else {
589
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
590
    $index_value = $system_value;
591
  }
592

    
593
  // Return the index value or the string representation.
594
  if ($returnTabIndex) {
595
    return $index_value;
596
  }
597
  else {
598
    return ($values[$index_value]);
599
  }
600
}
601

    
602
/**
603
 * Provides the feature block settings for a specific feature which matches the $feature_uuid parameter.
604
 *
605
 * In case specifically configured settings array, like these which are stored in the drupal variables, is missing
606
 * one or more fields these fields are taken from the default. That is the specific settings are always merges
607
 * with the default.
608
 *
609
 * Note: These settings only apply to feature blocks which do not have a special rendering
610
 * the specially handled features (e.g.: Distribution, CommonNames) may make use of the
611
 * 'special' element of the settings
612
 *
613
 * @param $feature_uuid
614
 *   The uuid string representation of the feature to return the settings for
615
 *
616
 * @return array
617
 *  an associative array of settings, with the following fields:
618
 *    - as_list: string
619
 *        this setting will be used in compose_feature_block_wrap_elements() as $enclosing_tag
620
 *        possible values are:
621
 *          div: not as list,
622
 *          ul: as bullet list,
623
 *          ol: as numbered list,
624
 *          dl: as definition list
625
 *        The tag used for the inner element, thus depends on the value of this field. The
626
 *        inner tag name can be retrieved by the function cdm_feature_block_element_tag_name()
627
 *    - link_to_reference: boolean,
628
 *        render the reference as link, ignored if the element is NOT a DescriptionElementSource
629
 *    - link_to_name_used_in_source": boolean
630
 *        whether to show name in source information as link which will point to the according name page
631
 *    - sources_as_content (boolean)
632
 *        TRUE (int: 1):
633
 *          1. If element is of the CDM type TextData and the text is not empty the source references will be
634
 *             appended in brackets like "text (source references)". If the original source has name in source
635
 *             information it will be appended to the citation string,
636
 *             like : "(citation, as name in source; citation, as name in source)"
637
 *          2. if the text of the TextData is empty, the original source citations are the only content
638
 *             (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
639
 *             prepended to the citation string like: "name in source: citation"
640
 *        FALSE (int: 0):
641
 *          Original sources are put into the bibliography(=references) pseudo feature block. If the original source
642
 *          citations are the only content, the resulting feature block content would only consist of footnotes.
643
 *          In this case the display of the respective feature block is suppressed.
644
 *          TODO if the bibliography is not enabled the sources will be treated as footnotes like annotations,
645
 *               in future however they will in this case be shown in a separate references section for each
646
 *               feature block.
647
 *    - sources_as_content_to_bibliography  (boolean)
648
 *        Only valid if sources_as_content == TRUE, will cause the sources to be also shown
649
 *        in the bibliography.
650
 *    - sort_elements
651
 *        whether and how to sort the elements
652
 *        possible values are the constants SORT_ASC, SORT_DESC, NULL,
653
 *        some feature types (Distribution) also support: SORT_HIERARCHICAL (
654
 *        TODO option to exclude levels, put in special?,
655
 *        TODO make use of this setting in compose_feature_block_wrap_elements())
656
 *    - element_tag
657
 *        specifies the tag to be used for creating the elements, only applies if "as_list" == 'div'
658
 *        possible values are span | div. the proper inner tag name can be retrieved by the function
659
 *        cdm_feature_block_element_tag_name()
660
 *    - special: array()
661
 *        an array with further settings, this field can be used for special
662
 *        settings for specialized rendering like for distributions
663
 *  }
664
 *
665
 */
666
function get_feature_block_settings($feature_uuid = 'DEFAULT') {
667
  // the default must conform to the default parameter values of
668
  // compose_feature_block_wrap_elements() : $glue = '', $sort = FALSE, $enclosing_tag = 'ul'
669
  // compose_description_element_text_data() : asListElement = NULL
670

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

    
673
  // ---- DEFAULTS settings
674

    
675
  // only needed as final option, when the settings are not having a default
676
  $default = array(
677
    'DEFAULT' => array(
678
      'as_list' => 'div',
679
      'link_to_reference' => 0,
680
      'link_to_name_used_in_source' => 1,
681
      'sources_as_content' => 0,
682
      'sources_as_content_to_bibliography' => 0,
683
      'sort_elements' => NO_SORT,
684
      'glue' => '',
685
      'element_tag' => NULL
686
    ),
687
    // settings for pseudo feature bibliography
688
    // only hard coded here
689
    'BIBLIOGRAPHY' => array(
690
      'as_list' => 'div',
691
      'link_to_reference' => 0,
692
      'link_to_name_used_in_source' => 1,
693
      'sources_as_content' => 0,
694
      'sources_as_content_to_bibliography' => 0,
695
      'sort_elements' => NO_SORT,
696
      'glue' => '',
697
      'element_tag' => NULL
698
    )
699
  );
700

    
701
  // will be used as preset in the settings
702
  $other_themes_default = array(
703
    'DEFAULT' => array(
704
      'as_list' => 'div',
705
      'link_to_reference' => 0,
706
      'link_to_name_used_in_source' => 1,
707
      'sources_as_content' => 0,
708
      'sources_as_content_to_bibliography' => 0,
709
      'sort_elements' => NO_SORT,
710
      'glue' => '',
711
      'element_tag' => NULL
712
    ),
713
    UUID_CITATION => array(
714
      'as_list' => 'div',
715
      'link_to_reference' => 0,
716
      'link_to_name_used_in_source' => 0,
717
      'sources_as_content' => 1,
718
      'sources_as_content_to_bibliography' => 0,
719
      'sort_elements' => SORT_ASC,
720
      'glue' => '',
721
      'element_tag' => 'div'
722
    ),
723
    UUID_DISTRIBUTION => array(
724
      'as_list' => 'div', // currently ignored
725
      'link_to_reference' => 0,
726
      'link_to_name_used_in_source' => 0,
727
      'sources_as_content' => 0,
728
      'sources_as_content_to_bibliography' => 0,
729
      'sort_elements' => NO_SORT, // will cause ...
730
      'glue' => '',
731
      'element_tag' => 'div',
732
      'special' => array()
733
    ),
734
    UUID_COMMON_NAME => array(
735
      'as_list' => 'div',
736
      'link_to_reference' => 0,
737
      'link_to_name_used_in_source' => 1,
738
      'sources_as_content' => 0,
739
      'sources_as_content_to_bibliography' => 0,
740
      'sort_elements' => NO_SORT,
741
      'glue' => '',
742
      'element_tag' => 'span'
743
    ),
744
  );
745

    
746
  // ---- Special DEFAULTS for existing portals
747
  // TODO:
748
  // this can be removed once the feature block
749
  // settings have been deployed for the first time to these portals
750

    
751
  $cichorieae_default = array(
752
    'DEFAULT' => array(
753
      'as_list' => 'div',
754
      'link_to_reference' => 1,
755
      'link_to_name_used_in_source' => 1,
756
      'sources_as_content' => 1,
757
      'sources_as_content_to_bibliography' => 0,
758
      'sort_elements' => NO_SORT,
759
      'glue' => '',
760
      'element_tag' => 'div'
761
    ),
762
    UUID_CITATION => array(
763
      'as_list' => 'div',
764
      'link_to_reference' => 0,
765
      'link_to_name_used_in_source' => 0,
766
      'sources_as_content' => 1,
767
      'sources_as_content_to_bibliography' => 0,
768
      'sort_elements' => SORT_ASC,
769
      'glue' => '',
770
      'element_tag' => 'div'
771
    ),
772
    UUID_CHROMOSOMES_NUMBERS => array(
773
      'as_list' => 'ul',
774
      'link_to_reference' => 1,
775
      'link_to_name_used_in_source' => 1,
776
      'sources_as_content' => 1,
777
      'sources_as_content_to_bibliography' => 0,
778
      'sort_elements' => NO_SORT,
779
      'glue' => '',
780
      'element_tag' => 'div'
781
    ),
782
    UUID_CHROMOSOMES => array(
783
      'as_list' => 'ul',
784
      'link_to_reference' => 0,
785
      'link_to_name_used_in_source' => 1,
786
      'sources_as_content' => 1,
787
      'sources_as_content_to_bibliography' => 0,
788
      'sort_elements' => NO_SORT,
789
      'glue' => '',
790
      'element_tag' => 'div'
791
    ),
792
    UUID_COMMON_NAME => array(
793
      'as_list' => 'div',
794
      'link_to_reference' => 0,
795
      'link_to_name_used_in_source' => 1,
796
      'sources_as_content' => 0,
797
      'sources_as_content_to_bibliography' => 0,
798
      'sort_elements' => NO_SORT,
799
      'glue' => '',
800
      'element_tag' => 'span'
801
    ),
802
  );
803

    
804
  $palmweb_default = array(
805
    'DEFAULT' => array(
806
      'as_list' => 'ul',
807
      'link_to_reference' => 1,
808
      'link_to_name_used_in_source' => 1,
809
      'sources_as_content' => 1,
810
      'sources_as_content_to_bibliography' => 1,
811
      'sort_elements' => NO_SORT,
812
      'glue' => '',
813
      'element_tag' => NULL
814
    ),
815
    UUID_CITATION => array(
816
      'as_list' => 'ul',
817
      'link_to_reference' => 1,
818
      'link_to_name_used_in_source' => 1,
819
      'sources_as_content' => 0,
820
      'sources_as_content_to_bibliography' => 1,
821
      'sort_elements' => SORT_ASC,
822
      'glue' => '',
823
      'element_tag' => 'div'
824
    ),
825
    UUID_DISTRIBUTION => array(
826
      'as_list' => 'div', // currently ignored
827
      'link_to_reference' => 1,
828
      'link_to_name_used_in_source' => 1,
829
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
830
      'sources_as_content_to_bibliography' => 1,
831
      'sort_elements' => NO_SORT, // will cause ...
832
      'glue' => ', ',
833
      'element_tag' => 'span',
834
      'special' => array()
835
    ),
836
  );
837

    
838
  $cyprus_default = $cichorieae_default;
839
  $cyprus_default[UUID_DISTRIBUTION] = array(
840
    'as_list' => 'div', // currently ignored
841
    'link_to_reference' => 0,
842
    'link_to_name_used_in_source' => 0,
843
    'sources_as_content' => 0,
844
    'sources_as_content_to_bibliography' => 0,
845
    'sort_elements' => NO_SORT, // will cause ...
846
    'glue' => ' ',
847
    'element_tag' => 'div',
848
    'special' => array()
849
  );
850

    
851
  $default_theme = variable_get('theme_default', NULL);
852

    
853
  switch ($default_theme) {
854
    case 'garland_cichorieae':
855
      $settings_for_theme = $cichorieae_default;
856
      break;
857
    case 'cyprus':
858
      // cyprus: no longer used in production,
859
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
860
      $settings_for_theme = $cyprus_default;
861
      break;
862
    case 'flore_afrique_centrale':
863
    case 'flora_malesiana':
864
    case 'flore_gabon':
865
      $settings_for_theme = $cichorieae_default;
866
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
867
      break;
868
    case 'palmweb_2':
869
      $settings_for_theme = $palmweb_default;
870
      break;
871
    default:
872
      $settings_for_theme = $other_themes_default;
873
  }
874
  // add pseudo feature settings
875
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
876

    
877
  // ---- END of DEFAULTS
878

    
879
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
880

    
881
  $feature_block_setting = null;
882

    
883
  if (isset($saved_settings[$feature_uuid])) {
884
    $feature_block_setting = $saved_settings[$feature_uuid];
885
  }
886
  else if (isset($settings_for_theme[$feature_uuid])) {
887
    $feature_block_setting = $settings_for_theme[$feature_uuid];
888
  }
889
  else if (isset($settings_for_theme['DEFAULT'])) {
890
    $feature_block_setting = $settings_for_theme['DEFAULT'];
891
  }
892

    
893
  // now merge the default and specific settings
894
  $settings_to_merge = array($default['DEFAULT']);
895
  if(is_array($saved_settings)){
896
    $settings_to_merge[] = $saved_settings['DEFAULT'];
897
  }
898
  if(isset($feature_block_setting)){
899
    $settings_to_merge[] = $feature_block_setting;
900
  }
901
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
902

    
903
  return $feature_block_setting;
904
}
905

    
906
/**
907
 * returns the current setting for the original source bibliography
908
 *
909
 * Caches internally
910
 *
911
 * @return array
912
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
913
 *   - 'enabled': 1|0
914
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
915
 */
916
function get_bibliography_settings($clear_cache = false){
917
  static $bibliography_settings = null;
918
  if(!$bibliography_settings || $clear_cache){
919
    $bibliography_settings = get_array_variable_merged(
920
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
921
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
922
    );
923
  }
924
  return $bibliography_settings;
925
}
926

    
927
/**
928
 * @todo Please document this function.
929
 * @see http://drupal.org/node/1354
930
 */
931
function cdm_dataportal_menu_admin(&$items) {
932
  // Display section on admin/config page.
933
  $items['admin/config/cdm_dataportal'] = array(
934
    'title' => 'CDM Dataportal',
935
    'description' => 'Settings for the CDM DataPortal.',
936
    'position' => 'right',
937
    'weight' => 10,
938
    'page callback' => 'system_admin_menu_block_page',
939
    'access arguments' => array('administer cdm_dataportal'),
940
    'file' => 'system.admin.inc',
941
    'file path' => drupal_get_path('module', 'system'),
942
  );
943
  $items['admin/config/cdm_dataportal/settings'] = array(
944
    'title' => 'Settings',
945
    'description' => 'Settings for the CDM DataPortal.',
946
    'weight' => 0,
947
    'page callback' => 'drupal_get_form',
948
    'page arguments' => array('cdm_settings_general'),
949
    'access arguments' => array('administer cdm_dataportal'),
950
    'type' => MENU_NORMAL_ITEM,
951
  );
952
  $items['admin/config/cdm_dataportal/settings/general'] = array(
953
    'title' => 'General',
954
    'description' => 'General',
955
    'weight' => 0,
956
    'page callback' => 'drupal_get_form',
957
    'page arguments' => array('cdm_settings_general'),
958
    'access arguments' => array('administer cdm_dataportal'),
959
    'type' => MENU_DEFAULT_LOCAL_TASK,
960
  );
961

    
962
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
963
    'title' => 'Cache',
964
    'description' => 'Cache',
965
    'access arguments' => array('administer cdm_dataportal'),
966
    'page callback' => 'drupal_get_form',
967
    'page arguments' => array('cdm_settings_cache'),
968
    'weight' => 10,
969
    'type' => MENU_LOCAL_TASK,
970
  );
971

    
972
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
973
    'title' => 'Geo & Map',
974
    'description' => 'Geo & Map',
975
    'access arguments' => array('administer cdm_dataportal'),
976
    'page callback' => 'drupal_get_form',
977
    'page arguments' => array('cdm_settings_geo'),
978
    'weight' => 1,
979
    'type' => MENU_LOCAL_TASK,
980
  );
981

    
982
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
983
    'title' => 'Layout',
984
    'description' => 'Configure and adjust the layout of your DataPortal ',
985
    'access arguments' => array('administer cdm_dataportal'),
986
    'page callback' => 'drupal_get_form',
987
    'page arguments' => array('cdm_settings_layout'),
988
    'weight' => 2,
989
    'type' => MENU_LOCAL_TASK,
990
  );
991

    
992
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
993
    'title' => 'Taxon',
994
    'description' => 'Configure and adjust the layout of your DataPortal ',
995
    'access arguments' => array('administer cdm_dataportal'),
996
    'page callback' => 'drupal_get_form',
997
    'page arguments' => array('cdm_settings_layout_taxon'),
998
    'weight' => 1,
999
    'type' => MENU_LOCAL_TASK,
1000
  );
1001
  /*
1002
  $items[] = array(
1003
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1004
  'title' => t('Synonymy'),
1005
  'description' => t('Configure and adjust the layout of your DataPortal '),
1006
  'access' => user_access('administer cdm_dataportal'),
1007
  'callback' => 'drupal_get_form',
1008
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1009
  'weight' => 1,
1010
  'type' => MENU_LOCAL_TASK,
1011
  );
1012

1013
  $items[] = array(
1014
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1015
  'title' => t('Specimens'),
1016
  'description' => t('Configure and adjust the layout of your DataPortal '),
1017
  'access' => user_access('administer cdm_dataportal'),
1018
  'callback' => 'drupal_get_form',
1019
  'callback arguments' => array('cdm_settings_layout_specimens'),
1020
  'weight' => 1,
1021
  'type' => MENU_LOCAL_TASK,
1022
  );
1023
  */
1024
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1025
    'title' => 'Search',
1026
    'description' => 'Configure and adjust the layout of your DataPortal ',
1027
    'access arguments' => array('administer cdm_dataportal'),
1028
    'page callback' => 'drupal_get_form',
1029
    'page arguments' => array('cdm_settings_layout_search'),
1030
    'weight' => 2,
1031
    'type' => MENU_LOCAL_TASK,
1032
  );
1033

    
1034
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1035
    'title' => 'Media',
1036
    'description' => 'Configure and adjust the layout of your DataPortal ',
1037
    'access arguments' => array('administer cdm_dataportal'),
1038
    'page callback' => 'drupal_get_form',
1039
    'page arguments' => array('cdm_settings_layout_media'),
1040
    'weight' => 3,
1041
    'type' => MENU_LOCAL_TASK,
1042
  );
1043

    
1044
}
1045

    
1046
/**
1047
 * @todo document this function.
1048
 */
1049
function cdm_help_general_cache() {
1050
  $form = array();
1051
  $form['cache_help'] = array(
1052
    '#type' => 'fieldset',
1053
    '#title' => t('Help'),
1054
    '#collapsible' => TRUE,
1055
    '#collapsed' => TRUE,
1056
  );
1057
  $form['cache_help']['test'] = array('#value' => t('probando'));
1058
  return drupal_render($form);
1059
  $res = array();
1060
  $res['default'] = drupal_render($help);
1061
  return $res;
1062
}
1063

    
1064
/**
1065
 * Configures the settings form for the CDM-API module.
1066
 *
1067
 * @return array
1068
 *   Drupal settings form.
1069
 */
1070
function cdm_settings_general() {
1071

    
1072
  $form['cdm_webservice'] = array(
1073
    '#type' => 'fieldset',
1074
    '#title' => t('CDM Server'),
1075
    '#collapsible' => FALSE,
1076
    '#collapsed' => FALSE,
1077
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1078
        CDM data base to the web via RESTful web services and thus is the source of the data
1079
        to be displayed by a CDM DataPotal.'),
1080
  );
1081

    
1082
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1083
    '#type' => 'textfield',
1084
    '#title' => t('CDM web service URL') . ':',
1085
    '#description' => t('This is the URL to the CDM-Server exposing your data
1086
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1087
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1088
  );
1089

    
1090
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1091
    '#type' => 'markup',
1092
    '#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')
1093
      . ' visible only for administrators',
1094
  );
1095

    
1096
  $form['cdm_webservice']['freetext_index'] = array(
1097
    '#type' => 'fieldset',
1098
    '#title' => t('Freetext index'),
1099
    '#collapsible' => FALSE,
1100
    '#collapsed' => FALSE,
1101
  );
1102

    
1103
  // Check the cdmserver port number and display a waring if it is not port 80
1104
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1105
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1106
    $form['cdm_webservice']['freetext_index']['message'] = array(
1107
      '#markup' => "<div class=\"description\">"
1108
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1109
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1110
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1111
          array('!port' => $portNumberMatch[1][0])
1112
        )
1113
      . "</div>",
1114
    );
1115
  };
1116

    
1117
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1118
  $trigger_link_options = array(
1119
    'attributes' => array(
1120
      'class' => 'index-trigger'
1121
    ),
1122
  );
1123
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1124
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1125
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1126
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1127
      ))
1128
    . '<div id="index-progress"></div></div>',
1129
  );
1130

    
1131
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1132
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1133
    '#type' => 'textfield',
1134
    '#title' => t('Login'),
1135
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1136
  );
1137
  drupal_add_js('
1138
        jQuery(document).ready(function() {
1139
             jQuery("#edit-cdm-login").change(function (e) {
1140
                var login = jQuery(e.target).val();
1141
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1142
                   var url = jQuery(this).attr("href");
1143
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1144
                   jQuery(this).attr("href", url);
1145
                });
1146
            });
1147
        });
1148
      ',
1149
    array(
1150
      'type' => 'inline',
1151
      'scope' => 'footer'
1152
    )
1153
  );
1154
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1155

    
1156
    $form['cdm_webservice']['freetext_index']['cdm_dataportal_taxon_auto_suggest'] = array(
1157
        '#type' => 'checkbox',
1158
        '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
1159
        '#default_value' => variable_get('cdm_dataportal_taxon_auto_suggest', CDM_DATAPORTAL_TAXON_AUTO_SUGGEST),
1160
        '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
1161
        This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
1162
    );
1163

    
1164
  $form['cdm_webservice']['proxy'] = array(
1165
    '#type' => 'fieldset',
1166
    '#title' => t('Proxy'),
1167
    '#collapsible' => TRUE,
1168
    '#collapsed' => TRUE,
1169
  );
1170

    
1171
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1172
    '#type' => 'textfield',
1173
    '#title' => t('Proxy URL') . ':',
1174
    '#description' => t('If this proxy url is set the cdm api tries
1175
    to connect the web service over the given proxy server.
1176
    Otherwise proxy usage is deactivated.'),
1177
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1178
  );
1179

    
1180
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1181
    '#type' => 'textfield',
1182
    '#title' => t('Proxy port') . ':',
1183
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1184
  );
1185

    
1186
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1187
    '#type' => 'textfield',
1188
    '#title' => t('Login') . ':',
1189
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1190
  );
1191

    
1192
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1193
    '#type' => 'textfield',
1194
    '#title' => t('Password') . ':',
1195
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1196
  );
1197

    
1198
  // TODO: settings are still incomplete, compare with
1199
  // trunk/dataportal/inc/config_default.php.inc.
1200
  $form['taxon_tree'] = array(
1201
    '#type' => 'fieldset',
1202
    '#title' => t('Taxon Tree'),
1203
    '#collapsible' => FALSE,
1204
    '#collapsed' => TRUE,
1205
    '#description' => t('<p>When you explore your collection, you can navigate
1206
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1207
      able to navigate through your collection the
1208
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1209
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1210
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1211
      </a></p>'),
1212
  );
1213

    
1214
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1215
    '#type' => 'select',
1216
    '#title' => t('Available classifications') . ':',
1217
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1218
    '#options' => cdm_get_taxontrees_as_options(),
1219
    '#description' => t('Select the default taxa classification for your
1220
      <em>taxon tree</em>, the other classifications will be also available but
1221
      with a manual user change.'),
1222
  );
1223

    
1224
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1225
    '#type' => 'select',
1226
    '#title' => t('Rank of highest displayed taxon') . ':',
1227
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1228
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1229
    '#options' => cdm_rankVocabulary_as_option(),
1230
    '#description' => t('This is the rank of the highest displayed taxon in the
1231
      <em>taxon tree</em>. You can select here which rank should be at the top
1232
      level of the tree structure.'),
1233
  );
1234

    
1235
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1236
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1237
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1238
      '#type' => 'checkboxes',
1239
      '#title' => t('Included Classifications') . ':',
1240
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1241
      '#options' => cdm_get_taxontrees_as_options(),
1242
      '#description' => t('Only the checked classifications will be avaliable in the classification chooser.'),
1243
  );
1244

    
1245
  $form['distribution'] = array(
1246
      '#type' => 'fieldset',
1247
      '#title' => t('Distributions'),
1248
      '#collapsible' => FALSE,
1249
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1250
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1251
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1252
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1253
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1254
          '<p>
1255
          </p>',
1256
  );
1257

    
1258
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1259
      '#type' => 'fieldset',
1260
      '#title' => 'Distribution filter',
1261
      '#collapsible' => FALSE,
1262
      '#collapsed' => FALSE,
1263
      '#tree' => TRUE,
1264
      '#description' => 'The Distribution filter offers the following options
1265
      <ul>
1266
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1267
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1268
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1269
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1270
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1271
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1272
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1273
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1274
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1275
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1276
      </ul>'
1277
  );
1278

    
1279
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1280
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1281
      '#type' => 'checkboxes',
1282
      '#title' => 'Filter rules',
1283
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1284
      '#options' => array(
1285
          'statusOrderPreference' => 'Status order preference rule',
1286
          'subAreaPreference' => 'Sub area preference rule'
1287
      ),
1288
  );
1289

    
1290
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1291
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1292
      '#type' => 'checkboxes',
1293
      '#title' => 'Hide marked area filter',
1294
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1295
      '#options' => $marker_type_options,
1296
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1297
  );
1298

    
1299
  $form['aggregation'] = array(
1300
      '#type' => 'fieldset',
1301
      '#title' => t('Aggregation of data'),
1302
      '#collapsible' => FALSE,
1303
      '#description' => 'This section covers the different aspects of aggregating information.
1304
          <p>
1305
          </p>',
1306
  );
1307

    
1308
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1309
      '#type' => 'checkboxes',
1310
      '#title' => 'Taxon media filter',
1311
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1312
      '#options' => array(
1313
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1314
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1315
          'includeOccurrences' => 'Media related to specimens and occurrences',
1316
      ),
1317
      '#description' => 'This filter configures which images should be taken into account.',
1318
  );
1319

    
1320
  $form['aggregation']['notice'] = array(
1321
      '#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
1322
          want to make use of the caching capabilities of the dataportal.',
1323
  );
1324

    
1325
  $form['aggregation']['media_aggregation'] = array(
1326
      '#type' => 'fieldset',
1327
      '#title' => t('Media aggregation'),
1328
      '#collapsible' => FALSE,
1329
      '#collapsed' => TRUE,
1330
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1331

    
1332
  );
1333
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1334
      '#type' => 'select',
1335
      '#title' => t('Aggregation of taxon pictures') . ':',
1336
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1337
      '#options' => array(
1338
          0 => "Show only pictures of the current taxon",
1339
          1 => "Include pictures of taxonomic children",
1340
      ),
1341
      '#description' => t("Choose whether to include the images of the taxonomic children. This will affect the <em>Images</em> tab and image tumbnails like in the search results."),
1342
  );
1343

    
1344
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1345
      '#type' => 'fieldset',
1346
      '#attributes' => array('class' => array('clearfix')),
1347
      '#title' => t('Aggregation via taxon relationsships'),
1348
      '#collapsible' => TRUE,
1349
      '#collapsed' => TRUE,
1350
      '#tree' => TRUE,
1351
      '#description' => t('Information on taxa will be aggregated along the below chosen
1352
          taxon relation ships. This will affect images and occurrences (specimens).
1353
          Taxon relation ships are directed and point form one taxon to another. The taxon
1354
          relationships to be taken into accunt can therefore configured for the direct direction
1355
          and for the inverse.'),
1356
  );
1357

    
1358
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1359
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1360

    
1361
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1362
      '#type' => 'checkboxes',
1363
      '#title' => t('Direct'),
1364
      '#options' => $taxonRelationshipTypeOptions,
1365
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1366
  );
1367
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1368
      '#type' => 'checkboxes',
1369
      '#title' => t('Invers'),
1370
      '#options' => $taxonRelationshipTypeOptions,
1371
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1372
  );
1373

    
1374
  $form['drupal_integration'] = array(
1375
    '#type' => 'fieldset',
1376
    '#attributes' => array('class'=> array('clearfix')),
1377
    '#title' => t('Drupal integration'),
1378
    '#collapsible' => FALSE,
1379
    '#collapsed' => FALSE,
1380
    '#tree' => FALSE
1381
  );
1382

    
1383
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1384
    '#type' => 'checkbox',
1385
    '#title' => 'Create drupal nodes',
1386
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1387
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1388
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1389
    cdm pages it is required that drupal nodes are created and stored in the database.'
1390
  );
1391

    
1392

    
1393

    
1394
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1395
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1396
    <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>',
1397
  );
1398
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1399
    '#type' => 'submit',
1400
    '#value' => t('Drop all cdm nodes'),
1401
    '#submit' => array('drop_all_cdm_nodes_submit')
1402
  );
1403

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

    
1408
    // ----------------------
1409
  $form['cdm_js_devel_mode'] = array(
1410
      '#type' => 'checkbox',
1411
      '#title' => 'Java-script developer mode',
1412
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1413
      '#description' => 'In production envirionments the java script libraries
1414
      the cdm_dataportal is making use of are compressed and optimized. This
1415
      is good for performance but a caveat if you need to debug java-script. When the
1416
      java-script developer mode is enabled the uncompressed and commented developer
1417
      versions of java-script libraries will be used where possible.
1418
      <br/><strong>Do not use this option in production!</strong>'
1419
  );
1420
  // ----------------------
1421
  $form['cdm_debug_mode'] = array(
1422
      '#type' => 'checkbox',
1423
      '#title' => 'CDM page debug mode',
1424
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1425
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1426
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1427
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1428
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1429
      The log is written by the drupal devel module function <code>dd()</code>.
1430
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1431
  );
1432

    
1433
  // Comment @WA: D7 form api does not support reset buttons,
1434
  // so to mimic the D5 reset button we add one like this.
1435
  $form['actions']['reset'] = array(
1436
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1437
    '#weight' => 1000,
1438
  );
1439

    
1440
  $form['#submit'][] = 'cdm_settings_general_submit';
1441

    
1442
  return system_settings_form($form);
1443
}
1444

    
1445
/**
1446
 * Submit callback; drops all cdm nodes.
1447
 *
1448
 * @ingroup forms
1449
 */
1450
function drop_all_cdm_nodes_submit($form, &$form_state) {
1451
  cdm_delete_all_cdm_nodes();
1452
  drupal_set_message(t('All cdm nodes dropped.'));
1453
}
1454

    
1455

    
1456
/**
1457
 * LAYOUT settings
1458
 * @return
1459
 *   todo
1460
 */
1461
function cdm_settings_layout() {
1462

    
1463
  $form = array();
1464

    
1465
  $form['about'] = array(
1466
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1467
      layout. If you want to configure the specific sites layout visit the
1468
      respective configuration site for taxon, search or media.') . '</p>',
1469
  );
1470

    
1471
  // ---- footnotes --- //
1472
  $form['footnotes'] = array(
1473
    '#type' => 'fieldset',
1474
    '#title' => t('Footnotes'),
1475
    '#collapsible' => FALSE,
1476
    '#collapsed' => FALSE,
1477
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1478
      media or distribution areas may have annotations or footnotes. When the
1479
      footnotes are enabled they will be visible (if they exist).'),
1480
  );
1481

    
1482
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1483
    '#type' => 'checkbox',
1484
    '#title' => t('Do not show footnotes'),
1485
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1486
    '#description' => t('Check this if you do not want to show any footnotes'),
1487
  );
1488

    
1489
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1490
    '#type' => 'checkbox',
1491
    '#title' => t('Do not show annotation footnotes'),
1492
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1493
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1494
  );
1495

    
1496
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1497
  // Additional option for the NULL case.
1498
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1499
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1500
    '#type' => 'checkboxes',
1501
    '#title' => t('Annotation types as footnotes'),
1502
    '#description' => t("Only annotations of the selected type will be displayed
1503
       as footnotes. You may want to turn 'technical annotations' off."),
1504
    '#options' => $annotationTypeOptions,
1505
  );
1506
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1507
  if (!empty($annotationsTypesAsFootnotes)) {
1508
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1509
  }
1510

    
1511
  // ---- original source --- //
1512
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1513
      '#type' => 'fieldset',
1514
      '#tree' => TRUE,
1515
      '#title' => t('Source Citations'),
1516
      '#collapsible' => FALSE,
1517
      '#collapsed' => FALSE,
1518
  );
1519

    
1520
  $bibliography_settings = get_bibliography_settings(true);
1521

    
1522
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1523
      '#type' => 'checkbox',
1524
      '#title' => t('Original Source in bibliography'),
1525
      '#default_value' => $bibliography_settings['enabled'],
1526
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1527
       annotations in each feature block.'),
1528
  );
1529

    
1530
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1531
    '#type' => 'select',
1532
    '#title' => t('The format of the key numerals'),
1533
    '#default_value' => $bibliography_settings['key_format'],
1534
    '#options' => array('latin' => 'Latin',
1535
      'ROMAN' => 'Roman (upper case)',
1536
      'roman' => 'Roman (lower case)',
1537
      'ALPHA'=> 'Alphabet (upper case)',
1538
      'alpha' => 'Alphabet (lower case)')
1539
  );
1540

    
1541
  // --- Advanced Search --- //
1542
  $form['asearch'] = array(
1543
      '#type' => 'fieldset',
1544
      '#title' => t('Advanced search'),
1545
      '#collapsible' => FALSE,
1546
      '#collapsed' => FALSE,
1547
  );
1548
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1549
      '#type' => 'checkbox',
1550
      '#title' => t('Show advanced search link'),
1551
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1552
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1553
  );
1554

    
1555
  // ---- Taxon Name Rendering --- //
1556
  $form['taxon_name'] = array(
1557
      '#type' => 'fieldset',
1558
      '#title' => t('Taxon name display'),
1559
      '#collapsible' => TRUE,
1560
      '#collapsed' => TRUE,
1561
      '#description' => t('The display of taxon names is configured by two parts.
1562
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1563
          The name parts are defined in the <stong>part definitions</strong>'),
1564
  );
1565

    
1566
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1567
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1568
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1569
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1570

    
1571
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1572
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1573
    $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.)';
1574
  } else if($is_custom_part_definition){
1575
    $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1576
  } else  {
1577
    $which_version_message = '(These are the default part definition.)';
1578
  }
1579

    
1580
  $diff_viewer_markup = '';
1581
  if($is_custom_part_definition){
1582
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1583
  }
1584

    
1585
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1586
    . $which_version_message
1587
    . '</div>'
1588
    . $diff_viewer_markup;
1589

    
1590
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1591
      '#type' => 'textarea',
1592
      '#title' => t('Part definitions'),
1593
      '#element_validate' => array('form_element_validate_json'),
1594
      '#default_value' =>  $current_part_definition_json,
1595
      '#description' => '
1596
          <p>' . $which_version_message . '</p>
1597
          <p>
1598
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1599
          </p>
1600
          <p>
1601
           A full taxon name plus additional information can consist of the following elements:
1602
          <ul>
1603
             <li>name: the taxon name inclugin rank nbut without author</li>
1604
             <li>authors:  The authors of a reference, also used in taxon names</li>
1605
             <li>reference: the nomenclatural reference,</li>
1606
             <li>microreference:  Volume, page number etc.</li>
1607
             <li>status:  The nomenclatural status of a name</li>
1608
             <li>description: name descriptions like protologues etc ...</li>
1609
          </ul>
1610
          </p>
1611
          <p>
1612
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1613
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1614
           The following parts can be formed and are recognized by the system:
1615
          <ul>
1616
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1617
            <li>authorshipPart: the author (for example: "L.")</li>
1618
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1619
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1620
               be combined when a link to the taxon is rendered.</li>
1621
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1622
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1623
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1624
            <li>statusPart: the nomenclatorical status</li>
1625
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1626
          </ul>
1627
          </p>
1628
          <p>
1629
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1630
           specific parts part definitions:
1631
          <ul>
1632
            <li>BotanicalName</li>
1633
            <li>ZoologicalName</li>
1634
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1635
          </ul>
1636
           An example:
1637
          <pre>
1638
           {
1639
            "ZoologicalName": {
1640
              "namePart": {
1641
                "name": true
1642
              },
1643
              "referencePart": {
1644
                "authors": true
1645
              },
1646
              "microreferencePart": {
1647
                "microreference": true
1648
              },
1649
              "statusPart": {
1650
                "status": true
1651
              },
1652
              "descriptionPart": {
1653
                "description": true
1654
              }
1655
            },
1656
            "BotanicalName": {
1657
              "namePart": {
1658
                "name": true,
1659
                "authors": true
1660
              },
1661
              "referencePart": {
1662
                "reference": true,
1663
                "microreference": true
1664
              },
1665
              "secReferencePart": {
1666
                "secReference": true
1667
              },
1668
              "statusPart": {
1669
                "status": true
1670
              },
1671
              "descriptionPart": {
1672
                "description": true
1673
              }
1674
            }
1675
          }
1676
           </pre>',
1677
  );
1678

    
1679
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1680
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1681
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1682
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1683
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1684

    
1685
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1686
    $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.)';
1687
  } else if($is_custom_render_template){
1688
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1689
  } else {
1690
    $which_version_message = '(These are the default render templates.)';
1691
  }
1692

    
1693
  $diff_viewer_markup = '';
1694
  if($is_custom_render_template){
1695
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1696
  }
1697

    
1698
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1699
    . $which_version_message
1700
    . '</div>'
1701
    . $diff_viewer_markup;
1702

    
1703
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1704
      '#type' => 'textarea',
1705
      '#title' => t('Name render templates'),
1706
      '#element_validate' => array('form_element_validate_json'),
1707
      '#default_value' =>  $current_render_templates_json,
1708
      '#description' => '
1709
          <p>' . $which_version_message . '</p>
1710
          <p>
1711
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1712
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1713
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1714
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1715
          The following render Path keys are currently recognized:
1716
          <ul>
1717
            <li>list_of_taxa</li>
1718
            <li>acceptedFor</li>
1719
            <li>homonym</li>
1720
            <li>taxon_page_synonymy</li>
1721
            <li>typedesignations</li>
1722
            <li>taxon_page_title</li>
1723
            <li>polytomousKey</li>
1724
            <li>na: name + authorship</li>
1725
            <li>nar:name + authorship + reference</li>
1726
            <li>#DEFAULT</li>
1727
          </ul>
1728
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1729
          array element should be a comma separated list of render paths, without any whitespace!.
1730
          </p>
1731
          <p>
1732
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1733
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1734
          <p>
1735
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1736
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1737
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1738
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1739
          links if the paramters $nameLink or $refenceLink are given to the name render function
1740
          (this is hard coded and cannot be configured here).',
1741
  );
1742

    
1743
  // @WA: D7 form api does not support reset buttons,
1744
  // so to mimic the D5 reset button we add one like this.
1745
  $form['actions']['reset'] = array(
1746
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1747
    '#weight' => 1000,
1748
  );
1749

    
1750
  $form['#submit'] = array('submit_json_as_php_array');
1751
  // #json_elements especially defined for submit_json_as_php_array()
1752
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1753
  return system_settings_form($form);
1754
}
1755

    
1756

    
1757
/**
1758
 * @param $form_name
1759
 * @param $form_title
1760
 * @param $collapsed
1761
 * @param string $form_description
1762
 *   The description for the fieldset of the gallery setting.
1763
 * @return mixed
1764
 */
1765
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1766
  $form[$form_name] = array(
1767
    '#type' => 'fieldset',
1768
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1769
    '#collapsible' => TRUE,
1770
    '#collapsed' => $collapsed,
1771
    '#tree' => TRUE,
1772
    '#description' => $form_description,
1773
  );
1774

    
1775
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1776
  $gallery_settings = variable_get($form_name, $default_values);
1777
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1778
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1779
    /*
1780
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1781
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1782
    '#type' => 'textfield',
1783
    '#title' => t('Search Page Size'),
1784
    '#default_value' => $test,
1785
    '#description' => t('Number of Names to display per page in search results.')
1786
    );
1787
    */
1788
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1789
      '#type' => 'checkbox',
1790
      '#title' => t('Show media thumbnails for accepted taxa'),
1791
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1792
    );
1793

    
1794
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1795
      '#type' => 'checkbox',
1796
      '#title' => t('Show media thumbnails for synonyms'),
1797
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1798
      '#description' => '',
1799
    );
1800
  }
1801

    
1802
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1803
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1804
    '#type' => 'checkbox',
1805
    '#title' => t('Show captions under thumbnails'),
1806
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1807
    '#description' => '',
1808
  );
1809

    
1810
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1811
    '#type' => 'textfield',
1812
    '#title' => t('Thumbnail size') . ':',
1813
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1814
    '#description' => t('Select the size of each individual thumbnail.'),
1815
  );
1816

    
1817
  if ($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME) {
1818
    $form[$form_name]['cdm_dataportal_media_cols'] = array(
1819
      '#type' => 'textfield',
1820
      '#title' => t('Number of columns') . ':',
1821
      '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1822
      '#description' => t('Group the thumbnails in columns: select how many
1823
        columns the gallery should display.'),
1824
    );
1825
  }
1826

    
1827
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1828
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1829
      '#type' => 'textfield',
1830
      '#title' => t('Maximum number of rows') . ':',
1831
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1832
      '#description' => t('You can group the thumbnails in rows, select in how
1833
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1834
        If you want an unlimited number of rows please set to 0.'),
1835
    );
1836
  }
1837

    
1838
  return $form;
1839
}
1840

    
1841
/**
1842
 * @todo document this function.
1843
 */
1844
function cdm_settings_layout_taxon() {
1845
  $collapsed = FALSE;
1846
  $form = array();
1847

    
1848
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1849

    
1850
  // --------- TABBED TAXON ------- //
1851
  $form['taxon_tabs'] = array(
1852
    '#type' => 'fieldset',
1853
    '#title' => t('Taxon tabs'),
1854
    '#collapsible' => TRUE,
1855
    '#collapsed' => TRUE,
1856
    '#description' => t('If tabbed taxon page is enabled the taxon profile will
1857
      be splitted in four diferent tabs; General, Synonymy, Images and
1858
      Specimens. If the taxon has no information for any of the tabs/sections
1859
      such tab will be not displayed.'),
1860
  );
1861

    
1862
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1863
    '#type' => 'checkbox',
1864
    '#title' => t('Tabbed taxon page'),
1865
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1866
    '#description' => t('<p>If selected split the taxon page into individual
1867
      tabs for description, images, synonymy and specimens. If not the taxon
1868
      data is rendered as a long single page without tabs.</p>'),
1869
  );
1870

    
1871
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1872
    '#type' => 'checkboxes',
1873
    '#title' => t('Tabs visibility options') . ':',
1874
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1875
    '#options' => get_taxon_options_list(),
1876
    '#description' => t('Enable or disable Tabs in the Tabbed page display'),
1877
  );
1878

    
1879
  // WEIGHT
1880
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1881
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1882
    '#title'  => 'Tabs order',
1883
    '#type' => 'fieldset',
1884
    '#collapsible' => false,
1885
    '#tree' => true,
1886
    '#description' => 'The weight value defines the order of the tabs or of the respective content block on the 
1887
        taxon page when it is the tabless mode.'
1888
  );
1889
  // Weights range from -delta to +delta, so delta should be at least half
1890
  // of the amount of tabs present.
1891
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1892
  foreach (get_taxon_tabs_list() as $label) {
1893
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1894
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1895
        '#title' => $label,
1896
        '#type'  => 'weight',
1897
        '#default_value' => $taxon_tabs_weights[$key],
1898
        '#delta' => $tab_weight_delta
1899
    );
1900
  }
1901

    
1902
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1903
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1904
    '#title'  => 'Tab label override',
1905
    '#type' => 'fieldset',
1906
    '#collapsible' => false,
1907
    '#tree' => true,
1908
    '#description' => 'Setting a label for a tab will override the default label. 
1909
      Please enter the label text in the default language of the portal.'
1910
  );
1911
  foreach (get_taxon_tabs_list() as $label) {
1912
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1913
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1914
      '#title' => $label,
1915
      '#type'  => 'textfield',
1916
      '#default_value' => $taxon_tabs_labels[$key]
1917
    );
1918
  }
1919

    
1920
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1921
    '#type' => 'select',
1922
    '#title' => t('Default tab to display') . ':',
1923
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1924
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1925
    '#description' => t('<p>Select the default tab to display when visiting a
1926
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1927
      <strong>Note:</strong> After performing a search and clicking in any
1928
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1929
      taxon and not the above selected tab.'),
1930
  );
1931

    
1932
  /* ======  TAXON_PROFILE ====== */
1933
  $form['taxon_profile'] = array(
1934
    '#type' => 'fieldset',
1935
    '#title' => t('Taxon profile (tab)'),
1936
    '#description' => t('<p>This section covers the settings related to the taxon
1937
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1938
    '#collapsible' => TRUE,
1939
    '#collapsed' => TRUE,
1940
  );
1941

    
1942
  // ---- PROFILE PICTURE ----//
1943

    
1944
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1945
    '#type' => 'fieldset',
1946
    '#tree' => TRUE,
1947
    '#title' => t('Taxon profile picture'),
1948
    '#collapsible' => TRUE,
1949
    '#collapsed' => FALSE,
1950
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1951
  );
1952

    
1953
  //FIXME migrate variables:
1954
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1955
  // FIXME
1956
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1957

    
1958
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1959

    
1960
  /*
1961
   * 'show' => 1,
1962
   * 'maxextend' => 184,
1963
   * 'media_uri_query' => ''
1964
   * 'custom_placeholder_image_on' => 1,
1965
   * 'custom_placeholder_image_fid' => ''
1966
   */
1967
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1968
    '#type' => 'checkbox',
1969
    '#title' => t('Enable profile picture'),
1970
    '#description' => t('Show the profile picture.'),
1971
    '#default_value' => $taxon_profile_image_settings['show'],
1972
  );
1973

    
1974
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1975
      '#type' => 'textfield',
1976
      '#tree' => TRUE,
1977
      '#title' => t('Profile picture maximum extend'),
1978
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
1979
      '#field_suffix' => 'px',
1980
      '#maxlength' => 4,
1981
      '#size' => 4,
1982
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
1983
  );
1984

    
1985
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
1986
      '#type' => 'textfield',
1987
      '#tree' => TRUE,
1988
      '#title' => t('Additional URI query parameter'),
1989
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
1990
      '#maxlength' => 1024,
1991
      '#size' => 60,
1992
      '#description' => t('Additional query parameters to be used when requesting for the  
1993
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
1994
            The query parameters will be appended to the uri of the media representation part
1995
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
1996
  );
1997

    
1998
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
1999
    '#type' => 'checkbox',
2000
    '#title' => t('Show the placeholder image'),
2001
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2002
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2003
  );
2004

    
2005
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2006
      '#type' => 'checkbox',
2007
      '#title' => t('Use a custom placeholder image'),
2008
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2009
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2010
  );
2011

    
2012
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2013
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2014
        '#type' => 'managed_file',
2015
        '#title' => t('Custom placeholder image file'),
2016
        '#progress_indicator' => 'bar',
2017
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2018
    //       '#name' => 'custom_placeholder_image',
2019
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2020
    );
2021

    
2022
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2023
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2024
      $url = file_create_url($profile_image_file->uri);
2025
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2026
                '#type' => 'item',
2027
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2028
      );
2029
    }
2030
  } else {
2031
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2032
      '#type' => 'hidden',
2033
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2034
    );
2035
  }
2036

    
2037
  $options = cdm_rankVocabulary_as_option();
2038
  array_unshift($options, '-- DISABLED --');
2039
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2040
    '#type' => 'select',
2041
    '#title' => t('Hide profile picture for higher ranks') . ':',
2042
    '#default_value' => variable_get('image_hide_rank', '0'),
2043
    '#options' => $options,
2044
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2045
  );
2046

    
2047
  // -- MEDIA THUMBNAILS -- //
2048
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2049
  $form_title = 'Taxon Profile Images';
2050
  $form_description = '<p>The different section 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>';
2051
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2052

    
2053
  // ---- FEATURE TREE BLOCKS ---- //
2054
  $form['taxon_profile']['feature_blocks'] = array(
2055
    '#type' => 'fieldset',
2056
    '#title' => t('Feature Blocks'),
2057
    '#collapsible' => TRUE,
2058
    '#collapsed' => FALSE,
2059
    '#description' => t("This section covers settings related to the taxon's
2060
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2061
      features such as description, distribution, common names"),
2062
  );
2063
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2064
  $profile_feature_tree = get_profile_feature_tree();
2065
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2066
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2067
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2068
  }
2069
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2070
    '#type' => 'radios',
2071
    '#title' => t('Taxon profile feature tree') . ':',
2072
    '#default_value' => $profile_feature_tree_uuid,
2073
    '#options' =>  $featureTrees['options'],
2074
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2075
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2076
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2077
      profile page.'
2078
    ),
2079
  );
2080

    
2081
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2082
  $profile_feature_tree = get_profile_feature_tree();
2083

    
2084
  if (isset($profile_feature_tree->root->childNodes)) {
2085

    
2086
    $form_feature_block_layout = array(
2087
      '#type' => 'fieldset',
2088
      '#tree' => true,
2089
      '#title' => t('Taxon profile feature block settings'),
2090
      '#collapsible' => TRUE,
2091
      '#collapsed' => FALSE,
2092
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2093
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2094
      The subforms have the following settings in common:<br />
2095
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2096
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2097
      <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>
2098
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2099
            <ol>
2100
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2101
                appended in brackets like "text (source references)". If the original source has name in source
2102
                information it will be appended to the citation string,
2103
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2104
             <li>if the text of the TextData is empty, the original source citations are the only content
2105
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2106
                prepended to the citation string like: "name in source: citation"</li>
2107
            </ol>
2108
            <strong>If disabled:</strong><br />
2109
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2110
             citations are the only content, the resulting feature block content would only consist of footnotes.
2111
             In this case the display of the respective feature block is suppressed.</div>
2112
      </dl>
2113
      <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
2114
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2115
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2116
        . '</em></div>
2117
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2118
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2119
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2120
      <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>
2121
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2122
           cdm_feature_block_element_tag_name()</div>',
2123
    );
2124

    
2125

    
2126
    $feature_list_layout_settings_disabled = FALSE;
2127

    
2128
    // creating helper object to retrieve the default settings
2129
    $featureNode = new stdClass();
2130
    $featureNode->feature = new stdClass();
2131
    $featureNode->feature->uuid="DEFAULT";
2132
    $featureNode->feature->representation_L10n = "Default";
2133
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2134

    
2135
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2136

    
2137
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2138

    
2139
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2140
        $subform_id = $featureNode->feature->uuid;
2141
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2142

    
2143
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2144

    
2145
        $form_feature_block_layout[$subform_id] = array(
2146
          '#type' => 'fieldset',
2147
          '#tree' => TRUE,
2148
          '#title' => $featureNode->feature->representation_L10n,
2149
          '#collapsible' => FALSE,
2150
          '#collapsed' => FALSE,
2151
        );
2152
        if($featureNode->feature->uuid == "DEFAULT"){
2153
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2154
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2155
          references</em> and <em>names in source</em> is only possible in the defaults';
2156
        }
2157

    
2158
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2159
          '#type' => 'select',
2160
          '#title' => 'List type',
2161
          '#default_value' => $feature_block_setting['as_list'],
2162
          '#options' => array(
2163
            'div' => 'not as list',
2164
            'ul' => 'bullet list',
2165
            'ol' => 'numbered list',
2166
            'dl' => 'definition list'
2167
          ),
2168
        );
2169

    
2170
        if($featureNode->feature->uuid == "DEFAULT"){
2171
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2172
            '#type' => 'checkbox',
2173
            '#title' => t('Link to reference'),
2174
            '#default_value' => $feature_block_setting['link_to_reference'],
2175
          );
2176

    
2177
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2178
            '#type' => 'checkbox',
2179
            '#title' => 'Link to name used in source',
2180
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2181
          );
2182
        }
2183

    
2184
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2185
          '#type' => 'checkbox',
2186
          '#title' => 'Sources as content',
2187
          '#default_value' => $feature_block_setting['sources_as_content'],
2188
        );
2189

    
2190
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2191
          '#type' => 'checkbox',
2192
          '#title' => 'Put sources also as content to bibliography',
2193
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2194
        );
2195

    
2196
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2197
          '#type' => 'select',
2198
          '#title' => t('Sort elements'),
2199
          '#default_value' => $feature_block_setting['sort_elements'],
2200
          '#options' => array(
2201
            NO_SORT => 'No sorting',
2202
            SORT_ASC => 'Ascending',
2203
            SORT_DESC => 'Descending',
2204
            SORT_HIERARCHICAL => 'Hierarchical'
2205
          ),
2206
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2207
          <dl>
2208
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2209
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2210
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2211
          <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>
2212
          </dl>',
2213
        );
2214

    
2215
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2216
          '#type' => 'select',
2217
          '#title' => t('Element tag'),
2218
          '#options' => array(
2219
            'span' => 'span',
2220
            'div' => 'div',
2221
            'p' => 'p'
2222
          ),
2223
          '#default_value' => $feature_block_setting['element_tag'],
2224
        );
2225
      }
2226
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2227
    }
2228
  }
2229

    
2230
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2231
  $form['taxon_profile']['structured_description_featuretree'] = array(
2232
    '#type' => 'fieldset',
2233
    '#title' => t('Structured Description Feature Tree'),
2234
    '#collapsible' => TRUE,
2235
    '#collapsed' => FALSE,
2236
  );
2237
  $featureTrees = cdm_get_featureTrees_as_options();
2238
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2239
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2240
    $profile_feature_tree_uuid = NULL;
2241
  }
2242
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2243
    '#type' => 'radios',
2244
    '#title' => t('Natural language representation of structured descriptions') . ':',
2245
    '#default_value' => $profile_feature_tree_uuid,
2246
    '#options' => $featureTrees['options'],
2247
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2248
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2249
    '#description' => t('Taxon descriptions can be stored in a highly structured
2250
      form. The feature tree selected here will be used to generate textual
2251
      representation in natural language.'
2252
    ),
2253
  );
2254

    
2255

    
2256

    
2257
  // ---- DISTRIBUTION LAYOUT ---- //
2258
  $form['taxon_profile']['distribution_layout'] = array(
2259
    '#title' => t('Distribution'),
2260
    '#collapsible' => TRUE,
2261
    '#collapsed' => FALSE,
2262
    '#type' => 'fieldset',
2263
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2264
        Map settings regarding the geometry, layers, etc are found in the '
2265
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2266
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2267
      . l(
2268
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2269
        array('fragment' => 'edit-feature-block-settings')
2270
      )
2271
      . ' More general settings regrading the filtering of Distributions are found at '
2272
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2273
      . '. (These settings here will be merged in future releases into the feature block settings)',
2274

    
2275
  );
2276

    
2277
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2278

    
2279
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2280
    '#type' => 'checkbox',
2281
    '#title' => t('Condensed distribution'),
2282
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2283
    '#description' => 'This option enables the display of a very compact representation
2284
    of the distribution which includes also information on the status.',
2285
  );
2286

    
2287
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2288
    '#type' => 'select',
2289
    '#title' => t('Condensed distribution recipe'),
2290
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2291
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2292
    '#description' => 'Recipe for creating the condensed distribution.',
2293
  );
2294

    
2295
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2296
    '#type' => 'textfield',
2297
    '#title' => t('Condensed distribution info path'),
2298
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2299
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2300
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2301
  );
2302

    
2303

    
2304
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2305
    '#type' => 'radios',
2306
    '#title' => t('Display mode') . ':',
2307
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2308
    '#options' => array(
2309
      'FLAT_ALPHA' => t('Flat list'),
2310
      'TREE' => t('Hierarchically ordered'),
2311
    ),
2312
    '#description' => 'Taxon distribution information is displayed with
2313
    focus on the area of the distribution. The list of areas can either be shown
2314
    as flat list ordered alphabetically or in the hierarchical of the parent
2315
    area and subarea relationship. Fall back areas areas with no Distribution data
2316
    are hidden from the area hierarchy so that their sub areas will move one level up.
2317
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2318
    ' for details on the <em>Marked area filter</em>.',
2319
  );
2320

    
2321
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2322
    '#type' => 'fieldset',
2323
    '#tree' => true,
2324
    '#title' => t('Distribution hierarchy style')
2325
  );
2326

    
2327
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2328
  foreach(array_keys($hierarchy_styles) as $level) {
2329
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2330
      '#type' => 'fieldset',
2331
      '#tree' => true,
2332
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2333
      '#attributes' => array('class' => array('fieldset-float'))
2334
    );
2335
    foreach ($hierarchy_styles[$level] as $key => $value) {
2336
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2337
        '#type' => 'textfield',
2338
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2339
        '#default_value' => $hierarchy_styles[$level][$key],
2340
        '#maxlength' => 4,
2341
        '#size' => 4
2342
      );
2343
    }
2344
  }
2345

    
2346
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2347
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2348
    '#type' => 'checkboxes',
2349
    '#title' => 'Omit area levels',
2350
    '#options' => $level_options,
2351
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2352
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2353
    Areas which belong to the selected area levels will be hidden in the portal.',
2354
  );
2355

    
2356
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2357
    '#type' => 'checkbox',
2358
    '#title' => t('Show TextData elements on top of the map'),
2359
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2360
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2361
      elements on top of the map. Otherwise all <code>TextData</code>
2362
      distribution elements will be listed below the other area elements.
2363
      This option is useful if you need to have descriptive texts for each
2364
      distribution map.'),
2365
  );
2366

    
2367
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2368
      '#type' => 'textarea',
2369
      '#title' => t('Custom status colors'),
2370
      '#element_validate' => array('form_element_validate_json'),
2371
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2372
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2373
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2374
          reference list of the idInVocabulary values of absence and presence terms:
2375
<pre>
2376
Presence Term
2377
p        present
2378
pd        present: doubtfully present
2379
n        native
2380
nq        native: presence questionable
2381
nd        native: doubtfully native
2382
c        cultivated
2383
i        introduced
2384
iq        introduced: presence questionable
2385
id        introduced: doubtfully introduced (perhaps cultivated only)
2386
ip        introduced: uncertain degree of naturalisation
2387
ia        introduced: adventitious (casual)
2388
in        introduced: naturalized
2389
ic        introduced: cultivated
2390
e        endemic for the relevant area
2391
na        naturalised
2392
iv        invasive
2393

2394
AbsenceTerm
2395
a        absent
2396
f        reported in error
2397
nf        native: reported in error
2398
if        introduced: reported in error
2399
cf        cultivated: reported in error
2400
ne        native: formerly native
2401
ie        introduced: formerly introduced
2402

2403
</pre>'),
2404
  );
2405

    
2406

    
2407
  /* ====== SYNONYMY ====== */
2408
  $form['taxon_synonymy'] = array(
2409
    '#type' => 'fieldset',
2410
    '#title' => t('Taxon synonymy (tab)'),
2411
    '#collapsible' => TRUE,
2412
    '#collapsed' => TRUE,
2413
    '#description' => t('This section covers the settings related to the taxon
2414
      <strong>synonymy</strong> tab.'),
2415
  );
2416

    
2417
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2418
    '#type' => 'checkbox',
2419
    '#title' => t('Show accepted taxon on top of the synonymy'),
2420
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2421
    '#description' => t('If checked, the first homotypic taxon is a repetition
2422
      of the accepted taxon most likely with the full nomenclatural reference
2423
      (depending on the currently chosen theme).'),
2424
  );
2425

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

    
2435
  /* === currently unused ===
2436
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2437
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2438
    '#type' => 'checkboxes',
2439
    '#title' => t('Display name relationships') . ':',
2440
    '#default_value' => variable_get('name_relationships_to_show', 0),
2441
    '#options' => $nameRelationshipTypeOptions,
2442
    '#description' => t('Select the name relationships you want to show for the
2443
      accepted taxa.'),
2444
  );
2445
 */
2446

    
2447
  $form['taxon_synonymy']['taxon_relations'] = array(
2448
    '#type' => 'fieldset',
2449
    '#title' => t('Taxon relationships'),
2450
    '#collapsible' => FALSE,
2451
    '#collapsed' => FALSE
2452
  );
2453

    
2454
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2455
    '#type' => 'checkbox',
2456
    '#title' => t('Show taxon relations ships of accepted taxon'),
2457
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2458
    '#description' => t('If this option is enabled the synonymy will show the
2459
      below selected taxon relationships of accepted taxa.'),
2460
  );
2461

    
2462
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2463
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2464
    '#type' => 'checkboxes',
2465
    '#title' => t('Taxon relationship types') . ':',
2466
    '#description' => t('Only taxon relationships of the selected type will be
2467
      displayed'),
2468
    '#options' => $taxonRelationshipTypeOptions,
2469
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2470
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2471
  );
2472

    
2473
  $form['taxon_synonymy']['name_relations'] = array(
2474
    '#type' => 'fieldset',
2475
    '#title' => t('Name relationships'),
2476
    '#collapsible' => FALSE,
2477
    '#collapsed' => FALSE
2478
  );
2479

    
2480
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2481
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2482
    '#type' => 'checkboxes',
2483
    '#title' => t('Name relationship types') . ':',
2484
    '#description' => t('Only name relationships of the selected type will be
2485
      displayed'),
2486
    '#options' => $taxonRelationshipTypeOptions,
2487
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2488
  );
2489

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

    
2500
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2501

    
2502
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2503
    '#type' => 'checkbox',
2504
    '#title' => t('Show specimen derivatives in a compressed table'),
2505
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2506
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2507
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2508
  );
2509

    
2510
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2511
        '#type' => 'textfield',
2512
        '#title' => t('Number of records per page') . ':',
2513
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2514
    );
2515

    
2516
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2517
    '#type' => 'checkbox',
2518
    '#title' => t('Show "Associated with" in specimen table.'),
2519
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2520
  );
2521

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

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

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

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

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

    
2588
/**
2589
 * @todo document this function.
2590
 */
2591
function cdm_settings_layout_search() {
2592

    
2593
  $form = array();
2594

    
2595
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2596

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

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

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

    
2626
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2627
    '#type' => 'textfield',
2628
    '#title' => t('Results per page') . ':',
2629
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2630
    '#description' => t('Number of results to display per page.'),
2631
  );
2632

    
2633
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2634
    '#type' => 'checkbox',
2635
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2636
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2637
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2638
  );
2639

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

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

    
2657
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2658
  );
2659

    
2660
  // --- SEARCH TAXA GALLERY ---- //
2661
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2662
  $collapsed = FALSE;
2663
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2664
  $form_title = 'Taxa Search thumbnails';
2665
  $form_description = 'Search results may show thumbnails. ';
2666
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2667

    
2668
  // Comment @WA: D7 form api does not support reset buttons,
2669
  // so to mimic the D5 reset button we add one like this.
2670
  $form['actions']['reset'] = array(
2671
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2672
    '#weight' => 1000,
2673
  );
2674
  return system_settings_form($form);
2675
}
2676

    
2677
/**
2678
 * @todo document this function.
2679
 */
2680
function cdm_settings_layout_media() {
2681

    
2682
  $form = array();
2683

    
2684
  $form['media_settings'] = array(
2685
    '#type' => 'fieldset',
2686
    '#title' => t('Media settings'),
2687
    '#collapsible' => FALSE,
2688
    '#collapsed' => FALSE,
2689
    '#description' => 'This section covers layout settings for media pages.'
2690
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2691
  );
2692

    
2693
  $form['media_settings']['image_gallery_viewer'] = array(
2694
    '#type' => 'select',
2695
    '#title' => t('Image viewer') . ':',
2696
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2697
    '#options' => array(
2698
      'default' => t('Standard image viewer'),
2699
      'fsi' => t('FSI viewer (requires FSI server!)'),
2700
    ),
2701
  );
2702

    
2703
  // --- MEDIA GALLERY ---- //
2704
  $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
2705
  $form_title = 'Standard viewer';
2706
  $form_description = '<p>Configure the standard image viewer.</p><p><strong>Note:</strong> the image viewer should selected otherwise settings are not taking into account.</p>';
2707
  // $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed);
2708
  $form['media_settings'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2709

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

    
2719
/**
2720
 * GEOSERVICE and Map settings.
2721
 */
2722
function cdm_settings_geo($form, &$form_state) {
2723

    
2724
  $current_geoserver_settings = get_edit_map_service_settings();
2725
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2726

    
2727

    
2728
  $form = array();
2729

    
2730
  $dummy_distribution_query = NULL;
2731
  if($map_distribution['map_type'] != 1){
2732
    // we need to apply a dummy query since the map service requires for image maps
2733
    // at least as and ad to be defined
2734
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2735
  }
2736

    
2737
  $form['map_preview'] = array(
2738
      '#type' => 'fieldset',
2739
      '#tree' => FALSE,
2740
      '#title' => t('Map preview'),
2741
      '#collapsible' => FALSE,
2742
      '#description' => 'The preview of the map'
2743
       . ($dummy_distribution_query != null ?
2744
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2745
           '.<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.')
2746
  );
2747
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2748
    'move' => "this.cdmOpenlayersMap.printInfo",
2749
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2750
  ), true // resizable
2751
  );
2752

    
2753
  /*
2754
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2755
  );
2756
  */
2757

    
2758
  /*
2759
   * GEO SERVER
2760
   */
2761
  $form['edit_map_server'] = array(
2762
    '#type' => 'fieldset',
2763
    '#tree' => true,
2764
    '#title' => t('EDIT map service'),
2765
    '#collapsible' => TRUE,
2766
    '#collapsed' => TRUE,
2767
    '#description' => t('Configuration and selection of your geo server.
2768
      The Geo Server is responsible for generating the maps.'),
2769
  );
2770

    
2771
  $form['edit_map_server']['base_uri'] = array(
2772
    '#type' => 'select',
2773
    '#title' => t('EDIT map service') . ':',
2774
    '#default_value' => $current_geoserver_settings['base_uri'],
2775
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2776
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2777
  );
2778
  $form['edit_map_server']['version'] = array(
2779
      '#type' => 'select',
2780
      '#title' => t('Version') . ':',
2781
      '#default_value' => $current_geoserver_settings['version'],
2782
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2783
      '#description' => t('The version of the EDIT map services'),
2784
  );
2785

    
2786
  /*
2787
   * MAP SETTINGS
2788
   */
2789

    
2790
  $form[CDM_MAP_DISTRIBUTION] = array(
2791
    '#type' => 'fieldset',
2792
    '#tree' => TRUE,
2793
    '#title' => t('Maps settings'),
2794
    '#collapsible' => TRUE,
2795
    '#collapsed' => TRUE,
2796
    '#description' => t('General configuration for all map types.'),
2797
  );
2798

    
2799
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2800
    '#type' => 'radios',
2801
    '#title' => 'Map types',
2802
    '#options' => array(
2803
      1 => "OpenLayers dynamic map viewer",
2804
      0 => "Plain image",
2805
    ),
2806
    '#default_value' => $map_distribution['map_type'],
2807
    '#description' => 'Two different map types are available :
2808
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2809
      which allows zooming and panning. If enabled you can configure the default layer
2810
      (background of your maps) below.</li>
2811
      <li><em>Plain image</em>: The map will be static non interactive
2812
      image.</li></ul>',
2813
  );
2814
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2815

    
2816
  /*
2817
   * settings for the distribution map are used also for specimens map!!!!
2818
   */
2819

    
2820
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2821
      '#type' => 'textfield',
2822
      '#title' => 'Aspect ratio',
2823
      '#default_value' => $map_distribution['aspect_ratio'],
2824
      '#maxlength' => 4,
2825
      '#size' => 4,
2826
      '#element_validate' => array('element_validate_number'),
2827
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2828
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2829
      width by the height:</br>
2830
      <pre>aspect ratio = w / h</pre>
2831
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2832
      for a square map use <strong>1</strong>.',
2833
  );
2834

    
2835
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2836
    '#type' => 'textfield',
2837
    '#title' => 'Bounding box',
2838
    '#default_value' => $map_distribution['bbox'],
2839
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2840
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2841
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2842
      <strong>TIP:</strong> You can use the map preview above to choose the <span class="map-extent-bbox"><strong>map extent bbox</strong> in <strong class="degree-value"">degree</strong></span> from the map.
2843
      (Maybe you need to change the map base layer to OpeLayers.)
2844
      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
2845
      below the map from where you can copy the bbox string.</p>'),
2846
  );
2847

    
2848
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2849
    '#type' => 'select',
2850
    '#title' => 'Max zoom level',
2851
    '#default_value' => $map_distribution['maxZoom'],
2852
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2853
  );
2854

    
2855
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2856
    '#type' => 'checkbox',
2857
    '#title' => 'Display area labels',
2858
    '#default_value' => $map_distribution['show_labels'],
2859
    '#description' => t('The map will show name labels of the areas'),
2860
  );
2861

    
2862
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2863
    '#type' => 'textfield',
2864
    '#title' => 'Map caption',
2865
    '#default_value' => $map_distribution['caption'],
2866
    '#description' => t('The caption will be shown below the map.'),
2867
  );
2868

    
2869
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2870
    '#type' => 'textfield',
2871
    '#title' => 'Distribution layer opacity',
2872
    '#default_value' => $map_distribution['distribution_opacity'],
2873
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2874
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2875
  );
2876

    
2877
  // --- Plain Image Settings --- //
2878
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2879
    '#type' => 'fieldset',
2880
    '#title' => 'Plain image map settings',
2881
    '#tree' => TRUE,
2882
    '#collapsible' => TRUE,
2883
    '#collapsed' => $open_layers_is_enabled,
2884
    '#description' => 'The settings in this section are still expertimental
2885
      and can only be used with the EDIT map service version 1.1 or above.',
2886
  );
2887
  $edit_mapserver_version = get_edit_map_service_version_number();
2888
  if ($edit_mapserver_version < 1.1) {
2889
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2890
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2891
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2892
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2893
  }
2894

    
2895
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2896
    '#type' => 'textfield',
2897
    '#title' => 'Width',
2898
    '#default_value' => $map_distribution['image_map']['width'],
2899
    '#maxlength' => 4,
2900
    '#size' => 4,
2901
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2902
  );
2903

    
2904
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2905
    '#type' => 'textfield',
2906
    '#title' => 'Background layer',
2907
    '#default_value' => $map_distribution['image_map']['base_layer'],
2908
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2909
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2910
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2911
    )),
2912
  );
2913

    
2914
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2915
    '#type' => 'textfield',
2916
    '#title' => 'Background color',
2917
    '#default_value' => $map_distribution['image_map']['bg_color'],
2918
  );
2919

    
2920
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2921
    '#type' => 'textfield',
2922
    '#title' => 'Background layer style',
2923
     // Only line color by now.
2924
    '#default_value' => $map_distribution['image_map']['layer_style'],
2925
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2926
  );
2927

    
2928
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2929
      '#type' => 'textfield',
2930
      '#title' => 'Projection',
2931
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2932
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2933
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2934
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2935
  );
2936

    
2937

    
2938
  // --- OpenLayers Settings --- //
2939
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2940
    '#type' => 'fieldset',
2941
    '#title' => 'OpenLayers settings',
2942
    '#tree' => TRUE,
2943
    '#collapsible' => TRUE,
2944
    '#collapsed' => !$open_layers_is_enabled,
2945
    '#description' => '',
2946
  );
2947

    
2948

    
2949
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
2950
      '#type' => 'checkbox',
2951
      '#title' => 'Display outside max extent',
2952
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
2953
      '#description' => t('Allows the map to display parts of the layers which are outside
2954
         the max extent if the aspect ratio of the map and of the baselayer
2955
         are not equal.'),
2956
  );
2957

    
2958

    
2959
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
2960
      '#type' => 'checkbox',
2961
      '#title' => 'Show Layer Switcher',
2962
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
2963
      '#description' => 'The Layer Switcher control displays a table of contents
2964
      for the map.  This allows the user interface to switch between
2965
      base layers and to show or hide overlays.  By default the switcher is
2966
      shown minimized on the right edge of the map, the user may expand it
2967
      by clicking on the handle.',
2968
  );
2969

    
2970
  if (!$open_layers_is_enabled) {
2971
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
2972
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
2973
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
2974
  }
2975

    
2976
  // The default layer must always be enabled
2977
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
2978
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
2979

    
2980
  $baselayer_options = array(
2981
    /*
2982
   NOTICE: must correspond to the layers defined in
2983
   js/openlayers_,ap.js#getLayersByName()
2984
   */
2985
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
2986
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
2987
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
2988
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
2989
    'edit-etopo1' => "ETOPO1 Global Relief Model",
2990
    // all others EPSG:900913
2991
    'mapnik' => 'OpenStreetMap',
2992
    // map quest is no longer free. it is required to sign up for a test plan.
2993
    // 'mapquest_open' => "MapQuest",
2994
    // 'mapquest_sat' => "MapQuest Sattelite",
2995
    'groadmap' => 'Google Roadmap',
2996
    'gsatellite' => 'Google Satellite',
2997
    'ghybrid' => 'Google Hybrid',
2998
    'gterrain' => 'Google Terrain',
2999
//     'veroad' => 'Virtual Earth Roads',
3000
//     'veaer' => 'Virtual Earth Aerial',
3001
//     'vehyb' => 'Virtual Earth Hybrid',
3002
    // 'yahoo' => 'Yahoo Street',
3003
    // 'yahoosat' => 'Yahoo Satellite',
3004
    // 'yahoohyb' => 'Yahoo Hybrid',
3005
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3006
  );
3007

    
3008
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3009
    '#type' => 'checkboxes_preferred',
3010
    '#title' => 'Base Layers',
3011
    '#options' => $baselayer_options,
3012
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3013
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3014
  );
3015

    
3016
  $google_maps_api_key = null;
3017
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3018
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3019
  }
3020
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3021
    '#type' => 'textfield',
3022
    '#title' => 'Google Maps API Key',
3023
    '#default_value' => $google_maps_api_key,
3024
    '#description' => 'In order to use any of the Google map layers you need to provide 
3025
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3026
  );
3027

    
3028
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3029
    $map_distribution['openlayers']['custom_wms_base_layer'],
3030
    'Custom WMS base layer',
3031
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3032
    true // add projection settings
3033
    );
3034

    
3035
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3036
    $map_distribution['openlayers']['wms_overlay_layer'],
3037
    'WMS overlay layer',
3038
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3039
                You can actually combine multiple layers for this overlay. 
3040
                For details please refer to the wms query parameter <code>Layers</code> .'
3041
  );
3042

    
3043
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3044
    '#type' => 'checkbox',
3045
    '#title' => 'Enable overlay layer',
3046
    '#weight' => -100,
3047
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3048
  );
3049

    
3050
  /*
3051
   * Map Legend
3052
   */
3053
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3054
    '#type' => 'fieldset',
3055
    '#title' => 'Map legend',
3056
    '#tree' => TRUE,
3057
    '#collapsible' => TRUE,
3058
    '#collapsed' => TRUE,
3059
    '#description' => 'Configure the maps legend.',
3060
  );
3061

    
3062
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3063
    '#type' => 'checkbox',
3064
    '#title' => 'Display a map legend',
3065
    '#default_value' => $map_distribution['legend']['show'],
3066
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3067
  );
3068

    
3069
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3070
    '#type' => 'textfield',
3071
    '#title' => 'Legend opacity',
3072
    '#default_value' => $map_distribution['legend']['opacity'],
3073
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3074
                         to 0.0 will be not much visible.',
3075
  );
3076

    
3077
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3078
    '#type' => 'textfield',
3079
    '#title' => 'Font size',
3080
    '#default_value' => $map_distribution['legend']['font_size'],
3081
    '#description' => 'Font size in pixels.',
3082
  );
3083

    
3084
  $fontStyles = array(
3085
    0 => "plane",
3086
    1 => "italic",
3087
  );
3088
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3089
    '#type' => 'select',
3090
    '#title' => 'Available font styles',
3091
    '#default_value' => $map_distribution['legend']['font_style'],
3092
    '#options' => $fontStyles,
3093
    '#description' => 'Select a font style for the map legend.',
3094
  );
3095

    
3096
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3097
    '#type' => 'textfield',
3098
    '#title' => 'Icon width',
3099
    '#default_value' => $map_distribution['legend']['icon_width'],
3100
    '#description' => 'Legend icon width in pixels.',
3101
  );
3102
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3103
    '#type' => 'textfield',
3104
    '#title' => 'Icon height',
3105
    '#default_value' => $map_distribution['legend']['icon_height'],
3106
    '#description' => 'Legend icon height in pixels.',
3107
  );
3108

    
3109
  // @WA: D7 form api does not support reset buttons,
3110
  // so to mimic the D5 reset button we add one like this.
3111
  $form['actions']['reset'] = array(
3112
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3113
    '#weight' => 1000,
3114
  );
3115

    
3116
  return system_settings_form($form);
3117
}
3118

    
3119
/**
3120
 * @param $default_settings
3121
 * @param $title
3122
 * @param $description
3123
 * @param bool $add_projection_settings
3124
 * @return array
3125
 */
3126
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3127
{
3128
  $form_elements = array(
3129
    '#type' => 'fieldset',
3130
    '#title' => $title,
3131
    '#tree' => TRUE,
3132
    '#collapsible' => FALSE,
3133
    '#collapsed' => FALSE,
3134
    '#description' => $description,
3135
  );
3136

    
3137
  $form_elements['name'] = array(
3138
    '#type' => 'textfield',
3139
    '#title' => 'Layer name',
3140
    // Only line color by now.
3141
    '#default_value' => $default_settings['name'],
3142
    '#description' => 'A arbitrary name for the layer.',
3143
  );
3144
  $form_elements['url'] = array(
3145
    '#type' => 'textfield',
3146
    '#title' => 'WMS url',
3147
    // Only line color by now.
3148
    '#default_value' => $default_settings['url'],
3149
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3150
  );
3151
  $form_elements['params'] = array(
3152
    '#type' => 'textarea',
3153
    '#title' => 'WMS parameters',
3154
    '#element_validate' => array('form_element_validate_json'),
3155
    // Only line color by now.
3156
    '#default_value' => $default_settings['params'],
3157
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3158
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3159
      . '), entered in valid JSON. For example:
3160
<pre> {
3161
  "Layers": "topp:em_tiny_jan2003",
3162
  "Format": "image/png",
3163
  "BGCOLOR": "0xe0faff"
3164
}
3165
</pre>
3166
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3167
  );
3168

    
3169
  if($add_projection_settings){
3170

    
3171
    $form_elements['projection'] = array(
3172
      '#type' => 'textfield',
3173
      '#title' => 'Projection',
3174
      // Only line color by now.
3175
      '#default_value' => $default_settings['projection'],
3176
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3177
    );
3178
    $form_elements['proj4js_def'] = array(
3179
      '#type' => 'textfield',
3180
      '#maxlength' => 256,
3181
      '#title' => 'proj4js definition',
3182
      // Only line color by now.
3183
      '#default_value' => $default_settings['proj4js_def'],
3184
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3185
              The definitions for
3186
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3187
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3188
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3189
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3190
              choose to display the proj4js definition string.
3191
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3192
              <pre>
3193
  +a         Semimajor radius of the ellipsoid axis
3194
  +alpha     ? Used with Oblique Mercator and possibly a few others
3195
  +axis      Axis orientation (new in 4.8.0)
3196
  +b         Semiminor radius of the ellipsoid axis
3197
  +datum     Datum name (see `proj -ld`)
3198
  +ellps     Ellipsoid name (see `proj -le`)
3199
  +k         Scaling factor (old name)
3200
  +k_0       Scaling factor (new name)
3201
  +lat_0     Latitude of origin
3202
  +lat_1     Latitude of first standard parallel
3203
  +lat_2     Latitude of second standard parallel
3204
  +lat_ts    Latitude of true scale
3205
  +lon_0     Central meridian
3206
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3207
  +lon_wrap  Center longitude to use for wrapping (see below)
3208
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3209
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3210
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3211
  +pm        Alternate prime meridian (typically a city name, see below)
3212
  +proj      Projection name (see `proj -l`)
3213
  +south     Denotes southern hemisphere UTM zone
3214
  +to_meter  Multiplier to convert map units to 1.0m
3215
  +towgs84   3 or 7 term datum transform parameters (see below)
3216
  +units     meters, US survey feet, etc.
3217
  +vto_meter vertical conversion to meters.
3218
  +vunits    vertical units.
3219
  +x_0       False easting
3220
  +y_0       False northing
3221
  +zone      UTM zone
3222
              </pre>
3223
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3224
    );
3225
    $form_elements['max_extent'] = array(
3226
      '#type' => '