Project

General

Profile

Download (152 KB) Statistics
| Branch: | Tag: | Revision:
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_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
27
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
28
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
29
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
30
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
31

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

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

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

    
51
  /* taxonRelationshipTypes */
52
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
53
    array(
54
      UUID_MISAPPLIED_NAME_FOR,
55
      UUID_PROPARTE_MISAPPLIEDNAME_FOR,
56
      UUID_PARTIAL_MISAPPLIEDNAME_FOR,
57
      UUID_PROPARTE_SYNONYM_FOR,
58
      UUID_PARTIAL_SYNONYM_FOR,
59
      UUID_INVALID_DESIGNATION_FOR
60
    )
61
  ));
62

    
63

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

    
94
    // --- Taxon profile settings --- /
95
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
96
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
97
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
98
      array(
99
          'show' => 0,
100
          'maxextend' => 184,
101
          'media_uri_query' => '',
102
          'custom_placeholder_enabled' => 1,
103
          'custom_placeholder_image_on' => 0,
104
          'custom_placeholder_image_fid' => ''
105
      )
106
    )
107
  );
108

    
109

    
110
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
111

    
112
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
113
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
114
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
115
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
116
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
117

    
118
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
119
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
120
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
121
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
122

    
123
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
124
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
125

    
126
/**
127
 * Returns the array of implemented taxon page tabs.
128
 * The array has fixed integer keys which must not be changed.
129
 */
130
function get_taxon_tabs_list() {
131
  $opts = array(
132
    0 => 'General',
133
    1 => 'Synonymy',
134
    2 => 'Images',
135
    3 => 'Specimens',
136
    4 => 'Keys',
137
    5 => 'Experts',
138
  );
139
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
140
    // skip the Synonymy if it is shown in  the general tab
141
    unset($opts[1]);
142
  }
143
  return $opts;
144
}
145

    
146
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
147
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
148
  array(
149
    'general' => '-3',
150
    'synonymy' => '-2',
151
    'images' => '0',
152
    'specimens' => '1',
153
    'keys' => '3',
154
    'experts' => '5',
155
    )
156
));
157

    
158

    
159
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
160
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
161
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
162
  array(
163
    'general' => null,
164
    'synonymy' => null,
165
    'images' => null,
166
    'specimens' => null,
167
    'keys' => null,
168
    'experts' => null,
169
  )
170
));
171

    
172
$taxon_tab_options = get_taxon_tabs_list();
173
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
174

    
175
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
176

    
177
/**
178
 * @todo document this function.
179
 */
180
function get_taxon_options_list() {
181
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
182
  foreach ($taxon_tab_options as $key => $value) {
183
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
184
  }
185
  return $taxon_tab_options;
186

    
187
}
188

    
189
define('CDM_PART_DEFINITIONS', 'cdm-part-definitions');
190
define('CDM_PART_DEFINITIONS_DEFAULT', serialize(
191
    array(
192
      'ZoologicalName' => array(
193
        'namePart' => array('name' => TRUE),
194
        'nameAuthorPart' => array('name' => TRUE),
195
        'referencePart' => array('authors' => TRUE),
196
        'microreferencePart' => array('microreference' => TRUE),
197
        'secReferencePart' => array('secReference' => TRUE,),
198
        'statusPart' => array('status' => TRUE),
199
        'descriptionPart' => array('description' => TRUE),
200
      ),
201
      'BotanicalName'=> array(
202
        'namePart' => array('name' => TRUE),
203
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
204
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
205
        'secReferencePart' => array('secReference' => TRUE,),
206
        'referenceYearPart' => array('reference.year' => TRUE),
207
        'statusPart' => array('status' => TRUE),
208
        'descriptionPart' => array('description' => TRUE),
209
      ),
210
     '#DEFAULT' => array(
211
        'namePart' => array(
212
            'name' => TRUE
213
        ),
214
        'nameAuthorPart' => array(
215
            'name' => TRUE,
216
            'authors' => TRUE
217
        ),
218
       'referencePart' => array(
219
         'reference' => TRUE
220
        ),
221
       'secReferencePart' => array(
222
         'secReference' => TRUE,
223
       ),
224
       'microreferencePart' => array(
225
          'microreference' => TRUE,
226
        ),
227
       'statusPart' => array(
228
          'status' => TRUE,
229
        ),
230
       'descriptionPart' => array(
231
          'description' => TRUE,
232
        ),
233
      )
234
    )
235
  )
236
);
237
define('CDM_PART_DEFINITIONS_DEFAULT_PRE_380', serialize(
238
    array(
239
      'ZoologicalName' => array(
240
        'namePart' => array('name' => TRUE),
241
        'nameAuthorPart' => array('name' => TRUE),
242
        'referencePart' => array('authors' => TRUE),
243
        'microreferencePart' => array('microreference' => TRUE),
244
        'statusPart' => array('status' => TRUE),
245
        'descriptionPart' => array('description' => TRUE),
246
      ),
247
      'BotanicalName'=> array(
248
        'namePart' => array('name' => TRUE),
249
        'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
250
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
251
        'referenceYearPart' => array('reference.year' => TRUE),
252
        'statusPart' => array('status' => TRUE),
253
        'descriptionPart' => array('description' => TRUE),
254
      ),
255
      '#DEFAULT' => array(
256
        'namePart' => array(
257
          'name' => TRUE
258
        ),
259
        'nameAuthorPart' => array(
260
          'name' => TRUE,
261
          'authors' => TRUE
262
        ),
263
        'referencePart' => array(
264
          'reference' => TRUE
265
        ),
266
        'microreferencePart' => array(
267
          'microreference' => TRUE,
268
        ),
269
        'statusPart' => array(
270
          'status' => TRUE,
271
        ),
272
        'descriptionPart' => array(
273
          'description' => TRUE,
274
        ),
275
      )
276
    )
277
  )
278
  );
279

    
280
define('CDM_NAME_RENDER_TEMPLATES', 'cdm-name-render-templates');
281
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT', serialize(
282
  array (
283
    'taxon_page_title,polytomousKey'=> array(
284
        'namePart' => array('#uri' => TRUE),
285
      ),
286
    'not_in_current_classification' => array(
287
     'nameAuthorPart' => TRUE,
288
     'referencePart' => TRUE,
289
     'statusPart' => TRUE,
290
     'secReferencePart' => TRUE,
291
    ),
292
    'taxon_page_synonymy,accepted_taxon.taxon_page_synonymy'=> array(
293
      'nameAuthorPart' => array('#uri' => TRUE),
294
      'referencePart' => TRUE,
295
      'descriptionPart' => TRUE,
296
      'statusPart' => TRUE,
297
    ),
298
    'related_taxon.other_taxon_relationship.taxon_relationships.taxon_page_synonymy'=> array(
299
      'nameAuthorPart' => array('#uri' => TRUE),
300
      'referencePart' => TRUE,
301
      'descriptionPart' => TRUE,
302
      'statusPart' => TRUE,
303
      'secReferencePart' => TRUE,
304
    ),
305
    'related_taxon.misapplied_name_for.taxon_relationships.taxon_page_synonymy' => array(
306
      'nameAuthorPart' => array('#uri' => TRUE),
307
      'referencePart' => TRUE,
308
      'descriptionPart' => TRUE,
309
      'statusPart' => TRUE,
310
      /* no sec ref in this case, misapplied names are
311
       * de-duplicated and the sec ref is shown as footnote */
312
    ),
313
    'homonym'=> array(
314
        'nameAuthorPart' => array('#uri' => TRUE),
315
        'referenceYearPart' => TRUE,
316
        'statusPart' => TRUE,
317
    ),
318
    'acceptedFor,typedesignations,list_of_taxa' => array(
319
        'nameAuthorPart' => array('#uri' => TRUE),
320
        'referencePart' => TRUE,
321
      ),
322
    '#DEFAULT' => array(
323
        'nameAuthorPart' => array('#uri' => TRUE),
324
        'referencePart' => TRUE,
325
     )
326
  )
327
));
328
define('CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380', serialize(
329
  array (
330
    'taxon_page_title,polytomousKey'=> array(
331
      'namePart' => array('#uri' => TRUE),
332
    ),
333
    'taxon_page_synonymy,related_taxon'=> array(
334
      'nameAuthorPart' => array('#uri' => TRUE),
335
      'referencePart' => TRUE,
336
      'statusPart' => TRUE,
337
      'descriptionPart' => TRUE,
338
    ),
339
    'homonym'=> array(
340
      'nameAuthorPart' => array('#uri' => TRUE),
341
      'referenceYearPart' => TRUE,
342
    ),
343
    'acceptedFor,typedesignations,list_of_taxa' => array(
344
      'nameAuthorPart' => array('#uri' => TRUE),
345
      'referencePart' => TRUE,
346
    ),
347
    '#DEFAULT' => array(
348
      'nameAuthorPart' => array('#uri' => TRUE),
349
      'referencePart' => TRUE,
350
    )
351
  )
352
));
353

    
354
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
355
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
356
    // to unset a default enntry set the value to 0
357
    array(
358
      'doTaxa'=>'doTaxa',
359
      'doSynonyms' => 'doSynonyms',
360
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
361
      'doMisappliedNames' => 'doMisappliedNames'
362
    )
363
  )
364
);
365

    
366
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
367

    
368
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
369
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
370
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
371

    
372
/* Gallery variables. */
373
$gallery_settings = array(
374
    "cdm_dataportal_show_taxon_thumbnails" => 1,
375
    "cdm_dataportal_show_synonym_thumbnails" => 0,
376
    "cdm_dataportal_show_thumbnail_captions" => 1,
377
    "cdm_dataportal_media_maxextend" => 120,
378
    "cdm_dataportal_media_cols" => 3,
379
    "cdm_dataportal_media_maxRows" => 1,
380
);
381

    
382
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
383
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
384
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
385
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
386
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
387
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
388
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
389
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
390
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
391
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
392
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
393

    
394
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
395
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
396
  'media_representation_details_enabled' => 0
397
)));
398

    
399
/**
400
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
401
 * the snonymy.
402
 *
403
 * @var string
404
 */
405
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
406

    
407
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
408
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
409
    array(
410
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
411
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
412
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
413
    )
414
  )
415
);
416

    
417
/**
418
 * The drupal variable for the configuration of the information aggregation along
419
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
420
 *    - direct: the uuids of the taxon relationship types to take into account in invers
421
 *      direction.
422
 *    - invers: the uuids of the taxon relationship types to take into account in direct
423
 *      direction.
424
 *
425
 * @var String
426
 */
427
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
428
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
429
    array(
430
        'direct'=>array(),
431
        'invers'=>array()
432
     )
433
   ));
434
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
435
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
436
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
437

    
438
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
439
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
440
      array(
441
      'filter_rules' => array(
442
        'statusOrderPreference' => 0,
443
        'subAreaPreference' => 0,
444
      ),
445
      'hiddenAreaMarkerType' => array()
446
     )
447
));
448

    
449
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
450
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
451
  "level_0" => array(
452
    'label_suffix' => ':',
453
    'status_glue' => '',
454
    'item_glue' => ' ',
455
    'item_group_prefix' => '',
456
    'item_group_postfix' => ''
457
  ),
458
  "level_1" => array(
459
    'label_suffix' => '',
460
    'status_glue' => '‒ ', // '&#8210; '
461
    'item_glue' => '; ',
462
    'item_group_prefix' => ', ',
463
    'item_group_postfix' => ''
464
  ),
465
  "level_2" => array(
466
    'label_suffix' => '',
467
    'status_glue' => '‒ ', // '&#8210; '
468
    'item_glue' => ', ',
469
    'item_group_prefix' => ' (',
470
    'item_group_postfix' => ')'
471
  )
472
)));
473

    
474
/**
475
 * Constant for the drupal variable key distribution_map_visibility
476
 *
477
 * possible values:
478
 *  - never
479
 *  - automatic
480
 *  - always
481
 */
482
define('DISTRIBUTION_MAP_VISIBILITY', 'distribution_map_visibility');
483
define('DISTRIBUTION_MAP_VISIBILITY_DEFAULT', 'automatic');
484

    
485
/**
486
 * Constant for the drupal variable key specimen_map_visibility
487
 *
488
 * possible values:
489
 *  - never
490
 *  - automatic
491
 *  - always
492
 */
493
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
494
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
495

    
496
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
497
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
498
    array(
499
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
500
        'includeOccurrences' => 0,
501
        'includeTaxonNameDescriptions' => 0
502
     )
503
  ));
504

    
505
define('CDM_MAP_DISTRIBUTION', 'cdm_map_distribution');
506
define('CDM_MAP_DISTRIBUTION_DEFAULT', serialize(array(
507
  // needs to be merged with user setting by drupal_array_merge_deep()
508
  // 'width' => 512, // optimum size for OSM layers is 512
509
  // 'height' => 512 / 2, // optimum size for OSM layers 256
510
  'aspect_ratio' => 2,
511
  'bbox' => '', // empty to allow automatic zooming to extend
512
  'maxZoom' => 15, // corresponds to the default in cdm_openlayers_map.defaults
513
  'show_labels' => FALSE,
514
  'caption' => '',
515
  'distribution_opacity' => '0.5',
516
  'map_type' => 1, //  1 = 'openlayers', 0 = 'image'
517
  'image_map' => array(
518
    'base_layer' => '', // none, formerly this was cyprusdivs
519
    'bg_color' => '1874CD',
520
    'layer_style' => 'ffffff,606060,,',
521
  ),
522
  'openlayers' => array(
523
    'base_layers' =>  array(
524
      // A layer MUST NOT BE SET in the defaults,
525
      // otherwise it can not be overidden by the user settings:
526
      // 'mapproxy_vmap0' => 'mapproxy_vmap0',
527
      // it is sufficient to define the preferred layer,
528
      // since it will automatically be enabled:
529
      'PREFERRED' => 'mapproxy_vmap0'),
530
    'custom_wms_base_layer' => array(
531
      'name' => NULL,
532
      'url' => NULL,
533
      'params' =>  NULL,
534
      'projection' => NULL,
535
      'proj4js_def' => NULL,
536
      'max_extent' => NULL,
537
      'units' => NULL,
538
      'untiled' => FALSE
539
    ),
540
    'wms_overlay_layer' => array(
541
      'name' => NULL,
542
      'url' => NULL,
543
      'params' =>  NULL,
544
      'untiled' => FALSE
545
    ),
546
    'show_layer_switcher' => TRUE,
547
    'display_outside_max_extent' => FALSE,
548
    'google_maps_api_key' => NULL,
549
  ),
550
  'legend' => array(
551
    'show' => TRUE,
552
    'opacity' => '0.5',
553
    'font_size' => 10,
554
    'font_style' => FALSE,
555
    'icon_width' => 35,
556
    'icon_height' => 15
557
  )
558
)));
559

    
560
/**
561
 * Merges the named array variable with the array of defaults.
562
 *
563
 * IMPORTANT: The array keys must be strings. When the keys are integers
564
 * the merging will not take place for these entities. Number keyed entities
565
 * are just appended to the result array.
566
 *
567
 * @param string $variable_name
568
 *     The variable name
569
 * @param string | array $default
570
 *     The array containing the default values either as array or serialized as string.
571
 *     Unserialization is cared for if necessary
572
 * @return array
573
 *     The merged array as returned by drupal_array_merge_deep()
574
 *
575
 * TODO compare with mixed_variable_get() duplicate functions? => result use this function instead of mixed_variable_get()
576
 * TODO force $default being an array
577
 */
