Project

General

Profile

Download (156 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('CDM_SUB_TREE_FILTER_UUID', 'cdm_sub_tree_filter_uuid');
16

    
17
  define('NO_SORT', -1);
18
  define('SORT_HIERARCHICAL', 9);
19

    
20
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
21

    
22
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT', 1);
23
  define('SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX', 'search_results_show_thumbnail_checkbox');
24

    
25
  define('CDM_DATAPORTAL_NOMREF_IN_TITLE', 1);
26
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE', 0);
27
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE', 50);
28
  define('CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_SHOW_DETERMINED_AS', 0);
29
  define('CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR', 0);
30
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE', 'cdm_synonymy_accepted_taxon_sec_separate');
31
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL', 'cdm_synonymy_accepted_taxon_sec_separate_label');
32
  define('CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT', 'Source');
33
  define('CDM_DATAPORTAL_ALL_FOOTNOTES', 0);
34
  define('CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES', 0);
35
  define('CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX', 999);
36
  define('CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE', 0);
37

    
38
  define('CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK', 'cdm_registration_presistent_identifier_as_link');
39

    
40
  /* annotationTypeKeys */
41
  $annotationTypeKeys = array_keys(cdm_vocabulary_as_option(UUID_ANNOTATION_TYPE));
42
  if (in_array(UUID_ANNOTATION_TYPE_TECHNICAL, $annotationTypeKeys)) {
43
    $annotationTypeKeys = array_flip($annotationTypeKeys);
44

    
45
    // Technical annotation are off by default.
46
    unset($annotationTypeKeys[UUID_ANNOTATION_TYPE_TECHNICAL]);
47
    $annotationTypeKeys = array_flip($annotationTypeKeys);
48
    // Additional value for the NULL case.
49
    $annotationTypeKeys[] = 'NULL_VALUE';
50
  }
51

    
52
  define('ANNOTATION_TYPES_VISIBLE', 'annotations_types_as_footnotes');
53
  define('ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT', serialize($annotationTypeKeys));
54

    
55
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE', 'bibliography_for_original_source');
56
  define('BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT', serialize(array(
57
    'enabled' => 0,
58
    'key_format' => 'ALPHA'
59
  )));
60

    
61
  /* taxonRelationshipTypes */
62
  define('CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT', serialize(
63
    array(
64
      UUID_MISAPPLIED_NAME_FOR => UUID_MISAPPLIED_NAME_FOR,
65
      UUID_PROPARTE_MISAPPLIEDNAME_FOR => UUID_PROPARTE_MISAPPLIEDNAME_FOR,
66
      UUID_PARTIAL_MISAPPLIEDNAME_FOR => UUID_PARTIAL_MISAPPLIEDNAME_FOR,
67
      UUID_PROPARTE_SYNONYM_FOR => UUID_PROPARTE_SYNONYM_FOR,
68
      UUID_PARTIAL_SYNONYM_FOR => UUID_PARTIAL_SYNONYM_FOR,
69
      UUID_INVALID_DESIGNATION_FOR => UUID_INVALID_DESIGNATION_FOR
70
    )
71
  ));
72

    
73

    
74
  /* ---- MAP SETTING CONSTANTS ---- */
75
  /**
76
   * @var array of URIs eg. http://edit.africamuseum.be"
77
   *   An options array
78
   */
79
  define('EDIT_MAPSERVER_URI', serialize(
80
      array(
81
        'http://edit.africamuseum.be'=>'Primary (http://edit.africamuseum.be)'
82
      )
83
    )
84
  );
85
  define('EDIT_MAPSERVER_PATH', '/edit_wp5');
86
  /**
87
   * @var array of versions eg. "v1.2"
88
   *   An options array
89
   */
90
  define('EDIT_MAPSERVER_VERSION', serialize(
91
      array(
92
//        'v1' => 'v1' ,           // no longer recommended
93
//        'v1.1' => 'v1.1',        // no longer recommended
94
//        'v1.2_dev' => 'v1.2_dev',// no longer recommended
95
        'v1.2' => 'v1.2',
96
        'v1.3_dev' => 'v1.3_dev (not recommended)',
97
        'v1.4_dev' => 'v1.4_dev (experimental features)'
98
      )
99
    )
100
  );
101
  define('EDIT_MAPSERVER_URI_DEFAULT', 'http://edit.africamuseum.be');
102
  define('EDIT_MAPSERVER_VERSION_DEFAULT', 'v1.2');
103

    
104
    // --- Taxon profile settings --- /
105
  define('DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP', 'distribution_textdata_on_top');
106
  define('CDM_TAXON_PROFILE_IMAGE', 'cdm_taxon_profile_image');
107
  define('CDM_TAXON_PROFILE_IMAGE_DEFAULT', serialize(
108
      array(
109
          'show' => 0,
110
          'maxextend' => 184,
111
          'media_uri_query' => '',
112
          'custom_placeholder_enabled' => 1,
113
          'custom_placeholder_image_on' => 0,
114
          'custom_placeholder_image_fid' => ''
115
      )
116
    )
117
  );
118

    
119

    
120
define('FEATURE_BLOCK_SETTINGS', 'feature_block_settings');
121

    
122
define('DISTRIBUTION_CONDENSED', 'distribution_condensed');
123
define('DISTRIBUTION_CONDENSED_INFO_PATH', 'distribution_condensed_info_path');
124
define('DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT', 'cdm_dataportal/help/condensed_distribution');
125
define('DISTRIBUTION_CONDENSED_RECIPE', 'distribution_condensed_recipe');
126
define('DISTRIBUTION_CONDENSED_RECIPE_DEFAULT', 'EuroPlusMed');
127

    
128
define('DISTRIBUTION_STATUS_COLORS', 'distribution_status_colors');
129
define('DISTRIBUTION_ORDER_MODE', 'distribution_order_mode');
130
define('DISTRIBUTION_ORDER_MODE_DEFAULT', 'TREE');
131
define('DISTRIBUTION_TREE_OMIT_LEVELS', 'distribution_tree_omit_levels');
132

    
133
define('CDM_SYNONYMY_AS_TAB', 'cdm_synonymy_as_tab');
134
define('CDM_SYNONYMY_AS_TAB_DEFAULT', 1);
135

    
136
/**
137
 * Returns the array of implemented taxon page tabs.
138
 * The array has fixed integer keys which must not be changed.
139
 */
140
function get_taxon_tabs_list() {
141
  $opts = array(
142
    0 => 'General',
143
    1 => 'Synonymy',
144
    2 => 'Images',
145
    3 => 'Specimens',
146
    4 => 'Keys',
147
    5 => 'Experts',
148
  );
149
  if(variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) !== 1){
150
    // skip the Synonymy if it is shown in  the general tab
151
    unset($opts[1]);
152
  }
153
  return $opts;
154
}
155

    
156
define('CDM_TAXONPAGE_TAB_WEIGHT', 'cdm_taxonpage_tab_weight');
157
define('CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT', serialize(
158
  array(
159
    'general' => '-3',
160
    'synonymy' => '-2',
161
    'images' => '0',
162
    'specimens' => '1',
163
    'keys' => '3',
164
    'experts' => '5',
165
    )
166
));
167

    
168

    
169
// CDM_TAXONPAGE_TAB_LABELS_DEFAULT
170
define('CDM_TAXONPAGE_TAB_LABELS', 'cdm_taxonpage_tab_labels');
171
define('CDM_TAXONPAGE_TAB_LABELS_DEFAULT', serialize(
172
  array(
173
    'general' => null,
174
    'synonymy' => null,
175
    'images' => null,
176
    'specimens' => null,
177
    'keys' => null,
178
    'experts' => null,
179
  )
180
));
181

    
182
$taxon_tab_options = get_taxon_tabs_list();
183
$taxon_tab_options[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX] = 'Last visited tab';
184

    
185
define('CDM_DATAPORTAL_DEFAULT_TAXON_TAB', serialize($taxon_tab_options));
186

    
187
/**
188
 * @todo document this function.
189
 */
190
function get_taxon_options_list() {
191
  $taxon_tab_options = array_flip(get_taxon_tabs_list());
192
  foreach ($taxon_tab_options as $key => $value) {
193
    $taxon_tab_options[$key] = t('@key', array('@key' => $key));
194
  }
195
  return $taxon_tab_options;
196

    
197
}
198

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

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

    
364
define('CDM_SEARCH_TAXA_MODE','cdm_search_taxa_mode');
365
define('CDM_SEARCH_TAXA_MODE_DEFAULT', serialize(
366
    // to unset a default enntry set the value to 0
367
    array(
368
      'doTaxa'=>'doTaxa',
369
      'doSynonyms' => 'doSynonyms',
370
      'doTaxaByCommonNames' => 'doTaxaByCommonNames',
371
      'doMisappliedNames' => 'doMisappliedNames'
372
    )
373
  )
374
);
375

    
376
define('CDM_SEARCH_AREA_FILTER_PRESET', 'cdm_search_area_filter_preset');
377

    
378
define('SIMPLE_SEARCH_USE_LUCENE_BACKEND', 'simple_search_use_lucene_backend');
379
define('SIMPLE_SEARCH_IGNORE_CLASSIFICATION', 'simple_search_ignore_classification');
380
define('SIMPLE_SEARCH_AUTO_SUGGEST', 'cdm_search_taxa_auto_suggest');
381

    
382
/* Gallery variables. */
383
$gallery_settings = array(
384
    "cdm_dataportal_show_taxon_thumbnails" => 1,
385
    "cdm_dataportal_show_synonym_thumbnails" => 0,
386
    "cdm_dataportal_show_thumbnail_captions" => 1,
387
    "cdm_dataportal_media_maxextend" => 120,
388
    "cdm_dataportal_media_cols" => 3,
389
    "cdm_dataportal_media_maxRows" => 1,
390
);
391

    
392
define('TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT', serialize(get_taxon_options_list()));
393
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
394
define('CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME', 'specimen_gallery');
395
define('CDM_DATAPORTAL_TYPE_SPECIMEN_GALLERY_NAME', 'type_specimen_gallery');
396
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
397
define('CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB', "taxon_tab_media_gallery");
398
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
399
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS', 'cdm_dataportal_display_taxon_relationships');
400
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS', 'cdm_dataportal_display_name_relations');
401
// define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_2', array("default" => t('Display all')));
402
define('CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT', 1);
403
define('CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT', 1);
404

    
405
define('CDM_STANDARD_IMAGE_VIEWER', "cdm_standard_image_viewer");
406
define('CDM_STANDARD_IMAGE_VIEWER_DEFAULT', serialize(array(
407
  'media_representation_details_enabled' => 0
408
)));
409

    
410
/**
411
 * The drupal variable key for the array containing the uuids of the taxon relationship types to display in
412
 * the snonymy.
413
 *
414
 * @var string
415
 */
416
define('CDM_TAXON_RELATIONSHIP_TYPES', 'cdm_taxon_relationship_types');
417

    
418
define('CDM_NAME_RELATIONSHIP_TYPES', 'cdm_name_relationship_types');
419
define('CDM_NAME_RELATIONSHIP_TYPES_DEFAULT', serialize(
420
    array(
421
      UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_LATER_HOMONYM,
422
      UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM => UUID_NAMERELATIONSHIPTYPE_TREATED_AS_LATER_HOMONYM,
423
      UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR => UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
424
    )
425
  )
426
);
427

    
428
/**
429
 * The drupal variable for the configuration of the information aggregation along
430
 * the taxon relation ships. The mapped arrayis associative and holds two elements:
431
 *    - direct: the uuids of the taxon relationship types to take into account in invers
432
 *      direction.
433
 *    - invers: the uuids of the taxon relationship types to take into account in direct
434
 *      direction.
435
 *
436
 * @var String
437
 */
438
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS', 'cdm_aggregate_by_taxon_relationships');
439
define('CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT', serialize(
440
    array(
441
        'direct'=>array(),
442
        'invers'=>array()
443
     )
444
   ));
445
define('CDM_PROFILE_FEATURETREE_UUID', 'cdm_dataportal_featuretree_uuid');
446
define('CDM_OCCURRENCE_FEATURETREE_UUID', 'cdm_occurrence_featuretree_uuid');
447
define('CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID', 'cdm_dataportal_structdesc_featuretree_uuid');
448

    
449
define('CDM_DISTRIBUTION_FILTER', 'cdm_distribution_filter');
450
define('CDM_DISTRIBUTION_FILTER_DEFAULT', serialize(
451
      array(
452
      'filter_rules' => array(
453
        'statusOrderPreference' => 0,
454
        'subAreaPreference' => 0,
455
      ),
456
      'hiddenAreaMarkerType' => array()
457
     )
458
));
459

    
460
define('DISTRIBUTION_HIERARCHY_STYLE', 'distribution_hierarchy_style');
461
define('DISTRIBUTION_HIERARCHY_STYLE_DEFAULT', serialize(array(
462
  "level_0" => array(
463
    'label_suffix' => ':',
464
    'status_glue' => '',
465
    'item_glue' => ' ',
466
    'item_group_prefix' => '',
467
    'item_group_postfix' => ''
468
  ),
469
  "level_1" => array(
470
    'label_suffix' => '',
471
    'status_glue' => '‒ ', // '&#8210; '
472
    'item_glue' => '; ',
473
    'item_group_prefix' => ', ',
474
    'item_group_postfix' => ''
475
  ),
476
  "level_2" => array(
477
    'label_suffix' => '',
478
    'status_glue' => '‒ ', // '&#8210; '
479
    'item_glue' => ', ',
480
    'item_group_prefix' => ' (',
481
    'item_group_postfix' => ')'
482
  )
483
)));
484

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

    
496
/**
497
 * Constant for the drupal variable key specimen_map_visibility
498
 *
499
 * possible values:
500
 *  - never
501
 *  - automatic
502
 *  - always
503
 */
504
define('SPECIMEN_MAP_VISIBILITY', 'specimen_map_visibility');
505
define('SPECIMEN_MAP_VISIBILITY_DEFAULT', 'automatic');
506

    
507
define('CDM_TAXON_MEDIA_FILTER', 'cdm_taxon_media_filter');
508
define('CDM_TAXON_MEDIA_FILTER_DEFAULT', serialize(
509
    array(
510
        'includeTaxonDescriptions' => 'includeTaxonDescriptions',
511
        'includeOccurrences' => 0,
512
        'includeTaxonNameDescriptions' => 0
513
     )
514
  ));
