Project

General

Profile

Download (152 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * CDM Dataportal settings.
5
 */
6

    
7

    
8
  // TODO Genus UUID.
9

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

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

    
18
  define('CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE', 25);
19

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

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

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

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

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

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

    
64

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

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

    
110

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

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

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

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

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

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

    
159

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

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

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

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

    
188
}
189

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
702
  // ---- DEFAULTS settings
703

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

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

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

    
780
  $cichorieae_default = array(
781
    'DEFAULT' => array(
782
      'as_list' => 'div',
783
      'link_to_reference' => 1,
784
      'link_to_name_used_in_source' => 1,
785
      'sources_as_content' => 1,
786
      'sources_as_content_to_bibliography' => 0,
787
      'sort_elements' => NO_SORT,
788
      'glue' => '',
789
      'element_tag' => 'div'
790
    ),
791
    UUID_CITATION => array(
792
      'as_list' => 'div',
793
      'link_to_reference' => 0,
794
      'link_to_name_used_in_source' => 0,
795
      'sources_as_content' => 1,
796
      'sources_as_content_to_bibliography' => 0,
797
      'sort_elements' => SORT_ASC,
798
      'glue' => '',
799
      'element_tag' => 'div'
800
    ),
801
    UUID_CHROMOSOMES_NUMBERS => array(
802
      'as_list' => 'ul',
803
      'link_to_reference' => 1,
804
      'link_to_name_used_in_source' => 1,
805
      'sources_as_content' => 1,
806
      'sources_as_content_to_bibliography' => 0,
807
      'sort_elements' => NO_SORT,
808
      'glue' => '',
809
      'element_tag' => 'div'
810
    ),
811
    UUID_CHROMOSOMES => array(
812
      'as_list' => 'ul',
813
      'link_to_reference' => 0,
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_COMMON_NAME => array(
822
      'as_list' => 'div',
823
      'link_to_reference' => 0,
824
      'link_to_name_used_in_source' => 1,
825
      'sources_as_content' => 0,
826
      'sources_as_content_to_bibliography' => 0,
827
      'sort_elements' => NO_SORT,
828
      'glue' => '',
829
      'element_tag' => 'span'
830
    ),
831
  );
832

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

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

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

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

    
906
  // ---- END of DEFAULTS
907

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

    
910
  $feature_block_setting = null;
911

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

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

    
932
  return $feature_block_setting;
933
}
934

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

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

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

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

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

    
1021
  $items['admin/config/cdm_dataportal/settings/layout/taxon'] = array(
1022
    'title' => 'Taxon',
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_taxon'),
1027
    'weight' => 1,
1028
    'type' => MENU_LOCAL_TASK,
1029
  );