578
function get_array_variable_merged($variable_name, $default){
579

    
580
    // unserialize if nessecary
581
    if(!is_array($default)){
582
      $default = unserialize($default);
583
    }
584
    $variable = variable_get($variable_name, array());
585
    $result = drupal_array_merge_deep($default, $variable);
586
    return $result;
587
}
588

    
589
/**
590
 * @todo document this function.
591
 */
592
function getGallerySettings($gallery_config_form_name) {
593
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
594
}
595

    
596
/**
597
 * Returns the string representation of the default tab.
598
 *
599
 * @param bool $returnTabIndex
600
 *   Defaults to FALSE, if set true this function will return the index number
601
 *   of the default tab. (used to supply default values to form elements).
602
 */
603
function get_default_taxon_tab($returnTabIndex = FALSE) {
604

    
605
  global $user;
606
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
607
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
608
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
609
  // Get the user value if the used has chosen to overwrite the system settings.
610
  $user_tab_on = variable_get($user_tab_active, FALSE);
611
  if ($user_tab_on) {
612
    $user_value = variable_get($user_tab, 0);
613
    $index_value = $user_value;
614
    // Get the system value.
615
  }
616
  else {
617
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
618
    $index_value = $system_value;
619
  }
620

    
621
  // Return the index value or the string representation.
622
  if ($returnTabIndex) {
623
    return $index_value;
624
  }
625
  else {
626
    return ($values[$index_value]);
627
  }
628
}
629

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

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

    
701
  // ---- DEFAULTS settings
702

    
703
  // only needed as final option, when the settings are not having a default
704
  $default = array(
705
    'DEFAULT' => array(
706
      'as_list' => 'div',
707
      'link_to_reference' => 0,
708
      'link_to_name_used_in_source' => 1,
709
      'sources_as_content' => 0,
710
      'sources_as_content_to_bibliography' => 0,
711
      'sort_elements' => NO_SORT,
712
      'glue' => '',
713
      'element_tag' => NULL
714
    ),
715
    // settings for pseudo feature bibliography
716
    // only hard coded here
717
    'BIBLIOGRAPHY' => array(
718
      'as_list' => 'div',
719
      'link_to_reference' => 0,
720
      'link_to_name_used_in_source' => 1,
721
      'sources_as_content' => 0,
722
      'sources_as_content_to_bibliography' => 0,
723
      'sort_elements' => NO_SORT,
724
      'glue' => '',
725
      'element_tag' => NULL
726
    )
727
  );
728

    
729
  // will be used as preset in the settings
730
  $other_themes_default = array(
731
    'DEFAULT' => array(
732
      'as_list' => 'div',
733
      'link_to_reference' => 0,
734
      'link_to_name_used_in_source' => 1,
735
      'sources_as_content' => 0,
736
      'sources_as_content_to_bibliography' => 0,
737
      'sort_elements' => NO_SORT,
738
      'glue' => '',
739
      'element_tag' => NULL
740
    ),
741
    UUID_CITATION => array(
742
      'as_list' => 'div',
743
      'link_to_reference' => 0,
744
      'link_to_name_used_in_source' => 0,
745
      'sources_as_content' => 1,
746
      'sources_as_content_to_bibliography' => 0,
747
      'sort_elements' => SORT_ASC,
748
      'glue' => '',
749
      'element_tag' => 'div'
750
    ),
751
    UUID_DISTRIBUTION => array(
752
      'as_list' => 'div', // currently ignored
753
      'link_to_reference' => 0,
754
      'link_to_name_used_in_source' => 0,
755
      'sources_as_content' => 0,
756
      'sources_as_content_to_bibliography' => 0,
757
      'sort_elements' => NO_SORT, // will cause ...
758
      'glue' => '',
759
      'element_tag' => 'div',
760
      'special' => array()
761
    ),
762
    UUID_COMMON_NAME => array(
763
      'as_list' => 'div',
764
      'link_to_reference' => 0,
765
      'link_to_name_used_in_source' => 1,
766
      'sources_as_content' => 0,
767
      'sources_as_content_to_bibliography' => 0,
768
      'sort_elements' => NO_SORT,
769
      'glue' => '',
770
      'element_tag' => 'span'
771
    ),
772
  );
773

    
774
  // ---- Special DEFAULTS for existing portals
775
  // TODO:
776
  // this can be removed once the feature block
777
  // settings have been deployed for the first time to these portals
778

    
779
  $cichorieae_default = array(
780
    'DEFAULT' => array(
781
      'as_list' => 'div',
782
      'link_to_reference' => 1,
783
      'link_to_name_used_in_source' => 1,
784
      'sources_as_content' => 1,
785
      'sources_as_content_to_bibliography' => 0,
786
      'sort_elements' => NO_SORT,
787
      'glue' => '',
788
      'element_tag' => 'div'
789
    ),
790
    UUID_CITATION => array(
791
      'as_list' => 'div',
792
      'link_to_reference' => 0,
793
      'link_to_name_used_in_source' => 0,
794
      'sources_as_content' => 1,
795
      'sources_as_content_to_bibliography' => 0,
796
      'sort_elements' => SORT_ASC,
797
      'glue' => '',
798
      'element_tag' => 'div'
799
    ),
800
    UUID_CHROMOSOMES_NUMBERS => array(
801
      'as_list' => 'ul',
802
      'link_to_reference' => 1,
803
      'link_to_name_used_in_source' => 1,
804
      'sources_as_content' => 1,
805
      'sources_as_content_to_bibliography' => 0,
806
      'sort_elements' => NO_SORT,
807
      'glue' => '',
808
      'element_tag' => 'div'
809
    ),
810
    UUID_CHROMOSOMES => array(
811
      'as_list' => 'ul',
812
      'link_to_reference' => 0,
813
      'link_to_name_used_in_source' => 1,
814
      'sources_as_content' => 1,
815
      'sources_as_content_to_bibliography' => 0,
816
      'sort_elements' => NO_SORT,
817
      'glue' => '',
818
      'element_tag' => 'div'
819
    ),
820
    UUID_COMMON_NAME => array(
821
      'as_list' => 'div',
822
      'link_to_reference' => 0,
823
      'link_to_name_used_in_source' => 1,
824
      'sources_as_content' => 0,
825
      'sources_as_content_to_bibliography' => 0,
826
      'sort_elements' => NO_SORT,
827
      'glue' => '',
828
      'element_tag' => 'span'
829
    ),
830
  );
831

    
832
  $palmweb_default = array(
833
    'DEFAULT' => array(
834
      'as_list' => 'ul',
835
      'link_to_reference' => 1,
836
      'link_to_name_used_in_source' => 1,
837
      'sources_as_content' => 1,
838
      'sources_as_content_to_bibliography' => 1,
839
      'sort_elements' => NO_SORT,
840
      'glue' => '',
841
      'element_tag' => NULL
842
    ),
843
    UUID_CITATION => array(
844
      'as_list' => 'ul',
845
      'link_to_reference' => 1,
846
      'link_to_name_used_in_source' => 1,
847
      'sources_as_content' => 0,
848
      'sources_as_content_to_bibliography' => 1,
849
      'sort_elements' => SORT_ASC,
850
      'glue' => '',
851
      'element_tag' => 'div'
852
    ),
853
    UUID_DISTRIBUTION => array(
854
      'as_list' => 'div', // currently ignored
855
      'link_to_reference' => 1,
856
      'link_to_name_used_in_source' => 1,
857
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
858
      'sources_as_content_to_bibliography' => 1,
859
      'sort_elements' => NO_SORT, // will cause ...
860
      'glue' => ', ',
861
      'element_tag' => 'span',
862
      'special' => array()
863
    ),
864
  );
865

    
866
  $cyprus_default = $cichorieae_default;
867
  $cyprus_default[UUID_DISTRIBUTION] = array(
868
    'as_list' => 'div', // currently ignored
869
    'link_to_reference' => 0,
870
    'link_to_name_used_in_source' => 0,
871
    'sources_as_content' => 0,
872
    'sources_as_content_to_bibliography' => 0,
873
    'sort_elements' => NO_SORT, // will cause ...
874
    'glue' => ' ',
875
    'element_tag' => 'div',
876
    'special' => array()
877
  );
878

    
879
  $default_theme = variable_get('theme_default', NULL);
880

    
881
  switch ($default_theme) {
882
    case 'garland_cichorieae':
883
      $settings_for_theme = $cichorieae_default;
884
      break;
885
    case 'cyprus':
886
      // cyprus: no longer used in production,
887
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
888
      $settings_for_theme = $cyprus_default;
889
      break;
890
    case 'flore_afrique_centrale':
891
    case 'flora_malesiana':
892
    case 'flore_gabon':
893
      $settings_for_theme = $cichorieae_default;
894
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
895
      break;
896
    case 'palmweb_2':
897
      $settings_for_theme = $palmweb_default;
898
      break;
899
    default:
900
      $settings_for_theme = $other_themes_default;
901
  }
902
  // add pseudo feature settings
903
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
904

    
905
  // ---- END of DEFAULTS
906

    
907
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
908

    
909
  $feature_block_setting = null;
910

    
911
  if (isset($saved_settings[$feature_uuid])) {
912
    $feature_block_setting = $saved_settings[$feature_uuid];
913
  }
914
  else if (isset($settings_for_theme[$feature_uuid])) {
915
    $feature_block_setting = $settings_for_theme[$feature_uuid];
916
  }
917
  else if (isset($settings_for_theme['DEFAULT'])) {
918
    $feature_block_setting = $settings_for_theme['DEFAULT'];
919
  }
920

    
921
  // now merge the default and specific settings
922
  $settings_to_merge = array($default['DEFAULT']);
923
  if(is_array($saved_settings)){
924
    $settings_to_merge[] = $saved_settings['DEFAULT'];
925
  }
926
  if(isset($feature_block_setting)){
927
    $settings_to_merge[] = $feature_block_setting;
928
  }
929
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
930

    
931
  return $feature_block_setting;
932
}
933

    
934
/**
935
 * returns the current setting for the original source bibliography
936
 *
937
 * Caches internally
938
 *
939
 * @return array
940
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
941
 *   - 'enabled': 1|0
942
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
943
 */
944
function get_bibliography_settings($clear_cache = false){
945
  static $bibliography_settings = null;
946
  if(!$bibliography_settings || $clear_cache){
947
    $bibliography_settings = get_array_variable_merged(
948
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
949
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
950
    );
951
  }
952
  return $bibliography_settings;
953
}
954

    
955
/**
956
 * @todo Please document this function.
957
 * @see http://drupal.org/node/1354
958
 */
959
function cdm_dataportal_menu_admin(&$items) {
960
  // Display section on admin/config page.
961
  $items['admin/config/cdm_dataportal'] = array(
962
    'title' => 'CDM Dataportal',
963
    'description' => 'Settings for the CDM DataPortal.',
964
    'position' => 'right',
965
    'weight' => 10,
966
    'page callback' => 'system_admin_menu_block_page',
967
    'access arguments' => array('administer cdm_dataportal'),
968
    'file' => 'system.admin.inc',
969
    'file path' => drupal_get_path('module', 'system'),
970
  );
971
  $items['admin/config/cdm_dataportal/settings'] = array(
972
    'title' => 'Settings',
973
    'description' => 'Settings for the CDM DataPortal.',
974
    'weight' => 0,
975
    'page callback' => 'drupal_get_form',
976
    'page arguments' => array('cdm_settings_general'),
977
    'access arguments' => array('administer cdm_dataportal'),
978
    'type' => MENU_NORMAL_ITEM,
979
  );
980
  $items['admin/config/cdm_dataportal/settings/general'] = array(
981
    'title' => 'General',
982
    'description' => 'General',
983
    'weight' => 0,
984
    'page callback' => 'drupal_get_form',
985
    'page arguments' => array('cdm_settings_general'),
986
    'access arguments' => array('administer cdm_dataportal'),
987
    'type' => MENU_DEFAULT_LOCAL_TASK,
988
  );
989

    
990
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
991
    'title' => 'Cache',
992
    'description' => 'Cache',
993
    'access arguments' => array('administer cdm_dataportal'),
994
    'page callback' => 'drupal_get_form',
995
    'page arguments' => array('cdm_settings_cache'),
996
    'weight' => 10,
997
    'type' => MENU_LOCAL_TASK,
998
  );
999

    
1000
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1001
    'title' => 'Geo & Map',
1002
    'description' => 'Geo & Map',
1003
    'access arguments' => array('administer cdm_dataportal'),
1004
    'page callback' => 'drupal_get_form',
1005
    'page arguments' => array('cdm_settings_geo'),
1006
    'weight' => 1,
1007
    'type' => MENU_LOCAL_TASK,
1008
  );
1009

    
1010
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1011
    'title' => 'Layout',
1012
    'description' => 'Configure and adjust the layout of your DataPortal ',
1013
    'access arguments' => array('administer cdm_dataportal'),
1014
    'page callback' => 'drupal_get_form',
1015
    'page arguments' => array('cdm_settings_layout'),
1016
    'weight' => 2,
1017
    'type' => MENU_LOCAL_TASK,
1018
  );
1019

    
1020
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1021
    'title' => 'Taxon',
1022
    'description' => 'Configure and adjust the layout of your DataPortal ',
1023
    'access arguments' => array('administer cdm_dataportal'),
1024
    'page callback' => 'drupal_get_form',
1025
    'page arguments' => array('cdm_settings_layout_taxon'),
1026
    'weight' => 1,
1027
    'type' => MENU_LOCAL_TASK,
1028
  );
1029
  /*
1030
  $items[] = array(
1031
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1032
  'title' => t('Synonymy'),
1033
  'description' => t('Configure and adjust the layout of your DataPortal '),
1034
  'access' => user_access('administer cdm_dataportal'),
1035
  'callback' => 'drupal_get_form',
1036
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1037
  'weight' => 1,
1038
  'type' => MENU_LOCAL_TASK,
1039
  );
1040

    
1041
  $items[] = array(
1042
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1043
  'title' => t('Specimens'),
1044
  'description' => t('Configure and adjust the layout of your DataPortal '),
1045
  'access' => user_access('administer cdm_dataportal'),
1046
  'callback' => 'drupal_get_form',
1047
  'callback arguments' => array('cdm_settings_layout_specimens'),
1048
  'weight' => 1,
1049
  'type' => MENU_LOCAL_TASK,
1050
  );
1051
  */
1052
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1053
    'title' => 'Search',
1054
    'description' => 'Configure and adjust the layout of your DataPortal ',
1055
    'access arguments' => array('administer cdm_dataportal'),
1056
    'page callback' => 'drupal_get_form',