515

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

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

    
591
    // unserialize if nessecary
592
    if(!is_array($default)){
593
      $default = unserialize($default);
594
    }
595
    $variable = variable_get($variable_name, array());
596
    $result = drupal_array_merge_deep($default, $variable);
597
    return $result;
598
}
599

    
600
/**
601
 * @todo document this function.
602
 */
603
function getGallerySettings($gallery_config_form_name) {
604
  return get_array_variable_merged($gallery_config_form_name, CDM_DATAPORTAL_GALLERY_SETTINGS);
605
}
606

    
607
/**
608
 * Returns the string representation of the default tab.
609
 *
610
 * @param bool $returnTabIndex
611
 *   Defaults to FALSE, if set true this function will return the index number
612
 *   of the default tab. (used to supply default values to form elements).
613
 */
614
function get_default_taxon_tab($returnTabIndex = FALSE) {
615

    
616
  global $user;
617
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
618
  $user_tab_active = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
619
  $user_tab = 'cdm_dataportal_' . $user->uid . '_default_tab';
620
  // Get the user value if the used has chosen to overwrite the system settings.
621
  $user_tab_on = variable_get($user_tab_active, FALSE);
622
  if ($user_tab_on) {
623
    $user_value = variable_get($user_tab, 0);
624
    $index_value = $user_value;
625
    // Get the system value.
626
  }
627
  else {
628
    $system_value = variable_get('cdm_dataportal_default_tab', 0);
629
    $index_value = $system_value;
630
  }
631

    
632
  // Return the index value or the string representation.
633
  if ($returnTabIndex) {
634
    return $index_value;
635
  }
636
  else {
637
    return ($values[$index_value]);
638
  }
639
}
640

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

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

    
712
  // ---- DEFAULTS settings
713

    
714
  // only needed as final option, when the settings are not having a default
715
  $default = array(
716
    'DEFAULT' => array(
717
      'as_list' => 'div',
718
      'link_to_reference' => 0,
719
      'link_to_name_used_in_source' => 1,
720
      'sources_as_content' => 0,
721
      'sources_as_content_to_bibliography' => 0,
722
      'sort_elements' => NO_SORT,
723
      'glue' => '',
724
      'element_tag' => NULL
725
    ),
726
    // settings for pseudo feature bibliography
727
    // only hard coded here
728
    'BIBLIOGRAPHY' => array(
729
      'as_list' => 'div',
730
      'link_to_reference' => 0,
731
      'link_to_name_used_in_source' => 1,
732
      'sources_as_content' => 0,
733
      'sources_as_content_to_bibliography' => 0,
734
      'sort_elements' => NO_SORT,
735
      'glue' => '',
736
      'element_tag' => NULL
737
    )
738
  );
739

    
740
  // will be used as preset in the settings
741
  $other_themes_default = array(
742
    'DEFAULT' => array(
743
      'as_list' => 'div',
744
      'link_to_reference' => 0,
745
      'link_to_name_used_in_source' => 1,
746
      'sources_as_content' => 0,
747
      'sources_as_content_to_bibliography' => 0,
748
      'sort_elements' => NO_SORT,
749
      'glue' => '',
750
      'element_tag' => NULL
751
    ),
752
    UUID_CITATION => array(
753
      'as_list' => 'div',
754
      'link_to_reference' => 0,
755
      'link_to_name_used_in_source' => 0,
756
      'sources_as_content' => 1,
757
      'sources_as_content_to_bibliography' => 0,
758
      'sort_elements' => SORT_ASC,
759
      'glue' => '',
760
      'element_tag' => 'div'
761
    ),
762
    UUID_DISTRIBUTION => array(
763
      'as_list' => 'div', // currently ignored
764
      'link_to_reference' => 0,
765
      'link_to_name_used_in_source' => 0,
766
      'sources_as_content' => 0,
767
      'sources_as_content_to_bibliography' => 0,
768
      'sort_elements' => NO_SORT, // will cause ...
769
      'glue' => '',
770
      'element_tag' => 'div',
771
      'special' => array()
772
    ),
773
    UUID_COMMON_NAME => array(
774
      'as_list' => 'div',
775
      'link_to_reference' => 0,
776
      'link_to_name_used_in_source' => 1,
777
      'sources_as_content' => 0,
778
      'sources_as_content_to_bibliography' => 0,
779
      'sort_elements' => NO_SORT,
780
      'glue' => '',
781
      'element_tag' => 'span'
782
    ),
783
  );
784

    
785
  // ---- Special DEFAULTS for existing portals
786
  // TODO:
787
  // this can be removed once the feature block
788
  // settings have been deployed for the first time to these portals
789

    
790
  $cichorieae_default = array(
791
    'DEFAULT' => array(
792
      'as_list' => 'div',
793
      'link_to_reference' => 1,
794
      'link_to_name_used_in_source' => 1,
795
      'sources_as_content' => 1,
796
      'sources_as_content_to_bibliography' => 0,
797
      'sort_elements' => NO_SORT,
798
      'glue' => '',
799
      'element_tag' => 'div'
800
    ),
801
    UUID_CITATION => array(
802
      'as_list' => 'div',
803
      'link_to_reference' => 0,
804
      'link_to_name_used_in_source' => 0,
805
      'sources_as_content' => 1,
806
      'sources_as_content_to_bibliography' => 0,
807
      'sort_elements' => SORT_ASC,
808
      'glue' => '',
809
      'element_tag' => 'div'
810
    ),
811
    UUID_CHROMOSOMES_NUMBERS => array(
812
      'as_list' => 'ul',
813
      'link_to_reference' => 1,
814
      'link_to_name_used_in_source' => 1,
815
      'sources_as_content' => 1,
816
      'sources_as_content_to_bibliography' => 0,
817
      'sort_elements' => NO_SORT,
818
      'glue' => '',
819
      'element_tag' => 'div'
820
    ),
821
    UUID_CHROMOSOMES => array(
822
      'as_list' => 'ul',
823
      'link_to_reference' => 0,
824
      'link_to_name_used_in_source' => 1,
825
      'sources_as_content' => 1,
826
      'sources_as_content_to_bibliography' => 0,
827
      'sort_elements' => NO_SORT,
828
      'glue' => '',
829
      'element_tag' => 'div'
830
    ),
831
    UUID_COMMON_NAME => array(
832
      'as_list' => 'div',
833
      'link_to_reference' => 0,
834
      'link_to_name_used_in_source' => 1,
835
      'sources_as_content' => 0,
836
      'sources_as_content_to_bibliography' => 0,
837
      'sort_elements' => NO_SORT,
838
      'glue' => '',
839
      'element_tag' => 'span'
840
    ),
841
  );
842

    
843
  $palmweb_default = array(
844
    'DEFAULT' => array(
845
      'as_list' => 'ul',
846
      'link_to_reference' => 1,
847
      'link_to_name_used_in_source' => 1,
848
      'sources_as_content' => 1,
849
      'sources_as_content_to_bibliography' => 1,
850
      'sort_elements' => NO_SORT,
851
      'glue' => '',
852
      'element_tag' => NULL
853
    ),
854
    UUID_CITATION => array(
855
      'as_list' => 'ul',
856
      'link_to_reference' => 1,
857
      'link_to_name_used_in_source' => 1,
858
      'sources_as_content' => 0,
859
      'sources_as_content_to_bibliography' => 1,
860
      'sort_elements' => SORT_ASC,
861
      'glue' => '',
862
      'element_tag' => 'div'
863
    ),
864
    UUID_DISTRIBUTION => array(
865
      'as_list' => 'div', // currently ignored
866
      'link_to_reference' => 1,
867
      'link_to_name_used_in_source' => 1,
868
      'sources_as_content' => 1, // FIXME seems to have no effect see Acanthophoenix rousselii (palmae)
869
      'sources_as_content_to_bibliography' => 1,
870
      'sort_elements' => NO_SORT, // will cause ...
871
      'glue' => ', ',
872
      'element_tag' => 'span',
873
      'special' => array()
874
    ),
875
  );
876

    
877
  $cyprus_default = $cichorieae_default;
878
  $cyprus_default[UUID_DISTRIBUTION] = array(
879
    'as_list' => 'div', // currently ignored
880
    'link_to_reference' => 0,
881
    'link_to_name_used_in_source' => 0,
882
    'sources_as_content' => 0,
883
    'sources_as_content_to_bibliography' => 0,
884
    'sort_elements' => NO_SORT, // will cause ...
885
    'glue' => ' ',
886
    'element_tag' => 'div',
887
    'special' => array()
888
  );
889

    
890
  $default_theme = variable_get('theme_default', NULL);
891

    
892
  switch ($default_theme) {
893
    case 'garland_cichorieae':
894
      $settings_for_theme = $cichorieae_default;
895
      break;
896
    case 'cyprus':
897
      // cyprus: no longer used in production,
898
      // but is required for selenium tests see class eu.etaxonomy.dataportal.pages.PortalPage
899
      $settings_for_theme = $cyprus_default;
900
      break;
901
    case 'flore_afrique_centrale':
902
    case 'flora_malesiana':
903
    case 'flore_gabon':
904
      $settings_for_theme = $cichorieae_default;
905
      $settings_for_theme[UUID_CITATION]['as_list'] = 'ul';
906
      break;
907
    case 'palmweb_2':
908
      $settings_for_theme = $palmweb_default;
909
      break;
910
    default:
911
      $settings_for_theme = $other_themes_default;
912
  }
913
  // add pseudo feature settings
914
  $settings_for_theme['BIBLIOGRAPHY'] = $default['BIBLIOGRAPHY'];
915

    
916
  // ---- END of DEFAULTS
917

    
918
  $saved_settings = variable_get(FEATURE_BLOCK_SETTINGS, NULL);
919

    
920
  $feature_block_setting = null;
921

    
922
  if (isset($saved_settings[$feature_uuid])) {
923
    $feature_block_setting = $saved_settings[$feature_uuid];
924
  }
925
  else if (isset($settings_for_theme[$feature_uuid])) {
926
    $feature_block_setting = $settings_for_theme[$feature_uuid];
927
  }
928
  else if (isset($settings_for_theme['DEFAULT'])) {
929
    $feature_block_setting = $settings_for_theme['DEFAULT'];
930
  }
931

    
932
  // now merge the default and specific settings
933
  $settings_to_merge = array($default['DEFAULT']);
934
  if(is_array($saved_settings)){
935
    $settings_to_merge[] = $saved_settings['DEFAULT'];
936
  }
937
  if(isset($feature_block_setting)){
938
    $settings_to_merge[] = $feature_block_setting;
939
  }
940
  $feature_block_setting = drupal_array_merge_deep_array($settings_to_merge);
941

    
942
  return $feature_block_setting;
943
}
944

    
945
/**
946
 * returns the current setting for the original source bibliography
947
 *
948
 * Caches internally
949
 *
950
 * @return array
951
 *  the setting for the original source bibliography see BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE:
952
 *   - 'enabled': 1|0
953
 *   - 'key_format': one of 'latin', 'ROMAN', 'roman', 'ALPHA', 'alpha'
954
 */
955
function get_bibliography_settings($clear_cache = false){
956
  static $bibliography_settings = null;
957
  if(!$bibliography_settings || $clear_cache){
958
    $bibliography_settings = get_array_variable_merged(
959
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE,
960
      BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE_DEFAULT
961
    );
962
  }
963
  return $bibliography_settings;
964
}
965

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

    
1001
  $items['admin/config/cdm_dataportal/settings/cachesite'] = array(
1002
    'title' => 'Cache',
1003
    'description' => 'Cache',
1004
    'access arguments' => array('administer cdm_dataportal'),
1005
    'page callback' => 'drupal_get_form',
1006
    'page arguments' => array('cdm_settings_cache'),
1007
    'weight' => 10,
1008
    'type' => MENU_LOCAL_TASK,
1009
  );
1010

    
1011
  $items['admin/config/cdm_dataportal/settings/geo'] = array(
1012
    'title' => 'Geo & Map',
1013
    'description' => 'Geo & Map',
1014
    'access arguments' => array('administer cdm_dataportal'),
1015
    'page callback' => 'drupal_get_form',
1016
    'page arguments' => array('cdm_settings_geo'),
1017
    'weight' => 1,
1018
    'type' => MENU_LOCAL_TASK,
1019
  );
1020

    
1021
  $items['admin/config/cdm_dataportal/settings/layout'] = array(
1022
    'title' => 'Layout',
1023
    'description' => 'Configure and adjust the layout of your DataPortal ',
1024
    'access arguments' => array('administer cdm_dataportal'),
1025
    'page callback' => 'drupal_get_form',
1026
    'page arguments' => array('cdm_settings_layout'),
1027
    'weight' => 2,
1028
    'type' => MENU_LOCAL_TASK,
1029
  );
1030

    
1031
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1032
    'title' => 'Taxon',
1033
    'description' => 'Configure and adjust the layout of your DataPortal ',
1034
    'access arguments' => array('administer cdm_dataportal'),
1035
    'page callback' => 'drupal_get_form',
1036
    'page arguments' => array('cdm_settings_layout_taxon'),
1037
    'weight' => 1,
1038
    'type' => MENU_LOCAL_TASK,
1039
  );
1040
  /*
1041
  $items[] = array(
1042
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1043
  'title' => t('Synonymy'),
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_synonymy'),
1048
  'weight' => 1,
1049
  'type' => MENU_LOCAL_TASK,
1050
  );
1051

    
1052
  $items[] = array(
1053
  'path' => 'admin/config/cdm_dataportal/layout/specimens',
1054
  'title' => t('Specimens'),
1055
  'description' => t('Configure and adjust the layout of your DataPortal '),
1056
  'access' => user_access('administer cdm_dataportal'),
1057
  'callback' => 'drupal_get_form',
1058
  'callback arguments' => array('cdm_settings_layout_specimens'),
1059
  'weight' => 1,
1060
  'type' => MENU_LOCAL_TASK,
1061
  );
1062
  */
1063
  $items['admin/config/cdm_dataportal/settings/layout/search'] = array(
1064
    'title' => 'Search',
1065
    'description' => 'Configure and adjust the layout of your DataPortal ',
1066
    'access arguments' => array('administer cdm_dataportal'),
1067
    'page callback' => 'drupal_get_form',
1068
    'page arguments' => array('cdm_settings_layout_search'),
1069
    'weight' => 2,
1070
    'type' => MENU_LOCAL_TASK,
1071
  );
1072

    
1073
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1074
    'title' => 'Media',