1030
  /*
1031
  $items[] = array(
1032
  'path' => 'admin/config/cdm_dataportal/layout/synonymy',
1033
  'title' => t('Synonymy'),
1034
  'description' => t('Configure and adjust the layout of your DataPortal '),
1035
  'access' => user_access('administer cdm_dataportal'),
1036
  'callback' => 'drupal_get_form',
1037
  'callback arguments' => array('cdm_settings_layout_synonymy'),
1038
  'weight' => 1,
1039
  'type' => MENU_LOCAL_TASK,
1040
  );
1041

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

    
1063
  $items['admin/config/cdm_dataportal/settings/layout/media'] = array(
1064
    'title' => 'Media',
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_media'),
1069
    'weight' => 3,
1070
    'type' => MENU_LOCAL_TASK,
1071
  );
1072

    
1073
}
1074

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1413

    
1414

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

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

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

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

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

    
1463
  return system_settings_form($form);
1464
}
1465

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

    
1476

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

    
1484
  $form = array();
1485

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

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

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

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

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

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

    
1541
  $bibliography_settings = get_bibliography_settings(true);
1542

    
1543
  $form[BIBLIOGRAPHY_FOR_ORIGINAL_SOURCE]['enabled'] = array(
1544
      '#type' => 'checkbox',
1545
      '#title' => t('Original Source in bibliography'),
1546
      '#default_value' => $bibliography_settings['enabled'],
1547
      '#description' => t('Show original source citations in bibliography block, instead of rendering them with other
1548
       annotations in each feature block.<br/><br/>Whether the Original Source reference of a Feature Block is actually put 
1549
       into the bibliography also depends on the settings in the ' .
1550
        l("Taxon profile feature block settings", "settings/layout/taxon") .
1551
        '. 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.'),
1552
  );
1553

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1780

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

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

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

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

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

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

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

    
1860
  return $form;
1861
}
1862

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

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

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

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

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

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

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

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

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

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

    
1965
  // ---- PROFILE PICTURE ----//
1966

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

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

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

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

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

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

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

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

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

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

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

    
2070
  // -- MEDIA THUMBNAILS -- //
2071
  $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
2072
  $form_title = 'Taxon Profile Images';
2073
  $form_description = '<p>The different section in the taxon  profile can have images associated with them. These images are displayed in a gallery of thumbnails wich can be configuered here:</p>';
2074
  $form['taxon_profile'][] = cdm_dataportal_create_gallery_settings_form($form_name, $form_title, $collapsed, $form_description);
2075

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

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

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

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

    
2151

    
2152
    $feature_list_layout_settings_disabled = FALSE;
2153

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2288

    
2289

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

    
2308
  );
2309

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

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

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

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

    
2336

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

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

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

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

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

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

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

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

    
2439

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

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

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

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

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

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

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

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

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

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

    
2534
  $form['taxon_specimens'][SPECIMEN_MAP_VISIBILITY]  = _cdm_map_visibility_setting('specimen');
2535

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

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

    
2550
    $form['taxon_specimens']['cdm_dataportal_specimen_derivate_tree'] = array(
2551
        '#type' => 'checkbox',
2552
        '#title' => t('Show specimen derivatives in a tree view'),
2553
        '#default_value' => variable_get('cdm_dataportal_specimen_derivate_tree', CDM_DATAPORTAL_SPECIMEN_DERIVATE_TREE),
2554
        '#description' => t('If checked, the specimen will be listed in a tree view.'),
2555
    );
2556

    
2557

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

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

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

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

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

    
2624
/**
2625
 * @todo document this function.
2626
 */
2627
function cdm_settings_layout_search() {
2628

    
2629
  $form = array();
2630

    
2631
  $form['#submit'][] = 'cdm_settings_layout_search_submit';
2632

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

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

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

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

    
2670
  $form['search_settings']['cdm_dataportal_search_items_on_page'] = array(
2671
    '#type' => 'textfield',
2672
    '#title' => t('Results per page') . ':',
2673
    '#default_value' => variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE),
2674
    '#description' => t('Number of results to display per page.'),
2675
  );
2676

    
2677
  $form['search_settings'][SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX] = array(
2678
    '#type' => 'checkbox',
2679
    '#title' => t('Show the') .  ' <i>' . t('Display image thumbnails') . '</i>' . t('button') . ':',
2680
    '#default_value' => variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT),
2681
    '#description' => t('The search results page will offer a button to toggle the display of image thumbnails.'),
2682
  );
2683

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

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

    
2701
    '#description' => t('Area uuids, comma separated, no whitespace. EXPERIMENTAL!!!!'),
2702
  );
2703

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

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

    
2721
/**
2722
 * @todo document this function.
2723
 */
2724
function cdm_settings_layout_media() {
2725

    
2726
  $form = array();
2727

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

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

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

    
2757
    $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
2758
    $form['media_settings'][CDM_STANDARD_IMAGE_VIEWER]['media_representation_details_enabled'] = array (
2759
      '#type' => 'checkbox',
2760
      '#title' => 'Show media representations',
2761
      '#default_value' => $cdm_standard_image_viewer_settings['media_representation_details_enabled']
2762

    
2763
    );
2764
  }
2765

    
2766

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

    
2776
/**
2777
 * GEOSERVICE and Map settings.
2778
 */
2779
function cdm_settings_geo($form, &$form_state) {
2780

    
2781
  $current_geoserver_settings = get_edit_map_service_settings();
2782
  $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT);
2783

    
2784

    
2785
  $form = array();
2786

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

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

    
2810
  /*
2811
  $form['map_preview']['map'] = compose_map(NULL, $dummy_distribution_query, NULL, array(), 0 // force image map
2812
  );
2813
  */
2814

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

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

    
2843
  /*
2844
   * MAP SETTINGS
2845
   */
2846

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

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

    
2873
  /*
2874
   * settings for the distribution map are used also for specimens map!!!!
2875
   */
2876

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

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

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

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

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

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

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

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

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

    
2971
  $form[CDM_MAP_DISTRIBUTION]['image_map']['bg_color'] = array(
2972
    '#type' => 'textfield',
2973
    '#title' => 'Background color',
2974
    '#default_value' => $map_distribution['image_map']['bg_color'],
2975
  );