1057
    'page arguments' => array('cdm_settings_layout_search'),
1058
    'weight' => 2,
1059
    'type' => MENU_LOCAL_TASK,
1060
  );
1061

    
1062
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1063
    'title' => 'Media',
1064
    'description' => 'Configure and adjust the layout of your DataPortal ',
1065
    'access arguments' => array('administer cdm_dataportal'),
1066
    'page callback' => 'drupal_get_form',
1067
    'page arguments' => array('cdm_settings_layout_media'),
1068
    'weight' => 3,
1069
    'type' => MENU_LOCAL_TASK,
1070
  );
1071

    
1072
}
1073

    
1074
/**
1075
 * @todo document this function.
1076
 */
1077
function cdm_help_general_cache() {
1078
  $form = array();
1079
  $form['cache_help'] = array(
1080
    '#type' => 'fieldset',
1081
    '#title' => t('Help'),
1082
    '#collapsible' => TRUE,
1083
    '#collapsed' => TRUE,
1084
  );
1085
  $form['cache_help']['test'] = array('#value' => t('probando'));
1086
  return drupal_render($form);
1087
  $res = array();
1088
  $res['default'] = drupal_render($help);
1089
  return $res;
1090
}
1091

    
1092
/**
1093
 * Configures the settings form for the CDM-API module.
1094
 *
1095
 * @return array
1096
 *   Drupal settings form.
1097
 */
1098
function cdm_settings_general() {
1099

    
1100
  $form['cdm_webservice'] = array(
1101
    '#type' => 'fieldset',
1102
    '#title' => t('CDM Server'),
1103
    '#collapsible' => FALSE,
1104
    '#collapsed' => FALSE,
1105
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1106
        CDM data base to the web via RESTful web services and thus is the source of the data
1107
        to be displayed by a CDM DataPotal.'),
1108
  );
1109

    
1110
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1111
    '#type' => 'textfield',
1112
    '#title' => t('CDM web service URL') . ':',
1113
    '#description' => t('This is the URL to the CDM-Server exposing your data
1114
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1115
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1116
  );
1117

    
1118
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1119
    '#type' => 'markup',
1120
    '#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')
1121
      . ' visible only for administrators',
1122
  );
1123

    
1124
  $form['cdm_webservice']['freetext_index'] = array(
1125
    '#type' => 'fieldset',
1126
    '#title' => t('Freetext index'),
1127
    '#collapsible' => FALSE,
1128
    '#collapsed' => FALSE,
1129
  );
1130

    
1131
  // Check the cdmserver port number and display a waring if it is not port 80
1132
  preg_match("#http[s]?://[0-9\p{L}\.]*:([0-9]*)/.*#u", variable_get('cdm_webservice_url', ''), $portNumberMatch, PREG_OFFSET_CAPTURE);
1133
  if (isset($portNumberMatch[1]) && $portNumberMatch[1] != '80') {
1134
    $form['cdm_webservice']['freetext_index']['message'] = array(
1135
      '#markup' => "<div class=\"description\">"
1136
      . t("The CDM web service URL contains a portnumber other than standart HTTP port 80: '!port'
1137
           Due to this the reindex and purge fuctions may not be working if there is a firewall in between you and the CDM Server.
1138
           You may want to contact the maintainer of the according CDM Server in order to solve this problem.",
1139
          array('!port' => $portNumberMatch[1][0])
1140
        )
1141
      . "</div>",
1142
    );
1143
  };
1144

    
1145
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1146
  $trigger_link_options = array(
1147
    'attributes' => array(
1148
      'class' => 'index-trigger'
1149
    ),
1150
  );
1151
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1152
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1153
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1154
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1155
      ))
1156
    . '<div id="index-progress"></div></div>',
1157
  );
1158

    
1159
  $form['cdm_webservice']['freetext_index']['cdm_login'] = array(
1160
    // this must not be stored, it is only used by the _add_js_cdm_ws_progressbar
1161
    '#type' => 'textfield',
1162
    '#title' => t('Login'),
1163
    '#description' => t('Your cdm user credentials in the following form: <code>user:password</code>')
1164
  );
1165
  drupal_add_js('
1166
        jQuery(document).ready(function() {
1167
             jQuery("#edit-cdm-login").change(function (e) {
1168
                var login = jQuery(e.target).val();
1169
                jQuery("#edit-freetext-index .index-trigger").each(function(index){
1170
                   var url = jQuery(this).attr("href");
1171
                   url = url.replace(/:\/\/[^@]+@|:\/\//, "://" + login + "@");
1172
                   jQuery(this).attr("href", url);
1173
                });
1174
            });
1175
        });
1176
      ',
1177
    array(
1178
      'type' => 'inline',
1179
      'scope' => 'footer'
1180
    )
1181
  );
1182
  _add_js_cdm_ws_progressbar(".index-trigger", "#index-progress");
1183

    
1184
  $form['cdm_webservice']['proxy'] = array(
1185
    '#type' => 'fieldset',
1186
    '#title' => t('Proxy'),
1187
    '#collapsible' => TRUE,
1188
    '#collapsed' => TRUE,
1189
  );
1190

    
1191
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1192
    '#type' => 'textfield',
1193
    '#title' => t('Proxy URL') . ':',
1194
    '#description' => t('If this proxy url is set the cdm api tries
1195
    to connect the web service over the given proxy server.
1196
    Otherwise proxy usage is deactivated.'),
1197
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1198
  );
1199

    
1200
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1201
    '#type' => 'textfield',
1202
    '#title' => t('Proxy port') . ':',
1203
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1204
  );
1205

    
1206
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1207
    '#type' => 'textfield',
1208
    '#title' => t('Login') . ':',
1209
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1210
  );
1211

    
1212
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1213
    '#type' => 'textfield',
1214
    '#title' => t('Password') . ':',
1215
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1216
  );
1217

    
1218
  // TODO: settings are still incomplete, compare with
1219
  // trunk/dataportal/inc/config_default.php.inc.
1220
  $form['taxon_tree'] = array(
1221
    '#type' => 'fieldset',
1222
    '#title' => t('Taxon Tree'),
1223
    '#collapsible' => FALSE,
1224
    '#collapsed' => TRUE,
1225
    '#description' => t('<p>When you explore your collection, you can navigate
1226
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1227
      able to navigate through your collection the
1228
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1229
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1230
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1231
      </a></p>'),
1232
  );
1233

    
1234
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1235
    '#type' => 'select',
1236
    '#title' => t('Default classification') . ':',
1237
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1238
    '#options' => cdm_get_taxontrees_as_options(),
1239
    '#description' => t('The default taxa classification to be used in the whole portal. 
1240
      This affects most obviously the classification browser and the search in case is is restricted 
1241
      to a specific classification. See also <i>Included Classifications</i> below.'),
1242
  );
1243

    
1244
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1245
    '#type' => 'select',
1246
    '#title' => t('Rank of highest displayed taxon') . ':',
1247
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1248
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1249
    '#options' => cdm_rankVocabulary_as_option(),
1250
    '#description' => t('This is the rank of the highest displayed taxon in the
1251
      <em>taxon tree</em>. You can select here which rank should be at the top
1252
      level of the tree structure.'),
1253
  );
1254

    
1255
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1256
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1257
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1258
      '#type' => 'checkboxes',
1259
      '#title' => t('Included Classifications') . ':',
1260
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1261
      '#options' => cdm_get_taxontrees_as_options(),
1262
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1263
  );
1264

    
1265
  $form['distribution'] = array(
1266
      '#type' => 'fieldset',
1267
      '#title' => t('Distributions'),
1268
      '#collapsible' => FALSE,
1269
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1270
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1271
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1272
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1273
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1274
          '<p>
1275
          </p>',
1276
  );
1277

    
1278
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1279
      '#type' => 'fieldset',
1280
      '#title' => 'Distribution filter',
1281
      '#collapsible' => FALSE,
1282
      '#collapsed' => FALSE,
1283
      '#tree' => TRUE,
1284
      '#description' => 'The Distribution filter offers the following options
1285
      <ul>
1286
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1287
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1288
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1289
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1290
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1291
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1292
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1293
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1294
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1295
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1296
      </ul>'
1297
  );
1298

    
1299
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1300
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1301
      '#type' => 'checkboxes',
1302
      '#title' => 'Filter rules',
1303
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1304
      '#options' => array(
1305
          'statusOrderPreference' => 'Status order preference rule',
1306
          'subAreaPreference' => 'Sub area preference rule'
1307
      ),
1308
  );
1309

    
1310
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1311
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1312
      '#type' => 'checkboxes',
1313
      '#title' => 'Hide marked area filter',
1314
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1315
      '#options' => $marker_type_options,
1316
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1317
  );
1318

    
1319
  $form['aggregation'] = array(
1320
      '#type' => 'fieldset',
1321
      '#title' => t('Aggregation of data'),
1322
      '#collapsible' => FALSE,
1323
      '#description' => 'This section covers the different aspects of aggregating information.
1324
          <p>
1325
          </p>',
1326
  );
1327

    
1328
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1329
      '#type' => 'checkboxes',
1330
      '#title' => 'Taxon media filter',
1331
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1332
      '#options' => array(
1333
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1334
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1335
          'includeOccurrences' => 'Media related to specimens and occurrences',
1336
      ),
1337
      '#description' => 'This filter configures which images should be taken into account.',
1338
  );
1339

    
1340
  $form['aggregation']['notice'] = array(
1341
      '#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
1342
          want to make use of the caching capabilities of the dataportal.',
1343
  );
1344

    
1345
  $form['aggregation']['media_aggregation'] = array(
1346
      '#type' => 'fieldset',
1347
      '#title' => t('Media aggregation'),
1348
      '#collapsible' => FALSE,
1349
      '#collapsed' => TRUE,
1350
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1351

    
1352
  );
1353
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1354
      '#type' => 'select',
1355
      '#title' => t('Aggregation of taxon pictures') . ':',
1356
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1357
      '#options' => array(
1358
          0 => "Show only pictures of the current taxon",
1359
          1 => "Include pictures of taxonomic children",
1360
      ),
1361
      '#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."),
1362
  );
1363

    
1364
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1365
      '#type' => 'fieldset',
1366
      '#attributes' => array('class' => array('clearfix')),
1367
      '#title' => t('Aggregation via taxon relationsships'),
1368
      '#collapsible' => TRUE,
1369
      '#collapsed' => TRUE,
1370
      '#tree' => TRUE,
1371
      '#description' => t('Information on taxa will be aggregated along the below chosen
1372
          taxon relation ships. This will affect images and occurrences (specimens).
1373
          Taxon relation ships are directed and point form one taxon to another. The taxon
1374
          relationships to be taken into accunt can therefore configured for the direct direction
1375
          and for the inverse.'),
1376
  );
1377

    
1378
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1379
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1380

    
1381
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1382
      '#type' => 'checkboxes',
1383
      '#title' => t('Direct'),
1384
      '#options' => $taxonRelationshipTypeOptions,
1385
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1386
  );
1387
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1388
      '#type' => 'checkboxes',
1389
      '#title' => t('Invers'),
1390
      '#options' => $taxonRelationshipTypeOptions,
1391
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1392
  );
1393

    
1394
  $form['drupal_integration'] = array(
1395
    '#type' => 'fieldset',
1396
    '#attributes' => array('class'=> array('clearfix')),
1397
    '#title' => t('Drupal integration'),
1398
    '#collapsible' => FALSE,
1399
    '#collapsed' => FALSE,
1400
    '#tree' => FALSE
1401
  );
1402

    
1403
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1404
    '#type' => 'checkbox',
1405
    '#title' => 'Create drupal nodes',
1406
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1407
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1408
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1409
    cdm pages it is required that drupal nodes are created and stored in the database.'
1410
  );
1411

    
1412

    
1413

    
1414
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1415
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1416
    <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>',
1417
  );
1418
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1419
    '#type' => 'submit',
1420
    '#value' => t('Drop all cdm nodes'),
1421
    '#submit' => array('drop_all_cdm_nodes_submit')
1422
  );
1423

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

    
1428
    // ----------------------
1429
  $form['cdm_js_devel_mode'] = array(
1430
      '#type' => 'checkbox',
1431
      '#title' => 'Java-script developer mode',
1432
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1433
      '#description' => 'In production envirionments the java script libraries
1434
      the cdm_dataportal is making use of are compressed and optimized. This
1435
      is good for performance but a caveat if you need to debug java-script. When the
1436
      java-script developer mode is enabled the uncompressed and commented developer
1437
      versions of java-script libraries will be used where possible.
1438
      <br/><strong>Do not use this option in production!</strong>'
1439
  );
1440
  // ----------------------
1441
  $form['cdm_debug_mode'] = array(
1442
      '#type' => 'checkbox',
1443
      '#title' => 'CDM page debug mode',
1444
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1445
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1446
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1447
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1448
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1449
      The log is written by the drupal devel module function <code>dd()</code>.
1450
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1451
  );
1452

    
1453
  // Comment @WA: D7 form api does not support reset buttons,
1454
  // so to mimic the D5 reset button we add one like this.
1455
  $form['actions']['reset'] = array(
1456
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1457
    '#weight' => 1000,
1458
  );
1459

    
1460
  $form['#submit'][] = 'cdm_settings_general_submit';
1461

    
1462
  return system_settings_form($form);
1463
}
1464

    
1465
/**
1466
 * Submit callback; drops all cdm nodes.
1467
 *
1468
 * @ingroup forms
1469
 */
1470
function drop_all_cdm_nodes_submit($form, &$form_state) {
1471
  cdm_delete_all_cdm_nodes();
1472
  drupal_set_message(t('All cdm nodes dropped.'));
1473
}
1474

    
1475

    
1476
/**
1477
 * LAYOUT settings
1478
 * @return
1479
 *   todo
1480
 */
1481
function cdm_settings_layout() {
1482

    
1483
  $form = array();
1484

    
1485
  $form['about'] = array(
1486
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1487
      layout. If you want to configure the specific sites layout visit the
1488
      respective configuration site for taxon, search or media.') . '</p>',
1489
  );
1490

    
1491
  // ---- footnotes --- //
1492
  $form['footnotes'] = array(
1493
    '#type' => 'fieldset',
1494
    '#title' => t('Footnotes'),
1495
    '#collapsible' => FALSE,
1496
    '#collapsed' => FALSE,
1497
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1498
      media or distribution areas may have annotations or footnotes. When the
1499
      footnotes are enabled they will be visible (if they exist).'),
1500
  );
1501

    
1502
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1503
    '#type' => 'checkbox',
1504
    '#title' => t('Do not show footnotes'),
1505
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1506
    '#description' => t('Check this if you do not want to show any footnotes'),
1507
  );
1508

    
1509
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1510
    '#type' => 'checkbox',
1511
    '#title' => t('Do not show annotation footnotes'),
1512
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1513
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1514
  );
1515

    
1516
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1517
  // Additional option for the NULL case.