1075
    'description' => 'Configure and adjust the layout of your DataPortal ',
1076
    'access arguments' => array('administer cdm_dataportal'),
1077
    'page callback' => 'drupal_get_form',
1078
    'page arguments' => array('cdm_settings_layout_media'),
1079
    'weight' => 3,
1080
    'type' => MENU_LOCAL_TASK,
1081
  );
1082

    
1083
}
1084

    
1085
/**
1086
 * @todo document this function.
1087
 */
1088
function cdm_help_general_cache() {
1089
  $form = array();
1090
  $form['cache_help'] = array(
1091
    '#type' => 'fieldset',
1092
    '#title' => t('Help'),
1093
    '#collapsible' => TRUE,
1094
    '#collapsed' => TRUE,
1095
  );
1096
  $form['cache_help']['test'] = array('#value' => t('probando'));
1097
  return drupal_render($form);
1098
  $res = array();
1099
  $res['default'] = drupal_render($help);
1100
  return $res;
1101
}
1102

    
1103
/**
1104
 * Configures the settings form for the CDM-API module.
1105
 *
1106
 * @return array
1107
 *   Drupal settings form.
1108
 */
1109
function cdm_settings_general() {
1110

    
1111
  $form['cdm_webservice'] = array(
1112
    '#type' => 'fieldset',
1113
    '#title' => t('CDM Server'),
1114
    '#collapsible' => FALSE,
1115
    '#collapsed' => FALSE,
1116
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
1117
        CDM data base to the web via RESTful web services and thus is the source of the data
1118
        to be displayed by a CDM DataPotal.'),
1119
  );
1120

    
1121
  $form['cdm_webservice']['cdm_webservice_url'] = array(
1122
    '#type' => 'textfield',
1123
    '#title' => t('CDM web service URL') . ':',
1124
    '#description' => t('This is the URL to the CDM-Server exposing your data
1125
      e.g. <em>"http://myserver.net/cdmserver/myproject"</em>'),
1126
    '#default_value' => variable_get('cdm_webservice_url', NULL),
1127
  );
1128

    
1129
  $form['cdm_webservice']['cdm_webservice_debug'] = array(
1130
    '#type' => 'markup',
1131
    '#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')
1132
      . ' visible only for administrators',
1133
  );
1134

    
1135
  $form['cdm_webservice']['freetext_index'] = array(
1136
    '#type' => 'fieldset',
1137
    '#title' => t('Freetext index'),
1138
    '#collapsible' => FALSE,
1139
    '#collapsed' => FALSE,
1140
  );
1141

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

    
1156
  $frontentURL = urlencode(variable_get('cdm_webservice_url', ''));
1157
  $trigger_link_options = array(
1158
    'attributes' => array(
1159
      'class' => 'index-trigger'
1160
    ),
1161
  );
1162
  $form['cdm_webservice']['freetext_index']['operations'] = array(
1163
    '#markup' => "<div>" . t('Operations: !url1 !url2', array(
1164
        '!url1' => l(t("Purge"), cdm_compose_url(CDM_WS_MANAGE_PURGE, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1165
        '!url2' => l(t("Reindex"), cdm_compose_url(CDM_WS_MANAGE_REINDEX, NULL, 'frontendBaseUrl=' . $frontentURL), $trigger_link_options),
1166
      ))
1167
    . '<div id="index-progress"></div></div>',
1168
  );
1169

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

    
1195
  $form['cdm_webservice']['proxy'] = array(
1196
    '#type' => 'fieldset',
1197
    '#title' => t('Proxy'),
1198
    '#collapsible' => TRUE,
1199
    '#collapsed' => TRUE,
1200
  );
1201

    
1202
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
1203
    '#type' => 'textfield',
1204
    '#title' => t('Proxy URL') . ':',
1205
    '#description' => t('If this proxy url is set the cdm api tries
1206
    to connect the web service over the given proxy server.
1207
    Otherwise proxy usage is deactivated.'),
1208
    '#default_value' => variable_get('cdm_webservice_proxy_url', FALSE),
1209
  );
1210

    
1211
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
1212
    '#type' => 'textfield',
1213
    '#title' => t('Proxy port') . ':',
1214
    '#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
1215
  );
1216

    
1217
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
1218
    '#type' => 'textfield',
1219
    '#title' => t('Login') . ':',
1220
    '#default_value' => variable_get('cdm_webservice_proxy_usr', FALSE),
1221
  );
1222

    
1223
  $form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
1224
    '#type' => 'textfield',
1225
    '#title' => t('Password') . ':',
1226
    '#default_value' => variable_get('cdm_webservice_proxy_pwd', FALSE),
1227
  );
1228

    
1229
  $form['sub_tree_filter'] = array(
1230
    '#type' => 'fieldset',
1231
    '#title' => t('Subtree filter'),
1232
    '#collapsible' => FALSE,
1233
    '#collapsed' => TRUE,
1234
    '#description' => t('The Data Portal can be restricted to the taxa which belong to a specific classification subtree. Other taxa will not be shown or accessible otherwise.'),
1235
  );
1236

    
1237
  $sub_tree_filter_uuid_value = variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE);
1238
  $taxon_node_info = '';
1239
  if($sub_tree_filter_uuid_value){
1240
    $taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE, array($sub_tree_filter_uuid_value));
1241
    if($taxon_node_dto){
1242
      $taxon_node_info = " Current taxon node: <strong>" . cdm_tagged_text_to_markup($taxon_node_dto->taggedTitle) . " [" . $taxon_node_dto->treeIndex . "]</strong>";
1243
    }
1244
  }
1245
  $form['sub_tree_filter'][CDM_SUB_TREE_FILTER_UUID] = array(
1246
    '#type' => 'textfield',
1247
    '#title' => t('Taxon Node UUID') . ':',
1248
    '#default_value' => variable_get(CDM_SUB_TREE_FILTER_UUID, FALSE),
1249
    '#description' => "The uuid of the TaxonNode entity to be used as filter." . $taxon_node_info
1250
  );
1251

    
1252
  // TODO: settings are still incomplete, compare with
1253
  // trunk/dataportal/inc/config_default.php.inc.
1254
  $form['taxon_tree'] = array(
1255
    '#type' => 'fieldset',
1256
    '#title' => t('Taxon Tree'),
1257
    '#collapsible' => FALSE,
1258
    '#collapsed' => TRUE,
1259
    '#description' => t('<p>When you explore your collection, you can navigate
1260
      it through a tree structure also called <em>Taxon Tree</em>.</p><p>To be
1261
      able to navigate through your collection the
1262
      <a href="http://drupal.org/handbook/blocks">drupal block</a>
1263
      <em>CDM Taxon Tree</em> should be visible for users. Enable the block at
1264
      <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks
1265
      </a></p>'),
1266
  );
1267

    
1268
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
1269
    '#type' => 'select',
1270
    '#title' => t('Default classification') . ':',
1271
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
1272
    '#options' => cdm_get_taxontrees_as_options(),
1273
    '#description' => t('The default taxa classification to be used in the whole portal. 
1274
      This affects most obviously the classification browser and the search in case is is restricted 
1275
      to a specific classification. See also <i>Included Classifications</i> below.'),
1276
  );
1277

    
1278
  $form['taxon_tree'][TAXONTREE_RANKLIMIT] = array(
1279
    '#type' => 'select',
1280
    '#title' => t('Rank of highest displayed taxon') . ':',
1281
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
1282
    '#default_value' => variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT),
1283
    '#options' => cdm_vocabulary_as_option(UUID_RANK, null, true),
1284
    '#description' => t('This is the rank of the highest displayed taxon in the
1285
      <em>taxon tree</em>. You can select here which rank should be at the top
1286
      level of the tree structure.'),
1287
  );
1288

    
1289
  $classification_uuids = array_keys(cdm_get_taxontrees_as_options());
1290
  $taxontree_includes_default = array_combine($classification_uuids, $classification_uuids);
1291
  $form['taxon_tree'][CDM_TAXONTREE_INCLUDES] = array(
1292
      '#type' => 'checkboxes',
1293
      '#title' => t('Included Classifications') . ':',
1294
      '#default_value' => variable_get(CDM_TAXONTREE_INCLUDES, $taxontree_includes_default),
1295
      '#options' => cdm_get_taxontrees_as_options(),
1296
      '#description' => t('Only the checked classifications will be available in the classification chooser.'),
1297
  );
1298

    
1299
  $form['distribution'] = array(
1300
      '#type' => 'fieldset',
1301
      '#title' => t('Distributions'),
1302
      '#collapsible' => FALSE,
1303
      '#description' => 'This section covers general settings regarding distributions, map related settings are found in the '
1304
          . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
1305
          '. Further settings regarding the Distribution feature block can be found in the Layout/Taxon tab at two distinct places: '
1306
          . l('Distribution appearance', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-distribution-layout')) .', '
1307
          . l('Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon', array('fragment' => 'edit-feature-block-settings')) .
1308
          '<p>
1309
          </p>',
1310
  );
1311

    
1312
  $form['distribution'][CDM_DISTRIBUTION_FILTER] = array(
1313
      '#type' => 'fieldset',
1314
      '#title' => 'Distribution filter',
1315
      '#collapsible' => FALSE,
1316
      '#collapsed' => FALSE,
1317
      '#tree' => TRUE,
1318
      '#description' => 'The Distribution filter offers the following options
1319
      <ul>
1320
      <li><strong>Status order preference rule:</strong> In case of multiple distribution status (PresenceAbsenceTermBase) for
1321
        the same area the status with the highest order is preferred, see OrderedTermBase.compareTo(OrderedTermBase).</li>
1322
      <li><strong>Sub area preference rule:</strong>If there is an area with a direct sub area and both areas have the same
1323
        computed status only the information on the sub area should be reported, whereas the super area should be ignored.</li>
1324
      <li><strong>Marked area filter:</strong>Skip distributions for areas having a TRUE Marker with one of the specified MarkerTypes.
1325
        Existing sub-areas of a marked area must also be marked with the same marker type, otherwise the marked
1326
        area acts as a fallback area for the sub areas. An area is a <em>fallback area</em> if it is marked to
1327
        be hidden and if it has at least one of sub area which is not marked to be hidden. The <em>fallback area</em>
1328
        will be show if there is no Distribution for any of the non hidden sub-areas. For more detailed discussion on
1329
        <em>fallback area</em> see https://dev.e-taxonomy.eu/trac/ticket/4408.</li>
1330
      </ul>'
1331
  );
1332

    
1333
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
1334
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['filter_rules'] = array(
1335
      '#type' => 'checkboxes',
1336
      '#title' => 'Filter rules',
1337
      '#default_value' => $cdm_distribution_filter['filter_rules'],
1338
      '#options' => array(
1339
          'statusOrderPreference' => 'Status order preference rule',
1340
          'subAreaPreference' => 'Sub area preference rule'
1341
      ),
1342
  );
1343

    
1344
  $marker_type_options = cdm_terms_by_type_as_option('MarkerType');
1345
  $form['distribution'][CDM_DISTRIBUTION_FILTER]['hiddenAreaMarkerType'] = array(
1346
      '#type' => 'checkboxes',
1347
      '#title' => 'Hide marked area filter',
1348
      '#default_value' => $cdm_distribution_filter['hiddenAreaMarkerType'],
1349
      '#options' => $marker_type_options,
1350
      '#description' => 'Check one or more MarkerTypes to define the "hide marked area" filter .',
1351
  );
1352

    
1353
  $form['aggregation'] = array(
1354
      '#type' => 'fieldset',
1355
      '#title' => t('Aggregation of data'),
1356
      '#collapsible' => FALSE,
1357
      '#description' => 'This section covers the different aspects of aggregating information.
1358
          <p>
1359
          </p>',
1360
  );
1361

    
1362
  $form['aggregation'][CDM_TAXON_MEDIA_FILTER] = array(
1363
      '#type' => 'checkboxes',
1364
      '#title' => 'Taxon media filter',
1365
      '#default_value' => variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT)),
1366
      '#options' => array(
1367
          'includeTaxonDescriptions' => 'Media in taxon descriptions',
1368
          'includeTaxonNameDescriptions' => 'Media in name descriptions',
1369
          'includeOccurrences' => 'Media related to specimens and occurrences',
1370
      ),
1371
      '#description' => 'This filter configures which images should be taken into account.',
1372
  );
1373

    
1374
  $form['aggregation']['notice'] = array(
1375
      '#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
1376
          want to make use of the caching capabilities of the dataportal.',
1377
  );
1378

    
1379
  $form['aggregation']['media_aggregation'] = array(
1380
      '#type' => 'fieldset',
1381
      '#title' => t('Media aggregation'),
1382
      '#collapsible' => FALSE,
1383
      '#collapsed' => TRUE,
1384
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
1385

    
1386
  );
1387
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
1388
      '#type' => 'select',
1389
      '#title' => t('Aggregation of taxon pictures') . ':',
1390
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
1391
      '#options' => array(
1392
          0 => "Show only pictures of the current taxon",
1393
          1 => "Include pictures of taxonomic children",
1394
      ),
1395
      '#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."),
1396
  );
1397

    
1398
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
1399
      '#type' => 'fieldset',
1400
      '#attributes' => array('class' => array('clearfix')),
1401
      '#title' => t('Aggregation via taxon relationsships'),
1402
      '#collapsible' => TRUE,
1403
      '#collapsed' => TRUE,
1404
      '#tree' => TRUE,
1405
      '#description' => t('Information on taxa will be aggregated along the below chosen
1406
          taxon relation ships. This will affect images and occurrences (specimens).
1407
          Taxon relation ships are directed and point form one taxon to another. The taxon
1408
          relationships to be taken into accunt can therefore configured for the direct direction
1409
          and for the inverse.'),
1410
  );
1411

    
1412
  $taxonRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
1413
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1414

    
1415
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
1416
      '#type' => 'checkboxes',
1417
      '#title' => t('Direct'),
1418
      '#options' => $taxonRelationshipTypeOptions,
1419
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
1420
  );
1421
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
1422
      '#type' => 'checkboxes',
1423
      '#title' => t('Invers'),
1424
      '#options' => $taxonRelationshipTypeOptions,
1425
      '#default_value' => $aggregate_by_taxon_relationships['invers'],
1426
  );
1427

    
1428
  $form['drupal_integration'] = array(
1429
    '#type' => 'fieldset',
1430
    '#attributes' => array('class'=> array('clearfix')),
1431
    '#title' => t('Drupal integration'),
1432
    '#collapsible' => FALSE,
1433
    '#collapsed' => FALSE,
1434
    '#tree' => FALSE
1435
  );