2976

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

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

    
2994

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

    
3005

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

    
3015

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

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

    
3033
  // The default layer must always be enabled
3034
  $preferred_layer = $map_distribution['openlayers']['base_layers']['PREFERRED'];
3035
  $map_distribution['openlayers']['base_layers'][$preferred_layer] = $preferred_layer;
3036

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

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

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

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

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

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

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

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

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

    
3136
  $form[CDM_MAP_DISTRIBUTION]['legend']['font_size'] = array(
3137
    '#type' => 'textfield',
3138
    '#title' => 'Font size',
3139
    '#default_value' => $map_distribution['legend']['font_size'],
3140
    '#description' => 'Font size in pixels.',
3141
  );
3142

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

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

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

    
3175
  return system_settings_form($form);
3176
}
3177

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

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

    
3231
  if($add_projection_settings){
3232

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

    
3298
  }
3299
  return $form_elements;
3300
}
3301

    
3302

    
3303
/**
3304
 * @todo document this function.
3305
 */
3306
function cdm_settings_cache() {
3307

    
3308
  $form = array();
3309

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

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

    
3333
  $form['cache_settings']['cdm_run_cache'] = array(
3334
    '#markup' => cdm_view_cache_site(),
3335
  );
3336

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

    
3346
/**
3347
 * Walk and cache all taxon pages.
3348
 */
3349
function cdm_view_cache_site() {
3350

    
3351
  $out = '';
3352

    
3353
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cache_all_taxa.js');
3354

    
3355
  $request_params = array();
3356
  $request_params['class'] = "Taxon";
3357

    
3358
  $cdm_ws_page_taxa_url = cdm_compose_url(CDM_WS_TAXON . ".json", NULL, queryString($request_params));
3359
  $cdm_ws_page_taxa_url = uri_uriByProxy($cdm_ws_page_taxa_url);
3360
  $cdm_ws_page_taxa_url = rtrim($cdm_ws_page_taxa_url, '/');
3361

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

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

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

    
3389

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

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

    
3421
/**
3422
 * Form validation handler for cdm_settings_general
3423
 *
3424
 * @param $form
3425
 * @param $form_state
3426
 */
3427
function cdm_settings_general_validate($form, &$form_state) {
3428

    
3429
  if (!str_endsWith($form_state['values']['cdm_webservice_url'], '/')) {
3430
    $form_state['values']['cdm_webservice_url'] .= '/';
3431
  }
3432

    
3433
}
3434

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

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

    
3461
}
3462

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

    
3474
  $settings = variable_get('edit_map_server', array(
3475
      'base_uri' => EDIT_MAPSERVER_URI_DEFAULT,
3476
      'version' => EDIT_MAPSERVER_VERSION_DEFAULT
3477
      )
3478
  );
3479

    
3480
  return $settings;
3481
}
3482

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

    
3494

    
3495
/**
3496
 * Returns the version number of the currently selected edit mapserver as a float
3497
 *
3498
 * @return float
3499
 *   The version number of the currently selected edit mapserver as a float.
3500
 *   Returns 0 on error.
3501
 */
3502
function get_edit_map_service_version_number() {
3503

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

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

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

    
3541

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

    
3560
/**
3561
 * #process callback function for the custom form element type 'checkbox_preferred'
3562
 *
3563
 *
3564
 */
3565
function checkboxes_preferred_expand($element, &$form_state, $form) {
3566

    
3567
  // First of all create checkboxes for each of the elements
3568
  $element = form_process_checkboxes($element);
3569

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

    
3579
  $children = element_children($element);
3580

    
3581
  $element['table_start'] = array(
3582
    '#markup' => '<table class="checkboxes_preferred"><tr><th></th><th>' . t('Enabled') . '</th><th>' . t('Default') . '</th></tr>',
3583
    '#weight' => -1,
3584
  );
3585

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

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

    
3621
  // end the table
3622
  $element['table_end'] = array(
3623
    '#markup' => '</table>',
3624
    '#weight' => $weight++,
3625
  );
3626

    
3627
  return $element;
3628
}
3629

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

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

    
3663
  $parent_id = $element['#parents'][count($element['#parents']) - 1];
3664

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

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

    
3692
  return $element;
3693
}
3694

    
3695
function radios_prepare_options_suffix(&$elements){
3696

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

    
3709
}
3710

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

    
3723

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

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