1518
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1519
  $form['footnotes']['annotations_types_as_footnotes'] = array(
1520
    '#type' => 'checkboxes',
1521
    '#title' => t('Annotation types as footnotes'),
1522
    '#description' => t("Only annotations of the selected type will be displayed
1523
       as footnotes. You may want to turn 'technical annotations' off."),
1524
    '#options' => $annotationTypeOptions,
1525
  );
1526
  $annotationsTypesAsFootnotes = variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1527
  if (!empty($annotationsTypesAsFootnotes)) {
1528
    $form['footnotes']['annotations_types_as_footnotes']['#default_value'] = $annotationsTypesAsFootnotes;
1529
  }
1530

    
1531
  // ---- original source --- //
1532
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1533
      '#type' => 'fieldset',
1534
      '#tree' => TRUE,
1535
      '#title' => t('Source Citations'),
1536
      '#collapsible' => FALSE,
1537
      '#collapsed' => FALSE,
1538
  );
1539

    
1540
  $bibliography_settings = get_bibliography_settings(true);
1541

    
1542
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1543
      '#type' => 'checkbox',
1544
      '#title' => t('Original Source in bibliography'),
1545
      '#default_value' => $bibliography_settings['enabled'],
1546
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1547
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1548
       into the bibliography also depends on the settings in the ' .
1549
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1550
        '. For more information please refer to the description on the settings "<em>Sources as content</em>" & "<em>Sources as content to bibliography</em>" in that settings page.'),
1551
  );
1552

    
1553
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1554
    '#type' => 'select',
1555
    '#title' => t('The format of the key numerals'),
1556
    '#default_value' => $bibliography_settings['key_format'],
1557
    '#options' => array('latin' => 'Latin',
1558
      'ROMAN' => 'Roman (upper case)',
1559
      'roman' => 'Roman (lower case)',
1560
      'ALPHA'=> 'Alphabet (upper case)',
1561
      'alpha' => 'Alphabet (lower case)')
1562
  );
1563

    
1564
  // --- Advanced Search --- //
1565
  $form['asearch'] = array(
1566
      '#type' => 'fieldset',
1567
      '#title' => t('Advanced search'),
1568
      '#collapsible' => FALSE,
1569
      '#collapsed' => FALSE,
1570
  );
1571
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1572
      '#type' => 'checkbox',
1573
      '#title' => t('Show advanced search link'),
1574
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1575
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1576
  );
1577

    
1578
  // ---- Taxon Name Rendering --- //
1579
  $form['taxon_name'] = array(
1580
      '#type' => 'fieldset',
1581
      '#title' => t('Taxon name display'),
1582
      '#collapsible' => TRUE,
1583
      '#collapsed' => TRUE,
1584
      '#description' => t('The display of taxon names is configured by two parts.
1585
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1586
          The name parts are defined in the <stong>part definitions</strong>'),
1587
  );
1588

    
1589
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1590
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1591
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1592
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1593

    
1594
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1595
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1596
    $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.)';
1597
  } else if($is_custom_part_definition){
1598
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1599
  } else  {
1600
    $which_version_message = '(These are the default part definition.)';
1601
  }
1602

    
1603
  $diff_viewer_markup = '';
1604
  if($is_custom_part_definition){
1605
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1606
  }
1607

    
1608
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1609
    . $which_version_message
1610
    . '</div>'
1611
    . $diff_viewer_markup;
1612

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

    
1702
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1703
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1704
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1705
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1706
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1707

    
1708
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1709
    $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.)';
1710
  } else if($is_custom_render_template){
1711
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1712
  } else {
1713
    $which_version_message = '(These are the default render templates.)';
1714
  }
1715

    
1716
  $diff_viewer_markup = '';
1717
  if($is_custom_render_template){
1718
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1719
  }
1720

    
1721
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1722
    . $which_version_message
1723
    . '</div>'
1724
    . $diff_viewer_markup;
1725

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

    
1766
  // @WA: D7 form api does not support reset buttons,
1767
  // so to mimic the D5 reset button we add one like this.
1768
  $form['actions']['reset'] = array(
1769
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1770
    '#weight' => 1000,
1771
  );
1772

    
1773
  $form['#submit'] = array('submit_json_as_php_array');
1774
  // #json_elements especially defined for submit_json_as_php_array()
1775
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1776
  return system_settings_form($form);
1777
}
1778

    
1779

    
1780
/**
1781
 * @param $form_name
1782
 * @param $form_title
1783
 * @param $collapsed
1784
 * @param string $form_description
1785
 *   The description for the fieldset of the gallery setting.
1786
 * @return mixed
1787
 */
1788
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1789
  $form[$form_name] = array(
1790
    '#type' => 'fieldset',
1791
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1792
    '#collapsible' => TRUE,
1793
    '#collapsed' => $collapsed,
1794
    '#tree' => TRUE,
1795
    '#description' => $form_description,
1796
  );
1797

    
1798
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1799
  $gallery_settings = variable_get($form_name, $default_values);
1800
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1801
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1802
    /*
1803
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1804
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1805
    '#type' => 'textfield',
1806
    '#title' => t('Search Page Size'),
1807
    '#default_value' => $test,
1808
    '#description' => t('Number of Names to display per page in search results.')
1809
    );
1810
    */
1811
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1812
      '#type' => 'checkbox',
1813
      '#title' => t('Show media thumbnails for accepted taxa'),
1814
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1815
    );
1816

    
1817
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1818
      '#type' => 'checkbox',
1819
      '#title' => t('Show media thumbnails for synonyms'),
1820
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1821
      '#description' => '',
1822
    );
1823
  }
1824

    
1825
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1826
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1827
    '#type' => 'checkbox',
1828
    '#title' => t('Show captions under thumbnails'),
1829
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1830
    '#description' => '',
1831
  );
1832

    
1833
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1834
    '#type' => 'textfield',
1835
    '#title' => t('Thumbnail size') . ':',
1836
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1837
    '#description' => t('Select the size of each individual thumbnail.'),
1838
  );
1839

    
1840
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1841
    '#type' => 'textfield',
1842
    '#title' => t('Number of columns') . ':',
1843
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1844
    '#description' => t('Group the thumbnails in columns: select how many
1845
      columns the gallery should display.'),
1846
  );
1847

    
1848
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1849
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1850
      '#type' => 'textfield',
1851
      '#title' => t('Maximum number of rows') . ':',
1852
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1853
      '#description' => t('You can group the thumbnails in rows, select in how
1854
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1855
        If you want an unlimited number of rows please set to 0.'),
1856
    );
1857
  }
1858

    
1859
  return $form;
1860
}
1861

    
1862
/**
1863
 * @todo document this function.
1864
 */
1865
function cdm_settings_layout_taxon() {
1866
  $collapsed = FALSE;
1867
  $form = array();
1868

    
1869
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1870

    
1871
  // --------- TABBED TAXON ------- //
1872
  $form['taxon_tabs'] = array(
1873
    '#type' => 'fieldset',
1874
    '#title' => t('Taxon tabs'),
1875
    '#collapsible' => TRUE,
1876
    '#collapsed' => TRUE,
1877
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1878
  );
1879

    
1880
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1881
    '#type' => 'checkbox',
1882
    '#title' => t('Tabbed taxon page'),
1883
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1884
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1885
  );
1886

    
1887
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1888
    '#type' => 'checkbox',
1889
    '#title' => t('Synonymy as tab'),
1890
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1891
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1892
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1893
  );
1894

    
1895
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1896
    '#type' => 'checkboxes',
1897
    '#title' => t('Section/Tab visibility') . ':',
1898
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1899
    '#options' => get_taxon_options_list()
1900
  );
1901

    
1902
  // WEIGHT
1903
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1904
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1905
    '#title'  => 'Section/Tab order',
1906
    '#type' => 'fieldset',
1907
    '#collapsible' => false,
1908
    '#tree' => true,
1909
    '#description' => 'The weight value defines the order of the section/tab.'
1910
  );
1911
  // Weights range from -delta to +delta, so delta should be at least half
1912
  // of the amount of tabs present.
1913
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1914
  foreach (get_taxon_tabs_list() as $label) {
1915
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1916
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1917
        '#title' => $label,
1918
        '#type'  => 'weight',
1919
        '#default_value' => $taxon_tabs_weights[$key],
1920
        '#delta' => $tab_weight_delta
1921
    );
1922
  }
1923

    
1924
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1925
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1926
    '#title'  => 'Section/Tab label override',
1927
    '#type' => 'fieldset',
1928
    '#collapsible' => false,
1929
    '#tree' => true,
1930
    '#description' => 'Setting a label for a section/tab will override the default label. 
1931
      Please enter the label text in the default language of the portal.'
1932
  );
1933
  foreach (get_taxon_tabs_list() as $label) {
1934
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1935
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1936
      '#title' => $label,
1937
      '#type'  => 'textfield',
1938
      '#default_value' => $taxon_tabs_labels[$key]
1939
    );
1940
  }
1941

    
1942
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1943
    '#type' => 'select',
1944
    '#title' => t('Default tab to display') . ':',
1945
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
1946
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
1947
    '#description' => t('<p>Select the default tab to display when visiting a
1948
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
1949
      <strong>Note:</strong> After performing a search and clicking in any
1950
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
1951
      taxon and not the above selected tab.'),
1952
  );
1953

    
1954
  /* ======  TAXON_PROFILE ====== */
1955
  $form['taxon_profile'] = array(
1956
    '#type' => 'fieldset',
1957
    '#title' => t('Taxon profile (tab)'),
1958
    '#description' => t('<p>This section covers the settings related to the taxon
1959
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
1960
    '#collapsible' => TRUE,
1961
    '#collapsed' => TRUE,
1962
  );
1963

    
1964
  // ---- PROFILE PICTURE ----//
1965

    
1966
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
1967
    '#type' => 'fieldset',
1968
    '#tree' => TRUE,
1969
    '#title' => t('Taxon profile picture'),
1970
    '#collapsible' => TRUE,
1971
    '#collapsed' => FALSE,
1972
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
1973
  );
1974

    
1975
  //FIXME migrate variables:
1976
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
1977
  // FIXME
1978
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
1979

    
1980
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
1981

    
1982
  /*
1983
   * 'show' => 1,
1984
   * 'maxextend' => 184,
1985
   * 'media_uri_query' => ''
1986
   * 'custom_placeholder_image_on' => 1,
1987
   * 'custom_placeholder_image_fid' => ''
1988
   */
1989
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
1990
    '#type' => 'checkbox',
1991
    '#title' => t('Enable profile picture'),
1992
    '#description' => t('Show the profile picture.'),
1993
    '#default_value' => $taxon_profile_image_settings['show'],
1994
  );
1995

    
1996
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
1997
      '#type' => 'textfield',
1998
      '#tree' => TRUE,
1999
      '#title' => t('Profile picture maximum extend'),
2000
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2001
      '#field_suffix' => 'px',
2002
      '#maxlength' => 4,
2003
      '#size' => 4,
2004
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2005
  );
2006

    
2007
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2008
      '#type' => 'textfield',
2009
      '#tree' => TRUE,
2010
      '#title' => t('Additional URI query parameter'),
2011
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2012
      '#maxlength' => 1024,
2013
      '#size' => 60,
2014
      '#description' => t('Additional query parameters to be used when requesting for the  
2015
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2016
            The query parameters will be appended to the uri of the media representation part
2017
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2018
  );
2019

    
2020
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2021
    '#type' => 'checkbox',
2022
    '#title' => t('Show the placeholder image'),
2023
    '#description' => t("If not taxon profile picture is available a placeholder image is shown instead."),
2024
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2025
  );
2026

    
2027
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2028
      '#type' => 'checkbox',
2029
      '#title' => t('Use a custom placeholder image'),
2030
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2031
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2032
  );
2033

    
2034
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2035
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2036
        '#type' => 'managed_file',
2037
        '#title' => t('Custom placeholder image file'),
2038
        '#progress_indicator' => 'bar',
2039
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2040
    //       '#name' => 'custom_placeholder_image',
2041
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2042
    );
2043

    
2044
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2045
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2046
      $url = file_create_url($profile_image_file->uri);
2047
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2048
                '#type' => 'item',
2049
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2050
      );
2051
    }
2052
  } else {
2053
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2054
      '#type' => 'hidden',
2055
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2056
    );
2057
  }
2058

    
2059
  $options = cdm_rankVocabulary_as_option();
2060
  array_unshift($options, '-- DISABLED --');
2061
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2062
    '#type' => 'select',
2063
    '#title' => t('Hide profile picture for higher ranks') . ':',
2064
    '#default_value' => variable_get('image_hide_rank', '0'),
2065
    '#options' => $options,
2066
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2067
  );
2068

    
2069
  // -- MEDIA THUMBNAILS -- //
2070
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2071
  $form_title = 'Taxon Profile Images';
2072
  $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>';
2073
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2074

    
2075
  // ---- FEATURE TREE BLOCKS ---- //
2076
  $form['taxon_profile']['feature_blocks'] = array(
2077
    '#type' => 'fieldset',
2078
    '#title' => t('Feature Blocks'),
2079
    '#collapsible' => TRUE,
2080
    '#collapsed' => FALSE,
2081
    '#description' => t("This section covers settings related to the taxon's
2082
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2083
      features such as description, distribution, common names"),
2084
  );
2085
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2086
  $profile_feature_tree = get_profile_feature_tree();
2087
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2088
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2089
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2090
  }
2091
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2092
    '#type' => 'radios',
2093
    '#title' => t('Taxon profile feature tree') . ':',
2094
    '#default_value' => $profile_feature_tree_uuid,
2095
    '#options' =>  $featureTrees['options'],
2096
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2097
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2098
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2099
      profile page.'
2100
    ),
2101
  );
2102

    
2103
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2104
  $profile_feature_tree = get_profile_feature_tree();