1436

    
1437
  $form['drupal_integration'][CDM_DRUPAL_NODE_CREATION] = array(
1438
    '#type' => 'checkbox',
1439
    '#title' => 'Create drupal nodes',
1440
    '#default_value' => variable_get(CDM_DRUPAL_NODE_CREATION, FALSE),
1441
    '#description' => 'Content für cdm_dataportal pages is directly retrieved from the 
1442
    CDM webservice configured above. In order to use other drupal modules like the "Comments" module together with the 
1443
    cdm pages it is required that drupal nodes are created and stored in the database.'
1444
  );
1445

    
1446

    
1447

    
1448
  $form['drupal_integration']['drop_all_cdm_nodes_warning_pre'] = array(
1449
    '#markup' => '<h6 style="color:red;">WARNING:</h6>
1450
    <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>',
1451
  );
1452
  $form['drupal_integration']['drop_all_cdm_nodes'] = array(
1453
    '#type' => 'submit',
1454
    '#value' => t('Drop all cdm nodes'),
1455
    '#submit' => array('drop_all_cdm_nodes_submit')
1456
  );
1457

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

    
1462
    // ----------------------
1463
  $form['cdm_js_devel_mode'] = array(
1464
      '#type' => 'checkbox',
1465
      '#title' => 'Java-script developer mode',
1466
      '#default_value' => variable_get('cdm_js_devel_mode', FALSE),
1467
      '#description' => 'In production envirionments the java script libraries
1468
      the cdm_dataportal is making use of are compressed and optimized. This
1469
      is good for performance but a caveat if you need to debug java-script. When the
1470
      java-script developer mode is enabled the uncompressed and commented developer
1471
      versions of java-script libraries will be used where possible.
1472
      <br/><strong>Do not use this option in production!</strong>'
1473
  );
1474
  // ----------------------
1475
  $form['cdm_debug_mode'] = array(
1476
      '#type' => 'checkbox',
1477
      '#title' => 'CDM page debug mode',
1478
      '#default_value' => variable_get('cdm_debug_mode', FALSE),
1479
      '#description' => 'When CDM page debug mode enabled the start and end of cdm entity page
1480
      creation is logged as well as any http request send via the cdm_api. The log is written to a file in the temporary
1481
      folder configured in the' . l('File system settings', 'admin/config/media/file-system') .
1482
       '. For this site the file is <code> ' . file_directory_temp() . '/drupal_debug.txt</code>
1483
      The log is written by the drupal devel module function <code>dd()</code>.
1484
      <br/><strong>Note:</strong> The start and end of the page creation is currently only logged for taxon pages only.'
1485
  );
1486

    
1487
  // Comment @WA: D7 form api does not support reset buttons,
1488
  // so to mimic the D5 reset button we add one like this.
1489
  $form['actions']['reset'] = array(
1490
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1491
    '#weight' => 1000,
1492
  );
1493

    
1494
  $form['#submit'][] = 'cdm_settings_general_submit';
1495

    
1496
  return system_settings_form($form);
1497
}
1498

    
1499
/**
1500
 * Submit callback; drops all cdm nodes.
1501
 *
1502
 * @ingroup forms
1503
 */
1504
function drop_all_cdm_nodes_submit($form, &$form_state) {
1505
  cdm_delete_all_cdm_nodes();
1506
  drupal_set_message(t('All cdm nodes dropped.'));
1507
}
1508

    
1509

    
1510
/**
1511
 * LAYOUT settings
1512
 * @return
1513
 *   todo
1514
 */
1515
function cdm_settings_layout() {
1516

    
1517
  $form = array();
1518

    
1519
  $form['about'] = array(
1520
    '#markup' => '<h4>' . t('Portal Layout') . '</h4><p>' . t('This settings contains the general configurations
1521
      layout. If you want to configure the specific sites layout visit the
1522
      respective configuration site for taxon, search or media.') . '</p>',
1523
  );
1524

    
1525
  // ---- footnotes --- //
1526
  $form['footnotes'] = array(
1527
    '#type' => 'fieldset',
1528
    '#title' => t('Footnotes'),
1529
    '#collapsible' => FALSE,
1530
    '#collapsed' => FALSE,
1531
    '#description' => t('Taxa data such authors, synonyms names, descriptions,
1532
      media or distribution areas may have annotations or footnotes. When the
1533
      footnotes are enabled they will be visible (if they exist).'),
1534
  );
1535

    
1536
  $form['footnotes']['cdm_dataportal_all_footnotes'] = array(
1537
    '#type' => 'checkbox',
1538
    '#title' => t('Do not show footnotes'),
1539
    '#default_value' => variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES),
1540
    '#description' => t('Check this if you do not want to show any footnotes'),
1541
  );
1542

    
1543
  $form['footnotes']['cdm_dataportal_annotations_footnotes'] = array(
1544
    '#type' => 'checkbox',
1545
    '#title' => t('Do not show annotation footnotes'),
1546
    '#default_value' => variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ANNOTATIONS_FOOTNOTES),
1547
    '#description' => t('Check this if you do not want to show annotation footnotes'),
1548
  );
1549

    
1550
  $form['annotations'] = array(
1551
    '#type' => 'fieldset',
1552
    '#title' => t('Annotations'),
1553
    '#collapsible' => FALSE,
1554
    '#collapsed' => FALSE,
1555
    '#description' => t('This sections allows configuring global settings regarding annotations and thus will affect annotations dispayed as footnote and others.'),
1556
  );
1557

    
1558
  $annotationTypeOptions = cdm_terms_by_type_as_option('AnnotationType');
1559
  // Additional option for the NULL case.
1560
  $annotationTypeOptions['NULL_VALUE'] = t('untyped');
1561
  $annotationsTypesAsFootnotes = variable_get(ANNOTATION_TYPES_VISIBLE, unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT));
1562
  $form['annotations'][ANNOTATION_TYPES_VISIBLE] = array(
1563
    '#type' => 'checkboxes',
1564
    '#title' => t('Visbility of annotation types'),
1565
    '#description' => t("Only annotations of the selected type will be displayed. You may want to turn 'technical annotations' off."),
1566
    '#options' => $annotationTypeOptions,
1567
    '#default_value' => $annotationsTypesAsFootnotes
1568
  );
1569

    
1570

    
1571
  // ---- original source --- //
1572
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE] = array(
1573
      '#type' => 'fieldset',
1574
      '#tree' => TRUE,
1575
      '#title' => t('Source Citations'),
1576
      '#collapsible' => FALSE,
1577
      '#collapsed' => FALSE,
1578
  );
1579

    
1580
  $bibliography_settings = get_bibliography_settings(true);
1581

    
1582
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1583
      '#type' => 'checkbox',
1584
      '#title' => t('Original Source in bibliography'),
1585
      '#default_value' => $bibliography_settings['enabled'],
1586
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1587
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1588
       into the bibliography also depends on the settings in the ' .
1589
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1590
        '. 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.'),
1591
  );
1592

    
1593
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['key_format'] = array(
1594
    '#type' => 'select',
1595
    '#title' => t('The format of the key numerals'),
1596
    '#default_value' => $bibliography_settings['key_format'],
1597
    '#options' => array('latin' => 'Latin',
1598
      'ROMAN' => 'Roman (upper case)',
1599
      'roman' => 'Roman (lower case)',
1600
      'ALPHA'=> 'Alphabet (upper case)',
1601
      'alpha' => 'Alphabet (lower case)')
1602
  );
1603

    
1604
  // --- Advanced Search --- //
1605
  $form['asearch'] = array(
1606
      '#type' => 'fieldset',
1607
      '#title' => t('Advanced search'),
1608
      '#collapsible' => FALSE,
1609
      '#collapsed' => FALSE,
1610
  );
1611
  $form['asearch']['cdm_dataportal_show_advanced_search'] = array(
1612
      '#type' => 'checkbox',
1613
      '#title' => t('Show advanced search link'),
1614
      '#default_value' => variable_get('cdm_dataportal_show_advanced_search', 1),
1615
      '#description' => t('Check this box if the link to advanced search should be show below the search box.'),
1616
  );
1617

    
1618
  // --- Registrations --- //
1619
  $form['registrations'] = array(
1620
    '#type' => 'fieldset',
1621
    '#title' => t('Registrations'),
1622
    '#collapsible' => FALSE,
1623
    '#collapsed' => FALSE,
1624
  );
1625
  $form['registrations']['cdm_registration_presistent_identifier_as_link'] = array(
1626
    '#type' => 'checkbox',
1627
    '#title' => t('Use the persistent http identifier as link'),
1628
    '#default_value' => variable_get('cdm_registration_presistent_identifier_as_link', 0),
1629
    '#description' => t('Switch the portal from using the drupal path <code>registration/{url encoded persistent http identifier}</code> to using the persistent http identifier directly as link.'),
1630
  );
1631

    
1632
  // ---- Taxon Name Rendering --- //
1633
  $form['taxon_name'] = array(
1634
      '#type' => 'fieldset',
1635
      '#title' => t('Taxon name display'),
1636
      '#collapsible' => TRUE,
1637
      '#collapsed' => TRUE,
1638
      '#description' => t('The display of taxon names is configured by two parts.
1639
          The <srong>name render templates</strong> define the parts of the name to be displayed in the different areas of the data portal pages.
1640
          The name parts are defined in the <stong>part definitions</strong>'),
1641
  );
1642

    
1643
  $default_part_definitions = unserialize(CDM_PART_DEFINITIONS_DEFAULT);
1644
  $default_part_definitions_pre_380_json = json_encode(unserialize(CDM_PART_DEFINITIONS_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1645
  $default_part_definition_json = json_encode($default_part_definitions, JSON_PRETTY_PRINT);
1646
  $current_part_definition_json = json_encode(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions), JSON_PRETTY_PRINT);
1647

    
1648
  $is_custom_part_definition = $default_part_definition_json != $current_part_definition_json;
1649
  if($default_part_definitions_pre_380_json == $current_part_definition_json){
1650
    $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.)';
1651
  } else if($is_custom_part_definition){
1652
      $which_version_message = '(This are custom part definitions, clearing the text area and and submitting the form will reset it to the default)';
1653
  } else  {
1654
    $which_version_message = '(These are the default part definition.)';
1655
  }
1656

    
1657
  $diff_viewer_markup = '';
1658
  if($is_custom_part_definition){
1659
    $diff_viewer_markup = diff_viewer($default_part_definition_json, $current_part_definition_json);
1660
  }
1661

    
1662
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1663
    . $which_version_message
1664
    . '</div>'
1665
    . $diff_viewer_markup;
1666

    
1667
  $form['taxon_name'][CDM_PART_DEFINITIONS] = array(
1668
      '#type' => 'textarea',
1669
      '#title' => t('Part definitions'),
1670
      '#element_validate' => array('form_element_validate_json'),
1671
      '#default_value' =>  $current_part_definition_json,
1672
      '#description' => '
1673
          <p>' . $which_version_message . '</p>
1674
          <p>
1675
           The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
1676
          </p>
1677
          <p>
1678
           A full taxon name plus additional information can consist of the following elements:
1679
          <ul>
1680
             <li>name: the taxon name inclugin rank nbut without author</li>
1681
             <li>authors:  The authors of a reference, also used in taxon names</li>
1682
             <li>reference: the nomenclatural reference,</li>
1683
             <li>microreference:  Volume, page number etc.</li>
1684
             <li>status:  The nomenclatural status of a name</li>
1685
             <li>description: name descriptions like protologues etc ...</li>
1686
          </ul>
1687
          </p>
1688
          <p>
1689
           These elements are combined in the part definitions array to from the specific parts to be rendered.
1690
           (The taxon name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example in the following)
1691
           The following parts can be formed and are recognized by the system:
1692
          <ul>
1693
            <li>namePart: the name and rank (for example: "Lapsana communis")</li>
1694
            <li>authorshipPart: the author (for example: "L.")</li>
1695
            <li>nameAuthorPart: the combination of name and author part (for example: "Lapsana communis L.").</li>
1696
               This is useful for zoological names where the authorshipPart belongs to the name and both should</li>
1697
               be combined when a link to the taxon is rendered.</li>
1698
            <li>referencePart: the nomencaltural reference (for example: "Sp. Pl. 1753")</li>
1699
          <li>referenceYearPart: the publication year of the nomencaltural reference (for example: "1753")</li>
1700
            <li>microreferencePart: usually the page number (for example ": 811.")</li>
1701
            <li>statusPart: the nomenclatorical status</li>
1702
            <li>descriptionPart: name descriptions like protologues etc ...</li>
1703
          </ul>
1704
          </p>
1705
          <p>
1706
           Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
1707
           specific parts part definitions:
1708
          <ul>
1709
            <li>BotanicalName</li>
1710
            <li>ZoologicalName</li>
1711
            <li>#DEFAULT: covers ViralNames and other NonViralNames
1712
          </ul>
1713
           An example:
1714
          <pre>
1715
           {
1716
            "ZoologicalName": {
1717
              "namePart": {
1718
                "name": true
1719
              },
1720
              "referencePart": {
1721
                "authors": true
1722
              },
1723
              "microreferencePart": {
1724
                "microreference": true
1725
              },
1726
              "statusPart": {
1727
                "status": true
1728
              },
1729
              "descriptionPart": {
1730
                "description": true
1731
              }
1732
            },
1733
            "BotanicalName": {
1734
              "namePart": {
1735
                "name": true,
1736
                "authors": true
1737
              },
1738
              "referencePart": {
1739
                "reference": true,
1740
                "microreference": true
1741
              },
1742
              "secReferencePart": {
1743
                "secReference": true
1744
              },
1745
              "statusPart": {
1746
                "status": true
1747
              },
1748
              "descriptionPart": {
1749
                "description": true
1750
              }
1751
            }
1752
          }
1753
           </pre>',
1754
  );
1755

    
1756
  $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
1757
  $default_render_templates_pre_380_json = json_encode(unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT_PRE_380), JSON_PRETTY_PRINT);
1758
  $default_render_templates_json = json_encode($default_render_templates, JSON_PRETTY_PRINT);
1759
  $current_render_templates_json = json_encode(variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates), JSON_PRETTY_PRINT);
1760
  $is_custom_render_template = $default_render_templates_json != $current_render_templates_json;