2105

    
2106
  if (isset($profile_feature_tree->root->childNodes)) {
2107

    
2108
    $form_feature_block_layout = array(
2109
      '#type' => 'fieldset',
2110
      '#tree' => true,
2111
      '#title' => t('Taxon profile feature block settings'),
2112
      '#collapsible' => TRUE,
2113
      '#collapsed' => FALSE,
2114
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2115
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2116
      The subforms have the following settings in common:<br />
2117
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2118
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2119
      <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>
2120
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2121
            <ol>
2122
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2123
                appended in brackets like "text (source references)". If the original source has name in source
2124
                information it will be appended to the citation string,
2125
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2126
             <li>if the text of the TextData is empty, the original source citations are the only content
2127
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2128
                prepended to the citation string like: "name in source: citation"</li>
2129
            </ol>
2130
            <strong>If disabled:</strong><br />
2131
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2132
             citations are the only content, the resulting feature block content would only consist of footnotes.
2133
             In this case the display of the respective feature block is suppressed.</div>
2134
      </dl>
2135
      <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
2136
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2137
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2138
        . '</em></div>
2139
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2140
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2141
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2142
      <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>
2143
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2144
           cdm_feature_block_element_tag_name()</div>
2145
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2146
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2147
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2148
    );
2149

    
2150

    
2151
    $feature_list_layout_settings_disabled = FALSE;
2152

    
2153
    // creating helper object to retrieve the default settings
2154
    $featureNode = new stdClass();
2155
    $featureNode->feature = new stdClass();
2156
    $featureNode->feature->uuid="DEFAULT";
2157
    $featureNode->feature->representation_L10n = "Default";
2158
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2159

    
2160
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2161

    
2162
      if (!$feature_list_layout_settings_disabled && isset($featureNode->feature)) {
2163

    
2164
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2165
        $subform_id = $featureNode->feature->uuid;
2166
        $feature_block_setting = get_feature_block_settings($featureNode->feature->uuid);
2167

    
2168
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2169

    
2170
        $form_feature_block_layout[$subform_id] = array(
2171
          '#type' => 'fieldset',
2172
          '#tree' => TRUE,
2173
          '#title' => $featureNode->feature->representation_L10n,
2174
          '#collapsible' => FALSE,
2175
          '#collapsed' => FALSE,
2176
        );
2177
        if($featureNode->feature->uuid == "DEFAULT"){
2178
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2179
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2180
          references</em> and <em>names in source</em> is only possible in the defaults';
2181
        }
2182

    
2183
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2184
          '#type' => 'select',
2185
          '#title' => 'List type',
2186
          '#default_value' => $feature_block_setting['as_list'],
2187
          '#options' => array(
2188
            'div' => 'not as list',
2189
            'ul' => 'bullet list',
2190
            'ol' => 'numbered list',
2191
            'dl' => 'definition list'
2192
          ),
2193
        );
2194

    
2195
        if($featureNode->feature->uuid == "DEFAULT"){
2196
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2197
            '#type' => 'checkbox',
2198
            '#title' => t('Link to reference'),
2199
            '#default_value' => $feature_block_setting['link_to_reference'],
2200
          );
2201

    
2202
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2203
            '#type' => 'checkbox',
2204
            '#title' => 'Link to name used in source',
2205
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2206
          );
2207
        }
2208

    
2209
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2210
          '#type' => 'checkbox',
2211
          '#title' => 'Sources as content',
2212
          '#default_value' => $feature_block_setting['sources_as_content'],
2213
        );
2214

    
2215
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2216
          '#type' => 'checkbox',
2217
          '#title' => 'Put sources also as content to bibliography',
2218
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2219
        );
2220

    
2221
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2222
          '#type' => 'select',
2223
          '#title' => t('Sort elements'),
2224
          '#default_value' => $feature_block_setting['sort_elements'],
2225
          '#options' => array(
2226
            NO_SORT => 'No sorting',
2227
            SORT_ASC => 'Ascending',
2228
            SORT_DESC => 'Descending',
2229
            SORT_HIERARCHICAL => 'Hierarchical'
2230
          ),
2231
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2232
          <dl>
2233
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2234
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2235
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2236
          <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>
2237
          </dl>',
2238
        );
2239

    
2240
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2241
          '#type' => 'select',
2242
          '#title' => t('Element tag'),
2243
          '#options' => array(
2244
            'span' => 'span',
2245
            'div' => 'div',
2246
            'p' => 'p'
2247
          ),
2248
          '#default_value' => $feature_block_setting['element_tag'],
2249
        );
2250
        $form_feature_block_layout[$subform_id]['glue'] = array(
2251
          '#type' => 'textfield',
2252
          '#title' => t('Element glue'),
2253
          '#default_value' => $feature_block_setting['glue'],
2254
          '#size' => 10
2255
      );
2256

    
2257
      }
2258
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2259
    }
2260
  }
2261

    
2262
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2263
  $form['taxon_profile']['structured_description_featuretree'] = array(
2264
    '#type' => 'fieldset',
2265
    '#title' => t('Structured Description Feature Tree'),
2266
    '#collapsible' => TRUE,
2267
    '#collapsed' => FALSE,
2268
  );
2269
  $featureTrees = cdm_get_featureTrees_as_options();
2270
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2271
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2272
    $profile_feature_tree_uuid = NULL;
2273
  }
2274
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2275
    '#type' => 'radios',
2276
    '#title' => t('Natural language representation of structured descriptions') . ':',
2277
    '#default_value' => $profile_feature_tree_uuid,
2278
    '#options' => $featureTrees['options'],
2279
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2280
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2281
    '#description' => t('Taxon descriptions can be stored in a highly structured
2282
      form. The feature tree selected here will be used to generate textual
2283
      representation in natural language.'
2284
    ),
2285
  );
2286

    
2287

    
2288

    
2289
  // ---- DISTRIBUTION LAYOUT ---- //
2290
  $form['taxon_profile']['distribution_layout'] = array(
2291
    '#title' => t('Distribution'),
2292
    '#collapsible' => TRUE,
2293
    '#collapsed' => FALSE,
2294
    '#type' => 'fieldset',
2295
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2296
        Map settings regarding the geometry, layers, etc are found in the '
2297
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2298
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2299
      . l(
2300
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2301
        array('fragment' => 'edit-feature-block-settings')
2302
      )
2303
      . ' More general settings regrading the filtering of Distributions are found at '
2304
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2305
      . '. (These settings here will be merged in future releases into the feature block settings)',
2306

    
2307
  );
2308

    
2309
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2310

    
2311
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2312
    '#type' => 'checkbox',
2313
    '#title' => t('Condensed distribution'),
2314
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2315
    '#description' => 'This option enables the display of a very compact representation
2316
    of the distribution which includes also information on the status.',
2317
  );
2318

    
2319
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2320
    '#type' => 'select',
2321
    '#title' => t('Condensed distribution recipe'),
2322
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2323
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2324
    '#description' => 'Recipe for creating the condensed distribution.',
2325
  );
2326

    
2327
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2328
    '#type' => 'textfield',
2329
    '#title' => t('Condensed distribution info path'),
2330
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2331
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2332
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2333
  );
2334

    
2335

    
2336
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2337
    '#type' => 'radios',
2338
    '#title' => t('Display mode') . ':',
2339
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2340
    '#options' => array(
2341
      'FLAT_ALPHA' => t('Flat list'),
2342
      'TREE' => t('Hierarchically ordered'),
2343
    ),
2344
    '#description' => 'Taxon distribution information is displayed with
2345
    focus on the area of the distribution. The list of areas can either be shown
2346
    as flat list ordered alphabetically or in the hierarchical of the parent
2347
    area and subarea relationship. Fall back areas areas with no Distribution data
2348
    are hidden from the area hierarchy so that their sub areas will move one level up.
2349
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2350
    ' for details on the <em>Marked area filter</em>.',
2351
  );
2352

    
2353
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2354
    '#type' => 'fieldset',
2355
    '#tree' => true,
2356
    '#title' => t('Distribution hierarchy style')
2357
  );
2358

    
2359
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2360
  foreach(array_keys($hierarchy_styles) as $level) {
2361
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2362
      '#type' => 'fieldset',
2363
      '#tree' => true,
2364
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2365
      '#attributes' => array('class' => array('fieldset-float'))
2366
    );
2367
    foreach ($hierarchy_styles[$level] as $key => $value) {
2368
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2369
        '#type' => 'textfield',
2370
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2371
        '#default_value' => $hierarchy_styles[$level][$key],
2372
        '#maxlength' => 4,
2373
        '#size' => 4
2374
      );
2375
    }
2376
  }
2377

    
2378
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2379
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2380
    '#type' => 'checkboxes',
2381
    '#title' => 'Omit area levels',
2382
    '#options' => $level_options,
2383
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2384
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2385
    Areas which belong to the selected area levels will be hidden in the portal.',
2386
  );
2387

    
2388
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2389
    '#type' => 'checkbox',
2390
    '#title' => t('Show TextData elements on top of the map'),
2391
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2392
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2393
      elements on top of the map. Otherwise all <code>TextData</code>
2394
      distribution elements will be listed below the other area elements.
2395
      This option is useful if you need to have descriptive texts for each
2396
      distribution map.'),
2397
  );
2398

    
2399
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2400
      '#type' => 'textarea',
2401
      '#title' => t('Custom status colors'),
2402
      '#element_validate' => array('form_element_validate_json'),
2403
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2404
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2405
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2406
          reference list of the idInVocabulary values of absence and presence terms:
2407
<pre>
2408
Presence Term
2409
p	present
2410
pd	present: doubtfully present
2411
n	native
2412
nq	native: presence questionable
2413
nd	native: doubtfully native
2414
c	cultivated
2415
i	introduced
2416
iq	introduced: presence questionable
2417
id	introduced: doubtfully introduced (perhaps cultivated only)
2418
ip	introduced: uncertain degree of naturalisation
2419
ia	introduced: adventitious (casual)
2420
in	introduced: naturalized
2421
ic	introduced: cultivated
2422
e	endemic for the relevant area
2423
na	naturalised
2424
iv	invasive
2425

    
2426
AbsenceTerm
2427
a	absent
2428
f	reported in error
2429
nf	native: reported in error
2430
if	introduced: reported in error
2431
cf	cultivated: reported in error
2432
ne	native: formerly native
2433
ie	introduced: formerly introduced
2434

    
2435
</pre>'),
2436
  );
2437

    
2438

    
2439
  /* ====== SYNONYMY ====== */
2440
  $form['taxon_synonymy'] = array(
2441
    '#type' => 'fieldset',
2442
    '#title' => t('Taxon synonymy (tab)'),
2443
    '#collapsible' => TRUE,
2444
    '#collapsed' => TRUE,
2445
    '#description' => t('This section covers the settings related to the taxon
2446
      <strong>synonymy</strong> tab.'),
2447
  );
2448

    
2449
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2450
    '#type' => 'checkbox',
2451
    '#title' => t('Show accepted taxon on top of the synonymy'),
2452
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2453
    '#description' => t('If checked, the first homotypic taxon is a repetition
2454
      of the accepted taxon most likely with the full nomenclatural reference
2455
      (depending on the currently chosen theme).'),
2456
  );
2457

    
2458
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2459
    '#type' => 'checkbox',
2460
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2461
      coming from a synonym link.'),
2462
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2463
    '#description' => t('Check this if after doing a search and clicking on a
2464
      synonym you want to see the "accept of" text for the accepted synonym.'),
2465
  );
2466

    
2467
  /* === currently unused ===
2468
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2469
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2470
    '#type' => 'checkboxes',
2471
    '#title' => t('Display name relationships') . ':',
2472
    '#default_value' => variable_get('name_relationships_to_show', 0),
2473
    '#options' => $nameRelationshipTypeOptions,
2474
    '#description' => t('Select the name relationships you want to show for the
2475
      accepted taxa.'),
2476
  );
2477
 */
2478

    
2479
  $form['taxon_synonymy']['taxon_relations'] = array(
2480
    '#type' => 'fieldset',
2481
    '#title' => t('Taxon relationships'),
2482
    '#collapsible' => FALSE,
2483
    '#collapsed' => FALSE
2484
  );
2485

    
2486
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2487
    '#type' => 'checkbox',
2488
    '#title' => t('Show taxon relations ships of accepted taxon'),
2489
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2490
    '#description' => t('If this option is enabled the synonymy will show the
2491
      below selected taxon relationships of accepted taxa.'),
2492
  );
2493

    
2494
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2495
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2496
    '#type' => 'checkboxes',
2497
    '#title' => t('Taxon relationship types') . ':',
2498
    '#description' => t('Only taxon relationships of the selected type will be
2499
      displayed'),
2500
    '#options' => $taxonRelationshipTypeOptions,
2501
    '#default_value' => variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT)),
2502
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2503
  );
2504

    
2505
  $form['taxon_synonymy']['name_relations'] = array(
2506
    '#type' => 'fieldset',
2507
    '#title' => t('Name relationships'),
2508
    '#collapsible' => FALSE,
2509
    '#collapsed' => FALSE
2510
  );
2511

    
2512
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2513
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2514
    '#type' => 'checkboxes',
2515
    '#title' => t('Name relationship types') . ':',
2516
    '#description' => t('Only name relationships of the selected type will be
2517
      displayed'),
2518
    '#options' => $taxonRelationshipTypeOptions,
2519
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2520
  );
2521

    
2522
  // ====== SPECIMENS ====== //
2523
  $form['taxon_specimens'] = array(
2524
    '#type' => 'fieldset',
2525
    '#title' => t('Taxon specimens (tab)'),
2526
    '#collapsible' => TRUE,
2527
    '#collapsed' => TRUE,
2528
    '#description' => t('This section covers the settings related to the taxon
2529
      <strong>specimens</strong> tab.'),
2530
  );
2531

    
2532
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2533

    
2534
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2535
    '#type' => 'checkbox',
2536
    '#title' => t('Show specimen derivatives in a compressed table'),
2537
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2538
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2539
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2540
  );
2541

    
2542
    $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2543
        '#type' => 'textfield',
2544
        '#title' => t('Number of records per page') . ':',
2545
        '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2546
    );
2547

    
2548
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_show_determined_as'] = array(
2549
    '#type' => 'checkbox',
2550
    '#title' => t('Show "Associated with" in specimen table.'),
2551
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS)
2552
  );
2553

    
2554
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2555
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2556
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2557
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2558
  }
2559
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2560
    '#type' => 'radios',
2561
    '#title' => t('Specimen description feature tree') . ':',
2562
    '#default_value' => $profile_feature_tree_uuid,
2563
    '#options' =>  $featureTrees['options'],
2564
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2565
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2566
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2567
    ),
2568
  );
2569

    
2570
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2571
  $form_title = t('Specimen media');
2572
  $form_description = t('Specimens may have media which is displayed at the
2573
     Specimen tab/section as a gallery. It is possible to configure the
2574
     thumbnails gallery here, however for configuring how a single media should
2575
     be displayed please go to !url.</p>',
2576
     array(
2577
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2578
     ));
2579
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2580

    
2581
  // --- MEDIA GALLERY ---- //
2582
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2583
  $form_title = 'Media gallery (tab)';
2584
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2585
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2586
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2587
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2588
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2589
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2590
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2591

    
2592
  // Comment @WA: D7 form api does not support reset buttons,
2593
  // so to mimic the D5 reset button we add one like this.
2594
  $form['actions']['reset'] = array(
2595
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2596
    '#weight' => 1000,
2597
  );
2598
  return system_settings_form($form);
2599
}
2600

    
2601
/**
2602
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2603
 *
2604
 * @param $map_id
2605
 * @param $form
2606
 * @return mixed
2607
 */
2608
function _cdm_map_visibility_setting($map_id)
2609
{
2610
  return array(
2611
    '#type' => 'select',
2612
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2613
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2614
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2615
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2616
        The map also can forced to show up <b>always</b> or <b>never</b>."
2617
  );
2618
}
2619

    
2620
/**
2621
 * @todo document this function.
2622
 */
2623
function cdm_settings_layout_search() {
2624

    
2625
  $form = array();
2626

    
2627
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2628

    
2629
  $form['search_settings'] = array(
2630
    '#type' => 'fieldset',
2631
    '#title' => t('Taxa Search'),
2632
    '#collapsible' => FALSE,
2633
    '#collapsed' => FALSE,
2634
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2635
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2636
         where they can write the text to be searched. You can find Drupal block configuration
2637
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2638
  );
2639

    
2640
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2641
      '#type' => 'checkbox',
2642
      '#title' => t('Ignore the chosen classification in simple search'),
2643
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2644
      '#description' => t('The simple search, which can be executed via the search block,
2645
          will by default search on the classification selected in the classification browser
2646
          selector. Set the tick if you want your portal to search on all classifications.'),
2647
  );
2648

    
2649
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2650
    '#type' => 'checkbox',
2651
    '#title' => t('Run simple search with free-text search backend.'),
2652
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2653
    '#description' => t('The simple search uses by default another search
2654
      backend as the advances search. By checking this option the simple search can be
2655
      configured to also use the free-text search backend.'),
2656
  );
2657

    
2658
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2659
    '#type' => 'checkbox',
2660
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2661
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2662
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2663
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2664
  );
2665

    
2666
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2667
    '#type' => 'textfield',
2668
    '#title' => t('Results per page') . ':',
2669
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2670
    '#description' => t('Number of results to display per page.'),
2671
  );
2672
    
2673
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2674
    '#type' => 'checkbox',
2675
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2676
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2677
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2678
  );
2679

    
2680
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2681
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2682
      '#type' => 'checkboxes',
2683
      '#title' => 'Search mode',
2684
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2685
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2686
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2687
          defaults set here.',
2688
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2689
      '#default_value' => $search_mode_default
2690
      );
2691

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

    
2697
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2698
  );
2699

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

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

    
2717
/**
2718
 * @todo document this function.
2719
 */
2720
function cdm_settings_layout_media() {
2721

    
2722
  $form = array();
2723

    
2724
  $form['media_settings'] = array(
2725
    '#type' => 'fieldset',
2726
    '#title' => t('Media settings'),
2727
    '#collapsible' => FALSE,
2728
    '#collapsed' => FALSE,
2729
    '#description' => 'This section covers layout settings for media pages.'
2730
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2731
  );
2732

    
2733
  $form['media_settings']['image_gallery_viewer'] = array(
2734
    '#type' => 'select',
2735
    '#title' => t('Image viewer') . ':',
2736
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2737
    '#options' => array(
2738
      'default' => t('Standard image viewer'),
2739
      'fsi' => t('FSI viewer (requires FSI server!)'),
2740
    ),
2741
  );
2742

    
2743
  // --- STANDARD_IMAGE_VIEWER ---- //
2744
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2745
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2746
      '#type' => 'fieldset',
2747
      '#tree' => true,
2748
      '#title' => t('Standard image viewer settings'),
2749
      '#collapsible' => FALSE,
2750
      '#collapsed' => FALSE,
2751
      );
2752

    
2753
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2754
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2755
      '#type' => 'checkbox',
2756
      '#title' => 'Show media representations',
2757
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2758

    
2759
    );
2760
  }
2761

    
2762

    
2763
  // @WA: D7 form api does not support reset buttons,
2764
  // so to mimic the D5 reset button we add one like this.
2765
  $form['actions']['reset'] = array(
2766
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2767
    '#weight' => 1000,
2768
  );
2769
  return system_settings_form($form);
2770
}
2771

    
2772
/**
2773
 * GEOSERVICE and Map settings.
2774
 */
2775
function cdm_settings_geo($form, &$form_state) {
2776

    
2777
  $current_geoserver_settings = get_edit_map_service_settings();
2778
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2779

    
2780

    
2781
  $form = array();
2782

    
2783
  $dummy_distribution_query = NULL;
2784
  if($map_distribution['map_type'] != 1){
2785
    // we need to apply a dummy query since the map service requires for image maps
2786
    // at least as and ad to be defined
2787
    $dummy_distribution_query = "as=a:339966&ad=tdwg1:a:1,2,3,4,5,6,7,8,9";
2788
  }
2789

    
2790
  $form['map_preview'] = array(
2791
      '#type' => 'fieldset',
2792
      '#tree' => FALSE,
2793
      '#title' => t('Map preview'),
2794
      '#collapsible' => FALSE,
2795
      '#description' => 'The preview of the map'
2796
       . ($dummy_distribution_query != null ?
2797
           ' may not be accurate in case of image maps, please check the map display in the taxon pages.':
2798
           '.<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.')
2799
  );
2800
  $form['map_preview']['openlayers_map'] = compose_map('settings-preview', NULL, $dummy_distribution_query, NULL, array(
2801
    'move' => "this.cdmOpenlayersMap.printInfo",
2802
    '#execute' => "this.cdmOpenlayersMap.printInfo"
2803
  ), true // resizable
2804
  );
2805

    
2806
  /*
2807
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2808
  );
2809
  */
2810

    
2811
  /*
2812
   * GEO SERVER
2813
   */
2814
  $form['edit_map_server'] = array(
2815
    '#type' => 'fieldset',
2816
    '#tree' => true,
2817
    '#title' => t('EDIT map service'),
2818
    '#collapsible' => TRUE,
2819
    '#collapsed' => TRUE,
2820
    '#description' => t('Configuration and selection of your geo server.
2821
      The Geo Server is responsible for generating the maps.'),
2822
  );
2823

    
2824
  $form['edit_map_server']['base_uri'] = array(
2825
    '#type' => 'select',
2826
    '#title' => t('EDIT map service') . ':',
2827
    '#default_value' => $current_geoserver_settings['base_uri'],
2828
    '#options' => unserialize(EDIT_MAPSERVER_URI),
2829
    '#description' => t('Select the EDIT map server you want to use within your data portal.'),
2830
  );
2831
  $form['edit_map_server']['version'] = array(
2832
      '#type' => 'select',
2833
      '#title' => t('Version') . ':',
2834
      '#default_value' => $current_geoserver_settings['version'],
2835
      '#options' => unserialize(EDIT_MAPSERVER_VERSION),
2836
      '#description' => t('The version of the EDIT map services'),
2837
  );
2838

    
2839
  /*
2840
   * MAP SETTINGS
2841
   */
2842

    
2843
  $form[CDM_MAP_DISTRIBUTION] = array(
2844
    '#type' => 'fieldset',
2845
    '#tree' => TRUE,
2846
    '#title' => t('Maps settings'),
2847
    '#collapsible' => TRUE,
2848
    '#collapsed' => TRUE,
2849
    '#description' => t('General configuration for all map types.'),
2850
  );
2851

    
2852
  $form[CDM_MAP_DISTRIBUTION]['map_type'] = array(
2853
    '#type' => 'radios',
2854
    '#title' => 'Map types',
2855
    '#options' => array(
2856
      1 => "OpenLayers dynamic map viewer",
2857
      0 => "Plain image",
2858
    ),
2859
    '#default_value' => $map_distribution['map_type'],
2860
    '#description' => 'Two different map types are available :
2861
      <ul><li><em>OpenLayers</em>: Display the maps in an interactive viewer
2862
      which allows zooming and panning. If enabled you can configure the default layer
2863
      (background of your maps) below.</li>
2864
      <li><em>Plain image</em>: The map will be static non interactive
2865
      image.</li></ul>',
2866
  );
2867
  $open_layers_is_enabled = $map_distribution['map_type'] == 1;
2868

    
2869
  /*
2870
   * settings for the distribution map are used also for specimens map!!!!
2871
   */
2872

    
2873
  $form[CDM_MAP_DISTRIBUTION]['aspect_ratio'] = array(
2874
      '#type' => 'textfield',
2875
      '#title' => 'Aspect ratio',
2876
      '#default_value' => $map_distribution['aspect_ratio'],
2877
      '#maxlength' => 4,
2878
      '#size' => 4,
2879
      '#element_validate' => array('element_validate_number'),
2880
      '#description' => 'The ratio of width to height of the map. Instead of expressing the aspect ratio as usually as
2881
      two numbers separated by a colon (x:y), this field requires a the value which is the result of the division of the
2882
      width by the height:</br>
2883
      <pre>aspect ratio = w / h</pre>
2884
      For a landscape oriented map with an aspect ratio of 2:1 use <strong>2</strong> as value,</br>
2885
      for a square map use <strong>1</strong>.',
2886
  );
2887

    
2888
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2889
    '#type' => 'textfield',
2890
    '#title' => 'Bounding box',
2891
    '#default_value' => $map_distribution['bbox'],
2892
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2893
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2894
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2895
      <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.
2896
      (Maybe you need to change the map base layer to OpeLayers.)
2897
      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
2898
      below the map from where you can copy the bbox string.</p>'),
2899
  );
2900

    
2901
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2902
    '#type' => 'select',
2903
    '#title' => 'Max zoom level',
2904
    '#default_value' => $map_distribution['maxZoom'],
2905
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2906
  );
2907

    
2908
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2909
    '#type' => 'checkbox',
2910
    '#title' => 'Display area labels',
2911
    '#default_value' => $map_distribution['show_labels'],
2912
    '#description' => t('The map will show name labels of the areas'),
2913
  );
2914

    
2915
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2916
    '#type' => 'textfield',
2917
    '#title' => 'Map caption',
2918
    '#default_value' => $map_distribution['caption'],
2919
    '#description' => t('The caption will be shown below the map.'),
2920
  );
2921

    
2922
  $form[CDM_MAP_DISTRIBUTION]['distribution_opacity'] = array(
2923
    '#type' => 'textfield',
2924
    '#title' => 'Distribution layer opacity',
2925
    '#default_value' => $map_distribution['distribution_opacity'],
2926
    '#description' => t('Valid values range from 0.0 to 1.0. Value 1.0 means the distributions
2927
    (the countries or regions) will fully visible, while a value near to 0.0 will be not much visible.'),
2928
  );
2929

    
2930
  // --- Plain Image Settings --- //
2931
  $form[CDM_MAP_DISTRIBUTION]['image_map'] = array(
2932
    '#type' => 'fieldset',
2933
    '#title' => 'Plain image map settings',
2934
    '#tree' => TRUE,
2935
    '#collapsible' => TRUE,
2936
    '#collapsed' => $open_layers_is_enabled,
2937
    '#description' => 'The settings in this section are still expertimental
2938
      and can only be used with the EDIT map service version 1.1 or above.',
2939
  );
2940
  $edit_mapserver_version = get_edit_map_service_version_number();
2941
  if ($edit_mapserver_version < 1.1) {
2942
    $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'] = '<div class="messages warning">'
2943
      . t("The chosen EDIT map service version (@edit-mapserver-version) is too low, it must be at least 1.1",
2944
        array('@edit_mapserver_version' => '$edit_mapserver_version')) . '</div>'
2945
      . $form[CDM_MAP_DISTRIBUTION]['image_map']['#description'];
2946
  }
2947

    
2948
  $form[CDM_MAP_DISTRIBUTION]['image_map']['width'] = array(
2949
    '#type' => 'textfield',
2950
    '#title' => 'Width',
2951
    '#default_value' => $map_distribution['image_map']['width'],
2952
    '#maxlength' => 4,
2953
    '#size' => 4,
2954
    '#description' => 'Width of the map. The height is calculated from the <strong>Aspect ratio</strong> set in the section above. ',
2955
  );
2956

    
2957
  $form[CDM_MAP_DISTRIBUTION]['image_map']['base_layer'] = array(
2958
    '#type' => 'textfield',
2959
    '#title' => 'Background layer',
2960
    '#default_value' => $map_distribution['image_map']['base_layer'],
2961
    '#description' => t('Background layer. For available layers inspect !url1 or !url2.', array(
2962
      '!url1' => l('deegree-csw', 'http://edit.africamuseum.be:8080/deegree-csw/md_search.jsp'),
2963
      '!url2' => l('geoserver layers', 'http://edit.africamuseum.be/geoserver/web/'),
2964
    )),
2965
  );
2966

    
2967
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2968
    '#type' => 'textfield',
2969
    '#title' => 'Background color',
2970
    '#default_value' => $map_distribution['image_map']['bg_color'],
2971
  );
2972

    
2973
  $form[CDM_MAP_DISTRIBUTION]['image_map']['layer_style'] = array(
2974
    '#type' => 'textfield',
2975
    '#title' => 'Background layer style',
2976
     // Only line color by now.
2977
    '#default_value' => $map_distribution['image_map']['layer_style'],
2978
    '#description' => 'Syntax: {Area fill color},{Area stroke color},{Area stroke width},{Area stroke dash style}',
2979
  );
2980

    
2981
  $form[CDM_MAP_DISTRIBUTION]['image_map']['projection'] = array(
2982
      '#type' => 'textfield',
2983
      '#title' => 'Projection',
2984
      '#default_value' => drupal_array_get_nested_value($map_distribution, array('image_map', 'projection')),
2985
      '#description' => 'Spatial Reference System (SRS) identifier ) optional ( Defines projections in WMS GetMap request.
2986
        Using EPSG:4326 (WGS84 lat/long) is the default but can be changed
2987
        on-the-fly to different UTM and much more zone specific. Examples: EPSG:4326, EPSG:900913, EPSG:3857, EPSG:7777777',
2988
  );
2989

    
2990

    
2991
  // --- OpenLayers Settings --- //
2992
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
2993
    '#type' => 'fieldset',
2994
    '#title' => 'OpenLayers settings',
2995
    '#tree' => TRUE,
2996
    '#collapsible' => TRUE,
2997
    '#collapsed' => !$open_layers_is_enabled,
2998
    '#description' => '',
2999
  );