1761

    
1762
  if($default_render_templates_pre_380_json == $current_render_templates_json){
1763
    $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.)';
1764
  } else if($is_custom_render_template){
1765
    $which_version_message = '(These are custom render templates, clearing the text area and and submitting the form will reset it to the default)';
1766
  } else {
1767
    $which_version_message = '(These are the default render templates.)';
1768
  }
1769

    
1770
  $diff_viewer_markup = '';
1771
  if($is_custom_render_template){
1772
    $diff_viewer_markup = diff_viewer($default_render_templates_json, $current_render_templates_json);
1773
  }
1774

    
1775
  $which_version_message = '<div style="color:#ff0000; font-weight: bold;">'
1776
    . $which_version_message
1777
    . '</div>'
1778
    . $diff_viewer_markup;
1779

    
1780
  $form['taxon_name'][CDM_NAME_RENDER_TEMPLATES] = array(
1781
      '#type' => 'textarea',
1782
      '#title' => t('Name render templates'),
1783
      '#element_validate' => array('form_element_validate_json'),
1784
      '#default_value' =>  $current_render_templates_json,
1785
      '#description' => '
1786
          <p>' . $which_version_message . '</p>
1787
          <p>
1788
          The render templates array contains one or more name render templates to be used within the page areas identified by the
1789
          render path. The render path of taxon names can be made visible by adding the URI query parameter 
1790
          <strong><code>RENDER_PATH=1</code></strong> to the page request.<br />
1791
          The render path is used as key of the array sub subelements whereas the name render template array is set as value.
1792
          The following render Path keys are currently recognized:
1793
          <ul>
1794
            <li>list_of_taxa</li>
1795
            <li>acceptedFor</li>
1796
            <li>homonym</li>
1797
            <li>taxon_page_synonymy</li>
1798
            <li>typedesignations</li>
1799
            <li>taxon_page_title</li>
1800
            <li>polytomousKey</li>
1801
            <li>na: name + authorship</li>
1802
            <li>nar:name + authorship + reference</li>
1803
            <li>#DEFAULT</li>
1804
          </ul>
1805
          A single render template can be used for multiple render paths. In this case the according key of the render templates
1806
          array element should be a comma separated list of render paths, without any whitespace!.
1807
          </p>
1808
          <p>
1809
          A render template is an associative array. The keys of this array are referring to the keys as defined in the part
1810
          definitions array. See <a href="#edit-cdm-part-definitions">Part definitions</a> above for more information.
1811
          <p>
1812
          The value of the render template element must be set to TRUE in order to let this part being rendered.
1813
          For some parts can <strong>links</strong> can be created which lead to the accoring intity page:</br>
1814
          The <strong>namePart</strong>, <strong>nameAuthorPart</strong>, <strong>referencePart</strong> and <strong>secReferencePart</strong> can also hold an associative array with a single
1815
          element: array(\'#uri\' => TRUE). The value of the #uri element will be replaced by the according
1816
          links if the paramters $nameLink or $refenceLink are given to the name render function
1817
          (this is hard coded and cannot be configured here).',
1818
  );
1819

    
1820
  // @WA: D7 form api does not support reset buttons,
1821
  // so to mimic the D5 reset button we add one like this.
1822
  $form['actions']['reset'] = array(
1823
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
1824
    '#weight' => 1000,
1825
  );
1826

    
1827
  $form['#submit'] = array('submit_json_as_php_array');
1828
  // #json_elements especially defined for submit_json_as_php_array()
1829
  $form['#json_elements'] = array(CDM_NAME_RENDER_TEMPLATES, CDM_PART_DEFINITIONS);
1830
  return system_settings_form($form);
1831
}
1832

    
1833

    
1834
/**
1835
 * @param $form_name
1836
 * @param $form_title
1837
 * @param $collapsed
1838
 * @param string $form_description
1839
 *   The description for the fieldset of the gallery setting.
1840
 * @return mixed
1841
 */
1842
function cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description = '') {
1843
  $form[$form_name] = array(
1844
    '#type' => 'fieldset',
1845
    '#title' => t('@form-title', array('@form-title' => $form_title)),
1846
    '#collapsible' => TRUE,
1847
    '#collapsed' => $collapsed,
1848
    '#tree' => TRUE,
1849
    '#description' => $form_description,
1850
  );
1851

    
1852
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
1853
  $gallery_settings = variable_get($form_name, $default_values);
1854
  // $test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
1855
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1856
    /*
1857
    TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
1858
    $form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
1859
    '#type' => 'textfield',
1860
    '#title' => t('Search Page Size'),
1861
    '#default_value' => $test,
1862
    '#description' => t('Number of Names to display per page in search results.')
1863
    );
1864
    */
1865
    $form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
1866
      '#type' => 'checkbox',
1867
      '#title' => t('Show media thumbnails for accepted taxa'),
1868
      '#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
1869
    );
1870

    
1871
    $form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
1872
      '#type' => 'checkbox',
1873
      '#title' => t('Show media thumbnails for synonyms'),
1874
      '#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
1875
      '#description' => '',
1876
    );
1877
  }
1878

    
1879
  // $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
1880
  $form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
1881
    '#type' => 'checkbox',
1882
    '#title' => t('Show captions under thumbnails'),
1883
    '#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
1884
    '#description' => '',
1885
  );
1886

    
1887
  $form[$form_name]['cdm_dataportal_media_maxextend'] = array(
1888
    '#type' => 'textfield',
1889
    '#title' => t('Thumbnail size (max of width or height)') . ':',
1890
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
1891
    '#description' => t('The maximum extend in either dimension, width or height, in pixels for the thumbnail images in the gallery.'),
1892
  );
1893

    
1894
  $form[$form_name]['cdm_dataportal_media_cols'] = array(
1895
    '#type' => 'textfield',
1896
    '#title' => t('Number of columns') . ':',
1897
    '#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
1898
    '#description' => t('Group the thumbnails in columns: select how many
1899
      columns the gallery should display.'),
1900
  );
1901

    
1902
  if ($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME) {
1903
    $form[$form_name]['cdm_dataportal_media_maxRows'] = array(
1904
      '#type' => 'textfield',
1905
      '#title' => t('Maximum number of rows') . ':',
1906
      '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
1907
      '#description' => t('You can group the thumbnails in rows, select in how
1908
        many rows should be the thumbnails grouped.<br/><strong>Note:</strong>
1909
        If you want an unlimited number of rows please set to 0.'),
1910
    );
1911
  }
1912

    
1913
  return $form;
1914
}
1915

    
1916
/**
1917
 * @todo document this function.
1918
 */
1919
function cdm_settings_layout_taxon() {
1920
  $collapsed = FALSE;
1921
  $form = array();
1922

    
1923
  $form['#submit'][] = 'cdm_settings_layout_taxon_submit';
1924

    
1925
  // --------- TABBED TAXON ------- //
1926
  $form['taxon_tabs'] = array(
1927
    '#type' => 'fieldset',
1928
    '#title' => t('Taxon tabs'),
1929
    '#collapsible' => TRUE,
1930
    '#collapsed' => TRUE,
1931
    '#description' => 'A taxon page consists of various sections, that is content blocks, each displaying a different kind of information.'
1932
  );
1933

    
1934
  $form['taxon_tabs']['cdm_dataportal_taxonpage_tabs'] = array(
1935
    '#type' => 'checkbox',
1936
    '#title' => t('Tabbed taxon page'),
1937
    '#default_value' => variable_get('cdm_dataportal_taxonpage_tabs', 1),
1938
    '#description' => t('If enabled the sections of a taxon page will be displayed as individual tabs'),
1939
  );
1940

    
1941
  $form['taxon_tabs'][CDM_SYNONYMY_AS_TAB] = array(
1942
    '#type' => 'checkbox',
1943
    '#title' => t('Synonymy as tab'),
1944
    '#default_value' => variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT),
1945
    '#description' => t('The synonymy can be moved to its own tab. This is only applicable when the tabbed taxon page option is activated.'),
1946
    '#disabled' =>  variable_get('cdm_dataportal_taxonpage_tabs', 1) !== 1
1947
  );
1948

    
1949
  $form['taxon_tabs']['cdm_taxonpage_tabs_visibility'] = array(
1950
    '#type' => 'checkboxes',
1951
    '#title' => t('Section/Tab visibility') . ':',
1952
    '#default_value' => variable_get('cdm_taxonpage_tabs_visibility', get_taxon_options_list()),
1953
    '#options' => get_taxon_options_list()
1954
  );
1955

    
1956
  // WEIGHT
1957
  $taxon_tabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
1958
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT] = array(
1959
    '#title'  => 'Section/Tab order',
1960
    '#type' => 'fieldset',
1961
    '#collapsible' => false,
1962
    '#tree' => true,
1963
    '#description' => 'The weight value defines the order of the section/tab.'
1964
  );
1965
  // Weights range from -delta to +delta, so delta should be at least half
1966
  // of the amount of tabs present.
1967
  $tab_weight_delta = round(count(get_taxon_tabs_list()) / 2) + 1;
1968
  foreach (get_taxon_tabs_list() as $label) {
1969
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1970
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_WEIGHT][$key] = array(
1971
        '#title' => $label,
1972
        '#type'  => 'weight',
1973
        '#default_value' => $taxon_tabs_weights[$key],
1974
        '#delta' => $tab_weight_delta
1975
    );
1976
  }
1977

    
1978
  $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1979
  $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS] = array(
1980
    '#title'  => 'Section/Tab label override',
1981
    '#type' => 'fieldset',
1982
    '#collapsible' => false,
1983
    '#tree' => true,
1984
    '#description' => 'Setting a label for a section/tab will override the default label. 
1985
      Please enter the label text in the default language of the portal.'
1986
  );
1987
  foreach (get_taxon_tabs_list() as $label) {
1988
    $key = strtolower($label); // turn in to string, since we need to use strings as keys
1989
    $form['taxon_tabs'][CDM_TAXONPAGE_TAB_LABELS][$key] = array(
1990
      '#title' => $label,
1991
      '#type'  => 'textfield',
1992
      '#default_value' => $taxon_tabs_labels[$key]
1993
    );
1994
  }
1995

    
1996
  $form['taxon_tabs']['cdm_dataportal_default_tab'] = array(
1997
    '#type' => 'select',
1998
    '#title' => t('Default tab to display') . ':',
1999
    '#default_value' => variable_get('cdm_dataportal_default_tab', 0),
2000
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
2001
    '#description' => t('<p>Select the default tab to display when visiting a
2002
      taxon page. Only available if Tabbed Taxon Page is enable.</p>
2003
      <strong>Note:</strong> After performing a search and clicking in any
2004
      synonym, the taxon tab to be rendered will be the synonymy of the accepted
2005
      taxon and not the above selected tab.'),
2006
  );
2007

    
2008
  /* ======  TAXON_PROFILE ====== */
2009
  $form['taxon_profile'] = array(
2010
    '#type' => 'fieldset',
2011
    '#title' => t('Taxon profile (tab)'),
2012
    '#description' => t('<p>This section covers the settings related to the taxon
2013
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
2014
    '#collapsible' => TRUE,
2015
    '#collapsed' => TRUE,
2016
  );
2017

    
2018
  // ---- PROFILE PICTURE ----//
2019

    
2020
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE] = array(
2021
    '#type' => 'fieldset',
2022
    '#tree' => TRUE,
2023
    '#title' => t('Taxon profile picture'),
2024
    '#collapsible' => TRUE,
2025
    '#collapsed' => FALSE,
2026
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
2027
  );
2028

    
2029
  //FIXME migrate variables:
2030
  //  cdm_dataportal_show_default_image ---> CDM_TAXON_PROFILE_IMAGE['show']
2031
  // FIXME
2032
  //  enable file module in profile and in update,(a.kohlbecker, 4.9.2014: is this still an open issue?)
2033

    
2034
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
2035

    
2036
  /*
2037
   * 'show' => 1,
2038
   * 'maxextend' => 184,
2039
   * 'media_uri_query' => ''
2040
   * 'custom_placeholder_image_on' => 1,
2041
   * 'custom_placeholder_image_fid' => ''
2042
   */
2043
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['show'] = array(
2044
    '#type' => 'checkbox',
2045
    '#title' => t('Enable profile picture'),
2046
    '#description' => t('Show the profile picture.'),
2047
    '#default_value' => $taxon_profile_image_settings['show'],
2048
  );
2049

    
2050
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['maxextend'] = array(
2051
      '#type' => 'textfield',
2052
      '#tree' => TRUE,
2053
      '#title' => t('Profile picture maximum extend'),
2054
      '#default_value' =>  $taxon_profile_image_settings['maxextend'],
2055
      '#field_suffix' => 'px',
2056
      '#maxlength' => 4,
2057
      '#size' => 4,
2058
      '#description' => t('The maximum extend in either dimension, width or height, of the profile picture in pixels.')
2059
  );
2060

    
2061
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['media_uri_query'] = array(
2062
      '#type' => 'textfield',
2063
      '#tree' => TRUE,
2064
      '#title' => t('Additional URI query parameter'),
2065
      '#default_value' =>  $taxon_profile_image_settings['media_uri_query'],
2066
      '#maxlength' => 1024,
2067
      '#size' => 60,
2068
      '#description' => t('Additional query parameters to be used when requesting for the  
2069
            profile image. E.g.: <code>width=400&height=300&quality=95&format=jpeg</code>.
2070
            The query parameters will be appended to the uri of the media representation part
2071
            as stored in the cdm. The query parameter string must not start with a \'&\' or  \'?\'')
2072
  );
2073

    
2074
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_enabled'] = array(
2075
    '#type' => 'checkbox',
2076
    '#title' => t('Show the placeholder image'),
2077
    '#description' => t("A placeholder image will be shown if no taxon profile picture is available."),
2078
    '#default_value' => $taxon_profile_image_settings['custom_placeholder_enabled']
2079
  );
2080

    
2081
  $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_on'] = array(
2082
      '#type' => 'checkbox',
2083
      '#title' => t('Use a custom placeholder image'),
2084
      '#description' => t("This image is shown as replacement if no image of the taxon is available."),
2085
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_on']
2086
  );
2087

    
2088
  if($taxon_profile_image_settings['custom_placeholder_image_on'] == 1){
2089
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2090
        '#type' => 'managed_file',
2091
        '#title' => t('Custom placeholder image file'),
2092
        '#progress_indicator' => 'bar',
2093
        '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid'],
2094
    //       '#name' => 'custom_placeholder_image',