3000

    
3001

    
3002
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['display_outside_max_extent'] = array(
3003
      '#type' => 'checkbox',
3004
      '#title' => 'Display outside max extent',
3005
      '#default_value' => $map_distribution['openlayers']['display_outside_max_extent'],
3006
      '#description' => t('Allows the map to display parts of the layers which are outside
3007
         the max extent if the aspect ratio of the map and of the baselayer
3008
         are not equal.'),
3009
  );
3010

    
3011

    
3012
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['show_layer_switcher'] = array(
3013
      '#type' => 'checkbox',
3014
      '#title' => 'Show Layer Switcher',
3015
      '#default_value' => $map_distribution['openlayers']['show_layer_switcher'],
3016
      '#description' => 'The Layer Switcher control displays a table of contents
3017
      for the map.  This allows the user interface to switch between
3018
      base layers and to show or hide overlays.  By default the switcher is
3019
      shown minimized on the right edge of the map, the user may expand it
3020
      by clicking on the handle.',
3021
  );
3022

    
3023
  if (!$open_layers_is_enabled) {
3024
    $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'] = '<div class="messages warning">'
3025
        . 'The Openlayers viewer is currently not enabled! (see section Maps settings above )</div>'
3026
        . $form[CDM_MAP_DISTRIBUTION]['openlayers']['#description'];
3027
  }
3028

    
3029
  // The default layer must always be enabled
3030
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3031
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3032

    
3033
  $baselayer_options = array(
3034
    /*
3035
   NOTICE: must correspond to the layers defined in
3036
   js/openlayers_,ap.js#getLayersByName()
3037
   */
3038
    'osgeo_vmap0' => "Metacarta Vmap0 (OSGeo server) - instable!", // EPSG:4326: EPSG:900913
3039
    'metacarta_vmap0' => "Metacarta Vmap0 (MetaCarta Labs server)  - instable!", // EPSG:4326, EPSG:900913
3040
    'mapproxy_vmap0' => "Metacarta Vmap0 (OSGeo server) - via fast EDIT MapProxy",
3041
    'mapproxy_etopo1' => "ETOPO1 Global Relief Model - via fast EDIT MapProxy",
3042
    'edit-etopo1' => "ETOPO1 Global Relief Model",
3043
    // all others EPSG:900913
3044
    'mapnik' => 'OpenStreetMap (mapnik)',
3045
    'stamen_terrain' => 'Stamen Terrain',
3046
    'open_topomap' => 'OpenTopoMap',
3047
    // map quest is no longer free. it is required to sign up for a test plan.
3048
    // 'mapquest_open' => "MapQuest",
3049
    // 'mapquest_sat' => "MapQuest Sattelite",
3050
    'groadmap' => 'Google Roadmap',
3051
    'gsatellite' => 'Google Satellite',
3052
    'ghybrid' => 'Google Hybrid',
3053
    'gterrain' => 'Google Terrain',
3054
//     'veroad' => 'Virtual Earth Roads',
3055
//     'veaer' => 'Virtual Earth Aerial',
3056
//     'vehyb' => 'Virtual Earth Hybrid',
3057
    // 'yahoo' => 'Yahoo Street',
3058
    // 'yahoosat' => 'Yahoo Satellite',
3059
    // 'yahoohyb' => 'Yahoo Hybrid',
3060
     'custom_wms_base_layer_1' => 'Custom WMS base layer (needs to be manually configured below!)',
3061
  );
3062

    
3063
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['base_layers'] = array(
3064
    '#type' => 'checkboxes_preferred',
3065
    '#title' => 'Base Layers',
3066
    '#options' => $baselayer_options,
3067
    '#default_value' =>  $map_distribution['openlayers']['base_layers'],
3068
    '#description' => 'Choose the baselayer layer you prefer to use as map background in the OpenLayers dynamic mapviewer.',
3069
  );
3070

    
3071
  $google_maps_api_key = null;
3072
  if(isset($map_distribution['openlayers']['google_maps_api_key'])){
3073
    $google_maps_api_key = $map_distribution['openlayers']['google_maps_api_key'];
3074
  }
3075
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['google_maps_api_key'] = array(
3076
    '#type' => 'textfield',
3077
    '#title' => 'Google Maps API Key',
3078
    '#default_value' => $google_maps_api_key,
3079
    '#description' => 'In order to use any of the Google map layers you need to provide 
3080
        your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Google Maps API Key</a>. ',
3081
  );
3082

    
3083
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['custom_wms_base_layer'] = wms_layer_settings(
3084
    $map_distribution['openlayers']['custom_wms_base_layer'],
3085
    'Custom WMS base layer',
3086
    'Here you an define a custom wms layer as additional base layer. You need to enable this layer in the base layers section above.',
3087
    true // add projection settings
3088
    );
3089

    
3090
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer'] = wms_layer_settings(
3091
    $map_distribution['openlayers']['wms_overlay_layer'],
3092
    'WMS overlay layer',
3093
    'Here you an define a wms layer which will overlay all other layers in the map viewer. 
3094
                You can actually combine multiple layers for this overlay. 
3095
                For details please refer to the wms query parameter <code>Layers</code> .'
3096
  );
3097

    
3098
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3099
    '#type' => 'checkbox',
3100
    '#title' => 'Enable overlay layer',
3101
    '#weight' => -100,
3102
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3103
  );
3104

    
3105
  /*
3106
   * Map Legend
3107
   */
3108
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3109
    '#type' => 'fieldset',
3110
    '#title' => 'Map legend',
3111
    '#tree' => TRUE,
3112
    '#collapsible' => TRUE,
3113
    '#collapsed' => TRUE,
3114
    '#description' => 'Configure the maps legend.',
3115
  );
3116

    
3117
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3118
    '#type' => 'checkbox',
3119
    '#title' => 'Display a map legend',
3120
    '#default_value' => $map_distribution['legend']['show'],
3121
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3122
  );
3123

    
3124
  $form[CDM_MAP_DISTRIBUTION]['legend']['opacity'] = array(
3125
    '#type' => 'textfield',
3126
    '#title' => 'Legend opacity',
3127
    '#default_value' => $map_distribution['legend']['opacity'],
3128
    '#description' => 'Valid values range from 0.0 to 1.0. Value 1.0 means the legend will be fully visible, while a value near
3129
                         to 0.0 will be not much visible.',
3130
  );
3131

    
3132
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3133
    '#type' => 'textfield',
3134
    '#title' => 'Font size',
3135
    '#default_value' => $map_distribution['legend']['font_size'],
3136
    '#description' => 'Font size in pixels.',
3137
  );
3138

    
3139
  $fontStyles = array(
3140
    0 => "plane",
3141
    1 => "italic",
3142
  );
3143
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_style'] = array(
3144
    '#type' => 'select',
3145
    '#title' => 'Available font styles',
3146
    '#default_value' => $map_distribution['legend']['font_style'],
3147
    '#options' => $fontStyles,
3148
    '#description' => 'Select a font style for the map legend.',
3149
  );
3150

    
3151
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3152
    '#type' => 'textfield',
3153
    '#title' => 'Icon width',
3154
    '#default_value' => $map_distribution['legend']['icon_width'],
3155
    '#description' => 'Legend icon width in pixels.',
3156
  );
3157
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3158
    '#type' => 'textfield',
3159
    '#title' => 'Icon height',
3160
    '#default_value' => $map_distribution['legend']['icon_height'],
3161
    '#description' => 'Legend icon height in pixels.',
3162
  );
3163

    
3164
  // @WA: D7 form api does not support reset buttons,
3165
  // so to mimic the D5 reset button we add one like this.
3166
  $form['actions']['reset'] = array(
3167
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3168
    '#weight' => 1000,
3169
  );
3170

    
3171
  return system_settings_form($form);
3172
}
3173

    
3174
/**
3175
 * @param $default_settings
3176
 * @param $title
3177
 * @param $description
3178
 * @param bool $add_projection_settings
3179
 * @return array
3180
 */
3181
function wms_layer_settings($default_settings, $title, $description, $add_projection_settings = false)
3182
{
3183
  $form_elements = array(
3184
    '#type' => 'fieldset',
3185
    '#title' => $title,
3186
    '#tree' => TRUE,
3187
    '#collapsible' => FALSE,
3188
    '#collapsed' => FALSE,
3189
    '#description' => $description,
3190
  );
3191

    
3192
  $form_elements['name'] = array(
3193
    '#type' => 'textfield',
3194
    '#title' => 'Layer name',
3195
    '#default_value' => $default_settings['name'],
3196
    '#description' => 'A arbitrary name for the layer.',
3197
  );
3198
  $form_elements['url'] = array(
3199
    '#type' => 'textfield',
3200
    '#title' => 'WMS url',
3201
    '#default_value' => $default_settings['url'],
3202
    '#description' => 'Base url for the WMS (e.g.  http://edit.africamuseum.be/geoserver/topp/wms, http://wms.jpl.nasa.gov/wms.cgi)'
3203
  );
3204
  $form_elements['untiled'] = array(
3205
    '#type' => 'checkbox',
3206
    '#title' => 'Untiled',
3207
    '#default_value' => $default_settings['untiled'],
3208
    '#description' => 'If the layer contains labels you may want to check this option to avoid label duplication or erratic invisibility.'
3209
  );
3210
  $form_elements['params'] = array(
3211
    '#type' => 'textarea',
3212
    '#title' => 'WMS parameters',
3213
    '#element_validate' => array('form_element_validate_json'),
3214
    '#default_value' => $default_settings['params'],
3215
    '#description' => 'An javasript object with key/value pairs representing the GetMap query string parameters and parameter values ('
3216
      .l('Geoserver WMS parameter reference', 'http://docs.geoserver.org/stable/en/user/services/wms/reference.html#getmap' )
3217
      . '), entered in valid JSON. For example:
3218
<pre> {
3219
  "Layers": "topp:em_tiny_jan2003",
3220
  "Format": "image/png",
3221
  "BGCOLOR": "0xe0faff"
3222
}
3223
</pre>
3224
    You can supply and web accessible SLD file by using the <code>sld</code> or <coded>sld_body</coded> parameters.'
3225
  );
3226

    
3227
  if($add_projection_settings){
3228

    
3229
    $form_elements['projection'] = array(
3230
      '#type' => 'textfield',
3231
      '#title' => 'Projection',
3232
      '#default_value' => $default_settings['projection'],
3233
      '#description' => 'The desired projection for the layer (e.g. EPSG:4326, EPSG:900913, EPSG:3857)'
3234
    );
3235
    $form_elements['proj4js_def'] = array(
3236
      '#type' => 'textfield',
3237
      '#maxlength' => 256,
3238
      '#title' => 'proj4js definition',
3239
      '#default_value' => $default_settings['proj4js_def'],
3240
      '#description' => 'The <a href="http://trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js">proj4js definition</a> for the projection named above.
3241
              The definitions for
3242
              EPSG:102067, EPSG:102757, EPSG:102758, EPSG:21781, EPSG:26591, EPSG:26912, EPSG:27200, EPSG:27563, EPSG:3857,
3243
              EPSG:41001, EPSG:4139, EPSG:4181, EPSG:42304, EPSG:4272, EPSG:4302, EPSG:900913
3244
              are already predefined and must NOT be added here again.  If your dont know the defintion of your desired projection,
3245
              go to  <a href="http://spatialreference.org/">http://spatialreference.org/</a>, search for your projection and
3246
              choose to display the proj4js definition string.
3247
              <h5>Quick Reference on the common proj4js definition parameters:</h5>
3248
              <pre>
3249
  +a         Semimajor radius of the ellipsoid axis
3250
  +alpha     ? Used with Oblique Mercator and possibly a few others
3251
  +axis      Axis orientation (new in 4.8.0)
3252
  +b         Semiminor radius of the ellipsoid axis
3253
  +datum     Datum name (see `proj -ld`)
3254
  +ellps     Ellipsoid name (see `proj -le`)
3255
  +k         Scaling factor (old name)
3256
  +k_0       Scaling factor (new name)
3257
  +lat_0     Latitude of origin
3258
  +lat_1     Latitude of first standard parallel
3259
  +lat_2     Latitude of second standard parallel
3260
  +lat_ts    Latitude of true scale
3261
  +lon_0     Central meridian
3262
  +lonc      ? Longitude used with Oblique Mercator and possibly a few others
3263
  +lon_wrap  Center longitude to use for wrapping (see below)
3264
  +nadgrids  Filename of NTv2 grid file to use for datum transforms (see below)
3265
  +no_defs   Don\'t use the /usr/share/proj/proj_def.dat defaults file
3266
  +over      Allow longitude output outside -180 to 180 range, disables wrapping (see below)
3267
  +pm        Alternate prime meridian (typically a city name, see below)
3268
  +proj      Projection name (see `proj -l`)
3269
  +south     Denotes southern hemisphere UTM zone
3270
  +to_meter  Multiplier to convert map units to 1.0m
3271
  +towgs84   3 or 7 term datum transform parameters (see below)
3272
  +units     meters, US survey feet, etc.
3273
  +vto_meter vertical conversion to meters.
3274
  +vunits    vertical units.
3275
  +x_0       False easting
3276
  +y_0       False northing
3277
  +zone      UTM zone
3278
              </pre>
3279
            For the full reference please refer to <a href="http://proj4.org/parameters.html">http://proj4.org/parameters.html</a>.'
3280
    );
3281
    $form_elements['max_extent'] = array(
3282
      '#type' => 'textfield',
3283
      '#title' => 'Maximum extent',
3284
      '#default_value' => $default_settings['max_extent'],
3285
      '#description' => 'The maximum extent of the map as bounding box (left, bottom, right, top) in the units of the map.'
3286
    );
3287
    $form_elements['units'] = array(
3288
      '#type' => 'textfield',
3289
      '#title' => 'Units',
3290
      '#default_value' => $default_settings['units'],
3291
      '#description' => 'The layer map units.  Defaults to null.  Possible values are ‘degrees’ (or ‘dd’), ‘m’, ‘ft’, ‘km’, ‘mi’, ‘inches’.  Normally taken from the projection.  Only required if both map and layers do not define a projection, or if they define a projection which does not define units.'
3292
    );
3293

    
3294
  }
3295
  return $form_elements;
3296
}
3297

    
3298

    
3299
/**
3300
 * @todo document this function.
3301
 */
3302
function cdm_settings_cache() {
3303

    
3304
  $form = array();
3305

    
3306
  $form['cache_settings'] = array(
3307
    '#type' => 'fieldset',
3308
    '#title' => t('Cache Settings'),
3309
    '#collapsible' => FALSE,
3310
    '#collapsed' => FALSE,
3311
    '#description' => t('<p>When caching is enabled all single taxon sites are
3312
      stored in an internal drupal cache doing the portal response of taxa pages
3313
      faster. This is possible because the sites are loaded from the cache and
3314
      are not created from scratch.</p>'),
3315
  );
3316

    
3317
  $form['cache_settings']['cdm_webservice_cache'] = array(
3318
    '#type' => 'checkbox',
3319
    '#title' => t('<strong>Enable caching</strong>'),
3320
    '#options' => cdm_help_general_cache(),
3321
    '#default_value' => variable_get('cdm_webservice_cache', 1),
3322
    '#description' => t('<p>Enable drupal to load taxa pages from the cache.</p>
3323
       <p><strong>Note:</strong> If taxa are modified by the editor or any other
3324
       application the changes will be not visible till the cache is erased.
3325
       Therefore developers should deactived this feature when they are working
3326
       on the CDM Dataportal Module.</p>'),
3327
  );
3328

    
3329
  $form['cache_settings']['cdm_run_cache'] = array(
3330
    '#markup' => cdm_view_cache_site(),
3331
  );
3332

    
3333
  // @WA: D7 form api does not support reset buttons,
3334
  // so to mimic the D5 reset button we add one like this.
3335
  $form['actions']['reset'] = array(
3336
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
3337
    '#weight' => 1000,
3338
  );
3339
  return system_settings_form($form);
3340
}
3341

    
3342
/**
3343
 * Walk and cache all taxon pages.
3344
 */
3345
function cdm_view_cache_site() {
3346

    
3347
  $out = '';
3348

    
3349
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3350

    
3351
  $request_params = array();
3352
  $request_params['class'] = "Taxon";
3353

    
3354
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3355
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3356
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3357

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

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

    
3367
  // Comment @WA: A form within a form is not valid html and not needed here.
3368
  // Also, it would be recommended just to include this part of the form in the
3369
  // rest of the form array in cdm_settings_cache().
3370
  // $out .= '<form id="cache_site">';
3371
  $out .= '<input type="hidden" name="pageTaxaUrl" value="' . $cdm_ws_page_taxa_url . '"/>';
3372
  $out .= '<input type="hidden" name="taxonPageUrl" value="' . url('cdm_dataportal/taxon/') . '"/>';
3373
  $out .= '<input type="button" name="start" value="' . t('Start') . '"/>';
3374
  $out .= '<input type="button" name="stop" value="' . t('Stop') . '"/>';
3375
  // $out .= '</form>';
3376
  $out .= '</div>';
3377
  /*
3378
  foreach($taxonPager->records as $taxon){
3379
    cdm_dataportal_taxon_view($uuid);
3380
  }
3381
  */
3382
  return $out;
3383
}
3384

    
3385

    
3386
function cdm_settings_layout_taxon_submit($form, &$form_state){
3387
  if (isset($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'])) {
3388
    $file = file_load($form_state['values'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid']);
3389
    if(is_object($file)){
3390
      $file->status = FILE_STATUS_PERMANENT;
3391
      file_save($file);
3392
      file_usage_add($file, 'cdm_dataportal', CDM_TAXON_PROFILE_IMAGE, 0);
3393
    }
3394
  }
3395
  // rebuild the menu if the specific tabs setting have changed, otherwise the change will not have a consistent effect
3396
  $tab_lables_modified = serialize(get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT)) != serialize($form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3397
  $tabs_enabled_modified = variable_get('cdm_dataportal_taxonpage_tabs', 1) != $form_state['values']['cdm_dataportal_taxonpage_tabs'];
3398
  if($tab_lables_modified || $tabs_enabled_modified){
3399
    // we first need to set the variable to persist the changes setting
3400
    variable_set('cdm_dataportal_taxonpage_tabs', $form_state['values']['cdm_dataportal_taxonpage_tabs']);
3401
    variable_set(CDM_TAXONPAGE_TAB_LABELS, $form_state['values'][CDM_TAXONPAGE_TAB_LABELS]);
3402
    menu_rebuild();
3403
  }
3404
}
3405

    
3406
function cdm_settings_layout_search_submit($form, &$form_state){
3407
  // the visibility of media thumbnails also affects the ui of the search results
3408
  // so reset the according session variable
3409
  //    1. in order to give the user immediate
3410
  //       feedback on potential setting changes
3411
  //    2. let refresh the default if it has changed
3412
  if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
3413
    unset($_SESSION['pageoption']['searchtaxa']['showThumbnails']);
3414
  }
3415
}
3416

    
3417
/**
3418
 * Form validation handler for cdm_settings_general
3419
 *
3420
 * @param $form
3421
 * @param $form_state
3422
 */
3423
function cdm_settings_general_validate($form, &$form_state) {
3424

    
3425
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3426
    $form_state['values']['cdm_webservice_url'] .= '/';
3427
  }
3428

    
3429
}
3430

    
3431
/**
3432
 * Form submit handler for settings general.
3433
 *
3434
 * tasks performed:
3435
 *  - clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3436
 *
3437
 * @param $form
3438
 * @param $form_state
3439
 */
3440
function cdm_settings_general_submit($form, &$form_state){
3441
  // clear the [cdm][taxonomictree_uuid] session variable since this taxonomictree_uuid might no longer bee valid
3442
  unset($_SESSION['cdm']['taxonomictree_uuid']);
3443
  unset($_SESSION['cdm_login']);
3444
}
3445

    
3446
/**
3447
 * Form validation handler for cdm_settings_cache
3448
 */
3449
function cdm_settings_cache_validate($form, &$form_state) {
3450
  if ($form_state['values']['cdm_webservice_cache'] != variable_get('cdm_webservice_cache', 1)) {
3451
    cache_clear_all(NULL, 'cache_cdm_ws');
3452
    // Better clear secref_cache since I can not be sure if the cache has not
3453
    // be used during this response.
3454
    cdm_api_secref_cache_clear();
3455
  }
3456

    
3457
}
3458

    
3459
/**
3460
 * Returns an associative array of the currently chosen settings for the EDIT map service or the defaults as
3461
 * specified in EDIT_MAPSERVER_URI_DEFAULT and EDIT_MAPSERVER_VERSION_DEFAULT:
3462
 *  - base_uri: the protocol and host part , e.g.: http://edit.africamuseum.be
3463
 *  - version: the version, e.g.: v1.1
3464
 *
3465
 * @return array
3466
 *    An associative array of the currently chosen settings for the EDIT map service or the defaults.
3467
 */
3468
function get_edit_map_service_settings() {
3469

    
3470
  $settings = variable_get('edit_map_server', array(
3471
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3472
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3473
      )
3474
  );
3475

    
3476
  return $settings;
3477
}
3478

    
3479
/**
3480
 * Returns the full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3481
 *
3482
 * @return string
3483
 *   The full edit map service URI e.g.: http://edit.africamuseum.be/edit_wp5/v1.1
3484
 */
3485
function get_edit_map_service_full_uri() {
3486
  $settings = get_edit_map_service_settings();
3487
  return $settings['base_uri'] . EDIT_MAPSERVER_PATH .  '/' . $settings['version'];
3488
}
3489

    
3490

    
3491
/**
3492
 * Returns the version number of the currently selected edit mapserver as a float
3493
 *
3494
 * @return float
3495
 *   The version number of the currently selected edit mapserver as a float.
3496
 *   Returns 0 on error.
3497
 */
3498
function get_edit_map_service_version_number() {
3499

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

    
3502
  $settings = get_edit_map_service_settings();
3503
  preg_match($pattern, $settings['version'], $matches, PREG_OFFSET_CAPTURE);
3504
  if (isset($matches[1])) {
3505
    // Convert string to float.
3506
    $version = 1 + $matches[1][0] - 1;
3507
    return $version;
3508
  }
3509
  else {
3510
    // Report error.
3511
    drupal_set_message(t(" Invalid EDIT map service version number: '!version'",
3512
        array(
3513
          '!version' => $settings['version'],
3514
          'warning')
3515
        )
3516
      );
3517
    return 0;
3518
  }
3519
}
3520

    
3521
/**
3522
 * Returns the array of selected items in a options array
3523
 *
3524
 * @param array $options
3525
 *   An options array as generated by a form element like checkoxes, select ...,
3526
 */
3527
function get_selection($options) {
3528
  $selection = array();
3529
  foreach ($options as $key=>$val) {
3530
    if (!empty($val)) {
3531
      $selection[] = $val;
3532
    }
3533
  }
3534
  return $selection;
3535
}
3536

    
3537

    
3538
/**
3539
 * Implements hook_element_info().
3540
 *
3541
 * Allows modules to declare their own Form API element types and specify their default values.
3542
 *
3543
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7
3544
 */
3545
function cdm_dataportal_element_info() {
3546
  $type['checkboxes_preferred'] = array(
3547
    '#input' => TRUE,
3548
    '#process' => array('checkboxes_preferred_expand'),
3549
    '#after_build' => array('checkboxes_preferred_after_build'),
3550
    '#theme' => array('checkboxes_preferred'),
3551
    // '#theme_wrapper' => array('form_element'),
3552
  );
3553
  return $type;
3554
}
3555

    
3556
/**
3557
 * #process callback function for the custom form element type 'checkbox_preferred'
3558
 *
3559
 *
3560
 */
3561
function checkboxes_preferred_expand($element, &$form_state, $form) {
3562

    
3563
  // First of all create checkboxes for each of the elements
3564
  $element = form_process_checkboxes($element);
3565

    
3566
  // compose the element name
3567
  $parents = array();
3568
  array_deep_copy($element['#parents'], $parents);
3569
  $parents[count($parents) -1 ] .= '_preferred';
3570
  $element_name = $parents[0];
3571
  for ($i=1; $i < count($parents); $i++){
3572
    $element_name .= '[' . $parents[$i] . ']';
3573
  }
3574

    
3575
  $children = element_children($element);
3576

    
3577
  $element['table_start'] = array(
3578
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3579
    '#weight' => -1,
3580
  );
3581

    
3582
  // prepare first part each of the table rows which contains the row label
3583
  $weight = 0;
3584
  foreach ($children as $key) {
3585
    $odd_even = $weight % 4 == 0 ? 'odd' : 'even';
3586
    $element[$key]['#weight'] = $weight;
3587
    $element[$key]['#prefix'] = '<tr class="' . $odd_even . '"><td>' . t('@row-label', array('@row-label' => $element['#options'][$key])) . '</td><td>';
3588
    $element[$key]['#suffix'] = '</td>';
3589
    unset($element[$key]['#title']);
3590
    $weight += 2;
3591
  }
3592
  $weight = 0;
3593

    
3594
  // add a radio button to each of the checkboxes, the
3595
  // check boxes have already been created at the beginning
3596
  // of this function
3597
  if (count($element['#options']) > 0) {
3598
    foreach ($element['#options'] as $key => $choice) {
3599
      if (!isset($element[$key . '_preferred'])) {
3600
        $element[$key . '_preferred'] = array(
3601
          '#type' => 'radio',
3602
          '#name' => $element_name,
3603
          '#return_value' => check_plain($key),
3604
          '#default_value' => empty($element['#default_value_2']) ? NULL : $element['#default_value_2'],
3605
          '#attributes' => $element['#attributes'],
3606
          '#parents' => $element['#parents'],
3607
          // '#spawned' => TRUE,
3608
          '#weight' => $weight + 1,
3609
          '#prefix' => '<td>',        // add a prefix to start a new table cell
3610
          '#suffix' => '</td></tr>',  // add a prefix to close the tabel row
3611
        );
3612
      }
3613
      $weight += 2;
3614
    }
3615
  }
3616

    
3617
  // end the table
3618
  $element['table_end'] = array(
3619
    '#markup' => '</table>',
3620
    '#weight' => $weight++,
3621
  );
3622

    
3623
  return $element;
3624
}
3625

    
3626
/**
3627
 * Theme function for the custom form field 'checkboxes_preferred'.
3628
 */
3629
function theme_checkboxes_preferred($variables) {
3630
  $element = $variables['element'];
3631
  $out = '<div id="edit-baselayers-wrapper" class="form-item">';
3632
  $out .= '<label for="edit-baselayers">' . $element['#title'] . '</label>';
3633
  $out .= drupal_render_children($element);
3634
  $out .= '<div class="description">' . $element['#description'] . '</div>';
3635
  $out .= '</div>';
3636
  return $out;
3637
}
3638

    
3639
/**
3640
 * Callback for checkboxes preferred for widget which will
3641
 * be called after the form or element is built. The call
3642
 * back is configured in the form element by setting it as
3643
 * #after_build parameter.
3644
 *
3645
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build
3646
 *
3647
 * @param $element
3648
 *   Nested array of form elements that comprise the form.
3649
 * @param $form_state
3650
 *   A keyed array containing the current state of the form.
3651
 *   This includes the current persistent storage data for the form.
3652
 *   Additional information, like the sanitized $_POST data,
3653
 *   is also accumulated here in $form_state['input']
3654
 *
3655
 * @return the modified form array
3656
 */
3657
function checkboxes_preferred_after_build($element, &$form_state) {
3658

    
3659
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3660

    
3661
  if ($_POST && count($_POST) > 0) {
3662
    // TODO use  $form_state['input'] instead of POST !!!
3663
    // First pass of form processing.
3664
    $parents = array();
3665
    array_deep_copy($element['#parents'], $parents);
3666
    $parents[count($parents) - 1] .= '_preferred';
3667
    $preferred_layer = drupal_array_get_nested_value($_POST, $parents);
3668
    $element['#value']['PREFERRED'] = $preferred_layer;
3669
//     $form_state[$parent_id] = $element['#value'];
3670
//     $form_state['values']['baselayers'] = $element['#value'];
3671
    $form_state_element_values = &drupal_array_get_nested_value($form_state['values'], $element['#parents']);
3672
    $form_state_element_values = $element['#value'];
3673
  }
3674
  else {
3675
    // Second pass of form processing.
3676
    $preferred_layer = $element['#value']['PREFERRED'];
3677
  }
3678

    
3679
  // Also set the chosen value (not sure if this is good Drupal style ....).
3680
  foreach ($children = element_children($element) as $key) {
3681
    if (!empty($element[$key]['#type']) && $element[$key]['#type'] == 'radio') {
3682
      $element[$key]['#value'] = $preferred_layer;
3683
    }
3684
  }
3685
  // The default layer must always be enabled.
3686
  $element[$preferred_layer]['#value'] = $preferred_layer;
3687

    
3688
  return $element;
3689
}
3690

    
3691
function radios_prepare_options_suffix(&$elements){
3692

    
3693
  $childrenKeys = element_children($elements);
3694
  foreach($childrenKeys as $key){
3695
    if(!is_array($elements[$key]['#theme_wrappers'])){
3696
      $elements[$key]['#theme_wrappers'] = array();
3697
    }
3698
    if(isset($elements['#options_suffixes'][$key])){
3699
      $elements[$key]['#theme_wrappers'][] = 'radio_options_suffix';
3700
      $elements[$key]['#options_suffix'] = $elements['#options_suffixes'][$key];
3701
    }
3702
  }
3703
  return $elements;
3704

    
3705
}
3706

    
3707
/**
3708
 * TODO
3709
 * @param unknown $variables
3710
 */
3711
function theme_radio_options_suffix($variables) {
3712
  $element = $variables['element'];
3713
  if(isset($element['#options_suffix'])) {
3714
    $element['#children'] .= $element['#options_suffix'];
3715
  }
3716
  return $element['#children'];
3717
}
3718

    
3719

    
3720
/**
3721
 * Element validate callback for text field and arrays containing json.
3722
 *
3723
 * @param $element
3724
 *   The form element to validate
3725
 * @param $form_state
3726
 *   A keyed array containing the current state of the form.
3727
 * @param $form
3728
 *   Nested array of form elements that comprise the form.
3729
 */
3730
function form_element_validate_json($element, &$form_state, $form) {
3731
   if (!empty($element['#value'])) {
3732
     json_decode($element['#value']);
3733
     if(json_last_error() != JSON_ERROR_NONE){
3734
       form_error($element,
3735
         t('The form element %title contains invalid JSON. You can check the syntax with ', array('%title' => $element['#title']))
3736
         . l('JSONLint', 'http://jsonlint.com/')
3737
       );
3738
     }
3739
   }
3740
}
3741

    
3742
/**
3743
 * Form submission handler for textareas and textfields containing JSON.
3744
 *
3745
 * The contained JSON will be converted into an php array
3746
 * or object and will be stored in the variables as such.
3747
 *
3748
 * @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#submit
3749
 *
3750
 * @param $form
3751
 *   Nested array of form elements that comprise the form.
3752
 * @param $form_state
3753
 *   A keyed array containing the current state of the form.
3754
 *
3755
 */
3756
function submit_json_as_php_array($form, &$form_state) {
3757
  if (is_array($form['#json_elements'])) {
3758
    foreach ($form['#json_elements'] as $element){
3759
      if (trim($form_state['values'][$element])) {
3760
        $form_state['values'][$element] = (array) json_decode($form_state['values'][$element]);
3761
      } else {
3762
        $form_state['values'][$element] = NULL;
3763
      }
3764
    }
3765
  }
3766
}
(18-18/18)