2095
        '#upload_location' => 'public://' . CDM_TAXON_PROFILE_IMAGE .'/'
2096
    );
2097

    
2098
    if($taxon_profile_image_settings['custom_placeholder_image_fid']){
2099
      $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
2100
      $url = file_create_url($profile_image_file->uri);
2101
      $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['preview'] = array(
2102
                '#type' => 'item',
2103
                '#markup' => '<div class="image-preview"><img src="' . $url . '"/></div>',
2104
      );
2105
    }
2106
  } else {
2107
    $form['taxon_profile'][CDM_TAXON_PROFILE_IMAGE]['custom_placeholder_image_fid'] = array(
2108
      '#type' => 'hidden',
2109
      '#default_value' => $taxon_profile_image_settings['custom_placeholder_image_fid']
2110
    );
2111
  }
2112

    
2113
  $options = cdm_vocabulary_as_option(UUID_RANK, null, true);
2114
  array_unshift($options, '-- DISABLED --');
2115
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
2116
    '#type' => 'select',
2117
    '#title' => t('Hide profile picture for higher ranks') . ':',
2118
    '#default_value' => variable_get('image_hide_rank', '0'),
2119
    '#options' => $options,
2120
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
2121
  );
2122

    
2123
  // -- MEDIA THUMBNAILS -- //
2124
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2125
  $form_title = 'Taxon Profile Images';
2126
  $form_description = '<p>The different sections in the taxon  profile can have images associated with them. These images are displayed in a gallery of thumbnails wich can be configuered here:</p>';
2127
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2128

    
2129
  // ---- FEATURE TREE BLOCKS ---- //
2130
  $form['taxon_profile']['feature_blocks'] = array(
2131
    '#type' => 'fieldset',
2132
    '#title' => t('Feature Blocks'),
2133
    '#collapsible' => TRUE,
2134
    '#collapsed' => FALSE,
2135
    '#description' => t("This section covers settings related to the taxon's
2136
      <em>Feature Tree</em>. The <em>feature tree</em> are the taxon's
2137
      features such as description, distribution, common names"),
2138
  );
2139
  $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2140
  $profile_feature_tree = get_profile_feature_tree();
2141
  $profile_feature_tree_uuid = $profile_feature_tree->uuid;
2142
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2143
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2144
  }
2145
  $form['taxon_profile']['feature_blocks'][CDM_PROFILE_FEATURETREE_UUID] = array(
2146
    '#type' => 'radios',
2147
    '#title' => t('Taxon profile feature tree') . ':',
2148
    '#default_value' => $profile_feature_tree_uuid,
2149
    '#options' =>  $featureTrees['options'],
2150
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2151
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2152
    '#description' => t('The Feature Tree selected here define the feature blocks which are visible in the taxon
2153
      profile page.'
2154
    ),
2155
  );
2156

    
2157
  // ---- FEATURE TREE BLOCKS > LAYOUT PER FEATURE BLOCK ---- //
2158
  $profile_feature_tree = get_profile_feature_tree();
2159

    
2160
  if (isset($profile_feature_tree->root->childNodes)) {
2161

    
2162
    $form_feature_block_layout = array(
2163
      '#type' => 'fieldset',
2164
      '#tree' => true,
2165
      '#title' => t('Taxon profile feature block settings'),
2166
      '#collapsible' => TRUE,
2167
      '#collapsed' => FALSE,
2168
      '#description' => 'This section let\'s you define how each of the feature blocks is displayed.
2169
      A sub form is for each of the features of currently selected feature tree allows to configre each feature block individually.
2170
      The subforms have the following settings in common:<br />
2171
      <h6>List type:</h6><div>Whether the description elements are displayed as list or not. Three different list types are available</div>
2172
      <h6>Link to reference:</h6><div>Render the reference as link, ignored if the element is NOT a DescriptionElementSource</div>
2173
      <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>
2174
      <h6>Sources as content:</h6><div><strong>If enabled:</strong><br />
2175
            <ol>
2176
            <li>If the element is a CDM TextData instance and if the text is not empty the source references will be
2177
                appended in brackets like "text (source references)". If the original source has name in source
2178
                information it will be appended to the citation string,
2179
                like : "(citation-A, as name-in-source-A; citation-B, as name-in-source-B)"</li>
2180
             <li>if the text of the TextData is empty, the original source citations are the only content
2181
                (e.g. use case CITATION) and are not put into brackets. In this case the nameInSource is
2182
                prepended to the citation string like: "name in source: citation"</li>
2183
            </ol>
2184
            <strong>If disabled:</strong><br />
2185
             Original sources are put into the bibliography(=references) pseudo feature block. If the original source
2186
             citations are the only content, the resulting feature block content would only consist of footnotes.
2187
             In this case the display of the respective feature block is suppressed.</div>
2188
      </dl>
2189
      <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
2190
           in the bibliography. For this to work the bibliography must be enabled the <em>' .l(
2191
            'Layout Settings', 'admin/config/cdm_dataportal/settings/layout', array('fragment'=>'edit-bibliography-for-original-source'))
2192
        . '</em></div>
2193
      <h6>Sort elements:</h6><div>Whether and how to sort the elements
2194
           possible values are the constants SORT_ASC, SORT_DESC, NULL,
2195
           some feature types (Distribution) also support: SORT_HIERARCHICAL</div>
2196
      <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>
2197
           possible values are span or div. Developers: The proper inner tag name can be retrieved by the function
2198
           cdm_feature_block_element_tag_name()</div>
2199
       <h6>Element glue:</h6><div>This string is used to concatenate individual items together. The glue is ignored when the items are displayed 
2200
           as list.<b>NOTE:</b>The glue is not yet fully implemented for all features and thus may not work as expected, see '
2201
           . l('#6831', 'https://dev.e-taxonomy.eu/redmine/issues/6831') . '</div>',
2202
    );
2203

    
2204

    
2205
    $feature_list_layout_settings_disabled = FALSE;
2206

    
2207
    // creating helper object to retrieve the default settings
2208
    $featureNode = new stdClass();
2209
    $featureNode->term = new stdClass();
2210
    $featureNode->term->uuid="DEFAULT";
2211
    $featureNode->term->representation_L10n = "Default";
2212
    array_unshift($profile_feature_tree->root->childNodes, $featureNode);
2213

    
2214
    foreach ($profile_feature_tree->root->childNodes as $featureNode) {
2215

    
2216
      if (!$feature_list_layout_settings_disabled && isset($featureNode->term)) {
2217

    
2218
        // $subform_id must not exceed 45 characters, a uuid has 36 characters
2219
        $subform_id = $featureNode->term->uuid;
2220
        $feature_block_setting = get_feature_block_settings($featureNode->term->uuid);
2221

    
2222
//        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
2223

    
2224
        $form_feature_block_layout[$subform_id] = array(
2225
          '#type' => 'fieldset',
2226
          '#tree' => TRUE,
2227
          '#title' => $featureNode->term->representation_L10n,
2228
          '#collapsible' => FALSE,
2229
          '#collapsed' => FALSE,
2230
        );
2231
        if($featureNode->term->uuid == "DEFAULT"){
2232
          $form_feature_block_layout[$subform_id]['#description']='These are the defaults which apply to
2233
          all feature blocks for which no specific settings have been defined. for consistency enabling links for <em>source
2234
          references</em> and <em>names in source</em> is only possible in the defaults';
2235
        }
2236

    
2237
        $form_feature_block_layout[$subform_id]['as_list'] = array(
2238
          '#type' => 'select',
2239
          '#title' => 'List type',
2240
          '#default_value' => $feature_block_setting['as_list'],
2241
          '#options' => array(
2242
            'div' => 'not as list',
2243
            'ul' => 'bullet list',
2244
            'ol' => 'numbered list',
2245
            'dl' => 'definition list'
2246
          ),
2247
        );
2248

    
2249
        if($featureNode->term->uuid == "DEFAULT"){
2250
          $form_feature_block_layout[$subform_id]['link_to_reference'] = array(
2251
            '#type' => 'checkbox',
2252
            '#title' => t('Link to reference'),
2253
            '#default_value' => $feature_block_setting['link_to_reference'],
2254
          );
2255

    
2256
          $form_feature_block_layout[$subform_id]['link_to_name_used_in_source'] = array(
2257
            '#type' => 'checkbox',
2258
            '#title' => 'Link to name used in source',
2259
            '#default_value' => $feature_block_setting['link_to_name_used_in_source'],
2260
          );
2261
        }
2262

    
2263
        $form_feature_block_layout[$subform_id]['sources_as_content'] = array(
2264
          '#type' => 'checkbox',
2265
          '#title' => 'Sources as content',
2266
          '#default_value' => $feature_block_setting['sources_as_content'],
2267
        );
2268

    
2269
        $form_feature_block_layout[$subform_id]['sources_as_content_to_bibliography'] = array(
2270
          '#type' => 'checkbox',
2271
          '#title' => 'Put sources also as content to bibliography',
2272
          '#default_value' => $feature_block_setting['sources_as_content_to_bibliography'],
2273
        );
2274

    
2275
        $form_feature_block_layout[$subform_id]['sort_elements'] = array(
2276
          '#type' => 'select',
2277
          '#title' => t('Sort elements'),
2278
          '#default_value' => $feature_block_setting['sort_elements'],
2279
          '#options' => array(
2280
            NO_SORT => 'No sorting',
2281
            SORT_ASC => 'Ascending',
2282
            SORT_DESC => 'Descending',
2283
            SORT_HIERARCHICAL => 'Hierarchical'
2284
          ),
2285
          '#description' => 'NOT YET FULLY USED! only in preparation (works partially for distributions)
2286
          <dl>
2287
          <dr><dt>No sorting</dt><dd>Sorting undefined</dd></dr>
2288
          <dr><dt>Ascending</dt><dd>Alphabetically in ascending order</dd></dr>
2289
          <dr><dt>Descending</dt><dd>Alphabetically in descending order</dd></dr>
2290
          <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>
2291
          </dl>',
2292
        );
2293

    
2294
        $form_feature_block_layout[$subform_id]['element_tag'] = array(
2295
          '#type' => 'select',
2296
          '#title' => t('Element tag'),
2297
          '#options' => array(
2298
            'span' => 'span',
2299
            'div' => 'div',
2300
            'p' => 'p'
2301
          ),
2302
          '#default_value' => $feature_block_setting['element_tag'],
2303
        );
2304
        $form_feature_block_layout[$subform_id]['glue'] = array(
2305
          '#type' => 'textfield',
2306
          '#title' => t('Element glue'),
2307
          '#default_value' => $feature_block_setting['glue'],
2308
          '#size' => 10
2309
      );
2310

    
2311
      }
2312
      $form['taxon_profile']['feature_blocks'][FEATURE_BLOCK_SETTINGS] = $form_feature_block_layout;
2313
    }
2314
  }
2315

    
2316
  // ---- STRUCTURED DESCRIPTION FEATURE TREE ---- //
2317
  $form['taxon_profile']['structured_description_featuretree'] = array(
2318
    '#type' => 'fieldset',
2319
    '#title' => t('Structured Description Feature Tree'),
2320
    '#collapsible' => TRUE,
2321
    '#collapsed' => FALSE,
2322
  );
2323
  $featureTrees = cdm_get_featureTrees_as_options();
2324
  $profile_feature_tree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2325
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2326
    $profile_feature_tree_uuid = NULL;
2327
  }
2328
  $form['taxon_profile']['structured_description_featuretree'][CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID] = array(
2329
    '#type' => 'radios',
2330
    '#title' => t('Natural language representation of structured descriptions') . ':',
2331
    '#default_value' => $profile_feature_tree_uuid,
2332
    '#options' => $featureTrees['options'],
2333
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2334
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2335
    '#description' => t('Taxon descriptions can be stored in a highly structured
2336
      form. The feature tree selected here will be used to generate textual
2337
      representation in natural language.'
2338
    ),
2339
  );
2340

    
2341

    
2342

    
2343
  // ---- DISTRIBUTION LAYOUT ---- //
2344
  $form['taxon_profile']['distribution_layout'] = array(
2345
    '#title' => t('Distribution'),
2346
    '#collapsible' => TRUE,
2347
    '#collapsed' => FALSE,
2348
    '#type' => 'fieldset',
2349
    '#description' => 'This section covers general settings regarding the textual representation of distributions and the visibility of the map.
2350
        Map settings regarding the geometry, layers, etc are found in the '
2351
      . l('geo & map tab', 'admin/config/cdm_dataportal/settings/geo') .
2352
      '. Further settings regarding the distribution feature block can be found in above in this tab at '
2353
      . l(
2354
        'Taxon profile feature block settings', 'admin/config/cdm_dataportal/settings/layout/taxon',
2355
        array('fragment' => 'edit-feature-block-settings')
2356
      )
2357
      . ' More general settings regrading the filtering of Distributions are found at '
2358
      . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution'))
2359
      . '. (These settings here will be merged in future releases into the feature block settings)',
2360

    
2361
  );
2362

    
2363
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_MAP_VISIBILITY] = _cdm_map_visibility_setting('distribution');
2364

    
2365
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED] = array(
2366
    '#type' => 'checkbox',
2367
    '#title' => t('Condensed distribution'),
2368
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED, 0),
2369
    '#description' => 'This option enables the display of a very compact representation
2370
    of the distribution which includes also information on the status.',
2371
  );
2372

    
2373
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_RECIPE] = array(
2374
    '#type' => 'select',
2375
    '#title' => t('Condensed distribution recipe'),
2376
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_RECIPE, DISTRIBUTION_CONDENSED_RECIPE_DEFAULT),
2377
    '#options' => array('EuroPlusMed' => 'Euro+Med', 'FloraCuba' => 'Flora of Cuba'),
2378
    '#description' => 'Recipe for creating the condensed distribution.',
2379
  );
2380

    
2381
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_CONDENSED_INFO_PATH] = array(
2382
    '#type' => 'textfield',
2383
    '#title' => t('Condensed distribution info path'),
2384
    '#default_value' => variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT),
2385
    '#description' => 'By default the help page ' .l(DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT)
2386
      . ' is used as target for the info link which is shown at the end of the condensed distribution string.',
2387
  );
2388

    
2389

    
2390
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_ORDER_MODE] = array(
2391
    '#type' => 'radios',
2392
    '#title' => t('Display mode') . ':',
2393
    '#default_value' => variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT),
2394
    '#options' => array(
2395
      'FLAT_ALPHA' => t('Flat list'),
2396
      'TREE' => t('Hierarchically ordered'),
2397
    ),
2398
    '#description' => 'Taxon distribution information is displayed with
2399
    focus on the area of the distribution. The list of areas can either be shown
2400
    as flat list ordered alphabetically or in the hierarchical of the parent
2401
    area and subarea relationship. Fall back areas areas with no Distribution data
2402
    are hidden from the area hierarchy so that their sub areas will move one level up.
2403
    See ' . l('Distribution appearance', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-distribution')) .
2404
    ' for details on the <em>Marked area filter</em>.',
2405
  );
2406

    
2407
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE] = array(
2408
    '#type' => 'fieldset',
2409
    '#tree' => true,
2410
    '#title' => t('Distribution hierarchy style')
2411
  );
2412

    
2413
  $hierarchy_styles = get_array_variable_merged(DISTRIBUTION_HIERARCHY_STYLE, DISTRIBUTION_HIERARCHY_STYLE_DEFAULT);
2414
  foreach(array_keys($hierarchy_styles) as $level) {
2415
    $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level] = array(
2416
      '#type' => 'fieldset',
2417
      '#tree' => true,
2418
      '#title' => t('@area-level', array('@area-level' => drupal_ucfirst((str_replace('_', ' ', $level))))),
2419
      '#attributes' => array('class' => array('fieldset-float'))
2420
    );
2421
    foreach ($hierarchy_styles[$level] as $key => $value) {
2422
      $form['taxon_profile']['distribution_layout'][DISTRIBUTION_HIERARCHY_STYLE][$level][$key] = array(
2423
        '#type' => 'textfield',
2424
        '#title' => t('@area-level-style', array('@area-level-style' => drupal_ucfirst((str_replace('_', ' ', $key))))),
2425
        '#default_value' => $hierarchy_styles[$level][$key],
2426
        '#maxlength' => 4,
2427
        '#size' => 4
2428
      );
2429
    }
2430
  }
2431

    
2432
  $level_options = cdm_vocabulary_as_option(UUID_NAMED_AREA_LEVEL, NULL, FALSE, NULL, CDM_ORDER_BY_ORDER_INDEX_ASC);
2433
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TREE_OMIT_LEVELS] = array(
2434
    '#type' => 'checkboxes',
2435
    '#title' => 'Omit area levels',
2436
    '#options' => $level_options,
2437
    '#default_value' => variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()),
2438
    '#description' => 'This option ins only applicable when distributions are hierachically orderd (see option above)!
2439
    Areas which belong to the selected area levels will be hidden in the portal.',
2440
  );
2441

    
2442
  $form['taxon_profile']['distribution_layout'][DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP] = array(
2443
    '#type' => 'checkbox',
2444
    '#title' => t('Show TextData elements on top of the map'),
2445
    '#default_value' => variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0),
2446
    '#description' => t('Check this if you want to appear all <code>TextData</code>
2447
      elements on top of the map. Otherwise all <code>TextData</code>
2448
      distribution elements will be listed below the other area elements.
2449
      This option is useful if you need to have descriptive texts for each
2450
      distribution map.'),
2451
  );
2452

    
2453
  $form['taxon_profile'][DISTRIBUTION_STATUS_COLORS] = array(
2454
      '#type' => 'textarea',
2455
      '#title' => t('Custom status colors'),
2456
      '#element_validate' => array('form_element_validate_json'),
2457
      '#default_value' => variable_get(DISTRIBUTION_STATUS_COLORS, ''),
2458
      '#description' => t('<strong>EXPERIMENTAL!</strong><br/>This may be changed in the next release without notification.
2459
          A json map object with StatusTerm.idInVocabulary as key and a hex color as value. e.g: <code>{"n":"#ff0000","p":"#00ff00"}</code>.
2460
          reference list of the idInVocabulary values of absence and presence terms:
2461
<pre>
2462
Presence Term
2463
p	present
2464
pd	present: doubtfully present
2465
n	native
2466
nq	native: presence questionable
2467
nd	native: doubtfully native
2468
c	cultivated
2469
i	introduced
2470
iq	introduced: presence questionable
2471
id	introduced: doubtfully introduced (perhaps cultivated only)
2472
ip	introduced: uncertain degree of naturalisation
2473
ia	introduced: adventitious (casual)
2474
in	introduced: naturalized
2475
ic	introduced: cultivated
2476
e	endemic for the relevant area
2477
na	naturalised
2478
iv	invasive
2479

    
2480
AbsenceTerm
2481
a	absent
2482
f	reported in error
2483
nf	native: reported in error
2484
if	introduced: reported in error
2485
cf	cultivated: reported in error
2486
ne	native: formerly native
2487
ie	introduced: formerly introduced
2488

    
2489
</pre>'),
2490
  );
2491

    
2492

    
2493
  /* ====== SYNONYMY ====== */
2494
  $form['taxon_synonymy'] = array(
2495
    '#type' => 'fieldset',
2496
    '#title' => t('Taxon synonymy (tab)'),
2497
    '#collapsible' => TRUE,
2498
    '#collapsed' => TRUE,
2499
    '#description' => t('This section covers the settings related to the taxon
2500
      <strong>synonymy</strong> tab.'),
2501
  );
2502

    
2503
  $form['taxon_synonymy']['cdm_dataportal_nomref_in_title'] = array(
2504
    '#type' => 'checkbox',
2505
    '#title' => t('Accepted taxon on top of the synonymy'),
2506
    '#default_value' => variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE),
2507
    '#description' => t('If checked, the first homotypic taxon is a repetition
2508
      of the accepted taxon most likely with the full nomenclatural reference, 
2509
      depending on the ' . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout') . '.'),
2510
  );
2511

    
2512
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE] = array(
2513
    '#type' => 'checkbox',
2514
    '#title' => t('Secundum referenence as separate line above the accepted taxon.'),
2515
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE, 0),
2516
    '#description' => t('You may want to remove the <code>"secReferencePart": true,</code> entry from <code>"accepted_taxon.taxon_page_synonymy"{</code> the in the '
2517
      . l('Name render templates', 'admin/config/cdm_dataportal/settings/layout')
2518
      . ' (Only applicable when the "Show accepted taxon on top of the synonymy" option above is enabled.)'),
2519
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE)
2520
  );
2521

    
2522
  $form['taxon_synonymy'][CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL] = array(
2523
    '#type' => 'textfield',
2524
    '#description' => 'Label for the secundum referenence.',
2525
    '#default_value' => variable_get(CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL, CDM_SYNONYMY_ACCEPTED_TAXON_SEC_SEPARATE_LABEL_DEFAULT),
2526
    '#disabled' =>  !variable_get('cdm_dataportal_nomref_in_title', 0)
2527
    );
2528

    
2529
  $form['taxon_synonymy']['cdm_dataportal_display_is_accepted_for'] = array(
2530
    '#type' => 'checkbox',
2531
    '#title' => t('Display <em>is accepted for ...</em> on taxon pages when
2532
      coming from a synonym link.'),
2533
    '#default_value' => variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR),
2534
    '#description' => t('Check this if after doing a search and clicking on a
2535
      synonym you want to see the "accept of" text for the accepted synonym.'),
2536
  );
2537

    
2538
  /* === currently unused ===
2539
  $nameRelationshipTypeOptions = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE);
2540
  $form['taxon_synonymy']['name_relationships']['name_relationships_to_show'] = array(
2541
    '#type' => 'checkboxes',
2542
    '#title' => t('Display name relationships') . ':',
2543
    '#default_value' => variable_get('name_relationships_to_show', 0),
2544
    '#options' => $nameRelationshipTypeOptions,
2545
    '#description' => t('Select the name relationships you want to show for the
2546
      accepted taxa.'),
2547
  );
2548
 */
2549

    
2550
  $form['taxon_synonymy']['taxon_relations'] = array(
2551
    '#type' => 'fieldset',
2552
    '#title' => t('Taxon relationships'),
2553
    '#collapsible' => FALSE,
2554
    '#collapsed' => FALSE
2555
  );
2556

    
2557
  $form['taxon_synonymy']['taxon_relations'][CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS] = array(
2558
    '#type' => 'checkbox',
2559
    '#title' => t('Show taxon relations ships of accepted taxon'),
2560
    '#default_value' => variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2561
    '#description' => t('If this option is enabled the synonymy will show the
2562
      below selected taxon relationships of accepted taxa.'),
2563
  );
2564

    
2565
  $taxon_relationship_type_options = cdm_vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2566
  $taxon_relationship_type_defaults = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
2567
  $form['taxon_synonymy']['taxon_relations'][CDM_TAXON_RELATIONSHIP_TYPES] = array(
2568
    '#type' => 'checkboxes',
2569
    '#title' => t('Taxon relationship types') . ':',
2570
    '#description' => t('Only taxon relationships of the selected type will be
2571
      displayed'),
2572
    '#options' => $taxon_relationship_type_options,
2573
    '#default_value' => $taxon_relationship_type_defaults,
2574
    '#disabled' => !variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT),
2575
  );
2576

    
2577
  $form['taxon_synonymy']['name_relations'] = array(
2578
    '#type' => 'fieldset',
2579
    '#title' => t('Name relationships'),
2580
    '#collapsible' => FALSE,
2581
    '#collapsed' => FALSE
2582
  );
2583

    
2584
  $name_relationship_type_options = cdm_vocabulary_as_option(UUID_NAME_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
2585
  $form['taxon_synonymy']['name_relations'][CDM_NAME_RELATIONSHIP_TYPES] = array(
2586
    '#type' => 'checkboxes',
2587
    '#title' => t('Name relationship types') . ':',
2588
    '#description' => t('Only name relationships of the selected type will be
2589
      displayed'),
2590
    '#options' => $name_relationship_type_options,
2591
    '#default_value' => variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT)),
2592
  );
2593

    
2594
  // ====== SPECIMENS ====== //
2595
  $form['taxon_specimens'] = array(
2596
    '#type' => 'fieldset',
2597
    '#title' => t('Taxon specimens (tab)'),
2598
    '#collapsible' => TRUE,
2599
    '#collapsed' => TRUE,
2600
    '#description' => t('This section covers the settings related to the taxon
2601
      <strong>specimens</strong> tab.'),
2602
  );
2603

    
2604
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2605

    
2606
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table'] = array(
2607
    '#type' => 'checkbox',
2608
    '#title' => t('Show specimen derivatives in a compressed table'),
2609
    '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE),
2610
    '#description' => t('If checked, the specimen will be listed in a table. Every row represents
2611
    a collection and it can be expanded to get an overview of the specimens and their derivates.'),
2612
  );
2613

    
2614
  $form['taxon_specimens']['cdm_dataportal_compressed_specimen_derivate_table_page_size'] = array(
2615
      '#type' => 'textfield',
2616
      '#title' => t('Number of records per page') . ':',
2617
      '#default_value' => variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size', CDM_DATAPORTAL_COMPRESSED_SPECIMEN_DERIVATE_TABLE_PAGE_SIZE),
2618
  );
2619

    
2620
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2621
        '#type' => 'checkbox',
2622
        '#title' => t('Show specimen derivatives in a tree view'),
2623
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2624
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2625
    );
2626

    
2627

    
2628
    $featureTrees = cdm_get_featureTrees_as_options(TRUE);
2629
  $profile_feature_tree_uuid = variable_get(CDM_OCCURRENCE_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE);
2630
  if(!isset($featureTrees['options'][$profile_feature_tree_uuid])) {
2631
    $profile_feature_tree_uuid = UUID_DEFAULT_FEATURETREE;
2632
  }
2633
  $form['taxon_specimens']['feature_trees'][CDM_OCCURRENCE_FEATURETREE_UUID] = array(
2634
    '#type' => 'radios',
2635
    '#title' => t('Specimen description feature tree') . ':',
2636
    '#default_value' => $profile_feature_tree_uuid,
2637
    '#options' =>  $featureTrees['options'],
2638
    '#pre_render' => array('form_pre_render_conditional_form_element', 'radios_prepare_options_suffix'),
2639
    '#options_suffixes' => $featureTrees['treeRepresentations'],
2640
    '#description' => t('Select the feature tree to be used for displaying specimen descriptions. Click "Show Details" to see the Feature Tree elements.'
2641
    ),
2642
  );
2643

    
2644
  $form_name = CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME;
2645
  $form_title = t('Specimen media');
2646
  $form_description = t('Specimens may have media which is displayed at the
2647
     Specimen tab/section as a gallery. It is possible to configure the
2648
     thumbnails gallery here, however for configuring how a single media should
2649
     be displayed please go to !url.</p>',
2650
     array(
2651
       '!url' => l(t('Layout -> Media'), 'admin/config/cdm_dataportal/settings/layout/media'),
2652
     ));
2653
  $form['taxon_specimens'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, FALSE, $form_description);
2654

    
2655
  // --- MEDIA GALLERY ---- //
2656
  $form_name = CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB;
2657
  $form_title = 'Media gallery (tab)';
2658
  $form_description = '<p>This section covers the settings related to the taxon <strong>images</strong> tab.
2659
   Taxa may have media (usually images) and they are displayed as thumbnails. It is possible to configure
2660
   the thumbnails gallery here, however for configuring how a single media should be displayed please go to
2661
   <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a></p>
2662
   <p><strong>Note:</strong> These settings are only taken into account when the standard
2663
   gallery viewer is selected at <a href="./?q=admin/settings/cdm_dataportal/layout/media">Layout -&gt; Media</a>.</p>';
2664
  $form['taxon_media'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, TRUE, $form_description);
2665

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

    
2675
/**
2676
 * Creates a form element for the constants DISTRIBUTION_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY.
2677
 *
2678
 * @param $map_id
2679
 * @param $form
2680
 * @return mixed
2681
 */
2682
function _cdm_map_visibility_setting($map_id)
2683
{
2684
  return array(
2685
    '#type' => 'select',
2686
    '#title' => t(ucfirst($map_id) . ' map visibility'),
2687
    '#default_value' => variable_get(constant(strtoupper($map_id) . '_MAP_VISIBILITY'), constant(strtoupper($map_id) . '_MAP_VISIBILITY_DEFAULT')),
2688
    '#options' => array('always' => 'always', 'automatic' => 'automatic', 'never' => 'never'),
2689
    '#description' => "The visibility of the map can managed <b>automatically</b> depending on whether there is data to show or not. 
2690
        The map also can forced to show up <b>always</b> or <b>never</b>."
2691
  );
2692
}
2693

    
2694
/**
2695
 * @todo document this function.
2696
 */
2697
function cdm_settings_layout_search() {
2698

    
2699
  $form = array();
2700

    
2701
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2702

    
2703
  $form['search_settings'] = array(
2704
    '#type' => 'fieldset',
2705
    '#title' => t('Taxa Search'),
2706
    '#collapsible' => FALSE,
2707
    '#collapsed' => FALSE,
2708
    '#description' => t('<p>The data portal allows the users to perform searchs.</p><p>To perform searchs
2709
         the block <em>CDM Taxon Search</em> should be enabled and visible for users
2710
         where they can write the text to be searched. You can find Drupal block configuration
2711
         site at <a href="./?q=admin/build/block">Administer&#45&#62Site building&#45&#62Blocks</a></p> '),
2712
  );
2713

    
2714
  $form['search_settings'][SIMPLE_SEARCH_IGNORE_CLASSIFICATION] = array(
2715
      '#type' => 'checkbox',
2716
      '#title' => t('Ignore the chosen classification in simple search'),
2717
      '#default_value' => variable_get(SIMPLE_SEARCH_IGNORE_CLASSIFICATION, 0),
2718
      '#description' => t('The simple search, which can be executed via the search block,
2719
          will by default search on the classification selected in the classification browser
2720
          selector. Set the tick if you want your portal to search on all classifications.'),
2721
  );
2722

    
2723
  $form['search_settings'][SIMPLE_SEARCH_USE_LUCENE_BACKEND] = array(
2724
    '#type' => 'checkbox',
2725
    '#title' => t('Run simple search with free-text search backend.'),
2726
    '#default_value' => variable_get(SIMPLE_SEARCH_USE_LUCENE_BACKEND, 0),
2727
    '#description' => t('The simple search uses by default another search
2728
      backend as the advances search. By checking this option the simple search can be
2729
      configured to also use the free-text search backend.'),
2730
  );
2731

    
2732
  $form['search_settings'][SIMPLE_SEARCH_AUTO_SUGGEST] = array(
2733
    '#type' => 'checkbox',
2734
    '#title' => t('(EXPERIMENTAL) Enable auto-suggest for taxon search'),
2735
    '#default_value' => variable_get(SIMPLE_SEARCH_AUTO_SUGGEST, 0),
2736
    '#description' => t('If enabled, the taxon search field will suggest taxon names while typing in a search query.
2737
    This function works on indexed taxon names. If you experience any delay maybe you have to reindex (see above).'),
2738
  );
2739

    
2740
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2741
    '#type' => 'textfield',
2742
    '#title' => t('Results per page') . ':',
2743
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2744
    '#description' => t('Number of results to display per page.'),
2745
  );
2746

    
2747
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2748
    '#type' => 'checkbox',
2749
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2750
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2751
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2752
  );
2753

    
2754
  $search_mode_default = get_array_variable_merged(CDM_SEARCH_TAXA_MODE, CDM_SEARCH_TAXA_MODE_DEFAULT);
2755
  $form['search_settings']['cdm_search_taxa_mode'] = array(
2756
      '#type' => 'checkboxes',
2757
      '#title' => 'Search mode',
2758
      '#description' => 'The taxon search can operate in different modes in order to find only taxa, synonyms,
2759
          taxa by its common name and even taxa which have been used as misappied names. The settings made here will affect the default
2760
          for the advance search form and the behaviour of the simple search form which always will behave according to the
2761
          defaults set here.',
2762
      '#options' => drupal_map_assoc(array_keys(unserialize(CDM_SEARCH_TAXA_MODE_DEFAULT))),
2763
      '#default_value' => $search_mode_default
2764
      );
2765

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

    
2771
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2772
  );
2773

    
2774
  // --- SEARCH TAXA GALLERY ---- //
2775
  $items = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
2776
  $collapsed = FALSE;
2777
  $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
2778
  $form_title = 'Taxa Search thumbnails';
2779
  $form_description = 'Search results may show thumbnails. ';
2780
  $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2781

    
2782
  // Comment @WA: D7 form api does not support reset buttons,
2783
  // so to mimic the D5 reset button we add one like this.
2784
  $form['actions']['reset'] = array(
2785
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2786
    '#weight' => 1000,
2787
  );
2788
  return system_settings_form($form);
2789
}
2790

    
2791
/**
2792
 * @todo document this function.
2793
 */
2794
function cdm_settings_layout_media() {
2795

    
2796
  $form = array();
2797

    
2798
  $form['media_settings'] = array(
2799
    '#type' => 'fieldset',
2800
    '#title' => t('Media settings'),
2801
    '#collapsible' => FALSE,
2802
    '#collapsed' => FALSE,
2803
    '#description' => 'This section covers layout settings for media pages.'
2804
      . 'Further media related settings may be found under the taxon layout settings and on the general settings.',
2805
  );
2806

    
2807
  $form['media_settings']['image_gallery_viewer'] = array(
2808
    '#type' => 'select',
2809
    '#title' => t('Image viewer') . ':',
2810
    '#default_value' => variable_get('image_gallery_viewer', 'default'),
2811
    '#options' => array(
2812
      'default' => t('Standard image viewer'),
2813
      'fsi' => t('FSI viewer (requires FSI server!)'),
2814
    ),
2815
  );
2816

    
2817
  // --- STANDARD_IMAGE_VIEWER ---- //
2818
  if(variable_get('image_gallery_viewer', 'default') == 'default') {
2819
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER] = array(
2820
      '#type' => 'fieldset',
2821
      '#tree' => true,
2822
      '#title' => t('Standard image viewer settings'),
2823
      '#collapsible' => FALSE,
2824
      '#collapsed' => FALSE,
2825
      );
2826

    
2827
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2828
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2829
      '#type' => 'checkbox',
2830
      '#title' => 'Show media representations',
2831
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2832

    
2833
    );
2834
  }
2835

    
2836

    
2837
  // @WA: D7 form api does not support reset buttons,
2838
  // so to mimic the D5 reset button we add one like this.
2839
  $form['actions']['reset'] = array(
2840
    '#markup' => '<input id="reset" type="reset" class="form-submit" value="' . t('Reset to defaults') . '" />',
2841
    '#weight' => 1000,
2842
  );
2843
  return system_settings_form($form);
2844
}
2845

    
2846
/**
2847
 * GEOSERVICE and Map settings.
2848
 */
2849
function cdm_settings_geo($form, &$form_state) {
2850

    
2851
  $current_geoserver_settings = get_edit_map_service_settings();
2852
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2853

    
2854

    
2855
  $form = array();
2856

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

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

    
2880
  /*
2881
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2882
  );
2883
  */
2884

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

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

    
2913
  /*
2914
   * MAP SETTINGS
2915
   */
2916

    
2917
  $form[CDM_MAP_DISTRIBUTION] = array(
2918
    '#type' => 'fieldset',
2919
    '#tree' => TRUE,
2920
    '#title' => t('Maps settings'),
2921
    '#collapsible' => TRUE,
2922
    '#collapsed' => TRUE,
2923
    '#description' => t('General configuration for all map types.'),
2924
  );
2925

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

    
2943
  /*
2944
   * settings for the distribution map are used also for specimens map!!!!
2945
   */
2946

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

    
2962
  $form[CDM_MAP_DISTRIBUTION]['bbox'] = array(
2963
    '#type' => 'textfield',
2964
    '#title' => 'Bounding box',
2965
    '#default_value' => $map_distribution['bbox'],
2966
    '#description' => t('The bounding box (left, bottom, right, top) in degree defines the area to be initially displayed in maps.
2967
      Use "-180,-90,180,90" for the whole world. Leave <strong>empty</strong>
2968
      to let the map <strong>automatically zoom</strong> to the bounds enclosing the shown data.</p>
2969
      <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.
2970
      (Maybe you need to change the map base layer to OpeLayers.)
2971
      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
2972
      below the map from where you can copy the bbox string.</p>'),
2973
  );
2974

    
2975
  $form[CDM_MAP_DISTRIBUTION]['maxZoom'] = array(
2976
    '#type' => 'select',
2977
    '#title' => 'Max zoom level',
2978
    '#default_value' => $map_distribution['maxZoom'],
2979
    '#options' => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)
2980
  );
2981

    
2982
  $form[CDM_MAP_DISTRIBUTION]['show_labels'] = array(
2983
    '#type' => 'checkbox',
2984
    '#title' => 'Display area labels',
2985
    '#default_value' => $map_distribution['show_labels'],
2986
    '#description' => t('The map will show name labels of the areas'),
2987
  );
2988

    
2989
  $form[CDM_MAP_DISTRIBUTION]['caption'] = array(
2990
    '#type' => 'textfield',
2991
    '#title' => 'Map caption',
2992
    '#default_value' => $map_distribution['caption'],
2993
    '#description' => t('The caption will be shown below the map.'),
2994
  );
2995

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

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

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

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

    
3041
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
3042
    '#type' => 'textfield',
3043
    '#title' => 'Background color',
3044
    '#default_value' => $map_distribution['image_map']['bg_color'],
3045
  );
3046

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

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

    
3064

    
3065
  // --- OpenLayers Settings --- //
3066
  $form[CDM_MAP_DISTRIBUTION]['openlayers'] = array(
3067
    '#type' => 'fieldset',
3068
    '#title' => 'OpenLayers settings',
3069
    '#tree' => TRUE,
3070
    '#collapsible' => TRUE,
3071
    '#collapsed' => !$open_layers_is_enabled,
3072
    '#description' => '',
3073
  );
3074

    
3075

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

    
3085

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

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

    
3103
  // The default layer must always be enabled
3104
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3105
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3106

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

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

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

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

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

    
3172
  $form[CDM_MAP_DISTRIBUTION]['openlayers']['wms_overlay_layer']['is_enabled'] = array(
3173
    '#type' => 'checkbox',
3174
    '#title' => 'Enable overlay layer',
3175
    '#weight' => -100,
3176
    '#default_value' => $map_distribution['openlayers']['wms_overlay_layer']['is_enabled'] === 1  ? 1 : 0
3177
  );
3178

    
3179
  /*
3180
   * Map Legend
3181
   */
3182
  $form[CDM_MAP_DISTRIBUTION]['legend'] = array(
3183
    '#type' => 'fieldset',
3184
    '#title' => 'Map legend',
3185
    '#tree' => TRUE,
3186
    '#collapsible' => TRUE,
3187
    '#collapsed' => TRUE,
3188
    '#description' => 'Configure the maps legend.',
3189
  );
3190

    
3191
  $form[CDM_MAP_DISTRIBUTION]['legend']['show'] = array(
3192
    '#type' => 'checkbox',
3193
    '#title' => 'Display a map legend',
3194
    '#default_value' => $map_distribution['legend']['show'],
3195
    '#description' => 'Check this if you like a legend to be displayed with the maps.',
3196
  );
3197

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

    
3206
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3207
    '#type' => 'textfield',
3208
    '#title' => 'Font size',
3209
    '#default_value' => $map_distribution['legend']['font_size'],
3210
    '#description' => 'Font size in pixels.',
3211
  );
3212

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

    
3225
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_width'] = array(
3226
    '#type' => 'textfield',
3227
    '#title' => 'Icon width',
3228
    '#default_value' => $map_distribution['legend']['icon_width'],
3229
    '#description' => 'Legend icon width in pixels.',
3230
  );
3231
  $form[CDM_MAP_DISTRIBUTION]['legend']['icon_height'] = array(
3232
    '#type' => 'textfield',
3233
    '#title' => 'Icon height',
3234
    '#default_value' => $map_distribution['legend']['icon_height'],
3235
    '#description' => 'Legend icon height in pixels.',
3236
  );
3237

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

    
3245
  return system_settings_form($form);
3246
}
3247

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

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

    
3301
  if($add_projection_settings){
3302

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

    
3368
  }
3369
  return $form_elements;
3370
}
3371

    
3372

    
3373
/**
3374
 * @todo document this function.
3375
 */
3376
function cdm_settings_cache() {
3377

    
3378
  $form = array();
3379

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

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

    
3403
  $form['cache_settings']['cdm_run_cache'] = array(
3404
    '#markup' => cdm_view_cache_site(),
3405
  );
3406

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

    
3416
/**
3417
 * Walk and cache all taxon pages.
3418
 */
3419
function cdm_view_cache_site() {
3420

    
3421
  $out = '';
3422

    
3423
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3424

    
3425
  $request_params = array();
3426
  $request_params['class'] = "Taxon";
3427

    
3428
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3429
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3430
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3431

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

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

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

    
3459

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

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

    
3491
/**
3492
 * Form validation handler for cdm_settings_general
3493
 *
3494
 * @param $form
3495
 * @param $form_state
3496
 */
3497
function cdm_settings_general_validate($form, &$form_state) {
3498

    
3499
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3500
    $form_state['values']['cdm_webservice_url'] .= '/';
3501
  }
3502

    
3503
}
3504

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

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

    
3531
}
3532

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

    
3544
  $settings = variable_get('edit_map_server', array(
3545
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3546
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3547
      )
3548
  );
3549

    
3550
  return $settings;
3551
}
3552

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

    
3564

    
3565
/**
3566
 * Returns the version number of the currently selected edit mapserver as a float
3567
 *
3568
 * @return float
3569
 *   The version number of the currently selected edit mapserver as a float.
3570
 *   Returns 0 on error.
3571
 */
3572
function get_edit_map_service_version_number() {
3573

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

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

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

    
3611

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

    
3630
/**
3631
 * #process callback function for the custom form element type 'checkbox_preferred'
3632
 *
3633
 *
3634
 */
3635
function checkboxes_preferred_expand($element, &$form_state, $form) {
3636

    
3637
  // First of all create checkboxes for each of the elements
3638
  $element = form_process_checkboxes($element);
3639

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

    
3649
  $children = element_children($element);
3650

    
3651
  $element['table_start'] = array(
3652
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3653
    '#weight' => -1,
3654
  );
3655

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

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

    
3691
  // end the table
3692
  $element['table_end'] = array(
3693
    '#markup' => '</table>',
3694
    '#weight' => $weight++,
3695
  );
3696

    
3697
  return $element;
3698
}
3699

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

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

    
3733
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3734

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

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

    
3762
  return $element;
3763
}
3764

    
3765
function radios_prepare_options_suffix(&$elements){
3766

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

    
3779
}
3780

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

    
3793

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

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